annotate py_avrjtag/cmd_proto.py @ 13:1ea479d26fce tip

Make sure shifting phase and add bypass.py. - shifting phase is started after entering SHIFT state Transition from CAP to SHIFT does not induce shifting. - shifting phase is stoped after leaving SHIFT state. Transition from SHIFT to EXIT1 also induce a bit of shifting.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 25 Feb 2009 20:08:29 +0800
parents cc106f278d7d
children
rev   line source
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 import struct
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 CPCMD_PING = 1
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 CPCMD_SHIFT_TDI = 2
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 CPCMD_SHIFT_TMS = 3
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 CPCMD_SHIFT_TDI_TDO = 4
7
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
7 CPCMD_TRST = 5
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
8 CPCMD_PONG = 6
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
9 CPCMD_DATA = 7
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
10 CPCMD_ACK = 8
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
11 CPCMD_NAK = 9
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 def csum_add(csum, c):
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 return (((csum << 3) | (csum >> 5)) ^ c) & 0xff
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 class cmd(object):
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 OFF_SEQ = 2
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 OFF_DSZ = 3
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 OFF_CODE = 4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 FRAME_OVERHEAD = 5
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 def __init__(self, seq=0, code=0, data=''):
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
23 if len(data) >= 255:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
24 raise ValueError, 'data length (%d) >= 255' % (len(data))
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 self.seq = seq
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 self.code = code
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 self.data = data
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 pass
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 def to_frame(self):
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 csum = 0
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 csum = csum_add(0, self.code)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 for c in self.data:
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 csum = csum_add(csum, ord(c))
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 pass
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 csum = csum_add(csum, 0)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 frame = struct.pack('BBBBB', ord('J'), ord('C'), self.seq,
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 len(self.data) + 1, self.code)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 frame = frame + self.data + chr(csum)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 return frame
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 def from_frame(self, frame):
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 if frame[:2] != 'JC':
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 return -1
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 csum = 0
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 for c in frame[self.OFF_CODE:]:
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 csum = csum_add(csum, ord(c))
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 pass
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 if csum:
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 return -1
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 data_sz = ord(frame[self.OFF_DSZ])
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 if data_sz != (len(frame) - self.FRAME_OVERHEAD):
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 return -1
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 if not data_sz:
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 return -1
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 self.seq = ord(frame[self.OFF_SEQ])
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 self.code = ord(frame[self.OFF_CODE])
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 self.data = frame[self.OFF_CODE + 1:-1]
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 pass
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 def __repr__(self):
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 return '<%s {seq: %d, code: %d, data: %s}>' % \
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 (self.__class__.__name__, self.seq, self.code, repr(self.data))
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 pass
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
71 def prepend_nbits(nbits, data):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
72 r = chr(nbits & 0xff) + chr(nbits >> 8) + data
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
73 return r