]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/avr_isp/pd.py
sdcard_spi: Define annotation rows.
[libsigrokdecode.git] / decoders / avr_isp / pd.py
index be6c1903db3ce196d9b520fb4338ee4c00f28bf0..05a46ec541295bfaaa2c88a90f05c1582a61a87b 100644 (file)
@@ -1,5 +1,5 @@
 ##
-## This file is part of the sigrok project.
+## This file is part of the libsigrokdecode project.
 ##
 ## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
 ##
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
-# AVR ISP protocol decoder
-
 import sigrokdecode as srd
-
-# Device code addresses:
-# 0x00: vendor code, 0x01: part family + flash size, 0x02: part number
-
-# Vendor code
-vendor_code = {
-    0x1e: 'Atmel',
-    0x00: 'Device locked',
-}
-
-# (Part family + flash size, part number)
-part = {
-    (0x90, 0x01): 'AT90S1200',
-    (0x91, 0x01): 'AT90S2313',
-    (0x92, 0x01): 'AT90S4414',
-    (0x92, 0x05): 'ATmega48', # 4kB flash
-    (0x93, 0x01): 'AT90S8515',
-    (0x93, 0x0a): 'ATmega88', # 8kB flash
-    (0x94, 0x06): 'ATmega168', # 16kB flash
-    (0xff, 0xff): 'Device code erased, or target missing',
-    (0x01, 0x02): 'Device locked',
-    # TODO: Lots more entries.
-}
+from .parts import *
 
 VENDOR_CODE_ATMEL = 0x1e
 
@@ -51,7 +27,7 @@ class Decoder(srd.Decoder):
     api_version = 1
     id = 'avr_isp'
     name = 'AVR ISP'
-    longname = 'AVR in-system programming'
+    longname = 'AVR In-System Programming'
     desc = 'Protocol for in-system programming Atmel AVR MCUs.'
     license = 'gplv2+'
     inputs = ['spi', 'logic']
@@ -62,8 +38,8 @@ class Decoder(srd.Decoder):
     ]
     options = {}
     annotations = [
-        ['Text', 'Human-readable text'],
-        ['Warnings', 'Human-readable warnings'],
+        ['text', 'Human-readable text'],
+        ['warnings', 'Human-readable warnings'],
     ]
 
     def __init__(self, **kwargs):
@@ -72,12 +48,9 @@ class Decoder(srd.Decoder):
         self.cmd_ss, self.cmd_es = 0, 0
         self.xx, self.yy, self.zz, self.mm = 0, 0, 0, 0
 
-    def start(self, metadata):
-        # self.out_proto = self.add(srd.OUTPUT_PROTO, 'avr_isp')
-        self.out_ann = self.add(srd.OUTPUT_ANN, 'avr_isp')
-
-    def report(self):
-        pass
+    def start(self):
+        # self.out_python = self.register(srd.OUTPUT_PYTHON)
+        self.out_ann = self.register(srd.OUTPUT_ANN)
 
     def putx(self, data):
         self.put(self.cmd_ss, self.cmd_es, self.out_ann, data)
@@ -138,9 +111,18 @@ class Decoder(srd.Decoder):
         self.xx, self.yy, self.zz, self.mm = 0, 0, 0, 0
 
     def handle_cmd_chip_erase(self, cmd, ret):
-        # TODO
+        # 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([0, ['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([1, ['Warning: Unexpected bytes in reply!']])
+
     def handle_cmd_read_fuse_bits(self, cmd, ret):
         # Read fuse bits.
         self.putx([0, ['Read fuse bits: 0x%02x' % ret[3]]])
@@ -195,13 +177,13 @@ class Decoder(srd.Decoder):
 
         self.ss, self.es = ss, es
 
+        if len(self.mosi_bytes) == 0:
+            self.cmd_ss = ss
+
         # Append new bytes.
         self.mosi_bytes.append(mosi)
         self.miso_bytes.append(miso)
 
-        if len(self.mosi_bytes) == 0:
-            self.cmd_ss = ss
-
         # All commands consist of 4 bytes.
         if len(self.mosi_bytes) < 4:
             return