build: cleanup src/jtag/drivers directory

Change-Id: I99c08ec0132d5a15250050e718310f1ddd9fe546
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/425
Tested-by: jenkins
__archive__
Spencer Oliver 2012-02-02 15:08:51 +00:00
parent 2af5b97ba3
commit de0130a0aa
64 changed files with 5989 additions and 7247 deletions

View File

@ -23,7 +23,7 @@
#include <stdint.h> #include <stdint.h>
#define NOP {__asm nop __endasm;} #define NOP { __asm nop __endasm; }
void delay_5us(void); void delay_5us(void);
void delay_1ms(void); void delay_1ms(void);

View File

@ -51,15 +51,14 @@
/* PORT A */ /* PORT A */
#define PIN_U_OE OUTA0 #define PIN_U_OE OUTA0
// PA1 Not Connected /* PA1 Not Connected */
#define PIN_OE OUTA2 #define PIN_OE OUTA2
// PA3 Not Connected /* PA3 Not Connected */
#define PIN_RUN_LED OUTA4 #define PIN_RUN_LED OUTA4
#define PIN_TDO PINA5 #define PIN_TDO PINA5
#define PIN_BRKOUT PINA6 #define PIN_BRKOUT PINA6
#define PIN_COM_LED OUTA7 #define PIN_COM_LED OUTA7
/* PORT B */ /* PORT B */
#define PIN_TDI OUTB0 #define PIN_TDI OUTB0
#define PIN_TMS OUTB1 #define PIN_TMS OUTB1
@ -77,18 +76,18 @@
#define PIN_RXD0 PINC0 #define PIN_RXD0 PINC0
#define PIN_TXD0 OUTC1 #define PIN_TXD0 OUTC1
#define PIN_RESET_2 PINC2 #define PIN_RESET_2 PINC2
// PC3 Not Connected /* PC3 Not Connecte */
// PC4 Not Connected /* PC4 Not Connected */
#define PIN_RTCK PINC5 #define PIN_RTCK PINC5
#define PIN_WR OUTC6 #define PIN_WR OUTC6
// PC7 Not Connected /* PC7 Not Connected */
/* LED Macros */ /* LED Macros */
#define SET_RUN_LED() OUTA &= ~PIN_RUN_LED #define SET_RUN_LED() (OUTA &= ~PIN_RUN_LED)
#define CLEAR_RUN_LED() OUTA |= PIN_RUN_LED #define CLEAR_RUN_LED() (OUTA |= PIN_RUN_LED)
#define SET_COM_LED() OUTA &= ~PIN_COM_LED #define SET_COM_LED() (OUTA &= ~PIN_COM_LED)
#define CLEAR_COM_LED() OUTA |= PIN_COM_LED #define CLEAR_COM_LED() (OUTA |= PIN_COM_LED)
/* JTAG Pin Macros */ /* JTAG Pin Macros */
#define GET_TMS() (PINSB & PIN_TMS) #define GET_TMS() (PINSB & PIN_TMS)
@ -99,27 +98,27 @@
#define GET_TRAP() (PINSB & PIN_TRAP) #define GET_TRAP() (PINSB & PIN_TRAP)
#define GET_RTCK() (PINSC & PIN_RTCK) #define GET_RTCK() (PINSC & PIN_RTCK)
#define SET_TMS_HIGH() OUTB |= PIN_TMS #define SET_TMS_HIGH() (OUTB |= PIN_TMS)
#define SET_TMS_LOW() OUTB &= ~PIN_TMS #define SET_TMS_LOW() (OUTB &= ~PIN_TMS)
#define SET_TCK_HIGH() OUTB |= PIN_TCK #define SET_TCK_HIGH() (OUTB |= PIN_TCK)
#define SET_TCK_LOW() OUTB &= ~PIN_TCK #define SET_TCK_LOW() (OUTB &= ~PIN_TCK)
#define SET_TDI_HIGH() OUTB |= PIN_TDI #define SET_TDI_HIGH() (OUTB |= PIN_TDI)
#define SET_TDI_LOW() OUTB &= ~PIN_TDI #define SET_TDI_LOW() (OUTB &= ~PIN_TDI)
/* TRST and RESET are low-active and inverted by hardware. SET_HIGH de-asserts /* TRST and RESET are low-active and inverted by hardware. SET_HIGH de-asserts
* the signal (enabling reset), SET_LOW asserts the signal (disabling reset) */ * the signal (enabling reset), SET_LOW asserts the signal (disabling reset) */
#define SET_TRST_HIGH() OUTB |= PIN_TRST #define SET_TRST_HIGH() (OUTB |= PIN_TRST)
#define SET_TRST_LOW() OUTB &= ~PIN_TRST #define SET_TRST_LOW() (OUTB &= ~PIN_TRST)
#define SET_RESET_HIGH() OUTB |= PIN_RESET #define SET_RESET_HIGH() (OUTB |= PIN_RESET)
#define SET_RESET_LOW() OUTB &= ~PIN_RESET #define SET_RESET_LOW() (OUTB &= ~PIN_RESET)
#define SET_OCDSE_HIGH() OUTB |= PIN_OCDSE #define SET_OCDSE_HIGH() (OUTB |= PIN_OCDSE)
#define SET_OCDSE_LOW() OUTB &= ~PIN_OCDSE #define SET_OCDSE_LOW() (OUTB &= ~PIN_OCDSE)
#define SET_BRKIN_HIGH() OUTB |= PIN_BRKIN #define SET_BRKIN_HIGH() (OUTB |= PIN_BRKIN)
#define SET_BRKIN_LOW() OUTB &= ~PIN_BRKIN #define SET_BRKIN_LOW() (OUTB &= ~PIN_BRKIN)
#endif #endif

View File

@ -23,7 +23,7 @@
#include <stdint.h> #include <stdint.h>
#define NOP {__asm nop __endasm;} #define NOP { __asm nop __endasm; }
void jtag_scan_in(uint8_t out_offset, uint8_t in_offset); void jtag_scan_in(uint8_t out_offset, uint8_t in_offset);
void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset); void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset);

View File

@ -51,9 +51,9 @@
#define bmBit6 0x40 #define bmBit6 0x40
#define bmBit7 0x80 #define bmBit7 0x80
/***************************************************************************/ /**************************************************************************
/************************ Special Function Registers ***********************/ ************************ Special Function Registers **********************
/***************************************************************************/ ***************************************************************************/
/* See EZ-USB TRM, pp. A-9 - A-10 */ /* See EZ-USB TRM, pp. A-9 - A-10 */
@ -65,33 +65,33 @@ SFR(DPL2, 0x85);
SFR(DPS, 0x86); SFR(DPS, 0x86);
#define SEL bmBit0 #define SEL bmBit0
// Bit 1 read-only, always reads '0' /* Bit 1 read-only, always reads '0' */
// Bit 2 read-only, always reads '0' /* Bit 2 read-only, always reads '0' */
// Bit 3 read-only, always reads '0' /* Bit 3 read-only, always reads '0' */
// Bit 4 read-only, always reads '0' /* Bit 4 read-only, always reads '0' */
// Bit 5 read-only, always reads '0' /* Bit 5 read-only, always reads '0' */
// Bit 6 read-only, always reads '0' /* Bit 6 read-only, always reads '0' */
// Bit 7 read-only, always reads '0' /* Bit 7 read-only, always reads '0' */
SFR(PCON, 0x87); SFR(PCON, 0x87);
#define IDLE bmBit0 #define IDLE bmBit0
#define STOP bmBit1 #define STOP bmBit1
#define GF0 bmBit2 #define GF0 bmBit2
#define GF1 bmBit3 #define GF1 bmBit3
// Bit 4 read-only, always reads '1' /* Bit 4 read-only, always reads '1' */
// Bit 5 read-only, always reads '1' /* Bit 5 read-only, always reads '1' */
// Bit 6 unused /* Bit 6 unused */
#define SMOD0 bmBit7 #define SMOD0 bmBit7
SFR(TCON, 0x88); SFR(TCON, 0x88);
SBIT(IT0, 0x88, 0); SBIT(IT0, 0x88, 0);
SBIT(IE0, 0x88, 1); SBIT(IE0, 0x88, 1);
SBIT(IT1, 0x88, 2); SBIT(IT1, 0x88, 2);
SBIT(IE1, 0x88, 3); SBIT(IE1, 0x88, 3);
SBIT(TR0, 0x88, 4); SBIT(TR0, 0x88, 4);
SBIT(TF0, 0x88, 5); SBIT(TF0, 0x88, 5);
SBIT(TR1, 0x88, 6); SBIT(TR1, 0x88, 6);
SBIT(TF1, 0x88, 7); SBIT(TF1, 0x88, 7);
SFR(TMOD, 0x89); SFR(TMOD, 0x89);
/* Some bits in this register share the same name in the EZ-USB TRM. Therefore, /* Some bits in this register share the same name in the EZ-USB TRM. Therefore,
@ -117,24 +117,24 @@ SFR(CKCON, 0x8E);
#define T0M bmBit3 #define T0M bmBit3
#define T1M bmBit4 #define T1M bmBit4
#define T2M bmBit5 #define T2M bmBit5
// Bit 6 unused /* Bit 6 unused */
// Bit 7 unused /* Bit 7 unused */
SFR(SPC_FNC, 0x8D); SFR(SPC_FNC, 0x8D);
#define bmWRS bmBit0 #define bmWRS bmBit0
// Bit 1 read-only, always reads '0' /* Bit 1 read-only, always reads '0' */
// Bit 2 read-only, always reads '0' /* Bit 2 read-only, always reads '0' */
// Bit 3 read-only, always reads '0' /* Bit 3 read-only, always reads '0' */
// Bit 4 read-only, always reads '0' /* Bit 4 read-only, always reads '0' */
// Bit 5 read-only, always reads '0' /* Bit 5 read-only, always reads '0' */
// Bit 6 read-only, always reads '0' /* Bit 6 read-only, always reads '0' */
// Bit 7 read-only, always reads '0' /* Bit 7 read-only, always reads '0' */
SFR(EXIF, 0x91); SFR(EXIF, 0x91);
// Bit 0 read-only, always reads '0' /* Bit 0 read-only, always reads '0' */
// Bit 1 read-only, always reads '0' /* Bit 1 read-only, always reads '0' */
// Bit 2 read-only, always reads '0' /* Bit 2 read-only, always reads '0' */
// Bit 3 read-only, always reads '1' /* Bit 3 read-only, always reads '1' */
#define USBINT bmBit4 #define USBINT bmBit4
#define I2CINT bmBit5 #define I2CINT bmBit5
#define IE4 bmBit6 #define IE4 bmBit6
@ -146,58 +146,58 @@ SFR(MPAGE, 0x92);
SFR(_XPAGE, 0x92); SFR(_XPAGE, 0x92);
SFR(SCON0, 0x98); SFR(SCON0, 0x98);
SBIT(RI_0, 0x98, 0); SBIT(RI_0, 0x98, 0);
SBIT(TI_0, 0x98, 1); SBIT(TI_0, 0x98, 1);
SBIT(RB8_0, 0x98, 2); SBIT(RB8_0, 0x98, 2);
SBIT(TB8_0, 0x98, 3); SBIT(TB8_0, 0x98, 3);
SBIT(REN_0, 0x98, 4); SBIT(REN_0, 0x98, 4);
SBIT(SM2_0, 0x98, 5); SBIT(SM2_0, 0x98, 5);
SBIT(SM1_0, 0x98, 6); SBIT(SM1_0, 0x98, 6);
SBIT(SM0_0, 0x98, 7); SBIT(SM0_0, 0x98, 7);
SFR(SBUF0, 0x99); SFR(SBUF0, 0x99);
SFR(IE, 0xA8); SFR(IE, 0xA8);
SBIT(EX0, 0xA8, 0); SBIT(EX0, 0xA8, 0);
SBIT(ET0, 0xA8, 1); SBIT(ET0, 0xA8, 1);
SBIT(EX1, 0xA8, 2); SBIT(EX1, 0xA8, 2);
SBIT(ET1, 0xA8, 3); SBIT(ET1, 0xA8, 3);
SBIT(ES0, 0xA8, 4); SBIT(ES0, 0xA8, 4);
SBIT(ET2, 0xA8, 5); SBIT(ET2, 0xA8, 5);
SBIT(ES1, 0xA8, 6); SBIT(ES1, 0xA8, 6);
SBIT(EA, 0xA8, 7); SBIT(EA, 0xA8, 7);
SFR(IP, 0xB8); SFR(IP, 0xB8);
SBIT(PX0, 0xB8, 0); SBIT(PX0, 0xB8, 0);
SBIT(PT0, 0xB8, 1); SBIT(PT0, 0xB8, 1);
SBIT(PX1, 0xB8, 2); SBIT(PX1, 0xB8, 2);
SBIT(PT1, 0xB8, 3); SBIT(PT1, 0xB8, 3);
SBIT(PS0, 0xB8, 4); SBIT(PS0, 0xB8, 4);
SBIT(PT2, 0xB8, 5); SBIT(PT2, 0xB8, 5);
SBIT(PS1, 0xB8, 6); SBIT(PS1, 0xB8, 6);
// Bit 7 read-only, always reads '1' /* Bit 7 read-only, always reads '1' */
SFR(SCON1, 0xC0); SFR(SCON1, 0xC0);
SBIT(RI_1, 0xC0, 0); SBIT(RI_1, 0xC0, 0);
SBIT(TI_1, 0xC0, 1); SBIT(TI_1, 0xC0, 1);
SBIT(RB8_1, 0xC0, 2); SBIT(RB8_1, 0xC0, 2);
SBIT(TB8_1, 0xC0, 3); SBIT(TB8_1, 0xC0, 3);
SBIT(REN_1, 0xC0, 4); SBIT(REN_1, 0xC0, 4);
SBIT(SM2_1, 0xC0, 5); SBIT(SM2_1, 0xC0, 5);
SBIT(SM1_1, 0xC0, 6); SBIT(SM1_1, 0xC0, 6);
SBIT(SM0_1, 0xC0, 7); SBIT(SM0_1, 0xC0, 7);
SFR(SBUF1, 0xC1); SFR(SBUF1, 0xC1);
SFR(T2CON, 0xC8); SFR(T2CON, 0xC8);
SBIT(CPRL2, 0xC8, 0); SBIT(CPRL2, 0xC8, 0);
SBIT(CT2, 0xC8, 1); SBIT(CT2, 0xC8, 1);
SBIT(TR2, 0xC8, 2); SBIT(TR2, 0xC8, 2);
SBIT(EXEN2, 0xC8, 3); SBIT(EXEN2, 0xC8, 3);
SBIT(TCLK, 0xC8, 4); SBIT(TCLK, 0xC8, 4);
SBIT(RCLK, 0xC8, 5); SBIT(RCLK, 0xC8, 5);
SBIT(EXF2, 0xC8, 6); SBIT(EXF2, 0xC8, 6);
SBIT(TF2, 0xC8, 7); SBIT(TF2, 0xC8, 7);
SFR(RCAP2L, 0xCA); SFR(RCAP2L, 0xCA);
SFR(RCAP2H, 0xCB); SFR(RCAP2H, 0xCB);
@ -205,52 +205,52 @@ SFR(TL2, 0xCC);
SFR(TH2, 0xCD); SFR(TH2, 0xCD);
SFR(PSW, 0xD0); SFR(PSW, 0xD0);
SBIT(P, 0xD0, 0); SBIT(P, 0xD0, 0);
SBIT(F1, 0xD0, 1); SBIT(F1, 0xD0, 1);
SBIT(OV, 0xD0, 2); SBIT(OV, 0xD0, 2);
SBIT(RS0, 0xD0, 3); SBIT(RS0, 0xD0, 3);
SBIT(RS1, 0xD0, 4); SBIT(RS1, 0xD0, 4);
SBIT(F0, 0xD0, 5); SBIT(F0, 0xD0, 5);
SBIT(AC, 0xD0, 6); SBIT(AC, 0xD0, 6);
SBIT(CY, 0xD0, 7); SBIT(CY, 0xD0, 7);
SFR(EICON, 0xD8); SFR(EICON, 0xD8);
// Bit 0 read-only, always reads '0' /* Bit 0 read-only, always reads '0' */
// Bit 1 read-only, always reads '0' /* Bit 1 read-only, always reads '0' */
// Bit 2 read-only, always reads '0' /* Bit 2 read-only, always reads '0' */
SBIT(INT6, 0xD8, 3); SBIT(INT6, 0xD8, 3);
SBIT(RESI, 0xD8, 4); SBIT(RESI, 0xD8, 4);
SBIT(ERESI, 0xD8, 5); SBIT(ERESI, 0xD8, 5);
// Bit 6 read-only, always reads '1' /* Bit 6 read-only, always reads '1' */
SBIT(SMOD1, 0xD8, 7); SBIT(SMOD1, 0xD8, 7);
SFR(ACC, 0xE0); SFR(ACC, 0xE0);
SFR(EIE, 0xE8); SFR(EIE, 0xE8);
SBIT(EUSB, 0xE8, 0); SBIT(EUSB, 0xE8, 0);
SBIT(EI2C, 0xE8, 1); SBIT(EI2C, 0xE8, 1);
SBIT(EX4, 0xE8, 2); SBIT(EX4, 0xE8, 2);
SBIT(EX5, 0xE8, 3); SBIT(EX5, 0xE8, 3);
SBIT(EWDI, 0xE8, 4); SBIT(EWDI, 0xE8, 4);
// Bit 5 read-only, always reads '1' /* Bit 5 read-only, always reads '1' */
// Bit 6 read-only, always reads '1' /* Bit 6 read-only, always reads '1' */
// Bit 7 read-only, always reads '1' /* Bit 7 read-only, always reads '1' */
SFR(B, 0xF0); SFR(B, 0xF0);
SFR(EIP, 0xF8); SFR(EIP, 0xF8);
SBIT(PUSB, 0xF8, 0); SBIT(PUSB, 0xF8, 0);
SBIT(PI2C, 0xF8, 1); SBIT(PI2C, 0xF8, 1);
SBIT(PX4, 0xF8, 2); SBIT(PX4, 0xF8, 2);
SBIT(PX5, 0xF8, 3); SBIT(PX5, 0xF8, 3);
SBIT(PX6, 0xF8, 4); SBIT(PX6, 0xF8, 4);
// Bit 5 read-only, always reads '1' /* Bit 5 read-only, always reads '1' */
// Bit 6 read-only, always reads '1' /* Bit 6 read-only, always reads '1' */
// Bit 7 read-only, always reads '1' /* Bit 7 read-only, always reads '1' */
/***************************************************************************/ /**************************************************************************
/***************************** XDATA Registers *****************************/ ***************************** XDATA Registers ****************************
/***************************************************************************/ ***************************************************************************/
/************************ Endpoint 0-7 Data Buffers ************************/ /************************ Endpoint 0-7 Data Buffers ************************/
SFRX(OUT7BUF[64], 0x7B40); SFRX(OUT7BUF[64], 0x7B40);
@ -269,7 +269,7 @@ SFRX(OUT1BUF[64], 0x7E40);
SFRX(IN1BUF[64], 0x7E80); SFRX(IN1BUF[64], 0x7E80);
SFRX(OUT0BUF[64], 0x7EC0); SFRX(OUT0BUF[64], 0x7EC0);
SFRX(IN0BUF[64], 0x7F00); SFRX(IN0BUF[64], 0x7F00);
// 0x7F40 - 0x7F5F reserved /* 0x7F40 - 0x7F5F reserved */
/**************************** Isochronous Data *****************************/ /**************************** Isochronous Data *****************************/
SFRX(OUT8DATA, 0x7F60); SFRX(OUT8DATA, 0x7F60);
@ -312,9 +312,9 @@ SFRX(OUT16BCL, 0x7F7F);
SFRX(CPUCS, 0x7F92); SFRX(CPUCS, 0x7F92);
#define RES8051 bmBit0 #define RES8051 bmBit0
#define CLK24OE bmBit1 #define CLK24OE bmBit1
// Bit 2 read-only, always reads '0' /* Bit 2 read-only, always reads '0' */
// Bit 3 read-only, always reads '0' /* Bit 3 read-only, always reads '0' */
// Bits 4...7: Chip Revision /* Bits 4...7: Chip Revision */
SFRX(PORTACFG, 0x7F93); SFRX(PORTACFG, 0x7F93);
#define T0OUT bmBit0 #define T0OUT bmBit0
@ -437,7 +437,7 @@ SFRX(OEC, 0x7F9E);
#define OEC6 bmBit6 #define OEC6 bmBit6
#define OEC7 bmBit7 #define OEC7 bmBit7
// 0x7F9F reserved /* 0x7F9F reserved */
/****************** Isochronous Control/Status Registers *******************/ /****************** Isochronous Control/Status Registers *******************/
SFRX(ISOERR, 0x7FA0); SFRX(ISOERR, 0x7FA0);
@ -455,10 +455,10 @@ SFRX(ISOCTL, 0x7FA1);
#define MBZ0 bmBit1 #define MBZ0 bmBit1
#define MBZ1 bmBit2 #define MBZ1 bmBit2
#define PPSTAT bmBit3 #define PPSTAT bmBit3
// Bit 4 unused /* Bit 4 unused */
// Bit 5 unused /* Bit 5 unused */
// Bit 6 unused /* Bit 6 unused */
// Bit 7 unused /* Bit 7 unused */
SFRX(ZBCOUT, 0x7FA2); SFRX(ZBCOUT, 0x7FA2);
#define EP8 bmBit0 #define EP8 bmBit0
@ -470,8 +470,8 @@ SFRX(ZBCOUT, 0x7FA2);
#define EP14 bmBit6 #define EP14 bmBit6
#define EP15 bmBit7 #define EP15 bmBit7
// 0x7FA3 reserved /* 0x7FA3 reserved */
// 0x7FA4 reserved /* 0x7FA4 reserved */
/****************************** I2C Registers ******************************/ /****************************** I2C Registers ******************************/
SFRX(I2CS, 0x7FA5); SFRX(I2CS, 0x7FA5);
@ -485,18 +485,18 @@ SFRX(I2CS, 0x7FA5);
#define I2C_START bmBit7 #define I2C_START bmBit7
SFRX(I2DAT, 0x7FA6); SFRX(I2DAT, 0x7FA6);
// 0x7FA7 reserved /* 0x7FA7 reserved */
/******************************* Interrupts ********************************/ /******************************* Interrupts ********************************/
SFRX(IVEC, 0x7FA8); SFRX(IVEC, 0x7FA8);
// Bit 0 read-only, always reads '0' /* Bit 0 read-only, always reads '0' */
// Bit 1 read-only, always reads '0' /* Bit 1 read-only, always reads '0' */
#define IV0 bmBit2 #define IV0 bmBit2
#define IV1 bmBit3 #define IV1 bmBit3
#define IV2 bmBit4 #define IV2 bmBit4
#define IV3 bmBit5 #define IV3 bmBit5
#define IV4 bmBit6 #define IV4 bmBit6
// Bit 7 read-only, always reads '0' /* Bit 7 read-only, always reads '0' */
SFRX(IN07IRQ, 0x7FA9); SFRX(IN07IRQ, 0x7FA9);
#define IN0IR bmBit0 #define IN0IR bmBit0
@ -524,9 +524,9 @@ SFRX(USBIRQ, 0x7FAB);
#define SUTOKIR bmBit2 #define SUTOKIR bmBit2
#define SUSPIR bmBit3 #define SUSPIR bmBit3
#define URESIR bmBit4 #define URESIR bmBit4
// Bit 5 unused /* Bit 5 unused */
// Bit 6 unused /* Bit 6 unused */
// Bit 7 unused /* Bit 7 unused */
SFRX(IN07IEN, 0x7FAC); SFRX(IN07IEN, 0x7FAC);
#define IN0IEN bmBit0 #define IN0IEN bmBit0
@ -554,22 +554,22 @@ SFRX(USBIEN, 0x7FAE);
#define SUTOKIE bmBit2 #define SUTOKIE bmBit2
#define SUSPIE bmBit3 #define SUSPIE bmBit3
#define URESIE bmBit4 #define URESIE bmBit4
// Bit 5 unused /* Bit 5 unused */
// Bit 6 unused /* Bit 6 unused */
// Bit 7 unused /* Bit 7 unused */
SFRX(USBBAV, 0x7FAF); SFRX(USBBAV, 0x7FAF);
#define AVEN bmBit0 #define AVEN bmBit0
#define BPEN bmBit1 #define BPEN bmBit1
#define BPPULSE bmBit2 #define BPPULSE bmBit2
#define BREAK bmBit3 #define BREAK bmBit3
// Bit 4 unused /* Bit 4 unused */
// Bit 5 unused /* Bit 5 unused */
// Bit 6 unused /* Bit 6 unused */
// Bit 7 unused /* Bit 7 unused */
// 0x7FB0 reserved /* 0x7FB0 reserved */
// 0x7FB1 reserved /* 0x7FB1 reserved */
SFRX(BPADDRH, 0x7FB2); SFRX(BPADDRH, 0x7FB2);
SFRX(BPADDRL, 0x7FB3); SFRX(BPADDRL, 0x7FB3);
@ -579,10 +579,10 @@ SFRX(EP0CS, 0x7FB4);
#define HSNAK bmBit1 #define HSNAK bmBit1
#define IN0BSY bmBit2 #define IN0BSY bmBit2
#define OUT0BSY bmBit3 #define OUT0BSY bmBit3
// Bit 4 unused /* Bit 4 unused */
// Bit 5 unused /* Bit 5 unused */
// Bit 6 unused /* Bit 6 unused */
// Bit 7 unused /* Bit 7 unused */
SFRX(IN0BC, 0x7FB5); SFRX(IN0BC, 0x7FB5);
SFRX(IN1CS, 0x7FB6); SFRX(IN1CS, 0x7FB6);
@ -599,7 +599,7 @@ SFRX(IN6CS, 0x7FC0);
SFRX(IN6BC, 0x7FC1); SFRX(IN6BC, 0x7FC1);
SFRX(IN7CS, 0x7FC2); SFRX(IN7CS, 0x7FC2);
SFRX(IN7BC, 0x7FC3); SFRX(IN7BC, 0x7FC3);
// 0x7FC4 reserved /* 0x7FC4 reserved */
SFRX(OUT0BC, 0x7FC5); SFRX(OUT0BC, 0x7FC5);
SFRX(OUT1CS, 0x7FC6); SFRX(OUT1CS, 0x7FC6);
SFRX(OUT1BC, 0x7FC7); SFRX(OUT1BC, 0x7FC7);
@ -630,16 +630,16 @@ SFRX(USBCS, 0x7FD6);
#define RENUM bmBit1 #define RENUM bmBit1
#define DISCOE bmBit2 #define DISCOE bmBit2
#define DISCON bmBit3 #define DISCON bmBit3
// Bit 4 unused /* Bit 4 unused */
// Bit 5 unused /* Bit 5 unused */
// Bit 6 unused /* Bit 6 unused */
#define WAKESRC bmBit7 #define WAKESRC bmBit7
SFRX(TOGCTL, 0x7FD7); SFRX(TOGCTL, 0x7FD7);
#define TOG_EP0 bmBit0 #define TOG_EP0 bmBit0
#define TOG_EP1 bmBit1 #define TOG_EP1 bmBit1
#define TOG_EP2 bmBit2 #define TOG_EP2 bmBit2
// Bit 3 is read-only, always reads '0' /* Bit 3 is read-only, always reads '0' */
#define TOG_IO bmBit4 #define TOG_IO bmBit4
#define TOG_R bmBit5 #define TOG_R bmBit5
#define TOG_S bmBit6 #define TOG_S bmBit6
@ -647,9 +647,9 @@ SFRX(TOGCTL, 0x7FD7);
SFRX(USBFRAMEL, 0x7FD8); SFRX(USBFRAMEL, 0x7FD8);
SFRX(USBFRAMEH, 0x7FD9); SFRX(USBFRAMEH, 0x7FD9);
// 0x7FDA reserved /* 0x7FDA reserved */
SFRX(FNADDR, 0x7FDB); SFRX(FNADDR, 0x7FDB);
// 0x7FDC reserved /* 0x7FDC reserved */
SFRX(USBPAIR, 0x7FDD); SFRX(USBPAIR, 0x7FDD);
#define PR2IN bmBit0 #define PR2IN bmBit0
@ -658,11 +658,11 @@ SFRX(USBPAIR, 0x7FDD);
#define PR2OUT bmBit3 #define PR2OUT bmBit3
#define PR4OUT bmBit4 #define PR4OUT bmBit4
#define PR6OUT bmBit5 #define PR6OUT bmBit5
// Bit 6 unused /* Bit 6 unused */
#define ISOSEND0 bmBit7 #define ISOSEND0 bmBit7
SFRX(IN07VAL, 0x7FDE); SFRX(IN07VAL, 0x7FDE);
// Bit 0 is read-only, always reads '1' /* Bit 0 is read-only, always reads '1' */
#define IN1VAL bmBit1 #define IN1VAL bmBit1
#define IN2VAL bmBit2 #define IN2VAL bmBit2
#define IN3VAL bmBit3 #define IN3VAL bmBit3
@ -672,7 +672,7 @@ SFRX(IN07VAL, 0x7FDE);
#define IN7VAL bmBit7 #define IN7VAL bmBit7
SFRX(OUT07VAL, 0x7FDF); SFRX(OUT07VAL, 0x7FDF);
// Bit 0 is read-only, always reads '1' /* Bit 0 is read-only, always reads '1' */
#define OUT1VAL bmBit1 #define OUT1VAL bmBit1
#define OUT2VAL bmBit2 #define OUT2VAL bmBit2
#define OUT3VAL bmBit3 #define OUT3VAL bmBit3
@ -714,8 +714,8 @@ SFRX(FASTXFR, 0x7FE2);
SFRX(AUTOPTRH, 0x7FE3); SFRX(AUTOPTRH, 0x7FE3);
SFRX(AUTOPTRL, 0x7FE4); SFRX(AUTOPTRL, 0x7FE4);
SFRX(AUTODATA, 0x7FE5); SFRX(AUTODATA, 0x7FE5);
// 0x7FE6 reserved /* 0x7FE6 reserved */
// 0x7FE7 reserved /* 0x7FE7 reserved */
/******************************* Setup Data ********************************/ /******************************* Setup Data ********************************/
SFRX(SETUPDAT[8], 0x7FE8); SFRX(SETUPDAT[8], 0x7FE8);

View File

@ -26,15 +26,15 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define NULL (void*)0; #define NULL (void *)0;
/* High and Low byte of a word (uint16_t) */ /* High and Low byte of a word (uint16_t) */
#define HI8(word) (uint8_t)(((uint16_t)word >> 8) & 0xff) #define HI8(word) (uint8_t)(((uint16_t)word >> 8) & 0xff)
#define LO8(word) (uint8_t)((uint16_t)word & 0xff) #define LO8(word) (uint8_t)((uint16_t)word & 0xff)
/* Convenience functions */ /* Convenience functions */
#define STALL_EP0() EP0CS |= EP0STALL #define STALL_EP0() (EP0CS |= EP0STALL)
#define CLEAR_IRQ() EXIF &= ~USBINT #define CLEAR_IRQ() (EXIF &= ~USBINT)
/*********** USB descriptors. See section 9.5 of the USB 1.1 spec **********/ /*********** USB descriptors. See section 9.5 of the USB 1.1 spec **********/
@ -45,84 +45,84 @@
#define DESCRIPTOR_TYPE_INTERFACE 0x04 #define DESCRIPTOR_TYPE_INTERFACE 0x04
#define DESCRIPTOR_TYPE_ENDPOINT 0x05 #define DESCRIPTOR_TYPE_ENDPOINT 0x05
#define STR_DESCR(len,...) { len*2+2, DESCRIPTOR_TYPE_STRING, { __VA_ARGS__ } } #define STR_DESCR(len, ...) { len * 2 + 2, DESCRIPTOR_TYPE_STRING, { __VA_ARGS__ } }
/** USB Device Descriptor. See USB 1.1 spec, pp. 196 - 198 */ /** USB Device Descriptor. See USB 1.1 spec, pp. 196 - 198 */
struct usb_device_descriptor { struct usb_device_descriptor {
uint8_t bLength; ///< Size of this descriptor in bytes. uint8_t bLength; /* /< Size of this descriptor in bytes. */
uint8_t bDescriptorType; ///< DEVICE Descriptor Type. uint8_t bDescriptorType;/* /< DEVICE Descriptor Type. */
uint16_t bcdUSB; ///< USB specification release number (BCD). uint16_t bcdUSB; /* /< USB specification release number (BCD). */
uint8_t bDeviceClass; ///< Class code. uint8_t bDeviceClass; /* /< Class code. */
uint8_t bDeviceSubClass; ///< Subclass code. uint8_t bDeviceSubClass;/* /< Subclass code. */
uint8_t bDeviceProtocol; ///< Protocol code. uint8_t bDeviceProtocol;/* /< Protocol code. */
uint8_t bMaxPacketSize0; ///< Maximum packet size for EP0 (8, 16, 32, 64). uint8_t bMaxPacketSize0;/* /< Maximum packet size for EP0 (8, 16, 32, 64). */
uint16_t idVendor; ///< USB Vendor ID. uint16_t idVendor; /* /< USB Vendor ID. */
uint16_t idProduct; ///< USB Product ID. uint16_t idProduct; /* /< USB Product ID. */
uint16_t bcdDevice; ///< Device Release Number (BCD). uint16_t bcdDevice; /* /< Device Release Number (BCD). */
uint8_t iManufacturer; ///< Index of manufacturer string descriptor. uint8_t iManufacturer; /* /< Index of manufacturer string descriptor. */
uint8_t iProduct; ///< Index of product string descriptor. uint8_t iProduct; /* /< Index of product string descriptor. */
uint8_t iSerialNumber; ///< Index of string descriptor containing serial #. uint8_t iSerialNumber; /* /< Index of string descriptor containing serial #. */
uint8_t bNumConfigurations; ///< Number of possible configurations. uint8_t bNumConfigurations; /* /< Number of possible configurations. */
}; };
/** USB Configuration Descriptor. See USB 1.1 spec, pp. 199 - 200 */ /** USB Configuration Descriptor. See USB 1.1 spec, pp. 199 - 200 */
struct usb_config_descriptor { struct usb_config_descriptor {
uint8_t bLength; ///< Size of this descriptor in bytes. uint8_t bLength; /* /< Size of this descriptor in bytes. */
uint8_t bDescriptorType; ///< CONFIGURATION descriptor type. uint8_t bDescriptorType;/* /< CONFIGURATION descriptor type. */
uint16_t wTotalLength; ///< Combined total length of all descriptors. uint16_t wTotalLength; /* /< Combined total length of all descriptors. */
uint8_t bNumInterfaces; ///< Number of interfaces in this configuration. uint8_t bNumInterfaces; /* /< Number of interfaces in this configuration. */
uint8_t bConfigurationValue;///< Value used to select this configuration. uint8_t bConfigurationValue; /* /< Value used to select this configuration. */
uint8_t iConfiguration; ///< Index of configuration string descriptor. uint8_t iConfiguration; /* /< Index of configuration string descriptor. */
uint8_t bmAttributes; ///< Configuration characteristics. uint8_t bmAttributes; /* /< Configuration characteristics. */
uint8_t MaxPower; ///< Maximum power consumption in 2 mA units. uint8_t MaxPower; /* /< Maximum power consumption in 2 mA units. */
}; };
/** USB Interface Descriptor. See USB 1.1 spec, pp. 201 - 203 */ /** USB Interface Descriptor. See USB 1.1 spec, pp. 201 - 203 */
struct usb_interface_descriptor { struct usb_interface_descriptor {
uint8_t bLength; ///< Size of this descriptor in bytes. uint8_t bLength; /* /< Size of this descriptor in bytes. */
uint8_t bDescriptorType; ///< INTERFACE descriptor type. uint8_t bDescriptorType;/* /< INTERFACE descriptor type. */
uint8_t bInterfaceNumber; ///< Interface number. uint8_t bInterfaceNumber; /* /< Interface number. */
uint8_t bAlternateSetting; ///< Value used to select alternate setting. uint8_t bAlternateSetting; /* /< Value used to select alternate setting. */
uint8_t bNumEndpoints; ///< Number of endpoints used by this interface. uint8_t bNumEndpoints; /* /< Number of endpoints used by this interface. */
uint8_t bInterfaceClass; ///< Class code. uint8_t bInterfaceClass;/* /< Class code. */
uint8_t bInterfaceSubclass; ///< Subclass code. uint8_t bInterfaceSubclass; /* /< Subclass code. */
uint8_t bInterfaceProtocol; ///< Protocol code. uint8_t bInterfaceProtocol; /* /< Protocol code. */
uint8_t iInterface; ///< Index of interface string descriptor. uint8_t iInterface; /* /< Index of interface string descriptor. */
}; };
/** USB Endpoint Descriptor. See USB 1.1 spec, pp. 203 - 204 */ /** USB Endpoint Descriptor. See USB 1.1 spec, pp. 203 - 204 */
struct usb_endpoint_descriptor { struct usb_endpoint_descriptor {
uint8_t bLength; ///< Size of this descriptor in bytes. uint8_t bLength; /* /< Size of this descriptor in bytes. */
uint8_t bDescriptorType; ///< ENDPOINT descriptor type. uint8_t bDescriptorType;/* /< ENDPOINT descriptor type. */
uint8_t bEndpointAddress; ///< Endpoint Address: USB 1.1 spec, table 9-10. uint8_t bEndpointAddress; /* /< Endpoint Address: USB 1.1 spec, table 9-10. */
uint8_t bmAttributes; ///< Endpoint Attributes: USB 1.1 spec, table 9-10. uint8_t bmAttributes; /* /< Endpoint Attributes: USB 1.1 spec, table 9-10. */
uint16_t wMaxPacketSize; ///< Maximum packet size for this endpoint. uint16_t wMaxPacketSize;/* /< Maximum packet size for this endpoint. */
uint8_t bInterval; ///< Polling interval (in ms) for this endpoint. uint8_t bInterval; /* /< Polling interval (in ms) for this endpoint. */
}; };
/** USB Language Descriptor. See USB 1.1 spec, pp. 204 - 205 */ /** USB Language Descriptor. See USB 1.1 spec, pp. 204 - 205 */
struct usb_language_descriptor { struct usb_language_descriptor {
uint8_t bLength; ///< Size of this descriptor in bytes. uint8_t bLength; /* /< Size of this descriptor in bytes. */
uint8_t bDescriptorType; ///< STRING descriptor type. uint8_t bDescriptorType;/* /< STRING descriptor type. */
uint16_t wLANGID[]; ///< LANGID codes. uint16_t wLANGID[]; /* /< LANGID codes. */
}; };
/** USB String Descriptor. See USB 1.1 spec, pp. 204 - 205 */ /** USB String Descriptor. See USB 1.1 spec, pp. 204 - 205 */
struct usb_string_descriptor { struct usb_string_descriptor {
uint8_t bLength; ///< Size of this descriptor in bytes. uint8_t bLength; /* /< Size of this descriptor in bytes. */
uint8_t bDescriptorType; ///< STRING descriptor type. uint8_t bDescriptorType;/* /< STRING descriptor type. */
uint16_t bString[]; ///< UNICODE encoded string. uint16_t bString[]; /* /< UNICODE encoded string. */
}; };
/********************** USB Control Endpoint 0 related *********************/ /********************** USB Control Endpoint 0 related *********************/
/** USB Control Setup Data. See USB 1.1 spec, pp. 183 - 185 */ /** USB Control Setup Data. See USB 1.1 spec, pp. 183 - 185 */
struct setup_data { struct setup_data {
uint8_t bmRequestType; ///< Characteristics of a request. uint8_t bmRequestType; /* /< Characteristics of a request. */
uint8_t bRequest; ///< Specific request. uint8_t bRequest; /* /< Specific request. */
uint16_t wValue; ///< Field that varies according to request. uint16_t wValue; /* /< Field that varies according to request. */
uint16_t wIndex; ///< Field that varies according to request. uint16_t wIndex; /* /< Field that varies according to request. */
uint16_t wLength; ///< Number of bytes to transfer in data stage. uint16_t wLength; /* /< Number of bytes to transfer in data stage. */
}; };
/* External declarations for variables that need to be accessed outside of /* External declarations for variables that need to be accessed outside of
@ -206,9 +206,9 @@ extern volatile __xdata __at 0x7FE8 struct setup_data setup_data;
/* USB Requests (bRequest): See USB 1.1 spec, table 9-4 on page 187 */ /* USB Requests (bRequest): See USB 1.1 spec, table 9-4 on page 187 */
#define GET_STATUS 0 #define GET_STATUS 0
#define CLEAR_FEATURE 1 #define CLEAR_FEATURE 1
// Value '2' is reserved for future use /* Value '2' is reserved for future use */
#define SET_FEATURE 3 #define SET_FEATURE 3
// Value '4' is reserved for future use /* Value '4' is reserved for future use */
#define SET_ADDRESS 5 #define SET_ADDRESS 5
#define GET_DESCRIPTOR 6 #define GET_DESCRIPTOR 6
#define SET_DESCRIPTOR 7 #define SET_DESCRIPTOR 7
@ -252,7 +252,7 @@ enum usb_isr {
/*************************** Function Prototypes ***************************/ /*************************** Function Prototypes ***************************/
__xdata uint8_t* usb_get_endpoint_cs_reg(uint8_t ep); __xdata uint8_t *usb_get_endpoint_cs_reg(uint8_t ep);
void usb_reset_data_toggle(uint8_t ep); void usb_reset_data_toggle(uint8_t ep);
bool usb_handle_get_status(void); bool usb_handle_get_status(void);

View File

@ -25,10 +25,12 @@ void delay_5us(void)
NOP; NOP;
} }
void delay_1ms(void) { void delay_1ms(void)
{
uint16_t i; uint16_t i;
for (i = 0; i < 598; i++); for (i = 0; i < 598; i++)
;
} }
void delay_us(uint16_t delay) void delay_us(uint16_t delay)
@ -36,16 +38,14 @@ void delay_us(uint16_t delay)
uint16_t i; uint16_t i;
uint16_t maxcount = (delay / 5); uint16_t maxcount = (delay / 5);
for (i = 0; i < maxcount; i++) { for (i = 0; i < maxcount; i++)
delay_5us(); delay_5us();
}
} }
void delay_ms(uint16_t delay) void delay_ms(uint16_t delay)
{ {
uint16_t i; uint16_t i;
for (i = 0; i < delay; i++) { for (i = 0; i < delay; i++)
delay_1ms(); delay_1ms();
}
} }

View File

@ -27,19 +27,19 @@
#include <stdbool.h> #include <stdbool.h>
/** Delay value for SCAN_IN operations with less than maximum TCK frequency */ /** Delay value for SCAN_IN operations with less than maximum TCK frequency */
uint8_t delay_scan_in = 0; uint8_t delay_scan_in;
/** Delay value for SCAN_OUT operations with less than maximum TCK frequency */ /** Delay value for SCAN_OUT operations with less than maximum TCK frequency */
uint8_t delay_scan_out = 0; uint8_t delay_scan_out;
/** Delay value for SCAN_IO operations with less than maximum TCK frequency */ /** Delay value for SCAN_IO operations with less than maximum TCK frequency */
uint8_t delay_scan_io = 0; uint8_t delay_scan_io;
/** Delay value for CLOCK_TCK operations with less than maximum frequency */ /** Delay value for CLOCK_TCK operations with less than maximum frequency */
uint8_t delay_tck = 0; uint8_t delay_tck;
/** Delay value for CLOCK_TMS operations with less than maximum frequency */ /** Delay value for CLOCK_TMS operations with less than maximum frequency */
uint8_t delay_tms = 0; uint8_t delay_tms;
/** /**
* Perform JTAG SCAN-IN operation at maximum TCK frequency. * Perform JTAG SCAN-IN operation at maximum TCK frequency.
@ -68,9 +68,8 @@ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3]; tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4]; tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) { if (tms_count_start > 0)
jtag_clock_tms(tms_count_start, tms_sequence_start); jtag_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS); outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
@ -83,10 +82,9 @@ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset)
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
@ -107,19 +105,17 @@ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset)
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
tdo_data = tdo_data >> (8 - bits_last_byte); tdo_data = tdo_data >> (8 - bits_last_byte);
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
/* Move to correct end state */ /* Move to correct end state */
if (tms_count_end > 0) { if (tms_count_end > 0)
jtag_clock_tms(tms_count_end, tms_sequence_end); jtag_clock_tms(tms_count_end, tms_sequence_end);
}
} }
/** /**
@ -149,9 +145,8 @@ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3]; tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4]; tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) { if (tms_count_start > 0)
jtag_slow_clock_tms(tms_count_start, tms_sequence_start); jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS); outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
@ -161,16 +156,17 @@ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
OUTB = outb_buffer; /* TCK changes here */ OUTB = outb_buffer; /* TCK changes here */
for (k = 0; k < delay_scan_in; k++); for (k = 0; k < delay_scan_in; k++)
;
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_in; k++); for (k = 0; k < delay_scan_in; k++)
;
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
@ -188,25 +184,25 @@ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
} }
OUTB = outb_buffer; /* TCK change here */ OUTB = outb_buffer; /* TCK change here */
for (k = 0; k < delay_scan_in; k++); for (k = 0; k < delay_scan_in; k++)
;
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_in; k++); for (k = 0; k < delay_scan_in; k++)
;
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
tdo_data = tdo_data >> (8 - bits_last_byte); tdo_data = tdo_data >> (8 - bits_last_byte);
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
/* Move to correct end state */ /* Move to correct end state */
if (tms_count_end > 0) { if (tms_count_end > 0)
jtag_slow_clock_tms(tms_count_end, tms_sequence_end); jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
} }
/** /**
@ -237,9 +233,8 @@ void jtag_scan_out(uint8_t out_offset)
tms_sequence_start = OUT2BUF[out_offset + 3]; tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4]; tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) { if (tms_count_start > 0)
jtag_clock_tms(tms_count_start, tms_sequence_start); jtag_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS); outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -248,12 +243,10 @@ void jtag_scan_out(uint8_t out_offset)
tdi_data = OUT2BUF[i + out_offset + 5]; tdi_data = OUT2BUF[i + out_offset + 5];
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
OUTB = outb_buffer; /* TDI and TCK change here */ OUTB = outb_buffer; /* TDI and TCK change here */
tdi_data = tdi_data >> 1; tdi_data = tdi_data >> 1;
@ -265,12 +258,10 @@ void jtag_scan_out(uint8_t out_offset)
/* Shift the last byte */ /* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) { for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
/* Assert TMS signal if requested and this is the last bit */ /* Assert TMS signal if requested and this is the last bit */
if ((j == bits_last_byte - 1) && (tms_count_end > 0)) { if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
@ -285,9 +276,8 @@ void jtag_scan_out(uint8_t out_offset)
} }
/* Move to correct end state */ /* Move to correct end state */
if (tms_count_end > 0) { if (tms_count_end > 0)
jtag_clock_tms(tms_count_end, tms_sequence_end); jtag_clock_tms(tms_count_end, tms_sequence_end);
}
} }
/** /**
@ -318,9 +308,8 @@ void jtag_slow_scan_out(uint8_t out_offset)
tms_sequence_start = OUT2BUF[out_offset + 3]; tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4]; tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) { if (tms_count_start > 0)
jtag_slow_clock_tms(tms_count_start, tms_sequence_start); jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS); outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -329,19 +318,19 @@ void jtag_slow_scan_out(uint8_t out_offset)
tdi_data = OUT2BUF[i + out_offset + 5]; tdi_data = OUT2BUF[i + out_offset + 5];
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
OUTB = outb_buffer; /* TDI and TCK change here */ OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_out; k++); for (k = 0; k < delay_scan_out; k++)
;
tdi_data = tdi_data >> 1; tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_out; k++); for (k = 0; k < delay_scan_out; k++)
;
} }
} }
@ -349,12 +338,10 @@ void jtag_slow_scan_out(uint8_t out_offset)
/* Shift the last byte */ /* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) { for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
/* Assert TMS signal if requested and this is the last bit */ /* Assert TMS signal if requested and this is the last bit */
if ((j == bits_last_byte - 1) && (tms_count_end > 0)) { if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
@ -364,17 +351,18 @@ void jtag_slow_scan_out(uint8_t out_offset)
} }
OUTB = outb_buffer; /* TDI and TCK change here */ OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_out; k++); for (k = 0; k < delay_scan_out; k++)
;
tdi_data = tdi_data >> 1; tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_out; k++); for (k = 0; k < delay_scan_out; k++)
;
} }
/* Move to correct end state */ /* Move to correct end state */
if (tms_count_end > 0) { if (tms_count_end > 0)
jtag_slow_clock_tms(tms_count_end, tms_sequence_end); jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
} }
/** /**
@ -405,9 +393,8 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3]; tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4]; tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) { if (tms_count_start > 0)
jtag_clock_tms(tms_count_start, tms_sequence_start); jtag_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS); outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -417,22 +404,19 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
tdo_data = 0; tdo_data = 0;
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
OUTB = outb_buffer; /* TDI and TCK change here */ OUTB = outb_buffer; /* TDI and TCK change here */
tdi_data = tdi_data >> 1; tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
@ -443,12 +427,10 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
/* Shift the last byte */ /* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) { for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
/* Assert TMS signal if requested and this is the last bit */ /* Assert TMS signal if requested and this is the last bit */
if ((j == bits_last_byte - 1) && (tms_count_end > 0)) { if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
@ -462,19 +444,17 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
tdo_data = tdo_data >> (8 - bits_last_byte); tdo_data = tdo_data >> (8 - bits_last_byte);
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
/* Move to correct end state */ /* Move to correct end state */
if (tms_count_end > 0) { if (tms_count_end > 0)
jtag_clock_tms(tms_count_end, tms_sequence_end); jtag_clock_tms(tms_count_end, tms_sequence_end);
}
} }
/** /**
@ -505,9 +485,8 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3]; tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4]; tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) { if (tms_count_start > 0)
jtag_slow_clock_tms(tms_count_start, tms_sequence_start); jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS); outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -517,25 +496,24 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
tdo_data = 0; tdo_data = 0;
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
OUTB = outb_buffer; /* TDI and TCK change here */ OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_io; k++); for (k = 0; k < delay_scan_io; k++)
;
tdi_data = tdi_data >> 1; tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_io; k++); for (k = 0; k < delay_scan_io; k++)
;
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
@ -546,12 +524,10 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
/* Shift the last byte */ /* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) { for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) { if (tdi_data & 0x01)
outb_buffer |= PIN_TDI; outb_buffer |= PIN_TDI;
} else
else {
outb_buffer &= ~PIN_TDI; outb_buffer &= ~PIN_TDI;
}
/* Assert TMS signal if requested and this is the last bit */ /* Assert TMS signal if requested and this is the last bit */
if ((j == bits_last_byte - 1) && (tms_count_end > 0)) { if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
@ -561,26 +537,26 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
} }
OUTB = outb_buffer; /* TDI and TCK change here */ OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_io; k++); for (k = 0; k < delay_scan_io; k++)
;
tdi_data = tdi_data >> 1; tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK); OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_io; k++); for (k = 0; k < delay_scan_io; k++)
;
tdo_data = tdo_data >> 1; tdo_data = tdo_data >> 1;
if (GET_TDO()) { if (GET_TDO())
tdo_data |= 0x80; tdo_data |= 0x80;
} }
}
tdo_data = tdo_data >> (8 - bits_last_byte); tdo_data = tdo_data >> (8 - bits_last_byte);
/* Copy TDO data to IN2BUF */ /* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data; IN2BUF[i + in_offset] = tdo_data;
/* Move to correct end state */ /* Move to correct end state */
if (tms_count_end > 0) { if (tms_count_end > 0)
jtag_slow_clock_tms(tms_count_end, tms_sequence_end); jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
} }
/** /**
@ -595,7 +571,7 @@ void jtag_clock_tck(uint16_t count)
uint16_t i; uint16_t i;
uint8_t outb_buffer = OUTB & ~(PIN_TCK); uint8_t outb_buffer = OUTB & ~(PIN_TCK);
for ( i = 0; i < count; i++ ) { for (i = 0; i < count; i++) {
OUTB = outb_buffer; OUTB = outb_buffer;
OUTB = outb_buffer | PIN_TCK; OUTB = outb_buffer | PIN_TCK;
} }
@ -614,11 +590,13 @@ void jtag_slow_clock_tck(uint16_t count)
uint8_t j; uint8_t j;
uint8_t outb_buffer = OUTB & ~(PIN_TCK); uint8_t outb_buffer = OUTB & ~(PIN_TCK);
for ( i = 0; i < count; i++ ) { for (i = 0; i < count; i++) {
OUTB = outb_buffer; OUTB = outb_buffer;
for (j = 0; j < delay_tck; j++); for (j = 0; j < delay_tck; j++)
;
OUTB = outb_buffer | PIN_TCK; OUTB = outb_buffer | PIN_TCK;
for (j = 0; j < delay_tck; j++); for (j = 0; j < delay_tck; j++)
;
} }
} }
@ -636,14 +614,12 @@ void jtag_clock_tms(uint8_t count, uint8_t sequence)
uint8_t outb_buffer = OUTB & ~(PIN_TCK); uint8_t outb_buffer = OUTB & ~(PIN_TCK);
uint8_t i; uint8_t i;
for ( i = 0; i < count; i++ ) { for (i = 0; i < count; i++) {
/* Set TMS pin according to sequence parameter */ /* Set TMS pin according to sequence parameter */
if ( sequence & 0x1 ) { if (sequence & 0x1)
outb_buffer |= PIN_TMS; outb_buffer |= PIN_TMS;
} else
else {
outb_buffer &= ~PIN_TMS; outb_buffer &= ~PIN_TMS;
}
OUTB = outb_buffer; OUTB = outb_buffer;
sequence = sequence >> 1; sequence = sequence >> 1;
@ -667,18 +643,18 @@ void jtag_slow_clock_tms(uint8_t count, uint8_t sequence)
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
/* Set TMS pin according to sequence parameter */ /* Set TMS pin according to sequence parameter */
if ( sequence & 0x1 ) { if (sequence & 0x1)
outb_buffer |= PIN_TMS; outb_buffer |= PIN_TMS;
} else
else {
outb_buffer &= ~PIN_TMS; outb_buffer &= ~PIN_TMS;
}
OUTB = outb_buffer; OUTB = outb_buffer;
for (j = 0; j < delay_tms; j++); for (j = 0; j < delay_tms; j++)
;
sequence = sequence >> 1; sequence = sequence >> 1;
OUTB = outb_buffer | PIN_TCK; OUTB = outb_buffer | PIN_TCK;
for (j = 0; j < delay_tms; j++); for (j = 0; j < delay_tms; j++)
;
} }
} }
@ -697,15 +673,12 @@ uint16_t jtag_get_signals(void)
output_signal_state = 0; output_signal_state = 0;
/* Get states of input pins */ /* Get states of input pins */
if (GET_TDO()) { if (GET_TDO())
input_signal_state |= SIGNAL_TDO; input_signal_state |= SIGNAL_TDO;
} if (GET_BRKOUT())
if (GET_BRKOUT()) {
input_signal_state |= SIGNAL_BRKOUT; input_signal_state |= SIGNAL_BRKOUT;
} if (GET_TRAP())
if (GET_TRAP()) {
input_signal_state |= SIGNAL_TRAP; input_signal_state |= SIGNAL_TRAP;
}
if (GET_RTCK()) { if (GET_RTCK()) {
/* Using RTCK this way would be extremely slow, /* Using RTCK this way would be extremely slow,
* implemented only for the sake of completeness */ * implemented only for the sake of completeness */

View File

@ -59,21 +59,17 @@ void execute_set_led_command(void)
{ {
uint8_t led_state = OUT2BUF[cmd_id_index + 1]; uint8_t led_state = OUT2BUF[cmd_id_index + 1];
if (led_state & RUN_LED_ON) { if (led_state & RUN_LED_ON)
SET_RUN_LED(); SET_RUN_LED();
}
if (led_state & COM_LED_ON) { if (led_state & COM_LED_ON)
SET_COM_LED(); SET_COM_LED();
}
if (led_state & RUN_LED_OFF) { if (led_state & RUN_LED_OFF)
CLEAR_RUN_LED(); CLEAR_RUN_LED();
}
if (led_state & COM_LED_OFF) { if (led_state & COM_LED_OFF)
CLEAR_COM_LED(); CLEAR_COM_LED();
}
} }
/** /**
@ -196,9 +192,8 @@ bool execute_command(void)
payload_index_in += usb_in_bytecount; payload_index_in += usb_in_bytecount;
/* Determine if this was the last command */ /* Determine if this was the last command */
if ((cmd_id_index + usb_out_bytecount + 1) >= OUT2BC) { if ((cmd_id_index + usb_out_bytecount + 1) >= OUT2BC)
return true; return true;
}
else { else {
/* Not the last command, update cmd_id_index */ /* Not the last command, update cmd_id_index */
cmd_id_index += (usb_out_bytecount + 1); cmd_id_index += (usb_out_bytecount + 1);
@ -218,7 +213,8 @@ void command_loop(void)
payload_index_in = 0; payload_index_in = 0;
/* Wait until host sends EP2 Bulk-OUT packet */ /* Wait until host sends EP2 Bulk-OUT packet */
while (!EP2_out); while (!EP2_out)
;
EP2_out = 0; EP2_out = 0;
/* Turn on COM LED to indicate command execution */ /* Turn on COM LED to indicate command execution */
@ -226,16 +222,16 @@ void command_loop(void)
/* Execute the commands */ /* Execute the commands */
last_command = false; last_command = false;
while (last_command == false) { while (last_command == false)
last_command = execute_command(); last_command = execute_command();
}
CLEAR_COM_LED(); CLEAR_COM_LED();
/* Send back EP2 Bulk-IN packet if required */ /* Send back EP2 Bulk-IN packet if required */
if (payload_index_in > 0) { if (payload_index_in > 0) {
IN2BC = payload_index_in; IN2BC = payload_index_in;
while (!EP2_in); while (!EP2_in)
;
EP2_in = 0; EP2_in = 0;
} }

View File

@ -33,8 +33,8 @@
/* Also update external declarations in "include/usb.h" if making changes to /* Also update external declarations in "include/usb.h" if making changes to
* these variables! */ * these variables! */
volatile bool EP2_out = 0; volatile bool EP2_out;
volatile bool EP2_in = 0; volatile bool EP2_in;
volatile __xdata __at 0x7FE8 struct setup_data setup_data; volatile __xdata __at 0x7FE8 struct setup_data setup_data;
@ -126,19 +126,19 @@ __code struct usb_language_descriptor language_descriptor = {
}; };
__code struct usb_string_descriptor strManufacturer = __code struct usb_string_descriptor strManufacturer =
STR_DESCR(9,'O','p','e','n','U','L','I','N','K'); STR_DESCR(9, 'O', 'p', 'e', 'n', 'U', 'L', 'I', 'N', 'K');
__code struct usb_string_descriptor strProduct = __code struct usb_string_descriptor strProduct =
STR_DESCR(9,'O','p','e','n','U','L','I','N','K'); STR_DESCR(9, 'O', 'p', 'e', 'n', 'U', 'L', 'I', 'N', 'K');
__code struct usb_string_descriptor strSerialNumber = __code struct usb_string_descriptor strSerialNumber =
STR_DESCR(6, '0','0','0','0','0','1'); STR_DESCR(6, '0', '0', '0', '0', '0', '1');
__code struct usb_string_descriptor strConfigDescr = __code struct usb_string_descriptor strConfigDescr =
STR_DESCR(12, 'J','T','A','G',' ','A','d','a','p','t','e','r'); STR_DESCR(12, 'J', 'T', 'A', 'G', ' ', 'A', 'd', 'a', 'p', 't', 'e', 'r');
/* Table containing pointers to string descriptors */ /* Table containing pointers to string descriptors */
__code struct usb_string_descriptor* __code en_string_descriptors[4] = { __code struct usb_string_descriptor *__code en_string_descriptors[4] = {
&strManufacturer, &strManufacturer,
&strProduct, &strProduct,
&strSerialNumber, &strSerialNumber,
@ -155,47 +155,87 @@ void sudav_isr(void) __interrupt SUDAV_ISR
EP0CS |= HSNAK; EP0CS |= HSNAK;
} }
void sof_isr(void) __interrupt SOF_ISR { } void sof_isr(void) __interrupt SOF_ISR
void sutok_isr(void) __interrupt SUTOK_ISR { } {
void suspend_isr(void) __interrupt SUSPEND_ISR { } }
void usbreset_isr(void) __interrupt USBRESET_ISR { } void sutok_isr(void) __interrupt SUTOK_ISR
void ibn_isr(void) __interrupt IBN_ISR { } {
}
void suspend_isr(void) __interrupt SUSPEND_ISR
{
}
void usbreset_isr(void) __interrupt USBRESET_ISR
{
}
void ibn_isr(void) __interrupt IBN_ISR
{
}
void ep0in_isr(void) __interrupt EP0IN_ISR { } void ep0in_isr(void) __interrupt EP0IN_ISR
void ep0out_isr(void) __interrupt EP0OUT_ISR { } {
void ep1in_isr(void) __interrupt EP1IN_ISR { } }
void ep1out_isr(void) __interrupt EP1OUT_ISR { } void ep0out_isr(void) __interrupt EP0OUT_ISR
{
}
void ep1in_isr(void) __interrupt EP1IN_ISR
{
}
void ep1out_isr(void) __interrupt EP1OUT_ISR
{
}
/** /**
* EP2 IN: called after the transfer from uC->Host has finished: we sent data * EP2 IN: called after the transfer from uC->Host has finished: we sent data
*/ */
void ep2in_isr(void) __interrupt EP2IN_ISR { void ep2in_isr(void) __interrupt EP2IN_ISR
{
EP2_in = 1; EP2_in = 1;
CLEAR_IRQ(); CLEAR_IRQ();
IN07IRQ = IN2IR; // Clear OUT2 IRQ IN07IRQ = IN2IR;/* Clear OUT2 IRQ */
} }
/** /**
* EP2 OUT: called after the transfer from Host->uC has finished: we got data * EP2 OUT: called after the transfer from Host->uC has finished: we got data
*/ */
void ep2out_isr(void) __interrupt EP2OUT_ISR { void ep2out_isr(void) __interrupt EP2OUT_ISR
{
EP2_out = 1; EP2_out = 1;
CLEAR_IRQ(); CLEAR_IRQ();
OUT07IRQ = OUT2IR; // Clear OUT2 IRQ OUT07IRQ = OUT2IR; /* Clear OUT2 IRQ */
} }
void ep3in_isr(void) __interrupt EP3IN_ISR { } void ep3in_isr(void) __interrupt EP3IN_ISR
void ep3out_isr(void) __interrupt EP3OUT_ISR { } {
void ep4in_isr(void) __interrupt EP4IN_ISR { } }
void ep4out_isr(void) __interrupt EP4OUT_ISR { } void ep3out_isr(void) __interrupt EP3OUT_ISR
void ep5in_isr(void) __interrupt EP5IN_ISR { } {
void ep5out_isr(void) __interrupt EP5OUT_ISR { } }
void ep6in_isr(void) __interrupt EP6IN_ISR { } void ep4in_isr(void) __interrupt EP4IN_ISR
void ep6out_isr(void) __interrupt EP6OUT_ISR { } {
void ep7in_isr(void) __interrupt EP7IN_ISR { } }
void ep7out_isr(void) __interrupt EP7OUT_ISR { } void ep4out_isr(void) __interrupt EP4OUT_ISR
{
}
void ep5in_isr(void) __interrupt EP5IN_ISR
{
}
void ep5out_isr(void) __interrupt EP5OUT_ISR
{
}
void ep6in_isr(void) __interrupt EP6IN_ISR
{
}
void ep6out_isr(void) __interrupt EP6OUT_ISR
{
}
void ep7in_isr(void) __interrupt EP7IN_ISR
{
}
void ep7out_isr(void) __interrupt EP7OUT_ISR
{
}
/** /**
* Return the control/status register for an endpoint * Return the control/status register for an endpoint
@ -205,7 +245,7 @@ void ep7out_isr(void) __interrupt EP7OUT_ISR { }
* specified in \a ep * specified in \a ep
* @return on failure: NULL * @return on failure: NULL
*/ */
__xdata uint8_t* usb_get_endpoint_cs_reg(uint8_t ep) __xdata uint8_t *usb_get_endpoint_cs_reg(uint8_t ep)
{ {
/* Mask direction bit */ /* Mask direction bit */
uint8_t ep_num = ep & 0x7F; uint8_t ep_num = ep & 0x7F;
@ -293,12 +333,10 @@ bool usb_handle_get_status(void)
/* Get stall bit for endpoint specified in low byte of wIndex */ /* Get stall bit for endpoint specified in low byte of wIndex */
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex & 0xff); ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex & 0xff);
if (*ep_cs & EPSTALL) { if (*ep_cs & EPSTALL)
IN0BUF[0] = 0x01; IN0BUF[0] = 0x01;
} else
else {
IN0BUF[0] = 0x00; IN0BUF[0] = 0x00;
}
/* Second byte sent has to be always zero */ /* Second byte sent has to be always zero */
IN0BUF[1] = 0; IN0BUF[1] = 0;
@ -333,12 +371,10 @@ bool usb_handle_clear_feature(void)
if (setup_data.wValue == 0) { if (setup_data.wValue == 0) {
/* Unstall the endpoint specified in wIndex */ /* Unstall the endpoint specified in wIndex */
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex); ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex);
if (!ep_cs) { if (!ep_cs)
return false; return false;
}
*ep_cs &= ~EPSTALL; *ep_cs &= ~EPSTALL;
} } else {
else {
/* Unsupported feature, stall EP0 */ /* Unsupported feature, stall EP0 */
STALL_EP0(); STALL_EP0();
} }
@ -362,20 +398,17 @@ bool usb_handle_set_feature(void)
switch (setup_data.bmRequestType) { switch (setup_data.bmRequestType) {
case SF_DEVICE: case SF_DEVICE:
if (setup_data.wValue == 2) { if (setup_data.wValue == 2)
return true; return true;
}
break; break;
case SF_ENDPOINT: case SF_ENDPOINT:
if (setup_data.wValue == 0) { if (setup_data.wValue == 0) {
/* Stall the endpoint specified in wIndex */ /* Stall the endpoint specified in wIndex */
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex); ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex);
if (!ep_cs) { if (!ep_cs)
return false; return false;
}
*ep_cs |= EPSTALL; *ep_cs |= EPSTALL;
} } else {
else {
/* Unsupported endpoint feature */ /* Unsupported endpoint feature */
return false; return false;
} }
@ -416,15 +449,12 @@ bool usb_handle_get_descriptor(void)
/* Supply language descriptor */ /* Supply language descriptor */
SUDPTRH = HI8(&language_descriptor); SUDPTRH = HI8(&language_descriptor);
SUDPTRL = LO8(&language_descriptor); SUDPTRL = LO8(&language_descriptor);
} } else if (setup_data.wIndex == 0x0409 /* US English */) {
else if (setup_data.wIndex == 0x0409 /* US English */) {
/* Supply string descriptor */ /* Supply string descriptor */
SUDPTRH = HI8(en_string_descriptors[descriptor_index - 1]); SUDPTRH = HI8(en_string_descriptors[descriptor_index - 1]);
SUDPTRL = LO8(en_string_descriptors[descriptor_index - 1]); SUDPTRL = LO8(en_string_descriptors[descriptor_index - 1]);
} } else
else {
return false; return false;
}
break; break;
default: default:
/* Unsupported descriptor type */ /* Unsupported descriptor type */
@ -459,23 +489,20 @@ void usb_handle_setup_data(void)
{ {
switch (setup_data.bRequest) { switch (setup_data.bRequest) {
case GET_STATUS: case GET_STATUS:
if (!usb_handle_get_status()) { if (!usb_handle_get_status())
STALL_EP0(); STALL_EP0();
}
break; break;
case CLEAR_FEATURE: case CLEAR_FEATURE:
if (!usb_handle_clear_feature()) { if (!usb_handle_clear_feature())
STALL_EP0(); STALL_EP0();
}
break; break;
case 2: case 4: case 2: case 4:
/* Reserved values */ /* Reserved values */
STALL_EP0(); STALL_EP0();
break; break;
case SET_FEATURE: case SET_FEATURE:
if (!usb_handle_set_feature()) { if (!usb_handle_set_feature())
STALL_EP0(); STALL_EP0();
}
break; break;
case SET_ADDRESS: case SET_ADDRESS:
/* Handled by USB core */ /* Handled by USB core */
@ -485,9 +512,8 @@ void usb_handle_setup_data(void)
STALL_EP0(); STALL_EP0();
break; break;
case GET_DESCRIPTOR: case GET_DESCRIPTOR:
if (!usb_handle_get_descriptor()) { if (!usb_handle_get_descriptor())
STALL_EP0(); STALL_EP0();
}
break; break;
case GET_CONFIGURATION: case GET_CONFIGURATION:
/* OpenULINK has only one configuration, return its index */ /* OpenULINK has only one configuration, return its index */
@ -518,7 +544,8 @@ void usb_handle_setup_data(void)
* USB initialization. Configures USB interrupts, endpoints and performs * USB initialization. Configures USB interrupts, endpoints and performs
* ReNumeration. * ReNumeration.
*/ */
void usb_init(void) { void usb_init(void)
{
/* Mark endpoint 2 IN & OUT as valid */ /* Mark endpoint 2 IN & OUT as valid */
IN07VAL = IN2VAL; IN07VAL = IN2VAL;
OUT07VAL = OUT2VAL; OUT07VAL = OUT2VAL;

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -53,11 +54,11 @@ static uint16_t amt_jtagaccel_port;
/* interface variables /* interface variables
*/ */
static uint8_t aw_control_rst = 0x00; static uint8_t aw_control_rst;
static uint8_t aw_control_fsm = 0x10; static uint8_t aw_control_fsm = 0x10;
static uint8_t aw_control_baudrate = 0x20; static uint8_t aw_control_baudrate = 0x20;
static int rtck_enabled = 0; static int rtck_enabled;
#if PARPORT_USE_PPDEV == 1 #if PARPORT_USE_PPDEV == 1
static int device_handle; static int device_handle;
@ -113,7 +114,7 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
#define AMT_DW(val) do { outb(val, amt_jtagaccel_port + 4); } while (0) #define AMT_DW(val) do { outb(val, amt_jtagaccel_port + 4); } while (0)
#define AMT_DR(val) do { val = inb(amt_jtagaccel_port + 4); } while (0) #define AMT_DR(val) do { val = inb(amt_jtagaccel_port + 4); } while (0)
#endif // PARPORT_USE_PPDEV #endif /* PARPORT_USE_PPDEV */
/* tap_move[i][j]: tap movement command to go from state i to state j /* tap_move[i][j]: tap movement command to go from state i to state j
* 0: Test-Logic-Reset * 0: Test-Logic-Reset
@ -123,18 +124,16 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
* 4: Shift-IR * 4: Shift-IR
* 5: Pause-IR * 5: Pause-IR
*/ */
static uint8_t amt_jtagaccel_tap_move[6][6][2] = static uint8_t amt_jtagaccel_tap_move[6][6][2] = {
{
/* RESET IDLE DRSHIFT DRPAUSE IRSHIFT IRPAUSE */ /* RESET IDLE DRSHIFT DRPAUSE IRSHIFT IRPAUSE */
{{0x1f, 0x00}, {0x0f, 0x00}, {0x05, 0x00}, {0x0a, 0x00}, {0x06, 0x00}, {0x96, 0x00}}, /* RESET */ { {0x1f, 0x00}, {0x0f, 0x00}, {0x05, 0x00}, {0x0a, 0x00}, {0x06, 0x00}, {0x96, 0x00} }, /* RESET */
{{0x1f, 0x00}, {0x00, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x0b, 0x00}}, /* IDLE */ { {0x1f, 0x00}, {0x00, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x0b, 0x00} }, /* IDLE */
{{0x1f, 0x00}, {0x0d, 0x00}, {0x00, 0x00}, {0x01, 0x00}, {0x8f, 0x09}, {0x8f, 0x01}}, /* DRSHIFT */ { {0x1f, 0x00}, {0x0d, 0x00}, {0x00, 0x00}, {0x01, 0x00}, {0x8f, 0x09}, {0x8f, 0x01} }, /* DRSHIFT */
{{0x1f, 0x00}, {0x0c, 0x00}, {0x08, 0x00}, {0x00, 0x00}, {0x8f, 0x09}, {0x8f, 0x01}}, /* DRPAUSE */ { {0x1f, 0x00}, {0x0c, 0x00}, {0x08, 0x00}, {0x00, 0x00}, {0x8f, 0x09}, {0x8f, 0x01} }, /* DRPAUSE */
{{0x1f, 0x00}, {0x0d, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x00, 0x00}, {0x01, 0x00}}, /* IRSHIFT */ { {0x1f, 0x00}, {0x0d, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x00, 0x00}, {0x01, 0x00} }, /* IRSHIFT */
{{0x1f, 0x00}, {0x0c, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x08, 0x00}, {0x00, 0x00}}, /* IRPAUSE */ { {0x1f, 0x00}, {0x0c, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x08, 0x00}, {0x00, 0x00} }, /* IRPAUSE */
}; };
static void amt_jtagaccel_reset(int trst, int srst) static void amt_jtagaccel_reset(int trst, int srst)
{ {
if (trst == 1) if (trst == 1)
@ -163,8 +162,7 @@ static void amt_jtagaccel_end_state(tap_state_t state)
{ {
if (tap_is_state_stable(state)) if (tap_is_state_stable(state))
tap_set_end_state(state); tap_set_end_state(state);
else else {
{
LOG_ERROR("BUG: %i is not a valid end state", state); LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1); exit(-1);
} }
@ -179,9 +177,11 @@ static void amt_wait_scan_busy(void)
while (((ar_status) & 0x80) && (timeout-- > 0)) while (((ar_status) & 0x80) && (timeout-- > 0))
AMT_AR(ar_status); AMT_AR(ar_status);
if (ar_status & 0x80) if (ar_status & 0x80) {
{ LOG_ERROR(
LOG_ERROR("amt_jtagaccel timed out while waiting for end of scan, rtck was %s, last AR_STATUS: 0x%2.2x", (rtck_enabled) ? "enabled" : "disabled", ar_status); "amt_jtagaccel timed out while waiting for end of scan, rtck was %s, last AR_STATUS: 0x%2.2x",
(rtck_enabled) ? "enabled" : "disabled",
ar_status);
exit(-1); exit(-1);
} }
} }
@ -199,14 +199,13 @@ static void amt_jtagaccel_state_move(void)
aw_scan_tms_5 = 0x40 | (tms_scan[0] & 0x1f); aw_scan_tms_5 = 0x40 | (tms_scan[0] & 0x1f);
AMT_AW(aw_scan_tms_5); AMT_AW(aw_scan_tms_5);
int jtag_speed=0; int jtag_speed = 0;
int retval = jtag_get_speed(&jtag_speed); int retval = jtag_get_speed(&jtag_speed);
assert(retval == ERROR_OK); assert(retval == ERROR_OK);
if (jtag_speed > 3 || rtck_enabled) if (jtag_speed > 3 || rtck_enabled)
amt_wait_scan_busy(); amt_wait_scan_busy();
if (tms_scan[0] & 0x80) if (tms_scan[0] & 0x80) {
{
aw_scan_tms_5 = 0x40 | (tms_scan[1] & 0x1f); aw_scan_tms_5 = 0x40 | (tms_scan[1] & 0x1f);
AMT_AW(aw_scan_tms_5); AMT_AW(aw_scan_tms_5);
if (jtag_speed > 3 || rtck_enabled) if (jtag_speed > 3 || rtck_enabled)
@ -225,21 +224,18 @@ static void amt_jtagaccel_runtest(int num_cycles)
tap_state_t saved_end_state = tap_get_end_state(); tap_state_t saved_end_state = tap_get_end_state();
/* only do a state_move when we're not already in IDLE */ /* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE) if (tap_get_state() != TAP_IDLE) {
{
amt_jtagaccel_end_state(TAP_IDLE); amt_jtagaccel_end_state(TAP_IDLE);
amt_jtagaccel_state_move(); amt_jtagaccel_state_move();
} }
while (num_cycles - i >= 5) while (num_cycles - i >= 5) {
{
aw_scan_tms_5 = 0x40; aw_scan_tms_5 = 0x40;
AMT_AW(aw_scan_tms_5); AMT_AW(aw_scan_tms_5);
i += 5; i += 5;
} }
if (num_cycles - i > 0) if (num_cycles - i > 0) {
{
aw_scan_tms_1to4 = 0x80 | ((num_cycles - i - 1) & 0x3) << 4; aw_scan_tms_1to4 = 0x80 | ((num_cycles - i - 1) & 0x3) << 4;
AMT_AW(aw_scan_tms_1to4); AMT_AW(aw_scan_tms_1to4);
} }
@ -272,8 +268,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
amt_jtagaccel_end_state(saved_end_state); amt_jtagaccel_end_state(saved_end_state);
/* handle unaligned bits at the beginning */ /* handle unaligned bits at the beginning */
if ((scan_size - 1) % 8) if ((scan_size - 1) % 8) {
{
aw_tdi_option = 0x30 | (((scan_size - 1) % 8) - 1); aw_tdi_option = 0x30 | (((scan_size - 1) % 8) - 1);
AMT_AW(aw_tdi_option); AMT_AW(aw_tdi_option);
@ -282,8 +277,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
if (jtag_speed_var > 3 || rtck_enabled) if (jtag_speed_var > 3 || rtck_enabled)
amt_wait_scan_busy(); amt_wait_scan_busy();
if ((type == SCAN_IN) || (type == SCAN_IO)) if ((type == SCAN_IN) || (type == SCAN_IO)) {
{
AMT_DR(dr_tdo); AMT_DR(dr_tdo);
dr_tdo = dr_tdo >> (8 - ((scan_size - 1) % 8)); dr_tdo = dr_tdo >> (8 - ((scan_size - 1) % 8));
buf_set_u32(buffer, bit_count, (scan_size - 1) % 8, dr_tdo); buf_set_u32(buffer, bit_count, (scan_size - 1) % 8, dr_tdo);
@ -293,15 +287,13 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
bits_left -= (scan_size - 1) % 8; bits_left -= (scan_size - 1) % 8;
} }
while (bits_left - 1 >= 8) while (bits_left - 1 >= 8) {
{
dw_tdi_scan = buf_get_u32(buffer, bit_count, 8) & 0xff; dw_tdi_scan = buf_get_u32(buffer, bit_count, 8) & 0xff;
AMT_DW(dw_tdi_scan); AMT_DW(dw_tdi_scan);
if (jtag_speed_var > 3 || rtck_enabled) if (jtag_speed_var > 3 || rtck_enabled)
amt_wait_scan_busy(); amt_wait_scan_busy();
if ((type == SCAN_IN) || (type == SCAN_IO)) if ((type == SCAN_IN) || (type == SCAN_IO)) {
{
AMT_DR(dr_tdo); AMT_DR(dr_tdo);
buf_set_u32(buffer, bit_count, 8, dr_tdo); buf_set_u32(buffer, bit_count, 8, dr_tdo);
} }
@ -310,22 +302,22 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
bits_left -= 8; bits_left -= 8;
} }
tms_scan[0] = amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][0]; tms_scan[0] =
tms_scan[1] = amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][1]; amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][0];
tms_scan[1] =
amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][1];
aw_tms_scan = 0x40 | (tms_scan[0] & 0x1f) | (buf_get_u32(buffer, bit_count, 1) << 5); aw_tms_scan = 0x40 | (tms_scan[0] & 0x1f) | (buf_get_u32(buffer, bit_count, 1) << 5);
AMT_AW(aw_tms_scan); AMT_AW(aw_tms_scan);
if (jtag_speed_var > 3 || rtck_enabled) if (jtag_speed_var > 3 || rtck_enabled)
amt_wait_scan_busy(); amt_wait_scan_busy();
if ((type == SCAN_IN) || (type == SCAN_IO)) if ((type == SCAN_IN) || (type == SCAN_IO)) {
{
AMT_DR(dr_tdo); AMT_DR(dr_tdo);
dr_tdo = dr_tdo >> 7; dr_tdo = dr_tdo >> 7;
buf_set_u32(buffer, bit_count, 1, dr_tdo); buf_set_u32(buffer, bit_count, 1, dr_tdo);
} }
if (tms_scan[0] & 0x80) if (tms_scan[0] & 0x80) {
{
aw_tms_scan = 0x40 | (tms_scan[1] & 0x1f); aw_tms_scan = 0x40 | (tms_scan[1] & 0x1f);
AMT_AW(aw_tms_scan); AMT_AW(aw_tms_scan);
if (jtag_speed_var > 3 || rtck_enabled) if (jtag_speed_var > 3 || rtck_enabled)
@ -347,23 +339,23 @@ static int amt_jtagaccel_execute_queue(void)
*/ */
retval = ERROR_OK; retval = ERROR_OK;
while (cmd) while (cmd) {
{ switch (cmd->type) {
switch (cmd->type)
{
case JTAG_RESET: case JTAG_RESET:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); LOG_DEBUG("reset trst: %i srst %i",
cmd->cmd.reset->trst,
cmd->cmd.reset->srst);
#endif #endif
if (cmd->cmd.reset->trst == 1) if (cmd->cmd.reset->trst == 1)
{
tap_set_state(TAP_RESET); tap_set_state(TAP_RESET);
}
amt_jtagaccel_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); amt_jtagaccel_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
break; break;
case JTAG_RUNTEST: case JTAG_RUNTEST:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); LOG_DEBUG("runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles,
cmd->cmd.runtest->end_state);
#endif #endif
amt_jtagaccel_end_state(cmd->cmd.runtest->end_state); amt_jtagaccel_end_state(cmd->cmd.runtest->end_state);
amt_jtagaccel_runtest(cmd->cmd.runtest->num_cycles); amt_jtagaccel_runtest(cmd->cmd.runtest->num_cycles);
@ -418,7 +410,13 @@ int amt_jtagaccel_get_giveio_access(void)
if (version.dwPlatformId != VER_PLATFORM_WIN32_NT) if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
return 0; return 0;
h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); h = CreateFile("\\\\.\\giveio",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
errno = ENODEV; errno = ENODEV;
return -1; return -1;
@ -442,8 +440,7 @@ static int amt_jtagaccel_init(void)
uint8_t ar_status; uint8_t ar_status;
#if PARPORT_USE_PPDEV == 1 #if PARPORT_USE_PPDEV == 1
if (device_handle > 0) if (device_handle > 0) {
{
LOG_ERROR("device is already opened"); LOG_ERROR("device is already opened");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -451,23 +448,21 @@ static int amt_jtagaccel_init(void)
snprintf(buffer, 256, "/dev/parport%d", amt_jtagaccel_port); snprintf(buffer, 256, "/dev/parport%d", amt_jtagaccel_port);
device_handle = open(buffer, O_RDWR); device_handle = open(buffer, O_RDWR);
if (device_handle < 0) if (device_handle < 0) {
{ LOG_ERROR(
LOG_ERROR("cannot open device. check it exists and that user read and write rights are set"); "cannot open device. check it exists and that user read and write rights are set");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
i = ioctl(device_handle, PPCLAIM); i = ioctl(device_handle, PPCLAIM);
if (i < 0) if (i < 0) {
{
LOG_ERROR("cannot claim device"); LOG_ERROR("cannot claim device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
i = IEEE1284_MODE_EPP; i = IEEE1284_MODE_EPP;
i = ioctl(device_handle, PPSETMODE, & i); i = ioctl(device_handle, PPSETMODE, &i);
if (i < 0) if (i < 0) {
{
LOG_ERROR(" cannot set compatible mode to device"); LOG_ERROR(" cannot set compatible mode to device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -479,8 +474,7 @@ static int amt_jtagaccel_init(void)
i = ioctl(device_handle, PPWCONTROL, &control_port); i = ioctl(device_handle, PPWCONTROL, &control_port);
#else #else
if (amt_jtagaccel_port == 0) if (amt_jtagaccel_port == 0) {
{
amt_jtagaccel_port = 0x378; amt_jtagaccel_port = 0x378;
LOG_WARNING("No parport port specified, using default '0x378' (LPT1)"); LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
} }
@ -494,8 +488,8 @@ static int amt_jtagaccel_init(void)
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
/* prepare epp port */ /* prepare epp port
/* clear timeout */ * clear timeout */
status_port = inb(amt_jtagaccel_port + 1); status_port = inb(amt_jtagaccel_port + 1);
outb(status_port | 0x1, amt_jtagaccel_port + 1); outb(status_port | 0x1, amt_jtagaccel_port + 1);
@ -504,8 +498,7 @@ static int amt_jtagaccel_init(void)
outb(0x04, amt_jtagaccel_port + 2); outb(0x04, amt_jtagaccel_port + 2);
#endif #endif
if (rtck_enabled) if (rtck_enabled) {
{
/* set RTCK enable bit */ /* set RTCK enable bit */
aw_control_fsm |= 0x02; aw_control_fsm |= 0x02;
} }
@ -542,17 +535,13 @@ static int amt_jtagaccel_quit(void)
COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command) COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command)
{ {
if (CMD_ARGC == 1) if (CMD_ARGC == 1) {
{
/* only if the port wasn't overwritten by cmdline */ /* only if the port wasn't overwritten by cmdline */
if (amt_jtagaccel_port == 0) if (amt_jtagaccel_port == 0) {
{
uint16_t port; uint16_t port;
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], port); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], port);
amt_jtagaccel_port = port; amt_jtagaccel_port = port;
} } else {
else
{
LOG_ERROR("The parport port was already configured!"); LOG_ERROR("The parport port was already configured!");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -565,22 +554,17 @@ COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command)
COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command) COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command)
{ {
if (CMD_ARGC == 0) if (CMD_ARGC == 0) {
{ command_print(CMD_CTX,
command_print(CMD_CTX, "amt_jtagaccel RTCK feature %s", (rtck_enabled) ? "enabled" : "disabled"); "amt_jtagaccel RTCK feature %s",
(rtck_enabled) ? "enabled" : "disabled");
return ERROR_OK; return ERROR_OK;
} } else {
else
{
if (strcmp(CMD_ARGV[0], "enabled") == 0) if (strcmp(CMD_ARGV[0], "enabled") == 0)
{
rtck_enabled = 1; rtck_enabled = 1;
}
else else
{
rtck_enabled = 0; rtck_enabled = 0;
} }
}
return ERROR_OK; return ERROR_OK;
} }

View File

@ -59,9 +59,13 @@ static void armjtagew_end_state(tap_state_t state);
static void armjtagew_state_move(void); static void armjtagew_state_move(void);
static void armjtagew_path_move(int num_states, tap_state_t *path); static void armjtagew_path_move(int num_states, tap_state_t *path);
static void armjtagew_runtest(int num_cycles); static void armjtagew_runtest(int num_cycles);
static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command); static void armjtagew_scan(bool ir_scan,
enum scan_type type,
uint8_t *buffer,
int scan_size,
struct scan_command *command);
static void armjtagew_reset(int trst, int srst); static void armjtagew_reset(int trst, int srst);
//static void armjtagew_simple_command(uint8_t command); /* static void armjtagew_simple_command(uint8_t command); */
static int armjtagew_get_status(void); static int armjtagew_get_status(void);
/* tap buffer functions */ /* tap buffer functions */
@ -73,7 +77,7 @@ static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_c
/* ARM-JTAG-EW lowlevel functions */ /* ARM-JTAG-EW lowlevel functions */
struct armjtagew { struct armjtagew {
struct usb_dev_handle* usb_handle; struct usb_dev_handle *usb_handle;
}; };
static struct armjtagew *armjtagew_usb_open(void); static struct armjtagew *armjtagew_usb_open(void);
@ -89,10 +93,10 @@ static int armjtagew_get_version_info(void);
static void armjtagew_debug_buffer(uint8_t *buffer, int length); static void armjtagew_debug_buffer(uint8_t *buffer, int length);
#endif #endif
static struct armjtagew* armjtagew_handle; static struct armjtagew *armjtagew_handle;
/***************************************************************************/ /**************************************************************************
/* External interface implementation */ * External interface implementation */
static int armjtagew_execute_queue(void) static int armjtagew_execute_queue(void)
{ {
@ -101,12 +105,11 @@ static int armjtagew_execute_queue(void)
enum scan_type type; enum scan_type type;
uint8_t *buffer; uint8_t *buffer;
while (cmd != NULL) while (cmd != NULL) {
{ switch (cmd->type) {
switch (cmd->type)
{
case JTAG_RUNTEST: case JTAG_RUNTEST:
DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ DEBUG_JTAG_IO("runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles, \
cmd->cmd.runtest->end_state); cmd->cmd.runtest->end_state);
armjtagew_end_state(cmd->cmd.runtest->end_state); armjtagew_end_state(cmd->cmd.runtest->end_state);
@ -125,7 +128,8 @@ static int armjtagew_execute_queue(void)
cmd->cmd.pathmove->num_states, \ cmd->cmd.pathmove->num_states, \
cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
armjtagew_path_move(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path); armjtagew_path_move(cmd->cmd.pathmove->num_states,
cmd->cmd.pathmove->path);
break; break;
case JTAG_SCAN: case JTAG_SCAN:
@ -140,18 +144,20 @@ static int armjtagew_execute_queue(void)
armjtagew_debug_buffer(buffer, (scan_size + 7) / 8); armjtagew_debug_buffer(buffer, (scan_size + 7) / 8);
#endif #endif
type = jtag_scan_type(cmd->cmd.scan); type = jtag_scan_type(cmd->cmd.scan);
armjtagew_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size, cmd->cmd.scan); armjtagew_scan(cmd->cmd.scan->ir_scan,
type, buffer,
scan_size, cmd->cmd.scan);
break; break;
case JTAG_RESET: case JTAG_RESET:
DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); DEBUG_JTAG_IO("reset trst: %i srst %i",
cmd->cmd.reset->trst,
cmd->cmd.reset->srst);
armjtagew_tap_execute(); armjtagew_tap_execute();
if (cmd->cmd.reset->trst == 1) if (cmd->cmd.reset->trst == 1)
{
tap_set_state(TAP_RESET); tap_set_state(TAP_RESET);
}
armjtagew_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); armjtagew_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
break; break;
@ -183,8 +189,7 @@ static int armjtagew_speed(int speed)
result = armjtagew_usb_message(armjtagew_handle, 5, 4); result = armjtagew_usb_message(armjtagew_handle, 5, 4);
if (result < 0) if (result < 0) {
{
LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result); LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -192,15 +197,11 @@ static int armjtagew_speed(int speed)
usb_out_buffer[0] = CMD_GET_TCK_FREQUENCY; usb_out_buffer[0] = CMD_GET_TCK_FREQUENCY;
result = armjtagew_usb_message(armjtagew_handle, 1, 4); result = armjtagew_usb_message(armjtagew_handle, 1, 4);
speed_real = (int)buf_get_u32(usb_in_buffer, 0, 32) / 1000; speed_real = (int)buf_get_u32(usb_in_buffer, 0, 32) / 1000;
if (result < 0) if (result < 0) {
{
LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result); LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} } else
else
{
LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real); LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real);
}
return ERROR_OK; return ERROR_OK;
} }
@ -212,7 +213,7 @@ static int armjtagew_khz(int khz, int *jtag_speed)
return ERROR_OK; return ERROR_OK;
} }
static int armjtagew_speed_div(int speed, int* khz) static int armjtagew_speed_div(int speed, int *khz)
{ {
*khz = speed; *khz = speed;
@ -225,17 +226,15 @@ static int armjtagew_init(void)
armjtagew_handle = armjtagew_usb_open(); armjtagew_handle = armjtagew_usb_open();
if (armjtagew_handle == 0) if (armjtagew_handle == 0) {
{ LOG_ERROR(
LOG_ERROR("Cannot find ARM-JTAG-EW Interface! Please check connection and permissions."); "Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
check_cnt = 0; check_cnt = 0;
while (check_cnt < 3) while (check_cnt < 3) {
{ if (armjtagew_get_version_info() == ERROR_OK) {
if (armjtagew_get_version_info() == ERROR_OK)
{
/* attempt to get status */ /* attempt to get status */
armjtagew_get_status(); armjtagew_get_status();
break; break;
@ -245,9 +244,7 @@ static int armjtagew_init(void)
} }
if (check_cnt == 3) if (check_cnt == 3)
{
LOG_INFO("ARM-JTAG-EW initial read failed, don't worry"); LOG_INFO("ARM-JTAG-EW initial read failed, don't worry");
}
/* Initial JTAG speed (for reset and initialization): 32 kHz */ /* Initial JTAG speed (for reset and initialization): 32 kHz */
armjtagew_speed(32); armjtagew_speed(32);
@ -266,17 +263,14 @@ static int armjtagew_quit(void)
return ERROR_OK; return ERROR_OK;
} }
/***************************************************************************/ /**************************************************************************
/* Queue command implementations */ * Queue command implementations */
static void armjtagew_end_state(tap_state_t state) static void armjtagew_end_state(tap_state_t state)
{ {
if (tap_is_state_stable(state)) if (tap_is_state_stable(state))
{
tap_set_end_state(state); tap_set_end_state(state);
} else {
else
{
LOG_ERROR("BUG: %i is not a valid end state", state); LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1); exit(-1);
} }
@ -290,8 +284,7 @@ static void armjtagew_state_move(void)
uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state()); int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
for (i = 0; i < tms_count; i++) for (i = 0; i < tms_count; i++) {
{
tms = (tms_scan >> i) & 1; tms = (tms_scan >> i) & 1;
armjtagew_tap_append_step(tms, 0); armjtagew_tap_append_step(tms, 0);
} }
@ -303,24 +296,19 @@ static void armjtagew_path_move(int num_states, tap_state_t *path)
{ {
int i; int i;
for (i = 0; i < num_states; i++) for (i = 0; i < num_states; i++) {
{
/* /*
* TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode. * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode.
* Either handle that here, or update the documentation with examples * Either handle that here, or update the documentation with examples
* how to fix that in the configuration files. * how to fix that in the configuration files.
*/ */
if (path[i] == tap_state_transition(tap_get_state(), false)) if (path[i] == tap_state_transition(tap_get_state(), false))
{
armjtagew_tap_append_step(0, 0); armjtagew_tap_append_step(0, 0);
}
else if (path[i] == tap_state_transition(tap_get_state(), true)) else if (path[i] == tap_state_transition(tap_get_state(), true))
{
armjtagew_tap_append_step(1, 0); armjtagew_tap_append_step(1, 0);
} else {
else LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
{ tap_state_name(tap_get_state()), tap_state_name(path[i]));
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(path[i]));
exit(-1); exit(-1);
} }
@ -337,27 +325,26 @@ static void armjtagew_runtest(int num_cycles)
tap_state_t saved_end_state = tap_get_end_state(); tap_state_t saved_end_state = tap_get_end_state();
/* only do a state_move when we're not already in IDLE */ /* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE) if (tap_get_state() != TAP_IDLE) {
{
armjtagew_end_state(TAP_IDLE); armjtagew_end_state(TAP_IDLE);
armjtagew_state_move(); armjtagew_state_move();
} }
/* execute num_cycles */ /* execute num_cycles */
for (i = 0; i < num_cycles; i++) for (i = 0; i < num_cycles; i++)
{
armjtagew_tap_append_step(0, 0); armjtagew_tap_append_step(0, 0);
}
/* finish in end_state */ /* finish in end_state */
armjtagew_end_state(saved_end_state); armjtagew_end_state(saved_end_state);
if (tap_get_state() != tap_get_end_state()) if (tap_get_state() != tap_get_end_state())
{
armjtagew_state_move(); armjtagew_state_move();
}
} }
static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command) static void armjtagew_scan(bool ir_scan,
enum scan_type type,
uint8_t *buffer,
int scan_size,
struct scan_command *command)
{ {
tap_state_t saved_end_state; tap_state_t saved_end_state;
@ -380,9 +367,7 @@ static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, i
tap_set_state(ir_scan ? TAP_IRPAUSE : TAP_DRPAUSE); tap_set_state(ir_scan ? TAP_IRPAUSE : TAP_DRPAUSE);
if (tap_get_state() != tap_get_end_state()) if (tap_get_state() != tap_get_end_state())
{
armjtagew_state_move(); armjtagew_state_move();
}
} }
static void armjtagew_reset(int trst, int srst) static void armjtagew_reset(int trst, int srst)
@ -396,27 +381,21 @@ static void armjtagew_reset(int trst, int srst)
LOG_DEBUG("trst: %i, srst: %i", trst, srst); LOG_DEBUG("trst: %i, srst: %i", trst, srst);
if (srst == 0) if (srst == 0) {
{
val |= srst_mask; val |= srst_mask;
outp_en &= ~srst_mask; /* tristate */ outp_en &= ~srst_mask; /* tristate */
change_mask |= srst_mask; change_mask |= srst_mask;
} } else if (srst == 1) {
else if (srst == 1)
{
val &= ~srst_mask; val &= ~srst_mask;
outp_en |= srst_mask; outp_en |= srst_mask;
change_mask |= srst_mask; change_mask |= srst_mask;
} }
if (trst == 0) if (trst == 0) {
{
val |= trst_mask; val |= trst_mask;
outp_en &= ~trst_mask; /* tristate */ outp_en &= ~trst_mask; /* tristate */
change_mask |= trst_mask; change_mask |= trst_mask;
} } else if (trst == 1) {
else if (trst == 1)
{
val &= ~trst_mask; val &= ~trst_mask;
outp_en |= trst_mask; outp_en |= trst_mask;
change_mask |= trst_mask; change_mask |= trst_mask;
@ -428,9 +407,7 @@ static void armjtagew_reset(int trst, int srst)
usb_out_buffer[3] = change_mask; usb_out_buffer[3] = change_mask;
result = armjtagew_usb_write(armjtagew_handle, 4); result = armjtagew_usb_write(armjtagew_handle, 4);
if (result != 4) if (result != 4)
{
LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result); LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
}
} }
static int armjtagew_get_status(void) static int armjtagew_get_status(void)
@ -440,10 +417,10 @@ static int armjtagew_get_status(void)
usb_out_buffer[0] = CMD_GET_TAPHW_STATE; usb_out_buffer[0] = CMD_GET_TAPHW_STATE;
result = armjtagew_usb_message(armjtagew_handle, 1, 12); result = armjtagew_usb_message(armjtagew_handle, 1, 12);
if (result == 0) if (result == 0) {
{
unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16); unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16);
LOG_INFO("U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s", LOG_INFO(
"U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
(int)(buf_get_u32(usb_in_buffer + 0, 0, 16)), (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)),
(int)(buf_get_u32(usb_in_buffer + 2, 0, 16)), (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)),
(int)(buf_get_u32(usb_in_buffer + 4, 0, 16)), (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
@ -453,14 +430,9 @@ static int armjtagew_get_status(void)
usb_in_buffer[10] ? "enabled" : "disabled"); usb_in_buffer[10] ? "enabled" : "disabled");
if (u_tg < 1500) if (u_tg < 1500)
{
LOG_ERROR("Vref too low. Check Target Power"); LOG_ERROR("Vref too low. Check Target Power");
} } else
}
else
{
LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result); LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
}
return ERROR_OK; return ERROR_OK;
} }
@ -475,34 +447,35 @@ static int armjtagew_get_version_info(void)
usb_out_buffer[0] = CMD_GET_VERSION; usb_out_buffer[0] = CMD_GET_VERSION;
result = armjtagew_usb_message(armjtagew_handle, 1, 4 + 15 + 256); result = armjtagew_usb_message(armjtagew_handle, 1, 4 + 15 + 256);
if (result != 0) if (result != 0) {
{
LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result); LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
memcpy(sn, usb_in_buffer + 4, 15); memcpy(sn, usb_in_buffer + 4, 15);
sn[15] = '\0'; sn[15] = '\0';
memcpy(auxinfo, usb_in_buffer + 4+15, 256); memcpy(auxinfo, usb_in_buffer + 4+15, 256);
auxinfo[256] = '\0'; auxinfo[256] = '\0';
LOG_INFO("ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s", \ LOG_INFO(
usb_in_buffer[1], usb_in_buffer[0], \ "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s", \
usb_in_buffer[1],
usb_in_buffer[0], \
isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X', \ isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X', \
sn, auxinfo); sn,
auxinfo);
if (1 != usb_in_buffer[1] || 6 != usb_in_buffer[0]) if (1 != usb_in_buffer[1] || 6 != usb_in_buffer[0])
{ LOG_WARNING(
LOG_WARNING("ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.", usb_in_buffer[1], usb_in_buffer[0]); "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
} usb_in_buffer[1],
usb_in_buffer[0]);
return ERROR_OK; return ERROR_OK;
} }
COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command) COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
{ {
if (armjtagew_get_version_info() == ERROR_OK) if (armjtagew_get_version_info() == ERROR_OK) {
{
/* attempt to get status */ /* attempt to get status */
armjtagew_get_status(); armjtagew_get_status();
} }
@ -532,8 +505,8 @@ struct jtag_interface armjtagew_interface = {
.quit = armjtagew_quit, .quit = armjtagew_quit,
}; };
/***************************************************************************/ /**************************************************************************
/* ARM-JTAG-EW tap functions */ * ARM-JTAG-EW tap functions */
/* 2048 is the max value we can use here */ /* 2048 is the max value we can use here */
#define ARMJTAGEW_TAP_BUFFER_SIZE 2048 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
@ -569,9 +542,7 @@ static void armjtagew_tap_ensure_space(int scans, int bits)
int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length; int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length;
if (scans > available_scans || bits > available_bits) if (scans > available_scans || bits > available_bits)
{
armjtagew_tap_execute(); armjtagew_tap_execute();
}
} }
static void armjtagew_tap_append_step(int tms, int tdi) static void armjtagew_tap_append_step(int tms, int tdi)
@ -579,40 +550,29 @@ static void armjtagew_tap_append_step(int tms, int tdi)
last_tms = tms; last_tms = tms;
int index_local = tap_length / 8; int index_local = tap_length / 8;
if (index_local < ARMJTAGEW_TAP_BUFFER_SIZE) if (index_local < ARMJTAGEW_TAP_BUFFER_SIZE) {
{
int bit_index = tap_length % 8; int bit_index = tap_length % 8;
uint8_t bit = 1 << bit_index; uint8_t bit = 1 << bit_index;
if (tms) if (tms)
{
tms_buffer[index_local] |= bit; tms_buffer[index_local] |= bit;
}
else else
{
tms_buffer[index_local] &= ~bit; tms_buffer[index_local] &= ~bit;
}
if (tdi) if (tdi)
{
tdi_buffer[index_local] |= bit; tdi_buffer[index_local] |= bit;
}
else else
{
tdi_buffer[index_local] &= ~bit; tdi_buffer[index_local] &= ~bit;
}
tap_length++; tap_length++;
} } else
else
{
LOG_ERROR("armjtagew_tap_append_step, overflow"); LOG_ERROR("armjtagew_tap_append_step, overflow");
}
} }
void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command) void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
{ {
struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[pending_scan_results_length]; struct pending_scan_result *pending_scan_result =
&pending_scan_results_buffer[pending_scan_results_length];
int i; int i;
pending_scan_result->first = tap_length; pending_scan_result->first = tap_length;
@ -621,9 +581,7 @@ void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command
pending_scan_result->buffer = buffer; pending_scan_result->buffer = buffer;
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{
armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1); armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1);
}
pending_scan_results_length++; pending_scan_results_length++;
} }
@ -637,11 +595,9 @@ static int armjtagew_tap_execute(void)
int i; int i;
int result; int result;
if (tap_length > 0) if (tap_length > 0) {
{
/* Pad last byte so that tap_length is divisible by 8 */ /* Pad last byte so that tap_length is divisible by 8 */
while (tap_length % 8 != 0) while (tap_length % 8 != 0) {
{
/* More of the last TMS value keeps us in the same state, /* More of the last TMS value keeps us in the same state,
* analogous to free-running JTAG interfaces. */ * analogous to free-running JTAG interfaces. */
armjtagew_tap_append_step(last_tms, 0); armjtagew_tap_append_step(last_tms, 0);
@ -654,36 +610,33 @@ static int armjtagew_tap_execute(void)
tms_offset = 3; tms_offset = 3;
for (i = 0; i < byte_length; i++) for (i = 0; i < byte_length; i++)
{ usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i], 8);
usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i],8);
}
tdi_offset = tms_offset + byte_length; tdi_offset = tms_offset + byte_length;
for (i = 0; i < byte_length; i++) for (i = 0; i < byte_length; i++)
{ usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i], 8);
usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i],8);
}
result = armjtagew_usb_message(armjtagew_handle, 3 + 2 * byte_length, byte_length + 4); result = armjtagew_usb_message(armjtagew_handle,
3 + 2 * byte_length,
byte_length + 4);
if (result == 0) if (result == 0) {
{
int stat_local; int stat_local;
stat_local = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32); stat_local = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32);
if (stat_local) { if (stat_local) {
LOG_ERROR("armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command", stat_local); LOG_ERROR(
"armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
stat_local);
return ERROR_JTAG_QUEUE_FAILED; return ERROR_JTAG_QUEUE_FAILED;
} }
for (i = 0; i < byte_length; i++) for (i = 0; i < byte_length; i++)
{ tdo_buffer[i] = flip_u32(usb_in_buffer[i], 8);
tdo_buffer[i] = flip_u32(usb_in_buffer[i],8);
}
for (i = 0; i < pending_scan_results_length; i++) for (i = 0; i < pending_scan_results_length; i++) {
{ struct pending_scan_result *pending_scan_result =
struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[i]; &pending_scan_results_buffer[i];
uint8_t *buffer = pending_scan_result->buffer; uint8_t *buffer = pending_scan_result->buffer;
int length = pending_scan_result->length; int length = pending_scan_result->length;
int first = pending_scan_result->first; int first = pending_scan_result->first;
@ -698,21 +651,18 @@ static int armjtagew_tap_execute(void)
armjtagew_debug_buffer(buffer, byte_length); armjtagew_debug_buffer(buffer, byte_length);
#endif #endif
if (jtag_read_buffer(buffer, command) != ERROR_OK) if (jtag_read_buffer(buffer, command) != ERROR_OK) {
{
armjtagew_tap_init(); armjtagew_tap_init();
return ERROR_JTAG_QUEUE_FAILED; return ERROR_JTAG_QUEUE_FAILED;
} }
if (pending_scan_result->buffer != NULL) if (pending_scan_result->buffer != NULL)
{
free(pending_scan_result->buffer); free(pending_scan_result->buffer);
} }
} } else {
} LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
else result,
{ byte_length);
LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d", result, byte_length);
return ERROR_JTAG_QUEUE_FAILED; return ERROR_JTAG_QUEUE_FAILED;
} }
@ -722,10 +672,10 @@ static int armjtagew_tap_execute(void)
return ERROR_OK; return ERROR_OK;
} }
/*****************************************************************************/ /****************************************************************************
/* JLink USB low-level functions */ * JLink USB low-level functions */
static struct armjtagew* armjtagew_usb_open() static struct armjtagew *armjtagew_usb_open()
{ {
usb_init(); usb_init();
@ -765,17 +715,15 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in
int result; int result;
result = armjtagew_usb_write(armjtagew, out_length); result = armjtagew_usb_write(armjtagew, out_length);
if (result == out_length) if (result == out_length) {
{
result = armjtagew_usb_read(armjtagew, in_length); result = armjtagew_usb_read(armjtagew, in_length);
if (result != in_length) if (result != in_length) {
{ LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)",
LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", in_length, result); in_length,
result);
return -1; return -1;
} }
} } else {
else
{
LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result); LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
return -1; return -1;
} }
@ -787,14 +735,15 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
{ {
int result; int result;
if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) {
{ LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)", out_length, ARMJTAGEW_OUT_BUFFER_SIZE); out_length,
ARMJTAGEW_OUT_BUFFER_SIZE);
return -1; return -1;
} }
result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, \ result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, \
(char*)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT); (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT);
DEBUG_JTAG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result); DEBUG_JTAG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
@ -808,7 +757,7 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length) static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
{ {
int result = usb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN, \ int result = usb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN, \
(char*)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT); (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT);
DEBUG_JTAG_IO("armjtagew_usb_read, result = %d", result); DEBUG_JTAG_IO("armjtagew_usb_read, result = %d", result);
@ -828,17 +777,15 @@ static void armjtagew_debug_buffer(uint8_t *buffer, int length)
int i; int i;
int j; int j;
for (i = 0; i < length; i += BYTES_PER_LINE) for (i = 0; i < length; i += BYTES_PER_LINE) {
{
snprintf(line, 5, "%04x", i); snprintf(line, 5, "%04x", i);
for (j = i; j < i + BYTES_PER_LINE && j < length; j++) for (j = i; j < i + BYTES_PER_LINE && j < length; j++) {
{
snprintf(s, 4, " %02x", buffer[j]); snprintf(s, 4, " %02x", buffer[j]);
strcat(line, s); strcat(line, s);
} }
LOG_DEBUG("%s", line); LOG_DEBUG("%s", line);
// Prevent GDB timeout (writing to log might take some time) /* Prevent GDB timeout (writing to log might take some time) */
keep_alive(); keep_alive();
} }
} }

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -26,7 +27,6 @@
#include <sys/mman.h> #include <sys/mman.h>
/* AT91RM9200 */ /* AT91RM9200 */
#define AT91C_BASE_SYS (0xfffff000) #define AT91C_BASE_SYS (0xfffff000)
@ -78,9 +78,8 @@
#define P30 (1 << 30) #define P30 (1 << 30)
#define P31 (1 << 31) #define P31 (1 << 31)
struct device_t struct device_t {
{ char *name;
char* name;
int TDO_PIO; /* PIO holding TDO */ int TDO_PIO; /* PIO holding TDO */
uint32_t TDO_MASK; /* TDO bitmask */ uint32_t TDO_MASK; /* TDO bitmask */
int TRST_PIO; /* PIO holding TRST */ int TRST_PIO; /* PIO holding TRST */
@ -95,21 +94,20 @@ struct device_t
uint32_t SRST_MASK; /* SRST bitmask */ uint32_t SRST_MASK; /* SRST bitmask */
}; };
static struct device_t devices[] = static struct device_t devices[] = {
{
{ "rea_ecr", PIOD, P27, PIOA, NC, PIOD, P23, PIOD, P24, PIOD, P26, PIOC, P5 }, { "rea_ecr", PIOD, P27, PIOA, NC, PIOD, P23, PIOD, P24, PIOD, P26, PIOC, P5 },
{ .name = NULL }, { .name = NULL },
}; };
/* configuration */ /* configuration */
static char* at91rm9200_device; static char *at91rm9200_device;
/* interface variables /* interface variables
*/ */
static struct device_t* device; static struct device_t *device;
static int dev_mem_fd; static int dev_mem_fd;
static void *sys_controller; static void *sys_controller;
static uint32_t* pio_base; static uint32_t *pio_base;
/* low level command set /* low level command set
*/ */
@ -121,8 +119,7 @@ static int at91rm9200_speed(int speed);
static int at91rm9200_init(void); static int at91rm9200_init(void);
static int at91rm9200_quit(void); static int at91rm9200_quit(void);
static struct bitbang_interface at91rm9200_bitbang = static struct bitbang_interface at91rm9200_bitbang = {
{
.read = at91rm9200_read, .read = at91rm9200_read,
.write = at91rm9200_write, .write = at91rm9200_write,
.reset = at91rm9200_reset, .reset = at91rm9200_reset,
@ -178,8 +175,7 @@ COMMAND_HANDLER(at91rm9200_handle_device_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
/* only if the device name wasn't overwritten by cmdline */ /* only if the device name wasn't overwritten by cmdline */
if (at91rm9200_device == 0) if (at91rm9200_device == 0) {
{
at91rm9200_device = malloc(strlen(CMD_ARGV[0]) + sizeof(char)); at91rm9200_device = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
strcpy(at91rm9200_device, CMD_ARGV[0]); strcpy(at91rm9200_device, CMD_ARGV[0]);
} }
@ -197,12 +193,9 @@ static const struct command_registration at91rm9200_command_handlers[] = {
COMMAND_REGISTRATION_DONE COMMAND_REGISTRATION_DONE
}; };
struct jtag_interface at91rm9200_interface = struct jtag_interface at91rm9200_interface = {
{
.name = "at91rm9200", .name = "at91rm9200",
.execute_queue = bitbang_execute_queue, .execute_queue = bitbang_execute_queue,
.speed = at91rm9200_speed, .speed = at91rm9200_speed,
.commands = at91rm9200_command_handlers, .commands = at91rm9200_command_handlers,
.init = at91rm9200_init, .init = at91rm9200_init,
@ -215,24 +208,20 @@ static int at91rm9200_init(void)
cur_device = devices; cur_device = devices;
if (at91rm9200_device == NULL || at91rm9200_device[0] == 0) if (at91rm9200_device == NULL || at91rm9200_device[0] == 0) {
{
at91rm9200_device = "rea_ecr"; at91rm9200_device = "rea_ecr";
LOG_WARNING("No at91rm9200 device specified, using default 'rea_ecr'"); LOG_WARNING("No at91rm9200 device specified, using default 'rea_ecr'");
} }
while (cur_device->name) while (cur_device->name) {
{ if (strcmp(cur_device->name, at91rm9200_device) == 0) {
if (strcmp(cur_device->name, at91rm9200_device) == 0)
{
device = cur_device; device = cur_device;
break; break;
} }
cur_device++; cur_device++;
} }
if (!device) if (!device) {
{
LOG_ERROR("No matching device found for %s", at91rm9200_device); LOG_ERROR("No matching device found for %s", at91rm9200_device);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -252,7 +241,7 @@ static int at91rm9200_init(void)
close(dev_mem_fd); close(dev_mem_fd);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
pio_base = (uint32_t*)sys_controller + 0x100; pio_base = (uint32_t *)sys_controller + 0x100;
/* /*
* Configure TDO as an input, and TDI, TCK, TMS, TRST, SRST * Configure TDO as an input, and TDI, TCK, TMS, TRST, SRST

View File

@ -20,6 +20,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -38,7 +39,6 @@
*/ */
static void bitbang_stableclocks(int num_cycles); static void bitbang_stableclocks(int num_cycles);
struct bitbang_interface *bitbang_interface; struct bitbang_interface *bitbang_interface;
/* DANGER!!!! clock absolutely *MUST* be 0 in idle or reset won't work! /* DANGER!!!! clock absolutely *MUST* be 0 in idle or reset won't work!
@ -61,14 +61,12 @@ struct bitbang_interface *bitbang_interface;
*/ */
#define CLOCK_IDLE() 0 #define CLOCK_IDLE() 0
/* The bitbang driver leaves the TCK 0 when in idle */ /* The bitbang driver leaves the TCK 0 when in idle */
static void bitbang_end_state(tap_state_t state) static void bitbang_end_state(tap_state_t state)
{ {
if (tap_is_state_stable(state)) if (tap_is_state_stable(state))
tap_set_end_state(state); tap_set_end_state(state);
else else {
{
LOG_ERROR("BUG: %i is not a valid end state", state); LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1); exit(-1);
} }
@ -80,8 +78,7 @@ static void bitbang_state_move(int skip)
uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state()); int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
for (i = skip; i < tms_count; i++) for (i = skip; i < tms_count; i++) {
{
tms = (tms_scan >> i) & 1; tms = (tms_scan >> i) & 1;
bitbang_interface->write(0, tms, 0); bitbang_interface->write(0, tms, 0);
bitbang_interface->write(1, tms, 0); bitbang_interface->write(1, tms, 0);
@ -91,7 +88,6 @@ static void bitbang_state_move(int skip)
tap_set_state(tap_get_end_state()); tap_set_state(tap_get_end_state());
} }
/** /**
* Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG * Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG
* (or SWD) state machine. * (or SWD) state machine.
@ -104,8 +100,7 @@ static int bitbang_execute_tms(struct jtag_command *cmd)
DEBUG_JTAG_IO("TMS: %d bits", num_bits); DEBUG_JTAG_IO("TMS: %d bits", num_bits);
int tms = 0; int tms = 0;
for (unsigned i = 0; i < num_bits; i++) for (unsigned i = 0; i < num_bits; i++) {
{
tms = ((bits[i/8] >> (i % 8)) & 1); tms = ((bits[i/8] >> (i % 8)) & 1);
bitbang_interface->write(0, tms, 0); bitbang_interface->write(0, tms, 0);
bitbang_interface->write(1, tms, 0); bitbang_interface->write(1, tms, 0);
@ -115,7 +110,6 @@ static int bitbang_execute_tms(struct jtag_command *cmd)
return ERROR_OK; return ERROR_OK;
} }
static void bitbang_path_move(struct pathmove_command *cmd) static void bitbang_path_move(struct pathmove_command *cmd)
{ {
int num_states = cmd->num_states; int num_states = cmd->num_states;
@ -123,19 +117,15 @@ static void bitbang_path_move(struct pathmove_command *cmd)
int tms = 0; int tms = 0;
state_count = 0; state_count = 0;
while (num_states) while (num_states) {
{
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
{
tms = 0; tms = 0;
}
else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
{
tms = 1; tms = 1;
} else {
else LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
{ tap_state_name(tap_get_state()),
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(cmd->path[state_count])); tap_state_name(cmd->path[state_count]));
exit(-1); exit(-1);
} }
@ -159,15 +149,13 @@ static void bitbang_runtest(int num_cycles)
tap_state_t saved_end_state = tap_get_end_state(); tap_state_t saved_end_state = tap_get_end_state();
/* only do a state_move when we're not already in IDLE */ /* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE) if (tap_get_state() != TAP_IDLE) {
{
bitbang_end_state(TAP_IDLE); bitbang_end_state(TAP_IDLE);
bitbang_state_move(0); bitbang_state_move(0);
} }
/* execute num_cycles */ /* execute num_cycles */
for (i = 0; i < num_cycles; i++) for (i = 0; i < num_cycles; i++) {
{
bitbang_interface->write(0, 0, 0); bitbang_interface->write(0, 0, 0);
bitbang_interface->write(1, 0, 0); bitbang_interface->write(1, 0, 0);
} }
@ -179,29 +167,26 @@ static void bitbang_runtest(int num_cycles)
bitbang_state_move(0); bitbang_state_move(0);
} }
static void bitbang_stableclocks(int num_cycles) static void bitbang_stableclocks(int num_cycles)
{ {
int tms = (tap_get_state() == TAP_RESET ? 1 : 0); int tms = (tap_get_state() == TAP_RESET ? 1 : 0);
int i; int i;
/* send num_cycles clocks onto the cable */ /* send num_cycles clocks onto the cable */
for (i = 0; i < num_cycles; i++) for (i = 0; i < num_cycles; i++) {
{
bitbang_interface->write(1, tms, 0); bitbang_interface->write(1, tms, 0);
bitbang_interface->write(0, tms, 0); bitbang_interface->write(0, tms, 0);
} }
} }
static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size) static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
{ {
tap_state_t saved_end_state = tap_get_end_state(); tap_state_t saved_end_state = tap_get_end_state();
int bit_cnt; int bit_cnt;
if (!((!ir_scan && (tap_get_state() == TAP_DRSHIFT)) || (ir_scan && (tap_get_state() == TAP_IRSHIFT)))) if (!((!ir_scan &&
{ (tap_get_state() == TAP_DRSHIFT)) ||
(ir_scan && (tap_get_state() == TAP_IRSHIFT)))) {
if (ir_scan) if (ir_scan)
bitbang_end_state(TAP_IRSHIFT); bitbang_end_state(TAP_IRSHIFT);
else else
@ -211,8 +196,7 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
bitbang_end_state(saved_end_state); bitbang_end_state(saved_end_state);
} }
for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
{
int val = 0; int val = 0;
int tms = (bit_cnt == scan_size-1) ? 1 : 0; int tms = (bit_cnt == scan_size-1) ? 1 : 0;
int tdi; int tdi;
@ -234,8 +218,7 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
bitbang_interface->write(1, tms, tdi); bitbang_interface->write(1, tms, tdi);
if (type != SCAN_OUT) if (type != SCAN_OUT) {
{
if (val) if (val)
buffer[bytec] |= bcval; buffer[bytec] |= bcval;
else else
@ -243,8 +226,7 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
} }
} }
if (tap_get_state() != tap_get_end_state()) if (tap_get_state() != tap_get_end_state()) {
{
/* we *KNOW* the above loop transitioned out of /* we *KNOW* the above loop transitioned out of
* the shift state, so we skip the first state * the shift state, so we skip the first state
* and move directly to the end state. * and move directly to the end state.
@ -261,8 +243,7 @@ int bitbang_execute_queue(void)
uint8_t *buffer; uint8_t *buffer;
int retval; int retval;
if (!bitbang_interface) if (!bitbang_interface) {
{
LOG_ERROR("BUG: Bitbang interface called, but not yet initialized"); LOG_ERROR("BUG: Bitbang interface called, but not yet initialized");
exit(-1); exit(-1);
} }
@ -275,23 +256,24 @@ int bitbang_execute_queue(void)
if (bitbang_interface->blink) if (bitbang_interface->blink)
bitbang_interface->blink(1); bitbang_interface->blink(1);
while (cmd) while (cmd) {
{ switch (cmd->type) {
switch (cmd->type)
{
case JTAG_RESET: case JTAG_RESET:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); LOG_DEBUG("reset trst: %i srst %i",
cmd->cmd.reset->trst,
cmd->cmd.reset->srst);
#endif #endif
if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) if ((cmd->cmd.reset->trst == 1) ||
{ (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
tap_set_state(TAP_RESET); tap_set_state(TAP_RESET);
}
bitbang_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); bitbang_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
break; break;
case JTAG_RUNTEST: case JTAG_RUNTEST:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); LOG_DEBUG("runtest %i cycles, end in %s",
cmd->cmd.runtest->num_cycles,
tap_state_name(cmd->cmd.runtest->end_state));
#endif #endif
bitbang_end_state(cmd->cmd.runtest->end_state); bitbang_end_state(cmd->cmd.runtest->end_state);
bitbang_runtest(cmd->cmd.runtest->num_cycles); bitbang_runtest(cmd->cmd.runtest->num_cycles);
@ -306,21 +288,25 @@ int bitbang_execute_queue(void)
case JTAG_TLR_RESET: case JTAG_TLR_RESET:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); LOG_DEBUG("statemove end in %s",
tap_state_name(cmd->cmd.statemove->end_state));
#endif #endif
bitbang_end_state(cmd->cmd.statemove->end_state); bitbang_end_state(cmd->cmd.statemove->end_state);
bitbang_state_move(0); bitbang_state_move(0);
break; break;
case JTAG_PATHMOVE: case JTAG_PATHMOVE:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states, LOG_DEBUG("pathmove: %i states, end in %s",
cmd->cmd.pathmove->num_states,
tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1])); tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
#endif #endif
bitbang_path_move(cmd->cmd.pathmove); bitbang_path_move(cmd->cmd.pathmove);
break; break;
case JTAG_SCAN: case JTAG_SCAN:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("%s scan end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", tap_state_name(cmd->cmd.scan->end_state)); LOG_DEBUG("%s scan end in %s",
(cmd->cmd.scan->ir_scan) ? "IR" : "DR",
tap_state_name(cmd->cmd.scan->end_state));
#endif #endif
bitbang_end_state(cmd->cmd.scan->end_state); bitbang_end_state(cmd->cmd.scan->end_state);
scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);

View File

@ -20,6 +20,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef BITBANG_H #ifndef BITBANG_H
#define BITBANG_H #define BITBANG_H

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -25,8 +26,7 @@
#include "bitq.h" #include "bitq.h"
#include <jtag/interface.h> #include <jtag/interface.h>
struct bitq_interface *bitq_interface; /* low level bit queue interface */
struct bitq_interface* bitq_interface; /* low level bit queue interface */
/* state of input queue */ /* state of input queue */
struct bitq_state { struct bitq_state {
@ -44,29 +44,23 @@ static struct bitq_state bitq_in_state;
static void bitq_in_proc(void) static void bitq_in_proc(void)
{ {
/* loop through the queue */ /* loop through the queue */
while (bitq_in_state.cmd) while (bitq_in_state.cmd) {
{
/* only JTAG_SCAN command may return data */ /* only JTAG_SCAN command may return data */
if (bitq_in_state.cmd->type == JTAG_SCAN) if (bitq_in_state.cmd->type == JTAG_SCAN) {
{
/* loop through the fields */ /* loop through the fields */
while (bitq_in_state.field_idx < bitq_in_state.cmd->cmd.scan->num_fields) while (bitq_in_state.field_idx < bitq_in_state.cmd->cmd.scan->num_fields) {
{
struct scan_field *field; struct scan_field *field;
field = &bitq_in_state.cmd->cmd.scan->fields[bitq_in_state.field_idx]; field = &bitq_in_state.cmd->cmd.scan->fields[bitq_in_state.field_idx];
if (field->in_value) if (field->in_value) {
{
/* field scanning */ /* field scanning */
while (bitq_in_state.bit_pos < field->num_bits) while (bitq_in_state.bit_pos < field->num_bits) {
{
/* index of byte being scanned */ /* index of byte being scanned */
int in_idx = bitq_in_state.bit_pos / 8; int in_idx = bitq_in_state.bit_pos / 8;
/* mask of next bit to be scanned */ /* mask of next bit to be scanned */
uint8_t in_mask = 1 << (bitq_in_state.bit_pos % 8); uint8_t in_mask = 1 << (bitq_in_state.bit_pos % 8);
int tdo = bitq_interface->in(); int tdo = bitq_interface->in();
if (tdo < 0) if (tdo < 0) {
{
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("bitq in EOF"); LOG_DEBUG("bitq in EOF");
#endif #endif
@ -89,7 +83,6 @@ static void bitq_in_proc(void)
} }
} }
static void bitq_io(int tms, int tdi, int tdo_req) static void bitq_io(int tms, int tdi, int tdo_req)
{ {
bitq_interface->out(tms, tdi, tdo_req); bitq_interface->out(tms, tdi, tdo_req);
@ -98,25 +91,21 @@ static void bitq_io(int tms, int tdi, int tdo_req)
bitq_in_proc(); bitq_in_proc();
} }
static void bitq_end_state(tap_state_t state) static void bitq_end_state(tap_state_t state)
{ {
if (!tap_is_state_stable(state)) if (!tap_is_state_stable(state)) {
{
LOG_ERROR("BUG: %i is not a valid end state", state); LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1); exit(-1);
} }
tap_set_end_state(state); tap_set_end_state(state);
} }
static void bitq_state_move(tap_state_t new_state) static void bitq_state_move(tap_state_t new_state)
{ {
int i = 0; int i = 0;
uint8_t tms_scan; uint8_t tms_scan;
if (!tap_is_state_stable(tap_get_state()) || !tap_is_state_stable(new_state)) if (!tap_is_state_stable(tap_get_state()) || !tap_is_state_stable(new_state)) {
{
LOG_ERROR("TAP move from or to unstable state"); LOG_ERROR("TAP move from or to unstable state");
exit(-1); exit(-1);
} }
@ -124,8 +113,7 @@ static void bitq_state_move(tap_state_t new_state)
tms_scan = tap_get_tms_path(tap_get_state(), new_state); tms_scan = tap_get_tms_path(tap_get_state(), new_state);
int tms_count = tap_get_tms_path_len(tap_get_state(), new_state); int tms_count = tap_get_tms_path_len(tap_get_state(), new_state);
for (i = 0; i < tms_count; i++) for (i = 0; i < tms_count; i++) {
{
bitq_io(tms_scan & 1, 0, 0); bitq_io(tms_scan & 1, 0, 0);
tms_scan >>= 1; tms_scan >>= 1;
} }
@ -133,19 +121,16 @@ static void bitq_state_move(tap_state_t new_state)
tap_set_state(new_state); tap_set_state(new_state);
} }
static void bitq_path_move(struct pathmove_command *cmd) static void bitq_path_move(struct pathmove_command *cmd)
{ {
int i; int i;
for (i = 0; i <= cmd->num_states; i++) for (i = 0; i <= cmd->num_states; i++) {
{
if (tap_state_transition(tap_get_state(), false) == cmd->path[i]) if (tap_state_transition(tap_get_state(), false) == cmd->path[i])
bitq_io(0, 0, 0); bitq_io(0, 0, 0);
else if (tap_state_transition(tap_get_state(), true) == cmd->path[i]) else if (tap_state_transition(tap_get_state(), true) == cmd->path[i])
bitq_io(1, 0, 0); bitq_io(1, 0, 0);
else else {
{
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name( LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(
tap_get_state()), tap_state_name(cmd->path[i])); tap_get_state()), tap_state_name(cmd->path[i]));
exit(-1); exit(-1);
@ -157,7 +142,6 @@ static void bitq_path_move(struct pathmove_command *cmd)
tap_set_end_state(tap_get_state()); tap_set_end_state(tap_get_state());
} }
static void bitq_runtest(int num_cycles) static void bitq_runtest(int num_cycles)
{ {
int i; int i;
@ -175,13 +159,12 @@ static void bitq_runtest(int num_cycles)
bitq_state_move(tap_get_end_state()); bitq_state_move(tap_get_end_state());
} }
static void bitq_scan_field(struct scan_field *field, int do_pause) static void bitq_scan_field(struct scan_field *field, int do_pause)
{ {
int bit_cnt; int bit_cnt;
int tdo_req; int tdo_req;
const uint8_t* out_ptr; const uint8_t *out_ptr;
uint8_t out_mask; uint8_t out_mask;
if (field->in_value) if (field->in_value)
@ -189,36 +172,29 @@ static void bitq_scan_field(struct scan_field *field, int do_pause)
else else
tdo_req = 0; tdo_req = 0;
if (field->out_value == NULL) if (field->out_value == NULL) {
{
/* just send zeros and request data from TDO */ /* just send zeros and request data from TDO */
for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--) for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--)
bitq_io(0, 0, tdo_req); bitq_io(0, 0, tdo_req);
bitq_io(do_pause, 0, tdo_req); bitq_io(do_pause, 0, tdo_req);
} } else {
else
{
/* send data, and optionally request TDO */ /* send data, and optionally request TDO */
out_mask = 0x01; out_mask = 0x01;
out_ptr = field->out_value; out_ptr = field->out_value;
for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--) for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--) {
{
bitq_io(0, ((*out_ptr) & out_mask) != 0, tdo_req); bitq_io(0, ((*out_ptr) & out_mask) != 0, tdo_req);
if (out_mask == 0x80) if (out_mask == 0x80) {
{
out_mask = 0x01; out_mask = 0x01;
out_ptr++; out_ptr++;
} } else
else
out_mask <<= 1; out_mask <<= 1;
} }
bitq_io(do_pause, ((*out_ptr) & out_mask) != 0, tdo_req); bitq_io(do_pause, ((*out_ptr) & out_mask) != 0, tdo_req);
} }
if (do_pause) if (do_pause) {
{
bitq_io(0, 0, 0); bitq_io(0, 0, 0);
if (tap_get_state() == TAP_IRSHIFT) if (tap_get_state() == TAP_IRSHIFT)
tap_set_state(TAP_IRPAUSE); tap_set_state(TAP_IRPAUSE);
@ -227,7 +203,6 @@ static void bitq_scan_field(struct scan_field *field, int do_pause)
} }
} }
static void bitq_scan(struct scan_command *cmd) static void bitq_scan(struct scan_command *cmd)
{ {
int i; int i;
@ -243,28 +218,25 @@ static void bitq_scan(struct scan_command *cmd)
bitq_scan_field(&cmd->fields[i], 1); bitq_scan_field(&cmd->fields[i], 1);
} }
int bitq_execute_queue(void) int bitq_execute_queue(void)
{ {
struct jtag_command* cmd = jtag_command_queue; /* currently processed command */ struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
bitq_in_state.cmd = jtag_command_queue; bitq_in_state.cmd = jtag_command_queue;
bitq_in_state.field_idx = 0; bitq_in_state.field_idx = 0;
bitq_in_state.bit_pos = 0; bitq_in_state.bit_pos = 0;
bitq_in_state.status = ERROR_OK; bitq_in_state.status = ERROR_OK;
while (cmd) while (cmd) {
{ switch (cmd->type) {
switch (cmd->type)
{
case JTAG_RESET: case JTAG_RESET:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
#endif #endif
if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) if ((cmd->cmd.reset->trst == 1) ||
{ (cmd->cmd.reset->srst &&
(jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
tap_set_state(TAP_RESET); tap_set_state(TAP_RESET);
}
bitq_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); bitq_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
if (bitq_interface->in_rdy()) if (bitq_interface->in_rdy())
bitq_in_proc(); bitq_in_proc();
@ -328,13 +300,11 @@ int bitq_execute_queue(void)
bitq_interface->flush(); bitq_interface->flush();
bitq_in_proc(); bitq_in_proc();
if (bitq_in_state.cmd) if (bitq_in_state.cmd) {
{
LOG_ERROR("missing data from bitq interface"); LOG_ERROR("missing data from bitq interface");
return ERROR_JTAG_QUEUE_FAILED; return ERROR_JTAG_QUEUE_FAILED;
} }
if (bitq_interface->in() >= 0) if (bitq_interface->in() >= 0) {
{
LOG_ERROR("extra data from bitq interface"); LOG_ERROR("extra data from bitq interface");
return ERROR_JTAG_QUEUE_FAILED; return ERROR_JTAG_QUEUE_FAILED;
} }
@ -342,7 +312,6 @@ int bitq_execute_queue(void)
return bitq_in_state.status; return bitq_in_state.status;
} }
void bitq_cleanup(void) void bitq_cleanup(void)
{ {
} }

View File

@ -17,13 +17,14 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef BITQ_H #ifndef BITQ_H
#define BITQ_H #define BITQ_H
#include <jtag/commands.h> #include <jtag/commands.h>
struct bitq_interface { struct bitq_interface {
// function to enqueueing low level IO requests /* function to enqueueing low level IO requests */
int (*out)(int tms, int tdi, int tdo_req); int (*out)(int tms, int tdi, int tdo_req);
int (*flush)(void); int (*flush)(void);

View File

@ -44,7 +44,6 @@ static void buspirate_runtest(int num_cycles);
static void buspirate_scan(bool ir_scan, enum scan_type type, static void buspirate_scan(bool ir_scan, enum scan_type type,
uint8_t *buffer, int scan_size, struct scan_command *command); uint8_t *buffer, int scan_size, struct scan_command *command);
#define CMD_UNKNOWN 0x00 #define CMD_UNKNOWN 0x00
#define CMD_PORT_MODE 0x01 #define CMD_PORT_MODE 0x01
#define CMD_FEATURE 0x02 #define CMD_FEATURE 0x02
@ -84,7 +83,6 @@ enum {
SERIAL_FAST = 1 SERIAL_FAST = 1
}; };
static int buspirate_fd = -1; static int buspirate_fd = -1;
static int buspirate_pinmode = MODE_JTAG_OD; static int buspirate_pinmode = MODE_JTAG_OD;
static int buspirate_baudrate = SERIAL_NORMAL; static int buspirate_baudrate = SERIAL_NORMAL;
@ -92,7 +90,6 @@ static int buspirate_vreg;
static int buspirate_pullup; static int buspirate_pullup;
static char *buspirate_port; static char *buspirate_port;
/* TAP interface */ /* TAP interface */
static void buspirate_tap_init(void); static void buspirate_tap_init(void);
static int buspirate_tap_execute(void); static int buspirate_tap_execute(void);
@ -279,9 +276,8 @@ COMMAND_HANDLER(buspirate_handle_adc_command)
COMMAND_HANDLER(buspirate_handle_vreg_command) COMMAND_HANDLER(buspirate_handle_vreg_command)
{ {
if (CMD_ARGC < 1) { if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
if (atoi(CMD_ARGV[0]) == 1) if (atoi(CMD_ARGV[0]) == 1)
buspirate_vreg = 1; buspirate_vreg = 1;
@ -296,9 +292,8 @@ COMMAND_HANDLER(buspirate_handle_vreg_command)
COMMAND_HANDLER(buspirate_handle_pullup_command) COMMAND_HANDLER(buspirate_handle_pullup_command)
{ {
if (CMD_ARGC < 1) { if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
if (atoi(CMD_ARGV[0]) == 1) if (atoi(CMD_ARGV[0]) == 1)
buspirate_pullup = 1; buspirate_pullup = 1;
@ -313,9 +308,8 @@ COMMAND_HANDLER(buspirate_handle_pullup_command)
COMMAND_HANDLER(buspirate_handle_led_command) COMMAND_HANDLER(buspirate_handle_led_command)
{ {
if (CMD_ARGC < 1) { if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
if (atoi(CMD_ARGV[0]) == 1) { if (atoi(CMD_ARGV[0]) == 1) {
/* enable led */ /* enable led */
@ -335,9 +329,8 @@ COMMAND_HANDLER(buspirate_handle_led_command)
COMMAND_HANDLER(buspirate_handle_mode_command) COMMAND_HANDLER(buspirate_handle_mode_command)
{ {
if (CMD_ARGC < 1) { if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
if (CMD_ARGV[0][0] == 'n') if (CMD_ARGV[0][0] == 'n')
buspirate_pinmode = MODE_JTAG; buspirate_pinmode = MODE_JTAG;
@ -352,9 +345,8 @@ COMMAND_HANDLER(buspirate_handle_mode_command)
COMMAND_HANDLER(buspirate_handle_speed_command) COMMAND_HANDLER(buspirate_handle_speed_command)
{ {
if (CMD_ARGC < 1) { if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
if (CMD_ARGV[0][0] == 'n') if (CMD_ARGV[0][0] == 'n')
buspirate_baudrate = SERIAL_NORMAL; buspirate_baudrate = SERIAL_NORMAL;
@ -369,9 +361,8 @@ COMMAND_HANDLER(buspirate_handle_speed_command)
COMMAND_HANDLER(buspirate_handle_port_command) COMMAND_HANDLER(buspirate_handle_port_command)
{ {
if (CMD_ARGC < 1) { if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
if (buspirate_port == NULL) if (buspirate_port == NULL)
buspirate_port = strdup(CMD_ARGV[0]); buspirate_port = strdup(CMD_ARGV[0]);
@ -987,8 +978,6 @@ static void buspirate_print_buffer(char *buf, int size)
} }
} }
if (line[0] != 0) { if (line[0] != 0)
LOG_DEBUG("%s", line); LOG_DEBUG("%s", line);
}
} }

View File

@ -27,6 +27,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -37,8 +38,7 @@
#include <jtag/minidriver.h> #include <jtag/minidriver.h>
#include <helper/command.h> #include <helper/command.h>
struct jtag_callback_entry struct jtag_callback_entry {
{
struct jtag_callback_entry *next; struct jtag_callback_entry *next;
jtag_callback_t callback; jtag_callback_t callback;
@ -48,8 +48,8 @@ struct jtag_callback_entry
jtag_callback_data_t data3; jtag_callback_data_t data3;
}; };
static struct jtag_callback_entry *jtag_callback_queue_head = NULL; static struct jtag_callback_entry *jtag_callback_queue_head;
static struct jtag_callback_entry *jtag_callback_queue_tail = NULL; static struct jtag_callback_entry *jtag_callback_queue_tail;
static void jtag_callback_queue_reset(void) static void jtag_callback_queue_reset(void)
{ {
@ -62,25 +62,25 @@ static void jtag_callback_queue_reset(void)
* *
* This allocates a new copy of out_value using cmd_queue_alloc. * This allocates a new copy of out_value using cmd_queue_alloc.
*/ */
static void cmd_queue_scan_field_clone(struct scan_field * dst, const struct scan_field * src) static void cmd_queue_scan_field_clone(struct scan_field *dst, const struct scan_field *src)
{ {
dst->num_bits = src->num_bits; dst->num_bits = src->num_bits;
dst->out_value = buf_cpy(src->out_value, cmd_queue_alloc(DIV_ROUND_UP(src->num_bits, 8)), src->num_bits); dst->out_value = buf_cpy(src->out_value, cmd_queue_alloc(DIV_ROUND_UP(src->num_bits, 8)), src->num_bits);
dst->in_value = src->in_value; dst->in_value = src->in_value;
} }
/** /**
* see jtag_add_ir_scan() * see jtag_add_ir_scan()
* *
*/ */
int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field *in_fields, tap_state_t state) int interface_jtag_add_ir_scan(struct jtag_tap *active,
const struct scan_field *in_fields, tap_state_t state)
{ {
size_t num_taps = jtag_tap_count_enabled(); size_t num_taps = jtag_tap_count_enabled();
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
struct scan_command * scan = cmd_queue_alloc(sizeof(struct scan_command)); struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
struct scan_field * out_fields = cmd_queue_alloc(num_taps * sizeof(struct scan_field)); struct scan_field *out_fields = cmd_queue_alloc(num_taps * sizeof(struct scan_field));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -92,23 +92,19 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
scan->fields = out_fields; scan->fields = out_fields;
scan->end_state = state; scan->end_state = state;
struct scan_field *field = out_fields; /* keep track where we insert data */
struct scan_field * field = out_fields; /* keep track where we insert data */
/* loop over all enabled TAPs */ /* loop over all enabled TAPs */
for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
{
/* search the input field list for fields for the current TAP */ /* search the input field list for fields for the current TAP */
if (tap == active) if (tap == active) {
{
/* if TAP is listed in input fields, copy the value */ /* if TAP is listed in input fields, copy the value */
tap->bypass = 0; tap->bypass = 0;
cmd_queue_scan_field_clone(field, in_fields); cmd_queue_scan_field_clone(field, in_fields);
} else } else {
{
/* if a TAP isn't listed in input fields, set it to BYPASS */ /* if a TAP isn't listed in input fields, set it to BYPASS */
tap->bypass = 1; tap->bypass = 1;
@ -123,8 +119,8 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
field++; field++;
} }
/* paranoia: jtag_tap_count_enabled() and jtag_tap_next_enabled() not in sync */
assert(field == out_fields + num_taps); /* paranoia: jtag_tap_count_enabled() and jtag_tap_next_enabled() not in sync */ assert(field == out_fields + num_taps);
return ERROR_OK; return ERROR_OK;
} }
@ -133,21 +129,21 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
* see jtag_add_dr_scan() * see jtag_add_dr_scan()
* *
*/ */
int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state) int interface_jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields,
const struct scan_field *in_fields, tap_state_t state)
{ {
/* count devices in bypass */ /* count devices in bypass */
size_t bypass_devices = 0; size_t bypass_devices = 0;
for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
{
if (tap->bypass) if (tap->bypass)
bypass_devices++; bypass_devices++;
} }
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
struct scan_command * scan = cmd_queue_alloc(sizeof(struct scan_command)); struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
struct scan_field * out_fields = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field)); struct scan_field *out_fields = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -159,25 +155,21 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
scan->fields = out_fields; scan->fields = out_fields;
scan->end_state = state; scan->end_state = state;
struct scan_field *field = out_fields; /* keep track where we insert data */
struct scan_field * field = out_fields; /* keep track where we insert data */
/* loop over all enabled TAPs */ /* loop over all enabled TAPs */
for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
{
/* if TAP is not bypassed insert matching input fields */ /* if TAP is not bypassed insert matching input fields */
if (!tap->bypass) if (!tap->bypass) {
{
assert(active == tap); assert(active == tap);
#ifndef NDEBUG #ifndef NDEBUG
/* remember initial position for assert() */ /* remember initial position for assert() */
struct scan_field *start_field = field; struct scan_field *start_field = field;
#endif /* NDEBUG */ #endif /* NDEBUG */
for (int j = 0; j < in_num_fields; j++) for (int j = 0; j < in_num_fields; j++) {
{
cmd_queue_scan_field_clone(field, in_fields + j); cmd_queue_scan_field_clone(field, in_fields + j);
field++; field++;
@ -187,8 +179,7 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
} }
/* if a TAP is bypassed, generated a dummy bit*/ /* if a TAP is bypassed, generated a dummy bit*/
else else {
{
field->num_bits = 1; field->num_bits = 1;
field->out_value = NULL; field->out_value = NULL;
field->in_value = NULL; field->in_value = NULL;
@ -202,8 +193,6 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
return ERROR_OK; return ERROR_OK;
} }
/** /**
* Generate a DR SCAN using the array of output values passed to the function * Generate a DR SCAN using the array of output values passed to the function
* *
@ -228,16 +217,15 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
size_t bypass_devices = 0; size_t bypass_devices = 0;
for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
{
if (tap->bypass) if (tap->bypass)
bypass_devices++; bypass_devices++;
} }
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
struct scan_command * scan = cmd_queue_alloc(sizeof(struct scan_command)); struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
struct scan_field * out_fields = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field)); struct scan_field *out_fields = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -252,22 +240,19 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
bool target_tap_match = false; bool target_tap_match = false;
struct scan_field * field = out_fields; /* keep track where we insert data */ struct scan_field *field = out_fields; /* keep track where we insert data */
/* loop over all enabled TAPs */ /* loop over all enabled TAPs */
for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
{
/* if TAP is not bypassed insert matching input fields */ /* if TAP is not bypassed insert matching input fields */
if (!tap->bypass) if (!tap->bypass) {
{
assert(tap == target_tap); /* target_tap must match the one not bypassed TAP */ assert(tap == target_tap); /* target_tap must match the one not bypassed TAP */
target_tap_match = true; target_tap_match = true;
for (int j = 0; j < in_num_fields; j++) for (int j = 0; j < in_num_fields; j++) {
{
uint8_t out_value[4]; uint8_t out_value[4];
size_t scan_size = num_bits[j]; size_t scan_size = num_bits[j];
buf_set_u32(out_value, 0, scan_size, value[j]); buf_set_u32(out_value, 0, scan_size, value[j]);
@ -281,8 +266,7 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
} }
/* if a TAP is bypassed, generated a dummy bit*/ /* if a TAP is bypassed, generated a dummy bit*/
else else {
{
field->num_bits = 1; field->num_bits = 1;
field->out_value = NULL; field->out_value = NULL;
@ -298,9 +282,9 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
static int jtag_add_plain_scan(int num_bits, const uint8_t *out_bits, static int jtag_add_plain_scan(int num_bits, const uint8_t *out_bits,
uint8_t *in_bits, tap_state_t state, bool ir_scan) uint8_t *in_bits, tap_state_t state, bool ir_scan)
{ {
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
struct scan_command * scan = cmd_queue_alloc(sizeof(struct scan_command)); struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
struct scan_field * out_fields = cmd_queue_alloc(sizeof(struct scan_field)); struct scan_field *out_fields = cmd_queue_alloc(sizeof(struct scan_field));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -334,7 +318,7 @@ int interface_jtag_add_tlr(void)
tap_state_t state = TAP_RESET; tap_state_t state = TAP_RESET;
/* allocate memory for a new list member */ /* allocate memory for a new list member */
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -374,7 +358,7 @@ int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state
int interface_jtag_add_pathmove(int num_states, const tap_state_t *path) int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
{ {
/* allocate memory for a new list member */ /* allocate memory for a new list member */
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -393,7 +377,7 @@ int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
int interface_jtag_add_runtest(int num_cycles, tap_state_t state) int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
{ {
/* allocate memory for a new list member */ /* allocate memory for a new list member */
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -409,7 +393,7 @@ int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
int interface_jtag_add_clocks(int num_cycles) int interface_jtag_add_clocks(int num_cycles)
{ {
/* allocate memory for a new list member */ /* allocate memory for a new list member */
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -424,7 +408,7 @@ int interface_jtag_add_clocks(int num_cycles)
int interface_jtag_add_reset(int req_trst, int req_srst) int interface_jtag_add_reset(int req_trst, int req_srst)
{ {
/* allocate memory for a new list member */ /* allocate memory for a new list member */
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -440,7 +424,7 @@ int interface_jtag_add_reset(int req_trst, int req_srst)
int interface_jtag_add_sleep(uint32_t us) int interface_jtag_add_sleep(uint32_t us)
{ {
/* allocate memory for a new list member */ /* allocate memory for a new list member */
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command)); struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
jtag_queue_command(cmd); jtag_queue_command(cmd);
@ -453,7 +437,9 @@ int interface_jtag_add_sleep(uint32_t us)
} }
/* add callback to end of queue */ /* add callback to end of queue */
void interface_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3) void interface_jtag_add_callback4(jtag_callback_t callback,
jtag_callback_data_t data0, jtag_callback_data_t data1,
jtag_callback_data_t data2, jtag_callback_data_t data3)
{ {
struct jtag_callback_entry *entry = cmd_queue_alloc(sizeof(struct jtag_callback_entry)); struct jtag_callback_entry *entry = cmd_queue_alloc(sizeof(struct jtag_callback_entry));
@ -464,12 +450,10 @@ void interface_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t
entry->data2 = data2; entry->data2 = data2;
entry->data3 = data3; entry->data3 = data3;
if (jtag_callback_queue_head == NULL) if (jtag_callback_queue_head == NULL) {
{
jtag_callback_queue_head = entry; jtag_callback_queue_head = entry;
jtag_callback_queue_tail = entry; jtag_callback_queue_tail = entry;
} else } else {
{
jtag_callback_queue_tail->next = entry; jtag_callback_queue_tail->next = entry;
jtag_callback_queue_tail = entry; jtag_callback_queue_tail = entry;
} }
@ -477,17 +461,15 @@ void interface_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t
int interface_jtag_execute_queue(void) int interface_jtag_execute_queue(void)
{ {
static int reentry = 0; static int reentry;
assert(reentry==0); assert(reentry == 0);
reentry++; reentry++;
int retval = default_interface_jtag_execute_queue(); int retval = default_interface_jtag_execute_queue();
if (retval == ERROR_OK) if (retval == ERROR_OK) {
{
struct jtag_callback_entry *entry; struct jtag_callback_entry *entry;
for (entry = jtag_callback_queue_head; entry != NULL; entry = entry->next) for (entry = jtag_callback_queue_head; entry != NULL; entry = entry->next) {
{
retval = entry->callback(entry->data0, entry->data1, entry->data2, entry->data3); retval = entry->callback(entry->data0, entry->data1, entry->data2, entry->data3);
if (retval != ERROR_OK) if (retval != ERROR_OK)
break; break;
@ -502,7 +484,8 @@ int interface_jtag_execute_queue(void)
return retval; return retval;
} }
static int jtag_convert_to_callback4(jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3) static int jtag_convert_to_callback4(jtag_callback_data_t data0,
jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
{ {
((jtag_callback1_t)data1)(data0); ((jtag_callback1_t)data1)(data0);
return ERROR_OK; return ERROR_OK;
@ -513,10 +496,9 @@ void interface_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t
jtag_add_callback4(jtag_convert_to_callback4, data0, (jtag_callback_data_t)callback, 0, 0); jtag_add_callback4(jtag_convert_to_callback4, data0, (jtag_callback_data_t)callback, 0, 0);
} }
/* A minidriver can use use an inline versions of this API level fn */ /* A minidriver can use use an inline versions of this API level fn */
void jtag_add_dr_out(struct jtag_tap* tap, void jtag_add_dr_out(struct jtag_tap *tap,
int num_fields, const int* num_bits, const uint32_t* value, int num_fields, const int *num_bits, const uint32_t *value,
tap_state_t end_state) tap_state_t end_state)
{ {
assert(end_state != TAP_RESET); assert(end_state != TAP_RESET);

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -25,7 +26,6 @@
#include "bitbang.h" #include "bitbang.h"
#include "hello.h" #include "hello.h"
/* my private tap controller state, which tracks state for calling code */ /* my private tap controller state, which tracks state for calling code */
static tap_state_t dummy_state = TAP_RESET; static tap_state_t dummy_state = TAP_RESET;
@ -35,7 +35,6 @@ static int clock_count; /* count clocks in any stable state, only stable
static uint32_t dummy_data; static uint32_t dummy_data;
static int dummy_read(void) static int dummy_read(void)
{ {
int data = 1 & dummy_data; int data = 1 & dummy_data;
@ -43,21 +42,16 @@ static int dummy_read(void)
return data; return data;
} }
static void dummy_write(int tck, int tms, int tdi) static void dummy_write(int tck, int tms, int tdi)
{ {
/* TAP standard: "state transitions occur on rising edge of clock" */ /* TAP standard: "state transitions occur on rising edge of clock" */
if (tck != dummy_clock) if (tck != dummy_clock) {
{ if (tck) {
if (tck)
{
tap_state_t old_state = dummy_state; tap_state_t old_state = dummy_state;
dummy_state = tap_state_transition(old_state, tms); dummy_state = tap_state_transition(old_state, tms);
if (old_state != dummy_state) if (old_state != dummy_state) {
{ if (clock_count) {
if (clock_count)
{
LOG_DEBUG("dummy_tap: %d stable clocks", clock_count); LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
clock_count = 0; clock_count = 0;
} }
@ -68,9 +62,7 @@ static void dummy_write(int tck, int tms, int tdi)
if (dummy_state == TAP_DRCAPTURE) if (dummy_state == TAP_DRCAPTURE)
dummy_data = 0x01255043; dummy_data = 0x01255043;
#endif #endif
} } else {
else
{
/* this is a stable state clock edge, no change of state here, /* this is a stable state clock edge, no change of state here,
* simply increment clock_count for subsequent logging * simply increment clock_count for subsequent logging
*/ */
@ -102,30 +94,21 @@ static struct bitbang_interface dummy_bitbang = {
.blink = &dummy_led, .blink = &dummy_led,
}; };
static int dummy_khz(int khz, int *jtag_speed) static int dummy_khz(int khz, int *jtag_speed)
{ {
if (khz == 0) if (khz == 0)
{
*jtag_speed = 0; *jtag_speed = 0;
}
else else
{
*jtag_speed = 64000/khz; *jtag_speed = 64000/khz;
}
return ERROR_OK; return ERROR_OK;
} }
static int dummy_speed_div(int speed, int *khz) static int dummy_speed_div(int speed, int *khz)
{ {
if (speed == 0) if (speed == 0)
{
*khz = 0; *khz = 0;
}
else else
{
*khz = 64000/speed; *khz = 64000/speed;
}
return ERROR_OK; return ERROR_OK;
} }

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -34,7 +35,7 @@
#include <sys/mman.h> #include <sys/mman.h>
static uint8_t output_value = 0x0; static uint8_t output_value;
static int dev_mem_fd; static int dev_mem_fd;
static void *gpio_controller; static void *gpio_controller;
static volatile uint8_t *gpio_data_register; static volatile uint8_t *gpio_data_register;
@ -52,8 +53,7 @@ static int ep93xx_quit(void);
struct timespec ep93xx_zzzz; struct timespec ep93xx_zzzz;
struct jtag_interface ep93xx_interface = struct jtag_interface ep93xx_interface = {
{
.name = "ep93xx", .name = "ep93xx",
.supported = DEBUG_CAP_TMS_SEQ, .supported = DEBUG_CAP_TMS_SEQ,
@ -64,8 +64,7 @@ struct jtag_interface ep93xx_interface =
.quit = ep93xx_quit, .quit = ep93xx_quit,
}; };
static struct bitbang_interface ep93xx_bitbang = static struct bitbang_interface ep93xx_bitbang = {
{
.read = ep93xx_read, .read = ep93xx_read,
.write = ep93xx_write, .write = ep93xx_write,
.reset = ep93xx_reset, .reset = ep93xx_reset,

File diff suppressed because it is too large Load Diff

View File

@ -27,8 +27,7 @@
static const char *ftd2xx_status_string(FT_STATUS status) static const char *ftd2xx_status_string(FT_STATUS status)
{ {
switch (status) switch (status) {
{
case FT_OK: return "OK"; case FT_OK: return "OK";
case FT_INVALID_HANDLE: return "invalid handle"; case FT_INVALID_HANDLE: return "invalid handle";
case FT_DEVICE_NOT_FOUND: return "device not found"; case FT_DEVICE_NOT_FOUND: return "device not found";

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -24,7 +25,6 @@
#include <jtag/interface.h> #include <jtag/interface.h>
#include <jtag/commands.h> #include <jtag/commands.h>
#if 1 #if 1
#define _DEBUG_GW16012_IO_ #define _DEBUG_GW16012_IO_
#endif #endif
@ -35,14 +35,13 @@
#include <machine/sysarch.h> #include <machine/sysarch.h>
#include <machine/cpufunc.h> #include <machine/cpufunc.h>
#define ioperm(startport,length,enable)\ #define ioperm(startport, length, enable) \
i386_set_ioperm((startport), (length), (enable)) 386_set_ioperm((startport), (length), (enable))
#else #else
#endif /* __FreeBSD__, __FreeBSD_kernel__ */ #endif /* __FreeBSD__, __FreeBSD_kernel__ */
#if PARPORT_USE_PPDEV == 1 #if PARPORT_USE_PPDEV == 1
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <dev/ppbus/ppi.h> #include <dev/ppbus/ppi.h>
@ -65,14 +64,13 @@
#include <windows.h> #include <windows.h>
#endif #endif
/* configuration */ /* configuration */
uint16_t gw16012_port; uint16_t gw16012_port;
/* interface variables /* interface variables
*/ */
static uint8_t gw16012_msb = 0x0; static uint8_t gw16012_msb;
static uint8_t gw16012_control_value = 0x0; static uint8_t gw16012_control_value;
#if PARPORT_USE_PPDEV == 1 #if PARPORT_USE_PPDEV == 1
static int device_handle; static int device_handle;
@ -100,8 +98,7 @@ static void gw16012_data(uint8_t value)
static void gw16012_control(uint8_t value) static void gw16012_control(uint8_t value)
{ {
if (value != gw16012_control_value) if (value != gw16012_control_value) {
{
gw16012_control_value = value; gw16012_control_value = value;
#ifdef _DEBUG_GW16012_IO_ #ifdef _DEBUG_GW16012_IO_
@ -159,8 +156,7 @@ static void gw16012_end_state(tap_state_t state)
{ {
if (tap_is_state_stable(state)) if (tap_is_state_stable(state))
tap_set_end_state(state); tap_set_end_state(state);
else else {
{
LOG_ERROR("BUG: %i is not a valid end state", state); LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1); exit(-1);
} }
@ -174,8 +170,7 @@ static void gw16012_state_move(void)
gw16012_control(0x0); /* single-bit mode */ gw16012_control(0x0); /* single-bit mode */
for (i = 0; i < tms_count; i++) for (i = 0; i < tms_count; i++) {
{
tms = (tms_scan >> i) & 1; tms = (tms_scan >> i) & 1;
gw16012_data(tms << 1); /* output next TMS bit */ gw16012_data(tms << 1); /* output next TMS bit */
} }
@ -189,20 +184,15 @@ static void gw16012_path_move(struct pathmove_command *cmd)
int state_count; int state_count;
state_count = 0; state_count = 0;
while (num_states) while (num_states) {
{
gw16012_control(0x0); /* single-bit mode */ gw16012_control(0x0); /* single-bit mode */
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
{
gw16012_data(0x0); /* TCK cycle with TMS low */ gw16012_data(0x0); /* TCK cycle with TMS low */
}
else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
{
gw16012_data(0x2); /* TCK cycle with TMS high */ gw16012_data(0x2); /* TCK cycle with TMS high */
} else {
else LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
{ tap_state_name(tap_get_state()), tap_state_name(cmd->path[state_count]));
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(cmd->path[state_count]));
exit(-1); exit(-1);
} }
@ -220,14 +210,12 @@ static void gw16012_runtest(int num_cycles)
int i; int i;
/* only do a state_move when we're not already in IDLE */ /* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE) if (tap_get_state() != TAP_IDLE) {
{
gw16012_end_state(TAP_IDLE); gw16012_end_state(TAP_IDLE);
gw16012_state_move(); gw16012_state_move();
} }
for (i = 0; i < num_cycles; i++) for (i = 0; i < num_cycles; i++) {
{
gw16012_control(0x0); /* single-bit mode */ gw16012_control(0x0); /* single-bit mode */
gw16012_data(0x0); /* TMS cycle with TMS low */ gw16012_data(0x0); /* TMS cycle with TMS low */
} }
@ -245,8 +233,8 @@ static void gw16012_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
uint8_t scan_out, scan_in; uint8_t scan_out, scan_in;
/* only if we're not already in the correct Shift state */ /* only if we're not already in the correct Shift state */
if (!((!ir_scan && (tap_get_state() == TAP_DRSHIFT)) || (ir_scan && (tap_get_state() == TAP_IRSHIFT)))) if (!((!ir_scan && (tap_get_state() == TAP_DRSHIFT)) ||
{ (ir_scan && (tap_get_state() == TAP_IRSHIFT)))) {
if (ir_scan) if (ir_scan)
gw16012_end_state(TAP_IRSHIFT); gw16012_end_state(TAP_IRSHIFT);
else else
@ -256,8 +244,7 @@ static void gw16012_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
gw16012_end_state(saved_end_state); gw16012_end_state(saved_end_state);
} }
while (type == SCAN_OUT && ((bits_left - 1) > 7)) while (type == SCAN_OUT && ((bits_left - 1) > 7)) {
{
gw16012_control(0x2); /* seven-bit mode */ gw16012_control(0x2); /* seven-bit mode */
scan_out = buf_get_u32(buffer, bit_count, 7); scan_out = buf_get_u32(buffer, bit_count, 7);
gw16012_data(scan_out); gw16012_data(scan_out);
@ -266,29 +253,22 @@ static void gw16012_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
} }
gw16012_control(0x0); /* single-bit mode */ gw16012_control(0x0); /* single-bit mode */
while (bits_left-- > 0) while (bits_left-- > 0) {
{
uint8_t tms = 0; uint8_t tms = 0;
scan_out = buf_get_u32(buffer, bit_count, 1); scan_out = buf_get_u32(buffer, bit_count, 1);
if (bits_left == 0) /* last bit */ if (bits_left == 0) /* last bit */ {
{
if ((ir_scan && (tap_get_end_state() == TAP_IRSHIFT)) if ((ir_scan && (tap_get_end_state() == TAP_IRSHIFT))
|| (!ir_scan && (tap_get_end_state() == TAP_DRSHIFT))) || (!ir_scan && (tap_get_end_state() == TAP_DRSHIFT)))
{
tms = 0; tms = 0;
}
else else
{
tms = 2; tms = 2;
} }
}
gw16012_data(scan_out | tms); gw16012_data(scan_out | tms);
if (type != SCAN_OUT) if (type != SCAN_OUT) {
{
gw16012_input(&scan_in); gw16012_input(&scan_in);
buf_set_u32(buffer, bit_count, 1, ((scan_in & 0x08) >> 3)); buf_set_u32(buffer, bit_count, 1, ((scan_in & 0x08) >> 3));
} }
@ -297,8 +277,7 @@ static void gw16012_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
} }
if (!((ir_scan && (tap_get_end_state() == TAP_IRSHIFT)) || if (!((ir_scan && (tap_get_end_state() == TAP_IRSHIFT)) ||
(!ir_scan && (tap_get_end_state() == TAP_DRSHIFT)))) (!ir_scan && (tap_get_end_state() == TAP_DRSHIFT)))) {
{
gw16012_data(0x0); gw16012_data(0x0);
if (ir_scan) if (ir_scan)
tap_set_state(TAP_IRPAUSE); tap_set_state(TAP_IRPAUSE);
@ -323,23 +302,20 @@ static int gw16012_execute_queue(void)
*/ */
retval = ERROR_OK; retval = ERROR_OK;
while (cmd) while (cmd) {
{ switch (cmd->type) {
switch (cmd->type)
{
case JTAG_RESET: case JTAG_RESET:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
#endif #endif
if (cmd->cmd.reset->trst == 1) if (cmd->cmd.reset->trst == 1)
{
tap_set_state(TAP_RESET); tap_set_state(TAP_RESET);
}
gw16012_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); gw16012_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
break; break;
case JTAG_RUNTEST: case JTAG_RUNTEST:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles,
cmd->cmd.runtest->end_state);
#endif #endif
gw16012_end_state(cmd->cmd.runtest->end_state); gw16012_end_state(cmd->cmd.runtest->end_state);
gw16012_runtest(cmd->cmd.runtest->num_cycles); gw16012_runtest(cmd->cmd.runtest->num_cycles);
@ -353,7 +329,8 @@ static int gw16012_execute_queue(void)
break; break;
case JTAG_PATHMOVE: case JTAG_PATHMOVE:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states,
cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
#endif #endif
gw16012_path_move(cmd->cmd.pathmove); gw16012_path_move(cmd->cmd.pathmove);
break; break;
@ -401,7 +378,8 @@ static int gw16012_get_giveio_access(void)
if (version.dwPlatformId != VER_PLATFORM_WIN32_NT) if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
return 0; return 0;
h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
errno = ENODEV; errno = ENODEV;
return -1; return -1;
@ -423,24 +401,21 @@ static int gw16012_init_ioctls(void)
{ {
int temp = 0; int temp = 0;
temp = ioctl(device_handle, PPCLAIM); temp = ioctl(device_handle, PPCLAIM);
if (temp < 0) if (temp < 0) {
{
LOG_ERROR("cannot claim device"); LOG_ERROR("cannot claim device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
temp = PARPORT_MODE_COMPAT; temp = PARPORT_MODE_COMPAT;
temp = ioctl(device_handle, PPSETMODE, &temp); temp = ioctl(device_handle, PPSETMODE, &temp);
if (temp < 0) if (temp < 0) {
{
LOG_ERROR(" cannot set compatible mode to device"); LOG_ERROR(" cannot set compatible mode to device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
temp = IEEE1284_MODE_COMPAT; temp = IEEE1284_MODE_COMPAT;
temp = ioctl(device_handle, PPNEGOT, &temp); temp = ioctl(device_handle, PPNEGOT, &temp);
if (temp < 0) if (temp < 0) {
{
LOG_ERROR("cannot set compatible 1284 mode to device"); LOG_ERROR("cannot set compatible 1284 mode to device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -455,15 +430,14 @@ static int gw16012_init_ioctls(void)
return ERROR_OK; return ERROR_OK;
} }
#endif // defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
static int gw16012_init_device(void) static int gw16012_init_device(void)
{ {
const char *device_name = GW16012_PPDEV_NAME; const char *device_name = GW16012_PPDEV_NAME;
char buffer[256]; char buffer[256];
if (device_handle > 0) if (device_handle > 0) {
{
LOG_ERROR("device is already opened"); LOG_ERROR("device is already opened");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -472,8 +446,7 @@ static int gw16012_init_device(void)
LOG_DEBUG("opening %s...", buffer); LOG_DEBUG("opening %s...", buffer);
device_handle = open(buffer, O_WRONLY); device_handle = open(buffer, O_WRONLY);
if (device_handle < 0) if (device_handle < 0) {
{
LOG_ERROR("cannot open device. check it exists and that user read and write rights are set"); LOG_ERROR("cannot open device. check it exists and that user read and write rights are set");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -486,23 +459,21 @@ static int gw16012_init_device(void)
return ERROR_OK; return ERROR_OK;
} }
#else // PARPORT_USE_PPDEV #else /* PARPORT_USE_PPDEV */
static int gw16012_init_device(void) static int gw16012_init_device(void)
{ {
if (gw16012_port == 0) if (gw16012_port == 0) {
{
gw16012_port = 0x378; gw16012_port = 0x378;
LOG_WARNING("No gw16012 port specified, using default '0x378' (LPT1)"); LOG_WARNING("No gw16012 port specified, using default '0x378' (LPT1)");
} }
LOG_DEBUG("requesting privileges for parallel port 0x%lx...", (long unsigned)(gw16012_port)); LOG_DEBUG("requesting privileges for parallel port 0x%lx...", (long unsigned)(gw16012_port));
#if PARPORT_USE_GIVEIO == 1 #if PARPORT_USE_GIVEIO == 1
if (gw16012_get_giveio_access() != 0) if (gw16012_get_giveio_access() != 0) {
#else /* PARPORT_USE_GIVEIO */ #else /* PARPORT_USE_GIVEIO */
if (ioperm(gw16012_port, 3, 1) != 0) if (ioperm(gw16012_port, 3, 1) != 0) {
#endif /* PARPORT_USE_GIVEIO */ #endif /* PARPORT_USE_GIVEIO */
{
LOG_ERROR("missing privileges for direct i/o"); LOG_ERROR("missing privileges for direct i/o");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -517,7 +488,7 @@ static int gw16012_init_device(void)
return ERROR_OK; return ERROR_OK;
} }
#endif // PARPORT_USE_PPDEV #endif /* PARPORT_USE_PPDEV */
static int gw16012_init(void) static int gw16012_init(void)
{ {
@ -542,15 +513,11 @@ static int gw16012_quit(void)
COMMAND_HANDLER(gw16012_handle_parport_port_command) COMMAND_HANDLER(gw16012_handle_parport_port_command)
{ {
if (CMD_ARGC == 1) if (CMD_ARGC == 1) {
{
/* only if the port wasn't overwritten by cmdline */ /* only if the port wasn't overwritten by cmdline */
if (gw16012_port == 0) if (gw16012_port == 0)
{
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], gw16012_port); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], gw16012_port);
} else {
else
{
LOG_ERROR("The parport port was already configured!"); LOG_ERROR("The parport port was already configured!");
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -36,8 +36,7 @@
* Reference manual for J-Link USB Protocol * Reference manual for J-Link USB Protocol
* Document RM08001-R6 Date: June 16, 2009 * Document RM08001-R6 Date: June 16, 2009
* (Or newer, with some SWD information). * (Or newer, with some SWD information).
* http://www.segger.com/cms/admin/uploads/productDocs/RM08001_JLinkUSBProtocol.pdf
http://www.segger.com/cms/admin/uploads/productDocs/RM08001_JLinkUSBProtocol.pdf
*/ */
/* /*
@ -46,6 +45,7 @@ http://www.segger.com/cms/admin/uploads/productDocs/RM08001_JLinkUSBProtocol.pdf
* *
* pid = ( usb_address > 0x4) ? 0x0101 : (0x101 + usb_address) * pid = ( usb_address > 0x4) ? 0x0101 : (0x101 + usb_address)
*/ */
#define VID 0x1366, 0x1366, 0x1366, 0x1366 #define VID 0x1366, 0x1366, 0x1366, 0x1366
#define PID 0x0101, 0x0102, 0x0103, 0x0104 #define PID 0x0101, 0x0102, 0x0103, 0x0104
@ -58,14 +58,14 @@ static unsigned int jlink_hw_jtag_version = 2;
#define JLINK_USB_TIMEOUT 1000 #define JLINK_USB_TIMEOUT 1000
// See Section 3.3.2 of the Segger JLink USB protocol manual /* See Section 3.3.2 of the Segger JLink USB protocol manual */
/* 2048 is the max value we can use here */ /* 2048 is the max value we can use here */
#define JLINK_TAP_BUFFER_SIZE 2048 #define JLINK_TAP_BUFFER_SIZE 2048
//#define JLINK_TAP_BUFFER_SIZE 256 /*#define JLINK_TAP_BUFFER_SIZE 256*/
//#define JLINK_TAP_BUFFER_SIZE 384 /*#define JLINK_TAP_BUFFER_SIZE 384*/
#define JLINK_IN_BUFFER_SIZE 2048 #define JLINK_IN_BUFFER_SIZE 2048
#define JLINK_OUT_BUFFER_SIZE 2*2048 + 4 #define JLINK_OUT_BUFFER_SIZE (2*2048 + 4)
#define JLINK_EMU_RESULT_BUFFER_SIZE 64 #define JLINK_EMU_RESULT_BUFFER_SIZE 64
/* Global USB buffers */ /* Global USB buffers */
@ -222,7 +222,7 @@ static inline void jlink_debug_buffer(uint8_t *buffer, int length)
static enum tap_state jlink_last_state = TAP_RESET; static enum tap_state jlink_last_state = TAP_RESET;
static struct jlink* jlink_handle; static struct jlink *jlink_handle;
/* pid could be specified at runtime */ /* pid could be specified at runtime */
static uint16_t vids[] = { VID, 0 }; static uint16_t vids[] = { VID, 0 };
@ -320,14 +320,25 @@ static void jlink_execute_sleep(struct jtag_command *cmd)
static void jlink_execute_command(struct jtag_command *cmd) static void jlink_execute_command(struct jtag_command *cmd)
{ {
switch (cmd->type) switch (cmd->type) {
{ case JTAG_RUNTEST:
case JTAG_RUNTEST: jlink_execute_runtest(cmd); break; jlink_execute_runtest(cmd);
case JTAG_TLR_RESET: jlink_execute_statemove(cmd); break; break;
case JTAG_PATHMOVE: jlink_execute_pathmove(cmd); break; case JTAG_TLR_RESET:
case JTAG_SCAN: jlink_execute_scan(cmd); break; jlink_execute_statemove(cmd);
case JTAG_RESET: jlink_execute_reset(cmd); break; break;
case JTAG_SLEEP: jlink_execute_sleep(cmd); break; case JTAG_PATHMOVE:
jlink_execute_pathmove(cmd);
break;
case JTAG_SCAN:
jlink_execute_scan(cmd);
break;
case JTAG_RESET:
jlink_execute_reset(cmd);
break;
case JTAG_SLEEP:
jlink_execute_sleep(cmd);
break;
default: default:
LOG_ERROR("BUG: unknown JTAG command type encountered"); LOG_ERROR("BUG: unknown JTAG command type encountered");
exit(-1); exit(-1);
@ -338,8 +349,7 @@ static int jlink_execute_queue(void)
{ {
struct jtag_command *cmd = jtag_command_queue; struct jtag_command *cmd = jtag_command_queue;
while (cmd != NULL) while (cmd != NULL) {
{
jlink_execute_command(cmd); jlink_execute_command(cmd);
cmd = cmd->next; cmd = cmd->next;
} }
@ -352,8 +362,7 @@ static int jlink_speed(int speed)
{ {
int result; int result;
if (speed > JLINK_MAX_SPEED) if (speed > JLINK_MAX_SPEED) {
{
LOG_INFO("reduce speed request: %dkHz to %dkHz maximum", LOG_INFO("reduce speed request: %dkHz to %dkHz maximum",
speed, JLINK_MAX_SPEED); speed, JLINK_MAX_SPEED);
speed = JLINK_MAX_SPEED; speed = JLINK_MAX_SPEED;
@ -368,8 +377,7 @@ static int jlink_speed(int speed)
usb_out_buffer[2] = (speed >> 8) & 0xff; usb_out_buffer[2] = (speed >> 8) & 0xff;
result = jlink_usb_write(jlink_handle, 3); result = jlink_usb_write(jlink_handle, 3);
if (result != 3) if (result != 3) {
{
LOG_ERROR("J-Link setting speed failed (%d)", result); LOG_ERROR("J-Link setting speed failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -377,7 +385,7 @@ static int jlink_speed(int speed)
return ERROR_OK; return ERROR_OK;
} }
static int jlink_speed_div(int speed, int* khz) static int jlink_speed_div(int speed, int *khz)
{ {
*khz = speed; *khz = speed;
@ -397,8 +405,7 @@ static int jlink_init(void)
jlink_handle = jlink_usb_open(); jlink_handle = jlink_usb_open();
if (jlink_handle == 0) if (jlink_handle == 0) {
{
LOG_ERROR("Cannot find jlink Interface! Please check " LOG_ERROR("Cannot find jlink Interface! Please check "
"connection and permissions."); "connection and permissions.");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
@ -428,8 +435,7 @@ static int jlink_init(void)
jlink_hw_jtag_version = 2; jlink_hw_jtag_version = 2;
if (jlink_get_version_info() == ERROR_OK) if (jlink_get_version_info() == ERROR_OK) {
{
/* attempt to get status */ /* attempt to get status */
jlink_get_status(); jlink_get_status();
} }
@ -442,9 +448,8 @@ static int jlink_init(void)
/* v5/6 jlink seems to have an issue if the first tap move /* v5/6 jlink seems to have an issue if the first tap move
* is not divisible by 8, so we send a TLR on first power up */ * is not divisible by 8, so we send a TLR on first power up */
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++)
jlink_tap_append_step(1, 0); jlink_tap_append_step(1, 0);
}
jlink_tap_execute(); jlink_tap_execute();
return ERROR_OK; return ERROR_OK;
@ -462,11 +467,8 @@ static int jlink_quit(void)
static void jlink_end_state(tap_state_t state) static void jlink_end_state(tap_state_t state)
{ {
if (tap_is_state_stable(state)) if (tap_is_state_stable(state))
{
tap_set_end_state(state); tap_set_end_state(state);
} else {
else
{
LOG_ERROR("BUG: %i is not a valid end state", state); LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1); exit(-1);
} }
@ -480,8 +482,7 @@ static void jlink_state_move(void)
uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
uint8_t tms_scan_bits = tap_get_tms_path_len(tap_get_state(), tap_get_end_state()); uint8_t tms_scan_bits = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
for (i = 0; i < tms_scan_bits; i++) for (i = 0; i < tms_scan_bits; i++) {
{
tms = (tms_scan >> i) & 1; tms = (tms_scan >> i) & 1;
jlink_tap_append_step(tms, 0); jlink_tap_append_step(tms, 0);
} }
@ -493,18 +494,12 @@ static void jlink_path_move(int num_states, tap_state_t *path)
{ {
int i; int i;
for (i = 0; i < num_states; i++) for (i = 0; i < num_states; i++) {
{
if (path[i] == tap_state_transition(tap_get_state(), false)) if (path[i] == tap_state_transition(tap_get_state(), false))
{
jlink_tap_append_step(0, 0); jlink_tap_append_step(0, 0);
}
else if (path[i] == tap_state_transition(tap_get_state(), true)) else if (path[i] == tap_state_transition(tap_get_state(), true))
{
jlink_tap_append_step(1, 0); jlink_tap_append_step(1, 0);
} else {
else
{
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
tap_state_name(tap_get_state()), tap_state_name(path[i])); tap_state_name(tap_get_state()), tap_state_name(path[i]));
exit(-1); exit(-1);
@ -522,28 +517,23 @@ static void jlink_runtest(int num_cycles)
tap_state_t saved_end_state = tap_get_end_state(); tap_state_t saved_end_state = tap_get_end_state();
jlink_tap_ensure_space(1,num_cycles + 16); jlink_tap_ensure_space(1, num_cycles + 16);
/* only do a state_move when we're not already in IDLE */ /* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE) if (tap_get_state() != TAP_IDLE) {
{
jlink_end_state(TAP_IDLE); jlink_end_state(TAP_IDLE);
jlink_state_move(); jlink_state_move();
// num_cycles--; /* num_cycles--; */
} }
/* execute num_cycles */ /* execute num_cycles */
for (i = 0; i < num_cycles; i++) for (i = 0; i < num_cycles; i++)
{
jlink_tap_append_step(0, 0); jlink_tap_append_step(0, 0);
}
/* finish in end_state */ /* finish in end_state */
jlink_end_state(saved_end_state); jlink_end_state(saved_end_state);
if (tap_get_state() != tap_get_end_state()) if (tap_get_state() != tap_get_end_state())
{
jlink_state_move(); jlink_state_move();
}
} }
static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
@ -573,9 +563,7 @@ static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
tap_set_state(ir_scan ? TAP_IRPAUSE : TAP_DRPAUSE); tap_set_state(ir_scan ? TAP_IRPAUSE : TAP_DRPAUSE);
if (tap_get_state() != tap_get_end_state()) if (tap_get_state() != tap_get_end_state())
{
jlink_state_move(); jlink_state_move();
}
} }
static void jlink_reset(int trst, int srst) static void jlink_reset(int trst, int srst)
@ -584,23 +572,16 @@ static void jlink_reset(int trst, int srst)
/* Signals are active low */ /* Signals are active low */
if (srst == 0) if (srst == 0)
{
jlink_simple_command(EMU_CMD_HW_RESET1); jlink_simple_command(EMU_CMD_HW_RESET1);
}
if (srst == 1) if (srst == 1)
{
jlink_simple_command(EMU_CMD_HW_RESET0); jlink_simple_command(EMU_CMD_HW_RESET0);
}
if (trst == 1) if (trst == 1)
{
jlink_simple_command(EMU_CMD_HW_TRST0); jlink_simple_command(EMU_CMD_HW_TRST0);
}
if (trst == 0) if (trst == 0)
{
jlink_simple_command(EMU_CMD_HW_TRST1); jlink_simple_command(EMU_CMD_HW_TRST1);
}
} }
static void jlink_simple_command(uint8_t command) static void jlink_simple_command(uint8_t command)
@ -613,9 +594,7 @@ static void jlink_simple_command(uint8_t command)
result = jlink_usb_write(jlink_handle, 1); result = jlink_usb_write(jlink_handle, 1);
if (result != 1) if (result != 1)
{
LOG_ERROR("J-Link command 0x%02x failed (%d)", command, result); LOG_ERROR("J-Link command 0x%02x failed (%d)", command, result);
}
} }
static int jlink_get_status(void) static int jlink_get_status(void)
@ -625,8 +604,7 @@ static int jlink_get_status(void)
jlink_simple_command(EMU_CMD_GET_STATE); jlink_simple_command(EMU_CMD_GET_STATE);
result = jlink_usb_read(jlink_handle, 8); result = jlink_usb_read(jlink_handle, 8);
if (result != 8) if (result != 8) {
{
LOG_ERROR("J-Link command EMU_CMD_GET_STATE failed (%d)", result); LOG_ERROR("J-Link command EMU_CMD_GET_STATE failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -649,8 +627,7 @@ static int jlink_get_status(void)
command_print(context, expr); \ command_print(context, expr); \
else \ else \
LOG_INFO(expr); \ LOG_INFO(expr); \
} while(0); } while (0);
static void jlink_caps_dump(struct command_context *ctx) static void jlink_caps_dump(struct command_context *ctx)
{ {
@ -713,8 +690,7 @@ static void jlink_config_dump(struct command_context *ctx, struct jlink_config *
jlink_config_usb_address_dump(ctx, cfg); jlink_config_usb_address_dump(ctx, cfg);
jlink_config_kickstart_dump(ctx, cfg); jlink_config_kickstart_dump(ctx, cfg);
if (jlink_hw_type == JLINK_HW_TYPE_JLINK_PRO) if (jlink_hw_type == JLINK_HW_TYPE_JLINK_PRO) {
{
jlink_config_ip_dump(ctx, cfg); jlink_config_ip_dump(ctx, cfg);
jlink_config_mac_address_dump(ctx, cfg); jlink_config_mac_address_dump(ctx, cfg);
} }
@ -728,8 +704,7 @@ static int jlink_get_config(struct jlink_config *cfg)
jlink_simple_command(EMU_CMD_READ_CONFIG); jlink_simple_command(EMU_CMD_READ_CONFIG);
result = jlink_usb_read(jlink_handle, size); result = jlink_usb_read(jlink_handle, size);
if (size != result) if (size != result) {
{
LOG_ERROR("jlink_usb_read failed (requested=%d, result=%d)", size, result); LOG_ERROR("jlink_usb_read failed (requested=%d, result=%d)", size, result);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -755,8 +730,7 @@ static int jlink_set_config(struct jlink_config *cfg)
memcpy(usb_out_buffer, cfg, size); memcpy(usb_out_buffer, cfg, size);
result = jlink_usb_write(jlink_handle, size); result = jlink_usb_write(jlink_handle, size);
if (result != size) if (result != size) {
{
LOG_ERROR("jlink_usb_write failed (requested=%d, result=%d)", 256, result); LOG_ERROR("jlink_usb_write failed (requested=%d, result=%d)", 256, result);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -774,22 +748,19 @@ static int jlink_get_version_info(void)
jlink_simple_command(EMU_CMD_VERSION); jlink_simple_command(EMU_CMD_VERSION);
result = jlink_usb_read(jlink_handle, 2); result = jlink_usb_read(jlink_handle, 2);
if (2 != result) if (2 != result) {
{
LOG_ERROR("J-Link command EMU_CMD_VERSION failed (%d)", result); LOG_ERROR("J-Link command EMU_CMD_VERSION failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
len = buf_get_u32(usb_in_buffer, 0, 16); len = buf_get_u32(usb_in_buffer, 0, 16);
if (len > JLINK_IN_BUFFER_SIZE) if (len > JLINK_IN_BUFFER_SIZE) {
{
LOG_ERROR("J-Link command EMU_CMD_VERSION impossible return length 0x%0x", len); LOG_ERROR("J-Link command EMU_CMD_VERSION impossible return length 0x%0x", len);
len = JLINK_IN_BUFFER_SIZE; len = JLINK_IN_BUFFER_SIZE;
} }
result = jlink_usb_read(jlink_handle, len); result = jlink_usb_read(jlink_handle, len);
if (result != len) if (result != len) {
{
LOG_ERROR("J-Link command EMU_CMD_VERSION failed (%d)", result); LOG_ERROR("J-Link command EMU_CMD_VERSION failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -801,8 +772,7 @@ static int jlink_get_version_info(void)
jlink_simple_command(EMU_CMD_GET_CAPS); jlink_simple_command(EMU_CMD_GET_CAPS);
result = jlink_usb_read(jlink_handle, 4); result = jlink_usb_read(jlink_handle, 4);
if (4 != result) if (4 != result) {
{
LOG_ERROR("J-Link command EMU_CMD_GET_CAPS failed (%d)", result); LOG_ERROR("J-Link command EMU_CMD_GET_CAPS failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -810,14 +780,12 @@ static int jlink_get_version_info(void)
jlink_caps = buf_get_u32(usb_in_buffer, 0, 32); jlink_caps = buf_get_u32(usb_in_buffer, 0, 32);
LOG_INFO("J-Link caps 0x%x", (unsigned)jlink_caps); LOG_INFO("J-Link caps 0x%x", (unsigned)jlink_caps);
if (jlink_caps & (1 << EMU_CAP_GET_HW_VERSION)) if (jlink_caps & (1 << EMU_CAP_GET_HW_VERSION)) {
{
/* query hardware version */ /* query hardware version */
jlink_simple_command(EMU_CMD_GET_HW_VERSION); jlink_simple_command(EMU_CMD_GET_HW_VERSION);
result = jlink_usb_read(jlink_handle, 4); result = jlink_usb_read(jlink_handle, 4);
if (4 != result) if (4 != result) {
{
LOG_ERROR("J-Link command EMU_CMD_GET_HW_VERSION failed (%d)", result); LOG_ERROR("J-Link command EMU_CMD_GET_HW_VERSION failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -836,14 +804,12 @@ static int jlink_get_version_info(void)
LOG_INFO("J-Link hw type %s", jlink_hw_type_str[jlink_hw_type]); LOG_INFO("J-Link hw type %s", jlink_hw_type_str[jlink_hw_type]);
} }
if (jlink_caps & (1 << EMU_CAP_GET_MAX_BLOCK_SIZE)) if (jlink_caps & (1 << EMU_CAP_GET_MAX_BLOCK_SIZE)) {
{
/* query hardware maximum memory block */ /* query hardware maximum memory block */
jlink_simple_command(EMU_CMD_GET_MAX_MEM_BLOCK); jlink_simple_command(EMU_CMD_GET_MAX_MEM_BLOCK);
result = jlink_usb_read(jlink_handle, 4); result = jlink_usb_read(jlink_handle, 4);
if (4 != result) if (4 != result) {
{
LOG_ERROR("J-Link command EMU_CMD_GET_MAX_MEM_BLOCK failed (%d)", result); LOG_ERROR("J-Link command EMU_CMD_GET_MAX_MEM_BLOCK failed (%d)", result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -852,8 +818,7 @@ static int jlink_get_version_info(void)
LOG_INFO("J-Link max mem block %i", (int)jlink_max_size); LOG_INFO("J-Link max mem block %i", (int)jlink_max_size);
} }
if (jlink_caps & (1 << EMU_CAP_READ_CONFIG)) if (jlink_caps & (1 << EMU_CAP_READ_CONFIG)) {
{
if (jlink_get_config(&jlink_cfg) != ERROR_OK) if (jlink_get_config(&jlink_cfg) != ERROR_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -865,8 +830,7 @@ static int jlink_get_version_info(void)
COMMAND_HANDLER(jlink_pid_command) COMMAND_HANDLER(jlink_pid_command)
{ {
if (CMD_ARGC != 1) if (CMD_ARGC != 1) {
{
LOG_ERROR("Need exactly one argument to jlink_pid"); LOG_ERROR("Need exactly one argument to jlink_pid");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -880,8 +844,7 @@ COMMAND_HANDLER(jlink_pid_command)
COMMAND_HANDLER(jlink_handle_jlink_info_command) COMMAND_HANDLER(jlink_handle_jlink_info_command)
{ {
if (jlink_get_version_info() == ERROR_OK) if (jlink_get_version_info() == ERROR_OK) {
{
/* attempt to get status */ /* attempt to get status */
jlink_get_status(); jlink_get_status();
} }
@ -905,7 +868,8 @@ COMMAND_HANDLER(jlink_handle_jlink_hw_jtag_command)
case 1: { case 1: {
int request_version = atoi(CMD_ARGV[0]); int request_version = atoi(CMD_ARGV[0]);
switch (request_version) { switch (request_version) {
case 2: case 3: case 2:
case 3:
jlink_hw_jtag_version = request_version; jlink_hw_jtag_version = request_version;
break; break;
default: default:
@ -924,8 +888,7 @@ COMMAND_HANDLER(jlink_handle_jlink_kickstart_command)
{ {
uint32_t kickstart; uint32_t kickstart;
if (CMD_ARGC < 1) if (CMD_ARGC < 1) {
{
jlink_config_kickstart_dump(CMD_CTX, &jlink_cfg); jlink_config_kickstart_dump(CMD_CTX, &jlink_cfg);
return ERROR_OK; return ERROR_OK;
} }
@ -943,8 +906,7 @@ COMMAND_HANDLER(jlink_handle_jlink_mac_address_command)
char *e; char *e;
const char *str; const char *str;
if (CMD_ARGC < 1) if (CMD_ARGC < 1) {
{
jlink_config_mac_address_dump(CMD_CTX, &jlink_cfg); jlink_config_mac_address_dump(CMD_CTX, &jlink_cfg);
return ERROR_OK; return ERROR_OK;
} }
@ -952,26 +914,22 @@ COMMAND_HANDLER(jlink_handle_jlink_mac_address_command)
str = CMD_ARGV[0]; str = CMD_ARGV[0];
if ((strlen(str) != 17) || (str[2] != ':' || str[5] != ':' || str[8] != ':' || if ((strlen(str) != 17) || (str[2] != ':' || str[5] != ':' || str[8] != ':' ||
str[11] != ':' || str[14] != ':')) str[11] != ':' || str[14] != ':')) {
{
command_print(CMD_CTX, "ethaddr miss format ff:ff:ff:ff:ff:ff"); command_print(CMD_CTX, "ethaddr miss format ff:ff:ff:ff:ff:ff");
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
for (i = 5; i >= 0; i--) for (i = 5; i >= 0; i--) {
{
addr[i] = strtoul(str, &e, 16); addr[i] = strtoul(str, &e, 16);
str = e + 1; str = e + 1;
} }
if (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5])) if (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5])) {
{
command_print(CMD_CTX, "invalid it's zero mac_address"); command_print(CMD_CTX, "invalid it's zero mac_address");
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
if (!(0x01 & addr[0])) if (!(0x01 & addr[0])) {
{
command_print(CMD_CTX, "invalid it's a multicat mac_address"); command_print(CMD_CTX, "invalid it's a multicat mac_address");
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
@ -1022,13 +980,12 @@ COMMAND_HANDLER(jlink_handle_jlink_ip_command)
int ret; int ret;
uint8_t subnet_bits = 24; uint8_t subnet_bits = 24;
if (CMD_ARGC < 1) if (CMD_ARGC < 1) {
{
jlink_config_ip_dump(CMD_CTX, &jlink_cfg); jlink_config_ip_dump(CMD_CTX, &jlink_cfg);
return ERROR_OK; return ERROR_OK;
} }
ret = string_to_ip(CMD_ARGV[0], (uint8_t*)&ip_address, &i); ret = string_to_ip(CMD_ARGV[0], (uint8_t *)&ip_address, &i);
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;
@ -1036,18 +993,14 @@ COMMAND_HANDLER(jlink_handle_jlink_ip_command)
/* check for this format A.B.C.D/E */ /* check for this format A.B.C.D/E */
if (i < len) if (i < len) {
{
if (CMD_ARGV[0][i] != '/') if (CMD_ARGV[0][i] != '/')
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0] + i + 1, subnet_bits); COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0] + i + 1, subnet_bits);
} } else {
else if (CMD_ARGC > 1) {
{ ret = string_to_ip(CMD_ARGV[1], (uint8_t *)&subnet_mask, &i);
if (CMD_ARGC > 1)
{
ret = string_to_ip(CMD_ARGV[1], (uint8_t*)&subnet_mask, &i);
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;
} }
@ -1055,10 +1008,10 @@ COMMAND_HANDLER(jlink_handle_jlink_ip_command)
if (!subnet_mask) if (!subnet_mask)
subnet_mask = (uint32_t)(subnet_bits < 32 ? subnet_mask = (uint32_t)(subnet_bits < 32 ?
((1ULL << subnet_bits) -1) : 0xffffffff); ((1ULL << subnet_bits) - 1) : 0xffffffff);
cpy_ip(jlink_cfg.ip_address, (uint8_t*)&ip_address); cpy_ip(jlink_cfg.ip_address, (uint8_t *)&ip_address);
cpy_ip(jlink_cfg.subnet_mask, (uint8_t*)&subnet_mask); cpy_ip(jlink_cfg.subnet_mask, (uint8_t *)&subnet_mask);
return ERROR_OK; return ERROR_OK;
} }
@ -1071,8 +1024,7 @@ COMMAND_HANDLER(jlink_handle_jlink_reset_command)
COMMAND_HANDLER(jlink_handle_jlink_save_command) COMMAND_HANDLER(jlink_handle_jlink_save_command)
{ {
if (!(jlink_caps & (1 << EMU_CAP_WRITE_CONFIG))) if (!(jlink_caps & (1 << EMU_CAP_WRITE_CONFIG))) {
{
command_print(CMD_CTX, "J-Link write emulator configuration not supported"); command_print(CMD_CTX, "J-Link write emulator configuration not supported");
return ERROR_OK; return ERROR_OK;
} }
@ -1085,16 +1037,14 @@ COMMAND_HANDLER(jlink_handle_jlink_usb_address_command)
{ {
uint32_t address; uint32_t address;
if (CMD_ARGC < 1) if (CMD_ARGC < 1) {
{
jlink_config_usb_address_dump(CMD_CTX, &jlink_cfg); jlink_config_usb_address_dump(CMD_CTX, &jlink_cfg);
return ERROR_OK; return ERROR_OK;
} }
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
if (address > 0x3 && address != 0xff) if (address > 0x3 && address != 0xff) {
{
command_print(CMD_CTX, "USB Address must be between 0x00 and 0x03 or 0xff"); command_print(CMD_CTX, "USB Address must be between 0x00 and 0x03 or 0xff");
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
@ -1108,17 +1058,15 @@ COMMAND_HANDLER(jlink_handle_jlink_config_command)
struct jlink_config cfg; struct jlink_config cfg;
int ret = ERROR_OK; int ret = ERROR_OK;
if (CMD_ARGC == 0) if (CMD_ARGC == 0) {
{ if (!(jlink_caps & (1 << EMU_CAP_READ_CONFIG))) {
if (!(jlink_caps & (1 << EMU_CAP_READ_CONFIG)))
{
command_print(CMD_CTX, "J-Link read emulator configuration not supported"); command_print(CMD_CTX, "J-Link read emulator configuration not supported");
goto exit; goto exit;
} }
ret = jlink_get_config(&cfg); ret = jlink_get_config(&cfg);
if ( ret != ERROR_OK) if (ret != ERROR_OK)
command_print(CMD_CTX, "J-Link read emulator configuration failled"); command_print(CMD_CTX, "J-Link read emulator configuration failled");
else else
jlink_config_dump(CMD_CTX, &jlink_cfg); jlink_config_dump(CMD_CTX, &jlink_cfg);
@ -1239,7 +1187,7 @@ struct jtag_interface jlink_interface = {
/* J-Link tap functions */ /* J-Link tap functions */
static unsigned tap_length = 0; static unsigned tap_length;
static uint8_t tms_buffer[JLINK_TAP_BUFFER_SIZE]; static uint8_t tms_buffer[JLINK_TAP_BUFFER_SIZE];
static uint8_t tdi_buffer[JLINK_TAP_BUFFER_SIZE]; static uint8_t tdi_buffer[JLINK_TAP_BUFFER_SIZE];
static uint8_t tdo_buffer[JLINK_TAP_BUFFER_SIZE]; static uint8_t tdo_buffer[JLINK_TAP_BUFFER_SIZE];
@ -1268,17 +1216,14 @@ static void jlink_tap_ensure_space(int scans, int bits)
int available_bits = JLINK_TAP_BUFFER_SIZE * 8 - tap_length - 32; int available_bits = JLINK_TAP_BUFFER_SIZE * 8 - tap_length - 32;
if (scans > available_scans || bits > available_bits) if (scans > available_scans || bits > available_bits)
{
jlink_tap_execute(); jlink_tap_execute();
}
} }
static void jlink_tap_append_step(int tms, int tdi) static void jlink_tap_append_step(int tms, int tdi)
{ {
int index_var = tap_length / 8; int index_var = tap_length / 8;
if (index_var >= JLINK_TAP_BUFFER_SIZE) if (index_var >= JLINK_TAP_BUFFER_SIZE) {
{
LOG_ERROR("jlink_tap_append_step: overflow"); LOG_ERROR("jlink_tap_append_step: overflow");
*(uint32_t *)0xFFFFFFFF = 0; *(uint32_t *)0xFFFFFFFF = 0;
exit(-1); exit(-1);
@ -1287,11 +1232,9 @@ static void jlink_tap_append_step(int tms, int tdi)
int bit_index = tap_length % 8; int bit_index = tap_length % 8;
uint8_t bit = 1 << bit_index; uint8_t bit = 1 << bit_index;
// we do not pad TMS, so be sure to initialize all bits /* we do not pad TMS, so be sure to initialize all bits */
if (0 == bit_index) if (0 == bit_index)
{
tms_buffer[index_var] = tdi_buffer[index_var] = 0; tms_buffer[index_var] = tdi_buffer[index_var] = 0;
}
if (tms) if (tms)
tms_buffer[index_var] |= bit; tms_buffer[index_var] |= bit;
@ -1318,8 +1261,7 @@ static void jlink_tap_append_scan(int length, uint8_t *buffer,
pending_scan_result->command = command; pending_scan_result->command = command;
pending_scan_result->buffer = buffer; pending_scan_result->buffer = buffer;
for (i = 0; i < length; i++) for (i = 0; i < length; i++) {
{
int tms = (i < (length - 1)) ? 0 : 1; int tms = (i < (length - 1)) ? 0 : 1;
int tdi = (buffer[i / 8] & (1 << (i % 8))) != 0; int tdi = (buffer[i / 8] & (1 << (i % 8))) != 0;
jlink_tap_append_step(tms, tdi); jlink_tap_append_step(tms, tdi);
@ -1342,11 +1284,9 @@ static int jlink_tap_execute(void)
* message is a multiple of 64, creates problems with USB comms. * message is a multiple of 64, creates problems with USB comms.
* WARNING: This will interfere with tap state counting. */ * WARNING: This will interfere with tap state counting. */
while ((DIV_ROUND_UP(tap_length, 8) % 64) == 0) while ((DIV_ROUND_UP(tap_length, 8) % 64) == 0)
{
jlink_tap_append_step((tap_get_state() == TAP_RESET) ? 1 : 0, 0); jlink_tap_append_step((tap_get_state() == TAP_RESET) ? 1 : 0, 0);
}
// number of full bytes (plus one if some would be left over) /* number of full bytes (plus one if some would be left over) */
byte_length = DIV_ROUND_UP(tap_length, 8); byte_length = DIV_ROUND_UP(tap_length, 8);
bool use_jtag3 = jlink_hw_jtag_version >= 3; bool use_jtag3 = jlink_hw_jtag_version >= 3;
@ -1361,8 +1301,7 @@ static int jlink_tap_execute(void)
tap_length, jlink_last_state); tap_length, jlink_last_state);
result = jlink_usb_message(jlink_handle, 4 + 2 * byte_length, byte_length); result = jlink_usb_message(jlink_handle, 4 + 2 * byte_length, byte_length);
if (result != byte_length) if (result != byte_length) {
{
LOG_ERROR("jlink_tap_execute, wrong result %d (expected %d)", LOG_ERROR("jlink_tap_execute, wrong result %d (expected %d)",
result, byte_length); result, byte_length);
jlink_tap_init(); jlink_tap_init();
@ -1371,8 +1310,7 @@ static int jlink_tap_execute(void)
memcpy(tdo_buffer, usb_in_buffer, byte_length); memcpy(tdo_buffer, usb_in_buffer, byte_length);
for (i = 0; i < pending_scan_results_length; i++) for (i = 0; i < pending_scan_results_length; i++) {
{
struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[i]; struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[i];
uint8_t *buffer = pending_scan_result->buffer; uint8_t *buffer = pending_scan_result->buffer;
int length = pending_scan_result->length; int length = pending_scan_result->length;
@ -1386,17 +1324,14 @@ static int jlink_tap_execute(void)
jlink_debug_buffer(buffer, DIV_ROUND_UP(length, 8)); jlink_debug_buffer(buffer, DIV_ROUND_UP(length, 8));
if (jtag_read_buffer(buffer, command) != ERROR_OK) if (jtag_read_buffer(buffer, command) != ERROR_OK) {
{
jlink_tap_init(); jlink_tap_init();
return ERROR_JTAG_QUEUE_FAILED; return ERROR_JTAG_QUEUE_FAILED;
} }
if (pending_scan_result->buffer != NULL) if (pending_scan_result->buffer != NULL)
{
free(pending_scan_result->buffer); free(pending_scan_result->buffer);
} }
}
jlink_tap_init(); jlink_tap_init();
return ERROR_OK; return ERROR_OK;
@ -1405,7 +1340,7 @@ static int jlink_tap_execute(void)
/*****************************************************************************/ /*****************************************************************************/
/* JLink USB low-level functions */ /* JLink USB low-level functions */
static struct jlink* jlink_usb_open() static struct jlink *jlink_usb_open()
{ {
struct jtag_libusb_device_handle *devh; struct jtag_libusb_device_handle *devh;
if (jtag_libusb_open(vids, pids, &devh) != ERROR_OK) if (jtag_libusb_open(vids, pids, &devh) != ERROR_OK)
@ -1432,14 +1367,12 @@ static struct jlink* jlink_usb_open()
/* reopen jlink after usb_reset /* reopen jlink after usb_reset
* on win32 this may take a second or two to re-enumerate */ * on win32 this may take a second or two to re-enumerate */
int retval; int retval;
while ((retval = jtag_libusb_open(vids, pids, &devh)) != ERROR_OK) while ((retval = jtag_libusb_open(vids, pids, &devh)) != ERROR_OK) {
{
usleep(1000); usleep(1000);
timeout--; timeout--;
if (!timeout) { if (!timeout)
break; break;
} }
}
if (ERROR_OK != retval) if (ERROR_OK != retval)
return NULL; return NULL;
#endif #endif
@ -1478,16 +1411,14 @@ static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length)
int result; int result;
result = jlink_usb_write(jlink, out_length); result = jlink_usb_write(jlink, out_length);
if (result != out_length) if (result != out_length) {
{
LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)",
out_length, result); out_length, result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
result = jlink_usb_read(jlink, in_length); result = jlink_usb_read(jlink, in_length);
if ((result != in_length) && (result != (in_length + 1))) if ((result != in_length) && (result != (in_length + 1))) {
{
LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)",
in_length, result); in_length, result);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -1497,18 +1428,15 @@ static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length)
return result; return result;
int result2 = ERROR_OK; int result2 = ERROR_OK;
if (result == in_length) if (result == in_length) {
{
/* Must read the result from the EMU too */ /* Must read the result from the EMU too */
result2 = jlink_usb_read_emu_result(jlink); result2 = jlink_usb_read_emu_result(jlink);
if (1 != result2) if (1 != result2) {
{
LOG_ERROR("jlink_usb_read_emu_result retried requested = 1, " LOG_ERROR("jlink_usb_read_emu_result retried requested = 1, "
"result=%d, in_length=%i", result2, in_length); "result=%d, in_length=%i", result2, in_length);
/* Try again once, should only happen if (in_length%64 == 0) */ /* Try again once, should only happen if (in_length%64 == 0) */
result2 = jlink_usb_read_emu_result(jlink); result2 = jlink_usb_read_emu_result(jlink);
if (1 != result2) if (1 != result2) {
{
LOG_ERROR("jlink_usb_read_emu_result failed " LOG_ERROR("jlink_usb_read_emu_result failed "
"(requested = 1, result=%d)", result2); "(requested = 1, result=%d)", result2);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -1517,15 +1445,12 @@ static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length)
/* Check the result itself */ /* Check the result itself */
result2 = usb_emu_result_buffer[0]; result2 = usb_emu_result_buffer[0];
} } else {
else
{
/* Save the result, then remove it from return value */ /* Save the result, then remove it from return value */
result2 = usb_in_buffer[result--]; result2 = usb_in_buffer[result--];
} }
if (result2) if (result2) {
{
LOG_ERROR("jlink_usb_message failed with result=%d)", result2); LOG_ERROR("jlink_usb_message failed with result=%d)", result2);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -1542,8 +1467,7 @@ static int usb_bulk_with_retries(
{ {
int tries = 3, count = 0; int tries = 3, count = 0;
while (tries && (count < size)) while (tries && (count < size)) {
{
int result = f(dev, ep, bytes + count, size - count, timeout); int result = f(dev, ep, bytes + count, size - count, timeout);
if (result > 0) if (result > 0)
count += result; count += result;
@ -1579,8 +1503,7 @@ static int jlink_usb_write(struct jlink *jlink, int out_length)
{ {
int result; int result;
if (out_length > JLINK_OUT_BUFFER_SIZE) if (out_length > JLINK_OUT_BUFFER_SIZE) {
{
LOG_ERROR("jlink_write illegal out_length=%d (max=%d)", LOG_ERROR("jlink_write illegal out_length=%d (max=%d)",
out_length, JLINK_OUT_BUFFER_SIZE); out_length, JLINK_OUT_BUFFER_SIZE);
return -1; return -1;
@ -1631,11 +1554,9 @@ static void jlink_debug_buffer(uint8_t *buffer, int length)
int i; int i;
int j; int j;
for (i = 0; i < length; i += BYTES_PER_LINE) for (i = 0; i < length; i += BYTES_PER_LINE) {
{
snprintf(line, 5, "%04x", i); snprintf(line, 5, "%04x", i);
for (j = i; j < i + BYTES_PER_LINE && j < length; j++) for (j = i; j < i + BYTES_PER_LINE && j < length; j++) {
{
snprintf(s, 4, " %02x", buffer[j]); snprintf(s, 4, " %02x", buffer[j]);
strcat(line, s); strcat(line, s);
} }

View File

@ -29,8 +29,8 @@ static inline void interface_jtag_add_scan_check_alloc(struct scan_field *field)
field->in_value = (uint8_t *)cmd_queue_alloc(num_bytes); field->in_value = (uint8_t *)cmd_queue_alloc(num_bytes);
} }
void interface_jtag_add_dr_out(struct jtag_tap* tap, void interface_jtag_add_dr_out(struct jtag_tap *tap,
int num_fields, const int* num_bits, const uint32_t* value, int num_fields, const int *num_bits, const uint32_t *value,
tap_state_t end_state); tap_state_t end_state);
void interface_jtag_add_callback(jtag_callback1_t f, jtag_callback_data_t data0); void interface_jtag_add_callback(jtag_callback1_t f, jtag_callback_data_t data0);
@ -39,8 +39,8 @@ void interface_jtag_add_callback4(jtag_callback_t f, jtag_callback_data_t data0,
jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data1, jtag_callback_data_t data2,
jtag_callback_data_t data3); jtag_callback_data_t data3);
void jtag_add_dr_out(struct jtag_tap* tap, void jtag_add_dr_out(struct jtag_tap *tap,
int num_fields, const int* num_bits, const uint32_t* value, int num_fields, const int *num_bits, const uint32_t *value,
tap_state_t end_state); tap_state_t end_state);
@ -48,4 +48,4 @@ void jtag_add_callback4(jtag_callback_t f, jtag_callback_data_t data0,
jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data1, jtag_callback_data_t data2,
jtag_callback_data_t data3); jtag_callback_data_t data3);
#endif // MINIDRIVER_IMP_H #endif /* MINIDRIVER_IMP_H */

View File

@ -20,6 +20,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -31,7 +32,7 @@
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <machine/sysarch.h> #include <machine/sysarch.h>
#include <machine/cpufunc.h> #include <machine/cpufunc.h>
#define ioperm(startport,length,enable)\ #define ioperm(startport, length, enable)\
i386_set_ioperm((startport), (length), (enable)) i386_set_ioperm((startport), (length), (enable))
#endif /* __FreeBSD__ */ #endif /* __FreeBSD__ */
@ -56,11 +57,10 @@
#include <windows.h> #include <windows.h>
#endif #endif
/* parallel port cable description /* parallel port cable description
*/ */
struct cable { struct cable {
char* name; char *name;
uint8_t TDO_MASK; /* status port bit containing current TDO value */ uint8_t TDO_MASK; /* status port bit containing current TDO value */
uint8_t TRST_MASK; /* data port bit for TRST */ uint8_t TRST_MASK; /* data port bit for TRST */
uint8_t TMS_MASK; /* data port bit for TMS */ uint8_t TMS_MASK; /* data port bit for TMS */
@ -74,8 +74,7 @@ struct cable {
uint8_t LED_MASK; /* data port bit for LED */ uint8_t LED_MASK; /* data port bit for LED */
}; };
static struct cable cables[] = static struct cable cables[] = {
{
/* name tdo trst tms tck tdi srst o_inv i_inv init exit led */ /* name tdo trst tms tck tdi srst o_inv i_inv init exit led */
{ "wiggler", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x80, 0x00 }, { "wiggler", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x80, 0x00 },
{ "wiggler2", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x00, 0x20 }, { "wiggler2", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x00, 0x20 },
@ -100,16 +99,16 @@ static struct cable cables[] =
}; };
/* configuration */ /* configuration */
static char* parport_cable = NULL; static char *parport_cable;
static uint16_t parport_port; static uint16_t parport_port;
static bool parport_exit = 0; static bool parport_exit;
static uint32_t parport_toggling_time_ns = 1000; static uint32_t parport_toggling_time_ns = 1000;
static int wait_states; static int wait_states;
/* interface variables /* interface variables
*/ */
static struct cable* cable; static struct cable *cable;
static uint8_t dataport_value = 0x0; static uint8_t dataport_value;
#if PARPORT_USE_PPDEV == 1 #if PARPORT_USE_PPDEV == 1
static int device_handle; static int device_handle;
@ -123,7 +122,7 @@ static int parport_read(void)
int data = 0; int data = 0;
#if PARPORT_USE_PPDEV == 1 #if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPRSTATUS, & data); ioctl(device_handle, PPRSTATUS, &data);
#else #else
data = inb(statusport); data = inb(statusport);
#endif #endif
@ -134,7 +133,7 @@ static int parport_read(void)
return 0; return 0;
} }
static __inline__ void parport_write_data(void) static inline void parport_write_data(void)
{ {
uint8_t output; uint8_t output;
output = dataport_value ^ cable->OUTPUT_INVERT; output = dataport_value ^ cable->OUTPUT_INVERT;
@ -208,7 +207,7 @@ static int parport_speed(int speed)
return ERROR_OK; return ERROR_OK;
} }
static int parport_khz(int khz, int* jtag_speed) static int parport_khz(int khz, int *jtag_speed)
{ {
if (khz == 0) { if (khz == 0) {
LOG_DEBUG("RCLK not supported"); LOG_DEBUG("RCLK not supported");
@ -219,7 +218,7 @@ static int parport_khz(int khz, int* jtag_speed)
return ERROR_OK; return ERROR_OK;
} }
static int parport_speed_div(int speed, int* khz) static int parport_speed_div(int speed, int *khz)
{ {
uint32_t denominator = (speed + 1) * parport_toggling_time_ns; uint32_t denominator = (speed + 1) * parport_toggling_time_ns;
@ -269,24 +268,20 @@ static int parport_init(void)
cur_cable = cables; cur_cable = cables;
if ((parport_cable == NULL) || (parport_cable[0] == 0)) if ((parport_cable == NULL) || (parport_cable[0] == 0)) {
{
parport_cable = "wiggler"; parport_cable = "wiggler";
LOG_WARNING("No parport cable specified, using default 'wiggler'"); LOG_WARNING("No parport cable specified, using default 'wiggler'");
} }
while (cur_cable->name) while (cur_cable->name) {
{ if (strcmp(cur_cable->name, parport_cable) == 0) {
if (strcmp(cur_cable->name, parport_cable) == 0)
{
cable = cur_cable; cable = cur_cable;
break; break;
} }
cur_cable++; cur_cable++;
} }
if (!cable) if (!cable) {
{
LOG_ERROR("No matching cable found for %s", parport_cable); LOG_ERROR("No matching cable found for %s", parport_cable);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -294,8 +289,7 @@ static int parport_init(void)
dataport_value = cable->PORT_INIT; dataport_value = cable->PORT_INIT;
#if PARPORT_USE_PPDEV == 1 #if PARPORT_USE_PPDEV == 1
if (device_handle > 0) if (device_handle > 0) {
{
LOG_ERROR("device is already opened"); LOG_ERROR("device is already opened");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -312,8 +306,7 @@ static int parport_init(void)
device_handle = open(buffer, O_WRONLY); device_handle = open(buffer, O_WRONLY);
#endif /* __FreeBSD__, __FreeBSD_kernel__ */ #endif /* __FreeBSD__, __FreeBSD_kernel__ */
if (device_handle < 0) if (device_handle < 0) {
{
int err = errno; int err = errno;
LOG_ERROR("cannot open device. check it exists and that user read and write rights are set. errno=%d", err); LOG_ERROR("cannot open device. check it exists and that user read and write rights are set. errno=%d", err);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
@ -324,32 +317,28 @@ static int parport_init(void)
#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) #if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
int i = ioctl(device_handle, PPCLAIM); int i = ioctl(device_handle, PPCLAIM);
if (i < 0) if (i < 0) {
{
LOG_ERROR("cannot claim device"); LOG_ERROR("cannot claim device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
i = PARPORT_MODE_COMPAT; i = PARPORT_MODE_COMPAT;
i= ioctl(device_handle, PPSETMODE, & i); i = ioctl(device_handle, PPSETMODE, &i);
if (i < 0) if (i < 0) {
{
LOG_ERROR(" cannot set compatible mode to device"); LOG_ERROR(" cannot set compatible mode to device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
i = IEEE1284_MODE_COMPAT; i = IEEE1284_MODE_COMPAT;
i = ioctl(device_handle, PPNEGOT, & i); i = ioctl(device_handle, PPNEGOT, &i);
if (i < 0) if (i < 0) {
{
LOG_ERROR("cannot set compatible 1284 mode to device"); LOG_ERROR("cannot set compatible 1284 mode to device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
#endif /* not __FreeBSD__, __FreeBSD_kernel__ */ #endif /* not __FreeBSD__, __FreeBSD_kernel__ */
#else /* not PARPORT_USE_PPDEV */ #else /* not PARPORT_USE_PPDEV */
if (parport_port == 0) if (parport_port == 0) {
{
parport_port = 0x378; parport_port = 0x378;
LOG_WARNING("No parport port specified, using default '0x378' (LPT1)"); LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
} }
@ -359,11 +348,10 @@ static int parport_init(void)
LOG_DEBUG("requesting privileges for parallel port 0x%lx...", dataport); LOG_DEBUG("requesting privileges for parallel port 0x%lx...", dataport);
#if PARPORT_USE_GIVEIO == 1 #if PARPORT_USE_GIVEIO == 1
if (parport_get_giveio_access() != 0) if (parport_get_giveio_access() != 0) {
#else /* PARPORT_USE_GIVEIO */ #else /* PARPORT_USE_GIVEIO */
if (ioperm(dataport, 3, 1) != 0) if (ioperm(dataport, 3, 1) != 0) {
#endif /* PARPORT_USE_GIVEIO */ #endif /* PARPORT_USE_GIVEIO */
{
LOG_ERROR("missing privileges for direct i/o"); LOG_ERROR("missing privileges for direct i/o");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -391,14 +379,12 @@ static int parport_quit(void)
{ {
parport_led(0); parport_led(0);
if (parport_exit) if (parport_exit) {
{
dataport_value = cable->PORT_EXIT; dataport_value = cable->PORT_EXIT;
parport_write_data(); parport_write_data();
} }
if (parport_cable) if (parport_cable) {
{
free(parport_cable); free(parport_cable);
parport_cable = NULL; parport_cable = NULL;
} }
@ -408,15 +394,11 @@ static int parport_quit(void)
COMMAND_HANDLER(parport_handle_parport_port_command) COMMAND_HANDLER(parport_handle_parport_port_command)
{ {
if (CMD_ARGC == 1) if (CMD_ARGC == 1) {
{
/* only if the port wasn't overwritten by cmdline */ /* only if the port wasn't overwritten by cmdline */
if (parport_port == 0) if (parport_port == 0)
{
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], parport_port); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], parport_port);
} else {
else
{
LOG_ERROR("The parport port was already configured!"); LOG_ERROR("The parport port was already configured!");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -433,8 +415,7 @@ COMMAND_HANDLER(parport_handle_parport_cable_command)
return ERROR_OK; return ERROR_OK;
/* only if the cable name wasn't overwritten by cmdline */ /* only if the cable name wasn't overwritten by cmdline */
if (parport_cable == 0) if (parport_cable == 0) {
{
/* REVISIT first verify that it's listed in cables[] ... */ /* REVISIT first verify that it's listed in cables[] ... */
parport_cable = malloc(strlen(CMD_ARGV[0]) + sizeof(char)); parport_cable = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
strcpy(parport_cable, CMD_ARGV[0]); strcpy(parport_cable, CMD_ARGV[0]);
@ -448,9 +429,7 @@ COMMAND_HANDLER(parport_handle_parport_cable_command)
COMMAND_HANDLER(parport_handle_write_on_exit_command) COMMAND_HANDLER(parport_handle_write_on_exit_command)
{ {
if (CMD_ARGC != 1) if (CMD_ARGC != 1)
{
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_ON_OFF(CMD_ARGV[0], parport_exit); COMMAND_PARSE_ON_OFF(CMD_ARGV[0], parport_exit);

View File

@ -35,7 +35,6 @@
#include <helper/time_support.h> #include <helper/time_support.h>
#include "bitq.h" #include "bitq.h"
/* PRESTO access library includes */ /* PRESTO access library includes */
#if BUILD_PRESTO_FTD2XX == 1 #if BUILD_PRESTO_FTD2XX == 1
#include <ftd2xx.h> #include <ftd2xx.h>
@ -72,8 +71,8 @@ struct presto {
int buff_out_pos; int buff_out_pos;
uint8_t buff_in[BUFFER_SIZE]; uint8_t buff_in[BUFFER_SIZE];
int buff_in_exp; /* expected in buffer length */ int buff_in_exp;/* expected in buffer length */
int buff_in_len; /* length of data received */ int buff_in_len;/* length of data received */
int buff_in_pos; int buff_in_pos;
unsigned long total_out; unsigned long total_out;
@ -92,8 +91,7 @@ struct presto {
static struct presto presto_state; static struct presto presto_state;
static struct presto *presto = &presto_state; static struct presto *presto = &presto_state;
static uint8_t presto_init_seq[] = static uint8_t presto_init_seq[] = {
{
0x80, 0xA0, 0xA8, 0xB0, 0xC0, 0xE0 0x80, 0xA0, 0xA8, 0xB0, 0xC0, 0xE0
}; };
@ -101,24 +99,23 @@ static int presto_write(uint8_t *buf, uint32_t size)
{ {
#if BUILD_PRESTO_FTD2XX == 1 #if BUILD_PRESTO_FTD2XX == 1
DWORD ftbytes; DWORD ftbytes;
if ((presto->status = FT_Write(presto->handle, buf, size, &ftbytes)) != FT_OK) presto->status = FT_Write(presto->handle, buf, size, &ftbytes);
{ if (presto->status != FT_OK) {
LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(presto->status)); LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(presto->status));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
#elif BUILD_PRESTO_LIBFTDI == 1 #elif BUILD_PRESTO_LIBFTDI == 1
uint32_t ftbytes; uint32_t ftbytes;
if ((presto->retval = ftdi_write_data(&presto->ftdic, buf, size)) < 0) presto->retval = ftdi_write_data(&presto->ftdic, buf, size);
{ if (presto->retval < 0) {
LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&presto->ftdic)); LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&presto->ftdic));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
ftbytes = presto->retval; ftbytes = presto->retval;
#endif #endif
if (ftbytes != size) if (ftbytes != size) {
{
LOG_ERROR("couldn't write the requested number of bytes to PRESTO (%u < %u)", LOG_ERROR("couldn't write the requested number of bytes to PRESTO (%u < %u)",
(unsigned)ftbytes, (unsigned)size); (unsigned)ftbytes, (unsigned)size);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -127,12 +124,12 @@ static int presto_write(uint8_t *buf, uint32_t size)
return ERROR_OK; return ERROR_OK;
} }
static int presto_read(uint8_t* buf, uint32_t size) static int presto_read(uint8_t *buf, uint32_t size)
{ {
#if BUILD_PRESTO_FTD2XX == 1 #if BUILD_PRESTO_FTD2XX == 1
DWORD ftbytes; DWORD ftbytes;
if ((presto->status = FT_Read(presto->handle, buf, size, &ftbytes)) != FT_OK) presto->status = FT_Read(presto->handle, buf, size, &ftbytes);
{ if (presto->status != FT_OK) {
LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(presto->status)); LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(presto->status));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -144,24 +141,24 @@ static int presto_read(uint8_t* buf, uint32_t size)
gettimeofday(&timeout, NULL); gettimeofday(&timeout, NULL);
timeval_add_time(&timeout, 1, 0); /* one second timeout */ timeval_add_time(&timeout, 1, 0); /* one second timeout */
while (ftbytes < size) while (ftbytes < size) {
{ presto->retval = ftdi_read_data(&presto->ftdic, buf + ftbytes, size - ftbytes);
if ((presto->retval = ftdi_read_data(&presto->ftdic, buf + ftbytes, size - ftbytes)) < 0) if (presto->retval < 0) {
{
LOG_ERROR("ftdi_read_data: %s", ftdi_get_error_string(&presto->ftdic)); LOG_ERROR("ftdi_read_data: %s", ftdi_get_error_string(&presto->ftdic));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
ftbytes += presto->retval; ftbytes += presto->retval;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec) && (now.tv_usec > timeout.tv_usec))) if ((now.tv_sec > timeout.tv_sec) ||
((now.tv_sec == timeout.tv_sec) && (now.tv_usec > timeout.tv_usec)))
break; break;
} }
#endif #endif
if (ftbytes != size) if (ftbytes != size) {
{ /* this is just a warning, there might have been timeout when detecting PRESTO,
/* this is just a warning, there might have been timeout when detecting PRESTO, which is not fatal */ *which is not fatal */
LOG_WARNING("couldn't read the requested number of bytes from PRESTO (%u < %u)", LOG_WARNING("couldn't read the requested number of bytes from PRESTO (%u < %u)",
(unsigned)ftbytes, (unsigned)size); (unsigned)ftbytes, (unsigned)size);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -186,39 +183,39 @@ static int presto_open_ftd2xx(char *req_serial)
#if IS_WIN32 == 0 #if IS_WIN32 == 0
/* Add non-standard Vid/Pid to the linux driver */ /* Add non-standard Vid/Pid to the linux driver */
if ((presto->status = FT_SetVIDPID(PRESTO_VID, PRESTO_PID)) != FT_OK) presto->status = FT_SetVIDPID(PRESTO_VID, PRESTO_PID);
{ if (presto->status != FT_OK) {
LOG_ERROR("couldn't add PRESTO VID/PID"); LOG_ERROR("couldn't add PRESTO VID/PID");
exit(-1); exit(-1);
} }
#endif #endif
if ((presto->status = FT_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY)) != FT_OK) presto->status = FT_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY);
{ if (presto->status != FT_OK) {
LOG_ERROR("FT_ListDevices failed: %s", ftd2xx_status_string(presto->status)); LOG_ERROR("FT_ListDevices failed: %s", ftd2xx_status_string(presto->status));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
LOG_DEBUG("FTDI devices available: %" PRIu32, (uint32_t)numdevs); LOG_DEBUG("FTDI devices available: %" PRIu32, (uint32_t)numdevs);
for (i = 0; i < numdevs; i++) for (i = 0; i < numdevs; i++) {
{ presto->status = FT_Open(i, &(presto->handle));
if ((presto->status = FT_Open(i, &(presto->handle))) != FT_OK) if (presto->status != FT_OK) {
{ /* this is not fatal, the device may be legitimately open by other process,
/* this is not fatal, the device may be legitimately open by other process, hence debug message only */ *hence debug message only */
LOG_DEBUG("FT_Open failed: %s", ftd2xx_status_string(presto->status)); LOG_DEBUG("FT_Open failed: %s", ftd2xx_status_string(presto->status));
continue; continue;
} }
LOG_DEBUG("FTDI device %i open", (int)i); LOG_DEBUG("FTDI device %i open", (int)i);
if ((presto->status = FT_GetDeviceInfo(presto->handle, &device, &vidpid, presto->status = FT_GetDeviceInfo(presto->handle, &device,
presto->serial, devname, NULL)) == FT_OK) &vidpid, presto->serial, devname, NULL);
{ if (presto->status == FT_OK) {
if (vidpid == PRESTO_VID_PID if (vidpid == PRESTO_VID_PID && (req_serial == NULL ||
&& (req_serial == NULL || !strcmp(presto->serial, req_serial))) !strcmp(presto->serial, req_serial)))
break; break;
} } else
else LOG_DEBUG("FT_GetDeviceInfo failed: %s", ftd2xx_status_string(
LOG_DEBUG("FT_GetDeviceInfo failed: %s", ftd2xx_status_string(presto->status)); presto->status));
LOG_DEBUG("FTDI device %i does not match, closing", (int)i); LOG_DEBUG("FTDI device %i does not match, closing", (int)i);
FT_Close(presto->handle); FT_Close(presto->handle);
@ -228,72 +225,85 @@ static int presto_open_ftd2xx(char *req_serial)
if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE) if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE)
return ERROR_JTAG_DEVICE_ERROR; /* presto not open, return */ return ERROR_JTAG_DEVICE_ERROR; /* presto not open, return */
if ((presto->status = FT_SetLatencyTimer(presto->handle, 1)) != FT_OK) presto->status = FT_SetLatencyTimer(presto->handle, 1);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
presto->status = FT_SetTimeouts(presto->handle, 100, 0);
if ((presto->status = FT_SetTimeouts(presto->handle, 100, 0)) != FT_OK) if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
if ((presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX)) != FT_OK) presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
presto_data = 0xD0; presto_data = 0xD0;
if ((presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes)) != FT_OK) presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
/* delay between first write/read turnaround (after purge?) necessary under Linux for unknown reason, /* delay between first write/read turnaround (after purge?) necessary
probably a bug in library threading */ * under Linux for unknown reason,
* probably a bug in library threading */
usleep(100000); usleep(100000);
if ((presto->status = FT_Read(presto->handle, &presto_data, 1, &ftbytes)) != FT_OK) presto->status = FT_Read(presto->handle, &presto_data, 1, &ftbytes);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
if (ftbytes != 1) if (ftbytes != 1) {
{
LOG_DEBUG("PRESTO reset"); LOG_DEBUG("PRESTO reset");
if ((presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX)) != FT_OK) presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
if ((presto->status = FT_SetBitMode(presto->handle, 0x80, 1)) != FT_OK) presto->status = FT_SetBitMode(presto->handle, 0x80, 1);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
if ((presto->status = FT_SetBaudRate(presto->handle, 9600)) != FT_OK) presto->status = FT_SetBaudRate(presto->handle, 9600);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
presto_data = 0; presto_data = 0;
for (i = 0; i < 4 * 62; i++) for (i = 0; i < 4 * 62; i++) {
if ((presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes)) != FT_OK) presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
}
usleep(100000); usleep(100000);
if ((presto->status = FT_SetBitMode(presto->handle, 0x00, 0)) != FT_OK) presto->status = FT_SetBitMode(presto->handle, 0x00, 0);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
if ((presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX)) != FT_OK) presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
presto_data = 0xD0; presto_data = 0xD0;
if ((presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes)) != FT_OK) presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
/* delay between first write/read turnaround (after purge?) necessary under Linux for unknown reason, /* delay between first write/read turnaround (after purge?) necessary under Linux for unknown reason,
probably a bug in library threading */ probably a bug in library threading */
usleep(100000); usleep(100000);
if ((presto->status = FT_Read(presto->handle, &presto_data, 1, &ftbytes)) != FT_OK) presto->status = FT_Read(presto->handle, &presto_data, 1, &ftbytes);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
if (ftbytes != 1) if (ftbytes != 1) {
{
LOG_DEBUG("PRESTO not responding"); LOG_DEBUG("PRESTO not responding");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
} }
if ((presto->status = FT_SetTimeouts(presto->handle, 0, 0)) != FT_OK) presto->status = FT_SetTimeouts(presto->handle, 0, 0);
if (presto->status != FT_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
presto->status = FT_Write(presto->handle, &presto_init_seq,
sizeof(presto_init_seq), &ftbytes);
presto->status = FT_Write(presto->handle, &presto_init_seq, sizeof(presto_init_seq), &ftbytes);
if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq)) if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq))
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -308,46 +318,39 @@ static int presto_open_libftdi(char *req_serial)
LOG_DEBUG("searching for PRESTO using libftdi"); LOG_DEBUG("searching for PRESTO using libftdi");
/* initialize FTDI context structure */ /* initialize FTDI context structure */
if (ftdi_init(&presto->ftdic) < 0) if (ftdi_init(&presto->ftdic) < 0) {
{
LOG_ERROR("unable to init libftdi: %s", presto->ftdic.error_str); LOG_ERROR("unable to init libftdi: %s", presto->ftdic.error_str);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
/* context, vendor id, product id */ /* context, vendor id, product id */
if (ftdi_usb_open_desc(&presto->ftdic, PRESTO_VID, PRESTO_PID, NULL, req_serial) < 0) if (ftdi_usb_open_desc(&presto->ftdic, PRESTO_VID, PRESTO_PID, NULL, req_serial) < 0) {
{
LOG_ERROR("unable to open PRESTO: %s", presto->ftdic.error_str); LOG_ERROR("unable to open PRESTO: %s", presto->ftdic.error_str);
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
if (ftdi_usb_reset(&presto->ftdic) < 0) if (ftdi_usb_reset(&presto->ftdic) < 0) {
{
LOG_ERROR("unable to reset PRESTO device"); LOG_ERROR("unable to reset PRESTO device");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
if (ftdi_set_latency_timer(&presto->ftdic, 1) < 0) if (ftdi_set_latency_timer(&presto->ftdic, 1) < 0) {
{
LOG_ERROR("unable to set latency timer"); LOG_ERROR("unable to set latency timer");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
if (ftdi_usb_purge_buffers(&presto->ftdic) < 0) if (ftdi_usb_purge_buffers(&presto->ftdic) < 0) {
{
LOG_ERROR("unable to purge PRESTO buffers"); LOG_ERROR("unable to purge PRESTO buffers");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
presto_data = 0xD0; presto_data = 0xD0;
if (presto_write(&presto_data, 1) != ERROR_OK) if (presto_write(&presto_data, 1) != ERROR_OK) {
{
LOG_ERROR("error writing to PRESTO"); LOG_ERROR("error writing to PRESTO");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
if (presto_read(&presto_data, 1) != ERROR_OK) if (presto_read(&presto_data, 1) != ERROR_OK) {
{
LOG_DEBUG("no response from PRESTO, retrying"); LOG_DEBUG("no response from PRESTO, retrying");
if (ftdi_usb_purge_buffers(&presto->ftdic) < 0) if (ftdi_usb_purge_buffers(&presto->ftdic) < 0)
@ -357,15 +360,13 @@ static int presto_open_libftdi(char *req_serial)
if (presto_write(&presto_data, 1) != ERROR_OK) if (presto_write(&presto_data, 1) != ERROR_OK)
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
if (presto_read(&presto_data, 1) != ERROR_OK) if (presto_read(&presto_data, 1) != ERROR_OK) {
{
LOG_ERROR("no response from PRESTO, giving up"); LOG_ERROR("no response from PRESTO, giving up");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
} }
if (presto_write(presto_init_seq, sizeof(presto_init_seq)) != ERROR_OK) if (presto_write(presto_init_seq, sizeof(presto_init_seq)) != ERROR_OK) {
{
LOG_ERROR("error writing PRESTO init sequence"); LOG_ERROR("error writing PRESTO init sequence");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -414,27 +415,35 @@ static int presto_close(void)
if (presto->status != FT_OK) if (presto->status != FT_OK)
result = ERROR_JTAG_DEVICE_ERROR; result = ERROR_JTAG_DEVICE_ERROR;
presto->status = FT_Write(presto->handle, &presto_init_seq, sizeof(presto_init_seq), &ftbytes); presto->status = FT_Write(presto->handle,
&presto_init_seq,
sizeof(presto_init_seq),
&ftbytes);
if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq)) if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq))
result = ERROR_JTAG_DEVICE_ERROR; result = ERROR_JTAG_DEVICE_ERROR;
if ((presto->status = FT_SetLatencyTimer(presto->handle, 16)) != FT_OK) presto->status = FT_SetLatencyTimer(presto->handle, 16);
if (presto->status != FT_OK)
result = ERROR_JTAG_DEVICE_ERROR; result = ERROR_JTAG_DEVICE_ERROR;
if ((presto->status = FT_Close(presto->handle)) != FT_OK) presto->status = FT_Close(presto->handle);
if (presto->status != FT_OK)
result = ERROR_JTAG_DEVICE_ERROR; result = ERROR_JTAG_DEVICE_ERROR;
else else
presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE; presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE;
#elif BUILD_PRESTO_LIBFTDI == 1 #elif BUILD_PRESTO_LIBFTDI == 1
if ((presto->retval = ftdi_write_data(&presto->ftdic, presto_init_seq, sizeof(presto_init_seq))) != sizeof(presto_init_seq)) presto->retval = ftdi_write_data(&presto->ftdic, presto_init_seq, sizeof(presto_init_seq));
if (presto->retval != sizeof(presto_init_seq))
result = ERROR_JTAG_DEVICE_ERROR; result = ERROR_JTAG_DEVICE_ERROR;
if ((presto->retval = ftdi_set_latency_timer(&presto->ftdic, 16)) < 0) presto->retval = ftdi_set_latency_timer(&presto->ftdic, 16);
if (presto->retval < 0)
result = ERROR_JTAG_DEVICE_ERROR; result = ERROR_JTAG_DEVICE_ERROR;
if ((presto->retval = ftdi_usb_close(&presto->ftdic)) < 0) presto->retval = ftdi_usb_close(&presto->ftdic);
if (presto->retval < 0)
result = ERROR_JTAG_DEVICE_ERROR; result = ERROR_JTAG_DEVICE_ERROR;
else else
ftdi_deinit(&presto->ftdic); ftdi_deinit(&presto->ftdic);
@ -449,17 +458,15 @@ static int presto_flush(void)
return ERROR_OK; return ERROR_OK;
#if BUILD_PRESTO_FTD2XX == 1 #if BUILD_PRESTO_FTD2XX == 1
if (presto->status != FT_OK) if (presto->status != FT_OK) {
#elif BUILD_PRESTO_LIBFTDI == 1 #elif BUILD_PRESTO_LIBFTDI == 1
if (presto->retval < 0) if (presto->retval < 0) {
#endif #endif
{
LOG_DEBUG("error in previous communication, canceling I/O operation"); LOG_DEBUG("error in previous communication, canceling I/O operation");
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
if (presto_write(presto->buff_out, presto->buff_out_pos) != ERROR_OK) if (presto_write(presto->buff_out, presto->buff_out_pos) != ERROR_OK) {
{
presto->buff_out_pos = 0; presto->buff_out_pos = 0;
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -473,8 +480,7 @@ static int presto_flush(void)
presto->buff_in_pos = 0; presto->buff_in_pos = 0;
presto->buff_in_len = 0; presto->buff_in_len = 0;
if (presto_read(presto->buff_in, presto->buff_in_exp) != ERROR_OK) if (presto_read(presto->buff_in, presto->buff_in_exp) != ERROR_OK) {
{
presto->buff_in_exp = 0; presto->buff_in_exp = 0;
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
} }
@ -488,21 +494,21 @@ static int presto_flush(void)
static int presto_sendbyte(int data) static int presto_sendbyte(int data)
{ {
if (data == EOF) return presto_flush(); if (data == EOF)
return presto_flush();
if (presto->buff_out_pos < BUFFER_SIZE) if (presto->buff_out_pos < BUFFER_SIZE) {
{
presto->buff_out[presto->buff_out_pos++] = (uint8_t)data; presto->buff_out[presto->buff_out_pos++] = (uint8_t)data;
if (((data & 0xC0) == 0x40) || ((data & 0xD0)== 0xD0)) if (((data & 0xC0) == 0x40) || ((data & 0xD0) == 0xD0))
presto->buff_in_exp++; presto->buff_in_exp++;
} } else
else
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
#if BUILD_PRESTO_FTD2XX == 1 #if BUILD_PRESTO_FTD2XX == 1
if (presto->buff_out_pos >= BUFFER_SIZE) if (presto->buff_out_pos >= BUFFER_SIZE)
#elif BUILD_PRESTO_LIBFTDI == 1 #elif BUILD_PRESTO_LIBFTDI == 1
/* libftdi does not do background read, be sure that USB IN buffer does not overflow (128 bytes only!) */ /* libftdi does not do background read, be sure that USB IN buffer does not overflow (128
*bytes only!) */
if (presto->buff_out_pos >= BUFFER_SIZE || presto->buff_in_exp == 128) if (presto->buff_out_pos >= BUFFER_SIZE || presto->buff_in_exp == 128)
#endif #endif
return presto_flush(); return presto_flush();
@ -536,8 +542,7 @@ static int presto_tdi_flush(void)
if (presto->jtag_tdi_count == 0) if (presto->jtag_tdi_count == 0)
return 0; return 0;
if (presto->jtag_tck == 0) if (presto->jtag_tck == 0) {
{
LOG_ERROR("BUG: unexpected TAP condition, TCK low"); LOG_ERROR("BUG: unexpected TAP condition, TCK low");
return -1; return -1;
} }
@ -552,8 +557,7 @@ static int presto_tdi_flush(void)
static int presto_tck_idle(void) static int presto_tck_idle(void)
{ {
if (presto->jtag_tck == 1) if (presto->jtag_tck == 1) {
{
presto_sendbyte(0xCA); presto_sendbyte(0xCA);
presto->jtag_tck = 0; presto->jtag_tck = 0;
} }
@ -569,11 +573,8 @@ static int presto_bitq_out(int tms, int tdi, int tdo_req)
unsigned char cmd; unsigned char cmd;
if (presto->jtag_tck == 0) if (presto->jtag_tck == 0)
{
presto_sendbyte(0xA4); /* LED idicator - JTAG active */ presto_sendbyte(0xA4); /* LED idicator - JTAG active */
} else if (presto->jtag_speed == 0 && !tdo_req && tms == presto->jtag_tms) {
else if (presto->jtag_speed == 0 && !tdo_req && tms == presto->jtag_tms)
{
presto->jtag_tdi_data |= (tdi != 0) << presto->jtag_tdi_count; presto->jtag_tdi_data |= (tdi != 0) << presto->jtag_tdi_count;
if (++presto->jtag_tdi_count == 4) if (++presto->jtag_tdi_count == 4)
@ -587,8 +588,7 @@ static int presto_bitq_out(int tms, int tdi, int tdo_req)
cmd = tdi ? 0xCB : 0xCA; cmd = tdi ? 0xCB : 0xCA;
presto_sendbyte(cmd); presto_sendbyte(cmd);
if (tms != presto->jtag_tms) if (tms != presto->jtag_tms) {
{
presto_sendbyte((tms ? 0xEC : 0xE8) | (presto->jtag_rst ? 0x02 : 0)); presto_sendbyte((tms ? 0xEC : 0xE8) | (presto->jtag_rst ? 0x02 : 0));
presto->jtag_tms = tms; presto->jtag_tms = tms;
} }
@ -630,7 +630,8 @@ static int presto_bitq_in(void)
{ {
if (presto->buff_in_pos >= presto->buff_in_len) if (presto->buff_in_pos >= presto->buff_in_len)
return -1; return -1;
if (presto->buff_in[presto->buff_in_pos++]&0x08) return 1; if (presto->buff_in[presto->buff_in_pos++]&0x08)
return 1;
return 0; return 0;
} }
@ -641,8 +642,7 @@ static int presto_bitq_sleep(unsigned long us)
presto_tdi_flush(); presto_tdi_flush();
presto_tck_idle(); presto_tck_idle();
if (us > 100000) if (us > 100000) {
{
presto_bitq_flush(); presto_bitq_flush();
jtag_sleep(us); jtag_sleep(us);
return 0; return 0;
@ -677,34 +677,36 @@ static struct bitq_interface presto_bitq = {
.reset = &presto_bitq_reset, .reset = &presto_bitq_reset,
.in_rdy = &presto_bitq_in_rdy, .in_rdy = &presto_bitq_in_rdy,
.in = &presto_bitq_in, .in = &presto_bitq_in,
}; };
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int presto_adapter_khz(int khz, int *jtag_speed) static int presto_adapter_khz(int khz, int *jtag_speed)
{ {
if (khz < 0) if (khz < 0) {
{
*jtag_speed = 0; *jtag_speed = 0;
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
if (khz >= 3000) *jtag_speed = 0; if (khz >= 3000)
else *jtag_speed = (1000 + khz-1)/khz; *jtag_speed = 0;
else
*jtag_speed = (1000 + khz-1)/khz;
return 0; return 0;
} }
static int presto_jtag_speed_div(int speed, int *khz) static int presto_jtag_speed_div(int speed, int *khz)
{ {
if ((speed < 0) || (speed > 1000)) if ((speed < 0) || (speed > 1000)) {
{
*khz = 0; *khz = 0;
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
if (speed == 0) *khz = 3000; if (speed == 0)
else *khz = 1000/speed; *khz = 3000;
else
*khz = 1000/speed;
return 0; return 0;
} }
@ -714,9 +716,7 @@ static int presto_jtag_speed(int speed)
int khz; int khz;
if (presto_jtag_speed_div(speed, &khz)) if (presto_jtag_speed_div(speed, &khz))
{
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
presto->jtag_speed = speed; presto->jtag_speed = speed;
@ -732,16 +732,12 @@ static char *presto_serial;
COMMAND_HANDLER(presto_handle_serial_command) COMMAND_HANDLER(presto_handle_serial_command)
{ {
if (CMD_ARGC == 1) if (CMD_ARGC == 1) {
{
if (presto_serial) if (presto_serial)
free(presto_serial); free(presto_serial);
presto_serial = strdup(CMD_ARGV[0]); presto_serial = strdup(CMD_ARGV[0]);
} } else
else
{
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK; return ERROR_OK;
} }
@ -759,8 +755,7 @@ static const struct command_registration presto_command_handlers[] = {
static int presto_jtag_init(void) static int presto_jtag_init(void)
{ {
if (presto_open(presto_serial) != ERROR_OK) if (presto_open(presto_serial) != ERROR_OK) {
{
presto_close(); presto_close();
if (presto_serial != NULL) if (presto_serial != NULL)
LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial); LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial);
@ -780,8 +775,7 @@ static int presto_jtag_quit(void)
presto_close(); presto_close();
LOG_INFO("PRESTO closed"); LOG_INFO("PRESTO closed");
if (presto_serial) if (presto_serial) {
{
free(presto_serial); free(presto_serial);
presto_serial = NULL; presto_serial = NULL;
} }

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -27,26 +28,29 @@
#include <jtag/interface.h> #include <jtag/interface.h>
#include "bitbang.h" #include "bitbang.h"
// from unix man page and sys/un.h: /* from unix man page and sys/un.h: */
#define UNIX_PATH_MAX 108 #define UNIX_PATH_MAX 108
// arbitrary limit on host name length: /* arbitrary limit on host name length: */
#define REMOTE_BITBANG_HOST_MAX 255 #define REMOTE_BITBANG_HOST_MAX 255
#define REMOTE_BITBANG_RAISE_ERROR(expr ...) \ #define REMOTE_BITBANG_RAISE_ERROR(expr ...) \
LOG_ERROR(expr); LOG_ERROR("Terminating openocd."); exit(-1); do { \
LOG_ERROR(expr); \
LOG_ERROR("Terminating openocd."); \
exit(-1); \
while (0)
static char remote_bitbang_host[REMOTE_BITBANG_HOST_MAX] = "openocd"; static char remote_bitbang_host[REMOTE_BITBANG_HOST_MAX] = "openocd";
static uint16_t remote_bitbang_port = 0; static uint16_t remote_bitbang_port;
FILE* remote_bitbang_in; FILE *remote_bitbang_in;
FILE* remote_bitbang_out; FILE *remote_bitbang_out;
static void remote_bitbang_putc(int c) static void remote_bitbang_putc(int c)
{ {
if (EOF == fputc(c, remote_bitbang_out)) { if (EOF == fputc(c, remote_bitbang_out))
REMOTE_BITBANG_RAISE_ERROR("remote_bitbang_putc: %s", strerror(errno)); REMOTE_BITBANG_RAISE_ERROR("remote_bitbang_putc: %s", strerror(errno));
}
} }
static int remote_bitbang_quit(void) static int remote_bitbang_quit(void)
@ -61,8 +65,8 @@ static int remote_bitbang_quit(void)
return ERROR_FAIL; return ERROR_FAIL;
} }
// We only need to close one of the FILE*s, because they both use the same /* We only need to close one of the FILE*s, because they both use the same */
// underlying file descriptor. /* underlying file descriptor. */
if (EOF == fclose(remote_bitbang_out)) { if (EOF == fclose(remote_bitbang_out)) {
LOG_ERROR("fclose: %s", strerror(errno)); LOG_ERROR("fclose: %s", strerror(errno));
return ERROR_FAIL; return ERROR_FAIL;
@ -72,7 +76,7 @@ static int remote_bitbang_quit(void)
return ERROR_OK; return ERROR_OK;
} }
// Get the next read response. /* Get the next read response. */
static int remote_bitbang_rread(void) static int remote_bitbang_rread(void)
{ {
if (EOF == fflush(remote_bitbang_out)) { if (EOF == fflush(remote_bitbang_out)) {
@ -82,8 +86,10 @@ static int remote_bitbang_rread(void)
int c = fgetc(remote_bitbang_in); int c = fgetc(remote_bitbang_in);
switch (c) { switch (c) {
case '0': return 0; case '0':
case '1': return 1; return 0;
case '1':
return 1;
default: default:
remote_bitbang_quit(); remote_bitbang_quit();
REMOTE_BITBANG_RAISE_ERROR( REMOTE_BITBANG_RAISE_ERROR(
@ -136,14 +142,22 @@ static int remote_bitbang_init_tcp(void)
return ERROR_FAIL; return ERROR_FAIL;
} }
struct hostent* hent = gethostbyname(remote_bitbang_host); struct hostent *hent = gethostbyname(remote_bitbang_host);
if (hent == NULL) { if (hent == NULL) {
char* errorstr = "???"; char *errorstr = "???";
switch (h_errno) { switch (h_errno) {
case HOST_NOT_FOUND: errorstr = "host not found"; break; case HOST_NOT_FOUND:
case NO_ADDRESS: errorstr = "no address"; break; errorstr = "host not found";
case NO_RECOVERY: errorstr = "no recovery"; break; break;
case TRY_AGAIN: errorstr = "try again"; break; case NO_ADDRESS:
errorstr = "no address";
break;
case NO_RECOVERY:
errorstr = "no recovery";
break;
case TRY_AGAIN:
errorstr = "try again";
break;
} }
LOG_ERROR("gethostbyname: %s", errorstr); LOG_ERROR("gethostbyname: %s", errorstr);
return ERROR_FAIL; return ERROR_FAIL;
@ -152,8 +166,8 @@ static int remote_bitbang_init_tcp(void)
struct sockaddr_in addr; struct sockaddr_in addr;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(remote_bitbang_port); addr.sin_port = htons(remote_bitbang_port);
addr.sin_addr = *(struct in_addr*)hent->h_addr; addr.sin_addr = *(struct in_addr *)hent->h_addr;
if (connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) < 0) { if (connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
LOG_ERROR("connect: %s", strerror(errno)); LOG_ERROR("connect: %s", strerror(errno));
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -188,7 +202,7 @@ static int remote_bitbang_init_unix(void)
strncpy(addr.sun_path, remote_bitbang_host, UNIX_PATH_MAX); strncpy(addr.sun_path, remote_bitbang_host, UNIX_PATH_MAX);
addr.sun_path[UNIX_PATH_MAX-1] = '\0'; addr.sun_path[UNIX_PATH_MAX-1] = '\0';
if (connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0) { if (connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
LOG_ERROR("connect: %s", strerror(errno)); LOG_ERROR("connect: %s", strerror(errno));
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -214,21 +228,20 @@ static int remote_bitbang_init(void)
bitbang_interface = &remote_bitbang_bitbang; bitbang_interface = &remote_bitbang_bitbang;
LOG_INFO("Initializing remote_bitbang driver"); LOG_INFO("Initializing remote_bitbang driver");
if (remote_bitbang_port == 0) { if (remote_bitbang_port == 0)
return remote_bitbang_init_unix(); return remote_bitbang_init_unix();
}
return remote_bitbang_init_tcp(); return remote_bitbang_init_tcp();
} }
static int remote_bitbang_khz(int khz, int* jtag_speed) static int remote_bitbang_khz(int khz, int *jtag_speed)
{ {
*jtag_speed = 0; *jtag_speed = 0;
return ERROR_OK; return ERROR_OK;
} }
static int remote_bitbang_speed_div(int speed, int* khz) static int remote_bitbang_speed_div(int speed, int *khz)
{ {
// I don't think this really matters any. /* I don't think this really matters any. */
*khz = 1; *khz = 1;
return ERROR_OK; return ERROR_OK;
} }

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
/* A command position with the high nybble of 0x0 is reserved for an error condition. If executed, it stops the DTC and raises the ERROR flag */ /* A command position with the high nybble of 0x0 is reserved for an error condition.
* If executed, it stops the DTC and raises the ERROR flag */
#define DTC_CMD_SHIFT_TMS_BYTES(bytes) ((0x1 << 4) | ((bytes) - 1)) #define DTC_CMD_SHIFT_TMS_BYTES(bytes) ((0x1 << 4) | ((bytes) - 1))
/* Shift 1-16 bytes out TMS. TDI is 0. */ /* Shift 1-16 bytes out TMS. TDI is 0. */
@ -46,10 +47,15 @@
) | (\ ) | (\
(tdo) ? (1 << 3) : 0 \ (tdo) ? (1 << 3) : 0 \
)) ))
/* Single bit shift. */ /* Single bit shift.
/* tms and tdi are the levels shifted out on TMS and TDI, respectively. */ * tms and tdi are the levels shifted out on TMS and TDI, respectively.
/* tdo indicates whether a byte will be returned in the reply buffer with its least significant bit set to reflect TDO */ * tdo indicates whether a byte will be returned in the reply buffer with its
/* Care should be taken when tdo is zero, as the underlying code actually does put that byte in the reply buffer. Setting tdo to zero just moves the pointer back. The result is that if this command is executed when the reply buffer is already full, a byte will be written erroneously to memory not belonging to the reply buffer. This could be worked around at the expense of DTC code space and speed. */ * least significant bit set to reflect TDO
* Care should be taken when tdo is zero, as the underlying code actually does put
* that byte in the reply buffer. Setting tdo to zero just moves the pointer back.
* The result is that if this command is executed when the reply buffer is already full,
* a byte will be written erroneously to memory not belonging to the reply buffer.
* This could be worked around at the expense of DTC code space and speed. */
#define DTC_CMD_SHIFT_TMS_BITS(bits) ((0x9 << 4) | ((bits) - 1)) #define DTC_CMD_SHIFT_TMS_BITS(bits) ((0x9 << 4) | ((bits) - 1))
/* Shift 1-8 bits out TMS. */ /* Shift 1-8 bits out TMS. */
@ -60,7 +66,8 @@
/* Bits to be shifted out are left justified in the following byte. */ /* Bits to be shifted out are left justified in the following byte. */
/* Bits shifted in are right justified in the byte placed in the reply buffer. */ /* Bits shifted in are right justified in the byte placed in the reply buffer. */
#define DTC_CMD_STOP (0xf << 4) #define DTC_CMD_STOP (0xf << 4)
/* Stop processing the command buffer and wait for the next one. */ /* Stop processing the command buffer and wait for the next one. */
/* A shared status byte is updated with bit 0 set when this has happened, and it is cleared when a new command buffer becomes ready. The host can poll that byte to see when it is safe to read a reply. */ /* A shared status byte is updated with bit 0 set when this has happened,
* and it is cleared when a new command buffer becomes ready.
* The host can poll that byte to see when it is safe to read a reply. */

View File

@ -95,7 +95,7 @@ const struct rlink_speed_table rlink_speed_table[] = {{
dtc_8, sizeof(dtc_8), (ST7_FOSC * 2) / (1000 * 8), 8 dtc_8, sizeof(dtc_8), (ST7_FOSC * 2) / (1000 * 8), 8
}, { }, {
dtc_2, sizeof(dtc_2), (ST7_FOSC * 2) / (1000 * 2), 2 dtc_2, sizeof(dtc_2), (ST7_FOSC * 2) / (1000 * 2), 2
}}; } };
const size_t rlink_speed_table_size = ARRAY_SIZE(rlink_speed_table); const size_t rlink_speed_table_size = ARRAY_SIZE(rlink_speed_table);

View File

@ -1,7 +1,29 @@
/***************************************************************************
* Copyright (C) 2011 by Mathias Kuester *
* Mathias Kuester <kesmtp@freenet.de> *
* *
* This code is based on https://github.com/texane/stlink *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _STLINK_USB_H_ #ifndef _STLINK_USB_H_
#define _STLINK_USB_H_ #define _STLINK_USB_H_
/** */ /** */
void *stlink_open_usb(struct stlink_interface_param_s *param); void *stlink_open_usb(struct stlink_interface_param_s *param);
#endif #endif /* _STLINK_USB_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -89,7 +89,7 @@
#if (BUILD_USB_BLASTER_FTD2XX == 1 && BUILD_USB_BLASTER_LIBFTDI == 1) #if (BUILD_USB_BLASTER_FTD2XX == 1 && BUILD_USB_BLASTER_LIBFTDI == 1)
#error "BUILD_USB_BLASTER_FTD2XX && BUILD_USB_BLASTER_LIBFTDI " #error "BUILD_USB_BLASTER_FTD2XX && BUILD_USB_BLASTER_LIBFTDI "
"are mutually exclusive" "are mutually exclusive"
#elif (BUILD_USB_BLASTER_FTD2XX != 1 && BUILD_USB_BLASTER_LIBFTDI != 1) #elif (BUILD_USB_BLASTER_FTD2XX != 1 && BUILD_USB_BLASTER_LIBFTDI != 1)
#error "BUILD_USB_BLASTER_FTD2XX || BUILD_USB_BLASTER_LIBFTDI must be chosen" #error "BUILD_USB_BLASTER_FTD2XX || BUILD_USB_BLASTER_LIBFTDI must be chosen"
#endif #endif
@ -112,9 +112,9 @@ static uint16_t usb_blaster_pid = 0x6001; /* USB-Blaster */
/* last output byte in simple bit banging (legacy) mode */ /* last output byte in simple bit banging (legacy) mode */
static uint8_t out_value; static uint8_t out_value;
/* global output buffer for bit banging */ /* global output buffer for bit banging */
#define BUF_LEN 64 //Size of EP1 #define BUF_LEN 64 /* Size of EP1 */
static uint8_t out_buffer[BUF_LEN]; static uint8_t out_buffer[BUF_LEN];
static uint16_t out_count = 0; static uint16_t out_count;
#if BUILD_USB_BLASTER_FTD2XX == 1 #if BUILD_USB_BLASTER_FTD2XX == 1
static FT_HANDLE ftdih; static FT_HANDLE ftdih;
@ -133,8 +133,7 @@ static int usb_blaster_buf_write(
LOG_DEBUG("usb_blaster_buf_write %02X (%d)", buf[0], size); LOG_DEBUG("usb_blaster_buf_write %02X (%d)", buf[0], size);
#endif #endif
status = FT_Write(ftdih, buf, size, &dw_bytes_written); status = FT_Write(ftdih, buf, size, &dw_bytes_written);
if (status != FT_OK) if (status != FT_OK) {
{
*bytes_written = dw_bytes_written; *bytes_written = dw_bytes_written;
LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(status)); LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -147,8 +146,7 @@ static int usb_blaster_buf_write(
LOG_DEBUG("usb_blaster_buf_write %02X (%d)", buf[0], size); LOG_DEBUG("usb_blaster_buf_write %02X (%d)", buf[0], size);
#endif #endif
retval = ftdi_write_data(&ftdic, buf, size); retval = ftdi_write_data(&ftdic, buf, size);
if (retval < 0) if (retval < 0) {
{
*bytes_written = 0; *bytes_written = 0;
LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&ftdic)); LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -158,16 +156,14 @@ static int usb_blaster_buf_write(
#endif #endif
} }
static int static int usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
{ {
#if BUILD_USB_BLASTER_FTD2XX == 1 #if BUILD_USB_BLASTER_FTD2XX == 1
DWORD dw_bytes_read; DWORD dw_bytes_read;
FT_STATUS status; FT_STATUS status;
status = FT_Read(ftdih, buf, size, &dw_bytes_read); status = FT_Read(ftdih, buf, size, &dw_bytes_read);
if (status != FT_OK) if (status != FT_OK) {
{
*bytes_read = dw_bytes_read; *bytes_read = dw_bytes_read;
LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(status)); LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
@ -183,12 +179,10 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
int timeout = 100; int timeout = 100;
*bytes_read = 0; *bytes_read = 0;
while ((*bytes_read < size) && timeout--) while ((*bytes_read < size) && timeout--) {
{
retval = ftdi_read_data(&ftdic, buf + *bytes_read, retval = ftdi_read_data(&ftdic, buf + *bytes_read,
size - *bytes_read); size - *bytes_read);
if (retval < 0) if (retval < 0) {
{
*bytes_read = 0; *bytes_read = 0;
LOG_ERROR("ftdi_read_data: %s", LOG_ERROR("ftdi_read_data: %s",
ftdi_get_error_string(&ftdic)); ftdi_get_error_string(&ftdic));
@ -249,13 +243,13 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
#define READ_TDO (1 << 0) #define READ_TDO (1 << 0)
static void usb_blaster_write_databuffer(uint8_t* buf, uint16_t len) static void usb_blaster_write_databuffer(uint8_t *buf, uint16_t len)
{ {
uint32_t bytes_written; uint32_t bytes_written;
usb_blaster_buf_write(buf, len, &bytes_written); usb_blaster_buf_write(buf, len, &bytes_written);
out_count = 0; out_count = 0;
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("---- WROTE %d",bytes_written); LOG_DEBUG("---- WROTE %d", bytes_written);
#endif #endif
} }
@ -263,7 +257,7 @@ static void usb_blaster_addtowritebuffer(uint8_t value, bool forcewrite)
{ {
out_buffer[out_count] = value; out_buffer[out_count] = value;
out_count += 1; out_count += 1;
if(out_count == BUF_LEN || forcewrite) if (out_count == BUF_LEN || forcewrite)
usb_blaster_write_databuffer(out_buffer, out_count); usb_blaster_write_databuffer(out_buffer, out_count);
} }
@ -273,7 +267,7 @@ static int usb_blaster_read_data(void)
uint8_t buf[1]; uint8_t buf[1];
uint32_t bytes_read; uint32_t bytes_read;
if(out_count > 0) if (out_count > 0)
usb_blaster_write_databuffer(out_buffer, out_count); usb_blaster_write_databuffer(out_buffer, out_count);
out_value |= READ; out_value |= READ;
@ -313,12 +307,12 @@ static int usb_blaster_speed(int speed)
/* TODO: libftdi's ftdi_set_baudrate chokes on high rates, use lowlevel /* TODO: libftdi's ftdi_set_baudrate chokes on high rates, use lowlevel
* usb function instead! And additionally allow user to throttle. * usb function instead! And additionally allow user to throttle.
*/ */
if (ftdi_set_baudrate(&ftdic, 3000000 / 4) < 0) if (ftdi_set_baudrate(&ftdic, 3000000 / 4) < 0) {
{
LOG_ERROR("Can't set baud rate to max: %s", LOG_ERROR("Can't set baud rate to max: %s",
ftdi_get_error_string(&ftdic)); ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR; return ERROR_JTAG_DEVICE_ERROR;
}; }
;
#endif #endif
return ERROR_OK; return ERROR_OK;
@ -333,7 +327,7 @@ static void usb_blaster_reset(int trst, int srst)
static void usb_blaster_blink(int state) static void usb_blaster_blink(int state)
{ {
out_value = 0x00; out_value = 0x00;
if(state) if (state)
out_value |= LED; out_value |= LED;
usb_blaster_addtowritebuffer(out_value, true); usb_blaster_addtowritebuffer(out_value, true);
@ -362,8 +356,7 @@ static int usb_blaster_init(void)
#if BUILD_USB_BLASTER_FTD2XX == 1 #if BUILD_USB_BLASTER_FTD2XX == 1
/* Open by device description */ /* Open by device description */
if (usb_blaster_device_desc == NULL) if (usb_blaster_device_desc == NULL) {
{
LOG_WARNING("no usb_blaster device description specified, " LOG_WARNING("no usb_blaster device description specified, "
"using default 'USB-Blaster'"); "using default 'USB-Blaster'");
usb_blaster_device_desc = "USB-Blaster"; usb_blaster_device_desc = "USB-Blaster";
@ -372,8 +365,7 @@ static int usb_blaster_init(void)
#if IS_WIN32 == 0 #if IS_WIN32 == 0
/* Add non-standard Vid/Pid to the linux driver */ /* Add non-standard Vid/Pid to the linux driver */
status = FT_SetVIDPID(usb_blaster_vid, usb_blaster_pid); status = FT_SetVIDPID(usb_blaster_vid, usb_blaster_pid);
if (status != FT_OK) if (status != FT_OK) {
{
LOG_WARNING("couldn't add %4.4x:%4.4x", LOG_WARNING("couldn't add %4.4x:%4.4x",
usb_blaster_vid, usb_blaster_pid); usb_blaster_vid, usb_blaster_pid);
} }
@ -381,16 +373,14 @@ static int usb_blaster_init(void)
status = FT_OpenEx(usb_blaster_device_desc, FT_OPEN_BY_DESCRIPTION, status = FT_OpenEx(usb_blaster_device_desc, FT_OPEN_BY_DESCRIPTION,
&ftdih); &ftdih);
if (status != FT_OK) if (status != FT_OK) {
{
DWORD num_devices; DWORD num_devices;
LOG_ERROR("unable to open ftdi device: %s", LOG_ERROR("unable to open ftdi device: %s",
ftd2xx_status_string(status)); ftd2xx_status_string(status));
status = FT_ListDevices(&num_devices, NULL, status = FT_ListDevices(&num_devices, NULL,
FT_LIST_NUMBER_ONLY); FT_LIST_NUMBER_ONLY);
if (status == FT_OK) if (status == FT_OK) {
{
char **desc_array = malloc(sizeof(char *) char **desc_array = malloc(sizeof(char *)
* (num_devices + 1)); * (num_devices + 1));
unsigned int i; unsigned int i;
@ -402,8 +392,7 @@ static int usb_blaster_init(void)
status = FT_ListDevices(desc_array, &num_devices, status = FT_ListDevices(desc_array, &num_devices,
FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION); FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION);
if (status == FT_OK) if (status == FT_OK) {
{
LOG_ERROR("ListDevices: %" PRIu32, (uint32_t)num_devices); LOG_ERROR("ListDevices: %" PRIu32, (uint32_t)num_devices);
for (i = 0; i < num_devices; i++) for (i = 0; i < num_devices; i++)
LOG_ERROR("%i: %s", i, desc_array[i]); LOG_ERROR("%i: %s", i, desc_array[i]);
@ -412,25 +401,20 @@ static int usb_blaster_init(void)
for (i = 0; i < num_devices; i++) for (i = 0; i < num_devices; i++)
free(desc_array[i]); free(desc_array[i]);
free(desc_array); free(desc_array);
} } else
else
{
printf("ListDevices: NONE\n"); printf("ListDevices: NONE\n");
}
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
status = FT_SetLatencyTimer(ftdih, 2); status = FT_SetLatencyTimer(ftdih, 2);
if (status != FT_OK) if (status != FT_OK) {
{
LOG_ERROR("unable to set latency timer: %s", LOG_ERROR("unable to set latency timer: %s",
ftd2xx_status_string(status)); ftd2xx_status_string(status));
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
status = FT_GetLatencyTimer(ftdih, &latency_timer); status = FT_GetLatencyTimer(ftdih, &latency_timer);
if (status != FT_OK) if (status != FT_OK) {
{
LOG_ERROR("unable to get latency timer: %s", LOG_ERROR("unable to get latency timer: %s",
ftd2xx_status_string(status)); ftd2xx_status_string(status));
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
@ -438,8 +422,7 @@ static int usb_blaster_init(void)
LOG_DEBUG("current latency timer: %i", latency_timer); LOG_DEBUG("current latency timer: %i", latency_timer);
status = FT_SetBitMode(ftdih, 0x00, 0); status = FT_SetBitMode(ftdih, 0x00, 0);
if (status != FT_OK) if (status != FT_OK) {
{
LOG_ERROR("unable to disable bit i/o mode: %s", LOG_ERROR("unable to disable bit i/o mode: %s",
ftd2xx_status_string(status)); ftd2xx_status_string(status));
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
@ -449,26 +432,22 @@ static int usb_blaster_init(void)
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
/* context, vendor id, product id */ /* context, vendor id, product id */
if (ftdi_usb_open(&ftdic, usb_blaster_vid, usb_blaster_pid) < 0) if (ftdi_usb_open(&ftdic, usb_blaster_vid, usb_blaster_pid) < 0) {
{
LOG_ERROR("unable to open ftdi device: %s", ftdic.error_str); LOG_ERROR("unable to open ftdi device: %s", ftdic.error_str);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
if (ftdi_usb_reset(&ftdic) < 0) if (ftdi_usb_reset(&ftdic) < 0) {
{
LOG_ERROR("unable to reset ftdi device"); LOG_ERROR("unable to reset ftdi device");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
if (ftdi_set_latency_timer(&ftdic, 2) < 0) if (ftdi_set_latency_timer(&ftdic, 2) < 0) {
{
LOG_ERROR("unable to set latency timer"); LOG_ERROR("unable to set latency timer");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
if (ftdi_get_latency_timer(&ftdic, &latency_timer) < 0) if (ftdi_get_latency_timer(&ftdic, &latency_timer) < 0) {
{
LOG_ERROR("unable to get latency timer"); LOG_ERROR("unable to get latency timer");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -481,14 +460,13 @@ static int usb_blaster_init(void)
#if 0 #if 0
#if BUILD_USB_BLASTER_FTD2XX == 1 #if BUILD_USB_BLASTER_FTD2XX == 1
if ((status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK) status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX);
{ if (status != FT_OK) {
LOG_ERROR("error purging ftd2xx device: %i", status); LOG_ERROR("error purging ftd2xx device: %i", status);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
#elif BUILD_USB_BLASTER_LIBFTDI == 1 #elif BUILD_USB_BLASTER_LIBFTDI == 1
if (ftdi_usb_purge_buffers(&ftdic) < 0) if (ftdi_usb_purge_buffers(&ftdic) < 0) {
{
LOG_ERROR("ftdi_purge_buffers: %s", ftdic.error_str); LOG_ERROR("ftdi_purge_buffers: %s", ftdic.error_str);
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -500,7 +478,7 @@ static int usb_blaster_init(void)
static int usb_blaster_quit(void) static int usb_blaster_quit(void)
{ {
if(out_count > 0) if (out_count > 0)
usb_blaster_write_databuffer(out_buffer, out_count); usb_blaster_write_databuffer(out_buffer, out_count);
#if BUILD_USB_BLASTER_FTD2XX == 1 #if BUILD_USB_BLASTER_FTD2XX == 1
@ -528,18 +506,15 @@ COMMAND_HANDLER(usb_blaster_handle_device_desc_command)
COMMAND_HANDLER(usb_blaster_handle_vid_pid_command) COMMAND_HANDLER(usb_blaster_handle_vid_pid_command)
{ {
if (CMD_ARGC > 2) if (CMD_ARGC > 2) {
{
LOG_WARNING("ignoring extra IDs in usb_blaster_vid_pid " LOG_WARNING("ignoring extra IDs in usb_blaster_vid_pid "
"(maximum is 1 pair)"); "(maximum is 1 pair)");
CMD_ARGC = 2; CMD_ARGC = 2;
} }
if (CMD_ARGC == 2) if (CMD_ARGC == 2) {
{
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], usb_blaster_vid); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], usb_blaster_vid);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], usb_blaster_pid); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], usb_blaster_pid);
} } else
else
LOG_WARNING("incomplete usb_blaster_vid_pid configuration"); LOG_WARNING("incomplete usb_blaster_vid_pid configuration");
return ERROR_OK; return ERROR_OK;
@ -547,9 +522,8 @@ COMMAND_HANDLER(usb_blaster_handle_vid_pid_command)
COMMAND_HANDLER(usb_blaster_handle_pin_command) COMMAND_HANDLER(usb_blaster_handle_pin_command)
{ {
if (CMD_ARGC == 2) if (CMD_ARGC == 2) {
{ const char *const pin_name = CMD_ARGV[0];
const char * const pin_name = CMD_ARGV[0];
uint8_t mask; uint8_t mask;
unsigned int state; unsigned int state;
@ -557,34 +531,26 @@ COMMAND_HANDLER(usb_blaster_handle_pin_command)
mask = NCE; mask = NCE;
else if (!strcmp(pin_name, "pin8")) else if (!strcmp(pin_name, "pin8"))
mask = NCS; mask = NCS;
else else {
{
LOG_ERROR("%s: pin name must be \"pin6\" or \"pin8\"", LOG_ERROR("%s: pin name must be \"pin6\" or \"pin8\"",
CMD_NAME); CMD_NAME);
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], state); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], state);
if (state == 0) if (state == 0) {
{
out_value &= ~mask; out_value &= ~mask;
usb_blaster_addtowritebuffer(out_value, true); usb_blaster_addtowritebuffer(out_value, true);
} } else if (state == 1) {
else if (state == 1)
{
out_value |= mask; out_value |= mask;
usb_blaster_addtowritebuffer(out_value, true); usb_blaster_addtowritebuffer(out_value, true);
} } else {
else
{
LOG_ERROR("%s: pin state must be 0 or 1", CMD_NAME); LOG_ERROR("%s: pin state must be 0 or 1", CMD_NAME);
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
return ERROR_OK; return ERROR_OK;
} } else {
else
{
LOG_ERROR("%s takes exactly two arguments", CMD_NAME); LOG_ERROR("%s takes exactly two arguments", CMD_NAME);
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }

View File

@ -26,14 +26,11 @@
static bool jtag_usb_match(struct usb_device *dev, static bool jtag_usb_match(struct usb_device *dev,
const uint16_t vids[], const uint16_t pids[]) const uint16_t vids[], const uint16_t pids[])
{ {
for (unsigned i = 0; vids[i] && pids[i]; i++) for (unsigned i = 0; vids[i] && pids[i]; i++) {
{
if (dev->descriptor.idVendor == vids[i] && if (dev->descriptor.idVendor == vids[i] &&
dev->descriptor.idProduct == pids[i]) dev->descriptor.idProduct == pids[i])
{
return true; return true;
} }
}
return false; return false;
} }
@ -44,10 +41,8 @@ int jtag_usb_open(const uint16_t vids[], const uint16_t pids[],
usb_find_devices(); usb_find_devices();
struct usb_bus *busses = usb_get_busses(); struct usb_bus *busses = usb_get_busses();
for (struct usb_bus *bus = busses; bus; bus = bus->next) for (struct usb_bus *bus = busses; bus; bus = bus->next) {
{ for (struct usb_device *dev = bus->devices; dev; dev = dev->next) {
for (struct usb_device *dev = bus->devices; dev; dev = dev->next)
{
if (!jtag_usb_match(dev, vids, pids)) if (!jtag_usb_match(dev, vids, pids))
continue; continue;

View File

@ -27,4 +27,4 @@
int jtag_usb_open(const uint16_t vids[], const uint16_t pids[], int jtag_usb_open(const uint16_t vids[], const uint16_t pids[],
struct usb_dev_handle **out); struct usb_dev_handle **out);
#endif // JTAG_USB_COMMON_H #endif /* JTAG_USB_COMMON_H */

View File

@ -38,7 +38,6 @@
#include <jtag/commands.h> #include <jtag/commands.h>
#include "usb_common.h" #include "usb_common.h"
#define VID 0x1781 #define VID 0x1781
#define PID 0x0c63 #define PID 0x0c63
@ -66,21 +65,20 @@ static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
#define WRITE_TMS 0x09 #define WRITE_TMS 0x09
#define WRITE_TMS_CHAIN 0x0A #define WRITE_TMS_CHAIN 0x0A
struct usbprog_jtag struct usbprog_jtag {
{ struct usb_dev_handle *usb_handle;
struct usb_dev_handle* usb_handle;
}; };
static struct usbprog_jtag * usbprog_jtag_handle; static struct usbprog_jtag *usbprog_jtag_handle;
static struct usbprog_jtag* usbprog_jtag_open(void); static struct usbprog_jtag *usbprog_jtag_open(void);
//static void usbprog_jtag_close(struct usbprog_jtag *usbprog_jtag); /* static void usbprog_jtag_close(struct usbprog_jtag *usbprog_jtag); */
static void usbprog_jtag_init(struct usbprog_jtag *usbprog_jtag); static void usbprog_jtag_init(struct usbprog_jtag *usbprog_jtag);
static unsigned char usbprog_jtag_message(struct usbprog_jtag *usbprog_jtag, char *msg, int msglen); static unsigned char usbprog_jtag_message(struct usbprog_jtag *usbprog_jtag, char *msg, int msglen);
static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char * buffer, int size); static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char *buffer, int size);
static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char * buffer, int size); static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char *buffer, int size);
static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char * buffer, int size); static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char *buffer, int size);
static void usbprog_jtag_write_tms(struct usbprog_jtag *usbprog_jtag, char tms_scan); static void usbprog_jtag_write_tms(struct usbprog_jtag *usbprog_jtag, char tms_scan);
static char tms_chain[64]; static char tms_chain[64];
@ -93,10 +91,10 @@ static void usbprog_write(int tck, int tms, int tdi);
static void usbprog_reset(int trst, int srst); static void usbprog_reset(int trst, int srst);
static void usbprog_jtag_set_direction(struct usbprog_jtag *usbprog_jtag, unsigned char direction); static void usbprog_jtag_set_direction(struct usbprog_jtag *usbprog_jtag, unsigned char direction);
static void usbprog_jtag_write_slice(struct usbprog_jtag *usbprog_jtag,unsigned char value); static void usbprog_jtag_write_slice(struct usbprog_jtag *usbprog_jtag, unsigned char value);
//static unsigned char usbprog_jtag_get_port(struct usbprog_jtag *usbprog_jtag); /* static unsigned char usbprog_jtag_get_port(struct usbprog_jtag *usbprog_jtag); */
static void usbprog_jtag_set_bit(struct usbprog_jtag *usbprog_jtag,int bit, int value); static void usbprog_jtag_set_bit(struct usbprog_jtag *usbprog_jtag, int bit, int value);
//static int usbprog_jtag_get_bit(struct usbprog_jtag *usbprog_jtag, int bit); /* static int usbprog_jtag_get_bit(struct usbprog_jtag *usbprog_jtag, int bit); */
static int usbprog_speed(int speed) static int usbprog_speed(int speed)
{ {
@ -110,23 +108,23 @@ static int usbprog_execute_queue(void)
enum scan_type type; enum scan_type type;
uint8_t *buffer; uint8_t *buffer;
while (cmd) while (cmd) {
{ switch (cmd->type) {
switch (cmd->type)
{
case JTAG_RESET: case JTAG_RESET:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); LOG_DEBUG("reset trst: %i srst %i",
cmd->cmd.reset->trst,
cmd->cmd.reset->srst);
#endif #endif
if (cmd->cmd.reset->trst == 1) if (cmd->cmd.reset->trst == 1)
{
tap_set_state(TAP_RESET); tap_set_state(TAP_RESET);
}
usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
break; break;
case JTAG_RUNTEST: case JTAG_RUNTEST:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); LOG_DEBUG("runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles,
cmd->cmd.runtest->end_state);
#endif #endif
usbprog_end_state(cmd->cmd.runtest->end_state); usbprog_end_state(cmd->cmd.runtest->end_state);
usbprog_runtest(cmd->cmd.runtest->num_cycles); usbprog_runtest(cmd->cmd.runtest->num_cycles);
@ -140,7 +138,8 @@ static int usbprog_execute_queue(void)
break; break;
case JTAG_PATHMOVE: case JTAG_PATHMOVE:
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, LOG_DEBUG("pathmove: %i states, end in %i",
cmd->cmd.pathmove->num_states,
cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
#endif #endif
usbprog_path_move(cmd->cmd.pathmove); usbprog_path_move(cmd->cmd.pathmove);
@ -180,8 +179,7 @@ static int usbprog_init(void)
usbprog_jtag_handle = usbprog_jtag_open(); usbprog_jtag_handle = usbprog_jtag_open();
tms_chain_index = 0; tms_chain_index = 0;
if (usbprog_jtag_handle == 0) if (usbprog_jtag_handle == 0) {
{
LOG_ERROR("Can't find USB JTAG Interface! Please check connection and permissions."); LOG_ERROR("Can't find USB JTAG Interface! Please check connection and permissions.");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -205,8 +203,7 @@ static void usbprog_end_state(tap_state_t state)
{ {
if (tap_is_state_stable(state)) if (tap_is_state_stable(state))
tap_set_end_state(state); tap_set_end_state(state);
else else {
{
LOG_ERROR("BUG: %i is not a valid end state", state); LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1); exit(-1);
} }
@ -231,23 +228,20 @@ static void usbprog_path_move(struct pathmove_command *cmd)
usbprog_jtag_tms_send(usbprog_jtag_handle); usbprog_jtag_tms_send(usbprog_jtag_handle);
state_count = 0; state_count = 0;
while (num_states) while (num_states) {
{ if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) {
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
{
/* LOG_INFO("1"); */ /* LOG_INFO("1"); */
usbprog_write(0, 0, 0); usbprog_write(0, 0, 0);
usbprog_write(1, 0, 0); usbprog_write(1, 0, 0);
} } else if (tap_state_transition(tap_get_state(),
else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count]) true) == cmd->path[state_count]) {
{
/* LOG_INFO("2"); */ /* LOG_INFO("2"); */
usbprog_write(0, 1, 0); usbprog_write(0, 1, 0);
usbprog_write(1, 1, 0); usbprog_write(1, 1, 0);
} } else {
else LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
{ tap_state_name(tap_get_state()),
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(cmd->path[state_count])); tap_state_name(cmd->path[state_count]));
exit(-1); exit(-1);
} }
@ -264,32 +258,28 @@ static void usbprog_runtest(int num_cycles)
int i; int i;
/* only do a state_move when we're not already in IDLE */ /* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE) if (tap_get_state() != TAP_IDLE) {
{
usbprog_end_state(TAP_IDLE); usbprog_end_state(TAP_IDLE);
usbprog_state_move(); usbprog_state_move();
} }
/* execute num_cycles */ /* execute num_cycles */
if (num_cycles > 0) if (num_cycles > 0) {
{
usbprog_jtag_tms_send(usbprog_jtag_handle); usbprog_jtag_tms_send(usbprog_jtag_handle);
usbprog_write(0, 0, 0); usbprog_write(0, 0, 0);
} } else {
else
{
usbprog_jtag_tms_send(usbprog_jtag_handle); usbprog_jtag_tms_send(usbprog_jtag_handle);
/* LOG_INFO("NUM CYCLES %i",num_cycles); */ /* LOG_INFO("NUM CYCLES %i",num_cycles); */
} }
for (i = 0; i < num_cycles; i++) for (i = 0; i < num_cycles; i++) {
{
usbprog_write(1, 0, 0); usbprog_write(1, 0, 0);
usbprog_write(0, 0, 0); usbprog_write(0, 0, 0);
} }
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest: cur_state %s end_state %s", tap_state_name(tap_get_state()), tap_state_name(tap_get_end_state())); LOG_DEBUG("runtest: cur_state %s end_state %s", tap_state_name(
tap_get_state()), tap_state_name(tap_get_end_state()));
#endif #endif
/* finish in end_state */ /* finish in end_state */
@ -317,11 +307,17 @@ static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
usbprog_jtag_tms_send(usbprog_jtag_handle); usbprog_jtag_tms_send(usbprog_jtag_handle);
void (*f)(struct usbprog_jtag *usbprog_jtag, char * buffer_local, int size); void (*f)(struct usbprog_jtag *usbprog_jtag, char *buffer_local, int size);
switch (type) { switch (type) {
case SCAN_OUT: f = &usbprog_jtag_write_tdi; break; case SCAN_OUT:
case SCAN_IN: f = &usbprog_jtag_read_tdo; break; f = &usbprog_jtag_write_tdi;
case SCAN_IO: f = &usbprog_jtag_write_and_read; break; break;
case SCAN_IN:
f = &usbprog_jtag_read_tdo;
break;
case SCAN_IO:
f = &usbprog_jtag_write_and_read;
break;
default: default:
LOG_ERROR("unknown scan type: %i", type); LOG_ERROR("unknown scan type: %i", type);
exit(-1); exit(-1);
@ -351,7 +347,7 @@ static void usbprog_write(int tck, int tms, int tdi)
if (tck) if (tck)
output_value |= (1 << TCK_BIT); output_value |= (1 << TCK_BIT);
usbprog_jtag_write_slice(usbprog_jtag_handle,output_value); usbprog_jtag_write_slice(usbprog_jtag_handle, output_value);
} }
/* (1) assert or (0) deassert reset lines */ /* (1) assert or (0) deassert reset lines */
@ -374,7 +370,7 @@ static void usbprog_reset(int trst, int srst)
struct usb_bus *busses; struct usb_bus *busses;
struct usbprog_jtag* usbprog_jtag_open(void) struct usbprog_jtag *usbprog_jtag_open(void)
{ {
usb_set_debug(10); usb_set_debug(10);
usb_init(); usb_init();
@ -405,20 +401,18 @@ static void usbprog_jtag_close(struct usbprog_jtag *usbprog_jtag)
static unsigned char usbprog_jtag_message(struct usbprog_jtag *usbprog_jtag, char *msg, int msglen) static unsigned char usbprog_jtag_message(struct usbprog_jtag *usbprog_jtag, char *msg, int msglen)
{ {
int res = usb_bulk_write(usbprog_jtag->usb_handle, 3, msg,msglen, 100); int res = usb_bulk_write(usbprog_jtag->usb_handle, 3, msg, msglen, 100);
if ((msg[0] == 2) || (msg[0] == 1) || (msg[0] == 4) || (msg[0] == 0) || \ if ((msg[0] == 2) || (msg[0] == 1) || (msg[0] == 4) || (msg[0] == 0) || \
(msg[0] == 6) || (msg[0] == 0x0A) || (msg[0] == 9)) (msg[0] == 6) || (msg[0] == 0x0A) || (msg[0] == 9))
return 1; return 1;
if (res == msglen) if (res == msglen) {
{
/* LOG_INFO("HALLLLOOO %i",(int)msg[0]); */ /* LOG_INFO("HALLLLOOO %i",(int)msg[0]); */
res = usb_bulk_read(usbprog_jtag->usb_handle, 0x82, msg, 2, 100); res = usb_bulk_read(usbprog_jtag->usb_handle, 0x82, msg, 2, 100);
if (res > 0) if (res > 0)
return (unsigned char)msg[1]; return (unsigned char)msg[1];
else else
return -1; return -1;
} } else
else
return -1; return -1;
return 0; return 0;
} }
@ -428,7 +422,7 @@ static void usbprog_jtag_init(struct usbprog_jtag *usbprog_jtag)
usbprog_jtag_set_direction(usbprog_jtag, 0xFE); usbprog_jtag_set_direction(usbprog_jtag, 0xFE);
} }
static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char * buffer, int size) static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char *buffer, int size)
{ {
char tmp[64]; /* fastes packet size for usb controller */ char tmp[64]; /* fastes packet size for usb controller */
int send_bits, bufindex = 0, fillindex = 0, i, loops; int send_bits, bufindex = 0, fillindex = 0, i, loops;
@ -436,16 +430,12 @@ static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char
char swap; char swap;
/* 61 byte can be transfered (488 bit) */ /* 61 byte can be transfered (488 bit) */
while (size > 0) while (size > 0) {
{ if (size > 488) {
if (size > 488)
{
send_bits = 488; send_bits = 488;
size = size - 488; size = size - 488;
loops = 61; loops = 61;
} } else {
else
{
send_bits = size; send_bits = size;
loops = size / 8; loops = size / 8;
loops++; loops++;
@ -455,26 +445,22 @@ static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char
tmp[1] = (char)(send_bits >> 8); /* high */ tmp[1] = (char)(send_bits >> 8); /* high */
tmp[2] = (char)(send_bits); /* low */ tmp[2] = (char)(send_bits); /* low */
for (i = 0; i < loops; i++) for (i = 0; i < loops; i++) {
{
tmp[3 + i] = buffer[bufindex]; tmp[3 + i] = buffer[bufindex];
bufindex++; bufindex++;
} }
if (usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000) == 64) if (usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000) == 64) {
{
/* LOG_INFO("HALLLLOOO2 %i",(int)tmp[0]); */ /* LOG_INFO("HALLLLOOO2 %i",(int)tmp[0]); */
usleep(1); usleep(1);
int timeout = 0; int timeout = 0;
while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 1000) < 1) while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 1000) < 1) {
{
timeout++; timeout++;
if (timeout > 10) if (timeout > 10)
break; break;
} }
for (i = 0; i < loops; i++) for (i = 0; i < loops; i++) {
{
swap = tmp[3 + i]; swap = tmp[3 + i];
buffer[fillindex++] = swap; buffer[fillindex++] = swap;
} }
@ -482,7 +468,7 @@ static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char
} }
} }
static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char * buffer, int size) static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char *buffer, int size)
{ {
char tmp[64]; /* fastes packet size for usb controller */ char tmp[64]; /* fastes packet size for usb controller */
int send_bits, fillindex = 0, i, loops; int send_bits, fillindex = 0, i, loops;
@ -490,16 +476,12 @@ static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char * buff
char swap; char swap;
/* 61 byte can be transfered (488 bit) */ /* 61 byte can be transfered (488 bit) */
while (size > 0) while (size > 0) {
{ if (size > 488) {
if (size > 488)
{
send_bits = 488; send_bits = 488;
size = size - 488; size = size - 488;
loops = 61; loops = 61;
} } else {
else
{
send_bits = size; send_bits = size;
loops = size / 8; loops = size / 8;
loops++; loops++;
@ -514,37 +496,31 @@ static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char * buff
/* LOG_INFO("HALLLLOOO3 %i",(int)tmp[0]); */ /* LOG_INFO("HALLLLOOO3 %i",(int)tmp[0]); */
int timeout = 0; int timeout = 0;
usleep(1); usleep(1);
while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 10) < 1) while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 10) < 1) {
{
timeout++; timeout++;
if (timeout > 10) if (timeout > 10)
break; break;
} }
for (i = 0; i < loops; i++) for (i = 0; i < loops; i++) {
{
swap = tmp[3 + i]; swap = tmp[3 + i];
buffer[fillindex++] = swap; buffer[fillindex++] = swap;
} }
} }
} }
static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char * buffer, int size) static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char *buffer, int size)
{ {
char tmp[64]; /* fastes packet size for usb controller */ char tmp[64]; /* fastes packet size for usb controller */
int send_bits, bufindex = 0, i, loops; int send_bits, bufindex = 0, i, loops;
/* 61 byte can be transfered (488 bit) */ /* 61 byte can be transfered (488 bit) */
while (size > 0) while (size > 0) {
{ if (size > 488) {
if (size > 488)
{
send_bits = 488; send_bits = 488;
size = size - 488; size = size - 488;
loops = 61; loops = 61;
} } else {
else
{
send_bits = size; send_bits = size;
loops = size/8; loops = size/8;
/* if (loops == 0) */ /* if (loops == 0) */
@ -555,8 +531,7 @@ static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char * buf
tmp[1] = (char)(send_bits >> 8); /* high */ tmp[1] = (char)(send_bits >> 8); /* high */
tmp[2] = (char)(send_bits); /* low */ tmp[2] = (char)(send_bits); /* low */
for (i = 0; i < loops; i++) for (i = 0; i < loops; i++) {
{
tmp[3 + i] = buffer[bufindex]; tmp[3 + i] = buffer[bufindex];
bufindex++; bufindex++;
} }
@ -577,7 +552,7 @@ static void usbprog_jtag_set_direction(struct usbprog_jtag *usbprog_jtag, unsign
usbprog_jtag_message(usbprog_jtag, tmp, 2); usbprog_jtag_message(usbprog_jtag, tmp, 2);
} }
static void usbprog_jtag_write_slice(struct usbprog_jtag *usbprog_jtag,unsigned char value) static void usbprog_jtag_write_slice(struct usbprog_jtag *usbprog_jtag, unsigned char value)
{ {
char tmp[2]; char tmp[2];
tmp[0] = PORT_SET; tmp[0] = PORT_SET;
@ -595,7 +570,7 @@ static unsigned char usbprog_jtag_get_port(struct usbprog_jtag *usbprog_jtag)
} }
#endif #endif
static void usbprog_jtag_set_bit(struct usbprog_jtag *usbprog_jtag,int bit, int value) static void usbprog_jtag_set_bit(struct usbprog_jtag *usbprog_jtag, int bit, int value)
{ {
char tmp[3]; char tmp[3];
tmp[0] = PORT_SETBIT; tmp[0] = PORT_SETBIT;
@ -631,8 +606,7 @@ static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag)
{ {
int i; int i;
/* LOG_INFO("TMS SEND"); */ /* LOG_INFO("TMS SEND"); */
if (tms_chain_index > 0) if (tms_chain_index > 0) {
{
char tmp[tms_chain_index + 2]; char tmp[tms_chain_index + 2];
tmp[0] = WRITE_TMS_CHAIN; tmp[0] = WRITE_TMS_CHAIN;
tmp[1] = (char)(tms_chain_index); tmp[1] = (char)(tms_chain_index);

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -45,8 +46,7 @@ RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask,
uint8_t conf[8]; uint8_t conf[8];
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -67,8 +67,7 @@ RESULT usbtogpio_in(uint8_t interface_index, uint32_t mask, uint32_t *value)
uint8_t buf[2]; uint8_t buf[2];
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -77,7 +76,7 @@ RESULT usbtogpio_in(uint8_t interface_index, uint32_t mask, uint32_t *value)
SET_LE_U16(&buf[0], mask); SET_LE_U16(&buf[0], mask);
return usbtoxxx_in_command(USB_TO_GPIO, interface_index, buf, 2, 2, return usbtoxxx_in_command(USB_TO_GPIO, interface_index, buf, 2, 2,
(uint8_t*)value, 0, 2, 0); (uint8_t *)value, 0, 2, 0);
} }
RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value) RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value)
@ -85,8 +84,7 @@ RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value)
uint8_t buf[4]; uint8_t buf[4];
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -97,4 +95,3 @@ RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value)
return usbtoxxx_out_command(USB_TO_GPIO, interface_index, buf, 4, 0); return usbtoxxx_out_command(USB_TO_GPIO, interface_index, buf, 4, 0);
} }

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -43,8 +44,7 @@ RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t kHz)
uint8_t cfg_buf[4]; uint8_t cfg_buf[4];
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -61,17 +61,14 @@ RESULT usbtojtagraw_execute(uint8_t interface_index, uint8_t *tdi,
uint16_t bytelen; uint16_t bytelen;
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
#endif #endif
if (bitlen > 8 * 0xFFFF) if (bitlen > 8 * 0xFFFF)
{
return ERROR_FAIL; return ERROR_FAIL;
}
bytelen = (uint16_t)((bitlen + 7) >> 3); bytelen = (uint16_t)((bitlen + 7) >> 3);
SET_LE_U32(&versaloon_cmd_buf[0], bitlen); SET_LE_U32(&versaloon_cmd_buf[0], bitlen);
@ -81,4 +78,3 @@ RESULT usbtojtagraw_execute(uint8_t interface_index, uint8_t *tdi,
return usbtoxxx_inout_command(USB_TO_JTAG_RAW, interface_index, return usbtoxxx_inout_command(USB_TO_JTAG_RAW, interface_index,
versaloon_cmd_buf, 4 + bytelen * 2, bytelen, tdo, 0, bytelen, 0); versaloon_cmd_buf, 4 + bytelen * 2, bytelen, tdo, 0, bytelen, 0);
} }

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -41,8 +42,7 @@ RESULT usbtopwr_fini(uint8_t interface_index)
RESULT usbtopwr_config(uint8_t interface_index) RESULT usbtopwr_config(uint8_t interface_index)
{ {
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -54,8 +54,7 @@ RESULT usbtopwr_config(uint8_t interface_index)
RESULT usbtopwr_output(uint8_t interface_index, uint16_t mV) RESULT usbtopwr_output(uint8_t interface_index, uint16_t mV)
{ {
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -64,4 +63,3 @@ RESULT usbtopwr_output(uint8_t interface_index, uint16_t mV)
return usbtoxxx_out_command(USB_TO_POWER, interface_index, (uint8_t *)&mV, return usbtoxxx_out_command(USB_TO_POWER, interface_index, (uint8_t *)&mV,
2, 0); 2, 0);
} }

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -36,9 +37,7 @@ RESULT usbtoswd_callback(void *p, uint8_t *src, uint8_t *processed)
processed = processed; processed = processed;
if (pending->extra_data != NULL) if (pending->extra_data != NULL)
{
*((uint8_t *)pending->extra_data) = src[0]; *((uint8_t *)pending->extra_data) = src[0];
}
return ERROR_OK; return ERROR_OK;
} }
@ -59,8 +58,7 @@ RESULT usbtoswd_config(uint8_t interface_index, uint8_t trn, uint16_t retry,
uint8_t cfg_buf[5]; uint8_t cfg_buf[5];
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -78,8 +76,7 @@ RESULT usbtoswd_seqout(uint8_t interface_index, uint8_t *data, uint16_t bitlen)
uint16_t bytelen = (bitlen + 7) >> 3; uint16_t bytelen = (bitlen + 7) >> 3;
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -98,8 +95,7 @@ RESULT usbtoswd_seqin(uint8_t interface_index, uint8_t *data, uint16_t bitlen)
uint8_t buff[2]; uint8_t buff[2];
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -118,8 +114,7 @@ RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request,
uint8_t buff[5]; uint8_t buff[5];
#if PARAM_CHECK #if PARAM_CHECK
if (interface_index > 7) if (interface_index > 7) {
{
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index); LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -132,27 +127,19 @@ RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request,
parity &= 1; parity &= 1;
buff[0] = (request | 0x81 | (parity << 5)) & ~0x40; buff[0] = (request | 0x81 | (parity << 5)) & ~0x40;
if (data != NULL) if (data != NULL)
{
SET_LE_U32(&buff[1], *data); SET_LE_U32(&buff[1], *data);
}
else else
{
memset(buff + 1, 0, 4); memset(buff + 1, 0, 4);
}
versaloon_set_extra_data(ack); versaloon_set_extra_data(ack);
versaloon_set_callback(usbtoswd_callback); versaloon_set_callback(usbtoswd_callback);
if (request & 0x04) if (request & 0x04) {
{ /* read */
// read
return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5, return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5,
(uint8_t *)data, 1, 4, 0); (uint8_t *)data, 1, 4, 0);
} } else {
else /* write */
{
// write
return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5, return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5,
NULL, 0, 0, 0); NULL, 0, 0, 0);
} }
} }

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -29,20 +30,20 @@
#include "usbtoxxx_internal.h" #include "usbtoxxx_internal.h"
#define N_A "n/a" #define N_A "n/a"
const char* types_name[96] =
{ const char *types_name[96] = {
"usbtousart", "usbtospi", "usbtoi2c", "usbtogpio", "usbtocan", "usbtopwm", "usbtousart", "usbtospi", "usbtoi2c", "usbtogpio", "usbtocan", "usbtopwm",
"usbtoadc", "usbtodac", "usbtoadc", "usbtodac",
"usbtomicrowire", "usbtoswim", "usbtodusi", N_A, N_A, N_A, "usbtopower", "usbtodelay", "usbtomicrowire", "usbtoswim", "usbtodusi", N_A, N_A, N_A, "usbtopower", "usbtodelay",
N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A,
N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A,
"usbtojtagll", "usbtojtaghl", "usbtoissp", "usbtoc2", "usbtosbw", "usbtojtagll", "usbtojtaghl", "usbtoissp", "usbtoc2", "usbtosbw",
"usbtolpcicp", "usbtoswd", "usbtojtagraw", "usbtolpcicp", "usbtoswd", "usbtojtagraw",
"usbtobdm", N_A, N_A, N_A, N_A, N_A, N_A, N_A, "usbtobdm", N_A, N_A, N_A, N_A, N_A, N_A, N_A,
N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A,
"usbtomsp430jtag", N_A, N_A, N_A, N_A, N_A, N_A, N_A, "usbtomsp430jtag", N_A, N_A, N_A, N_A, N_A, N_A, N_A,
"usbtopower", "usbtodelay", "usbtopoll", N_A, N_A, N_A, N_A, N_A, "usbtopower", "usbtodelay", "usbtopoll", N_A, N_A, N_A, N_A, N_A,
N_A, N_A, N_A, N_A, N_A, N_A, N_A, "usbtoall" N_A, N_A, N_A, N_A, N_A, N_A, N_A, "usbtoall"
}; };
uint8_t usbtoxxx_abilities[USB_TO_XXX_ABILITIES_LEN]; uint8_t usbtoxxx_abilities[USB_TO_XXX_ABILITIES_LEN];
@ -51,17 +52,16 @@ uint8_t usbtoxxx_abilities[USB_TO_XXX_ABILITIES_LEN];
types_name[((type) - VERSALOON_USB_TO_XXX_CMD_START) \ types_name[((type) - VERSALOON_USB_TO_XXX_CMD_START) \
% (sizeof(types_name) / sizeof(types_name[0]))] % (sizeof(types_name) / sizeof(types_name[0]))]
static uint8_t type_pre = 0; static uint8_t type_pre;
static uint16_t usbtoxxx_buffer_index = 0; static uint16_t usbtoxxx_buffer_index;
static uint16_t usbtoxxx_current_cmd_index = 0; static uint16_t usbtoxxx_current_cmd_index;
static uint8_t *usbtoxxx_buffer = NULL; static uint8_t *usbtoxxx_buffer;
uint16_t collect_index = 0; uint16_t collect_index;
uint8_t collect_cmd; uint8_t collect_cmd;
static uint8_t poll_nesting = 0; static uint8_t poll_nesting;
struct usbtoxxx_context_t struct usbtoxxx_context_t {
{
uint8_t type_pre; uint8_t type_pre;
uint8_t *usbtoxxx_buffer; uint8_t *usbtoxxx_buffer;
uint16_t usbtoxxx_current_cmd_index; uint16_t usbtoxxx_current_cmd_index;
@ -90,11 +90,9 @@ static void usbtoxxx_pop_context(struct usbtoxxx_context_t *c)
RESULT usbtoxxx_validate_current_command_type(void) RESULT usbtoxxx_validate_current_command_type(void)
{ {
if (type_pre > 0) if (type_pre > 0) {
{ /* not the first command */
// not the first command if (NULL == usbtoxxx_buffer) {
if (NULL == usbtoxxx_buffer)
{
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer)); LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer));
return ERRCODE_INVALID_BUFFER; return ERRCODE_INVALID_BUFFER;
} }
@ -103,14 +101,12 @@ RESULT usbtoxxx_validate_current_command_type(void)
SET_LE_U16(&usbtoxxx_buffer[1], usbtoxxx_current_cmd_index); SET_LE_U16(&usbtoxxx_buffer[1], usbtoxxx_current_cmd_index);
usbtoxxx_buffer_index += usbtoxxx_current_cmd_index; usbtoxxx_buffer_index += usbtoxxx_current_cmd_index;
} } else {
else /* first command */
{
// first command
usbtoxxx_buffer_index = 3; usbtoxxx_buffer_index = 3;
} }
// prepare for next command /* prepare for next command */
usbtoxxx_current_cmd_index = 3; usbtoxxx_current_cmd_index = 3;
usbtoxxx_buffer = versaloon_buf + usbtoxxx_buffer_index; usbtoxxx_buffer = versaloon_buf + usbtoxxx_buffer_index;
@ -120,29 +116,24 @@ RESULT usbtoxxx_validate_current_command_type(void)
return ERROR_OK; return ERROR_OK;
} }
RESULT usbtoxxx_execute_command(void) RESULT usbtoxxx_execute_command(void)
{ {
uint16_t i; uint16_t i;
uint16_t inlen; uint16_t inlen;
RESULT result = ERROR_OK; RESULT result = ERROR_OK;
if (poll_nesting) if (poll_nesting) {
{
LOG_BUG(ERRMSG_INVALID_USAGE, "USB_TO_POLL"); LOG_BUG(ERRMSG_INVALID_USAGE, "USB_TO_POLL");
versaloon_free_want_pos(); versaloon_free_want_pos();
return ERROR_FAIL; return ERROR_FAIL;
} }
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
versaloon_free_want_pos(); versaloon_free_want_pos();
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
if (3 == usbtoxxx_buffer_index) if (3 == usbtoxxx_buffer_index) {
{
versaloon_free_want_pos(); versaloon_free_want_pos();
return ERROR_OK; return ERROR_OK;
} }
@ -150,33 +141,27 @@ RESULT usbtoxxx_execute_command(void)
versaloon_buf[0] = USB_TO_ALL; versaloon_buf[0] = USB_TO_ALL;
SET_LE_U16(&versaloon_buf[1], usbtoxxx_buffer_index); SET_LE_U16(&versaloon_buf[1], usbtoxxx_buffer_index);
if (ERROR_OK != versaloon_send_command(usbtoxxx_buffer_index, &inlen)) if (ERROR_OK != versaloon_send_command(usbtoxxx_buffer_index, &inlen)) {
{
versaloon_free_want_pos(); versaloon_free_want_pos();
return ERROR_FAIL; return ERROR_FAIL;
} }
// process return data /* process return data */
usbtoxxx_buffer_index = 0; usbtoxxx_buffer_index = 0;
for (i = 0; i < versaloon_pending_idx; i++) for (i = 0; i < versaloon_pending_idx; i++) {
{ /* check result */
// check result
if ((0 == i) || !((versaloon_pending[i].collect) if ((0 == i) || !((versaloon_pending[i].collect)
&& (versaloon_pending[i - 1].collect) && (versaloon_pending[i - 1].collect)
&& (versaloon_pending[i].cmd && (versaloon_pending[i].cmd
== versaloon_pending[i - 1].cmd))) == versaloon_pending[i - 1].cmd))) {
{
if (USB_TO_XXX_CMD_NOT_SUPPORT if (USB_TO_XXX_CMD_NOT_SUPPORT
== versaloon_buf[usbtoxxx_buffer_index]) == versaloon_buf[usbtoxxx_buffer_index]) {
{
LOG_ERROR(ERRMSG_NOT_SUPPORT_BY, LOG_ERROR(ERRMSG_NOT_SUPPORT_BY,
usbtoxxx_get_type_name(versaloon_pending[i].type), usbtoxxx_get_type_name(versaloon_pending[i].type),
"current dongle"); "current dongle");
result = ERROR_FAIL; result = ERROR_FAIL;
break; break;
} } else if (USB_TO_XXX_OK != versaloon_buf[usbtoxxx_buffer_index]) {
else if (USB_TO_XXX_OK != versaloon_buf[usbtoxxx_buffer_index])
{
LOG_ERROR("%s command 0x%02x failed with 0x%02x", LOG_ERROR("%s command 0x%02x failed with 0x%02x",
usbtoxxx_get_type_name(versaloon_pending[i].type), usbtoxxx_get_type_name(versaloon_pending[i].type),
versaloon_pending[i].cmd, versaloon_pending[i].cmd,
@ -187,27 +172,24 @@ RESULT usbtoxxx_execute_command(void)
usbtoxxx_buffer_index++; usbtoxxx_buffer_index++;
} }
// get result data /* get result data */
if (versaloon_pending[i].pos != NULL) if (versaloon_pending[i].pos != NULL) {
{
uint8_t processed = 0; uint8_t processed = 0;
if (versaloon_pending[i].callback != NULL) if (versaloon_pending[i].callback != NULL) {
{
versaloon_pending[i].callback(&versaloon_pending[i], versaloon_pending[i].callback(&versaloon_pending[i],
versaloon_buf + usbtoxxx_buffer_index, &processed); versaloon_buf + usbtoxxx_buffer_index, &processed);
} }
if (!processed) if (!processed) {
{
struct versaloon_want_pos_t *tmp; struct versaloon_want_pos_t *tmp;
tmp = versaloon_pending[i].pos; tmp = versaloon_pending[i].pos;
while (tmp != NULL) while (tmp != NULL) {
{ if ((tmp->buff != NULL) && (tmp->size > 0)) {
if ((tmp->buff != NULL) && (tmp->size > 0)) memcpy(tmp->buff,
{ versaloon_buf + usbtoxxx_buffer_index
memcpy(tmp->buff, versaloon_buf + usbtoxxx_buffer_index + tmp->offset,
+ tmp->offset, tmp->size); tmp->size);
} }
struct versaloon_want_pos_t *free_tmp; struct versaloon_want_pos_t *free_tmp;
free_tmp = tmp; free_tmp = tmp;
@ -216,19 +198,15 @@ RESULT usbtoxxx_execute_command(void)
} }
versaloon_pending[i].pos = NULL; versaloon_pending[i].pos = NULL;
} }
} } else if ((versaloon_pending[i].want_data_size > 0)
else if ((versaloon_pending[i].want_data_size > 0) && (versaloon_pending[i].data_buffer != NULL)) {
&& (versaloon_pending[i].data_buffer != NULL))
{
uint8_t processed = 0; uint8_t processed = 0;
if (versaloon_pending[i].callback != NULL) if (versaloon_pending[i].callback != NULL) {
{
versaloon_pending[i].callback(&versaloon_pending[i], versaloon_pending[i].callback(&versaloon_pending[i],
versaloon_buf + usbtoxxx_buffer_index, &processed); versaloon_buf + usbtoxxx_buffer_index, &processed);
} }
if (!processed) if (!processed) {
{
memcpy(versaloon_pending[i].data_buffer, memcpy(versaloon_pending[i].data_buffer,
versaloon_buf + usbtoxxx_buffer_index versaloon_buf + usbtoxxx_buffer_index
+ versaloon_pending[i].want_data_pos, + versaloon_pending[i].want_data_pos,
@ -236,8 +214,7 @@ RESULT usbtoxxx_execute_command(void)
} }
} }
usbtoxxx_buffer_index += versaloon_pending[i].actual_data_size; usbtoxxx_buffer_index += versaloon_pending[i].actual_data_size;
if (usbtoxxx_buffer_index > inlen) if (usbtoxxx_buffer_index > inlen) {
{
LOG_BUG("%s command 0x%02x process error", LOG_BUG("%s command 0x%02x process error",
usbtoxxx_get_type_name(versaloon_pending[i].type), usbtoxxx_get_type_name(versaloon_pending[i].type),
versaloon_pending[i].cmd); versaloon_pending[i].cmd);
@ -246,20 +223,16 @@ RESULT usbtoxxx_execute_command(void)
} }
} }
// data is not the right size /* data is not the right size */
if (inlen != usbtoxxx_buffer_index) if (inlen != usbtoxxx_buffer_index) {
{
LOG_ERROR(ERRMSG_INVALID_TARGET, "length of return data"); LOG_ERROR(ERRMSG_INVALID_TARGET, "length of return data");
result = ERROR_FAIL; result = ERROR_FAIL;
} }
if (versaloon_pending_idx > 0) if (versaloon_pending_idx > 0)
{
versaloon_pending_idx = 0; versaloon_pending_idx = 0;
} else {
else /* no receive data, avoid collision */
{
// no receive data, avoid collision
sleep_ms(10); sleep_ms(10);
} }
@ -276,9 +249,7 @@ RESULT usbtoxxx_init(void)
if ((ERROR_OK != usbtoinfo_get_abilities(usbtoxxx_abilities)) || if ((ERROR_OK != usbtoinfo_get_abilities(usbtoxxx_abilities)) ||
(ERROR_OK != usbtoxxx_execute_command())) (ERROR_OK != usbtoxxx_execute_command()))
{
return ERROR_FAIL; return ERROR_FAIL;
}
LOG_INFO("USB_TO_XXX abilities: 0x%08X:0x%08X:0x%08X", LOG_INFO("USB_TO_XXX abilities: 0x%08X:0x%08X:0x%08X",
GET_LE_U32(&usbtoxxx_abilities[0]), GET_LE_U32(&usbtoxxx_abilities[0]),
GET_LE_U32(&usbtoxxx_abilities[4]), GET_LE_U32(&usbtoxxx_abilities[4]),
@ -297,31 +268,24 @@ bool usbtoxxx_interface_supported(uint8_t cmd)
{ {
if ((cmd < VERSALOON_USB_TO_XXX_CMD_START) || if ((cmd < VERSALOON_USB_TO_XXX_CMD_START) ||
(cmd > VERSALOON_USB_TO_XXX_CMD_END)) (cmd > VERSALOON_USB_TO_XXX_CMD_END))
{
return false; return false;
}
cmd -= VERSALOON_USB_TO_XXX_CMD_START; cmd -= VERSALOON_USB_TO_XXX_CMD_START;
return (usbtoxxx_abilities[cmd / 8] & (1 << (cmd % 8))) > 0; return (usbtoxxx_abilities[cmd / 8] & (1 << (cmd % 8))) > 0;
} }
RESULT usbtoxxx_ensure_buffer_size(uint16_t cmdlen) RESULT usbtoxxx_ensure_buffer_size(uint16_t cmdlen)
{ {
// check free space, commit if not enough /* check free space, commit if not enough */
if (((usbtoxxx_buffer_index + usbtoxxx_current_cmd_index + cmdlen) if (((usbtoxxx_buffer_index + usbtoxxx_current_cmd_index + cmdlen)
>= versaloon_buf_size) >= versaloon_buf_size)
|| (versaloon_pending_idx >= VERSALOON_MAX_PENDING_NUMBER)) || (versaloon_pending_idx >= VERSALOON_MAX_PENDING_NUMBER)) {
{
struct usbtoxxx_context_t context_tmp; struct usbtoxxx_context_t context_tmp;
uint8_t poll_nesting_tmp = 0; uint8_t poll_nesting_tmp = 0;
memset(&context_tmp, 0, sizeof(context_tmp)); memset(&context_tmp, 0, sizeof(context_tmp));
if (poll_nesting) if (poll_nesting) {
{ if (0 == poll_context.type_pre) {
if (0 == poll_context.type_pre)
{
LOG_BUG("USB_TO_POLL toooooo long"); LOG_BUG("USB_TO_POLL toooooo long");
return ERROR_OK; return ERROR_OK;
} }
@ -333,12 +297,9 @@ RESULT usbtoxxx_ensure_buffer_size(uint16_t cmdlen)
} }
if (usbtoxxx_execute_command() != ERROR_OK) if (usbtoxxx_execute_command() != ERROR_OK)
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (poll_nesting_tmp) if (poll_nesting_tmp) {
{
uint16_t newlen, oldlen; uint16_t newlen, oldlen;
newlen = context_tmp.versaloon_pending_idx newlen = context_tmp.versaloon_pending_idx
@ -368,48 +329,37 @@ RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf,
{ {
uint16_t len_tmp; uint16_t len_tmp;
// 3 more bytes by usbtoxxx_validate_current_command_type /* 3 more bytes by usbtoxxx_validate_current_command_type */
// 3 more bytes when ((0 == collect_index) || (collect_cmd != cmd)) /* 3 more bytes when ((0 == collect_index) || (collect_cmd != cmd)) */
if (ERROR_OK != usbtoxxx_ensure_buffer_size(cmdlen + 6)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(cmdlen + 6))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if ((type_pre != type) || (NULL == usbtoxxx_buffer)) if ((type_pre != type) || (NULL == usbtoxxx_buffer)) {
{ if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
if (ERROR_OK != usbtoxxx_validate_current_command_type())
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
type_pre = type; type_pre = type;
} }
if ((0 == collect_index) || (collect_cmd != cmd)) if ((0 == collect_index) || (collect_cmd != cmd)) {
{
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = cmd; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = cmd;
if (collect) if (collect) {
{
collect_index = usbtoxxx_current_cmd_index; collect_index = usbtoxxx_current_cmd_index;
collect_cmd = cmd; collect_cmd = cmd;
} } else {
else
{
collect_index = 0; collect_index = 0;
collect_cmd = 0; collect_cmd = 0;
} }
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], cmdlen); SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], cmdlen);
usbtoxxx_current_cmd_index += 2; usbtoxxx_current_cmd_index += 2;
} } else {
else
{
len_tmp = GET_LE_U16(&usbtoxxx_buffer[collect_index]) + cmdlen; len_tmp = GET_LE_U16(&usbtoxxx_buffer[collect_index]) + cmdlen;
SET_LE_U16(&usbtoxxx_buffer[collect_index], len_tmp); SET_LE_U16(&usbtoxxx_buffer[collect_index], len_tmp);
} }
if (cmdbuf != NULL) if (cmdbuf != NULL) {
{
memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen); memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen);
usbtoxxx_current_cmd_index += cmdlen; usbtoxxx_current_cmd_index += cmdlen;
} }
@ -418,19 +368,12 @@ RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf,
wantbuf, collect); wantbuf, collect);
} }
RESULT usbtoinfo_get_abilities(uint8_t abilities[USB_TO_XXX_ABILITIES_LEN]) RESULT usbtoinfo_get_abilities(uint8_t abilities[USB_TO_XXX_ABILITIES_LEN])
{ {
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(3))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
@ -440,22 +383,14 @@ RESULT usbtoinfo_get_abilities(uint8_t abilities[USB_TO_XXX_ABILITIES_LEN])
USB_TO_XXX_ABILITIES_LEN, abilities, 0); USB_TO_XXX_ABILITIES_LEN, abilities, 0);
} }
RESULT usbtopoll_start(uint16_t retry_cnt, uint16_t interval_us) RESULT usbtopoll_start(uint16_t retry_cnt, uint16_t interval_us)
{ {
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 5)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 5))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (!poll_nesting) if (!poll_nesting)
{
usbtoxxx_save_context(&poll_context); usbtoxxx_save_context(&poll_context);
}
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
@ -473,18 +408,14 @@ RESULT usbtopoll_start(uint16_t retry_cnt, uint16_t interval_us)
RESULT usbtopoll_end(void) RESULT usbtopoll_end(void)
{ {
if (!poll_nesting) if (!poll_nesting) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 1)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 1))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
@ -502,23 +433,18 @@ RESULT usbtopoll_checkok(uint8_t equ, uint16_t offset, uint8_t size,
{ {
uint8_t i; uint8_t i;
if (size > 4) if (size > 4) {
{ LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
return ERRCODE_INVALID_PARAMETER; return ERRCODE_INVALID_PARAMETER;
} }
if (!poll_nesting) if (!poll_nesting) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 4 + 2 * size)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 4 + 2 * size))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
@ -530,14 +456,10 @@ RESULT usbtopoll_checkok(uint8_t equ, uint16_t offset, uint8_t size,
usbtoxxx_current_cmd_index += 2; usbtoxxx_current_cmd_index += 2;
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = size; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = size;
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = equ; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = equ;
for (i =0; i < size; i++) for (i = 0; i < size; i++)
{
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (mask >> (8 * i)) & 0xFF; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (mask >> (8 * i)) & 0xFF;
} for (i = 0; i < size; i++)
for (i =0; i < size; i++)
{
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (value >> (8 * i)) & 0xFF; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (value >> (8 * i)) & 0xFF;
}
return ERROR_OK; return ERROR_OK;
} }
@ -547,23 +469,18 @@ RESULT usbtopoll_checkfail(uint8_t equ, uint16_t offset, uint8_t size,
{ {
uint8_t i; uint8_t i;
if (size > 4) if (size > 4) {
{ LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
return ERRCODE_INVALID_PARAMETER; return ERRCODE_INVALID_PARAMETER;
} }
if (!poll_nesting) if (!poll_nesting) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 4 + 2 * size)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 4 + 2 * size))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
@ -575,32 +492,24 @@ RESULT usbtopoll_checkfail(uint8_t equ, uint16_t offset, uint8_t size,
usbtoxxx_current_cmd_index += 2; usbtoxxx_current_cmd_index += 2;
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = size; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = size;
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = equ; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = equ;
for (i =0; i < size; i++) for (i = 0; i < size; i++)
{
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (mask >> (8 * i)) & 0xFF; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (mask >> (8 * i)) & 0xFF;
} for (i = 0; i < size; i++)
for (i =0; i < size; i++)
{
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (value >> (8 * i)) & 0xFF; usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (value >> (8 * i)) & 0xFF;
}
return ERROR_OK; return ERROR_OK;
} }
RESULT usbtopoll_verifybuff(uint16_t offset, uint16_t size, uint8_t *buff) RESULT usbtopoll_verifybuff(uint16_t offset, uint16_t size, uint8_t *buff)
{ {
if (!poll_nesting) if (!poll_nesting) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 5 + size)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 5 + size))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
@ -618,18 +527,12 @@ RESULT usbtopoll_verifybuff(uint16_t offset, uint16_t size, uint8_t *buff)
return ERROR_OK; return ERROR_OK;
} }
RESULT usbtodelay_delay(uint16_t dly) RESULT usbtodelay_delay(uint16_t dly)
{ {
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 2)) if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 2))
{
return ERROR_FAIL; return ERROR_FAIL;
}
if (ERROR_OK != usbtoxxx_validate_current_command_type()) if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
{
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands"); LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
@ -650,4 +553,3 @@ RESULT usbtodelay_delayus(uint16_t us)
{ {
return usbtodelay_delay(us & 0x7FFF); return usbtodelay_delay(us & 0x7FFF);
} }

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef __USBTOXXX_H_INCLUDED__ #ifndef __USBTOXXX_H_INCLUDED__
#define __USBTOXXX_H_INCLUDED__ #define __USBTOXXX_H_INCLUDED__
@ -27,17 +28,15 @@ RESULT usbtoxxx_execute_command(void);
extern uint8_t usbtoxxx_abilities[USB_TO_XXX_ABILITIES_LEN]; extern uint8_t usbtoxxx_abilities[USB_TO_XXX_ABILITIES_LEN];
bool usbtoxxx_interface_supported(uint8_t cmd); bool usbtoxxx_interface_supported(uint8_t cmd);
// USB_TO_INFO /* USB_TO_INFO */
RESULT usbtoinfo_get_abilities(uint8_t abilities[USB_TO_XXX_ABILITIES_LEN]); RESULT usbtoinfo_get_abilities(uint8_t abilities[USB_TO_XXX_ABILITIES_LEN]);
// USB_TO_DELAY /* USB_TO_DELAY */
RESULT usbtodelay_delay(uint16_t dly); RESULT usbtodelay_delay(uint16_t dly);
RESULT usbtodelay_delayms(uint16_t ms); RESULT usbtodelay_delayms(uint16_t ms);
RESULT usbtodelay_delayus(uint16_t us); RESULT usbtodelay_delayus(uint16_t us);
/* USB_TO_USART */
// USB_TO_USART
RESULT usbtousart_init(uint8_t interface_index); RESULT usbtousart_init(uint8_t interface_index);
RESULT usbtousart_fini(uint8_t interface_index); RESULT usbtousart_fini(uint8_t interface_index);
RESULT usbtousart_config(uint8_t interface_index, uint32_t baudrate, RESULT usbtousart_config(uint8_t interface_index, uint32_t baudrate,
@ -47,16 +46,14 @@ RESULT usbtousart_receive(uint8_t interface_index, uint8_t *buf, uint16_t len);
RESULT usbtousart_status(uint8_t interface_index, RESULT usbtousart_status(uint8_t interface_index,
struct usart_status_t *status); struct usart_status_t *status);
// USB_TO_SPI /* USB_TO_SPI */
RESULT usbtospi_init(uint8_t interface_index); RESULT usbtospi_init(uint8_t interface_index);
RESULT usbtospi_fini(uint8_t interface_index); RESULT usbtospi_fini(uint8_t interface_index);
RESULT usbtospi_config(uint8_t interface_index, uint32_t kHz, uint8_t mode); RESULT usbtospi_config(uint8_t interface_index, uint32_t kHz, uint8_t mode);
RESULT usbtospi_io(uint8_t interface_index, uint8_t *out, uint8_t *in, RESULT usbtospi_io(uint8_t interface_index, uint8_t *out, uint8_t *in,
uint16_t bytelen); uint16_t bytelen);
/* USB_TO_GPIO */
// USB_TO_GPIO
RESULT usbtogpio_init(uint8_t interface_index); RESULT usbtogpio_init(uint8_t interface_index);
RESULT usbtogpio_fini(uint8_t interface_index); RESULT usbtogpio_fini(uint8_t interface_index);
RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask, RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask,
@ -65,9 +62,7 @@ RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask,
RESULT usbtogpio_in(uint8_t interface_index, uint32_t mask, uint32_t *value); RESULT usbtogpio_in(uint8_t interface_index, uint32_t mask, uint32_t *value);
RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value); RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value);
/* USB_TO_ISSP */
// USB_TO_ISSP
RESULT usbtoissp_init(uint8_t interface_index); RESULT usbtoissp_init(uint8_t interface_index);
RESULT usbtoissp_fini(uint8_t interface_index); RESULT usbtoissp_fini(uint8_t interface_index);
RESULT usbtoissp_enter_program_mode(uint8_t interface_index, uint8_t mode); RESULT usbtoissp_enter_program_mode(uint8_t interface_index, uint8_t mode);
@ -76,9 +71,7 @@ RESULT usbtoissp_wait_and_poll(uint8_t interface_index);
RESULT usbtoissp_vector(uint8_t interface_index, uint8_t operate, uint8_t addr, RESULT usbtoissp_vector(uint8_t interface_index, uint8_t operate, uint8_t addr,
uint8_t data, uint8_t *buf); uint8_t data, uint8_t *buf);
/* USB_TO_LPCICP */
// USB_TO_LPCICP
RESULT usbtolpcicp_init(uint8_t interface_index); RESULT usbtolpcicp_init(uint8_t interface_index);
RESULT usbtolpcicp_fini(uint8_t interface_index); RESULT usbtolpcicp_fini(uint8_t interface_index);
RESULT usbtolpcicp_config(uint8_t interface_index); RESULT usbtolpcicp_config(uint8_t interface_index);
@ -88,23 +81,19 @@ RESULT usbtolpcicp_out(uint8_t interface_index, uint8_t *buff, uint16_t len);
RESULT usbtolpcicp_poll_ready(uint8_t interface_index, uint8_t data, RESULT usbtolpcicp_poll_ready(uint8_t interface_index, uint8_t data,
uint8_t *ret, uint8_t setmask, uint8_t clearmask, uint16_t pollcnt); uint8_t *ret, uint8_t setmask, uint8_t clearmask, uint16_t pollcnt);
/* USB_TO_JTAG_LL */
// USB_TO_JTAG_LL
RESULT usbtojtagll_init(uint8_t interface_index); RESULT usbtojtagll_init(uint8_t interface_index);
RESULT usbtojtagll_fini(uint8_t interface_index); RESULT usbtojtagll_fini(uint8_t interface_index);
RESULT usbtojtagll_config(uint8_t interface_index, uint32_t kHz); RESULT usbtojtagll_config(uint8_t interface_index, uint32_t kHz);
RESULT usbtojtagll_tms(uint8_t interface_index, uint8_t *tms, uint8_t bytelen); RESULT usbtojtagll_tms(uint8_t interface_index, uint8_t *tms, uint8_t bytelen);
RESULT usbtojtagll_tms_clocks(uint8_t interface_index, uint32_t bytelen, RESULT usbtojtagll_tms_clocks(uint8_t interface_index, uint32_t bytelen,
uint8_t tms); uint8_t tms);
RESULT usbtojtagll_scan(uint8_t interface_index, uint8_t* data, RESULT usbtojtagll_scan(uint8_t interface_index, uint8_t *data,
uint16_t bitlen, uint8_t tms_before_valid, uint16_t bitlen, uint8_t tms_before_valid,
uint8_t tms_before, uint8_t tms_after0, uint8_t tms_before, uint8_t tms_after0,
uint8_t tms_after1); uint8_t tms_after1);
/* USB_TO_JTAG_HL */
// USB_TO_JTAG_HL
RESULT usbtojtaghl_init(uint8_t interface_index); RESULT usbtojtaghl_init(uint8_t interface_index);
RESULT usbtojtaghl_fini(uint8_t interface_index); RESULT usbtojtaghl_fini(uint8_t interface_index);
RESULT usbtojtaghl_config(uint8_t interface_index, uint32_t kHz, uint8_t ub, RESULT usbtojtaghl_config(uint8_t interface_index, uint32_t kHz, uint8_t ub,
@ -118,19 +107,14 @@ RESULT usbtojtaghl_runtest(uint8_t interface_index, uint32_t cycles);
RESULT usbtojtaghl_register_callback(uint8_t index, jtag_callback_t send_callback, RESULT usbtojtaghl_register_callback(uint8_t index, jtag_callback_t send_callback,
jtag_callback_t receive_callback); jtag_callback_t receive_callback);
/* USB_TO_JTAG_RAW */
// USB_TO_JTAG_RAW
RESULT usbtojtagraw_init(uint8_t interface_index); RESULT usbtojtagraw_init(uint8_t interface_index);
RESULT usbtojtagraw_fini(uint8_t interface_index); RESULT usbtojtagraw_fini(uint8_t interface_index);
RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t kHz); RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t kHz);
RESULT usbtojtagraw_execute(uint8_t interface_index, uint8_t *tdi, RESULT usbtojtagraw_execute(uint8_t interface_index, uint8_t *tdi,
uint8_t *tms, uint8_t *tdo, uint32_t bitlen); uint8_t *tms, uint8_t *tdo, uint32_t bitlen);
/* USB_TO_C2 */
// USB_TO_C2
RESULT usbtoc2_init(uint8_t interface_index); RESULT usbtoc2_init(uint8_t interface_index);
RESULT usbtoc2_fini(uint8_t interface_index); RESULT usbtoc2_fini(uint8_t interface_index);
RESULT usbtoc2_writeaddr(uint8_t interface_index, uint8_t addr); RESULT usbtoc2_writeaddr(uint8_t interface_index, uint8_t addr);
@ -138,9 +122,7 @@ RESULT usbtoc2_readaddr(uint8_t interface_index, uint8_t *data);
RESULT usbtoc2_writedata(uint8_t interface_index, uint8_t *buf, uint8_t len); RESULT usbtoc2_writedata(uint8_t interface_index, uint8_t *buf, uint8_t len);
RESULT usbtoc2_readdata(uint8_t interface_index, uint8_t *buf, uint8_t len); RESULT usbtoc2_readdata(uint8_t interface_index, uint8_t *buf, uint8_t len);
/* USB_TO_I2C */
// USB_TO_I2C
RESULT usbtoi2c_init(uint8_t interface_index); RESULT usbtoi2c_init(uint8_t interface_index);
RESULT usbtoi2c_fini(uint8_t interface_index); RESULT usbtoi2c_fini(uint8_t interface_index);
RESULT usbtoi2c_config(uint8_t interface_index, uint16_t kHz, RESULT usbtoi2c_config(uint8_t interface_index, uint16_t kHz,
@ -151,9 +133,7 @@ RESULT usbtoi2c_read(uint8_t interface_index, uint16_t chip_addr,
RESULT usbtoi2c_write(uint8_t interface_index, uint16_t chip_addr, RESULT usbtoi2c_write(uint8_t interface_index, uint16_t chip_addr,
uint8_t *data, uint16_t data_len, uint8_t stop); uint8_t *data, uint16_t data_len, uint8_t stop);
/* USB_TO_MSP430_JTAG */
// USB_TO_MSP430_JTAG
RESULT usbtomsp430jtag_init(uint8_t interface_index); RESULT usbtomsp430jtag_init(uint8_t interface_index);
RESULT usbtomsp430jtag_fini(uint8_t interface_index); RESULT usbtomsp430jtag_fini(uint8_t interface_index);
RESULT usbtomsp430jtag_config(uint8_t interface_index, uint8_t has_test); RESULT usbtomsp430jtag_config(uint8_t interface_index, uint8_t has_test);
@ -168,9 +148,7 @@ RESULT usbtomsp430jtag_poll(uint8_t interface_index, uint32_t dr,
uint32_t mask, uint32_t value, uint8_t len, uint32_t mask, uint32_t value, uint8_t len,
uint16_t poll_cnt, uint8_t toggle_tclk); uint16_t poll_cnt, uint8_t toggle_tclk);
/* USB_TO_MSP430_SBW */
// USB_TO_MSP430_SBW
RESULT usbtomsp430sbw_init(uint8_t interface_index); RESULT usbtomsp430sbw_init(uint8_t interface_index);
RESULT usbtomsp430sbw_fini(uint8_t interface_index); RESULT usbtomsp430sbw_fini(uint8_t interface_index);
RESULT usbtomsp430sbw_config(uint8_t interface_index, uint8_t has_test); RESULT usbtomsp430sbw_config(uint8_t interface_index, uint8_t has_test);
@ -185,17 +163,13 @@ RESULT usbtomsp430sbw_poll(uint8_t interface_index, uint32_t dr, uint32_t mask,
uint32_t value, uint8_t len, uint16_t poll_cnt, uint32_t value, uint8_t len, uint16_t poll_cnt,
uint8_t toggle_tclk); uint8_t toggle_tclk);
/* USB_TO_POWER */
// USB_TO_POWER
RESULT usbtopwr_init(uint8_t interface_index); RESULT usbtopwr_init(uint8_t interface_index);
RESULT usbtopwr_fini(uint8_t interface_index); RESULT usbtopwr_fini(uint8_t interface_index);
RESULT usbtopwr_config(uint8_t interface_index); RESULT usbtopwr_config(uint8_t interface_index);
RESULT usbtopwr_output(uint8_t interface_index, uint16_t mV); RESULT usbtopwr_output(uint8_t interface_index, uint16_t mV);
/* USB_TO_POLL */
// USB_TO_POLL
RESULT usbtopoll_start(uint16_t retry_cnt, uint16_t interval_us); RESULT usbtopoll_start(uint16_t retry_cnt, uint16_t interval_us);
RESULT usbtopoll_end(void); RESULT usbtopoll_end(void);
RESULT usbtopoll_checkok(uint8_t equ, uint16_t offset, uint8_t size, RESULT usbtopoll_checkok(uint8_t equ, uint16_t offset, uint8_t size,
@ -204,9 +178,7 @@ RESULT usbtopoll_checkfail(uint8_t equ, uint16_t offset, uint8_t size,
uint32_t mask, uint32_t value); uint32_t mask, uint32_t value);
RESULT usbtopoll_verifybuff(uint16_t offset, uint16_t size, uint8_t *buff); RESULT usbtopoll_verifybuff(uint16_t offset, uint16_t size, uint8_t *buff);
/* USB_TO_SWD */
// USB_TO_SWD
RESULT usbtoswd_init(uint8_t interface_index); RESULT usbtoswd_init(uint8_t interface_index);
RESULT usbtoswd_fini(uint8_t interface_index); RESULT usbtoswd_fini(uint8_t interface_index);
RESULT usbtoswd_config(uint8_t interface_index, uint8_t trn, uint16_t retry, RESULT usbtoswd_config(uint8_t interface_index, uint8_t trn, uint16_t retry,
@ -216,9 +188,7 @@ RESULT usbtoswd_seqin(uint8_t interface_index, uint8_t *data, uint16_t bitlen);
RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request, RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request,
uint32_t *data, uint8_t *ack); uint32_t *data, uint8_t *ack);
/* USB_TO_SWIM */
// USB_TO_SWIM
RESULT usbtoswim_init(uint8_t interface_index); RESULT usbtoswim_init(uint8_t interface_index);
RESULT usbtoswim_fini(uint8_t interface_index); RESULT usbtoswim_fini(uint8_t interface_index);
RESULT usbtoswim_config(uint8_t interface_index, uint8_t mHz, uint8_t cnt0, RESULT usbtoswim_config(uint8_t interface_index, uint8_t mHz, uint8_t cnt0,
@ -231,28 +201,21 @@ RESULT usbtoswim_rotf(uint8_t interface_index, uint8_t *data,
RESULT usbtoswim_sync(uint8_t interface_index, uint8_t mHz); RESULT usbtoswim_sync(uint8_t interface_index, uint8_t mHz);
RESULT usbtoswim_enable(uint8_t interface_index); RESULT usbtoswim_enable(uint8_t interface_index);
/* USB_TO_BDM */
// USB_TO_BDM
RESULT usbtobdm_init(uint8_t interface_index); RESULT usbtobdm_init(uint8_t interface_index);
RESULT usbtobdm_fini(uint8_t interface_index); RESULT usbtobdm_fini(uint8_t interface_index);
RESULT usbtobdm_sync(uint8_t interface_index, uint16_t *khz); RESULT usbtobdm_sync(uint8_t interface_index, uint16_t *khz);
RESULT usbtobdm_transact(uint8_t interface_index, uint8_t *out, RESULT usbtobdm_transact(uint8_t interface_index, uint8_t *out,
uint8_t outlen, uint8_t *in, uint8_t inlen, uint8_t delay, uint8_t ack); uint8_t outlen, uint8_t *in, uint8_t inlen, uint8_t delay, uint8_t ack);
/* USB_TO_DUSI */
// USB_TO_DUSI
RESULT usbtodusi_init(uint8_t interface_index); RESULT usbtodusi_init(uint8_t interface_index);
RESULT usbtodusi_fini(uint8_t interface_index); RESULT usbtodusi_fini(uint8_t interface_index);
RESULT usbtodusi_config(uint8_t interface_index, uint32_t kHz, uint8_t mode); RESULT usbtodusi_config(uint8_t interface_index, uint32_t kHz, uint8_t mode);
RESULT usbtodusi_io(uint8_t interface_index, uint8_t *mo, uint8_t *mi, RESULT usbtodusi_io(uint8_t interface_index, uint8_t *mo, uint8_t *mi,
uint8_t *so, uint8_t *si, uint32_t bitlen); uint8_t *so, uint8_t *si, uint32_t bitlen);
/* USB_TO_MICROWIRE */
// USB_TO_MICROWIRE
RESULT usbtomicrowire_init(uint8_t interface_index); RESULT usbtomicrowire_init(uint8_t interface_index);
RESULT usbtomicrowire_fini(uint8_t interface_index); RESULT usbtomicrowire_fini(uint8_t interface_index);
RESULT usbtomicrowire_config(uint8_t interface_index, uint16_t kHz, RESULT usbtomicrowire_config(uint8_t interface_index, uint16_t kHz,
@ -265,9 +228,7 @@ RESULT usbtomicrowire_transport(uint8_t interface_index,
RESULT usbtomicrowire_poll(uint8_t interface_index, uint16_t interval_us, RESULT usbtomicrowire_poll(uint8_t interface_index, uint16_t interval_us,
uint16_t retry_cnt); uint16_t retry_cnt);
/* USB_TO_PWM */
// USB_TO_PWM
RESULT usbtopwm_init(uint8_t interface_index); RESULT usbtopwm_init(uint8_t interface_index);
RESULT usbtopwm_fini(uint8_t interface_index); RESULT usbtopwm_fini(uint8_t interface_index);
RESULT usbtopwm_config(uint8_t interface_index, uint16_t kHz, uint8_t mode); RESULT usbtopwm_config(uint8_t interface_index, uint16_t kHz, uint8_t mode);
@ -275,4 +236,3 @@ RESULT usbtopwm_out(uint8_t interface_index, uint16_t count, uint16_t *rate);
RESULT usbtopwm_in(uint8_t interface_index, uint16_t count, uint16_t *rate); RESULT usbtopwm_in(uint8_t interface_index, uint16_t count, uint16_t *rate);
#endif /* __USBTOXXX_H_INCLUDED__ */ #endif /* __USBTOXXX_H_INCLUDED__ */

View File

@ -16,11 +16,12 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef __USBTOXXX_INTERNAL_H_INCLUDED__ #ifndef __USBTOXXX_INTERNAL_H_INCLUDED__
#define __USBTOXXX_INTERNAL_H_INCLUDED__ #define __USBTOXXX_INTERNAL_H_INCLUDED__
// USB_TO_XXX USB Commands /* USB_TO_XXX USB Commands */
// Page0 /* Page0 */
#define USB_TO_USART (VERSALOON_USB_TO_XXX_CMD_START + 0x00) #define USB_TO_USART (VERSALOON_USB_TO_XXX_CMD_START + 0x00)
#define USB_TO_SPI (VERSALOON_USB_TO_XXX_CMD_START + 0x01) #define USB_TO_SPI (VERSALOON_USB_TO_XXX_CMD_START + 0x01)
#define USB_TO_I2C (VERSALOON_USB_TO_XXX_CMD_START + 0x02) #define USB_TO_I2C (VERSALOON_USB_TO_XXX_CMD_START + 0x02)
@ -32,7 +33,7 @@
#define USB_TO_MICROWIRE (VERSALOON_USB_TO_XXX_CMD_START + 0x08) #define USB_TO_MICROWIRE (VERSALOON_USB_TO_XXX_CMD_START + 0x08)
#define USB_TO_SWIM (VERSALOON_USB_TO_XXX_CMD_START + 0x09) #define USB_TO_SWIM (VERSALOON_USB_TO_XXX_CMD_START + 0x09)
#define USB_TO_DUSI (VERSALOON_USB_TO_XXX_CMD_START + 0x0A) #define USB_TO_DUSI (VERSALOON_USB_TO_XXX_CMD_START + 0x0A)
// Page1 /* Page1 */
#define USB_TO_JTAG_LL (VERSALOON_USB_TO_XXX_CMD_START + 0x20) #define USB_TO_JTAG_LL (VERSALOON_USB_TO_XXX_CMD_START + 0x20)
#define USB_TO_JTAG_HL (VERSALOON_USB_TO_XXX_CMD_START + 0x21) #define USB_TO_JTAG_HL (VERSALOON_USB_TO_XXX_CMD_START + 0x21)
#define USB_TO_ISSP (VERSALOON_USB_TO_XXX_CMD_START + 0x22) #define USB_TO_ISSP (VERSALOON_USB_TO_XXX_CMD_START + 0x22)
@ -43,21 +44,19 @@
#define USB_TO_JTAG_RAW (VERSALOON_USB_TO_XXX_CMD_START + 0x27) #define USB_TO_JTAG_RAW (VERSALOON_USB_TO_XXX_CMD_START + 0x27)
#define USB_TO_BDM (VERSALOON_USB_TO_XXX_CMD_START + 0x28) #define USB_TO_BDM (VERSALOON_USB_TO_XXX_CMD_START + 0x28)
#define USB_TO_MSP430_JTAG (VERSALOON_USB_TO_XXX_CMD_START + 0x38) #define USB_TO_MSP430_JTAG (VERSALOON_USB_TO_XXX_CMD_START + 0x38)
// Page2 /* Page2 */
#define USB_TO_POWER (VERSALOON_USB_TO_XXX_CMD_START + 0x40) #define USB_TO_POWER (VERSALOON_USB_TO_XXX_CMD_START + 0x40)
#define USB_TO_DELAY (VERSALOON_USB_TO_XXX_CMD_START + 0x41) #define USB_TO_DELAY (VERSALOON_USB_TO_XXX_CMD_START + 0x41)
#define USB_TO_POLL (VERSALOON_USB_TO_XXX_CMD_START + 0x42) #define USB_TO_POLL (VERSALOON_USB_TO_XXX_CMD_START + 0x42)
#define USB_TO_INFO (VERSALOON_USB_TO_XXX_CMD_START + 0x5E) #define USB_TO_INFO (VERSALOON_USB_TO_XXX_CMD_START + 0x5E)
#define USB_TO_ALL (VERSALOON_USB_TO_XXX_CMD_START + 0x5F) #define USB_TO_ALL (VERSALOON_USB_TO_XXX_CMD_START + 0x5F)
/* USB_TO_XXX Masks */
// USB_TO_XXX Masks
#define USB_TO_XXX_CMDMASK 0xF8 #define USB_TO_XXX_CMDMASK 0xF8
#define USB_TO_XXX_CMDSHIFT 3 #define USB_TO_XXX_CMDSHIFT 3
#define USB_TO_XXX_IDXMASK 0x07 #define USB_TO_XXX_IDXMASK 0x07
// USB_TO_XXX Sub Commands /* USB_TO_XXX Sub Commands */
// Common Sub Commands /* Common Sub Commands */
#define USB_TO_XXX_INIT (0x00 << USB_TO_XXX_CMDSHIFT) #define USB_TO_XXX_INIT (0x00 << USB_TO_XXX_CMDSHIFT)
#define USB_TO_XXX_FINI (0x01 << USB_TO_XXX_CMDSHIFT) #define USB_TO_XXX_FINI (0x01 << USB_TO_XXX_CMDSHIFT)
#define USB_TO_XXX_CONFIG (0x02 << USB_TO_XXX_CMDSHIFT) #define USB_TO_XXX_CONFIG (0x02 << USB_TO_XXX_CMDSHIFT)
@ -72,16 +71,14 @@
#define USB_TO_XXX_SYNC (0x0B << USB_TO_XXX_CMDSHIFT) #define USB_TO_XXX_SYNC (0x0B << USB_TO_XXX_CMDSHIFT)
#define USB_TO_XXX_ENABLE (0x0C << USB_TO_XXX_CMDSHIFT) #define USB_TO_XXX_ENABLE (0x0C << USB_TO_XXX_CMDSHIFT)
#define USB_TO_XXX_DISABLE (0x0D << USB_TO_XXX_CMDSHIFT) #define USB_TO_XXX_DISABLE (0x0D << USB_TO_XXX_CMDSHIFT)
// USB_TO_POLL /* USB_TO_POLL */
#define USB_TO_POLL_START 0x00 #define USB_TO_POLL_START 0x00
#define USB_TO_POLL_END 0x01 #define USB_TO_POLL_END 0x01
#define USB_TO_POLL_CHECKOK 0x02 #define USB_TO_POLL_CHECKOK 0x02
#define USB_TO_POLL_CHECKFAIL 0x03 #define USB_TO_POLL_CHECKFAIL 0x03
#define USB_TO_POLL_VERIFYBUFF 0x04 #define USB_TO_POLL_VERIFYBUFF 0x04
/* USB_TO_XXX Replys */
// USB_TO_XXX Replys
#define USB_TO_XXX_OK 0x00 #define USB_TO_XXX_OK 0x00
#define USB_TO_XXX_FAILED 0x01 #define USB_TO_XXX_FAILED 0x01
#define USB_TO_XXX_TIME_OUT 0x02 #define USB_TO_XXX_TIME_OUT 0x02
@ -90,9 +87,7 @@
#define USB_TO_XXX_INVALID_CMD 0x05 #define USB_TO_XXX_INVALID_CMD 0x05
#define USB_TO_XXX_CMD_NOT_SUPPORT 0x06 #define USB_TO_XXX_CMD_NOT_SUPPORT 0x06
/* USB_TO_XXX */
// USB_TO_XXX
RESULT usbtoxxx_add_pending(uint8_t type, uint8_t cmd, uint16_t RESULT usbtoxxx_add_pending(uint8_t type, uint8_t cmd, uint16_t
actual_szie, uint16_t want_pos, actual_szie, uint16_t want_pos,
uint16_t want_size, uint8_t *buffer); uint16_t want_size, uint8_t *buffer);
@ -125,9 +120,9 @@ RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf,
usbtoxxx_add_command((type), (USB_TO_XXX_OUT | (port)), (cmdbuf), \ usbtoxxx_add_command((type), (USB_TO_XXX_OUT | (port)), (cmdbuf), \
(cmdlen), 0, NULL, 0, 0, (c)) (cmdlen), 0, NULL, 0, 0, (c))
#define usbtoxxx_poll_command(type, port, cmdbuf, cmdlen, retbuf, retlen) \ #define usbtoxxx_poll_command(type, port, cmdbuf, cmdlen, retbuf, retlen) \
usbtoxxx_add_command((type), (USB_TO_XXX_POLL | (port)), (cmdbuf),\ usbtoxxx_add_command((type), (USB_TO_XXX_POLL | (port)), (cmdbuf), \
(cmdlen), (retlen), (retbuf), 0, (retlen), 0) (cmdlen), (retlen), (retbuf), 0, (retlen), 0)
#define usbtoxxx_status_command(type, port, retlen, wantbuf, wantpos, wantlen, c)\ #define usbtoxxx_status_command(type, port, retlen, wantbuf, wantpos, wantlen, c) \
usbtoxxx_add_command((type), (USB_TO_XXX_STATUS | (port)), \ usbtoxxx_add_command((type), (USB_TO_XXX_STATUS | (port)), \
NULL, 0, (retlen), (wantbuf), (wantpos), \ NULL, 0, (retlen), (wantbuf), (wantpos), \
(wantlen), (c)) (wantlen), (c))
@ -150,20 +145,19 @@ RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf,
usbtoxxx_add_command((type), (USB_TO_XXX_DISABLE | (port)), \ usbtoxxx_add_command((type), (USB_TO_XXX_DISABLE | (port)), \
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0) (cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
// USB_TO_SPI /* USB_TO_SPI */
#define USB_TO_SPI_BAUDRATE_MSK 0x1F #define USB_TO_SPI_BAUDRATE_MSK 0x1F
#define USB_TO_SPI_CPOL_MSK 0x20 #define USB_TO_SPI_CPOL_MSK 0x20
#define USB_TO_SPI_CPHA_MSK 0x40 #define USB_TO_SPI_CPHA_MSK 0x40
#define USB_TO_SPI_MSB_FIRST 0x80 #define USB_TO_SPI_MSB_FIRST 0x80
// USB_TO_DUSI /* USB_TO_DUSI */
#define USB_TO_DUSI_BAUDRATE_MSK 0x1F #define USB_TO_DUSI_BAUDRATE_MSK 0x1F
#define USB_TO_DUSI_CPOL_MSK 0x20 #define USB_TO_DUSI_CPOL_MSK 0x20
#define USB_TO_DUSI_CPHA_MSK 0x40 #define USB_TO_DUSI_CPHA_MSK 0x40
#define USB_TO_DUSI_MSB_FIRST 0x80 #define USB_TO_DUSI_MSB_FIRST 0x80
// USB_TO_GPIO /* USB_TO_GPIO */
#define USB_TO_GPIO_DIR_MSK 0x01 #define USB_TO_GPIO_DIR_MSK 0x01
#endif /* __USBTOXXX_INTERNAL_H_INCLUDED__ */ #endif /* __USBTOXXX_INTERNAL_H_INCLUDED__ */

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -28,14 +29,14 @@
#include "versaloon_internal.h" #include "versaloon_internal.h"
#include "usbtoxxx/usbtoxxx.h" #include "usbtoxxx/usbtoxxx.h"
uint8_t *versaloon_buf = NULL; uint8_t *versaloon_buf;
uint8_t *versaloon_cmd_buf = NULL; uint8_t *versaloon_cmd_buf;
uint16_t versaloon_buf_size; uint16_t versaloon_buf_size;
struct versaloon_pending_t versaloon_pending[VERSALOON_MAX_PENDING_NUMBER]; struct versaloon_pending_t versaloon_pending[VERSALOON_MAX_PENDING_NUMBER];
uint16_t versaloon_pending_idx = 0; uint16_t versaloon_pending_idx;
usb_dev_handle *versaloon_usb_device_handle = NULL; usb_dev_handle *versaloon_usb_device_handle;
static uint32_t versaloon_usb_to = VERSALOON_TIMEOUT; static uint32_t versaloon_usb_to = VERSALOON_TIMEOUT;
RESULT versaloon_init(void); RESULT versaloon_init(void);
@ -44,27 +45,27 @@ RESULT versaloon_get_target_voltage(uint16_t *voltage);
RESULT versaloon_set_target_voltage(uint16_t voltage); RESULT versaloon_set_target_voltage(uint16_t voltage);
RESULT versaloon_delay_ms(uint16_t ms); RESULT versaloon_delay_ms(uint16_t ms);
RESULT versaloon_delay_us(uint16_t us); RESULT versaloon_delay_us(uint16_t us);
struct versaloon_interface_t versaloon_interface =
{ struct versaloon_interface_t versaloon_interface = {
.init = versaloon_init, .init = versaloon_init,
.fini = versaloon_fini, .fini = versaloon_fini,
{// adaptors { /* adaptors */
{// target_voltage { /* target_voltage */
.get = versaloon_get_target_voltage, .get = versaloon_get_target_voltage,
.set = versaloon_set_target_voltage, .set = versaloon_set_target_voltage,
}, },
{// gpio { /* gpio */
.init = usbtogpio_init, .init = usbtogpio_init,
.fini = usbtogpio_fini, .fini = usbtogpio_fini,
.config = usbtogpio_config, .config = usbtogpio_config,
.out = usbtogpio_out, .out = usbtogpio_out,
.in = usbtogpio_in, .in = usbtogpio_in,
}, },
{// delay { /* delay */
.delayms = versaloon_delay_ms, .delayms = versaloon_delay_ms,
.delayus = versaloon_delay_us, .delayus = versaloon_delay_us,
}, },
{// swd { /* swd */
.init = usbtoswd_init, .init = usbtoswd_init,
.fini = usbtoswd_fini, .fini = usbtoswd_fini,
.config = usbtoswd_config, .config = usbtoswd_config,
@ -72,7 +73,7 @@ struct versaloon_interface_t versaloon_interface =
.seqin = usbtoswd_seqin, .seqin = usbtoswd_seqin,
.transact = usbtoswd_transact, .transact = usbtoswd_transact,
}, },
{// jtag_raw { /* jtag_raw */
.init = usbtojtagraw_init, .init = usbtojtagraw_init,
.fini = usbtojtagraw_fini, .fini = usbtojtagraw_fini,
.config = usbtojtagraw_config, .config = usbtojtagraw_config,
@ -80,7 +81,7 @@ struct versaloon_interface_t versaloon_interface =
}, },
.peripheral_commit = usbtoxxx_execute_command, .peripheral_commit = usbtoxxx_execute_command,
}, },
{// usb_setting { /* usb_setting */
.vid = VERSALOON_VID, .vid = VERSALOON_VID,
.pid = VERSALOON_PID, .pid = VERSALOON_PID,
.ep_out = VERSALOON_OUTP, .ep_out = VERSALOON_OUTP,
@ -91,11 +92,12 @@ struct versaloon_interface_t versaloon_interface =
} }
}; };
// programmer_cmd /* programmer_cmd */
static uint32_t versaloon_pending_id = 0; static uint32_t versaloon_pending_id;
static versaloon_callback_t versaloon_callback = NULL; static versaloon_callback_t versaloon_callback;
static void *versaloon_extra_data = NULL; static void *versaloon_extra_data;
static struct versaloon_want_pos_t *versaloon_want_pos = NULL; static struct versaloon_want_pos_t *versaloon_want_pos;
void versaloon_set_pending_id(uint32_t id) void versaloon_set_pending_id(uint32_t id)
{ {
versaloon_pending_id = id; versaloon_pending_id = id;
@ -104,7 +106,7 @@ void versaloon_set_callback(versaloon_callback_t callback)
{ {
versaloon_callback = callback; versaloon_callback = callback;
} }
void versaloon_set_extra_data(void * p) void versaloon_set_extra_data(void *p)
{ {
versaloon_extra_data = p; versaloon_extra_data = p;
} }
@ -115,19 +117,16 @@ void versaloon_free_want_pos(void)
struct versaloon_want_pos_t *tmp, *free_tmp; struct versaloon_want_pos_t *tmp, *free_tmp;
tmp = versaloon_want_pos; tmp = versaloon_want_pos;
while (tmp != NULL) while (tmp != NULL) {
{
free_tmp = tmp; free_tmp = tmp;
tmp = tmp->next; tmp = tmp->next;
free(free_tmp); free(free_tmp);
} }
versaloon_want_pos = NULL; versaloon_want_pos = NULL;
for (i = 0; i < dimof(versaloon_pending); i++) for (i = 0; i < dimof(versaloon_pending); i++) {
{
tmp = versaloon_pending[i].pos; tmp = versaloon_pending[i].pos;
while (tmp != NULL) while (tmp != NULL) {
{
free_tmp = tmp; free_tmp = tmp;
tmp = tmp->next; tmp = tmp->next;
free(free_tmp); free(free_tmp);
@ -141,8 +140,7 @@ RESULT versaloon_add_want_pos(uint16_t offset, uint16_t size, uint8_t *buff)
struct versaloon_want_pos_t *new_pos = NULL; struct versaloon_want_pos_t *new_pos = NULL;
new_pos = (struct versaloon_want_pos_t *)malloc(sizeof(*new_pos)); new_pos = (struct versaloon_want_pos_t *)malloc(sizeof(*new_pos));
if (NULL == new_pos) if (NULL == new_pos) {
{
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
} }
@ -152,17 +150,12 @@ RESULT versaloon_add_want_pos(uint16_t offset, uint16_t size, uint8_t *buff)
new_pos->next = NULL; new_pos->next = NULL;
if (NULL == versaloon_want_pos) if (NULL == versaloon_want_pos)
{
versaloon_want_pos = new_pos; versaloon_want_pos = new_pos;
} else {
else
{
struct versaloon_want_pos_t *tmp = versaloon_want_pos; struct versaloon_want_pos_t *tmp = versaloon_want_pos;
while (tmp->next != NULL) while (tmp->next != NULL)
{
tmp = tmp->next; tmp = tmp->next;
}
tmp->next = new_pos; tmp->next = new_pos;
} }
@ -173,8 +166,7 @@ RESULT versaloon_add_pending(uint8_t type, uint8_t cmd, uint16_t actual_szie,
uint16_t want_pos, uint16_t want_size, uint8_t *buffer, uint8_t collect) uint16_t want_pos, uint16_t want_size, uint8_t *buffer, uint8_t collect)
{ {
#if PARAM_CHECK #if PARAM_CHECK
if (versaloon_pending_idx >= VERSALOON_MAX_PENDING_NUMBER) if (versaloon_pending_idx >= VERSALOON_MAX_PENDING_NUMBER) {
{
LOG_BUG(ERRMSG_INVALID_INDEX, versaloon_pending_idx, LOG_BUG(ERRMSG_INVALID_INDEX, versaloon_pending_idx,
"versaloon pending data"); "versaloon pending data");
return ERROR_FAIL; return ERROR_FAIL;
@ -206,14 +198,12 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen)
int ret; int ret;
#if PARAM_CHECK #if PARAM_CHECK
if (NULL == versaloon_buf) if (NULL == versaloon_buf) {
{
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf)); LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER; return ERRCODE_INVALID_BUFFER;
} }
if ((0 == out_len) || (out_len > versaloon_interface.usb_setting.buf_size)) if ((0 == out_len) || (out_len > versaloon_interface.usb_setting.buf_size)) {
{ LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
return ERRCODE_INVALID_PARAMETER; return ERRCODE_INVALID_PARAMETER;
} }
#endif #endif
@ -221,34 +211,26 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen)
ret = usb_bulk_write(versaloon_usb_device_handle, ret = usb_bulk_write(versaloon_usb_device_handle,
versaloon_interface.usb_setting.ep_out, (char *)versaloon_buf, versaloon_interface.usb_setting.ep_out, (char *)versaloon_buf,
out_len, versaloon_usb_to); out_len, versaloon_usb_to);
if (ret != out_len) if (ret != out_len) {
{
LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "send usb data", LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "send usb data",
usb_strerror()); usb_strerror());
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} }
if (inlen != NULL) if (inlen != NULL) {
{
ret = usb_bulk_read(versaloon_usb_device_handle, ret = usb_bulk_read(versaloon_usb_device_handle,
versaloon_interface.usb_setting.ep_in, (char *)versaloon_buf, versaloon_interface.usb_setting.ep_in, (char *)versaloon_buf,
versaloon_interface.usb_setting.buf_size, versaloon_usb_to); versaloon_interface.usb_setting.buf_size, versaloon_usb_to);
if (ret > 0) if (ret > 0) {
{
*inlen = (uint16_t)ret; *inlen = (uint16_t)ret;
return ERROR_OK; return ERROR_OK;
} } else {
else
{
LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "receive usb data", LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "receive usb data",
usb_strerror()); usb_strerror());
return ERROR_FAIL; return ERROR_FAIL;
} }
} } else
else
{
return ERROR_OK; return ERROR_OK;
}
} }
#define VERSALOON_RETRY_CNT 10 #define VERSALOON_RETRY_CNT 10
@ -258,31 +240,26 @@ RESULT versaloon_init(void)
uint8_t retry; uint8_t retry;
uint32_t timeout_tmp; uint32_t timeout_tmp;
// malloc temporary buffer /* malloc temporary buffer */
versaloon_buf = versaloon_buf =
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size); (uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
if (NULL == versaloon_buf) if (NULL == versaloon_buf) {
{
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
} }
// connect to versaloon /* connect to versaloon */
timeout_tmp = versaloon_usb_to; timeout_tmp = versaloon_usb_to;
// not output error message when connectting /* not output error message when connectting */
// 100ms delay when connect /* 100ms delay when connect */
versaloon_usb_to = 100; versaloon_usb_to = 100;
for (retry = 0; retry < VERSALOON_RETRY_CNT; retry++) for (retry = 0; retry < VERSALOON_RETRY_CNT; retry++) {
{
versaloon_buf[0] = VERSALOON_GET_INFO; versaloon_buf[0] = VERSALOON_GET_INFO;
if ((ERROR_OK == versaloon_send_command(1, &ret)) && (ret >= 3)) if ((ERROR_OK == versaloon_send_command(1, &ret)) && (ret >= 3))
{
break; break;
} }
}
versaloon_usb_to = timeout_tmp; versaloon_usb_to = timeout_tmp;
if (VERSALOON_RETRY_CNT == retry) if (VERSALOON_RETRY_CNT == retry) {
{
versaloon_fini(); versaloon_fini();
LOG_ERROR(ERRMSG_FAILURE_OPERATION, "communicate with versaloon"); LOG_ERROR(ERRMSG_FAILURE_OPERATION, "communicate with versaloon");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
@ -293,28 +270,25 @@ RESULT versaloon_init(void)
versaloon_interface.usb_setting.buf_size = versaloon_buf_size; versaloon_interface.usb_setting.buf_size = versaloon_buf_size;
LOG_INFO("%s", versaloon_buf + 2); LOG_INFO("%s", versaloon_buf + 2);
// free temporary buffer /* free temporary buffer */
free(versaloon_buf); free(versaloon_buf);
versaloon_buf = NULL; versaloon_buf = NULL;
versaloon_buf = versaloon_buf =
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size); (uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
if (NULL == versaloon_buf) if (NULL == versaloon_buf) {
{
versaloon_fini(); versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
} }
versaloon_cmd_buf = versaloon_cmd_buf =
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size - 3); (uint8_t *)malloc(versaloon_interface.usb_setting.buf_size - 3);
if (NULL == versaloon_cmd_buf) if (NULL == versaloon_cmd_buf) {
{
versaloon_fini(); versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
} }
if (ERROR_OK != usbtoxxx_init()) if (ERROR_OK != usbtoxxx_init()) {
{
LOG_ERROR(ERRMSG_FAILURE_OPERATION, "initialize usbtoxxx"); LOG_ERROR(ERRMSG_FAILURE_OPERATION, "initialize usbtoxxx");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -323,20 +297,17 @@ RESULT versaloon_init(void)
RESULT versaloon_fini(void) RESULT versaloon_fini(void)
{ {
if (versaloon_usb_device_handle != NULL) if (versaloon_usb_device_handle != NULL) {
{
usbtoxxx_fini(); usbtoxxx_fini();
versaloon_free_want_pos(); versaloon_free_want_pos();
versaloon_usb_device_handle = NULL; versaloon_usb_device_handle = NULL;
if (versaloon_buf != NULL) if (versaloon_buf != NULL) {
{
free(versaloon_buf); free(versaloon_buf);
versaloon_buf = NULL; versaloon_buf = NULL;
} }
if (versaloon_cmd_buf != NULL) if (versaloon_cmd_buf != NULL) {
{
free(versaloon_cmd_buf); free(versaloon_cmd_buf);
versaloon_cmd_buf = NULL; versaloon_cmd_buf = NULL;
} }
@ -360,27 +331,22 @@ RESULT versaloon_get_target_voltage(uint16_t *voltage)
uint16_t inlen; uint16_t inlen;
#if PARAM_CHECK #if PARAM_CHECK
if (NULL == versaloon_buf) if (NULL == versaloon_buf) {
{
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf)); LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
return ERRCODE_INVALID_BUFFER; return ERRCODE_INVALID_BUFFER;
} }
if (NULL == voltage) if (NULL == voltage) {
{ LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
return ERRCODE_INVALID_PARAMETER; return ERRCODE_INVALID_PARAMETER;
} }
#endif #endif
versaloon_buf[0] = VERSALOON_GET_TVCC; versaloon_buf[0] = VERSALOON_GET_TVCC;
if ((ERROR_OK != versaloon_send_command(1, &inlen)) || (inlen != 2)) if ((ERROR_OK != versaloon_send_command(1, &inlen)) || (inlen != 2)) {
{
LOG_ERROR(ERRMSG_FAILURE_OPERATION, "communicate with versaloon"); LOG_ERROR(ERRMSG_FAILURE_OPERATION, "communicate with versaloon");
return ERRCODE_FAILURE_OPERATION; return ERRCODE_FAILURE_OPERATION;
} } else {
else
{
*voltage = versaloon_buf[0] + (versaloon_buf[1] << 8); *voltage = versaloon_buf[0] + (versaloon_buf[1] << 8);
return ERROR_OK; return ERROR_OK;
} }
@ -395,4 +361,3 @@ RESULT versaloon_delay_us(uint16_t us)
{ {
return usbtodelay_delay(us & 0x7FFF); return usbtodelay_delay(us & 0x7FFF);
} }

View File

@ -16,11 +16,11 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef __VERSALOON_H_INCLUDED__ #ifndef __VERSALOON_H_INCLUDED__
#define __VERSALOON_H_INCLUDED__ #define __VERSALOON_H_INCLUDED__
struct usart_status_t struct usart_status_t {
{
uint32_t tx_buff_avail; uint32_t tx_buff_avail;
uint32_t tx_buff_size; uint32_t tx_buff_size;
uint32_t rx_buff_avail; uint32_t rx_buff_avail;
@ -29,7 +29,7 @@ struct usart_status_t
#include "usbtoxxx/usbtoxxx.h" #include "usbtoxxx/usbtoxxx.h"
// GPIO pins /* GPIO pins */
#define GPIO_SRST (1 << 0) #define GPIO_SRST (1 << 0)
#define GPIO_TRST (1 << 1) #define GPIO_TRST (1 << 1)
#define GPIO_USR1 (1 << 2) #define GPIO_USR1 (1 << 2)
@ -39,61 +39,55 @@ struct usart_status_t
#define GPIO_TDI (1 << 6) #define GPIO_TDI (1 << 6)
#define GPIO_RTCK (1 << 7) #define GPIO_RTCK (1 << 7)
#define GPIO_TMS (1 << 8) #define GPIO_TMS (1 << 8)
struct interface_gpio_t
{ struct interface_gpio_t {
RESULT (*init)(uint8_t interface_index); RESULT(*init)(uint8_t interface_index);
RESULT (*fini)(uint8_t interface_index); RESULT(*fini)(uint8_t interface_index);
RESULT (*config)(uint8_t interface_index, uint32_t pin_mask, uint32_t io, RESULT(*config)(uint8_t interface_index, uint32_t pin_mask, uint32_t io,
uint32_t pull_en_mask, uint32_t input_pull_mask); uint32_t pull_en_mask, uint32_t input_pull_mask);
RESULT (*out)(uint8_t interface_index, uint32_t pin_mask, uint32_t value); RESULT(*out)(uint8_t interface_index, uint32_t pin_mask, uint32_t value);
RESULT (*in)(uint8_t interface_index, uint32_t pin_mask, uint32_t *value); RESULT(*in)(uint8_t interface_index, uint32_t pin_mask, uint32_t *value);
}; };
struct interface_delay_t struct interface_delay_t {
{ RESULT(*delayms)(uint16_t ms);
RESULT (*delayms)(uint16_t ms); RESULT(*delayus)(uint16_t us);
RESULT (*delayus)(uint16_t us);
}; };
struct interface_swd_t struct interface_swd_t {
{ RESULT(*init)(uint8_t interface_index);
RESULT (*init)(uint8_t interface_index); RESULT(*fini)(uint8_t interface_index);
RESULT (*fini)(uint8_t interface_index); RESULT(*config)(uint8_t interface_index, uint8_t trn, uint16_t retry,
RESULT (*config)(uint8_t interface_index, uint8_t trn, uint16_t retry,
uint16_t dly); uint16_t dly);
RESULT (*seqout)(uint8_t interface_index, uint8_t *data, uint16_t bitlen); RESULT(*seqout)(uint8_t interface_index, uint8_t *data, uint16_t bitlen);
RESULT (*seqin)(uint8_t interface_index, uint8_t *data, uint16_t bitlen); RESULT(*seqin)(uint8_t interface_index, uint8_t *data, uint16_t bitlen);
RESULT (*transact)(uint8_t interface_index, uint8_t request, RESULT(*transact)(uint8_t interface_index, uint8_t request,
uint32_t *data, uint8_t *ack); uint32_t *data, uint8_t *ack);
}; };
struct interface_jtag_raw_t struct interface_jtag_raw_t {
{ RESULT(*init)(uint8_t interface_index);
RESULT (*init)(uint8_t interface_index); RESULT(*fini)(uint8_t interface_index);
RESULT (*fini)(uint8_t interface_index); RESULT(*config)(uint8_t interface_index, uint32_t kHz);
RESULT (*config)(uint8_t interface_index, uint32_t kHz); RESULT(*execute)(uint8_t interface_index, uint8_t *tdi, uint8_t *tms,
RESULT (*execute)(uint8_t interface_index, uint8_t* tdi, uint8_t* tms,
uint8_t *tdo, uint32_t bitlen); uint8_t *tdo, uint32_t bitlen);
}; };
struct interface_target_voltage_t struct interface_target_voltage_t {
{ RESULT(*get)(uint16_t *voltage);
RESULT (*get)(uint16_t *voltage); RESULT(*set)(uint16_t voltage);
RESULT (*set)(uint16_t voltage);
}; };
struct versaloon_adaptors_t struct versaloon_adaptors_t {
{
struct interface_target_voltage_t target_voltage; struct interface_target_voltage_t target_voltage;
struct interface_gpio_t gpio; struct interface_gpio_t gpio;
struct interface_delay_t delay; struct interface_delay_t delay;
struct interface_swd_t swd; struct interface_swd_t swd;
struct interface_jtag_raw_t jtag_raw; struct interface_jtag_raw_t jtag_raw;
RESULT (*peripheral_commit)(void); RESULT(*peripheral_commit)(void);
}; };
struct versaloon_usb_setting_t struct versaloon_usb_setting_t {
{
uint16_t vid; uint16_t vid;
uint16_t pid; uint16_t pid;
uint8_t ep_out; uint8_t ep_out;
@ -104,10 +98,9 @@ struct versaloon_usb_setting_t
uint16_t buf_size; uint16_t buf_size;
}; };
struct versaloon_interface_t struct versaloon_interface_t {
{ RESULT(*init)(void);
RESULT (*init)(void); RESULT(*fini)(void);
RESULT (*fini)(void);
struct versaloon_adaptors_t adaptors; struct versaloon_adaptors_t adaptors;
struct versaloon_usb_setting_t usb_setting; struct versaloon_usb_setting_t usb_setting;
}; };

View File

@ -16,8 +16,9 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// This file is used to include different header and macros
// according to different platform /* This file is used to include different header and macros */
/* according to different platform */
#include <jtag/interface.h> #include <jtag/interface.h>
#include <jtag/commands.h> #include <jtag/commands.h>
#include "usb_common.h" #include "usb_common.h"
@ -31,7 +32,7 @@
#define RESULT int #define RESULT int
#define LOG_BUG LOG_ERROR #define LOG_BUG LOG_ERROR
// Common error messages /* Common error messages */
#define ERRMSG_NOT_ENOUGH_MEMORY "Lack of memory." #define ERRMSG_NOT_ENOUGH_MEMORY "Lack of memory."
#define ERRCODE_NOT_ENOUGH_MEMORY ERROR_FAIL #define ERRCODE_NOT_ENOUGH_MEMORY ERROR_FAIL
@ -52,38 +53,38 @@
#define ERRMSG_FAILURE_OPERATION_MESSAGE "Fail to %s, %s" #define ERRMSG_FAILURE_OPERATION_MESSAGE "Fail to %s, %s"
#define ERRCODE_FAILURE_OPERATION ERROR_FAIL #define ERRCODE_FAILURE_OPERATION ERROR_FAIL
#define GET_U16_MSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 8) | \ #define GET_U16_MSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 8) | \
((*((uint8_t *)(p) + 1)) << 0)) ((*((uint8_t *)(p) + 1)) << 0))
#define GET_U32_MSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 24) | \ #define GET_U32_MSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 24) | \
((*((uint8_t *)(p) + 1)) << 16) | \ ((*((uint8_t *)(p) + 1)) << 16) | \
((*((uint8_t *)(p) + 2)) << 8) | \ ((*((uint8_t *)(p) + 2)) << 8) | \
((*((uint8_t *)(p) + 3)) << 0)) ((*((uint8_t *)(p) + 3)) << 0))
#define GET_U16_LSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 0) | \ #define GET_U16_LSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 0) | \
((*((uint8_t *)(p) + 1)) << 8)) ((*((uint8_t *)(p) + 1)) << 8))
#define GET_U32_LSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 0) | \ #define GET_U32_LSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 0) | \
((*((uint8_t *)(p) + 1)) << 8) | \ ((*((uint8_t *)(p) + 1)) << 8) | \
((*((uint8_t *)(p) + 2)) << 16) | \ ((*((uint8_t *)(p) + 2)) << 16) | \
((*((uint8_t *)(p) + 3)) << 24)) ((*((uint8_t *)(p) + 3)) << 24))
#define SET_U16_MSBFIRST(p, v) \ #define SET_U16_MSBFIRST(p, v) \
do{\ do {\
*((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 8) & 0xFF;\ *((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 8) & 0xFF;\
*((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 0) & 0xFF;\ *((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 0) & 0xFF;\
} while (0) } while (0)
#define SET_U32_MSBFIRST(p, v) \ #define SET_U32_MSBFIRST(p, v) \
do{\ do {\
*((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 24) & 0xFF;\ *((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 24) & 0xFF;\
*((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 16) & 0xFF;\ *((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 16) & 0xFF;\
*((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 8) & 0xFF;\ *((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 8) & 0xFF;\
*((uint8_t *)(p) + 3) = (((uint32_t)(v)) >> 0) & 0xFF;\ *((uint8_t *)(p) + 3) = (((uint32_t)(v)) >> 0) & 0xFF;\
} while (0) } while (0)
#define SET_U16_LSBFIRST(p, v) \ #define SET_U16_LSBFIRST(p, v) \
do{\ do {\
*((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 0) & 0xFF;\ *((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 0) & 0xFF;\
*((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 8) & 0xFF;\ *((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 8) & 0xFF;\
} while (0) } while (0)
#define SET_U32_LSBFIRST(p, v) \ #define SET_U32_LSBFIRST(p, v) \
do{\ do {\
*((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 0) & 0xFF;\ *((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 0) & 0xFF;\
*((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 8) & 0xFF;\ *((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 8) & 0xFF;\
*((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 16) & 0xFF;\ *((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 16) & 0xFF;\

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef __VERSALOON_INTERNAL_H_INCLUDED__ #ifndef __VERSALOON_INTERNAL_H_INCLUDED__
#define __VERSALOON_INTERNAL_H_INCLUDED__ #define __VERSALOON_INTERNAL_H_INCLUDED__
@ -37,8 +38,8 @@
#define VERSALOON_TIMEOUT 5000 #define VERSALOON_TIMEOUT 5000
#define VERSALOON_TIMEOUT_LONG 60000 #define VERSALOON_TIMEOUT_LONG 60000
// USB Commands /* USB Commands */
// Common Commands /* Common Commands */
#define VERSALOON_COMMON_CMD_START 0x00 #define VERSALOON_COMMON_CMD_START 0x00
#define VERSALOON_COMMON_CMD_END 0x0F #define VERSALOON_COMMON_CMD_END 0x0F
@ -52,40 +53,34 @@
#define VERSALOON_FW_UPDATE 0x0F #define VERSALOON_FW_UPDATE 0x0F
#define VERSALOON_FW_UPDATE_KEY 0xAA #define VERSALOON_FW_UPDATE_KEY 0xAA
// MCU Command /* MCU Command */
#define VERSALOON_MCU_CMD_START 0x10 #define VERSALOON_MCU_CMD_START 0x10
#define VERSALOON_MCU_CMD_END 0x1F #define VERSALOON_MCU_CMD_END 0x1F
// USB_TO_XXX Command /* USB_TO_XXX Command */
#define VERSALOON_USB_TO_XXX_CMD_START 0x20 #define VERSALOON_USB_TO_XXX_CMD_START 0x20
#define VERSALOON_USB_TO_XXX_CMD_END 0x7F #define VERSALOON_USB_TO_XXX_CMD_END 0x7F
// VSLLink Command /* VSLLink Command */
#define VERSALOON_VSLLINK_CMD_START 0x80 #define VERSALOON_VSLLINK_CMD_START 0x80
#define VERSALOON_VSLLINK_CMD_END 0xFF #define VERSALOON_VSLLINK_CMD_END 0xFF
/* Mass-product */
// Mass-product
#define MP_OK 0x00 #define MP_OK 0x00
#define MP_FAIL 0x01 #define MP_FAIL 0x01
#define MP_ISSP 0x11 #define MP_ISSP 0x11
/* pending struct */
// pending struct
#define VERSALOON_MAX_PENDING_NUMBER 4096 #define VERSALOON_MAX_PENDING_NUMBER 4096
typedef RESULT (*versaloon_callback_t)(void *, uint8_t *, uint8_t *); typedef RESULT(*versaloon_callback_t)(void *, uint8_t *, uint8_t *);
struct versaloon_want_pos_t struct versaloon_want_pos_t {
{
uint16_t offset; uint16_t offset;
uint16_t size; uint16_t size;
uint8_t *buff; uint8_t *buff;
struct versaloon_want_pos_t *next; struct versaloon_want_pos_t *next;
}; };
struct versaloon_pending_t struct versaloon_pending_t {
{
uint8_t type; uint8_t type;
uint8_t cmd; uint8_t cmd;
uint16_t want_data_pos; uint16_t want_data_pos;
@ -103,7 +98,7 @@ extern struct versaloon_pending_t \
extern uint16_t versaloon_pending_idx; extern uint16_t versaloon_pending_idx;
void versaloon_set_pending_id(uint32_t id); void versaloon_set_pending_id(uint32_t id);
void versaloon_set_callback(versaloon_callback_t callback); void versaloon_set_callback(versaloon_callback_t callback);
void versaloon_set_extra_data(void * p); void versaloon_set_extra_data(void *p);
RESULT versaloon_add_want_pos(uint16_t offset, uint16_t size, uint8_t *buff); RESULT versaloon_add_want_pos(uint16_t offset, uint16_t size, uint8_t *buff);
RESULT versaloon_add_pending(uint8_t type, uint8_t cmd, uint16_t actual_szie, RESULT versaloon_add_pending(uint8_t type, uint8_t cmd, uint16_t actual_szie,
uint16_t want_pos, uint16_t want_size, uint8_t *buffer, uint8_t collect); uint16_t want_pos, uint16_t want_size, uint8_t *buffer, uint8_t collect);
@ -115,4 +110,3 @@ extern uint8_t *versaloon_cmd_buf;
extern uint16_t versaloon_buf_size; extern uint16_t versaloon_buf_size;
#endif /* __VERSALOON_INTERNAL_H_INCLUDED__ */ #endif /* __VERSALOON_INTERNAL_H_INCLUDED__ */

View File

@ -106,8 +106,7 @@ static int vsllink_execute_queue(void)
case JTAG_RUNTEST: case JTAG_RUNTEST:
DEBUG_JTAG_IO("runtest %i cycles, end in %s", DEBUG_JTAG_IO("runtest %i cycles, end in %s",
cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->num_cycles,
tap_state_name(cmd->cmd.runtest tap_state_name(cmd->cmd.runtest->end_state));
->end_state));
vsllink_end_state(cmd->cmd.runtest->end_state); vsllink_end_state(cmd->cmd.runtest->end_state);
vsllink_runtest(cmd->cmd.runtest->num_cycles); vsllink_runtest(cmd->cmd.runtest->num_cycles);
@ -115,24 +114,18 @@ static int vsllink_execute_queue(void)
case JTAG_TLR_RESET: case JTAG_TLR_RESET:
DEBUG_JTAG_IO("statemove end in %s", DEBUG_JTAG_IO("statemove end in %s",
tap_state_name(cmd->cmd.statemove tap_state_name(cmd->cmd.statemove->end_state));
->end_state));
vsllink_end_state(cmd->cmd.statemove vsllink_end_state(cmd->cmd.statemove->end_state);
->end_state);
vsllink_state_move(); vsllink_state_move();
break; break;
case JTAG_PATHMOVE: case JTAG_PATHMOVE:
DEBUG_JTAG_IO("pathmove: %i states, end in %s", DEBUG_JTAG_IO("pathmove: %i states, end in %s",
cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->num_states,
tap_state_name(cmd->cmd.pathmove tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
->path[cmd->cmd.pathmove
->num_states - 1]));
vsllink_path_move( vsllink_path_move(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
cmd->cmd.pathmove->num_states,
cmd->cmd.pathmove->path);
break; break;
case JTAG_SCAN: case JTAG_SCAN:
@ -148,16 +141,14 @@ static int vsllink_execute_queue(void)
"JTAG Scan write IR(%d bits), " "JTAG Scan write IR(%d bits), "
"end in %s:", "end in %s:",
scan_size, scan_size,
tap_state_name(cmd->cmd.scan tap_state_name(cmd->cmd.scan->end_state));
->end_state));
else else
DEBUG_JTAG_IO( DEBUG_JTAG_IO(
"JTAG Scan write DR(%d bits), " "JTAG Scan write DR(%d bits), "
"end in %s:", "end in %s:",
scan_size, scan_size,
tap_state_name(cmd->cmd.scan tap_state_name(cmd->cmd.scan->end_state));
->end_state));
#ifdef _DEBUG_JTAG_IO_ #ifdef _DEBUG_JTAG_IO_
vsllink_debug_buffer(buffer, vsllink_debug_buffer(buffer,
@ -218,8 +209,7 @@ static int vsllink_execute_queue(void)
); );
exit(-1); exit(-1);
} }
vsllink_stableclocks(cmd->cmd.stableclocks vsllink_stableclocks(cmd->cmd.stableclocks->num_cycles, scan_size);
->num_cycles, scan_size);
break; break;
case JTAG_TMS: case JTAG_TMS:
@ -262,18 +252,15 @@ static int vsllink_speed_div(int jtag_speed, int *khz)
static void vsllink_free_buffer(void) static void vsllink_free_buffer(void)
{ {
if (tdi_buffer != NULL) if (tdi_buffer != NULL) {
{
free(tdi_buffer); free(tdi_buffer);
tdi_buffer = NULL; tdi_buffer = NULL;
} }
if (tdo_buffer != NULL) if (tdo_buffer != NULL) {
{
free(tdo_buffer); free(tdo_buffer);
tdo_buffer = NULL; tdo_buffer = NULL;
} }
if (tms_buffer != NULL) if (tms_buffer != NULL) {
{
free(tms_buffer); free(tms_buffer);
tms_buffer = NULL; tms_buffer = NULL;
} }
@ -298,7 +285,7 @@ static int vsllink_init(void)
{ {
vsllink_handle = vsllink_usb_open(); vsllink_handle = vsllink_usb_open();
if (vsllink_handle == 0) { if (vsllink_handle == 0) {
LOG_ERROR("Can't find USB JTAG Interface!"\ LOG_ERROR("Can't find USB JTAG Interface!" \
"Please check connection and permissions."); "Please check connection and permissions.");
return ERROR_JTAG_INIT_FAILED; return ERROR_JTAG_INIT_FAILED;
} }
@ -308,23 +295,19 @@ static int vsllink_init(void)
versaloon_usb_device_handle = vsllink_handle->usb_handle; versaloon_usb_device_handle = vsllink_handle->usb_handle;
if (ERROR_OK != versaloon_interface.init()) if (ERROR_OK != versaloon_interface.init())
{
return ERROR_FAIL; return ERROR_FAIL;
} if (versaloon_interface.usb_setting.buf_size < 32) {
if (versaloon_interface.usb_setting.buf_size < 32)
{
versaloon_interface.fini(); versaloon_interface.fini();
return ERROR_FAIL; return ERROR_FAIL;
} }
// malloc buffer size for tap /* malloc buffer size for tap */
tap_buffer_size = versaloon_interface.usb_setting.buf_size - 32; tap_buffer_size = versaloon_interface.usb_setting.buf_size - 32;
vsllink_free_buffer(); vsllink_free_buffer();
tdi_buffer = (uint8_t *)malloc(tap_buffer_size); tdi_buffer = (uint8_t *)malloc(tap_buffer_size);
tdo_buffer = (uint8_t *)malloc(tap_buffer_size); tdo_buffer = (uint8_t *)malloc(tap_buffer_size);
tms_buffer = (uint8_t *)malloc(tap_buffer_size); tms_buffer = (uint8_t *)malloc(tap_buffer_size);
if ((NULL == tdi_buffer) || (NULL == tdo_buffer) || (NULL == tms_buffer)) if ((NULL == tdi_buffer) || (NULL == tdo_buffer) || (NULL == tms_buffer)) {
{
vsllink_quit(); vsllink_quit();
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -335,17 +318,15 @@ static int vsllink_init(void)
versaloon_interface.adaptors.gpio.config(0, GPIO_SRST | GPIO_TRST, versaloon_interface.adaptors.gpio.config(0, GPIO_SRST | GPIO_TRST,
GPIO_TRST, GPIO_SRST, GPIO_SRST); GPIO_TRST, GPIO_SRST, GPIO_SRST);
if (ERROR_OK != versaloon_interface.adaptors.peripheral_commit()) if (ERROR_OK != versaloon_interface.adaptors.peripheral_commit())
{
return ERROR_FAIL; return ERROR_FAIL;
}
vsllink_reset(0, 0); vsllink_reset(0, 0);
vsllink_tap_init(); vsllink_tap_init();
return ERROR_OK; return ERROR_OK;
} }
/***************************************************************************/ /**************************************************************************
/* Queue command implementations */ * Queue command implementations */
static void vsllink_end_state(tap_state_t state) static void vsllink_end_state(tap_state_t state)
{ {
@ -394,9 +375,8 @@ static void vsllink_path_move(int num_states, tap_state_t *path)
static void vsllink_tms(int num_bits, const uint8_t *bits) static void vsllink_tms(int num_bits, const uint8_t *bits)
{ {
for (int i = 0; i < num_bits; i++) { for (int i = 0; i < num_bits; i++)
vsllink_tap_append_step((bits[i / 8] >> (i % 8)) & 1, 0); vsllink_tap_append_step((bits[i / 8] >> (i % 8)) & 1, 0);
}
} }
static void vsllink_stableclocks(int num_cycles, int tms) static void vsllink_stableclocks(int num_cycles, int tms)
@ -419,8 +399,8 @@ static void vsllink_runtest(int num_cycles)
vsllink_stableclocks(num_cycles, 0); vsllink_stableclocks(num_cycles, 0);
// post-process /* post-process */
// set end_state /* set end_state */
vsllink_end_state(saved_end_state); vsllink_end_state(saved_end_state);
if (tap_get_end_state() != tap_get_end_state()) if (tap_get_end_state() != tap_get_end_state())
vsllink_state_move(); vsllink_state_move();
@ -471,9 +451,8 @@ static void vsllink_reset(int trst, int srst)
COMMAND_HANDLER(vsllink_handle_usb_vid_command) COMMAND_HANDLER(vsllink_handle_usb_vid_command)
{ {
if (CMD_ARGC != 1) { if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0],
versaloon_interface.usb_setting.vid); versaloon_interface.usb_setting.vid);
@ -482,9 +461,8 @@ COMMAND_HANDLER(vsllink_handle_usb_vid_command)
COMMAND_HANDLER(vsllink_handle_usb_pid_command) COMMAND_HANDLER(vsllink_handle_usb_pid_command)
{ {
if (CMD_ARGC != 1) { if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0],
versaloon_interface.usb_setting.pid); versaloon_interface.usb_setting.pid);
return ERROR_OK; return ERROR_OK;
@ -492,9 +470,8 @@ COMMAND_HANDLER(vsllink_handle_usb_pid_command)
COMMAND_HANDLER(vsllink_handle_usb_bulkin_command) COMMAND_HANDLER(vsllink_handle_usb_bulkin_command)
{ {
if (CMD_ARGC != 1) { if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0], COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0],
versaloon_interface.usb_setting.ep_in); versaloon_interface.usb_setting.ep_in);
@ -506,9 +483,8 @@ COMMAND_HANDLER(vsllink_handle_usb_bulkin_command)
COMMAND_HANDLER(vsllink_handle_usb_bulkout_command) COMMAND_HANDLER(vsllink_handle_usb_bulkout_command)
{ {
if (CMD_ARGC != 1) { if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0], COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0],
versaloon_interface.usb_setting.ep_out); versaloon_interface.usb_setting.ep_out);
@ -520,17 +496,16 @@ COMMAND_HANDLER(vsllink_handle_usb_bulkout_command)
COMMAND_HANDLER(vsllink_handle_usb_interface_command) COMMAND_HANDLER(vsllink_handle_usb_interface_command)
{ {
if (CMD_ARGC != 1) { if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0], COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0],
versaloon_interface.usb_setting.interface); versaloon_interface.usb_setting.interface);
return ERROR_OK; return ERROR_OK;
} }
/***************************************************************************/ /**************************************************************************
/* VSLLink tap functions */ * VSLLink tap functions */
static void vsllink_tap_init(void) static void vsllink_tap_init(void)
{ {
@ -673,22 +648,20 @@ static int vsllink_tap_execute(void)
return vsllink_jtag_execute(); return vsllink_jtag_execute();
} }
/*****************************************************************************/ /****************************************************************************
/* VSLLink USB low-level functions */ * VSLLink USB low-level functions */
static uint8_t usb_check_string(usb_dev_handle *usb, uint8_t stringidx, static uint8_t usb_check_string(usb_dev_handle *usb, uint8_t stringidx,
char * string, char * buff, uint16_t buf_size) char *string, char *buff, uint16_t buf_size)
{ {
int len; int len;
uint8_t alloced = 0; uint8_t alloced = 0;
uint8_t ret = 1; uint8_t ret = 1;
if (NULL == buff) if (NULL == buff) {
{
buf_size = 256; buf_size = 256;
buff = (char*)malloc(buf_size); buff = (char *)malloc(buf_size);
if (NULL == buff) if (NULL == buff) {
{
ret = 0; ret = 0;
goto free_and_return; goto free_and_return;
} }
@ -697,29 +670,26 @@ static uint8_t usb_check_string(usb_dev_handle *usb, uint8_t stringidx,
strcpy(buff, ""); strcpy(buff, "");
len = usb_get_string_simple(usb, stringidx, (char *)buff, buf_size); len = usb_get_string_simple(usb, stringidx, (char *)buff, buf_size);
if ((len < 0) || (len != ((int)strlen((const char *)buff)))) if ((len < 0) || (len != ((int)strlen((const char *)buff)))) {
{
ret = 0; ret = 0;
goto free_and_return; goto free_and_return;
} }
buff[len] = '\0'; buff[len] = '\0';
if ((string != NULL) && strcmp((const char *)buff, string)) if ((string != NULL) && strcmp((const char *)buff, string)) {
{
ret = 0; ret = 0;
goto free_and_return; goto free_and_return;
} }
free_and_return: free_and_return:
if (alloced && (buff != NULL)) if (alloced && (buff != NULL)) {
{
free(buff); free(buff);
buff = NULL; buff = NULL;
} }
return ret; return ret;
} }
static usb_dev_handle* find_usb_device(uint16_t VID, uint16_t PID, static usb_dev_handle *find_usb_device(uint16_t VID, uint16_t PID,
uint8_t interface, int8_t serialindex, char *serialstring, uint8_t interface, int8_t serialindex, char *serialstring,
int8_t productindex, char *productstring) int8_t productindex, char *productstring)
{ {
@ -733,36 +703,30 @@ static usb_dev_handle* find_usb_device(uint16_t VID, uint16_t PID,
usb_find_devices(); usb_find_devices();
busses = usb_get_busses(); busses = usb_get_busses();
for (bus = busses; bus; bus = bus->next) for (bus = busses; bus; bus = bus->next) {
{ for (dev = bus->devices; dev; dev = dev->next) {
for (dev = bus->devices; dev; dev = dev->next)
{
if ((dev->descriptor.idVendor == VID) if ((dev->descriptor.idVendor == VID)
&& (dev->descriptor.idProduct == PID)) && (dev->descriptor.idProduct == PID)) {
{
dev_handle = usb_open(dev); dev_handle = usb_open(dev);
if (NULL == dev_handle) if (NULL == dev_handle) {
{
LOG_ERROR("failed to open %04X:%04X, %s", VID, PID, LOG_ERROR("failed to open %04X:%04X, %s", VID, PID,
usb_strerror()); usb_strerror());
continue; continue;
} }
// check description string /* check description string */
if (((productstring != NULL) && (productindex >= 0) if (((productstring != NULL) && (productindex >= 0)
&& !usb_check_string(dev_handle, productindex, && !usb_check_string(dev_handle, productindex,
productstring, NULL, 0)) productstring, NULL, 0))
|| ((serialstring != NULL) && (serialindex >= 0) || ((serialstring != NULL) && (serialindex >= 0)
&& !usb_check_string(dev_handle, serialindex, && !usb_check_string(dev_handle, serialindex,
serialstring, NULL, 0))) serialstring, NULL, 0))) {
{
usb_close(dev_handle); usb_close(dev_handle);
dev_handle = NULL; dev_handle = NULL;
continue; continue;
} }
if (usb_claim_interface(dev_handle, interface) != 0) if (usb_claim_interface(dev_handle, interface) != 0) {
{
LOG_ERROR(ERRMSG_FAILURE_OPERATION_MESSAGE, LOG_ERROR(ERRMSG_FAILURE_OPERATION_MESSAGE,
"claim interface", usb_strerror()); "claim interface", usb_strerror());
usb_close(dev_handle); usb_close(dev_handle);
@ -771,12 +735,10 @@ static usb_dev_handle* find_usb_device(uint16_t VID, uint16_t PID,
} }
if (dev_handle != NULL) if (dev_handle != NULL)
{
return dev_handle; return dev_handle;
} }
} }
} }
}
return dev_handle; return dev_handle;
} }

View File

@ -18,13 +18,14 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef MINIDRIVER_IMP_H #ifndef MINIDRIVER_IMP_H
#define MINIDRIVER_IMP_H #define MINIDRIVER_IMP_H
#include <jtag/jtag_minidriver.h> #include <jtag/jtag_minidriver.h>
static inline void jtag_add_dr_out(struct jtag_tap* tap, static inline void jtag_add_dr_out(struct jtag_tap *tap,
int num_fields, const int* num_bits, const uint32_t* value, int num_fields, const int *num_bits, const uint32_t *value,
tap_state_t end_state) tap_state_t end_state)
{ {
cmd_queue_cur_state = end_state; cmd_queue_cur_state = end_state;
@ -36,8 +37,7 @@ static inline void jtag_add_dr_out(struct jtag_tap* tap,
#define jtag_add_callback(callback, in) interface_jtag_add_callback(callback, in) #define jtag_add_callback(callback, in) interface_jtag_add_callback(callback, in)
#define jtag_add_callback4(callback, in, data1, data2, data3) interface_jtag_add_callback4(callback, in, data1, data2, data3) #define jtag_add_callback4(callback, in, data1, data2, data3) \
interface_jtag_add_callback4(callback, in, data1, data2, data3)
#endif /* MINIDRIVER_IMP_H */
#endif // MINIDRIVER_IMP_H

View File

@ -17,10 +17,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
static inline void interface_jtag_add_dr_out_core(struct jtag_tap *targettap,
static __inline__ void interface_jtag_add_dr_out_core(struct jtag_tap *targettap,
int num_fields, int num_fields,
const int *num_bits, const int *num_bits,
const uint32_t *value, const uint32_t *value,
@ -29,7 +26,7 @@ static __inline__ void interface_jtag_add_dr_out_core(struct jtag_tap *targettap
/* synchronously do the operation here */ /* synchronously do the operation here */
} }
static __inline__ void interface_jtag_add_dr_out(struct jtag_tap *targettap, static inline void interface_jtag_add_dr_out(struct jtag_tap *targettap,
int num_fields, int num_fields,
const int *num_bits, const int *num_bits,
const uint32_t *value, const uint32_t *value,
@ -40,4 +37,5 @@ static __inline__ void interface_jtag_add_dr_out(struct jtag_tap *targettap,
#define interface_jtag_add_callback(callback, in) callback(in) #define interface_jtag_add_callback(callback, in) callback(in)
#define interface_jtag_add_callback4(callback, in, data1, data2, data3) jtag_set_error(callback(in, data1, data2, data3)) #define interface_jtag_add_callback4(callback, in, data1, data2, data3) \
jtag_set_error(callback(in, data1, data2, data3))

View File

@ -16,6 +16,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -25,8 +26,7 @@
#include <jtag/minidriver.h> #include <jtag/minidriver.h>
#include <jtag/interface.h> #include <jtag/interface.h>
struct jtag_interface minidummy_interface = struct jtag_interface minidummy_interface = {
{
.name = "minidummy", .name = "minidummy",
.execute_queue = NULL, .execute_queue = NULL,
.speed = NULL, .speed = NULL,
@ -46,29 +46,32 @@ int interface_jtag_execute_queue(void)
return ERROR_OK; return ERROR_OK;
} }
int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, tap_state_t state) int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields,
{ tap_state_t state)
/* synchronously do the operation here */
return ERROR_OK;
}
int interface_jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
{ {
/* synchronously do the operation here */ /* synchronously do the operation here */
return ERROR_OK; return ERROR_OK;
} }
int interface_jtag_add_dr_scan(struct jtag_tap *active, int num_fields, const struct scan_field *fields, tap_state_t state) int interface_jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits,
uint8_t *in_bits, tap_state_t state)
{ {
/* synchronously do the operation here */ /* synchronously do the operation here */
return ERROR_OK; return ERROR_OK;
} }
int interface_jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state) int interface_jtag_add_dr_scan(struct jtag_tap *active, int num_fields,
const struct scan_field *fields, tap_state_t state)
{
/* synchronously do the operation here */
return ERROR_OK;
}
int interface_jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits,
uint8_t *in_bits, tap_state_t state)
{ {
/* synchronously do the operation here */ /* synchronously do the operation here */
@ -118,19 +121,14 @@ int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
tap_state_t cur_state = cmd_queue_cur_state; tap_state_t cur_state = cmd_queue_cur_state;
while (num_states) while (num_states) {
{
if (tap_state_transition(cur_state, false) == path[state_count]) if (tap_state_transition(cur_state, false) == path[state_count])
{
tms = 0; tms = 0;
}
else if (tap_state_transition(cur_state, true) == path[state_count]) else if (tap_state_transition(cur_state, true) == path[state_count])
{
tms = 1; tms = 1;
} else {
else LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
{ tap_state_name(cur_state), tap_state_name(path[state_count]));
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state), tap_state_name(path[state_count]));
exit(-1); exit(-1);
} }
@ -154,18 +152,20 @@ int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state
return ERROR_OK; return ERROR_OK;
} }
void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, const uint8_t *buffer, int little, int count) void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, const uint8_t *buffer,
int little, int count)
{ {
int i; int i;
for (i = 0; i < count; i++) for (i = 0; i < count; i++) {
{
embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little)); embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little));
buffer += 4; buffer += 4;
} }
} }
int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap * tap, uint32_t opcode, uint32_t * data, size_t count) int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, uint32_t opcode,
uint32_t *data, size_t count)
{ {
int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap * tap, uint32_t opcode, uint32_t * data, size_t count); int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *tap, \
uint32_t opcode, uint32_t *data, size_t count);
return arm11_run_instr_data_to_core_noack_inner_default(tap, opcode, data, count); return arm11_run_instr_data_to_core_noack_inner_default(tap, opcode, data, count);
} }

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef _STLINK_INTERFACE_ #ifndef _STLINK_INTERFACE_
#define _STLINK_INTERFACE_ #define _STLINK_INTERFACE_

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef _STLINK_LAYOUT_H_ #ifndef _STLINK_LAYOUT_H_
#define _STLINK_LAYOUT_H_ #define _STLINK_LAYOUT_H_

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef _STLINK_TCL_ #ifndef _STLINK_TCL_
#define _STLINK_TCL_ #define _STLINK_TCL_

View File

@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef _STLINK_TRANSPORT_ #ifndef _STLINK_TRANSPORT_
#define _STLINK_TRANSPORT_ #define _STLINK_TRANSPORT_

View File

@ -24,13 +24,13 @@
#if BUILD_ZY1000_MASTER #if BUILD_ZY1000_MASTER
#if BUILD_ECOSBOARD #if BUILD_ECOSBOARD
#include <cyg/hal/hal_io.h> // low level i/o #include <cyg/hal/hal_io.h> /* low level i/o */
#include <cyg/hal/hal_intr.h> // low level i/o #include <cyg/hal/hal_intr.h> /* low level i/o */
#define ZY1000_PEEK(a, b) HAL_READ_UINT32(a, b) #define ZY1000_PEEK(a, b) HAL_READ_UINT32(a, b)
#define ZY1000_POKE(a, b) HAL_WRITE_UINT32(a, b) #define ZY1000_POKE(a, b) HAL_WRITE_UINT32(a, b)
#else #else
#define ZY1000_PEEK(a, b) do {b = *( ( volatile uint32_t *)(a) );} while (0) #define ZY1000_PEEK(a, b) do {b = *((volatile uint32_t *)(a)); } while (0)
#define ZY1000_POKE(a, b) do {*( ( volatile uint32_t *)(a) ) = b;} while (0) #define ZY1000_POKE(a, b) do {*((volatile uint32_t *)(a)) = b; } while (0)
extern volatile void *zy1000_jtag_master; extern volatile void *zy1000_jtag_master;
#define ZY1000_JTAG_BASE ((unsigned long)zy1000_jtag_master) #define ZY1000_JTAG_BASE ((unsigned long)zy1000_jtag_master)
#endif #endif
@ -41,29 +41,26 @@ extern volatile void *zy1000_jtag_master;
#define ZY1000_JTAG_BASE 0 #define ZY1000_JTAG_BASE 0
extern void zy1000_tcpout(uint32_t address, uint32_t data); extern void zy1000_tcpout(uint32_t address, uint32_t data);
extern uint32_t zy1000_tcpin(uint32_t address); extern uint32_t zy1000_tcpin(uint32_t address);
#define ZY1000_PEEK(a, b) b=zy1000_tcpin(a) #define ZY1000_PEEK(a, b) b = zy1000_tcpin(a)
#define ZY1000_POKE(a, b) zy1000_tcpout(a, b) #define ZY1000_POKE(a, b) zy1000_tcpout(a, b)
#endif #endif
#if BUILD_ZY1000_MASTER #if BUILD_ZY1000_MASTER
// FIFO empty? /* FIFO empty? */
static __inline__ void waitIdle(void) static inline void waitIdle(void)
{ {
uint32_t empty; uint32_t empty;
do do {
{
ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, empty); ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, empty);
} while ((empty & 0x100) == 0); } while ((empty & 0x100) == 0);
} }
static __inline__ void zy1000_flush_readqueue(void) static inline void zy1000_flush_readqueue(void)
{ {
/* Not used w/hardware fifo */ /* Not used w/hardware fifo */
} }
static __inline__ void zy1000_flush_callbackqueue(void) static inline void zy1000_flush_callbackqueue(void)
{ {
/* Not used w/hardware fifo */ /* Not used w/hardware fifo */
} }
@ -71,16 +68,20 @@ static __inline__ void zy1000_flush_callbackqueue(void)
extern void waitIdle(void); extern void waitIdle(void);
void zy1000_flush_readqueue(void); void zy1000_flush_readqueue(void);
void zy1000_flush_callbackqueue(void); void zy1000_flush_callbackqueue(void);
void zy1000_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3); void zy1000_jtag_add_callback4(jtag_callback_t callback,
jtag_callback_data_t data0,
jtag_callback_data_t data1,
jtag_callback_data_t data2,
jtag_callback_data_t data3);
void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0); void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0);
#endif #endif
static __inline__ void waitQueue(void) static inline void waitQueue(void)
{ {
// waitIdle(); /* waitIdle(); */
} }
static __inline__ void sampleShiftRegister(void) static inline void sampleShiftRegister(void)
{ {
#if 0 #if 0
uint32_t dummy; uint32_t dummy;
@ -89,17 +90,16 @@ static __inline__ void sampleShiftRegister(void)
#endif #endif
} }
static __inline__ void setCurrentState(enum tap_state state) static inline void setCurrentState(enum tap_state state)
{ {
uint32_t a; uint32_t a;
a = state; a = state;
int repeat = 0; int repeat = 0;
if (state == TAP_RESET) if (state == TAP_RESET) {
{ /* The FPGA nor we know the current state of the CPU TAP */
// The FPGA nor we know the current state of the CPU TAP /* controller. This will move it to TAP for sure. */
// controller. This will move it to TAP for sure. /* */
// /* 5 should be enough here, 7 is what OpenOCD uses */
// 5 should be enough here, 7 is what OpenOCD uses
repeat = 7; repeat = 7;
} }
waitQueue(); waitQueue();
@ -112,9 +112,12 @@ static __inline__ void setCurrentState(enum tap_state state)
* Enter state and cause repeat transitions *out* of that state. So if the endState != state, then * Enter state and cause repeat transitions *out* of that state. So if the endState != state, then
* the transition from state to endState counts as a transition out of state. * the transition from state to endState counts as a transition out of state.
*/ */
static __inline__ void shiftValueInner(const enum tap_state state, const enum tap_state endState, int repeat, uint32_t value) static inline void shiftValueInner(const enum tap_state state,
const enum tap_state endState,
int repeat,
uint32_t value)
{ {
uint32_t a,b; uint32_t a, b;
a = state; a = state;
b = endState; b = endState;
waitQueue(); waitQueue();
@ -122,18 +125,14 @@ static __inline__ void shiftValueInner(const enum tap_state state, const enum ta
ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value); ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value);
#if 1 #if 1
#if TEST_MANUAL() #if TEST_MANUAL()
if ((state == TAP_DRSHIFT) && (endState != TAP_DRSHIFT)) if ((state == TAP_DRSHIFT) && (endState != TAP_DRSHIFT)) {
{
int i; int i;
setCurrentState(state); setCurrentState(state);
for (i = 0; i < repeat; i++) for (i = 0; i < repeat; i++) {
{
int tms; int tms;
tms = 0; tms = 0;
if ((i == repeat-1) && (state != endState)) if ((i == repeat-1) && (state != endState))
{
tms = 1; tms = 1;
}
/* shift out value */ /* shift out value */
waitIdle(); waitIdle();
ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, (((value >> i)&1) << 1) | tms); ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, (((value >> i)&1) << 1) | tms);
@ -141,25 +140,27 @@ static __inline__ void shiftValueInner(const enum tap_state state, const enum ta
waitIdle(); waitIdle();
ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0); ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0);
waitIdle(); waitIdle();
//ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT); // set this state and things break => expected /* ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT); // set this state and things
ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRPAUSE); // set this and things will work => expected. Not setting this is not sufficient to make things break. * break => expected */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRPAUSE); /* set this and things will
* work => expected. Not
* setting this is not
* sufficient to make things
* break. */
setCurrentState(endState); setCurrentState(endState);
} else } else
{
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b); ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
}
#else #else
/* fast version */ /* fast version */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b); ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
#endif #endif
#else #else
/* maximum debug version */ /* maximum debug version */
if ((repeat > 0) && ((state == TAP_DRSHIFT)||(state == TAP_SI))) if ((repeat > 0) && ((state == TAP_DRSHIFT) || (state == TAP_SI))) {
{
int i; int i;
/* sample shift register for every bit. */ /* sample shift register for every bit. */
for (i = 0; i < repeat-1; i++) for (i = 0; i < repeat-1; i++) {
{
sampleShiftRegister(); sampleShiftRegister();
ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> i); ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> i);
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | a); ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | a);
@ -167,8 +168,7 @@ static __inline__ void shiftValueInner(const enum tap_state state, const enum ta
sampleShiftRegister(); sampleShiftRegister();
ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> (repeat-1)); ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> (repeat-1));
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | b); ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | b);
} else } else {
{
sampleShiftRegister(); sampleShiftRegister();
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b); ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
} }
@ -176,9 +176,7 @@ static __inline__ void shiftValueInner(const enum tap_state state, const enum ta
#endif #endif
} }
static inline void interface_jtag_add_dr_out_core(struct jtag_tap *target_tap,
static __inline__ void interface_jtag_add_dr_out_core(struct jtag_tap *target_tap,
int num_fields, int num_fields,
const int *num_bits, const int *num_bits,
const uint32_t *value, const uint32_t *value,
@ -187,30 +185,23 @@ static __inline__ void interface_jtag_add_dr_out_core(struct jtag_tap *target_ta
enum tap_state pause_state = TAP_DRSHIFT; enum tap_state pause_state = TAP_DRSHIFT;
struct jtag_tap *tap, *nextTap; struct jtag_tap *tap, *nextTap;
for (tap = jtag_tap_next_enabled(NULL); tap!= NULL; tap = nextTap) for (tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = nextTap) {
{
nextTap = jtag_tap_next_enabled(tap); nextTap = jtag_tap_next_enabled(tap);
if (nextTap == NULL) if (nextTap == NULL)
{
pause_state = end_state; pause_state = end_state;
} if (tap == target_tap) {
if (tap == target_tap)
{
int j; int j;
for (j = 0; j < (num_fields-1); j++) for (j = 0; j < (num_fields-1); j++)
{
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[j], value[j]); shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[j], value[j]);
}
shiftValueInner(TAP_DRSHIFT, pause_state, num_bits[j], value[j]); shiftValueInner(TAP_DRSHIFT, pause_state, num_bits[j], value[j]);
} else } else {
{
/* program the scan field to 1 bit length, and ignore it's value */ /* program the scan field to 1 bit length, and ignore it's value */
shiftValueInner(TAP_DRSHIFT, pause_state, 1, 0); shiftValueInner(TAP_DRSHIFT, pause_state, 1, 0);
} }
} }
} }
static __inline__ void interface_jtag_add_dr_out(struct jtag_tap *target_tap, static inline void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
int num_fields, int num_fields,
const int *num_bits, const int *num_bits,
const uint32_t *value, const uint32_t *value,
@ -218,27 +209,29 @@ static __inline__ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
{ {
int singletap = (jtag_tap_next_enabled(jtag_tap_next_enabled(NULL)) == NULL); int singletap = (jtag_tap_next_enabled(jtag_tap_next_enabled(NULL)) == NULL);
if ((singletap) && (num_fields == 3)) if ((singletap) && (num_fields == 3)) {
{
/* used by embeddedice_write_reg_inner() */ /* used by embeddedice_write_reg_inner() */
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[0], value[0]); shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[0], value[0]);
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[1], value[1]); shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[1], value[1]);
shiftValueInner(TAP_DRSHIFT, end_state, num_bits[2], value[2]); shiftValueInner(TAP_DRSHIFT, end_state, num_bits[2], value[2]);
} else if ((singletap) && (num_fields == 2)) } else if ((singletap) && (num_fields == 2)) {
{
/* used by arm7 code */ /* used by arm7 code */
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[0], value[0]); shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[0], value[0]);
shiftValueInner(TAP_DRSHIFT, end_state, num_bits[1], value[1]); shiftValueInner(TAP_DRSHIFT, end_state, num_bits[1], value[1]);
} else } else
{
interface_jtag_add_dr_out_core(target_tap, num_fields, num_bits, value, end_state); interface_jtag_add_dr_out_core(target_tap, num_fields, num_bits, value, end_state);
}
} }
#if BUILD_ZY1000_MASTER #if BUILD_ZY1000_MASTER
#define interface_jtag_add_callback(callback, in) callback(in) #define interface_jtag_add_callback(callback, in) callback(in)
#define interface_jtag_add_callback4(callback, in, data1, data2, data3) jtag_set_error(callback(in, data1, data2, data3)) #define interface_jtag_add_callback4(callback, in, data1, data2, \
data3) jtag_set_error(callback(in, data1, data2, data3))
#else #else
#define interface_jtag_add_callback(callback, in) zy1000_jtag_add_callback(callback, in) #define interface_jtag_add_callback(callback, in) zy1000_jtag_add_callback(callback, in)
#define interface_jtag_add_callback4(callback, in, data1, data2, data3) zy1000_jtag_add_callback4(callback, in, data1, data2, data3) #define interface_jtag_add_callback4(callback, in, data1, data2, data3) zy1000_jtag_add_callback4( \
callback, \
in, \
data1, \
data2, \
data3)
#endif #endif

File diff suppressed because it is too large Load Diff