r4649 - in developers/werner/ahrt/host/tmc: . demo lib
werner at docs.openmoko.org
werner at docs.openmoko.org
Tue Sep 16 05:02:47 CEST 2008
Author: werner
Date: 2008-09-16 05:02:47 +0200 (Tue, 16 Sep 2008)
New Revision: 4649
Added:
developers/werner/ahrt/host/tmc/lib/crc.py
Modified:
developers/werner/ahrt/host/tmc/demo/dxplore.py
developers/werner/ahrt/host/tmc/lib/decode.py
developers/werner/ahrt/host/tmc/setup.py
Log:
Highlights:
- added CRC7 checking and SDIO R5 SPI response decoding
- more decoding bugs fixed
Details:
- lib/crc.py (crc): CRC7 and CRC16 calculation
- lib/decode.py (d_sdio_cmd, d_crc7_msb): verify CRC7 in SDIO commands
- lib/decode.py (d_sdio_r5_spi): decoder for SDIO R5 response in SPI mode
- lib/decode.py (d_sdio_cmd): flag undefined start and stop bits
- lib/decode.py (decode_address): CIS pointer length is three bytes, not just
one
- lib/decode.py (decode_address): added decoding of Function Basic Registers
one
- lib/decode.py (d_sdio_cmd): unknown arguments were incorrectly treated as
invalid
- demo/dxplore.py: digitizing the analog wave is a waste of time
Modified: developers/werner/ahrt/host/tmc/demo/dxplore.py
===================================================================
--- developers/werner/ahrt/host/tmc/demo/dxplore.py 2008-09-16 02:58:24 UTC (rev 4648)
+++ developers/werner/ahrt/host/tmc/demo/dxplore.py 2008-09-16 03:02:47 UTC (rev 4649)
@@ -27,21 +27,21 @@
w.load(argv[1])
dig = []
-for wv in w:
+for wv in w[1:]:
dig.append(wv.digitize(0.5))
-min = dig[1].sample_step()
-for d in dig[2:]:
+min = dig[0].sample_step()
+for d in dig[1:]:
step = d.sample_step()
if step is not None and step < min:
min = step
da = []
-for d in dig[1:]:
+for d in dig:
a = d.sample(min)
# print len(a)
if len(a) >= 1500:
da.append(a)
da.reverse()
-dxplore(da, dig[1].start(), min, argv[1])
+dxplore(da, dig[0].start(), min, argv[1])
Added: developers/werner/ahrt/host/tmc/lib/crc.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/crc.py (rev 0)
+++ developers/werner/ahrt/host/tmc/lib/crc.py 2008-09-16 03:02:47 UTC (rev 4649)
@@ -0,0 +1,91 @@
+#
+# crc.py - CRC calculation
+#
+# This source code is licensed under the GNU General Public License,
+# Version 2. See the file COPYING for more details.
+#
+# From the Linux kernel, lib/crc7.c, include/linux/crc7.h, lib/crc16.c,
+# and include/linux/crc16.h
+#
+
+class crc:
+
+ # Table for CRC-7 (polynomial x^7 + x^3 + 1)
+
+ crc7_syndrome = (
+ 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f,
+ 0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77,
+ 0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26,
+ 0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e,
+ 0x32, 0x3b, 0x20, 0x29, 0x16, 0x1f, 0x04, 0x0d,
+ 0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45,
+ 0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14,
+ 0x63, 0x6a, 0x71, 0x78, 0x47, 0x4e, 0x55, 0x5c,
+ 0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b,
+ 0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13,
+ 0x7d, 0x74, 0x6f, 0x66, 0x59, 0x50, 0x4b, 0x42,
+ 0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a,
+ 0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69,
+ 0x1e, 0x17, 0x0c, 0x05, 0x3a, 0x33, 0x28, 0x21,
+ 0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70,
+ 0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38,
+ 0x41, 0x48, 0x53, 0x5a, 0x65, 0x6c, 0x77, 0x7e,
+ 0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36,
+ 0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67,
+ 0x10, 0x19, 0x02, 0x0b, 0x34, 0x3d, 0x26, 0x2f,
+ 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c,
+ 0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04,
+ 0x6a, 0x63, 0x78, 0x71, 0x4e, 0x47, 0x5c, 0x55,
+ 0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d,
+ 0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a,
+ 0x6d, 0x64, 0x7f, 0x76, 0x49, 0x40, 0x5b, 0x52,
+ 0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03,
+ 0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b,
+ 0x17, 0x1e, 0x05, 0x0c, 0x33, 0x3a, 0x21, 0x28,
+ 0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60,
+ 0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31,
+ 0x46, 0x4f, 0x54, 0x5d, 0x62, 0x6b, 0x70, 0x79 )
+
+ crc16_syndrome = (
+ 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
+ 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
+ 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
+ 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
+ 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
+ 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
+ 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
+ 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
+ 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
+ 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
+ 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
+ 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
+ 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
+ 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
+ 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
+ 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
+ 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
+ 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
+ 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
+ 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
+ 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
+ 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
+ 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
+ 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
+ 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
+ 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
+ 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
+ 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
+ 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
+ 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
+ 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
+ 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 )
+
+ def crc7(self, crc, bytes):
+ for b in bytes:
+ crc = self.crc7_syndrome[(crc << 1) ^ b]
+ return crc
+
+ def crc16(self, crc, bytes):
+ for b in bytes(crc, bytes):
+ crc = (crc >> 8) ^ self.crc16_syndrome[(crc ^ b) & 0xff]
+ return crc
Modified: developers/werner/ahrt/host/tmc/lib/decode.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/decode.py 2008-09-16 02:58:24 UTC (rev 4648)
+++ developers/werner/ahrt/host/tmc/lib/decode.py 2008-09-16 03:02:47 UTC (rev 4649)
@@ -1,6 +1,25 @@
-#!/usr/bin/python
+#
+# decode.py - Data stream decoders
+#
+# Copyright (C) 2008 by OpenMoko, Inc.
+# Written by Werner Almesberger <werner at openmoko.org>
+# All Rights Reserved
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+import tmc.crc
+
+
+# One CRC instance can be shared by all decoders
+
+g_crc = tmc.crc.crc()
+
+
def d_bits(bits):
s = ""
for b in bits:
@@ -52,13 +71,25 @@
def decode_address(addr):
+
+ # CCCR
if addr < 0x14:
return (
"Rev", "SDR", "IOE", "IOR",
"IEN", "INT", "Abr", "Bus",
- "Cap", "CIS", "Sus", "Sel",
- "EXF", "RDY", "BSZ", "BSZ",
- "PWR", "HSp")[addr]
+ "Cap", "CIS", "CIS", "CIS",
+ "Sus", "Sel", "EXF", "RDY",
+ "BSZ", "BSZ", "PWR", "HSp")[addr]
+
+ # FBR
+ if addr >= 0x100 and addr < 0x800 and (addr & 0xff) < 0x112:
+ return ("F%d" % (addr >> 8))+(
+ "FIC", "EFC", "Pwr", "RFU",
+ "RFU", "RFU", "RFU", "RFU",
+ "RFU", "CIS", "CIS", "CIS",
+ "CSA", "CSA", "CSA", "DCA",
+ "BSZ", "BSZ")[addr & 0xff]
+
return None
@@ -95,6 +126,18 @@
return None
+def d_crc7_msb(payload):
+ crc = 0
+ while len(payload):
+ v = 0
+ for b in range(0, 8):
+ if payload[0] == "X":
+ return None
+ v = (v << 1) | payload.pop(0)
+ crc = g_crc.crc7(crc, [v])
+ return crc
+
+
def d_sdio_cmd(bits, stop = False):
if bits[0]:
s = "~"
@@ -104,6 +147,12 @@
while len(bits) and bits[0]:
del bits[0]
+ # We access the payload as soon as the CRC has been read, but possibly
+ # before we also have the stop bit.
+
+ if len(bits) >= 47:
+ payload = bits[0:40]
+
if len(bits) == 0:
return s
s += "["
@@ -111,7 +160,7 @@
if len(bits) == 0:
return s
- if bits[0]:
+ if bits[0] and bits[0] != "X":
s += ">"
else:
s += "?"
@@ -138,15 +187,15 @@
return s+"("+d_byte_msb(bits)
arg = d_msb(bits[0:32])
if cmd is None or arg is None:
- arg = None
+ arg_pretty = None
else:
- arg = decode_arg(cmd, arg)
- if arg is None:
- s += "("+d_byte_msb(bits)+")"
- if stop:
+ arg_pretty = decode_arg(cmd, arg)
+ if arg_pretty is None:
+ s += "("+d_byte_msb(bits[0:32])+")"
+ if stop and arg is None:
return s
else:
- s += "("+arg+")"
+ s += "("+arg_pretty+")"
del bits[0:32]
if len(bits) == 0:
@@ -159,12 +208,20 @@
if stop:
return s
else:
- s += "CRC%02x" % crc
+ s += "CRC%02X" % crc
+ check = d_crc7_msb(payload)
+ if check is None:
+ s += "?"
+ elif check != crc:
+ s += "/%02X" % check
del bits[0:7]
if len(bits) == 0:
return s
- s += ("?", "]")[bits[0]]
+ if bits[0] and bits[0] != "X":
+ s += "]"
+ else:
+ s += "?"
del bits[0]
if stop:
@@ -184,6 +241,89 @@
return "SDIO"
+def d_sdio_r5_spi(bits, stop = False):
+ if bits[0]:
+ s = "~"
+ else:
+ s = ""
+
+ while len(bits) and bits[0]:
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ s += "["
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ if bits[0]:
+ s += "Prm"
+ else:
+ s += "-"
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ if bits[0]:
+ s += "???"
+ if stop:
+ return s
+ else:
+ s += "-"
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ if bits[0]:
+ s += "Fn#"
+ else:
+ s += "-"
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ if bits[0]:
+ s += "Crc"
+ else:
+ s += "-"
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ if bits[0]:
+ s += "Cmd"
+ else:
+ s += "-"
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ if bits[0]:
+ s += "???"
+ if stop:
+ return s
+ else:
+ s += "-"
+ del bits[0]
+
+ if len(bits) == 0:
+ return s
+ if bits[0]:
+ s += "Idl"
+ else:
+ s += "-"
+ del bits[0]
+
+ s += d_byte_msb(bits[0:8])
+ if len(bits) >= 8:
+ s += "]"
+ if len(bits) > 8 and not stop:
+ s += "|"+d_bits(bits[8:])
+
+ return s
+
+
decoders = [
# 0123456789abcdef -- maximum length is 16 characters
( "LSB->MSB", d_byte_lsb ),
@@ -191,4 +331,5 @@
( "SDIO CMD", d_sdio_cmd ),
( "SDIO RESP (SD)", d_sdio_resp_sd ),
( "SDIO RESP (SPI)", d_sdio_resp_spi ),
+ ( "SDIO R5 (SPI)", d_sdio_r5_spi ),
]
Modified: developers/werner/ahrt/host/tmc/setup.py
===================================================================
--- developers/werner/ahrt/host/tmc/setup.py 2008-09-16 02:58:24 UTC (rev 4648)
+++ developers/werner/ahrt/host/tmc/setup.py 2008-09-16 03:02:47 UTC (rev 4649)
@@ -5,7 +5,7 @@
description = "Test and Measurement Control",
py_modules = [ "tmc.instrument",
"tmc.wave", "tmc.trigger", "tmc.shape",
- "tmc.decode", "tmc.dxplore",
+ "tmc.crc", "tmc.decode", "tmc.dxplore",
"tmc.meter", "tmc.scope", "tmc.power", "tmc.function" ],
package_dir = { "tmc": "lib" },
ext_modules = [
More information about the commitlog
mailing list