X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fjtag%2Fjtag.c;h=5abba15cb43d6cee14365179c5b8f38f1a01c690;hp=cffec3d248ac99fb473cb625bf24d1251207d63b;hb=3e4369fde16445c994da1b1efb332704aad0716d;hpb=ff6e482b1ca3d0b0657baa03d4184618ededbfa4 diff --git a/firmware/apps/jtag/jtag.c b/firmware/apps/jtag/jtag.c index cffec3d..5abba15 100644 --- a/firmware/apps/jtag/jtag.c +++ b/firmware/apps/jtag/jtag.c @@ -8,10 +8,8 @@ #include "jtag.h" - - //! Set up the pins for JTAG mode. -unsigned char jtagsetup(){ +void jtagsetup(){ P5DIR|=MOSI+SCK+TMS; P5DIR&=~MISO; P5OUT|=0xFFFF; @@ -27,9 +25,9 @@ unsigned char jtagtrans8(unsigned char byte){ for (bit = 0; bit < 8; bit++) { /* write MOSI on trailing edge of previous clock */ if (byte & 0x80) - SETMOSI; + {SETMOSI;} else - CLRMOSI; + {CLRMOSI;} byte <<= 1; if(bit==7) @@ -53,27 +51,36 @@ 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; + unsigned int high=(word>>16); SAVETCLK; - for (bit = 0; bit < 16; bit++) { + + + for (bit = 0; bit < bitcount; bit++) { /* write MOSI on trailing edge of previous clock */ if (word & 0x8000) - SETMOSI; + {SETMOSI;} else - CLRMOSI; + {CLRMOSI;} word <<= 1; - if(bit==15) + if(bit==bitcount-1) SETTMS;//TMS high on last bit to exit. CLRTCK; SETTCK; - /* read MISO on trailing edge */ + /* read MISO on trailing edge */ word |= READMISO; } + + if(bitcount==20){ + word = ((word << 16) | (word >> 4)) & 0x000FFFFF; + } + RESTORETCLK; // exit state @@ -87,15 +94,50 @@ unsigned int jtagtrans16(unsigned int word){ 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(){ P5OUT=0; P4OUT=0; } - -//! Shift 16 bits of the DR. -unsigned int jtag_dr_shift16(unsigned int in){ +unsigned int drwidth=20; +//! Shift all bits of the DR. +unsigned long jtag_dr_shift(unsigned long in){ // idle SETTMS; CLRTCK; @@ -107,9 +149,16 @@ unsigned int jtag_dr_shift16(unsigned int in){ // capture IR CLRTCK; SETTCK; - + // shift DR, then idle - return(jtagtrans16(in)); + return(jtagtransn(in,drwidth)); +} + + +//! Shift 16 bits of the DR. +unsigned int jtag_dr_shift16(unsigned int in){ + //This name is deprecated, kept around to find 16-bit dependent code. + return jtag_dr_shift(in); }