Skip to content

Commit

Permalink
wip: Add checksum before COBS encoding frames.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyp committed Aug 12, 2024
1 parent f222b2a commit 51aee0c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions orbtrace/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def __init__(self, platform):
#pv := PipeValid([('data', 128)]),
#Converter(128, 8),
tpiu.TPIUDemux(),
cobs.ChecksumAppender(),
cobs.COBSEncoder(),
cobs.DelimiterAppender(),
cobs.SuperFramer(7500000, 65536),
Expand Down
32 changes: 32 additions & 0 deletions orbtrace/trace/cobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ def __init__(self, delimiter = 0):
self.group_combiner.source.connect(self.source),
]

class ChecksumAppender(Module):
def __init__(self):
self.sink = stream.Endpoint([('data', 8)])
self.source = stream.Endpoint([('data', 8)])

self.submodules.fsm = fsm = FSM()

checksum = Signal(8)

fsm.act('DATA',
self.sink.connect(self.source, omit = {'last'}),

If(self.sink.valid & self.sink.ready,
NextValue(checksum, checksum - self.sink.data),
),

If(self.sink.valid & self.sink.ready & self.sink.last,
NextState('CHECKSUM'),
),
)

fsm.act('CHECKSUM',
self.source.data.eq(checksum),
self.source.last.eq(1),
self.source.valid.eq(1),

If(self.source.ready,
NextState('DATA'),
NextValue(checksum, 0),
),
)

class DelimiterAppender(Module):
def __init__(self, delimiter = 0):
self.sink = stream.Endpoint([('data', 8)])
Expand Down

0 comments on commit 51aee0c

Please sign in to comment.