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