Bringing back MSP430X2 JTAG. Not there yet.
[goodfet] / firmware / include / jtag.h
1 /*! \file jtag.h
2   \author Travis Goodspeed
3   \brief JTAG handler functions.
4 */
5
6 #ifndef JTAG_H
7 #define JTAG_H
8
9 #include "app.h"
10
11 #define JTAG 0x10
12
13 //! JTAG device ID.
14 extern unsigned char jtagid;
15
16
17 // Generic Commands
18
19 //! Shift n bytes.
20 unsigned long jtagtransn(unsigned long word,
21                          unsigned char bitcount,
22              unsigned char flags);
23 //! Shift the address width.
24 unsigned long jtag_dr_shiftadr(unsigned long in);
25 //! Shift 8 bits of the IR.
26 unsigned char jtag_ir_shift8(unsigned char);
27 //! Shift 16 bits of the DR.
28 unsigned int jtag_dr_shift16(unsigned int);
29 //! Shift 20 bits of the DR, MSP430 specific.
30 unsigned long jtag_dr_shift20(unsigned long in);
31 //! Stop JTAG, release pins
32 void jtag_stop();
33
34 //! Setup the JTAG pin directions.
35 void jtagsetup();
36
37 //! Ratchet Clock Down and Up
38 void jtag_tcktock();
39 //! Go to SHIFT_IR
40 void jtag_goto_shift_ir();
41 //! Go to SHIFT_DR
42 void jtag_goto_shift_dr();
43 //! TAP RESET
44 void jtag_resettap();
45
46 //Pins.  Both SPI and JTAG names are acceptable.
47 //#define SS   BIT0
48 #define MOSI BIT1
49 #define MISO BIT2
50 #define SCK  BIT3
51
52 #define TMS BIT0
53 #define TDI BIT1
54 #define TDO BIT2
55 #define TCK BIT3
56
57 #define TCLK TDI
58
59 //These are not on P5
60 #define RST BIT6
61 #define TST BIT0
62
63 //This could be more accurate.
64 //Does it ever need to be?
65 #define JTAGSPEED 20
66 #define JTAGDELAY(x) delay(x)
67
68 #define SETMOSI P5OUT|=MOSI
69 #define CLRMOSI P5OUT&=~MOSI
70 #define SETCLK P5OUT|=SCK
71 #define CLRCLK P5OUT&=~SCK
72 #define READMISO (P5IN&MISO?1:0)
73 #define SETTMS P5OUT|=TMS
74 #define CLRTMS P5OUT&=~TMS
75 #define SETTCK P5OUT|=TCK
76 #define CLRTCK P5OUT&=~TCK
77 #define SETTDI P5OUT|=TDI
78 #define CLRTDI P5OUT&=~TDI
79
80 #define SETTST P4OUT|=TST
81 #define CLRTST P4OUT&=~TST
82 #define SETRST P2OUT|=RST
83 #define CLRRST P2OUT&=~RST
84
85 #define SETTCLK SETTDI
86 #define CLRTCLK CLRTDI
87
88 extern int savedtclk;
89 #define SAVETCLK savedtclk=P5OUT&TCLK;
90 #define RESTORETCLK if(savedtclk) P5OUT|=TCLK; else P5OUT&=~TCLK
91
92 //Replace every "CLRTCK SETTCK" with this.
93 #define TCKTOCK CLRTCK,SETTCK
94
95 //JTAG commands
96 #define JTAG_IR_SHIFT 0x80
97 #define JTAG_DR_SHIFT 0x81
98 #define JTAG_RESETTAP 0x82
99 #define JTAG_RESETTARGET 0x83
100 #define JTAG_DR_SHIFT20 0x91
101
102 #define MSB         0
103 #define LSB         1
104 #define NOEND       2
105 #define NORETIDLE   4
106
107 //JTAG430 commands
108 #define Exit2_DR 0x0
109 #define Exit_DR 0x1
110 #define Shift_DR 0x2
111 #define Pause_DR 0x3
112 #define Select_IR 0x4
113 #define Update_DR 0x5
114 #define Capture_DR 0x6
115 #define Select_DR 0x7
116 #define Exit2_IR 0x8
117 #define Exit_IR 0x9
118 #define Shift_IR 0xa
119 #define Pause_IR 0xb
120 #define RunTest_Idle 0xc
121 #define Update_IR 0xd
122 #define Capture_IR 0xe
123 #define Test_Reset 0xf
124
125 extern app_t const jtag_app;
126
127 #endif