]> git.zerfleddert.de Git - usb-driver/blob - jtagmon.c
Always set return value for parallel ports
[usb-driver] / jtagmon.c
1 #include <string.h>
2 #include <stdio.h>
3 #include "jtagmon.h"
4
5 enum tap_states {
6 TEST_LOGIC_RESET,
7 RUN_TEST_IDLE,
8 SELECT_DR,
9 CAPTURE_DR,
10 SHIFT_DR,
11 EXIT1_DR,
12 PAUSE_DR,
13 EXIT2_DR,
14 UPDATE_DR,
15 SELECT_IR,
16 CAPTURE_IR,
17 SHIFT_IR,
18 EXIT1_IR,
19 PAUSE_IR,
20 EXIT2_IR,
21 UPDATE_IR
22 };
23
24 void jtagmon(unsigned char tck, unsigned char tms, unsigned char tdi) {
25 static unsigned char last_tck = 1;
26 static char tdi_written = 0;
27 static int state = TEST_LOGIC_RESET;
28 static char state_text[32] = "Test Logic Reset";
29 char last_state_text[32];
30 int last_state = state;
31
32 strcpy(last_state_text, state_text);
33
34 if (!last_tck && tck) {
35 switch(state) {
36 case TEST_LOGIC_RESET:
37 if (tms) {
38 state = TEST_LOGIC_RESET;
39 } else {
40 state = RUN_TEST_IDLE;
41 }
42 break;
43 case RUN_TEST_IDLE:
44 if (tms) {
45 state = SELECT_DR;
46 } else {
47 state = RUN_TEST_IDLE;
48 }
49 break;
50 case SELECT_DR:
51 if (tms) {
52 state = SELECT_IR;
53 } else {
54 state = CAPTURE_DR;
55 }
56 break;
57 case CAPTURE_DR:
58 if (tms) {
59 state = EXIT1_DR;
60 } else {
61 state = SHIFT_DR;
62 }
63 break;
64 case SHIFT_DR:
65 if (tms) {
66 state = EXIT1_DR;
67 } else {
68 state = SHIFT_DR;
69 }
70 break;
71 case EXIT1_DR:
72 if (tms) {
73 state = UPDATE_DR;
74 } else {
75 state = PAUSE_DR;
76 }
77 break;
78 case PAUSE_DR:
79 if (tms) {
80 state = EXIT2_DR;
81 } else {
82 state = PAUSE_DR;
83 }
84 break;
85 case EXIT2_DR:
86 if (tms) {
87 state = UPDATE_DR;
88 } else {
89 state = SHIFT_DR;
90 }
91 break;
92 case UPDATE_DR:
93 if (tms) {
94 state = SELECT_DR;
95 } else {
96 state = RUN_TEST_IDLE;
97 }
98 break;
99 case SELECT_IR:
100 if (tms) {
101 state = TEST_LOGIC_RESET;
102 } else {
103 state = CAPTURE_IR;
104 }
105 break;
106 case CAPTURE_IR:
107 if (tms) {
108 state = EXIT1_IR;
109 } else {
110 state = SHIFT_IR;
111 }
112 break;
113 case SHIFT_IR:
114 if (tms) {
115 state = EXIT1_IR;
116 } else {
117 state = SHIFT_IR;
118 }
119 break;
120 case EXIT1_IR:
121 if (tms) {
122 state = UPDATE_IR;
123 } else {
124 state = PAUSE_IR;
125 }
126 break;
127 case PAUSE_IR:
128 if (tms) {
129 state = EXIT2_IR;
130 } else {
131 state = PAUSE_IR;
132 }
133 break;
134 case EXIT2_IR:
135 if (tms) {
136 state = UPDATE_IR;
137 } else {
138 state = SHIFT_IR;
139 }
140 break;
141 case UPDATE_IR:
142 if (tms) {
143 state = SELECT_DR;
144 } else {
145 state = RUN_TEST_IDLE;
146 }
147 break;
148 }
149
150 switch(state) {
151 case TEST_LOGIC_RESET:
152 strcpy(state_text, "Test Logic Reset");
153 break;
154 case RUN_TEST_IDLE:
155 strcpy(state_text, "Run-Test / Idle");
156 break;
157 case SELECT_DR:
158 strcpy(state_text, "Select-DR");
159 break;
160 case CAPTURE_DR:
161 strcpy(state_text, "Capture-DR");
162 break;
163 case SHIFT_DR:
164 strcpy(state_text, "Shift-DR");
165 break;
166 case EXIT1_DR:
167 strcpy(state_text, "Exit1-DR");
168 break;
169 case PAUSE_DR:
170 strcpy(state_text, "Pause-DR");
171 break;
172 case EXIT2_DR:
173 strcpy(state_text, "Exit2-DR");
174 break;
175 case UPDATE_DR:
176 strcpy(state_text, "Update-DR");
177 break;
178 case SELECT_IR:
179 strcpy(state_text, "Select-IR");
180 break;
181 case CAPTURE_IR:
182 strcpy(state_text, "Capture-IR");
183 break;
184 case SHIFT_IR:
185 strcpy(state_text, "Shift-IR");
186 break;
187 case EXIT1_IR:
188 strcpy(state_text, "Exit1-IR");
189 break;
190 case PAUSE_IR:
191 strcpy(state_text, "Pause-IR");
192 break;
193 case EXIT2_IR:
194 strcpy(state_text, "Exit2-IR");
195 break;
196 case UPDATE_IR:
197 strcpy(state_text, "Update-IR");
198 break;
199 }
200
201 if (last_state != state) {
202 if (tdi_written)
203 fprintf(stderr,"\n");
204
205 fprintf(stderr,"TAP state transition from %s to %s\n", last_state_text, state_text);
206 tdi_written = 0;
207 } else {
208 fprintf(stderr,"%d",(tdi ? 1 : 0));
209 tdi_written = 1;
210 }
211 }
212
213 last_tck = tck;
214 }
Impressum, Datenschutz