Hallo, this is my second try to contribute to the sigrok project. I found in the wiki. "Send the decoder (preferrably as a patch against the current git HEAD of libsigrokdecode) to the sigrok-devel mailing list". So I try this here.
I am working on the AVR_ISP decoder. In the first step I have replaced the number literals by some kind of enumeration as recommended on the same wiki page. Further I fixed an annotation index. The index for "programming enable" was errornously used instaed of the index for "warning". The patches for libsigrokdecode and sigroktest are attached. When these are accepted I plan to update to the new commit and provide the next patches that extend the functionality of the decoder. Best regards, Helge
decoders/avr_isp/pd.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/decoders/avr_isp/pd.py b/decoders/avr_isp/pd.py index bb52bb6..42e4682 100644 --- a/decoders/avr_isp/pd.py +++ b/decoders/avr_isp/pd.py @@ -20,6 +20,9 @@ import sigrokdecode as srd from .parts import * +class Ann: + PE, RSB0, RSB1, RSB2, CE, RFB, RHFB, REFB, WARN, DEV = range(10) + VENDOR_CODE_ATMEL = 0x1e class Decoder(srd.Decoder): @@ -46,9 +49,9 @@ class Decoder(srd.Decoder): ) annotation_rows = ( ('bits', 'Bits', ()), - ('commands', 'Commands', tuple(range(7 + 1))), - ('warnings', 'Warnings', (8,)), - ('devs', 'Devices', (9,)), + ('commands', 'Commands', tuple(range(Ann.REFB + 1))), + ('warnings', 'Warnings', (Ann.WARN + 1,)), + ('devs', 'Devices', (Ann.DEV + 1,)), ) def __init__(self): @@ -70,17 +73,17 @@ def putx(self, data): def handle_cmd_programming_enable(self, cmd, ret): # Programming enable. # Note: The chip doesn't send any ACK for 'Programming enable'. - self.putx([0, ['Programming enable']]) + self.putx([Ann.PE, ['Programming enable']]) # Sanity check on reply. if ret[1:4] != [0xac, 0x53, cmd[2]]: - self.putx([8, ['Warning: Unexpected bytes in reply!']]) + self.putx([Ann.WARN, ['Warning: Unexpected bytes in reply!']]) def handle_cmd_read_signature_byte_0x00(self, cmd, ret): # Signature byte 0x00: vendor code. self.vendor_code = ret[3] v = vendor_code[self.vendor_code] - self.putx([1, ['Vendor code: 0x%02x (%s)' % (ret[3], v)]]) + self.putx([Ann.RSB0, ['Vendor code: 0x%02x (%s)' % (ret[3], v)]]) # Store for later. self.xx = cmd[1] # Same as ret[2]. @@ -89,16 +92,16 @@ def handle_cmd_read_signature_byte_0x00(self, cmd, ret): # Sanity check on reply. if ret[1] != 0x30 or ret[2] != cmd[1]: - self.putx([8, ['Warning: Unexpected bytes in reply!']]) + self.putx([Ann.WARN, ['Warning: Unexpected bytes in reply!']]) # Sanity check for the vendor code. if self.vendor_code != VENDOR_CODE_ATMEL: - self.putx([8, ['Warning: Vendor code was not 0x1e (Atmel)!']]) + self.putx([Ann.WARN, ['Warning: Vendor code was not 0x1e (Atmel)!']]) def handle_cmd_read_signature_byte_0x01(self, cmd, ret): # Signature byte 0x01: part family and memory size. self.part_fam_flash_size = ret[3] - self.putx([2, ['Part family / memory size: 0x%02x' % ret[3]]]) + self.putx([Ann.RSB1, ['Part family / memory size: 0x%02x' % ret[3]]]) # Store for later. self.mm = cmd[3] @@ -106,20 +109,20 @@ def handle_cmd_read_signature_byte_0x01(self, cmd, ret): # Sanity check on reply. if ret[1] != 0x30 or ret[2] != cmd[1] or ret[0] != self.yy: - self.putx([8, ['Warning: Unexpected bytes in reply!']]) + self.putx([Ann.WARN, ['Warning: Unexpected bytes in reply!']]) def handle_cmd_read_signature_byte_0x02(self, cmd, ret): # Signature byte 0x02: part number. self.part_number = ret[3] - self.putx([3, ['Part number: 0x%02x' % ret[3]]]) + self.putx([Ann.RSB2, ['Part number: 0x%02x' % ret[3]]]) p = part[(self.part_fam_flash_size, self.part_number)] - data = [9, ['Device: Atmel %s' % p]] + data = [Ann.DEV, ['Device: Atmel %s' % p]] self.put(self.ss_device, self.es_cmd, self.out_ann, data) # Sanity check on reply. if ret[1] != 0x30 or ret[2] != self.xx or ret[0] != self.mm: - self.putx([8, ['Warning: Unexpected bytes in reply!']]) + self.putx([Ann.WARN, ['Warning: Unexpected bytes in reply!']]) self.xx, self.yy, self.zz, self.mm = 0, 0, 0, 0 @@ -127,32 +130,32 @@ def handle_cmd_chip_erase(self, cmd, ret): # Chip erase (erases both flash an EEPROM). # Upon successful chip erase, the lock bits will also be erased. # The only way to end a Chip Erase cycle is to release RESET#. - self.putx([4, ['Chip erase']]) + self.putx([Ann.CE, ['Chip erase']]) # TODO: Check/handle RESET#. # Sanity check on reply. bit = (ret[2] & (1 << 7)) >> 7 if ret[1] != 0xac or bit != 1 or ret[3] != cmd[2]: - self.putx([8, ['Warning: Unexpected bytes in reply!']]) + self.putx([Ann.WARN, ['Warning: Unexpected bytes in reply!']]) def handle_cmd_read_fuse_bits(self, cmd, ret): # Read fuse bits. - self.putx([5, ['Read fuse bits: 0x%02x' % ret[3]]]) + self.putx([Ann.RFB, ['Read fuse bits: 0x%02x' % ret[3]]]) # TODO: Decode fuse bits. # TODO: Sanity check on reply. def handle_cmd_read_fuse_high_bits(self, cmd, ret): # Read fuse high bits. - self.putx([6, ['Read fuse high bits: 0x%02x' % ret[3]]]) + self.putx([Ann.RHFB, ['Read fuse high bits: 0x%02x' % ret[3]]]) # TODO: Decode fuse bits. # TODO: Sanity check on reply. def handle_cmd_read_extended_fuse_bits(self, cmd, ret): # Read extended fuse bits. - self.putx([7, ['Read extended fuse bits: 0x%02x' % ret[3]]]) + self.putx([Ann.REFB, ['Read extended fuse bits: 0x%02x' % ret[3]]]) # TODO: Decode fuse bits. # TODO: Sanity check on reply. @@ -177,7 +180,7 @@ def handle_command(self, cmd, ret): else: c = '%02x %02x %02x %02x' % tuple(cmd) r = '%02x %02x %02x %02x' % tuple(ret) - self.putx([0, ['Unknown command: %s (reply: %s)!' % (c, r)]]) + self.putx([Ann.WARN, ['Unknown command: %s (reply: %s)!' % (c, r)]]) def decode(self, ss, es, data): ptype, mosi, miso = data
decoder/test/avr_isp/atmega88_erase_chip.output | 8 ++++---- decoder/test/avr_isp/atmega88_read_lfuse.output | 8 ++++---- decoder/test/avr_isp/atmega88_scan.output | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/decoder/test/avr_isp/atmega88_erase_chip.output b/decoder/test/avr_isp/atmega88_erase_chip.output index 39b06ca..5e0e120 100644 --- a/decoder/test/avr_isp/atmega88_erase_chip.output +++ b/decoder/test/avr_isp/atmega88_erase_chip.output @@ -13,10 +13,10 @@ 5264650-5265998 avr_isp: refb: "Read extended fuse bits: 0xf9" 5281330-5282678 avr_isp: refb: "Read extended fuse bits: 0xf9" 5297338-5298687 avr_isp: refb: "Read extended fuse bits: 0xf9" -5312699-5314048 avr_isp: pe: "Unknown command: a0 01 fc 00 (reply: 00 a0 01 ff)!" -5329353-5330702 avr_isp: pe: "Unknown command: a0 01 fd 00 (reply: 00 a0 01 ff)!" -5344691-5346042 avr_isp: pe: "Unknown command: a0 01 fe 00 (reply: 00 a0 01 ff)!" -5360931-5362282 avr_isp: pe: "Unknown command: a0 01 ff 00 (reply: 00 a0 01 ff)!" +5312699-5314048 avr_isp: warning: "Unknown command: a0 01 fc 00 (reply: 00 a0 01 ff)!" +5329353-5330702 avr_isp: warning: "Unknown command: a0 01 fd 00 (reply: 00 a0 01 ff)!" +5344691-5346042 avr_isp: warning: "Unknown command: a0 01 fe 00 (reply: 00 a0 01 ff)!" +5360931-5362282 avr_isp: warning: "Unknown command: a0 01 ff 00 (reply: 00 a0 01 ff)!" 5376907-5378241 avr_isp: ce: "Chip erase" 5674961-5676308 avr_isp: pe: "Programming enable" 5674961-5676308 avr_isp: warning: "Warning: Unexpected bytes in reply!" diff --git a/decoder/test/avr_isp/atmega88_read_lfuse.output b/decoder/test/avr_isp/atmega88_read_lfuse.output index 39aa88f..86da65f 100644 --- a/decoder/test/avr_isp/atmega88_read_lfuse.output +++ b/decoder/test/avr_isp/atmega88_read_lfuse.output @@ -13,10 +13,10 @@ 6026034-6027382 avr_isp: refb: "Read extended fuse bits: 0xf9" 6041368-6042716 avr_isp: refb: "Read extended fuse bits: 0xf9" 6057592-6058940 avr_isp: refb: "Read extended fuse bits: 0xf9" -6073389-6074740 avr_isp: pe: "Unknown command: a0 01 fc 00 (reply: 00 a0 01 ff)!" -6090091-6091442 avr_isp: pe: "Unknown command: a0 01 fd 00 (reply: 00 a0 01 ff)!" -6106091-6107442 avr_isp: pe: "Unknown command: a0 01 fe 00 (reply: 00 a0 01 ff)!" -6121409-6122760 avr_isp: pe: "Unknown command: a0 01 ff 00 (reply: 00 a0 01 ff)!" +6073389-6074740 avr_isp: warning: "Unknown command: a0 01 fc 00 (reply: 00 a0 01 ff)!" +6090091-6091442 avr_isp: warning: "Unknown command: a0 01 fd 00 (reply: 00 a0 01 ff)!" +6106091-6107442 avr_isp: warning: "Unknown command: a0 01 fe 00 (reply: 00 a0 01 ff)!" +6121409-6122760 avr_isp: warning: "Unknown command: a0 01 ff 00 (reply: 00 a0 01 ff)!" 6138099-6139448 avr_isp: rfb: "Read fuse bits: 0xff" 6153440-6154789 avr_isp: rfb: "Read fuse bits: 0xff" 6170107-6171456 avr_isp: rfb: "Read fuse bits: 0xff" diff --git a/decoder/test/avr_isp/atmega88_scan.output b/decoder/test/avr_isp/atmega88_scan.output index 4369f69..b26abdd 100644 --- a/decoder/test/avr_isp/atmega88_scan.output +++ b/decoder/test/avr_isp/atmega88_scan.output @@ -13,10 +13,10 @@ 6604121-6605470 avr_isp: refb: "Read extended fuse bits: 0xf9" 6620800-6622149 avr_isp: refb: "Read extended fuse bits: 0xf9" 6636153-6637502 avr_isp: refb: "Read extended fuse bits: 0xf9" -6652190-6653540 avr_isp: pe: "Unknown command: a0 01 fc 00 (reply: 00 a0 01 ff)!" -6668387-6669738 avr_isp: pe: "Unknown command: a0 01 fd 00 (reply: 00 a0 01 ff)!" -6684163-6685514 avr_isp: pe: "Unknown command: a0 01 fe 00 (reply: 00 a0 01 ff)!" -6700843-6702194 avr_isp: pe: "Unknown command: a0 01 ff 00 (reply: 00 a0 01 ff)!" +6652190-6653540 avr_isp: warning: "Unknown command: a0 01 fc 00 (reply: 00 a0 01 ff)!" +6668387-6669738 avr_isp: warning: "Unknown command: a0 01 fd 00 (reply: 00 a0 01 ff)!" +6684163-6685514 avr_isp: warning: "Unknown command: a0 01 fe 00 (reply: 00 a0 01 ff)!" +6700843-6702194 avr_isp: warning: "Unknown command: a0 01 ff 00 (reply: 00 a0 01 ff)!" 6716410-6717759 avr_isp: rfb: "Read fuse bits: 0xff" 6732620-6733969 avr_isp: rfb: "Read fuse bits: 0xff" 6748623-6749972 avr_isp: rfb: "Read fuse bits: 0xff"
_______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel