2 \author Travis Goodspeed
3 \brief JTAG handler functions.
14 extern unsigned int drwidth;
18 #define MSP430X2MODE 2
19 extern unsigned int jtag430mode;
24 unsigned long jtagtransn(unsigned long word,
25 unsigned int bitcount);
26 //! Shift the address width.
27 unsigned long jtag_dr_shiftadr(unsigned long in);
28 //! Shift 8 bits of the IR.
29 unsigned char jtag_ir_shift8(unsigned char);
30 //! Shift 16 bits of the DR.
31 unsigned int jtag_dr_shift16(unsigned int);
32 //! Shift 20 bits of the DR, MSP430 specific.
33 unsigned long jtag_dr_shift20(unsigned long in);
34 //! Stop JTAG, release pins
37 //! Setup the JTAG pin directions.
42 //! Start JTAG, unique to the '430.
44 //! Reset the TAP state machine, check the fuse.
45 void jtag430_resettap();
47 //! Defined in jtag430asm.S
48 void jtag430_tclk_flashpulses(int);
50 //High-level Macros follow
51 //! Write data to address.
52 void jtag430_writemem(unsigned int adr, unsigned int data);
53 //! Read data from address
54 unsigned int jtag430_readmem(unsigned int adr);
56 void jtag430_haltcpu();
58 void jtag430_releasecpu();
59 //! Set CPU to Instruction Fetch
60 void jtag430_setinstrfetch();
61 //! Set the program counter.
62 void jtag430_setpc(unsigned int adr);
63 //! Write data to address.
64 void jtag430_writeflash(unsigned int adr, unsigned int data);
66 //Pins. Both SPI and JTAG names are acceptable.
83 //This could be more accurate.
84 //Does it ever need to be?
86 #define JTAGDELAY(x) delay(x)
88 #define SETMOSI P5OUT|=MOSI
89 #define CLRMOSI P5OUT&=~MOSI
90 #define SETCLK P5OUT|=SCK
91 #define CLRCLK P5OUT&=~SCK
92 #define READMISO (P5IN&MISO?1:0)
93 #define SETTMS P5OUT|=TMS
94 #define CLRTMS P5OUT&=~TMS
95 #define SETTCK P5OUT|=TCK
96 #define CLRTCK P5OUT&=~TCK
97 #define SETTDI P5OUT|=TDI
98 #define CLRTDI P5OUT&=~TDI
100 #define SETTST P4OUT|=TST
101 #define CLRTST P4OUT&=~TST
102 #define SETRST P2OUT|=RST
103 #define CLRRST P2OUT&=~RST
105 #define SETTCLK SETTDI
106 #define CLRTCLK CLRTDI
108 extern int savedtclk;
109 #define SAVETCLK savedtclk=P5OUT&TCLK;
110 #define RESTORETCLK if(savedtclk) P5OUT|=TCLK; else P5OUT&=~TCLK
112 //Replace every "CLRTCK SETTCK" with this.
113 #define TCKTOCK CLRTCK,SETTCK
116 //16-bit MSP430 JTAG commands, bit-swapped
117 //Rewrite these with MSP430 prefix.
118 #define IR_CNTRL_SIG_16BIT 0xC8 // 0x13
119 #define IR_CNTRL_SIG_CAPTURE 0x28 // 0x14
120 #define IR_CNTRL_SIG_RELEASE 0xA8 // 0x15
121 // Instructions for the JTAG Fuse
122 #define IR_PREPARE_BLOW 0x44 // 0x22
123 #define IR_EX_BLOW 0x24 // 0x24
124 // Instructions for the JTAG data register
125 #define IR_DATA_16BIT 0x82 // 0x41
126 #define IR_DATA_QUICK 0xC2 // 0x43
127 // Instructions for the JTAG PSA mode
128 #define IR_DATA_PSA 0x22 // 0x44
129 #define IR_SHIFT_OUT_PSA 0x62 // 0x46
130 // Instructions for the JTAG address register
131 #define IR_ADDR_16BIT 0xC1 // 0x83
132 #define IR_ADDR_CAPTURE 0x21 // 0x84
133 #define IR_DATA_TO_ADDR 0xA1 // 0x85
134 // Bypass instruction
135 #define IR_BYPASS 0xFF // 0xFF
138 #define IR_COREIP_ID 0xE8 // 0x17
139 #define IR_DEVICE_ID 0xE1 // 0x87
142 #define MSP430JTAGID 0x89
144 #define MSP430X2JTAGID 0x91
147 unsigned int jtag430x2_syncpor();
148 //! Executes an MSP430X2 POR
149 unsigned int jtag430x2_por();
154 #define JTAG_IR_SHIFT 0x80
155 #define JTAG_DR_SHIFT 0x81
156 #define JTAG_DR_SHIFT20 0x91