annotate src/jtag.c @ 5:eb14cac68cbb

Transite TAP controller to shift state. - shift commands will transite state machine of TAP controller to shift state before starting shifting.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 22 Feb 2009 13:55:50 +0800
parents 6b1594fb668f
children 61f27549de57
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
5
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
33 /*!
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
34 * 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
35 * 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
36 * starts.
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
37 */
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 void jtag_tms(char *buf, int nbits) {
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 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
40 int nbytes, byte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 int byteoff, bitoff;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 int bit;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
44 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
45 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
46 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
47
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
48 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
49 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
50 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
51
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
52 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
53 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
54 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
55
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
56 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
57 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
58 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
59
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
60 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
61 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
62 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
63
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
64 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
65 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
66 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
67
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
68 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
69 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
70 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
71
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
72 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
73 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
74 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
75
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
76 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
77 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
78 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
79 }
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 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
82 nbits %= 8;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 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
84 bit = byte & (1 << i);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 SEND_BIT(JTAG_TMS, bit);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 TCK_LO();
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 void jtag_shift(char *buf, int nbits) {
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 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
92 int nbytes, byte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 int byteoff, bitoff;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 int bit;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95
5
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
96 /* Transite to shift state.
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
97 * \sa jtag_tms()
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
98 */
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
99 pin_lo(JTAG_PORT, JTAG_TMS);
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
100
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
101 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
102 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
103 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
104
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
105 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
106 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
107 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
108
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
109 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
110 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
111 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
112
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
113 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
114 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
115 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
116
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
117 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
118 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
119 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
120
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
121 bit = byte & 0x10;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 SEND_BIT(JTAG_TDI, bit);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 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
124
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
125 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
126 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
127 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
128
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
129 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
130 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
131 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
132
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
133 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
134 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
135 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
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
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 }
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 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
150 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
151 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
152 int tdo;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 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
154 int bit;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155
5
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
156 /* Transite to shift state.
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
157 * \sa jtag_tms()
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
158 */
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
159 pin_lo(JTAG_PORT, JTAG_TMS);
eb14cac68cbb Transite TAP controller to shift state.
Thinker K.F. Li <thinker@branda.to>
parents: 4
diff changeset
160
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
161 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
162 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
163 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
164 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
165
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
166 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
167 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
168 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
169 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
170 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
171 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
172 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
173 TCK_LO();
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
175 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
176 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
177 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
178 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
179 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
180 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
181 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
182 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
183
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
184 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
185 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
186 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
187 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
188 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
189 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
190 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
191 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
192
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
193 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
194 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
195 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
196 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
197 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
198 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
199 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
200 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
201
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
202 bit = byte & 0x10;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 SEND_BIT(JTAG_TDI, bit);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
204 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
205 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
206 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
207 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
208 obyte &= ~0x10;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209 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
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 & 0x20;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
212 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
213 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
214 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
215 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
216 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
217 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
218 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
219
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
220 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
221 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
222 tdo = GET_TDO();
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
223 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
224 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
225 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
226 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
227 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
228
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
229 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
230 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
231 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
232 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
233 obyte |= 0x80;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 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
235 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
236 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
237
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
238 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
239 }
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
240
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 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
251 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
252 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
253 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
254 }
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
255 obuf[i] = obyte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
256 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
257 }