Mercurial > avr_jtag
annotate py_avrjtag/jtagdev.py @ 8:074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 22 Feb 2009 22:30:20 +0800 |
parents | |
children | cc106f278d7d |
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 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 class jtagdev(object): |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 ST_REST = 0 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 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
|
7 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
|
8 ST_SHIFT_IR = 3 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 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
|
11 self.fo = fo |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 self.state = self.IDLE |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 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
|
14 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 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
|
17 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
|
18 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
|
19 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 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
|
21 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
|
22 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 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
|
25 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
|
26 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
|
27 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 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
|
35 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
|
36 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 if tmo is None: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 select.select((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
|
39 else: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 select.select((self.fo,), (), (), tmo) |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 frame = self.fo.read() |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 cmd = cmd_proto.cmd() |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 cmd.from_frame(frame) |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 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
|
46 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 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
|
48 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
|
49 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 ptn, nbits = tms_ptns.TMS_IDLE_SEQ |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 self.send_tms(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
|
52 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 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
|
54 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 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
|
57 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
|
58 return |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 if 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
|
61 ptn, ptn_nbits = tms_ptns.TMS_CAP_IR |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 self.send_tms(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
|
63 elif 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
|
64 ptn, ptn_nbits = tms_ptns.TMS_SHIFT_DR_2_CAP_IR |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 self.send_tms(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
|
66 else: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 raise RuntimeError, 'Transite to shift IR 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
|
68 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
|
69 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 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
|
72 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
|
73 return |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 if 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
|
76 ptn, ptn_nbits = tms_ptns.TMS_CAP_DR |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 self.send_tms(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
|
78 elif 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
|
79 ptn, ptn_nbits = tms_ptns.TMS_SHIFT_IR_2_CAP_DR |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 self.send_tms(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
|
81 else: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 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
|
83 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 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
|
85 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 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
|
88 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
|
89 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 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
|
91 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
|
92 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 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
|
94 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
|
95 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
96 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
97 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
|
98 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
|
99 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
100 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
|
101 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
|
102 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 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
|
104 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
|
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 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
|
108 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
|
109 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
110 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
|
111 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
|
112 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
113 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
|
114 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
|
115 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
116 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
121 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
123 def _extract_nbits_data(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
|
124 nbits = ord(nbits_data[0]) | (ord(nbits_data[1] << 8)) |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
125 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
|
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 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
|
128 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
|
129 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
|
130 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
|
131 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
132 def identify_components(dev): |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
133 dev.go_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
|
134 reply = dev.wait_reply() |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
135 if reply.code != cmd_proto.CPCMD_ACK: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
136 raise RutimeError, 'invliad reply code 0x%02x' % (reply.code) |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
137 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
138 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
|
139 dev.shift_DR('\xff' * 253, 253 * 8) |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
140 reply = dev.wait_reply() |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
141 if reply.code != cmd_proto.CPCMD_DATA: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
142 raise RutimeError, 'invliad reply code 0x%02x' % (reply.code) |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
143 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 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
|
145 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
146 components = [] |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 else: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 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
|
158 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
159 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
|
160 break |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
161 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
|
162 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
|
163 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
164 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
165 return components |