Full commands, even when they contain 0xA7.
[goodfet] / firmware / include / sbw.h
1 /*! \file sbw.h
2   \author Travis Goodspeed and Mark Rages
3   \brief Spy-Bi-Wire Stuff
4 */
5
6 #include "platform.h"
7
8 //IO Pins; these are for EZ430, not GoodFET/UIF
9 #define SBWTCK  BIT3
10 #define SBWTDIO BIT2
11
12 //This should be universal, move to jtag.h
13 #define TCKTOCK CLRTCK,SETTCK
14
15 //If SBW is defined, rewrite JTAG functions to be SBW.
16 #ifdef SBWREWRITE
17 #define jtagsetup sbwsetup
18
19 // I/O Redefintions
20 extern int tms, tdi, tdo;
21 #define SETTMS tms=1
22 #define CLRTMS tms=0
23 #define SETTDI tdi=1
24 #define CLRTDI tdi=0
25 #define TCKTOCK clock_sbw()
26 #define SETMOSI SETTDI
27 #define CLRMOSI CLRTDI
28 #define READMISO tdo
29
30 #endif
31
32 //! Enter SBW mode.
33 void sbwsetup();
34
35 //! Handle a SBW request.
36 void sbwhandle(u8 app, u8 verb, u8 len);
37
38 //! Perform a SBW bit transaction.
39 void clock_sbw();
40 //! Set the TCLK line, performing a transaction.
41 void sbwSETTCLK();
42 //! Clear the line.
43 void sbwCLRTCLK();
44
45 // Macros
46 #define SBWCLK() do { \
47     P5OUT &= ~SBWTCK; \
48     asm("nop");       \
49     asm("nop");       \
50     asm("nop");       \
51     P5OUT |= SBWTCK;  \
52   } while (0)
53 #define SETSBWIO(x) do {                        \
54   if (x)                                        \
55     P5OUT |= SBWTDIO;                           \
56   else                                          \
57     P5OUT &= ~SBWTDIO;                          \
58   } while (0)
59 #undef RESTORETCLK
60 #define RESTORETCLK do {                        \
61     if(savedtclk) {                             \
62       SETTCLK;                                  \
63     } else {                                    \
64       CLRTCLK;                                  \
65     }                                           \
66   } while (0);
67 #undef SETTCLK
68 #define SETTCLK do {                            \
69     sbwSETTCLK();                               \
70     savedtclk=1;                                \
71   } while (0);
72 #undef CLRTCLK
73 #define CLRTCLK do {                            \
74     sbwCLRTCLK();                               \
75     savedtclk=0;                                \
76   } while (0); 
77
78 #undef SAVETCLK
79 //Do nothing for this.
80 #define SAVETCLK 
81
82
83