annotate src/jtag.c @ 10:cc106f278d7d

Get identify of components
author Thinker K.F. Li <thinker@branda.to>
date Tue, 24 Feb 2009 13:32:04 +0800
parents 61f27549de57
children 1ea479d26fce
rev   line source
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <util/delay.h>
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include "jtag.h"
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "avriotools.h"
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 /* It is supposed to work at 1Mbps */
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
7 #define CLK_DELAY() _delay_us(1)
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 void jtag_init(void) {
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 pin_mode(&JTAG_PORT, JTAG_TCK, PM_OUTPUT);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 pin_mode(&JTAG_PORT, JTAG_TMS, PM_OUTPUT);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 pin_mode(&JTAG_PORT, JTAG_TDI, PM_OUTPUT);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 pin_mode(&JTAG_PORT, JTAG_TDO, PM_INPUT);
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
14 pin_mode(&JTAG_PORT, JTAG_TRST, PM_OUTPUT);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 pin_lo(JTAG_PORT, JTAG_TCK);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 pin_lo(JTAG_PORT, JTAG_TMS);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 pin_lo(JTAG_PORT, JTAG_TDI);
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
18 pin_hi(JTAG_PORT, JTAG_TRST);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 #define TCK_LO() pin_lo(JTAG_PORT, JTAG_TCK)
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 #define TCK_HI() pin_hi(JTAG_PORT, JTAG_TCK)
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 #define SEND_BIT(pin, bit) \
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 do { \
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 if(bit) \
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
26 pin_hi(JTAG_PORT, pin); \
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 else \
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
28 pin_lo(JTAG_PORT, pin); \
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 CLK_DELAY(); \
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 TCK_HI(); \
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 CLK_DELAY(); \
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
32 TCK_LO(); \
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 } while(0)
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 #define GET_TDO() (JTAG_PIN & _BV(JTAG_TDO))
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
35 #define SEND_GET_BIT(pin, bit, out) \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
36 do { \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
37 if(bit) \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
38 pin_hi(JTAG_PORT, pin); \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
39 else \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
40 pin_lo(JTAG_PORT, pin); \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
41 CLK_DELAY(); \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
42 TCK_HI(); \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
43 CLK_DELAY(); \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
44 out = GET_TDO(); \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
45 TCK_LO(); \
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
46 } while(0)
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47
7
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
48 void jtag_trst(void) {
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
49 pin_lo(JTAG_PORT, JTAG_TRST);
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
50 SEND_BIT(JTAG_TMS, 1);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
51 SEND_BIT(JTAG_TMS, 1);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
52 SEND_BIT(JTAG_TMS, 1);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
53 SEND_BIT(JTAG_TMS, 1);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
54 SEND_BIT(JTAG_TMS, 1);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
55 pin_hi(JTAG_PORT, JTAG_TRST);
7
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
56 }
61f27549de57 Support TRST.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
57
5
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
58 /*!
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
59 * Before shifting registers, TAP controller must move to last state before
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
60 * shift state. The state machine transite to shift state when shifting
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
61 * starts.
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
62 */
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
63 void jtag_tms(unsigned char *buf, int nbits) {
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 int i;
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
65 int nbytes, byte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 int byteoff, bitoff;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 int bit;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
69 pin_hi(JTAG_PORT, JTAG_TDI);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
70
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
71 nbytes = nbits / 8;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
72 for(i = 0; i < nbytes; i++) {
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
73 byte = buf[i];
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
74
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
75 bit = byte & 0x01;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
76 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
77
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
78 bit = byte & 0x02;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
79 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
80
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
81 bit = byte & 0x04;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
82 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
83
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
84 bit = byte & 0x08;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
85 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
86
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
87 bit = byte & 0x10;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
88 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
89
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
90 bit = byte & 0x20;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
91 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
92
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
93 bit = byte & 0x40;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
94 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
95
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
96 bit = byte & 0x80;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
97 SEND_BIT(JTAG_TMS, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
98 }
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
99
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
100 byte = buf[i];
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
101 nbits %= 8;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 for(i = 0; i < nbits; i++) {
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
103 bit = byte & (1 << i);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 SEND_BIT(JTAG_TMS, bit);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
108 void jtag_shift(unsigned char *buf, int nbits) {
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 int i;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
110 int nbits_1;
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
111 int nbytes, byte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 int byteoff, bitoff;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
113 int bit, remain;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
114
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
115 if(nbits == 0)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
116 return;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117
5
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
118 /* Transite to shift state.
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
119 * \sa jtag_tms()
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
120 */
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
121 pin_lo(JTAG_PORT, JTAG_TMS);
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
122
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
123 nbits_1 = nbits - 1;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
124 nbytes = nbits_1 / 8;
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
125 for(i = 0; i < nbytes; i++) {
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
126 byte = buf[i];
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
127
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
128 bit = byte & 0x01;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
129 SEND_BIT(JTAG_TDI, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
130
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
131 bit = byte & 0x02;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
132 SEND_BIT(JTAG_TDI, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
133
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
134 bit = byte & 0x04;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
135 SEND_BIT(JTAG_TDI, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
136
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
137 bit = byte & 0x08;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
138 SEND_BIT(JTAG_TDI, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
139
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
140 bit = byte & 0x10;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 SEND_BIT(JTAG_TDI, bit);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
142
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
143 bit = byte & 0x20;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
144 SEND_BIT(JTAG_TDI, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
145
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
146 bit = byte & 0x40;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
147 SEND_BIT(JTAG_TDI, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
148
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
149 bit = byte & 0x80;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
150 SEND_BIT(JTAG_TDI, bit);
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
151 }
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
152
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
153 remain = nbits_1 % 8;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
154 byte = buf[i];
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
155 for(i = 0; i < remain; i++) {
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
156 bit = byte & (1 << i);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
157 SEND_BIT(JTAG_TDI, bit);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158 }
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
159
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
160 byte = buf[nbits / 8];
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
161 bit = byte & (1 << (nbits_1 % 8));
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
162
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
163 pin_hi(JTAG_PORT, JTAG_TMS);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
164 SEND_BIT(JTAG_TDI, bit);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
167 void jtag_shift_inout(unsigned char *ibuf, unsigned char *obuf, int nbits) {
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
168 int i, j;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
169 int nbits_1;
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
170 int nbytes, byte, obyte;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
171 int tdo;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 int byteoff, bitoff;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
173 int bit, remain;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
174
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
175 if(nbits == 0)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
176 return;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177
5
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
178 /* Transite to shift state.
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
179 * \sa jtag_tms()
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
180 */
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
181 pin_lo(JTAG_PORT, JTAG_TMS);
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
182
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
183 nbits_1 = nbits - 1;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
184 nbytes = nbits_1 / 8;
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
185 for(i = 0; i < nbytes; i++) {
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
186 byte = ibuf[i];
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
187 obyte = 0;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
188
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
189 bit = byte & 0x01;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
190 SEND_GET_BIT(JTAG_TDI, bit, tdo);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
191 if(tdo)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
192 obyte |= 0x01;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
193 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
194 obyte &= ~0x01;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
196 bit = byte & 0x02;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
197 SEND_GET_BIT(JTAG_TDI, bit, tdo);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
198 tdo = GET_TDO();
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
199 if(tdo)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
200 obyte |= 0x02;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
201 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
202 obyte &= ~0x02;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
203
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
204 bit = byte & 0x04;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
205 SEND_GET_BIT(JTAG_TDI, bit, tdo);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
206 if(tdo)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
207 obyte |= 0x04;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
208 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
209 obyte &= ~0x04;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
210
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
211 bit = byte & 0x08;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
212 SEND_GET_BIT(JTAG_TDI, bit, tdo);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
213 if(tdo)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
214 obyte |= 0x08;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
215 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
216 obyte &= ~0x08;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
217
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
218 bit = byte & 0x10;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
219 SEND_GET_BIT(JTAG_TDI, bit, tdo);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
220 if(tdo)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
221 obyte |= 0x10;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
222 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
223 obyte &= ~0x10;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
224
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
225 bit = byte & 0x20;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
226 SEND_GET_BIT(JTAG_TDI, bit, tdo);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
227 if(tdo)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
228 obyte |= 0x20;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
229 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
230 obyte &= ~0x20;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
231
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
232 bit = byte & 0x40;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
233 SEND_GET_BIT(JTAG_TDI, bit, tdo);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 if(tdo)
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
235 obyte |= 0x40;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
236 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
237 obyte &= ~0x40;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
238
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
239 bit = byte & 0x80;
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
240 SEND_GET_BIT(JTAG_TDI, bit, tdo);
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
241 if(tdo)
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
242 obyte |= 0x80;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
243 else
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
244 obyte &= ~0x80;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
245
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
246 obuf[i] = obyte;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
247 }
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
248
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
249 remain = nbits_1 % 8;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
250 byte = ibuf[i];
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
251 obyte = 0;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
252 for(j = 0; j < remain; j++) {
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
253 bit = byte & (1 << j);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
254 SEND_GET_BIT(JTAG_TDI, bit, tdo);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
255 if(tdo)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
256 obyte |= 1 << j;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
257 else
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
258 obyte &= ~(1 << j);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
259 }
10
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
260 obuf[i] = obyte;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
261
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
262 byte = ibuf[nbits / 8];
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
263 bit = byte & (1 << (nbits_1 % 8));
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
264
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
265 pin_hi(JTAG_PORT, JTAG_TMS);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
266 SEND_GET_BIT(JTAG_TDI, bit, tdo);
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
267 if(tdo)
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
268 obuf[nbits / 8] |= 1 << j;
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
269 else
cc106f278d7d Get identify of components
Thinker K.F. Li <thinker@branda.to>
parents: 7
diff changeset
270 obuf[nbits / 8] &= ~(1 << j);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
271 }