X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Finclude%2Fsbw.h;fp=firmware%2Finclude%2Fsbw.h;h=3ca606357ebc5d07fd2e65d2c8a588560cae4245;hp=0000000000000000000000000000000000000000;hb=d7ad826230d336ad7b7bd20e47dccc26d7ad456f;hpb=cdc69563892a4e2e085e5d1654b3b397e0e7ec2e diff --git a/firmware/include/sbw.h b/firmware/include/sbw.h new file mode 100644 index 0000000..3ca6063 --- /dev/null +++ b/firmware/include/sbw.h @@ -0,0 +1,82 @@ +/*! \file sbw.h + \author Travis Goodspeed and Mark Rages + \brief Spy-Bi-Wire Stuff +*/ + +//IO Pins; these are for EZ430, not GoodFET/UIF +#define SBWTCK BIT3 +#define SBWTDIO BIT2 + +//This should be universal, move to jtag.h +#define TCKTOCK CLRTCK,SETTCK + +//If SBW is defined, rewrite JTAG functions to be SBW. +#ifdef SBWREWRITE +#define jtagsetup sbwsetup + +// I/O Redefintions +extern int tms, tdi, tdo; +#define SETTMS tms=1 +#define CLRTMS tms=0 +#define SETTDI tdi=1 +#define CLRTDI tdi=0 +#define TCKTOCK clock_sbw() +#define SETMOSI SETTDI +#define CLRMOSI CLRTDI +#define READMISO tdo + +#endif + +//! Enter SBW mode. +void sbwsetup(); + +//! Handle a SBW request. +void sbwhandle(u8 app, u8 verb, u8 len); + +//! Perform a SBW bit transaction. +void clock_sbw(); +//! Set the TCLK line, performing a transaction. +void sbwSETTCLK(); +//! Clear the line. +void sbwCLRTCLK(); + +// Macros + +#define SBWCLK() do { \ + P5OUT &= ~SBWTCK; \ + asm("nop"); \ + asm("nop"); \ + asm("nop"); \ + P5OUT |= SBWTCK; \ + } while (0) +#define SETSBWIO(x) do { \ + if (x) \ + P5OUT |= SBWTDIO; \ + else \ + P5OUT &= ~SBWTDIO; \ + } while (0) +#undef RESTORETCLK +#define RESTORETCLK do { \ + if(savedtclk) { \ + SETTCLK; \ + } else { \ + CLRTCLK; \ + } \ + } while (0); +#undef SETTCLK +#define SETTCLK do { \ + sbwSETTCLK(); \ + savedtclk=1; \ + } while (0); +#undef CLRTCLK +#define CLRTCLK do { \ + sbwCLRTCLK(); \ + savedtclk=0; \ + } while (0); + +#undef SAVETCLK +//Do nothing for this. +#define SAVETCLK + + +