X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fjtag%2Fjtag.c;h=14e87617edd1a48e57b32c658b9b345ff6870a79;hp=2b04a81ea9e793b878a21606c6d6435ca53f97b6;hb=1283fdb830f9ecd0e27e10ef66927562aff674a7;hpb=3bf98a899ca8003835b69d949d299369a5d7a4f7;ds=sidebyside diff --git a/firmware/apps/jtag/jtag.c b/firmware/apps/jtag/jtag.c index 2b04a81..14e8761 100644 --- a/firmware/apps/jtag/jtag.c +++ b/firmware/apps/jtag/jtag.c @@ -8,15 +8,15 @@ #include "jtag.h" - - //! Set up the pins for JTAG mode. void jtagsetup(){ P5DIR|=MOSI+SCK+TMS; P5DIR&=~MISO; P5OUT|=0xFFFF; + P5OUT=0; P4DIR|=TST; P2DIR|=RST; + msdelay(100); } int savedtclk=0; @@ -53,13 +53,62 @@ unsigned char jtagtrans8(unsigned char byte){ return byte; } -//! Shift 8 bits in and out. -unsigned int jtagtrans16(unsigned int word){ +//! Shift n bits in and out. +unsigned long jtagtransn(unsigned long word, + unsigned int bitcount){ unsigned int bit; + //0x8000 + unsigned long high; + + if(bitcount==20) + high=0x80000; + if(bitcount==16) + high= 0x8000; + SAVETCLK; - for (bit = 0; bit < 16; bit++) { + for (bit = 0; bit < bitcount; bit++) { /* write MOSI on trailing edge of previous clock */ + if (word & high) + {SETMOSI;} + else + {CLRMOSI;} + word <<= 1; + + if(bit==bitcount-1) + SETTMS;//TMS high on last bit to exit. + + CLRTCK; + SETTCK; + /* read MISO on trailing edge */ + word |= READMISO; + } + + if(bitcount==20){ + word = ((word << 16) | (word >> 4)) & 0x000FFFFF; + } + + RESTORETCLK; + + // exit state + CLRTCK; + SETTCK; + // update state + CLRTMS; + CLRTCK; + SETTCK; + + 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 @@ -71,7 +120,7 @@ unsigned int jtagtrans16(unsigned int word){ CLRTCK; SETTCK; - /* read MISO on trailing edge */ + // read MISO on trailing edge word |= READMISO; } RESTORETCLK; @@ -85,7 +134,7 @@ unsigned int jtagtrans16(unsigned int word){ SETTCK; return word; -} +}*/ //! Stop JTAG, release pins void jtag_stop(){ @@ -93,6 +142,25 @@ void jtag_stop(){ P4OUT=0; } +unsigned int drwidth=20; +//! Shift all bits of the DR. +unsigned long jtag_dr_shift20(unsigned long in){ + // idle + SETTMS; + CLRTCK; + SETTCK; + // select DR + CLRTMS; + CLRTCK; + SETTCK; + // capture IR + CLRTCK; + SETTCK; + + // shift DR, then idle + return(jtagtransn(in,20)); +} + //! Shift 16 bits of the DR. unsigned int jtag_dr_shift16(unsigned int in){ @@ -107,9 +175,9 @@ unsigned int jtag_dr_shift16(unsigned int in){ // capture IR CLRTCK; SETTCK; - + // shift DR, then idle - return(jtagtrans16(in)); + return(jtagtransn(in,16)); }