]> sigrok.org Git - libsigrokdecode.git/commitdiff
adf435x: Add warning on frame size mismatch
authorVesa-Pekka Palmu <redacted>
Mon, 26 Dec 2022 17:05:18 +0000 (19:05 +0200)
committerGerhard Sittig <redacted>
Mon, 9 Jan 2023 19:10:46 +0000 (20:10 +0100)
Check the bit count of SPI transfers. Only start inspecting ADF435x
register content when the accumulation of the expected 32bit word has
completed. Emit a warning annotation for unexpected transfer sizes.

decoders/adf435x/pd.py

index 3cc74b64ea79c136d462e68cf557977908d4753e..e3d51a9d979c288dd3e953cae67986a5416c31e6 100644 (file)
@@ -86,6 +86,7 @@ regs = {
 }
 
 ANN_REG = 0
+ANN_WARN = 1
 
 class Decoder(srd.Decoder):
     api_version = 3
@@ -100,9 +101,11 @@ class Decoder(srd.Decoder):
     annotations = (
         # Sent from the host to the chip.
         ('write', 'Register write'),
+        ('warning', "Warnings"),
     )
     annotation_rows = (
         ('writes', 'Register writes', (ANN_REG,)),
+        ('warnings', 'Warnings', (ANN_WARN,)),
     )
 
     def __init__(self):
@@ -110,6 +113,7 @@ class Decoder(srd.Decoder):
 
     def reset(self):
         self.bits = []
+        self.packet_start = 0
 
     def start(self):
         self.out_ann = self.register(srd.OUTPUT_ANN)
@@ -140,7 +144,14 @@ class Decoder(srd.Decoder):
                         field_descs = regs[reg_value]
                         for field_desc in field_descs:
                             field = self.decode_field(*field_desc)
+                else:
+                    error = "Frame error: Wrong number of bits: got %d expected 32" % len(self.bits)
+                    self.put(self.packet_start, es, self.out_ann, [ANN_WARN, [error, 'Frame error']])
                 self.bits = []
+            else:
+                # Start of a new register write packet
+                self.packet_start = ss
+
         if ptype == 'BITS':
             _, mosi_bits, miso_bits = data
             self.bits = mosi_bits + self.bits