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