2 \author Travis Goodspeed <travis at radiantmachines.com>
13 //! Handles a monitor command.
14 void jtag_handle_fn(uint8_t const app,
18 // define the jtag app's app_t
19 app_t const jtag_app = {
31 "\tThe JTAG app handles basic JTAG operations such as\n"
32 "\tresetting the TAP, resetting the target, detecting\n"
33 "\tthe instruction register width, shifting bits into\n"
34 "\tboth the instruction and data registers.\n"
38 //! Set up the pins for JTAG mode.
51 /************************** JTAG Primitives ****************************/
52 // these have been turned into functions to save flash space
60 void jtag_goto_shift_ir() {
69 void jtag_goto_shift_dr() {
83 jtag_tcktock(); // now in Reset state
85 jtag_tcktock(); // now in Run-Test/Idle state
90 // NOTE: important: THIS MODULE REVOLVES AROUND RETURNING TO RUNTEST/IDLE, OR
91 // THE FUNCTIONAL EQUIVALENT
92 //! Shift N bits over TDI/TDO. May choose LSB or MSB, and select whether to
93 // terminate (TMS-high on last bit) and whether to return to RUNTEST/IDLE
94 // flags should be 0 for most uses.
95 // for the extreme case, flags should be (NOEND|NORETDLE|LSB)
96 // other edge cases can involve a combination of those three flags
98 // the max bit-size that can be be shifted is 32-bits.
99 // for longer shifts, use the NOEND flag (which infers NORETIDLE so the
100 // additional flag is unnecessary)
102 // NORETIDLE is used for special cases where (as with arm) the debug
103 // subsystem does not want to return to the RUN-TEST/IDLE state between
105 unsigned long jtagtransn(unsigned long word,
106 unsigned char bitcount,
107 unsigned char flags) {
109 unsigned long high = 1L;
112 //for (bit=(bitcount-1)/8; bit>0; bit--)
114 //high <<= ((bitcount-1)%8);
115 high <<= (bitcount-1);
121 for (bit = bitcount; bit > 0; bit--) {
122 /* write MOSI on trailing edge of previous clock */
129 if (bit==1 && !(flags & NOEND))
130 SETTMS;//TMS high on last bit to exit.
134 /* read MISO on trailing edge */
140 for (bit = bitcount; bit > 0; bit--) {
141 /* write MOSI on trailing edge of previous clock */
146 word = (word & mask) << 1;
148 if (bit==1 && !(flags & NOEND))
149 SETTMS;//TMS high on last bit to exit.
153 /* read MISO on trailing edge */
162 if (!(flags & NOEND)){
166 if (!(flags & NORETIDLE)){
174 //! Shift 8 bits in and out.
175 unsigned char jtagtrans8(unsigned char byte){
178 for (bit = 0; bit < 8; bit++) {
179 /* write MOSI on trailing edge of previous clock */
187 SETTMS;//TMS high on last bit to exit.
190 /* read MISO on trailing edge */
204 //! Shift n bits in and out.
205 /*unsigned long jtagtransn(unsigned long word,
206 unsigned int bitcount){
209 unsigned long high=0x8000;
218 for (bit = 0; bit < bitcount; bit++) {
219 // write MOSI on trailing edge of previous clock *
227 SETTMS;//TMS high on last bit to exit.
230 // read MISO on trailing edge *
235 word = ((word << 16) | (word >> 4)) & 0x000FFFFF;
250 //! Stop JTAG, release pins
256 unsigned int drwidth=16;
257 //! Shift all bits of the DR.
258 unsigned long jtag_dr_shift20(unsigned long in){
268 // shift DR, then idle
269 return(jtagtransn(in,20,0));
273 //! Shift 16 bits of the DR.
274 unsigned int jtag_dr_shift16(unsigned int in){
284 // shift DR, then idle
285 return(jtagtransn(in,16,0));
288 //! Shift native width of the DR
289 unsigned long jtag_dr_shiftadr(unsigned long in){
302 out=jtagtransn(in,drwidth,0);
304 // shift DR, then idle
309 //! Shift 8 bits of the IR.
310 unsigned char jtag_ir_shift8(unsigned char in){
322 // shift IR, then idle.
323 return(jtagtrans8(in));
326 //! Handles a monitor command.
327 void jtag_handle_fn(uint8_t const app,
333 //START handled by specific JTAG
345 cmddata[0]=jtag_ir_shift8(cmddata[0]);
350 cmddataword[0]=jtag_dr_shift16(cmddataword[0]);