X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Finclude%2Fjtag.h;h=5baaf296f8830e863fae1565685f209f7cc0c644;hp=1ef3b79b967898f1b8e13fae9a9093bf736de520;hb=a031b4a563978102c664466d1e91a9c3ab0553dd;hpb=eddb0eb08f187dc156a6cb51878104df67d97436 diff --git a/firmware/include/jtag.h b/firmware/include/jtag.h index 1ef3b79..5baaf29 100644 --- a/firmware/include/jtag.h +++ b/firmware/include/jtag.h @@ -3,60 +3,94 @@ \brief JTAG handler functions. */ -#include -#include -#include - - -extern unsigned int drwidth; - -#define MSP430MODE 0 -#define MSP430XMODE 1 -#define MSP430X2MODE 2 -extern unsigned int jtag430mode; - -// Generic Commands +#ifndef JTAG_H +#define JTAG_H + +#include "app.h" + +#define JTAG 0x10 + +//! All states in the JTAG TAP +enum eTAPState +{ + UNKNOWN = 0x0000, + TEST_LOGIC_RESET = 0x0001, + RUN_TEST_IDLE = 0x0002, + SELECT_DR_SCAN = 0x0004, + CAPTURE_DR = 0x0008, + SHIFT_DR = 0x0010, + EXIT1_DR = 0x0020, + PAUSE_DR = 0x0040, + EXIT2_DR = 0x0080, + UPDATE_DR = 0x0100, + SELECT_IR_SCAN = 0x0200, + CAPTURE_IR = 0x0400, + SHIFT_IR = 0x0800, + EXIT1_IR = 0x1000, + PAUSE_IR = 0x2000, + EXIT2_IR = 0x4000, + UPDATE_IR = 0x8000 +}; + +extern unsigned char jtagid; + +//! the global state of the JTAG TAP +extern enum eTAPState jtag_state; + +//! Returns true if we're in any of the data register states +int in_dr(); +//! Returns true if we're in any of the instruction register states +int in_ir(); +//! Returns true if we're in run-test-idle state +int in_run_test_idle(); +//! Check the state +int in_state(enum eTAPState state); + +//! jtag_trans_n flags +enum eTransFlags +{ + MSB = 0x0, + LSB = 0x1, + NOEND = 0x2, + NORETIDLE = 0x4 +}; //! Shift n bytes. -unsigned long jtagtransn(unsigned long word, - unsigned int bitcount); +uint32_t jtag_trans_n(uint32_t word, + uint8_t bitcount, + enum eTransFlags flags); +//! Shift 8 bits in/out of selected register +uint8_t jtag_trans_8(uint8_t in); +//! Shift 16 bits in/out of selected register +uint16_t jtag_trans_16(uint16_t in); //! Shift 8 bits of the IR. -unsigned char jtag_ir_shift8(unsigned char); +uint8_t jtag_ir_shift_8(uint8_t in); //! Shift 16 bits of the DR. -unsigned int jtag_dr_shift16(unsigned int); -//! Shift 20 bits of the DR, MSP430 specific. -unsigned long jtag_dr_shift20(unsigned long in); +uint16_t jtag_dr_shift_16(uint16_t in); //! Stop JTAG, release pins void jtag_stop(); - //! Setup the JTAG pin directions. -void jtagsetup(); - -// JTAG430 Commands - -//! Start JTAG, unique to the '430. -void jtag430_start(); -//! Reset the TAP state machine, check the fuse. -void jtag430_resettap(); - -//! Defined in jtag430asm.S -void jtag430_tclk_flashpulses(int); - -//High-level Macros follow -//! Write data to address. -void jtag430_writemem(unsigned int adr, unsigned int data); -//! Read data from address -unsigned int jtag430_readmem(unsigned int adr); -//! Halt the CPU -void jtag430_haltcpu(); -//! Release the CPU -void jtag430_releasecpu(); -//! Set CPU to Instruction Fetch -void jtag430_setinstrfetch(); -//! Set the program counter. -void jtag430_setpc(unsigned int adr); -//! Write data to address. -void jtag430_writeflash(unsigned int adr, unsigned int data); +void jtag_setup(); +//! Ratchet Clock Down and Up +void jtag_tcktock(); +//! Reset the target device +void jtag_reset_target(); +//! TAP RESET +void jtag_reset_tap(); +//! Get into the Shift-IR or Shift-DR +void jtag_shift_register(); +//! Get into Capture-IR state +void jtag_capture_ir(); +//! Get into Capture-DR state +void jtag_capture_dr(); +//! Get to Run-Test-Idle without going through Test-Logic-Reset +void jtag_run_test_idle(); +//! Detect instruction register width +uint16_t jtag_detect_ir_width(); +//! Detects how many TAPs are in the JTAG chain +uint16_t jtag_detect_chain_length(); +//! Gets device ID for specified chip in the chain +uint32_t jtag_get_device_id(int chip); //Pins. Both SPI and JTAG names are acceptable. //#define SS BIT0 @@ -80,17 +114,18 @@ void jtag430_writeflash(unsigned int adr, unsigned int data); #define JTAGSPEED 20 #define JTAGDELAY(x) delay(x) -#define SETMOSI P5OUT|=MOSI -#define CLRMOSI P5OUT&=~MOSI -#define SETCLK P5OUT|=SCK -#define CLRCLK P5OUT&=~SCK -#define READMISO (P5IN&MISO?1:0) -#define SETTMS P5OUT|=TMS -#define CLRTMS P5OUT&=~TMS -#define SETTCK P5OUT|=TCK -#define CLRTCK P5OUT&=~TCK -#define SETTDI P5OUT|=TDI -#define CLRTDI P5OUT&=~TDI + +#define SETMOSI SPIOUT|=MOSI +#define CLRMOSI SPIOUT&=~MOSI +#define SETCLK SPIOUT|=SCK +#define CLRCLK SPIOUT&=~SCK +#define READMISO (SPIIN&MISO?1:0) +#define SETTMS SPIOUT|=TMS +#define CLRTMS SPIOUT&=~TMS +#define SETTCK SPIOUT|=TCK +#define CLRTCK SPIOUT&=~TCK +#define SETTDI SPIOUT|=TDI +#define CLRTDI SPIOUT&=~TDI #define SETTST P4OUT|=TST #define CLRTST P4OUT&=~TST @@ -101,64 +136,19 @@ void jtag430_writeflash(unsigned int adr, unsigned int data); #define CLRTCLK CLRTDI extern int savedtclk; -#define SAVETCLK savedtclk=P5OUT&TCLK; -#define RESTORETCLK if(savedtclk) P5OUT|=TCLK; else P5OUT&=~TCLK - - -//16-bit MSP430 JTAG commands, bit-swapped -#define IR_CNTRL_SIG_16BIT 0xC8 // 0x13 -#define IR_CNTRL_SIG_CAPTURE 0x28 // 0x14 -#define IR_CNTRL_SIG_RELEASE 0xA8 // 0x15 -// Instructions for the JTAG Fuse -#define IR_PREPARE_BLOW 0x44 // 0x22 -#define IR_EX_BLOW 0x24 // 0x24 -// Instructions for the JTAG data register -#define IR_DATA_16BIT 0x82 // 0x41 -#define IR_DATA_QUICK 0xC2 // 0x43 -// Instructions for the JTAG PSA mode -#define IR_DATA_PSA 0x22 // 0x44 -#define IR_SHIFT_OUT_PSA 0x62 // 0x46 -// Instructions for the JTAG address register -#define IR_ADDR_16BIT 0xC1 // 0x83 -#define IR_ADDR_CAPTURE 0x21 // 0x84 -#define IR_DATA_TO_ADDR 0xA1 // 0x85 -// Bypass instruction -#define IR_BYPASS 0xFF // 0xFF - -//MSP430X2 unique -#define IR_COREIP_ID 0xE8 // 0x17 -#define IR_DEVICE_ID 0xE1 // 0x87 - -//MSP430 or MSP430X -#define MSP430JTAGID 0x89 -//MSP430X2 only -#define MSP430X2JTAGID 0x91 - -//! Syncs a POR. -unsigned int jtag430x2_syncpor(); -//! Executes an MSP430X2 POR -unsigned int jtag430x2_por(); -//! Power-On Reset -void jtag430_por(); +#define SAVETCLK savedtclk=SPIOUT&TCLK; +#define RESTORETCLK if(savedtclk) SPIOUT|=TCLK; else SPIOUT&=~TCLK //JTAG commands #define JTAG_IR_SHIFT 0x80 #define JTAG_DR_SHIFT 0x81 -#define JTAG_DR_SHIFT20 0x91 - - -//JTAG430 commands -#define JTAG430_HALTCPU 0xA0 -#define JTAG430_RELEASECPU 0xA1 -#define JTAG430_SETINSTRFETCH 0xC1 -#define JTAG430_SETPC 0xC2 -#define JTAG430_WRITEMEM 0xE0 -#define JTAG430_WRITEFLASH 0xE1 -#define JTAG430_READMEM 0xE2 -#define JTAG430_ERASEFLASH 0xE3 -#define JTAG430_ERASECHECK 0xE4 -#define JTAG430_VERIFYMEM 0xE5 -#define JTAG430_BLOWFUSE 0xE6 -#define JTAG430_ISFUSEBLOWN 0xE7 -#define JTAG430_COREIP_ID 0xF0 -#define JTAG430_DEVICE_ID 0xF1 +#define JTAG_RESET_TAP 0x82 +#define JTAG_RESET_TARGET 0x83 +#define JTAG_DETECT_IR_WIDTH 0x84 +#define JTAG_DETECT_CHAIN_LENGTH 0x85 +#define JTAG_GET_DEVICE_ID 0x86 +//#define JTAG_DR_SHIFT20 0x91 + +extern app_t const jtag_app; + +#endif