]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/mx25lxx05d/mx25lxx05d.py
srd: mx25lxx05d: Add empty handlers for TODO cmds.
[libsigrokdecode.git] / decoders / mx25lxx05d / mx25lxx05d.py
index f3c74efcc74aebd51143df03d1995bc0ed918f79..b979f6886c736c71ec15761b7489db44528f8051 100644 (file)
@@ -32,7 +32,7 @@ cmds = {
     0x05: ('RDSR', 'Read status register'),
     0x01: ('WRSR', 'Write status register'),
     0x03: ('READ', 'Read data'),
-    0x0b: ('FAST_READ', 'Fast read data'),
+    0x0b: ('FAST/READ', 'Fast read data'),
     0xbb: ('2READ', '2x I/O read'),
     0x20: ('SE', 'Sector erase'),
     0xd8: ('BE', 'Block erase'),
@@ -41,9 +41,7 @@ cmds = {
     0x02: ('PP', 'Page program'),
     0xad: ('CP', 'Continuously program mode'),
     0xb9: ('DP', 'Deep power down'),
-    # 0xab: ('RDP', 'Release from deep powerdown'),
-    # 0xab: ('RES', 'Read electronic ID'),
-    0xab: ('RDP_RES', 'Release from deep powerdown / Read electronic ID'),
+    0xab: ('RDP/RES', 'Release from deep powerdown / Read electronic ID'),
     0x90: ('REMS', 'Read electronic manufacturer & device ID'),
     0xef: ('REMS2', 'Read ID for 2x I/O mode'),
     0xb1: ('ENSO', 'Enter secured OTP'),
@@ -99,14 +97,14 @@ class Decoder(srd.Decoder):
         {'id': 'hold', 'name': 'HOLD#', 'desc': 'TODO.'},
         {'id': 'wp_acc', 'name': 'WP#/ACC', 'desc': 'TODO.'},
     ]
-    options = {} # TODO
+    options = {}
     annotations = [
         ['Text', 'Human-readable text'],
     ]
 
     def __init__(self, **kwargs):
         self.state = None
-        self.cmdstate = 1 # TODO
+        self.cmdstate = 1
         self.addr = 0
         self.data = []
 
@@ -122,15 +120,18 @@ class Decoder(srd.Decoder):
         self.put(self.ss, self.es, self.out_ann, data)
 
     def handle_wren(self, mosi, miso):
-        self.putx([0, ['Command: %s' % cmds[self.cmd][1]]])
+        self.putx([0, ['Command: %s' % cmds[self.state][1]]])
         self.state = None
 
+    def handle_wrdi(self, mosi, miso):
+        pass # TODO
+
     # TODO: Check/display device ID / name
     def handle_rdid(self, mosi, miso):
         if self.cmdstate == 1:
             # Byte 1: Master sends command ID.
             self.start_sample = self.ss
-            self.putx([0, ['Command: %s' % cmds[self.cmd][1]]])
+            self.putx([0, ['Command: %s' % cmds[self.state][1]]])
         elif self.cmdstate == 2:
             # Byte 2: Slave sends the JEDEC manufacturer ID.
             self.putx([0, ['Manufacturer ID: 0x%02x' % miso]])
@@ -151,6 +152,66 @@ class Decoder(srd.Decoder):
         else:
             self.cmdstate += 1
 
+    def handle_rdsr(self, mosi, miso):
+        # Read status register: Master asserts CS#, sends RDSR command,
+        # reads status register byte. If CS# is kept asserted, the status
+        # register can be read continuously / multiple times in a row.
+        # When done, the master de-asserts CS# again.
+        if self.cmdstate == 1:
+            # Byte 1: Master sends command ID.
+            self.putx([0, ['Command: %s' % cmds[self.state][1]]])
+        elif self.cmdstate >= 2:
+            # Bytes 2-x: Slave sends status register as long as master clocks.
+            if self.cmdstate <= 3: # TODO: While CS# asserted.
+                self.putx([0, ['Status register: 0x%02x' % miso]])
+                self.putx([0, [decode_status_reg(miso)]])
+
+            if self.cmdstate == 3: # TODO: If CS# got de-asserted.
+                self.state = None
+                return
+
+        self.cmdstate += 1
+
+    def handle_wrsr(self, mosi, miso):
+        pass # TODO
+
+    def handle_read(self, mosi, miso):
+        # Read data bytes: Master asserts CS#, sends READ command, sends
+        # 3-byte address, reads >= 1 data bytes, de-asserts CS#.
+        if self.cmdstate == 1:
+            # Byte 1: Master sends command ID.
+            self.putx([0, ['Command: %s' % cmds[self.state][1]]])
+        elif self.cmdstate in (2, 3, 4):
+            # Bytes 2/3/4: Master sends read address (24bits, MSB-first).
+            self.addr |= (mosi << ((4 - self.cmdstate) * 8))
+            # self.putx([0, ['Read address, byte %d: 0x%02x' % \
+            #                (4 - self.cmdstate, mosi)]])
+            if self.cmdstate == 4:
+                self.putx([0, ['Read address: 0x%06x' % self.addr]])
+                self.addr = 0
+        elif self.cmdstate >= 5:
+            # Bytes 5-x: Master reads data bytes (until CS# de-asserted).
+            # TODO: For now we hardcode 256 bytes per READ command.
+            if self.cmdstate <= 256 + 4: # TODO: While CS# asserted.
+                self.data.append(miso)
+                # self.putx([0, ['New read byte: 0x%02x' % miso]])
+
+            if self.cmdstate == 256 + 4: # TODO: If CS# got de-asserted.
+                # s = ', '.join(map(hex, self.data))
+                s = ''.join(map(chr, self.data))
+                self.putx([0, ['Read data: %s' % s]])
+                self.data = []
+                self.state = None
+                return
+
+        self.cmdstate += 1
+
+    def handle_fast_read(self, mosi, miso):
+        pass # TODO
+
+    def handle_2read(self, mosi, miso):
+        pass # TODO
+
     # TODO: Warn/abort if we don't see the necessary amount of bytes.
     # TODO: Warn if WREN was not seen before.
     def handle_se(self, mosi, miso):
@@ -158,7 +219,7 @@ class Decoder(srd.Decoder):
             # Byte 1: Master sends command ID.
             self.addr = 0
             self.start_sample = self.ss
-            self.putx([0, ['Command: %s' % cmds[self.cmd][1]]])
+            self.putx([0, ['Command: %s' % cmds[self.state][1]]])
         elif self.cmdstate in (2, 3, 4):
             # Bytes 2/3/4: Master sends sectror address (24bits, MSB-first).
             self.addr |= (mosi << ((4 - self.cmdstate) * 8))
@@ -177,11 +238,60 @@ class Decoder(srd.Decoder):
         else:
             self.cmdstate += 1
 
+    def handle_be(self, mosi, miso):
+        pass # TODO
+
+    def handle_ce(self, mosi, miso):
+        pass # TODO
+
+    def handle_ce2(self, mosi, miso):
+        pass # TODO
+
+    def handle_pp(self, mosi, miso):
+        # Page program: Master asserts CS#, sends PP command, sends 3-byte
+        # page address, sends >= 1 data bytes, de-asserts CS#.
+        if self.cmdstate == 1:
+            # Byte 1: Master sends command ID.
+            self.putx([0, ['Command: %s' % cmds[self.state][1]]])
+        elif self.cmdstate in (2, 3, 4):
+            # Bytes 2/3/4: Master sends page address (24bits, MSB-first).
+            self.addr |= (mosi << ((4 - self.cmdstate) * 8))
+            # self.putx([0, ['Page address, byte %d: 0x%02x' % \
+            #                (4 - self.cmdstate, mosi)]])
+            if self.cmdstate == 4:
+                self.putx([0, ['Page address: 0x%06x' % self.addr]])
+                self.addr = 0
+        elif self.cmdstate >= 5:
+            # Bytes 5-x: Master sends data bytes (until CS# de-asserted).
+            # TODO: For now we hardcode 256 bytes per page / PP command.
+            if self.cmdstate <= 256 + 4: # TODO: While CS# asserted.
+                self.data.append(mosi)
+                # self.putx([0, ['New data byte: 0x%02x' % mosi]])
+
+            if self.cmdstate == 256 + 4: # TODO: If CS# got de-asserted.
+                # s = ', '.join(map(hex, self.data))
+                s = ''.join(map(chr, self.data))
+                self.putx([0, ['Page data: %s' % s]])
+                self.data = []
+                self.state = None
+                return
+
+        self.cmdstate += 1
+
+    def handle_cp(self, mosi, miso):
+        pass # TODO
+
+    def handle_dp(self, mosi, miso):
+        pass # TODO
+
+    def handle_rdp_res(self, mosi, miso):
+        pass # TODO
+
     def handle_rems(self, mosi, miso):
         if self.cmdstate == 1:
             # Byte 1: Master sends command ID.
             self.start_sample = self.ss
-            self.putx([0, ['Command: %s' % cmds[self.cmd][1]]])
+            self.putx([0, ['Command: %s' % cmds[self.state][1]]])
         elif self.cmdstate in (2, 3):
             # Bytes 2/3: Master sends two dummy bytes.
             # TODO: Check dummy bytes? Check reply from device?
@@ -203,9 +313,6 @@ class Decoder(srd.Decoder):
             self.ids.append(miso)
             d = 'Manufacturer' if self.manufacturer_id_first else 'Device'
             self.putx([0, ['%s ID' % d]])
-        else:
-            # TODO: Error?
-            pass
 
         if self.cmdstate == 6:
             self.end_sample = self.es
@@ -215,124 +322,56 @@ class Decoder(srd.Decoder):
         else:
             self.cmdstate += 1
 
-    def handle_rdsr(self, mosi, miso):
-        # Read status register: Master asserts CS#, sends RDSR command,
-        # reads status register byte. If CS# is kept asserted, the status
-        # register can be read continuously / multiple times in a row.
-        # When done, the master de-asserts CS# again.
-        if self.cmdstate == 1:
-            # Byte 1: Master sends command ID.
-            self.putx([0, ['Command: %s' % cmds[self.cmd][1]]])
-        elif self.cmdstate >= 2:
-            # Bytes 2-x: Slave sends status register as long as master clocks.
-            if self.cmdstate <= 3: # TODO: While CS# asserted.
-                self.putx([0, ['Status register: 0x%02x' % miso]])
-                self.putx([0, [decode_status_reg(miso)]])
+    def handle_rems2(self, mosi, miso):
+        pass # TODO
 
-            if self.cmdstate == 3: # TODO: If CS# got de-asserted.
-                self.state = None
-                return
+    def handle_enso(self, mosi, miso):
+        pass # TODO
 
-        self.cmdstate += 1
+    def handle_exso(self, mosi, miso):
+        pass # TODO
 
-    def handle_pp(self, mosi, miso):
-        # Page program: Master asserts CS#, sends PP command, sends 3-byte
-        # page address, sends >= 1 data bytes, de-asserts CS#.
-        if self.cmdstate == 1:
-            # Byte 1: Master sends command ID.
-            self.putx([0, ['Command: %s' % cmds[self.cmd][1]]])
-        elif self.cmdstate in (2, 3, 4):
-            # Bytes 2/3/4: Master sends page address (24bits, MSB-first).
-            self.addr |= (mosi << ((4 - self.cmdstate) * 8))
-            # self.putx([0, ['Page address, byte %d: 0x%02x' % \
-            #                (4 - self.cmdstate, mosi)]])
-            if self.cmdstate == 4:
-                self.putx([0, ['Page address: 0x%06x' % self.addr]])
-                self.addr = 0
-        elif self.cmdstate >= 5:
-            # Bytes 5-x: Master sends data bytes (until CS# de-asserted).
-            # TODO: For now we hardcode 256 bytes per page / PP command.
-            if self.cmdstate <= 256 + 4: # TODO: While CS# asserted.
-                self.data.append(mosi)
-                # self.putx([0, ['New data byte: 0x%02x' % mosi]])
-
-            if self.cmdstate == 256 + 4: # TODO: If CS# got de-asserted.
-                # s = ', '.join(map(hex, self.data))
-                s = ''.join(map(chr, self.data))
-                self.putx([0, ['Page data: %s' % s]])
-                self.data = []
-                self.state = None
-                return
-
-        self.cmdstate += 1
+    def handle_rdscur(self, mosi, miso):
+        pass # TODO
 
-    def handle_read(self, mosi, miso):
-        # Read data bytes: Master asserts CS#, sends READ command, sends
-        # 3-byte address, reads >= 1 data bytes, de-asserts CS#.
-        if self.cmdstate == 1:
-            # Byte 1: Master sends command ID.
-            self.putx([0, ['Command: %s' % cmds[self.cmd][1]]])
-        elif self.cmdstate in (2, 3, 4):
-            # Bytes 2/3/4: Master sends read address (24bits, MSB-first).
-            self.addr |= (mosi << ((4 - self.cmdstate) * 8))
-            # self.putx([0, ['Read address, byte %d: 0x%02x' % \
-            #                (4 - self.cmdstate, mosi)]])
-            if self.cmdstate == 4:
-                self.putx([0, ['Read address: 0x%06x' % self.addr]])
-                self.addr = 0
-        elif self.cmdstate >= 5:
-            # Bytes 5-x: Master reads data bytes (until CS# de-asserted).
-            # TODO: For now we hardcode 256 bytes per READ command.
-            if self.cmdstate <= 256 + 4: # TODO: While CS# asserted.
-                self.data.append(miso)
-                # self.putx([0, ['New read byte: 0x%02x' % miso]])
+    def handle_wrscur(self, mosi, miso):
+        pass # TODO
 
-            if self.cmdstate == 256 + 4: # TODO: If CS# got de-asserted.
-                # s = ', '.join(map(hex, self.data))
-                s = ''.join(map(chr, self.data))
-                self.putx([0, ['Read data: %s' % s]])
-                self.data = []
-                self.state = None
-                return
+    def handle_esry(self, mosi, miso):
+        pass # TODO
 
-        self.cmdstate += 1
+    def handle_dsry(self, mosi, miso):
+        pass # TODO
 
     def decode(self, ss, es, data):
 
         ptype, mosi, miso = data
 
         # if ptype == 'DATA':
-        #     s = 'MOSI: 0x%02x, MISO: 0x%02x' % (mosi, miso)
-        #     self.put(0, 0, self.out_ann, [0, [s]])
-        #     pass
+        #     self.putx([0, ['MOSI: 0x%02x, MISO: 0x%02x' % (mosi, miso)]])
 
         # if ptype == 'CS-CHANGE':
         #     if mosi == 1 and miso == 0:
-        #         self.put(0, 0, self.out_ann, [0, ['Asserting CS#']])
+        #         self.putx([0, ['Asserting CS#']])
         #     elif mosi == 0 and miso == 1:
-        #         self.put(0, 0, self.out_ann, [0, ['De-asserting CS#']])
-        #     return
+        #         self.putx([0, ['De-asserting CS#']])
 
         if ptype != 'DATA':
             return
 
-        cmd = mosi
         self.ss, self.es = ss, es
 
         # If we encountered a known chip command, enter the resp. state.
         if self.state == None:
-            if cmd in cmds:
-                self.state = cmd
-                self.cmd = cmd # TODO: Eliminate?
-                self.cmdstate = 1
-            else:
-                pass # TODO
+            self.state = mosi
+            self.cmdstate = 1
 
         # Handle commands.
-        if self.state in cmds.keys():
-            handle_reg = getattr(self, 'handle_%s' % cmds[self.cmd][0].lower())
+        if self.state in cmds:
+            s = 'handle_%s' % cmds[self.state][0].lower().replace('/', '_')
+            handle_reg = getattr(self, s)
             handle_reg(mosi, miso)
         else:
-            self.put(0, 0, self.out_ann, [0, ['Unknown command: 0x%02x' % cmd]])
+            self.putx([0, ['Unknown command: 0x%02x' % mosi]])
             self.state = None