]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/sle44xx/pd.py
sle44xx: support memory read "to end of capacity"
[libsigrokdecode.git] / decoders / sle44xx / pd.py
index 559bbc8ab0614c01efd9d9edf8f428731c4f53fc..9f33207789636b5bbb668df8df5ad1d61ad99321 100644 (file)
@@ -78,6 +78,8 @@ class Decoder(srd.Decoder):
         self.reset()
 
     def reset(self):
+        self.samplerate = None
+        self.max_addr = 256
         self.bits = []
         self.atr_bytes = []
         self.cmd_bytes = []
@@ -101,6 +103,13 @@ class Decoder(srd.Decoder):
     def putb(self, ss, es, cls , data):
         self.put(ss, es, self.out_binary, [cls, data,])
 
+    def snums_to_usecs(self, snum_count):
+        if not self.samplerate:
+            return None
+        snums_per_usec = self.samplerate / 1e6
+        usecs = snum_count / snums_per_usec
+        return usecs
+
     def lookup_proto_ann_txt(self, key, variables):
         ann = {
             'RESET_SYM': [Ann.RESET_SYM, 'Reset', 'R',],
@@ -200,6 +209,10 @@ class Decoder(srd.Decoder):
             clk = self.proc_state['clk']
             high = self.proc_state['io1']
             text = '{clk} clocks, I/O {high}'.format(clk = clk, high = int(high))
+            usecs = self.snums_to_usecs(es - ss)
+            if usecs:
+                msecs = usecs / 1000
+                text = '{msecs:.2f} ms, {text}'.format(msecs = msecs, text = text)
             cls, texts = self.lookup_proto_ann_txt(key, {'data': text})
             self.putx(ss, es, cls, texts)
 
@@ -240,6 +253,7 @@ class Decoder(srd.Decoder):
                     'read main memory, addr {addr:02x}',
                     'RD-M @{addr:02x}',
                 ],
+                'len': lambda ctrl, addr, data: self.max_addr - addr,
             },
             0x31: {
                 'fmt': [
@@ -294,6 +308,8 @@ class Decoder(srd.Decoder):
             fmt = [fmt,]
         texts = [f.format(ctrl = ctrl, addr = addr, data = data) for f in fmt]
         length = code.get('len', None)
+        if callable(length):
+            length = length(ctrl, addr, data)
         is_proc = code.get('proc', False)
         return texts, length, is_proc
 
@@ -516,13 +532,6 @@ class Decoder(srd.Decoder):
             # The START/STOP conditions are only applicable outside of
             # "outgoing data" or "internal processing" periods. This is
             # what the data sheet specifies.
-            # TODO There is the decoder's inability to reliably detect
-            # where memory reads are done because they reached the end
-            # of the chip's capacity. Which makes the decoder miss the
-            # next START symbol, and lose synchronization to the BIT
-            # stream (bit counts are off, which breaks the accumulation
-            # of bytes). That's why this decoder unconditionally keeps
-            # detecting the START condition although it should not.
             if not is_outgoing and not is_processing:
                 if self.matched[COND_CMD_START]:
                     self.handle_command(self.samplenum, True)
@@ -530,7 +539,3 @@ class Decoder(srd.Decoder):
                 if self.matched[COND_CMD_STOP]:
                     self.handle_command(self.samplenum, False)
                     continue
-            if True: # HACK See the comment above.
-                if self.matched[COND_CMD_START]:
-                    self.handle_command(self.samplenum, True)
-                    continue