annotate py_avrjtag/jtagdev.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 68ecd42850d3
children
rev   line source
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 import tms_ptns
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 import cmd_proto
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
11
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
4 debug_frame = 0
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
5
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
6 def dump_frame(frame):
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
7 r = ''
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
8 for c in frame:
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
9 r = r + ('%02x ' % (ord(c)))
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
10 pass
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
11 print r
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
12 pass
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
13
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 class jtagdev(object):
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
15 ST_RESET = 0
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 ST_IDLE = 1
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 ST_SHIFT_DR = 2
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 ST_SHIFT_IR = 3
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
19 ST_EXIT1_DR = 4
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
20 ST_EXIT1_IR = 5
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 def __init__(self, fo):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 self.fo = fo
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
24 self.state = self.ST_RESET
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 self.seq = 0
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 def _send_cmd(self, code, data):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 cmd = cmd_proto.cmd(self.seq, code, data)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 frame = cmd.to_frame()
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 self.fo.write(frame)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 self.fo.flush()
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 def _send_nbits_data_cmd(self, code, nbits, data):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 nbits_data = cmd_proto.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:
diff changeset
38 self._send_cmd(code, nbits_data)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 def _send_tms(self, ptn, nbits):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 self._send_nbits_data_cmd(cmd_proto.CPCMD_SHIFT_TMS,
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 nbits, ptn)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 def wait_reply(self, tmo=None):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 import select
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
49 frame = ''
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
50 while True:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
51 if tmo == None:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
52 rlist, wlist, xlist = select.select((self.fo,), (), ())
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
53 else:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
54 rlist, wlist, xlist = select.select((self.fo,), (), (), tmo)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
55 pass
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
56 if not rlist:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
57 break
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
58 frame = frame + self.fo.read()
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
59 if len(frame) >= 4 and \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
60 len(frame) >= (ord(frame[3]) +
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
61 cmd_proto.cmd.FRAME_OVERHEAD):
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
62 break
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
63 tmo = 0.05
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 pass
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
65
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
66 if not frame:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
67 return None
11
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
68 if debug_frame:
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
69 dump_frame(frame)
11
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
70 pass
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
71
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 cmd = cmd_proto.cmd()
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
73 r = cmd.from_frame(frame)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
74 if r:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
75 return None
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 return cmd
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 def idle(self):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 self.seq = (self.seq + 1) % 256
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
81 if self.state == self.ST_RESET:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
82 ptn, nbits = tms_ptns.TMS_RESET_2_IDLE
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
83 else:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
84 ptn, nbits = tms_ptns.TMS_IDLE_SEQ
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
85 pass
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
86 self._send_tms(ptn, nbits)
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 self.state = self.ST_IDLE
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 def go_shift_IR(self):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 if self.state == self.ST_SHIFT_IR:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 return
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 if self.state == self.ST_IDLE:
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
96 ptn, ptn_nbits = tms_ptns.TMS_SHIFT_IR
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
97 elif self.state == self.ST_EXIT1_DR:
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
98 ptn, ptn_nbits = tms_ptns.TMS_EXIT1_DR_2_SHIFT_IR
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
99 elif self.state == self.ST_EXIT1_IR:
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
100 ptn, ptn_nbits = tms_ptns.TMS_EXIT1_IR_2_SHIFT_IR
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 else:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 raise RuntimeError, 'Transite to shift IR state from invalid state'
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
103 self._send_tms(ptn, ptn_nbits)
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 self.state = self.ST_SHIFT_IR
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 def go_shift_DR(self):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 if self.state == self.ST_SHIFT_DR:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 return
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 if self.state == self.ST_IDLE:
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
112 ptn, ptn_nbits = tms_ptns.TMS_SHIFT_DR
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
113 elif self.state == self.ST_EXIT1_IR:
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
114 ptn, ptn_nbits = tms_ptns.TMS_EXIT1_IR_2_SHIFT_DR
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
115 elif self.state == self.ST_EXIT1_DR:
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
116 ptn, ptn_nbits = tms_ptns.TMS_EXIT1_DR_2_SHIFT_DR
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 else:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 raise RuntimeError, 'Transite to shift DR state from invalid state'
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 pass
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
120 self._send_tms(ptn, ptn_nbits)
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 self.state = self.ST_SHIFT_DR
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 def shift_IR(self, data, nbits):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 self.seq = (self.seq + 1) % 256
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 if self.state != self.ST_SHIFT_IR:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 raise RuntimeError, 'Invalid state'
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 self._send_nbits_data_cmd(cmd_proto.CPCMD_SHIFT_TDI,
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 nbits, data)
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
132 self.state = self.ST_EXIT1_IR
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134
11
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
135 def shift_IR_n_out(self, data, nbits):
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
136 self.seq = (self.seq + 1) % 256
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
137
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
138 if self.state != self.ST_SHIFT_IR:
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
139 raise RuntimeError, 'Invalid state'
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
140
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
141 self._send_nbits_data_cmd(cmd_proto.CPCMD_SHIFT_TDI_TDO,
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
142 nbits, data)
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
143 self.state = self.ST_EXIT1_IR
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
144 pass
520f45b72ba7 Add debug_frame flag to enable print-out frame when received
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
145
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 def shift_DR(self, data, nbits):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 self.seq = (self.seq + 1) % 256
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 if self.state != self.ST_SHIFT_DR:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 raise RuntimeError, 'Invalid state'
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 self._send_nbits_data_cmd(cmd_proto.CPCMD_SHIFT_TDI,
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 nbits, data)
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
154 self.state = self.ST_EXIT1_DR
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 def shift_DR_n_out(self, data, nbits):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158 self.seq = (self.seq + 1) % 256
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160 if self.state != self.ST_SHIFT_DR:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 raise RuntimeError, 'Invalid state'
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 self._send_nbits_data_cmd(cmd_proto.CPCMD_SHIFT_TDI_TDO,
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 nbits, data)
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
165 self.state = self.ST_EXIT1_DR
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 def reset(self):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169 self._send_cmd(cmd_proto.CPCMD_TRST, '')
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 self.state = self.ST_RESET
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 def _extract_nbits_data(nbits_data):
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
175 nbits = ord(nbits_data[0]) | (ord(nbits_data[1]) << 8)
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 return nbits, nbits_data[2:]
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178 def _get_bit(data, bit_idx):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 byte_off = bit_idx / 8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180 bit_off = bit_idx % 8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 return (ord(data[byte_off]) >> bit_off) & 0x1
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 def identify_components(dev):
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
184 # dev.go_shift_IR()
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
185 # reply = dev.wait_reply()
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
186 # if reply.code != cmd_proto.CPCMD_ACK:
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
187 # raise RuntimeError, 'invalid reply code 0x%02x' % (reply.code)
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
188
13
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
189 # dev.shift_IR('\x04', 4)
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
190 # reply = dev.wait_reply()
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
191 # if reply.code != cmd_proto.CPCMD_ACK:
1ea479d26fce Make sure shifting phase and add bypass.py.
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
192 # raise RuntimeError, 'invalid reply code 0x%02x' % (reply.code)
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 dev.go_shift_DR()
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195 reply = dev.wait_reply()
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
196 if reply.code != cmd_proto.CPCMD_ACK:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
197 raise RuntimeError, 'invalid reply code 0x%02x' % (reply.code)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
198
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
199 dev.shift_DR_n_out('\xff' * 252, 252 * 8)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
200 reply = dev.wait_reply()
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
201 if not reply:
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
202 raise RuntimeError, 'Invalid replied message'
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 if reply.code != cmd_proto.CPCMD_DATA:
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 8
diff changeset
204 raise RuntimeError, 'invalid replied code 0x%02x %s' % (reply.code, repr(reply))
8
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
205
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
206 nbits, data = _extract_nbits_data(reply.data)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
207
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
208 components = []
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209 i = 0
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
210 while i < nbits:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211 bit = _get_bit(data, i)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
212 if bit == 0:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
213 components.append(0)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
214 i = i + 1
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
215 else:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216 comp_id = 0
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217 for j in range(32):
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
218 bit = _get_bit(data, i + j)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219 comp_id = comp_id | (bit << j)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
220 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
221 if comp_id == 0xffffffff:
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
222 break
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
223 components.append(comp_id)
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
224 i = i + 32
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
225 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
226 pass
074e860d7d31 jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
227 return components