2 \author Travis Goodspeed
3 \brief JTAG handler functions.
13 //! All states in the JTAG TAP
17 TEST_LOGIC_RESET = 0x0001,
18 RUN_TEST_IDLE = 0x0002,
19 SELECT_DR_SCAN = 0x0004,
26 SELECT_IR_SCAN = 0x0200,
35 extern unsigned char jtagid;
37 //! the global state of the JTAG TAP
38 extern enum eTAPState jtag_state;
40 //! Returns true if we're in any of the data register states
42 //! Returns true if we're in any of the instruction register states
44 //! Returns true if we're in run-test-idle state
45 int in_run_test_idle();
47 int in_state(enum eTAPState state);
49 //! jtag_trans_n flags
59 uint32_t jtag_trans_n(uint32_t word,
61 enum eTransFlags flags);
62 //! Shift 8 bits in/out of selected register
63 uint8_t jtag_trans_8(uint8_t in);
64 //! Shift 16 bits in/out of selected register
65 uint16_t jtag_trans_16(uint16_t in);
66 //! Shift 8 bits of the IR.
67 uint8_t jtag_ir_shift_8(uint8_t in);
68 //! Shift 16 bits of the DR.
69 uint16_t jtag_dr_shift_16(uint16_t in);
70 //! Stop JTAG, release pins
72 //! Setup the JTAG pin directions.
74 //! Ratchet Clock Down and Up
76 //! Reset the target device
77 void jtag_reset_target();
79 void jtag_reset_tap();
80 //! Get into the Shift-IR or Shift-DR
81 void jtag_shift_register();
82 //! Get into Capture-IR state
83 void jtag_capture_ir();
84 //! Get into Capture-DR state
85 void jtag_capture_dr();
86 //! Get to Run-Test-Idle without going through Test-Logic-Reset
87 void jtag_run_test_idle();
88 //! Detect instruction register width
89 uint16_t jtag_detect_ir_width();
90 //! Detects how many TAPs are in the JTAG chain
91 uint16_t jtag_detect_chain_length();
92 //! Gets device ID for specified chip in the chain
93 uint32_t jtag_get_device_id(int chip);
95 //Pins. Both SPI and JTAG names are acceptable.
108 //These are not on P5
112 //This could be more accurate.
113 //Does it ever need to be?
115 #define JTAGDELAY(x) delay(x)
118 #define SETMOSI SPIOUT|=MOSI
119 #define CLRMOSI SPIOUT&=~MOSI
120 #define SETCLK SPIOUT|=SCK
121 #define CLRCLK SPIOUT&=~SCK
122 #define READMISO (SPIIN&MISO?1:0)
123 #define SETTMS SPIOUT|=TMS
124 #define CLRTMS SPIOUT&=~TMS
125 #define SETTCK SPIOUT|=TCK
126 #define CLRTCK SPIOUT&=~TCK
127 #define SETTDI SPIOUT|=TDI
128 #define CLRTDI SPIOUT&=~TDI
130 #define SETTST P4OUT|=TST
131 #define CLRTST P4OUT&=~TST
132 #define SETRST P2OUT|=RST
133 #define CLRRST P2OUT&=~RST
135 #define SETTCLK SETTDI
136 #define CLRTCLK CLRTDI
138 extern int savedtclk;
139 #define SAVETCLK savedtclk=SPIOUT&TCLK;
140 #define RESTORETCLK if(savedtclk) SPIOUT|=TCLK; else SPIOUT&=~TCLK
143 #define JTAG_IR_SHIFT 0x80
144 #define JTAG_DR_SHIFT 0x81
145 #define JTAG_RESET_TAP 0x82
146 #define JTAG_RESET_TARGET 0x83
147 #define JTAG_DETECT_IR_WIDTH 0x84
148 #define JTAG_DETECT_CHAIN_LENGTH 0x85
149 #define JTAG_GET_DEVICE_ID 0x86
150 #define JTAG_DR_SHIFT_MORE 0x87 // used for shiftings > 32bits. assumes JTAG_DR_SHIFT with NOEND first
151 //#define JTAG_DR_SHIFT20 0x91
153 extern app_t const jtag_app;