X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fjtag%2Fjtag.c;h=d0d2118b0543fd3195b1de4973022e501ad03047;hp=5abba15cb43d6cee14365179c5b8f38f1a01c690;hb=5c029aa0c4f7573d9fa49beefe6e887dee2b25f9;hpb=3e4369fde16445c994da1b1efb332704aad0716d;ds=sidebyside diff --git a/firmware/apps/jtag/jtag.c b/firmware/apps/jtag/jtag.c index 5abba15..d0d2118 100644 --- a/firmware/apps/jtag/jtag.c +++ b/firmware/apps/jtag/jtag.c @@ -1,7 +1,8 @@ -//GoodFET JTAG Application -//Handles basic I/O +/*! \file jtag.c + \author Travis Goodspeed + \brief Low-level JTAG +*/ -//Higher level left to client application. #include "platform.h" #include "command.h" @@ -12,9 +13,13 @@ void jtagsetup(){ P5DIR|=MOSI+SCK+TMS; P5DIR&=~MISO; + /* P5OUT|=0xFFFF; + P5OUT=0; + */ P4DIR|=TST; P2DIR|=RST; + msdelay(100); } int savedtclk=0; @@ -33,20 +38,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; } @@ -55,14 +57,19 @@ unsigned char jtagtrans8(unsigned char byte){ unsigned long jtagtransn(unsigned long word, unsigned int bitcount){ unsigned int bit; - unsigned int high=(word>>16); - SAVETCLK; + //0x8000 + unsigned long high=0x8000; + if(bitcount==20) + high=0x80000; + if(bitcount==16) + high= 0x8000; + SAVETCLK; for (bit = 0; bit < bitcount; bit++) { /* write MOSI on trailing edge of previous clock */ - if (word & 0x8000) + if (word & high) {SETMOSI;} else {CLRMOSI;} @@ -71,8 +78,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; } @@ -84,50 +90,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(){ @@ -135,30 +105,56 @@ void jtag_stop(){ P4OUT=0; } -unsigned int drwidth=20; +unsigned int drwidth=16; //! Shift all bits of the DR. -unsigned long jtag_dr_shift(unsigned long in){ +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,drwidth)); + return(jtagtransn(in,20)); } //! 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); + // idle + SETTMS; + TCKTOCK; + // select DR + CLRTMS; + TCKTOCK; + // capture IR + 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); } @@ -166,18 +162,14 @@ unsigned int jtag_dr_shift16(unsigned int in){ 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)); @@ -186,7 +178,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: