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