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