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