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