Mercurial > avr_jtag
annotate py_avrjtag/jtagdev.py @ 10:cc106f278d7d
Get identify of components
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 24 Feb 2009 13:32:04 +0800 |
parents | 074e860d7d31 |
children | 520f45b72ba7 |
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): |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
5 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
|
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 |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
9 ST_EXIT1_DR = 4 |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
10 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
|
11 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 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
|
13 self.fo = fo |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
14 self.state = self.ST_IDLE |
8
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 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
|
16 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 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
|
19 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
|
20 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
|
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 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
|
23 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
|
24 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 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
|
32 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
|
33 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
|
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 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
|
37 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
|
38 |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
39 frame = '' |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
40 while True: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
41 if tmo == None: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
42 rlist, wlist, xlist = select.select((self.fo,), (), ()) |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
43 else: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
44 rlist, wlist, xlist = select.select((self.fo,), (), (), tmo) |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
45 pass |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
46 if not rlist: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
47 break |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
48 frame = frame + self.fo.read() |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
49 if len(frame) >= 4 and \ |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
50 len(frame) >= (ord(frame[3]) + |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
51 cmd_proto.cmd.FRAME_OVERHEAD): |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
52 break |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
53 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
|
54 pass |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
55 |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
56 if not frame: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
57 return None |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
58 |
8
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 cmd = cmd_proto.cmd() |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
60 r = cmd.from_frame(frame) |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
61 if r: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
62 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
|
63 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
|
64 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 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
|
66 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
|
67 |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
68 if self.state == self.ST_RESET: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
69 ptn, nbits = tms_ptns.TMS_RESET_2_IDLE |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
70 else: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
71 ptn, nbits = tms_ptns.TMS_IDLE_SEQ |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
72 pass |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
73 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
|
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 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 pass |
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 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
|
79 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
|
80 return |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 if self.state == self.ST_IDLE: |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
83 ptn, ptn_nbits = tms_ptns.TMS_SHIFT_IR |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
84 self._send_tms(ptn, ptn_nbits) |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
85 elif self.state == self.ST_EXIT1_DR: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
86 ptn, ptn_nbits = tms_ptns.TMS_EXIT1_DR_2_SHIFT_IR |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
87 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
|
88 else: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
89 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
|
90 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 pass |
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 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
|
94 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
|
95 return |
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 if self.state == self.ST_IDLE: |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
98 ptn, ptn_nbits = tms_ptns.TMS_SHIFT_DR |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
99 self._send_tms(ptn, ptn_nbits) |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
100 elif self.state == self.ST_EXIT1_IR: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
101 ptn, ptn_nbits = tms_ptns.TMS_EXIT1_IR_2_SHIFT_DR |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
102 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
|
103 else: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
104 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
|
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 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
|
107 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
108 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
109 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
|
110 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
|
111 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
112 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
|
113 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
|
114 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
115 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
|
116 nbits, data) |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
117 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
|
118 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
119 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 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
|
121 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
|
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 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
|
124 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
|
125 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
126 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
|
127 nbits, data) |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
128 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
|
129 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
130 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
131 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
|
132 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
|
133 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
134 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
|
135 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
|
136 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
137 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
|
138 nbits, data) |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
139 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
|
140 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
141 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
146 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
147 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
148 def _extract_nbits_data(nbits_data): |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
149 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
|
150 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
|
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 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
|
153 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
|
154 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
|
155 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
|
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 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
|
158 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
|
159 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
|
160 if reply.code != cmd_proto.CPCMD_ACK: |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
161 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
|
162 |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
163 dev.shift_IR('\x02', 4) |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
164 reply = dev.wait_reply() |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
165 if reply.code != cmd_proto.CPCMD_ACK: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
166 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
|
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 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
|
169 reply = dev.wait_reply() |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
170 if reply.code != cmd_proto.CPCMD_ACK: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
171 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
|
172 |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
173 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
|
174 reply = dev.wait_reply() |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
175 if not reply: |
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
176 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
|
177 if reply.code != cmd_proto.CPCMD_DATA: |
10
cc106f278d7d
Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents:
8
diff
changeset
|
178 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
|
179 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
180 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
|
181 |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
182 components = [] |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 else: |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 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
|
194 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
195 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
|
196 break |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
197 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
|
198 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
|
199 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
200 pass |
074e860d7d31
jtagdev is a desktop client to communicate with jtag device through Arduino.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
201 return components |