2 \author Travis Goodspeed <travis at radiantmachines.com>
12 //! Set up the pins for JTAG mode.
25 /************************** JTAG Primitives ****************************/
26 // these have been turned into functions to save flash space
28 //delay(1); // FIXME: Should never wait this long...
31 //delay(1); // FIXME: Should never wait this long...
36 void jtag_goto_shift_ir() {
45 void jtag_goto_shift_dr() {
53 void jtag_reset_to_runtest_idle() {
59 jtag_tcktock(); // now in Reset state
61 jtag_tcktock(); // now in Run-Test/Idle state
66 // NOTE: important: THIS MODULE REVOLVES AROUND RETURNING TO RUNTEST/IDLE, OR THE FUNCTIONAL EQUIVALENT
67 //! Shift N bits over TDI/TDO. May choose LSB or MSB, and select whether to terminate (TMS-high on last bit) and whether to return to RUNTEST/IDLE
68 // flags should be 0 for most uses.
69 // for the extreme case, flags should be (NOEND|NORETDLE|LSB)
70 // other edge cases can involve a combination of those three flags
72 // the max bit-size that can be be shifted is 32-bits.
73 // for longer shifts, use the NOEND flag (which infers NORETIDLE so the additional flag is unnecessary)
75 // NORETIDLE is used for special cases where (as with arm) the debug subsystem does not want to
76 // return to the RUN-TEST/IDLE state between setting IR and DR
77 unsigned long jtagtransn(unsigned long word, unsigned char bitcount, unsigned char flags){
79 unsigned long high = 1L;
82 //for (bit=(bitcount-1)/8; bit>0; bit--)
84 //high <<= ((bitcount-1)%8);
85 high <<= (bitcount-1);
91 for (bit = bitcount; bit > 0; bit--) {
92 /* write MOSI on trailing edge of previous clock */
99 if (bit==1 && !(flags & NOEND))
100 SETTMS;//TMS high on last bit to exit.
104 /* read MISO on trailing edge */
110 for (bit = bitcount; bit > 0; bit--) {
111 /* write MOSI on trailing edge of previous clock */
116 word = (word & mask) << 1;
118 if (bit==1 && !(flags & NOEND))
119 SETTMS;//TMS high on last bit to exit.
123 /* read MISO on trailing edge */
132 if (!(flags & NOEND)){
136 if (!(flags & NORETIDLE)){
144 //! Shift 8 bits in and out.
145 unsigned char jtagtrans8(unsigned char byte){
148 for (bit = 0; bit < 8; bit++) {
149 /* write MOSI on trailing edge of previous clock */
157 SETTMS;//TMS high on last bit to exit.
160 /* read MISO on trailing edge */
174 //! Shift n bits in and out.
175 /*unsigned long jtagtransn(unsigned long word,
176 unsigned int bitcount){
179 unsigned long high=0x8000;
188 for (bit = 0; bit < bitcount; bit++) {
189 //* write MOSI on trailing edge of previous clock *
197 SETTMS;//TMS high on last bit to exit.
200 //* read MISO on trailing edge *
205 word = ((word << 16) | (word >> 4)) & 0x000FFFFF;
220 //! Stop JTAG, release pins
226 unsigned int drwidth=16;
227 //! Shift all bits of the DR.
228 unsigned long jtag_dr_shift20(unsigned long in){
238 // shift DR, then idle
239 return(jtagtransn(in,20,0));
243 //! Shift 16 bits of the DR.
244 unsigned int jtag_dr_shift16(unsigned int in){
254 // shift DR, then idle
255 return(jtagtransn(in,16,0));
258 //! Shift native width of the DR
259 unsigned long jtag_dr_shiftadr(unsigned long in){
272 out=jtagtransn(in,drwidth,0);
274 // shift DR, then idle
279 //! Shift 8 bits of the IR.
280 unsigned char jtag_ir_shift8(unsigned char in){
292 // shift IR, then idle.
293 return(jtagtrans8(in));
296 //! Handles a monitor command.
297 void jtaghandle(unsigned char app,
301 //START handled by specific JTAG
311 cmddata[0]=jtag_ir_shift8(cmddata[0]);
315 cmddataword[0]=jtag_dr_shift16(cmddataword[0]);