Skip to content

Commit

Permalink
i2c_packet: removed non-transaction mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sespivak committed Aug 31, 2022
1 parent a05d3a9 commit 100544f
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions decoders/i2c_packet/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
'''

class Ann:
PACKET_READ, \
PACKET_WRITE, \
TRANSACTION, \
= range(3)
DATA = 0

class Decoder(srd.Decoder):
api_version = 3
Expand All @@ -62,17 +59,12 @@ class Decoder(srd.Decoder):
options = (
{'id': 'format', 'desc': 'Data format', 'default': 'hex',
'values': ('ascii', 'dec', 'hex', 'oct', 'bin')},
{'id': 'transaction', 'desc': 'Transaction mode', 'default': 'no', 'values': ('yes', 'no')},
)
annotations = (
('rd', 'Read'),
('wr', 'Write'),
('data', 'Data'),
)
annotation_rows = (
('rd', 'Read', (Ann.PACKET_READ, )),
('wr', 'Write', (Ann.PACKET_WRITE, )),
('data', 'Data', (Ann.TRANSACTION, )),
('packet', 'Packet', (Ann.DATA,)),
)

def __init__(self):
Expand All @@ -84,7 +76,6 @@ def __init__(self):
self.packet_ss = 0
self.packet_part_ss = 0
self.packet_es = 0
self.transaction = False
self.read_sign = False
self.address = 0
self.fmt = None
Expand All @@ -105,7 +96,6 @@ def start(self):
self.fmt = '{:03o}'
else:
self.fmt = None
self.transaction = self.options['transaction'] == 'yes'
self.packet_data = deque()

def reset(self):
Expand All @@ -130,6 +120,7 @@ def format_data_value(self, v):
# below 32 is "control" and thus not printable, above 127 is
# "not ASCII" in its strict sense, 127 (DEL) is not printable,
# fall back to hex representation for non-printables.
# (comment from same code of uart PD by Gerhard Sittig @gsigh)
if self.fmt is None:
if 32 <= v <= 126:
return chr(v)
Expand All @@ -153,7 +144,7 @@ def format_packet(self):

packet_str_short = packet_str[2:]

if self.transaction and self.packet_str:
if self.packet_str:
packet_str = self.packet_str + ' [SR] ' + packet_str
packet_str_short = self.packet_str_short + ' [SR] ' + packet_str_short

Expand All @@ -168,24 +159,20 @@ def handle_packet(self, start_repeat=False):
packet_str, packet_str_short = self.format_packet()

ptype = 'PACKET READ' if self.read_sign else 'PACKET WRITE'
self.putp(self.packet_part_ss, self.packet_es, (ptype, (self.address, tuple(self.packet_data))))
self.putp(self.packet_part_ss, self.packet_es,
(ptype, (self.address, tuple(self.packet_data))))
if not start_repeat:
self.putp(self.packet_es, self.packet_es, ('TRANSACTION END', None))
self.putp(self.packet_es, self.packet_es,
('TRANSACTION END', None))

if start_repeat and self.transaction:
if start_repeat:
self.packet_data.clear()
self.packet_str = packet_str
self.packet_str_short = packet_str_short
else:
if self.transaction:
ann = Ann.TRANSACTION
elif self.read_sign:
ann = Ann.PACKET_READ
else:
ann = Ann.PACKET_WRITE

packet_ss = self.packet_ss if self.transaction else self.packet_part_ss
self.putg(packet_ss, self.packet_es, [ann, [packet_str, packet_str_short]])
packet_ss = self.packet_ss
self.putg(packet_ss, self.packet_es,
[Ann.DATA, [packet_str, packet_str_short]])
self.reset()

def decode(self, ss, es, data):
Expand Down

0 comments on commit 100544f

Please sign in to comment.