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
34 void jtag_goto_shift_ir() {
43 void jtag_goto_shift_dr() {
57 jtag_tcktock(); // now in Reset state
59 jtag_tcktock(); // now in Run-Test/Idle state
64 // NOTE: important: THIS MODULE REVOLVES AROUND RETURNING TO RUNTEST/IDLE, OR THE FUNCTIONAL EQUIVALENT
65 //! 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
66 // flags should be 0 for most uses.
67 // for the extreme case, flags should be (NOEND|NORETDLE|LSB)
68 // other edge cases can involve a combination of those three flags
70 // the max bit-size that can be be shifted is 32-bits.
71 // for longer shifts, use the NOEND flag (which infers NORETIDLE so the additional flag is unnecessary)
73 // NORETIDLE is used for special cases where (as with arm) the debug subsystem does not want to
74 // return to the RUN-TEST/IDLE state between setting IR and DR
75 unsigned long jtagtransn(unsigned long word, unsigned char bitcount, unsigned char flags){
77 unsigned long high = 1L;
80 //for (bit=(bitcount-1)/8; bit>0; bit--)
82 //high <<= ((bitcount-1)%8);
83 high <<= (bitcount-1);
89 for (bit = bitcount; bit > 0; bit--) {
90 /* write MOSI on trailing edge of previous clock */
97 if (bit==1 && !(flags & NOEND))
98 SETTMS;//TMS high on last bit to exit.
102 /* read MISO on trailing edge */
108 for (bit = bitcount; bit > 0; bit--) {
109 /* write MOSI on trailing edge of previous clock */
114 word = (word & mask) << 1;
116 if (bit==1 && !(flags & NOEND))
117 SETTMS;//TMS high on last bit to exit.
121 /* read MISO on trailing edge */
130 if (!(flags & NOEND)){
134 if (!(flags & NORETIDLE)){
142 //! Shift 8 bits in and out.
143 unsigned char jtagtrans8(unsigned char byte){
146 for (bit = 0; bit < 8; bit++) {
147 /* write MOSI on trailing edge of previous clock */
155 SETTMS;//TMS high on last bit to exit.
158 /* read MISO on trailing edge */
172 //! Shift n bits in and out.
173 /*unsigned long jtagtransn(unsigned long word,
174 unsigned int bitcount){
177 unsigned long high=0x8000;
186 for (bit = 0; bit < bitcount; bit++) {
187 // write MOSI on trailing edge of previous clock *
195 SETTMS;//TMS high on last bit to exit.
198 // read MISO on trailing edge *
203 word = ((word << 16) | (word >> 4)) & 0x000FFFFF;
218 //! Stop JTAG, release pins
224 unsigned int drwidth=16;
225 //! Shift all bits of the DR.
226 unsigned long jtag_dr_shift20(unsigned long in){
236 // shift DR, then idle
237 return(jtagtransn(in,20,0));
241 //! Shift 16 bits of the DR.
242 unsigned int jtag_dr_shift16(unsigned int in){
252 // shift DR, then idle
253 return(jtagtransn(in,16,0));
256 //! Shift native width of the DR
257 unsigned long jtag_dr_shiftadr(unsigned long in){
270 out=jtagtransn(in,drwidth,0);
272 // shift DR, then idle
277 //! Shift 8 bits of the IR.
278 unsigned char jtag_ir_shift8(unsigned char in){
290 // shift IR, then idle.
291 return(jtagtrans8(in));
294 //! Handles a monitor command.
295 void jtaghandle(unsigned char app,
299 //START handled by specific JTAG
309 cmddata[0]=jtag_ir_shift8(cmddata[0]);
313 cmddataword[0]=jtag_dr_shift16(cmddataword[0]);