annotate src/jtag.c @ 7:61f27549de57

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