a766b06e53505a25c996a836c7f4b47410d0fd07
[goodfet] / firmware / include / jtag.h
1
2 #include <signal.h>
3 #include <io.h>
4 #include <iomacros.h>
5
6
7 extern unsigned int drwidth;
8
9 #define MSP430MODE 0
10 #define MSP430XMODE 1
11 #define MSP430X2MODE 2
12 extern unsigned int jtag430mode;
13
14 // Generic Commands
15
16 //! Shift n bytes.
17 unsigned long jtagtransn(unsigned long word,
18                          unsigned int bitcount);
19 //! Shift 8 bits of the IR.
20 unsigned char jtag_ir_shift8(unsigned char);
21 //! Shift 16 bits of the DR.
22 unsigned int jtag_dr_shift16(unsigned int);
23 //! Shift 20 bits of the DR, MSP430 specific.
24 unsigned long jtag_dr_shift20(unsigned long in);
25 //! Stop JTAG, release pins
26 void jtag_stop();
27
28 //! Setup the JTAG pin directions.
29 void jtagsetup();
30
31 // JTAG430 Commands
32
33 //! Start JTAG, unique to the '430.
34 void jtag430_start();
35 //! Reset the TAP state machine, check the fuse.
36 void jtag430_resettap();
37
38 //! Defined in jtag430asm.S
39 void jtag430_tclk_flashpulses(int);
40
41 //High-level Macros follow
42 //! Write data to address.
43 void jtag430_writemem(unsigned int adr, unsigned int data);
44 //! Read data from address
45 unsigned int jtag430_readmem(unsigned int adr);
46 //! Halt the CPU
47 void jtag430_haltcpu();
48 //! Release the CPU
49 void jtag430_releasecpu();
50 //! Set CPU to Instruction Fetch
51 void jtag430_setinstrfetch();
52 //! Set the program counter.
53 void jtag430_setpc(unsigned int adr);
54 //! Write data to address.
55 void jtag430_writeflash(unsigned int adr, unsigned int data);
56
57 //Pins.  Both SPI and JTAG names are acceptable.
58 //#define SS   BIT0
59 #define MOSI BIT1
60 #define MISO BIT2
61 #define SCK  BIT3
62
63 #define TMS BIT0
64 #define TDI BIT1
65 #define TDO BIT2
66 #define TCK BIT3
67
68 #define TCLK TDI
69
70 //These are not on P5
71 #define RST BIT6
72 #define TST BIT0
73
74 //This could be more accurate.
75 //Does it ever need to be?
76 #define JTAGSPEED 20
77 #define JTAGDELAY(x) delay(x)
78
79 #define SETMOSI P5OUT|=MOSI
80 #define CLRMOSI P5OUT&=~MOSI
81 #define SETCLK P5OUT|=SCK
82 #define CLRCLK P5OUT&=~SCK
83 #define READMISO (P5IN&MISO?1:0)
84 #define SETTMS P5OUT|=TMS
85 #define CLRTMS P5OUT&=~TMS
86 #define SETTCK P5OUT|=TCK
87 #define CLRTCK P5OUT&=~TCK
88 #define SETTDI P5OUT|=TDI
89 #define CLRTDI P5OUT&=~TDI
90
91 #define SETTST P4OUT|=TST
92 #define CLRTST P4OUT&=~TST
93 #define SETRST P2OUT|=RST
94 #define CLRRST P2OUT&=~RST
95
96 #define SETTCLK SETTDI
97 #define CLRTCLK CLRTDI
98
99 extern int savedtclk;
100 #define SAVETCLK savedtclk=P5OUT&TCLK;
101 #define RESTORETCLK if(savedtclk) P5OUT|=TCLK; else P5OUT&=~TCLK
102
103
104 //16-bit MSP430 JTAG commands, bit-swapped
105 #define IR_CNTRL_SIG_16BIT         0xC8   // 0x13
106 #define IR_CNTRL_SIG_CAPTURE       0x28   // 0x14
107 #define IR_CNTRL_SIG_RELEASE       0xA8   // 0x15
108 // Instructions for the JTAG Fuse
109 #define IR_PREPARE_BLOW            0x44   // 0x22
110 #define IR_EX_BLOW                 0x24   // 0x24
111 // Instructions for the JTAG data register
112 #define IR_DATA_16BIT              0x82   // 0x41
113 #define IR_DATA_QUICK              0xC2   // 0x43
114 // Instructions for the JTAG PSA mode
115 #define IR_DATA_PSA                0x22   // 0x44
116 #define IR_SHIFT_OUT_PSA           0x62   // 0x46
117 // Instructions for the JTAG address register
118 #define IR_ADDR_16BIT              0xC1   // 0x83
119 #define IR_ADDR_CAPTURE            0x21   // 0x84
120 #define IR_DATA_TO_ADDR            0xA1   // 0x85
121 // Bypass instruction
122 #define IR_BYPASS                  0xFF   // 0xFF
123
124 //MSP430X2 unique
125 #define IR_COREIP_ID               0xE8   // 0x17 
126 #define IR_DEVICE_ID               0xE1   // 0x87
127
128 //MSP430 or MSP430X
129 #define MSP430JTAGID 0x89
130 //MSP430X2 only
131 #define MSP430X2JTAGID 0x91
132
133 //! Syncs a POR.
134 unsigned int jtag430x2_syncpor();
135 //! Executes an MSP430X2 POR
136 unsigned int jtag430x2_por();