X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=firmware%2Fapps%2Fjtag%2Fjtag.c;h=d9193e895fa5dd9c95249b66f76653e66595efd5;hb=93abf8b177c06d34457856d7a8b53720e5cb3414;hp=cf9199d90fbca16c6ced460f7cb9fd2aa352fa59;hpb=ce0bba3cfbf4844bdce1f6984af24d1f78c347f1;p=goodfet diff --git a/firmware/apps/jtag/jtag.c b/firmware/apps/jtag/jtag.c index cf9199d..d9193e8 100644 --- a/firmware/apps/jtag/jtag.c +++ b/firmware/apps/jtag/jtag.c @@ -1,10 +1,6 @@ /*! \file jtag.c \author Travis Goodspeed - - This is an implementation of the low-level JTAG functions - for the GoodFET project at http://goodfet.sf.net/ - - See the license file for details of proper use. + \brief Low-level JTAG */ @@ -40,20 +36,17 @@ unsigned char jtagtrans8(unsigned char byte){ if(bit==7) SETTMS;//TMS high on last bit to exit. - CLRTCK; - SETTCK; - /* read MISO on trailing edge */ + TCKTOCK; + /* read MISO on trailing edge */ byte |= READMISO; } RESTORETCLK; // exit state - CLRTCK; - SETTCK; + TCKTOCK; // update state CLRTMS; - CLRTCK; - SETTCK; + TCKTOCK; return byte; } @@ -63,7 +56,7 @@ unsigned long jtagtransn(unsigned long word, unsigned int bitcount){ unsigned int bit; //0x8000 - unsigned long high; + unsigned long high=0x8000; if(bitcount==20) high=0x80000; @@ -83,8 +76,7 @@ unsigned long jtagtransn(unsigned long word, if(bit==bitcount-1) SETTMS;//TMS high on last bit to exit. - CLRTCK; - SETTCK; + TCKTOCK; /* read MISO on trailing edge */ word |= READMISO; } @@ -96,50 +88,14 @@ unsigned long jtagtransn(unsigned long word, RESTORETCLK; // exit state - CLRTCK; - SETTCK; + TCKTOCK; // update state CLRTMS; - CLRTCK; - SETTCK; + TCKTOCK; return word; } -/* -//! Shift 16 bits in and out. -unsigned int jtagtrans16(unsigned int word){ //REMOVEME - unsigned int bit; - SAVETCLK; - - for (bit = 0; bit < 16; bit++) { - // write MOSI on trailing edge of previous clock - if (word & 0x8000) - {SETMOSI;} - else - {CLRMOSI;} - word <<= 1; - - if(bit==15) - SETTMS;//TMS high on last bit to exit. - - CLRTCK; - SETTCK; - // read MISO on trailing edge - word |= READMISO; - } - RESTORETCLK; - - // exit state - CLRTCK; - SETTCK; - // update state - CLRTMS; - CLRTCK; - SETTCK; - - return word; -}*/ //! Stop JTAG, release pins void jtag_stop(){ @@ -147,20 +103,17 @@ void jtag_stop(){ P4OUT=0; } -unsigned int drwidth=20; +unsigned int drwidth=16; //! Shift all bits of the DR. unsigned long jtag_dr_shift20(unsigned long in){ // idle SETTMS; - CLRTCK; - SETTCK; + TCKTOCK; // select DR CLRTMS; - CLRTCK; - SETTCK; + TCKTOCK; // capture IR - CLRTCK; - SETTCK; + TCKTOCK; // shift DR, then idle return(jtagtransn(in,20)); @@ -171,37 +124,50 @@ unsigned long jtag_dr_shift20(unsigned long in){ unsigned int jtag_dr_shift16(unsigned int in){ // idle SETTMS; - CLRTCK; - SETTCK; + TCKTOCK; // select DR CLRTMS; - CLRTCK; - SETTCK; + TCKTOCK; // capture IR - CLRTCK; - SETTCK; + TCKTOCK; // shift DR, then idle return(jtagtransn(in,16)); } +//! Shift native width of the DR +unsigned long jtag_dr_shiftadr(unsigned long in){ + unsigned long out=0; + + // idle + SETTMS; + TCKTOCK; + // select DR + CLRTMS; + TCKTOCK; + // capture IR + TCKTOCK; + + + out=jtagtransn(in,drwidth); + + // shift DR, then idle + return(out); +} + //! Shift 8 bits of the IR. unsigned char jtag_ir_shift8(unsigned char in){ // idle SETTMS; - CLRTCK; - SETTCK; + TCKTOCK; // select DR - CLRTCK; - SETTCK; + TCKTOCK; // select IR CLRTMS; - CLRTCK; - SETTCK; + TCKTOCK; // capture IR - CLRTCK; - SETTCK; + TCKTOCK; // shift IR, then idle. return(jtagtrans8(in)); @@ -210,7 +176,7 @@ unsigned char jtag_ir_shift8(unsigned char in){ //! Handles a monitor command. void jtaghandle(unsigned char app, unsigned char verb, - unsigned char len){ + unsigned long len){ switch(verb){ //START handled by specific JTAG case STOP: