Refactoring a lot of the P5 stuff.
[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
69 #define SETMOSI SPIOUT|=MOSI
70 #define CLRMOSI SPIOUT&=~MOSI
71 #define SETCLK SPIOUT|=SCK
72 #define CLRCLK SPIOUT&=~SCK
73 #define READMISO (SPIIN&MISO?1:0)
74 #define SETTMS SPIOUT|=TMS
75 #define CLRTMS SPIOUT&=~TMS
76 #define SETTCK SPIOUT|=TCK
77 #define CLRTCK SPIOUT&=~TCK
78 #define SETTDI SPIOUT|=TDI
79 #define CLRTDI SPIOUT&=~TDI
80
81 #define SETTST P4OUT|=TST
82 #define CLRTST P4OUT&=~TST
83 #define SETRST P2OUT|=RST
84 #define CLRRST P2OUT&=~RST
85
86 #define SETTCLK SETTDI
87 #define CLRTCLK CLRTDI
88
89 extern int savedtclk;
90 #define SAVETCLK savedtclk=SPIOUT&TCLK;
91 #define RESTORETCLK if(savedtclk) SPIOUT|=TCLK; else SPIOUT&=~TCLK
92
93 //Replace every "CLRTCK SETTCK" with this.
94 #define TCKTOCK CLRTCK,SETTCK
95
96 //JTAG commands
97 #define JTAG_IR_SHIFT 0x80
98 #define JTAG_DR_SHIFT 0x81
99 #define JTAG_RESETTAP 0x82
100 #define JTAG_RESETTARGET 0x83
101 #define JTAG_DR_SHIFT20 0x91
102
103 #define MSB         0
104 #define LSB         1
105 #define NOEND       2
106 #define NORETIDLE   4
107
108 //JTAG430 commands
109 #define Exit2_DR 0x0
110 #define Exit_DR 0x1
111 #define Shift_DR 0x2
112 #define Pause_DR 0x3
113 #define Select_IR 0x4
114 #define Update_DR 0x5
115 #define Capture_DR 0x6
116 #define Select_DR 0x7
117 #define Exit2_IR 0x8
118 #define Exit_IR 0x9
119 #define Shift_IR 0xa
120 #define Pause_IR 0xb
121 #define RunTest_Idle 0xc
122 #define Update_IR 0xd
123 #define Capture_IR 0xe
124 #define Test_Reset 0xf
125
126 extern app_t const jtag_app;
127
128 #endif