annotate src/jtag.c @ 4:6b1594fb668f

Improve performance of jtag.c and test it with Python scripts. - cp_tditdo.py send bits to TDI and hope it will feed back from TDO. - Expand loops in jtag.c to improve performance.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 22 Feb 2009 12:54:45 +0800
parents abf221bf3ce4
children eb14cac68cbb
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
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 void jtag_tms(char *buf, int nbits) {
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 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
35 int nbytes, byte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 int byteoff, bitoff;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 int bit;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
39 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
40 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
41 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
42
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
43 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
44 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
45 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
46
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
47 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
48 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
49 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
50
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
51 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
52 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
53 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
54
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
55 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
56 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
57 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
58
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
59 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
60 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
61 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
62
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
63 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
64 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
65 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
66
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
67 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
68 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
69 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
70
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
71 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
72 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
73 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
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
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
76 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
77 nbits %= 8;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 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
79 bit = byte & (1 << i);
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 SEND_BIT(JTAG_TMS, bit);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 TCK_LO();
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 void jtag_shift(char *buf, int nbits) {
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 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
87 int nbytes, byte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 int byteoff, bitoff;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 int bit;
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
91 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
92 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
93 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
94
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
95 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
96 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
97 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
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 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
100 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
101 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
102
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 & 0x04;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
104 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
105 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
106
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
107 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
108 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
109 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
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 & 0x10;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 SEND_BIT(JTAG_TDI, bit);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 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
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 & 0x20;
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 & 0x40;
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 & 0x80;
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
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 }
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 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
140 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
141 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
142 int tdo;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 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
144 int bit;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145
4
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
146 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
147 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
148 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
149 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
150
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
151 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
152 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
153 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
154 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
155 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
156 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
157 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
158 TCK_LO();
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159
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 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
161 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
162 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
163 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
164 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
165 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
166 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
167 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
168
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
169 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
170 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
171 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
172 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
173 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
174 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
175 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
176 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
177
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
178 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
179 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
180 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
181 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
182 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
183 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
184 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
185 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
186
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
187 bit = byte & 0x10;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
188 SEND_BIT(JTAG_TDI, bit);
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189 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
190 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
191 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
192 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
193 obyte &= ~0x10;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 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
195
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 & 0x20;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
197 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
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 |= 0x20;
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 &= ~0x20;
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
203 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
204
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
205 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
206 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
207 tdo = GET_TDO();
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
208 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
209 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
210 else
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
211 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
212 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
213
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
214 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
215 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
216 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
217 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
218 obyte |= 0x80;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219 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
220 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
221 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
222
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
223 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
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
6b1594fb668f Improve performance of jtag.c and test it with Python scripts.
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
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 &= ~(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
238 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
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 obuf[i] = obyte;
2
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
241 }
abf221bf3ce4 AVR JTAG server.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
242 }