17833d66a3bf6784dd9791199242d476697bbccb
[goodfet] / firmware / include / jtag.h
1
2 #include <signal.h>
3 #include <io.h>
4 #include <iomacros.h>
5
6
7 // Generic Commands
8
9 //! Shift 8 bits of the IR.
10 unsigned char jtag_ir_shift8(unsigned char);
11 //! Shift 16 bits of the DR.
12 unsigned int jtag_dr_shift16(unsigned int);
13 //! Stop JTAG, release pins
14 void jtag_stop();
15
16
17 // JTAG430 Commands
18
19 //! Start JTAG, unique to the '430.
20 void jtag430_start();
21 //! Reset the TAP state machine, check the fuse.
22 void jtag430_resettap();
23
24 //High-level Macros follow
25 //! Write data to address.
26 void jtag430_writemem(unsigned int adr, unsigned int data);
27 //! Read data from address
28 unsigned int jtag430_readmem(unsigned int adr);
29 //! Halt the CPU
30 void jtag430_haltcpu();
31 //! Release the CPU
32 void jtag430_releasecpu();
33 //! Set CPU to Instruction Fetch
34 void jtag430_setinstrfetch();
35 //! Set the program counter.
36 void jtag430_setpc(unsigned int adr);
37 //! Write data to address.
38 void jtag430_writeflash(unsigned int adr, unsigned int data);
39
40 //Pins.  Both SPI and JTAG names are acceptable.
41 //#define SS   BIT0
42 #define MOSI BIT1
43 #define MISO BIT2
44 #define SCK  BIT3
45
46 #define TMS BIT0
47 #define TDI BIT1
48 #define TDO BIT2
49 #define TCK BIT3
50
51 #define TCLK TDI
52
53 //These are not on P5
54 #define RST BIT6
55 #define TST BIT0
56
57 //This could be more accurate.
58 //Does it ever need to be?
59 #define JTAGSPEED 20
60 #define JTAGDELAY(x) delay(x)
61
62 #define SETMOSI P5OUT|=MOSI
63 #define CLRMOSI P5OUT&=~MOSI
64 #define SETCLK P5OUT|=SCK
65 #define CLRCLK P5OUT&=~SCK
66 #define READMISO (P5IN&MISO?1:0)
67 #define SETTMS P5OUT|=TMS
68 #define CLRTMS P5OUT&=~TMS
69 #define SETTCK P5OUT|=TCK
70 #define CLRTCK P5OUT&=~TCK
71 #define SETTDI P5OUT|=TDI
72 #define CLRTDI P5OUT&=~TDI
73
74 #define SETTST P4OUT|=TST
75 #define CLRTST P4OUT&=~TST
76 #define SETRST P2OUT|=RST
77 #define CLRRST P2OUT&=~RST
78
79 #define SETTCLK SETTDI
80 #define CLRTCLK CLRTDI
81
82 extern int savedtclk;
83 #define SAVETCLK savedtclk=P5OUT&TCLK;
84 #define RESTORETCLK if(savedtclk) P5OUT|=TCLK; else P5OUT&=~TCLK
85
86 //JTAG commands, bit-swapped
87 #define IR_CNTRL_SIG_16BIT         0xC8   // 0x13
88 #define IR_CNTRL_SIG_CAPTURE       0x28   // 0x14
89 #define IR_CNTRL_SIG_RELEASE       0xA8   // 0x15
90 // Instructions for the JTAG Fuse
91 #define IR_PREPARE_BLOW            0x44   // 0x22
92 #define IR_EX_BLOW                 0x24   // 0x24
93 // Instructions for the JTAG data register
94 #define IR_DATA_16BIT              0x82   // 0x41
95 #define IR_DATA_QUICK              0xC2   // 0x43
96 // Instructions for the JTAG PSA mode
97 #define IR_DATA_PSA                0x22   // 0x44
98 #define IR_SHIFT_OUT_PSA           0x62   // 0x46
99 // Instructions for the JTAG address register
100 #define IR_ADDR_16BIT              0xC1   // 0x83
101 #define IR_ADDR_CAPTURE            0x21   // 0x84
102 #define IR_DATA_TO_ADDR            0xA1   // 0x85
103 // Bypass instruction
104 #define IR_BYPASS                  0xFF   // 0xFF
105