2 \author Travis Goodspeed <travis at radiantmachines.com>
13 //! Handles a monitor command.
14 void jtag_handle_fn(uint8_t const app,
19 unsigned char jtagid=0;
21 // define the jtag app's app_t
22 app_t const jtag_app = {
34 "\tThe JTAG app handles basic JTAG operations such as\n"
35 "\tresetting the TAP, resetting the target, detecting\n"
36 "\tthe instruction register width, shifting bits into\n"
37 "\tboth the instruction and data registers.\n"
41 //! Set up the pins for JTAG mode.
54 /************************** JTAG Primitives ****************************/
55 // these have been turned into functions to save flash space
63 void jtag_goto_shift_ir() {
72 void jtag_goto_shift_dr() {
86 jtag_tcktock(); // now in Reset state
88 jtag_tcktock(); // now in Run-Test/Idle state
93 // NOTE: important: THIS MODULE REVOLVES AROUND RETURNING TO RUNTEST/IDLE, OR
94 // THE FUNCTIONAL EQUIVALENT
95 //! Shift N bits over TDI/TDO. May choose LSB or MSB, and select whether to
96 // terminate (TMS-high on last bit) and whether to return to RUNTEST/IDLE
97 // flags should be 0 for most uses.
98 // for the extreme case, flags should be (NOEND|NORETDLE|LSB)
99 // other edge cases can involve a combination of those three flags
101 // the max bit-size that can be be shifted is 32-bits.
102 // for longer shifts, use the NOEND flag (which infers NORETIDLE so the
103 // additional flag is unnecessary)
105 // NORETIDLE is used for special cases where (as with arm) the debug
106 // subsystem does not want to return to the RUN-TEST/IDLE state between
108 unsigned long jtagtransn(unsigned long word,
109 unsigned char bitcount,
110 unsigned char flags) {
112 unsigned long high = 1L;
115 //for (bit=(bitcount-1)/8; bit>0; bit--)
117 //high <<= ((bitcount-1)%8);
118 high <<= (bitcount-1);
124 for (bit = bitcount; bit > 0; bit--) {
125 /* write MOSI on trailing edge of previous clock */
132 if (bit==1 && !(flags & NOEND))
133 SETTMS;//TMS high on last bit to exit.
137 /* read MISO on trailing edge */
143 for (bit = bitcount; bit > 0; bit--) {
144 /* write MOSI on trailing edge of previous clock */
149 word = (word & mask) << 1;
151 if (bit==1 && !(flags & NOEND))
152 SETTMS;//TMS high on last bit to exit.
156 /* read MISO on trailing edge */
165 if (!(flags & NOEND)){
169 if (!(flags & NORETIDLE)){
177 //! Shift 8 bits in and out.
178 unsigned char jtagtrans8(unsigned char byte){
181 for (bit = 0; bit < 8; bit++) {
182 /* write MOSI on trailing edge of previous clock */
190 SETTMS;//TMS high on last bit to exit.
193 /* read MISO on trailing edge */
207 //! Shift n bits in and out.
208 /*unsigned long jtagtransn(unsigned long word,
209 unsigned int bitcount){
212 unsigned long high=0x8000;
221 for (bit = 0; bit < bitcount; bit++) {
222 // write MOSI on trailing edge of previous clock *
230 SETTMS;//TMS high on last bit to exit.
233 // read MISO on trailing edge *
238 word = ((word << 16) | (word >> 4)) & 0x000FFFFF;
253 //! Stop JTAG, release pins
259 unsigned int drwidth=16;
260 //! Shift all bits of the DR.
261 unsigned long jtag_dr_shift20(unsigned long in){
271 // shift DR, then idle
272 return(jtagtransn(in,20,0));
276 //! Shift 16 bits of the DR.
277 unsigned int jtag_dr_shift16(unsigned int in){
287 // shift DR, then idle
288 return(jtagtransn(in,16,0));
291 //! Shift native width of the DR
292 unsigned long jtag_dr_shiftadr(unsigned long in){
305 out=jtagtransn(in,drwidth,0);
307 // shift DR, then idle
312 //! Shift 8 bits of the IR.
313 unsigned char jtag_ir_shift8(unsigned char in){
325 // shift IR, then idle.
326 return(jtagtrans8(in));
329 //! Handles a monitor command.
330 void jtag_handle_fn(uint8_t const app,
336 //START handled by specific JTAG
348 cmddata[0]=jtag_ir_shift8(cmddata[0]);
353 cmddataword[0]=jtag_dr_shift16(cmddataword[0]);