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