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__
parent
2af5b97ba3
commit
de0130a0aa
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define NOP {__asm nop __endasm;}
|
||||
#define NOP { __asm nop __endasm; }
|
||||
|
||||
void delay_5us(void);
|
||||
void delay_1ms(void);
|
||||
|
|
|
@ -51,15 +51,14 @@
|
|||
|
||||
/* PORT A */
|
||||
#define PIN_U_OE OUTA0
|
||||
// PA1 Not Connected
|
||||
/* PA1 Not Connected */
|
||||
#define PIN_OE OUTA2
|
||||
// PA3 Not Connected
|
||||
/* PA3 Not Connected */
|
||||
#define PIN_RUN_LED OUTA4
|
||||
#define PIN_TDO PINA5
|
||||
#define PIN_BRKOUT PINA6
|
||||
#define PIN_COM_LED OUTA7
|
||||
|
||||
|
||||
/* PORT B */
|
||||
#define PIN_TDI OUTB0
|
||||
#define PIN_TMS OUTB1
|
||||
|
@ -77,18 +76,18 @@
|
|||
#define PIN_RXD0 PINC0
|
||||
#define PIN_TXD0 OUTC1
|
||||
#define PIN_RESET_2 PINC2
|
||||
// PC3 Not Connected
|
||||
// PC4 Not Connected
|
||||
/* PC3 Not Connecte */
|
||||
/* PC4 Not Connected */
|
||||
#define PIN_RTCK PINC5
|
||||
#define PIN_WR OUTC6
|
||||
// PC7 Not Connected
|
||||
/* PC7 Not Connected */
|
||||
|
||||
/* LED Macros */
|
||||
#define SET_RUN_LED() OUTA &= ~PIN_RUN_LED
|
||||
#define CLEAR_RUN_LED() OUTA |= PIN_RUN_LED
|
||||
#define SET_RUN_LED() (OUTA &= ~PIN_RUN_LED)
|
||||
#define CLEAR_RUN_LED() (OUTA |= PIN_RUN_LED)
|
||||
|
||||
#define SET_COM_LED() OUTA &= ~PIN_COM_LED
|
||||
#define CLEAR_COM_LED() OUTA |= PIN_COM_LED
|
||||
#define SET_COM_LED() (OUTA &= ~PIN_COM_LED)
|
||||
#define CLEAR_COM_LED() (OUTA |= PIN_COM_LED)
|
||||
|
||||
/* JTAG Pin Macros */
|
||||
#define GET_TMS() (PINSB & PIN_TMS)
|
||||
|
@ -99,27 +98,27 @@
|
|||
#define GET_TRAP() (PINSB & PIN_TRAP)
|
||||
#define GET_RTCK() (PINSC & PIN_RTCK)
|
||||
|
||||
#define SET_TMS_HIGH() OUTB |= PIN_TMS
|
||||
#define SET_TMS_LOW() OUTB &= ~PIN_TMS
|
||||
#define SET_TMS_HIGH() (OUTB |= PIN_TMS)
|
||||
#define SET_TMS_LOW() (OUTB &= ~PIN_TMS)
|
||||
|
||||
#define SET_TCK_HIGH() OUTB |= PIN_TCK
|
||||
#define SET_TCK_LOW() OUTB &= ~PIN_TCK
|
||||
#define SET_TCK_HIGH() (OUTB |= PIN_TCK)
|
||||
#define SET_TCK_LOW() (OUTB &= ~PIN_TCK)
|
||||
|
||||
#define SET_TDI_HIGH() OUTB |= PIN_TDI
|
||||
#define SET_TDI_LOW() OUTB &= ~PIN_TDI
|
||||
#define SET_TDI_HIGH() (OUTB |= PIN_TDI)
|
||||
#define SET_TDI_LOW() (OUTB &= ~PIN_TDI)
|
||||
|
||||
/* 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) */
|
||||
#define SET_TRST_HIGH() OUTB |= PIN_TRST
|
||||
#define SET_TRST_LOW() OUTB &= ~PIN_TRST
|
||||
#define SET_TRST_HIGH() (OUTB |= PIN_TRST)
|
||||
#define SET_TRST_LOW() (OUTB &= ~PIN_TRST)
|
||||
|
||||
#define SET_RESET_HIGH() OUTB |= PIN_RESET
|
||||
#define SET_RESET_LOW() OUTB &= ~PIN_RESET
|
||||
#define SET_RESET_HIGH() (OUTB |= PIN_RESET)
|
||||
#define SET_RESET_LOW() (OUTB &= ~PIN_RESET)
|
||||
|
||||
#define SET_OCDSE_HIGH() OUTB |= PIN_OCDSE
|
||||
#define SET_OCDSE_LOW() OUTB &= ~PIN_OCDSE
|
||||
#define SET_OCDSE_HIGH() (OUTB |= PIN_OCDSE)
|
||||
#define SET_OCDSE_LOW() (OUTB &= ~PIN_OCDSE)
|
||||
|
||||
#define SET_BRKIN_HIGH() OUTB |= PIN_BRKIN
|
||||
#define SET_BRKIN_LOW() OUTB &= ~PIN_BRKIN
|
||||
#define SET_BRKIN_HIGH() (OUTB |= PIN_BRKIN)
|
||||
#define SET_BRKIN_LOW() (OUTB &= ~PIN_BRKIN)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#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_slow_scan_in(uint8_t out_offset, uint8_t in_offset);
|
||||
|
@ -43,6 +43,6 @@ uint16_t jtag_get_signals(void);
|
|||
void jtag_set_signals(uint8_t low, uint8_t high);
|
||||
|
||||
void jtag_configure_tck_delay(uint8_t scan_in, uint8_t scan_out,
|
||||
uint8_t scan_io, uint8_t tck, uint8_t tms);
|
||||
uint8_t scan_io, uint8_t tck, uint8_t tms);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,9 +51,9 @@
|
|||
#define bmBit6 0x40
|
||||
#define bmBit7 0x80
|
||||
|
||||
/***************************************************************************/
|
||||
/************************ Special Function Registers ***********************/
|
||||
/***************************************************************************/
|
||||
/**************************************************************************
|
||||
************************ Special Function Registers **********************
|
||||
***************************************************************************/
|
||||
|
||||
/* See EZ-USB TRM, pp. A-9 - A-10 */
|
||||
|
||||
|
@ -65,33 +65,33 @@ SFR(DPL2, 0x85);
|
|||
|
||||
SFR(DPS, 0x86);
|
||||
#define SEL bmBit0
|
||||
// Bit 1 read-only, always reads '0'
|
||||
// Bit 2 read-only, always reads '0'
|
||||
// Bit 3 read-only, always reads '0'
|
||||
// Bit 4 read-only, always reads '0'
|
||||
// Bit 5 read-only, always reads '0'
|
||||
// Bit 6 read-only, always reads '0'
|
||||
// Bit 7 read-only, always reads '0'
|
||||
/* Bit 1 read-only, always reads '0' */
|
||||
/* Bit 2 read-only, always reads '0' */
|
||||
/* Bit 3 read-only, always reads '0' */
|
||||
/* Bit 4 read-only, always reads '0' */
|
||||
/* Bit 5 read-only, always reads '0' */
|
||||
/* Bit 6 read-only, always reads '0' */
|
||||
/* Bit 7 read-only, always reads '0' */
|
||||
|
||||
SFR(PCON, 0x87);
|
||||
#define IDLE bmBit0
|
||||
#define STOP bmBit1
|
||||
#define GF0 bmBit2
|
||||
#define GF1 bmBit3
|
||||
// Bit 4 read-only, always reads '1'
|
||||
// Bit 5 read-only, always reads '1'
|
||||
// Bit 6 unused
|
||||
/* Bit 4 read-only, always reads '1' */
|
||||
/* Bit 5 read-only, always reads '1' */
|
||||
/* Bit 6 unused */
|
||||
#define SMOD0 bmBit7
|
||||
|
||||
SFR(TCON, 0x88);
|
||||
SBIT(IT0, 0x88, 0);
|
||||
SBIT(IE0, 0x88, 1);
|
||||
SBIT(IT1, 0x88, 2);
|
||||
SBIT(IE1, 0x88, 3);
|
||||
SBIT(TR0, 0x88, 4);
|
||||
SBIT(TF0, 0x88, 5);
|
||||
SBIT(TR1, 0x88, 6);
|
||||
SBIT(TF1, 0x88, 7);
|
||||
SBIT(IT0, 0x88, 0);
|
||||
SBIT(IE0, 0x88, 1);
|
||||
SBIT(IT1, 0x88, 2);
|
||||
SBIT(IE1, 0x88, 3);
|
||||
SBIT(TR0, 0x88, 4);
|
||||
SBIT(TF0, 0x88, 5);
|
||||
SBIT(TR1, 0x88, 6);
|
||||
SBIT(TF1, 0x88, 7);
|
||||
|
||||
SFR(TMOD, 0x89);
|
||||
/* 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 T1M bmBit4
|
||||
#define T2M bmBit5
|
||||
// Bit 6 unused
|
||||
// Bit 7 unused
|
||||
/* Bit 6 unused */
|
||||
/* Bit 7 unused */
|
||||
|
||||
SFR(SPC_FNC, 0x8D);
|
||||
#define bmWRS bmBit0
|
||||
// Bit 1 read-only, always reads '0'
|
||||
// Bit 2 read-only, always reads '0'
|
||||
// Bit 3 read-only, always reads '0'
|
||||
// Bit 4 read-only, always reads '0'
|
||||
// Bit 5 read-only, always reads '0'
|
||||
// Bit 6 read-only, always reads '0'
|
||||
// Bit 7 read-only, always reads '0'
|
||||
/* Bit 1 read-only, always reads '0' */
|
||||
/* Bit 2 read-only, always reads '0' */
|
||||
/* Bit 3 read-only, always reads '0' */
|
||||
/* Bit 4 read-only, always reads '0' */
|
||||
/* Bit 5 read-only, always reads '0' */
|
||||
/* Bit 6 read-only, always reads '0' */
|
||||
/* Bit 7 read-only, always reads '0' */
|
||||
|
||||
SFR(EXIF, 0x91);
|
||||
// Bit 0 read-only, always reads '0'
|
||||
// Bit 1 read-only, always reads '0'
|
||||
// Bit 2 read-only, always reads '0'
|
||||
// Bit 3 read-only, always reads '1'
|
||||
/* Bit 0 read-only, always reads '0' */
|
||||
/* Bit 1 read-only, always reads '0' */
|
||||
/* Bit 2 read-only, always reads '0' */
|
||||
/* Bit 3 read-only, always reads '1' */
|
||||
#define USBINT bmBit4
|
||||
#define I2CINT bmBit5
|
||||
#define IE4 bmBit6
|
||||
|
@ -146,58 +146,58 @@ SFR(MPAGE, 0x92);
|
|||
SFR(_XPAGE, 0x92);
|
||||
|
||||
SFR(SCON0, 0x98);
|
||||
SBIT(RI_0, 0x98, 0);
|
||||
SBIT(TI_0, 0x98, 1);
|
||||
SBIT(RB8_0, 0x98, 2);
|
||||
SBIT(TB8_0, 0x98, 3);
|
||||
SBIT(REN_0, 0x98, 4);
|
||||
SBIT(SM2_0, 0x98, 5);
|
||||
SBIT(SM1_0, 0x98, 6);
|
||||
SBIT(SM0_0, 0x98, 7);
|
||||
SBIT(RI_0, 0x98, 0);
|
||||
SBIT(TI_0, 0x98, 1);
|
||||
SBIT(RB8_0, 0x98, 2);
|
||||
SBIT(TB8_0, 0x98, 3);
|
||||
SBIT(REN_0, 0x98, 4);
|
||||
SBIT(SM2_0, 0x98, 5);
|
||||
SBIT(SM1_0, 0x98, 6);
|
||||
SBIT(SM0_0, 0x98, 7);
|
||||
|
||||
SFR(SBUF0, 0x99);
|
||||
|
||||
SFR(IE, 0xA8);
|
||||
SBIT(EX0, 0xA8, 0);
|
||||
SBIT(ET0, 0xA8, 1);
|
||||
SBIT(EX1, 0xA8, 2);
|
||||
SBIT(ET1, 0xA8, 3);
|
||||
SBIT(ES0, 0xA8, 4);
|
||||
SBIT(ET2, 0xA8, 5);
|
||||
SBIT(ES1, 0xA8, 6);
|
||||
SBIT(EA, 0xA8, 7);
|
||||
SBIT(EX0, 0xA8, 0);
|
||||
SBIT(ET0, 0xA8, 1);
|
||||
SBIT(EX1, 0xA8, 2);
|
||||
SBIT(ET1, 0xA8, 3);
|
||||
SBIT(ES0, 0xA8, 4);
|
||||
SBIT(ET2, 0xA8, 5);
|
||||
SBIT(ES1, 0xA8, 6);
|
||||
SBIT(EA, 0xA8, 7);
|
||||
|
||||
SFR(IP, 0xB8);
|
||||
SBIT(PX0, 0xB8, 0);
|
||||
SBIT(PT0, 0xB8, 1);
|
||||
SBIT(PX1, 0xB8, 2);
|
||||
SBIT(PT1, 0xB8, 3);
|
||||
SBIT(PS0, 0xB8, 4);
|
||||
SBIT(PT2, 0xB8, 5);
|
||||
SBIT(PS1, 0xB8, 6);
|
||||
// Bit 7 read-only, always reads '1'
|
||||
SBIT(PX0, 0xB8, 0);
|
||||
SBIT(PT0, 0xB8, 1);
|
||||
SBIT(PX1, 0xB8, 2);
|
||||
SBIT(PT1, 0xB8, 3);
|
||||
SBIT(PS0, 0xB8, 4);
|
||||
SBIT(PT2, 0xB8, 5);
|
||||
SBIT(PS1, 0xB8, 6);
|
||||
/* Bit 7 read-only, always reads '1' */
|
||||
|
||||
SFR(SCON1, 0xC0);
|
||||
SBIT(RI_1, 0xC0, 0);
|
||||
SBIT(TI_1, 0xC0, 1);
|
||||
SBIT(RB8_1, 0xC0, 2);
|
||||
SBIT(TB8_1, 0xC0, 3);
|
||||
SBIT(REN_1, 0xC0, 4);
|
||||
SBIT(SM2_1, 0xC0, 5);
|
||||
SBIT(SM1_1, 0xC0, 6);
|
||||
SBIT(SM0_1, 0xC0, 7);
|
||||
SBIT(RI_1, 0xC0, 0);
|
||||
SBIT(TI_1, 0xC0, 1);
|
||||
SBIT(RB8_1, 0xC0, 2);
|
||||
SBIT(TB8_1, 0xC0, 3);
|
||||
SBIT(REN_1, 0xC0, 4);
|
||||
SBIT(SM2_1, 0xC0, 5);
|
||||
SBIT(SM1_1, 0xC0, 6);
|
||||
SBIT(SM0_1, 0xC0, 7);
|
||||
|
||||
SFR(SBUF1, 0xC1);
|
||||
|
||||
SFR(T2CON, 0xC8);
|
||||
SBIT(CPRL2, 0xC8, 0);
|
||||
SBIT(CT2, 0xC8, 1);
|
||||
SBIT(TR2, 0xC8, 2);
|
||||
SBIT(EXEN2, 0xC8, 3);
|
||||
SBIT(TCLK, 0xC8, 4);
|
||||
SBIT(RCLK, 0xC8, 5);
|
||||
SBIT(EXF2, 0xC8, 6);
|
||||
SBIT(TF2, 0xC8, 7);
|
||||
SBIT(CPRL2, 0xC8, 0);
|
||||
SBIT(CT2, 0xC8, 1);
|
||||
SBIT(TR2, 0xC8, 2);
|
||||
SBIT(EXEN2, 0xC8, 3);
|
||||
SBIT(TCLK, 0xC8, 4);
|
||||
SBIT(RCLK, 0xC8, 5);
|
||||
SBIT(EXF2, 0xC8, 6);
|
||||
SBIT(TF2, 0xC8, 7);
|
||||
|
||||
SFR(RCAP2L, 0xCA);
|
||||
SFR(RCAP2H, 0xCB);
|
||||
|
@ -205,52 +205,52 @@ SFR(TL2, 0xCC);
|
|||
SFR(TH2, 0xCD);
|
||||
|
||||
SFR(PSW, 0xD0);
|
||||
SBIT(P, 0xD0, 0);
|
||||
SBIT(F1, 0xD0, 1);
|
||||
SBIT(OV, 0xD0, 2);
|
||||
SBIT(RS0, 0xD0, 3);
|
||||
SBIT(RS1, 0xD0, 4);
|
||||
SBIT(F0, 0xD0, 5);
|
||||
SBIT(AC, 0xD0, 6);
|
||||
SBIT(CY, 0xD0, 7);
|
||||
SBIT(P, 0xD0, 0);
|
||||
SBIT(F1, 0xD0, 1);
|
||||
SBIT(OV, 0xD0, 2);
|
||||
SBIT(RS0, 0xD0, 3);
|
||||
SBIT(RS1, 0xD0, 4);
|
||||
SBIT(F0, 0xD0, 5);
|
||||
SBIT(AC, 0xD0, 6);
|
||||
SBIT(CY, 0xD0, 7);
|
||||
|
||||
SFR(EICON, 0xD8);
|
||||
// Bit 0 read-only, always reads '0'
|
||||
// Bit 1 read-only, always reads '0'
|
||||
// Bit 2 read-only, always reads '0'
|
||||
SBIT(INT6, 0xD8, 3);
|
||||
SBIT(RESI, 0xD8, 4);
|
||||
SBIT(ERESI, 0xD8, 5);
|
||||
// Bit 6 read-only, always reads '1'
|
||||
SBIT(SMOD1, 0xD8, 7);
|
||||
/* Bit 0 read-only, always reads '0' */
|
||||
/* Bit 1 read-only, always reads '0' */
|
||||
/* Bit 2 read-only, always reads '0' */
|
||||
SBIT(INT6, 0xD8, 3);
|
||||
SBIT(RESI, 0xD8, 4);
|
||||
SBIT(ERESI, 0xD8, 5);
|
||||
/* Bit 6 read-only, always reads '1' */
|
||||
SBIT(SMOD1, 0xD8, 7);
|
||||
|
||||
SFR(ACC, 0xE0);
|
||||
|
||||
SFR(EIE, 0xE8);
|
||||
SBIT(EUSB, 0xE8, 0);
|
||||
SBIT(EI2C, 0xE8, 1);
|
||||
SBIT(EX4, 0xE8, 2);
|
||||
SBIT(EX5, 0xE8, 3);
|
||||
SBIT(EWDI, 0xE8, 4);
|
||||
// Bit 5 read-only, always reads '1'
|
||||
// Bit 6 read-only, always reads '1'
|
||||
// Bit 7 read-only, always reads '1'
|
||||
SBIT(EUSB, 0xE8, 0);
|
||||
SBIT(EI2C, 0xE8, 1);
|
||||
SBIT(EX4, 0xE8, 2);
|
||||
SBIT(EX5, 0xE8, 3);
|
||||
SBIT(EWDI, 0xE8, 4);
|
||||
/* Bit 5 read-only, always reads '1' */
|
||||
/* Bit 6 read-only, always reads '1' */
|
||||
/* Bit 7 read-only, always reads '1' */
|
||||
|
||||
SFR(B, 0xF0);
|
||||
|
||||
SFR(EIP, 0xF8);
|
||||
SBIT(PUSB, 0xF8, 0);
|
||||
SBIT(PI2C, 0xF8, 1);
|
||||
SBIT(PX4, 0xF8, 2);
|
||||
SBIT(PX5, 0xF8, 3);
|
||||
SBIT(PX6, 0xF8, 4);
|
||||
// Bit 5 read-only, always reads '1'
|
||||
// Bit 6 read-only, always reads '1'
|
||||
// Bit 7 read-only, always reads '1'
|
||||
SBIT(PUSB, 0xF8, 0);
|
||||
SBIT(PI2C, 0xF8, 1);
|
||||
SBIT(PX4, 0xF8, 2);
|
||||
SBIT(PX5, 0xF8, 3);
|
||||
SBIT(PX6, 0xF8, 4);
|
||||
/* Bit 5 read-only, always reads '1' */
|
||||
/* Bit 6 read-only, always reads '1' */
|
||||
/* Bit 7 read-only, always reads '1' */
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************** XDATA Registers *****************************/
|
||||
/***************************************************************************/
|
||||
/**************************************************************************
|
||||
***************************** XDATA Registers ****************************
|
||||
***************************************************************************/
|
||||
|
||||
/************************ Endpoint 0-7 Data Buffers ************************/
|
||||
SFRX(OUT7BUF[64], 0x7B40);
|
||||
|
@ -269,7 +269,7 @@ SFRX(OUT1BUF[64], 0x7E40);
|
|||
SFRX(IN1BUF[64], 0x7E80);
|
||||
SFRX(OUT0BUF[64], 0x7EC0);
|
||||
SFRX(IN0BUF[64], 0x7F00);
|
||||
// 0x7F40 - 0x7F5F reserved
|
||||
/* 0x7F40 - 0x7F5F reserved */
|
||||
|
||||
/**************************** Isochronous Data *****************************/
|
||||
SFRX(OUT8DATA, 0x7F60);
|
||||
|
@ -312,9 +312,9 @@ SFRX(OUT16BCL, 0x7F7F);
|
|||
SFRX(CPUCS, 0x7F92);
|
||||
#define RES8051 bmBit0
|
||||
#define CLK24OE bmBit1
|
||||
// Bit 2 read-only, always reads '0'
|
||||
// Bit 3 read-only, always reads '0'
|
||||
// Bits 4...7: Chip Revision
|
||||
/* Bit 2 read-only, always reads '0' */
|
||||
/* Bit 3 read-only, always reads '0' */
|
||||
/* Bits 4...7: Chip Revision */
|
||||
|
||||
SFRX(PORTACFG, 0x7F93);
|
||||
#define T0OUT bmBit0
|
||||
|
@ -437,7 +437,7 @@ SFRX(OEC, 0x7F9E);
|
|||
#define OEC6 bmBit6
|
||||
#define OEC7 bmBit7
|
||||
|
||||
// 0x7F9F reserved
|
||||
/* 0x7F9F reserved */
|
||||
|
||||
/****************** Isochronous Control/Status Registers *******************/
|
||||
SFRX(ISOERR, 0x7FA0);
|
||||
|
@ -455,10 +455,10 @@ SFRX(ISOCTL, 0x7FA1);
|
|||
#define MBZ0 bmBit1
|
||||
#define MBZ1 bmBit2
|
||||
#define PPSTAT bmBit3
|
||||
// Bit 4 unused
|
||||
// Bit 5 unused
|
||||
// Bit 6 unused
|
||||
// Bit 7 unused
|
||||
/* Bit 4 unused */
|
||||
/* Bit 5 unused */
|
||||
/* Bit 6 unused */
|
||||
/* Bit 7 unused */
|
||||
|
||||
SFRX(ZBCOUT, 0x7FA2);
|
||||
#define EP8 bmBit0
|
||||
|
@ -470,8 +470,8 @@ SFRX(ZBCOUT, 0x7FA2);
|
|||
#define EP14 bmBit6
|
||||
#define EP15 bmBit7
|
||||
|
||||
// 0x7FA3 reserved
|
||||
// 0x7FA4 reserved
|
||||
/* 0x7FA3 reserved */
|
||||
/* 0x7FA4 reserved */
|
||||
|
||||
/****************************** I2C Registers ******************************/
|
||||
SFRX(I2CS, 0x7FA5);
|
||||
|
@ -485,18 +485,18 @@ SFRX(I2CS, 0x7FA5);
|
|||
#define I2C_START bmBit7
|
||||
|
||||
SFRX(I2DAT, 0x7FA6);
|
||||
// 0x7FA7 reserved
|
||||
/* 0x7FA7 reserved */
|
||||
|
||||
/******************************* Interrupts ********************************/
|
||||
SFRX(IVEC, 0x7FA8);
|
||||
// Bit 0 read-only, always reads '0'
|
||||
// Bit 1 read-only, always reads '0'
|
||||
/* Bit 0 read-only, always reads '0' */
|
||||
/* Bit 1 read-only, always reads '0' */
|
||||
#define IV0 bmBit2
|
||||
#define IV1 bmBit3
|
||||
#define IV2 bmBit4
|
||||
#define IV3 bmBit5
|
||||
#define IV4 bmBit6
|
||||
// Bit 7 read-only, always reads '0'
|
||||
/* Bit 7 read-only, always reads '0' */
|
||||
|
||||
SFRX(IN07IRQ, 0x7FA9);
|
||||
#define IN0IR bmBit0
|
||||
|
@ -524,9 +524,9 @@ SFRX(USBIRQ, 0x7FAB);
|
|||
#define SUTOKIR bmBit2
|
||||
#define SUSPIR bmBit3
|
||||
#define URESIR bmBit4
|
||||
// Bit 5 unused
|
||||
// Bit 6 unused
|
||||
// Bit 7 unused
|
||||
/* Bit 5 unused */
|
||||
/* Bit 6 unused */
|
||||
/* Bit 7 unused */
|
||||
|
||||
SFRX(IN07IEN, 0x7FAC);
|
||||
#define IN0IEN bmBit0
|
||||
|
@ -554,22 +554,22 @@ SFRX(USBIEN, 0x7FAE);
|
|||
#define SUTOKIE bmBit2
|
||||
#define SUSPIE bmBit3
|
||||
#define URESIE bmBit4
|
||||
// Bit 5 unused
|
||||
// Bit 6 unused
|
||||
// Bit 7 unused
|
||||
/* Bit 5 unused */
|
||||
/* Bit 6 unused */
|
||||
/* Bit 7 unused */
|
||||
|
||||
SFRX(USBBAV, 0x7FAF);
|
||||
#define AVEN bmBit0
|
||||
#define BPEN bmBit1
|
||||
#define BPPULSE bmBit2
|
||||
#define BREAK bmBit3
|
||||
// Bit 4 unused
|
||||
// Bit 5 unused
|
||||
// Bit 6 unused
|
||||
// Bit 7 unused
|
||||
/* Bit 4 unused */
|
||||
/* Bit 5 unused */
|
||||
/* Bit 6 unused */
|
||||
/* Bit 7 unused */
|
||||
|
||||
// 0x7FB0 reserved
|
||||
// 0x7FB1 reserved
|
||||
/* 0x7FB0 reserved */
|
||||
/* 0x7FB1 reserved */
|
||||
SFRX(BPADDRH, 0x7FB2);
|
||||
SFRX(BPADDRL, 0x7FB3);
|
||||
|
||||
|
@ -579,10 +579,10 @@ SFRX(EP0CS, 0x7FB4);
|
|||
#define HSNAK bmBit1
|
||||
#define IN0BSY bmBit2
|
||||
#define OUT0BSY bmBit3
|
||||
// Bit 4 unused
|
||||
// Bit 5 unused
|
||||
// Bit 6 unused
|
||||
// Bit 7 unused
|
||||
/* Bit 4 unused */
|
||||
/* Bit 5 unused */
|
||||
/* Bit 6 unused */
|
||||
/* Bit 7 unused */
|
||||
|
||||
SFRX(IN0BC, 0x7FB5);
|
||||
SFRX(IN1CS, 0x7FB6);
|
||||
|
@ -599,7 +599,7 @@ SFRX(IN6CS, 0x7FC0);
|
|||
SFRX(IN6BC, 0x7FC1);
|
||||
SFRX(IN7CS, 0x7FC2);
|
||||
SFRX(IN7BC, 0x7FC3);
|
||||
// 0x7FC4 reserved
|
||||
/* 0x7FC4 reserved */
|
||||
SFRX(OUT0BC, 0x7FC5);
|
||||
SFRX(OUT1CS, 0x7FC6);
|
||||
SFRX(OUT1BC, 0x7FC7);
|
||||
|
@ -630,16 +630,16 @@ SFRX(USBCS, 0x7FD6);
|
|||
#define RENUM bmBit1
|
||||
#define DISCOE bmBit2
|
||||
#define DISCON bmBit3
|
||||
// Bit 4 unused
|
||||
// Bit 5 unused
|
||||
// Bit 6 unused
|
||||
/* Bit 4 unused */
|
||||
/* Bit 5 unused */
|
||||
/* Bit 6 unused */
|
||||
#define WAKESRC bmBit7
|
||||
|
||||
SFRX(TOGCTL, 0x7FD7);
|
||||
#define TOG_EP0 bmBit0
|
||||
#define TOG_EP1 bmBit1
|
||||
#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_R bmBit5
|
||||
#define TOG_S bmBit6
|
||||
|
@ -647,9 +647,9 @@ SFRX(TOGCTL, 0x7FD7);
|
|||
|
||||
SFRX(USBFRAMEL, 0x7FD8);
|
||||
SFRX(USBFRAMEH, 0x7FD9);
|
||||
// 0x7FDA reserved
|
||||
/* 0x7FDA reserved */
|
||||
SFRX(FNADDR, 0x7FDB);
|
||||
// 0x7FDC reserved
|
||||
/* 0x7FDC reserved */
|
||||
|
||||
SFRX(USBPAIR, 0x7FDD);
|
||||
#define PR2IN bmBit0
|
||||
|
@ -658,11 +658,11 @@ SFRX(USBPAIR, 0x7FDD);
|
|||
#define PR2OUT bmBit3
|
||||
#define PR4OUT bmBit4
|
||||
#define PR6OUT bmBit5
|
||||
// Bit 6 unused
|
||||
/* Bit 6 unused */
|
||||
#define ISOSEND0 bmBit7
|
||||
|
||||
SFRX(IN07VAL, 0x7FDE);
|
||||
// Bit 0 is read-only, always reads '1'
|
||||
/* Bit 0 is read-only, always reads '1' */
|
||||
#define IN1VAL bmBit1
|
||||
#define IN2VAL bmBit2
|
||||
#define IN3VAL bmBit3
|
||||
|
@ -672,7 +672,7 @@ SFRX(IN07VAL, 0x7FDE);
|
|||
#define IN7VAL bmBit7
|
||||
|
||||
SFRX(OUT07VAL, 0x7FDF);
|
||||
// Bit 0 is read-only, always reads '1'
|
||||
/* Bit 0 is read-only, always reads '1' */
|
||||
#define OUT1VAL bmBit1
|
||||
#define OUT2VAL bmBit2
|
||||
#define OUT3VAL bmBit3
|
||||
|
@ -714,8 +714,8 @@ SFRX(FASTXFR, 0x7FE2);
|
|||
SFRX(AUTOPTRH, 0x7FE3);
|
||||
SFRX(AUTOPTRL, 0x7FE4);
|
||||
SFRX(AUTODATA, 0x7FE5);
|
||||
// 0x7FE6 reserved
|
||||
// 0x7FE7 reserved
|
||||
/* 0x7FE6 reserved */
|
||||
/* 0x7FE7 reserved */
|
||||
|
||||
/******************************* Setup Data ********************************/
|
||||
SFRX(SETUPDAT[8], 0x7FE8);
|
||||
|
|
|
@ -26,15 +26,15 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define NULL (void*)0;
|
||||
#define NULL (void *)0;
|
||||
|
||||
/* High and Low byte of a word (uint16_t) */
|
||||
#define HI8(word) (uint8_t)(((uint16_t)word >> 8) & 0xff)
|
||||
#define LO8(word) (uint8_t)((uint16_t)word & 0xff)
|
||||
|
||||
/* Convenience functions */
|
||||
#define STALL_EP0() EP0CS |= EP0STALL
|
||||
#define CLEAR_IRQ() EXIF &= ~USBINT
|
||||
#define STALL_EP0() (EP0CS |= EP0STALL)
|
||||
#define CLEAR_IRQ() (EXIF &= ~USBINT)
|
||||
|
||||
/*********** USB descriptors. See section 9.5 of the USB 1.1 spec **********/
|
||||
|
||||
|
@ -45,84 +45,84 @@
|
|||
#define DESCRIPTOR_TYPE_INTERFACE 0x04
|
||||
#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 */
|
||||
struct usb_device_descriptor {
|
||||
uint8_t bLength; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; ///< DEVICE Descriptor Type.
|
||||
uint16_t bcdUSB; ///< USB specification release number (BCD).
|
||||
uint8_t bDeviceClass; ///< Class code.
|
||||
uint8_t bDeviceSubClass; ///< Subclass code.
|
||||
uint8_t bDeviceProtocol; ///< Protocol code.
|
||||
uint8_t bMaxPacketSize0; ///< Maximum packet size for EP0 (8, 16, 32, 64).
|
||||
uint16_t idVendor; ///< USB Vendor ID.
|
||||
uint16_t idProduct; ///< USB Product ID.
|
||||
uint16_t bcdDevice; ///< Device Release Number (BCD).
|
||||
uint8_t iManufacturer; ///< Index of manufacturer string descriptor.
|
||||
uint8_t iProduct; ///< Index of product string descriptor.
|
||||
uint8_t iSerialNumber; ///< Index of string descriptor containing serial #.
|
||||
uint8_t bNumConfigurations; ///< Number of possible configurations.
|
||||
uint8_t bLength; /* /< Size of this descriptor in bytes. */
|
||||
uint8_t bDescriptorType;/* /< DEVICE Descriptor Type. */
|
||||
uint16_t bcdUSB; /* /< USB specification release number (BCD). */
|
||||
uint8_t bDeviceClass; /* /< Class code. */
|
||||
uint8_t bDeviceSubClass;/* /< Subclass code. */
|
||||
uint8_t bDeviceProtocol;/* /< Protocol code. */
|
||||
uint8_t bMaxPacketSize0;/* /< Maximum packet size for EP0 (8, 16, 32, 64). */
|
||||
uint16_t idVendor; /* /< USB Vendor ID. */
|
||||
uint16_t idProduct; /* /< USB Product ID. */
|
||||
uint16_t bcdDevice; /* /< Device Release Number (BCD). */
|
||||
uint8_t iManufacturer; /* /< Index of manufacturer string descriptor. */
|
||||
uint8_t iProduct; /* /< Index of product string descriptor. */
|
||||
uint8_t iSerialNumber; /* /< Index of string descriptor containing serial #. */
|
||||
uint8_t bNumConfigurations; /* /< Number of possible configurations. */
|
||||
};
|
||||
|
||||
/** USB Configuration Descriptor. See USB 1.1 spec, pp. 199 - 200 */
|
||||
struct usb_config_descriptor {
|
||||
uint8_t bLength; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; ///< CONFIGURATION descriptor type.
|
||||
uint16_t wTotalLength; ///< Combined total length of all descriptors.
|
||||
uint8_t bNumInterfaces; ///< Number of interfaces in this configuration.
|
||||
uint8_t bConfigurationValue;///< Value used to select this configuration.
|
||||
uint8_t iConfiguration; ///< Index of configuration string descriptor.
|
||||
uint8_t bmAttributes; ///< Configuration characteristics.
|
||||
uint8_t MaxPower; ///< Maximum power consumption in 2 mA units.
|
||||
uint8_t bLength; /* /< Size of this descriptor in bytes. */
|
||||
uint8_t bDescriptorType;/* /< CONFIGURATION descriptor type. */
|
||||
uint16_t wTotalLength; /* /< Combined total length of all descriptors. */
|
||||
uint8_t bNumInterfaces; /* /< Number of interfaces in this configuration. */
|
||||
uint8_t bConfigurationValue; /* /< Value used to select this configuration. */
|
||||
uint8_t iConfiguration; /* /< Index of configuration string descriptor. */
|
||||
uint8_t bmAttributes; /* /< Configuration characteristics. */
|
||||
uint8_t MaxPower; /* /< Maximum power consumption in 2 mA units. */
|
||||
};
|
||||
|
||||
/** USB Interface Descriptor. See USB 1.1 spec, pp. 201 - 203 */
|
||||
struct usb_interface_descriptor {
|
||||
uint8_t bLength; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; ///< INTERFACE descriptor type.
|
||||
uint8_t bInterfaceNumber; ///< Interface number.
|
||||
uint8_t bAlternateSetting; ///< Value used to select alternate setting.
|
||||
uint8_t bNumEndpoints; ///< Number of endpoints used by this interface.
|
||||
uint8_t bInterfaceClass; ///< Class code.
|
||||
uint8_t bInterfaceSubclass; ///< Subclass code.
|
||||
uint8_t bInterfaceProtocol; ///< Protocol code.
|
||||
uint8_t iInterface; ///< Index of interface string descriptor.
|
||||
uint8_t bLength; /* /< Size of this descriptor in bytes. */
|
||||
uint8_t bDescriptorType;/* /< INTERFACE descriptor type. */
|
||||
uint8_t bInterfaceNumber; /* /< Interface number. */
|
||||
uint8_t bAlternateSetting; /* /< Value used to select alternate setting. */
|
||||
uint8_t bNumEndpoints; /* /< Number of endpoints used by this interface. */
|
||||
uint8_t bInterfaceClass;/* /< Class code. */
|
||||
uint8_t bInterfaceSubclass; /* /< Subclass code. */
|
||||
uint8_t bInterfaceProtocol; /* /< Protocol code. */
|
||||
uint8_t iInterface; /* /< Index of interface string descriptor. */
|
||||
};
|
||||
|
||||
/** USB Endpoint Descriptor. See USB 1.1 spec, pp. 203 - 204 */
|
||||
struct usb_endpoint_descriptor {
|
||||
uint8_t bLength; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; ///< ENDPOINT descriptor type.
|
||||
uint8_t bEndpointAddress; ///< Endpoint Address: 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.
|
||||
uint8_t bInterval; ///< Polling interval (in ms) for this endpoint.
|
||||
uint8_t bLength; /* /< Size of this descriptor in bytes. */
|
||||
uint8_t bDescriptorType;/* /< ENDPOINT descriptor type. */
|
||||
uint8_t bEndpointAddress; /* /< Endpoint Address: 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. */
|
||||
uint8_t bInterval; /* /< Polling interval (in ms) for this endpoint. */
|
||||
};
|
||||
|
||||
/** USB Language Descriptor. See USB 1.1 spec, pp. 204 - 205 */
|
||||
struct usb_language_descriptor {
|
||||
uint8_t bLength; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; ///< STRING descriptor type.
|
||||
uint16_t wLANGID[]; ///< LANGID codes.
|
||||
uint8_t bLength; /* /< Size of this descriptor in bytes. */
|
||||
uint8_t bDescriptorType;/* /< STRING descriptor type. */
|
||||
uint16_t wLANGID[]; /* /< LANGID codes. */
|
||||
};
|
||||
|
||||
/** USB String Descriptor. See USB 1.1 spec, pp. 204 - 205 */
|
||||
struct usb_string_descriptor {
|
||||
uint8_t bLength; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; ///< STRING descriptor type.
|
||||
uint16_t bString[]; ///< UNICODE encoded string.
|
||||
uint8_t bLength; /* /< Size of this descriptor in bytes. */
|
||||
uint8_t bDescriptorType;/* /< STRING descriptor type. */
|
||||
uint16_t bString[]; /* /< UNICODE encoded string. */
|
||||
};
|
||||
|
||||
/********************** USB Control Endpoint 0 related *********************/
|
||||
|
||||
/** USB Control Setup Data. See USB 1.1 spec, pp. 183 - 185 */
|
||||
struct setup_data {
|
||||
uint8_t bmRequestType; ///< Characteristics of a request.
|
||||
uint8_t bRequest; ///< Specific request.
|
||||
uint16_t wValue; ///< 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.
|
||||
uint8_t bmRequestType; /* /< Characteristics of a request. */
|
||||
uint8_t bRequest; /* /< Specific request. */
|
||||
uint16_t wValue; /* /< 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. */
|
||||
};
|
||||
|
||||
/* 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 */
|
||||
#define GET_STATUS 0
|
||||
#define CLEAR_FEATURE 1
|
||||
// Value '2' is reserved for future use
|
||||
/* Value '2' is reserved for future use */
|
||||
#define SET_FEATURE 3
|
||||
// Value '4' is reserved for future use
|
||||
/* Value '4' is reserved for future use */
|
||||
#define SET_ADDRESS 5
|
||||
#define GET_DESCRIPTOR 6
|
||||
#define SET_DESCRIPTOR 7
|
||||
|
@ -226,33 +226,33 @@ extern volatile __xdata __at 0x7FE8 struct setup_data setup_data;
|
|||
|
||||
/** USB Interrupts. See AN2131-TRM, page 9-4 for details */
|
||||
enum usb_isr {
|
||||
SUDAV_ISR = 13,
|
||||
SOF_ISR,
|
||||
SUTOK_ISR,
|
||||
SUSPEND_ISR,
|
||||
USBRESET_ISR,
|
||||
IBN_ISR,
|
||||
EP0IN_ISR,
|
||||
EP0OUT_ISR,
|
||||
EP1IN_ISR,
|
||||
EP1OUT_ISR,
|
||||
EP2IN_ISR,
|
||||
EP2OUT_ISR,
|
||||
EP3IN_ISR,
|
||||
EP3OUT_ISR,
|
||||
EP4IN_ISR,
|
||||
EP4OUT_ISR,
|
||||
EP5IN_ISR,
|
||||
EP5OUT_ISR,
|
||||
EP6IN_ISR,
|
||||
EP6OUT_ISR,
|
||||
EP7IN_ISR,
|
||||
EP7OUT_ISR
|
||||
SUDAV_ISR = 13,
|
||||
SOF_ISR,
|
||||
SUTOK_ISR,
|
||||
SUSPEND_ISR,
|
||||
USBRESET_ISR,
|
||||
IBN_ISR,
|
||||
EP0IN_ISR,
|
||||
EP0OUT_ISR,
|
||||
EP1IN_ISR,
|
||||
EP1OUT_ISR,
|
||||
EP2IN_ISR,
|
||||
EP2OUT_ISR,
|
||||
EP3IN_ISR,
|
||||
EP3OUT_ISR,
|
||||
EP4IN_ISR,
|
||||
EP4OUT_ISR,
|
||||
EP5IN_ISR,
|
||||
EP5OUT_ISR,
|
||||
EP6IN_ISR,
|
||||
EP6OUT_ISR,
|
||||
EP7IN_ISR,
|
||||
EP7OUT_ISR
|
||||
};
|
||||
|
||||
/*************************** 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);
|
||||
|
||||
bool usb_handle_get_status(void);
|
||||
|
|
|
@ -22,30 +22,30 @@
|
|||
|
||||
void delay_5us(void)
|
||||
{
|
||||
NOP;
|
||||
NOP;
|
||||
}
|
||||
|
||||
void delay_1ms(void) {
|
||||
uint16_t i;
|
||||
void delay_1ms(void)
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
for (i = 0; i < 598; i++);
|
||||
for (i = 0; i < 598; i++)
|
||||
;
|
||||
}
|
||||
|
||||
void delay_us(uint16_t delay)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t maxcount = (delay / 5);
|
||||
uint16_t i;
|
||||
uint16_t maxcount = (delay / 5);
|
||||
|
||||
for (i = 0; i < maxcount; i++) {
|
||||
delay_5us();
|
||||
}
|
||||
for (i = 0; i < maxcount; i++)
|
||||
delay_5us();
|
||||
}
|
||||
|
||||
void delay_ms(uint16_t delay)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t i;
|
||||
|
||||
for (i = 0; i < delay; i++) {
|
||||
delay_1ms();
|
||||
}
|
||||
for (i = 0; i < delay; i++)
|
||||
delay_1ms();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -49,43 +49,43 @@ extern void ep7out_isr(void) __interrupt;
|
|||
|
||||
void io_init(void)
|
||||
{
|
||||
/* PORTxCFG register bits select alternate functions (1 == alternate function,
|
||||
* 0 == standard I/O)
|
||||
* OEx register bits turn on/off output buffer (1 == output, 0 == input)
|
||||
* OUTx register bits determine pin state of output
|
||||
* PINx register bits reflect pin state (high == 1, low == 0) */
|
||||
/* PORTxCFG register bits select alternate functions (1 == alternate function,
|
||||
* 0 == standard I/O)
|
||||
* OEx register bits turn on/off output buffer (1 == output, 0 == input)
|
||||
* OUTx register bits determine pin state of output
|
||||
* PINx register bits reflect pin state (high == 1, low == 0) */
|
||||
|
||||
/* PORT A */
|
||||
PORTACFG = PIN_OE;
|
||||
OEA = PIN_U_OE | PIN_OE | PIN_RUN_LED | PIN_COM_LED;
|
||||
OUTA = PIN_RUN_LED | PIN_COM_LED;
|
||||
/* PORT A */
|
||||
PORTACFG = PIN_OE;
|
||||
OEA = PIN_U_OE | PIN_OE | PIN_RUN_LED | PIN_COM_LED;
|
||||
OUTA = PIN_RUN_LED | PIN_COM_LED;
|
||||
|
||||
/* PORT B */
|
||||
PORTBCFG = 0x00;
|
||||
OEB = PIN_TDI | PIN_TMS | PIN_TCK | PIN_TRST | PIN_BRKIN | PIN_RESET
|
||||
| PIN_OCDSE;
|
||||
/* PORT B */
|
||||
PORTBCFG = 0x00;
|
||||
OEB = PIN_TDI | PIN_TMS | PIN_TCK | PIN_TRST | PIN_BRKIN | PIN_RESET
|
||||
| PIN_OCDSE;
|
||||
|
||||
/* TRST and RESET signals are low-active but inverted by hardware, so we clear
|
||||
* these signals here! */
|
||||
OUTB = 0x00;
|
||||
/* TRST and RESET signals are low-active but inverted by hardware, so we clear
|
||||
* these signals here! */
|
||||
OUTB = 0x00;
|
||||
|
||||
/* PORT C */
|
||||
PORTCCFG = PIN_WR;
|
||||
OEC = PIN_TXD0 | PIN_WR;
|
||||
OUTC = 0x00;
|
||||
/* PORT C */
|
||||
PORTCCFG = PIN_WR;
|
||||
OEC = PIN_TXD0 | PIN_WR;
|
||||
OUTC = 0x00;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
io_init();
|
||||
usb_init();
|
||||
io_init();
|
||||
usb_init();
|
||||
|
||||
/* Enable Interrupts */
|
||||
EA = 1;
|
||||
/* Enable Interrupts */
|
||||
EA = 1;
|
||||
|
||||
/* Begin executing command(s). This function never returns. */
|
||||
command_loop();
|
||||
/* Begin executing command(s). This function never returns. */
|
||||
command_loop();
|
||||
|
||||
/* Never reached, but SDCC complains about missing return statement */
|
||||
return 0;
|
||||
/* Never reached, but SDCC complains about missing return statement */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@
|
|||
* are configured to use the maximum packet size for full-speed transfers,
|
||||
* 64 bytes. Commands always start with a command ID (see msgtypes.h for
|
||||
* command ID definitions) and contain zero or more payload data bytes in both
|
||||
* transfer directions (IN and OUT). The payload
|
||||
* transfer directions (IN and OUT). The payload
|
||||
*
|
||||
* Almost all commands contain a fixed number of payload data bytes. The number
|
||||
* of payload data bytes for the IN and OUT direction does not need to be the
|
||||
* same.
|
||||
*
|
||||
*
|
||||
* Multiple commands may be sent in one EP2 Bulk-OUT packet. Because the
|
||||
* OpenULINK firmware does not perform bounds checking for EP2 Bulk-IN packets,
|
||||
* the host MUST ensure that the commands sent in the OUT packet require a
|
||||
|
@ -57,23 +57,19 @@ volatile uint8_t payload_index_in;
|
|||
*/
|
||||
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) {
|
||||
SET_RUN_LED();
|
||||
}
|
||||
if (led_state & RUN_LED_ON)
|
||||
SET_RUN_LED();
|
||||
|
||||
if (led_state & COM_LED_ON) {
|
||||
SET_COM_LED();
|
||||
}
|
||||
if (led_state & COM_LED_ON)
|
||||
SET_COM_LED();
|
||||
|
||||
if (led_state & RUN_LED_OFF) {
|
||||
CLEAR_RUN_LED();
|
||||
}
|
||||
if (led_state & RUN_LED_OFF)
|
||||
CLEAR_RUN_LED();
|
||||
|
||||
if (led_state & COM_LED_OFF) {
|
||||
CLEAR_COM_LED();
|
||||
}
|
||||
if (led_state & COM_LED_OFF)
|
||||
CLEAR_COM_LED();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,123 +83,122 @@ void execute_set_led_command(void)
|
|||
*/
|
||||
bool execute_command(void)
|
||||
{
|
||||
uint8_t usb_out_bytecount, usb_in_bytecount;
|
||||
uint16_t signal_state;
|
||||
uint16_t count;
|
||||
uint8_t usb_out_bytecount, usb_in_bytecount;
|
||||
uint16_t signal_state;
|
||||
uint16_t count;
|
||||
|
||||
/* Most commands do not transfer IN data. To save code space, we write 0 to
|
||||
* usb_in_bytecount here, then modify it in the switch statement below where
|
||||
* neccessary */
|
||||
usb_in_bytecount = 0;
|
||||
/* Most commands do not transfer IN data. To save code space, we write 0 to
|
||||
* usb_in_bytecount here, then modify it in the switch statement below where
|
||||
* neccessary */
|
||||
usb_in_bytecount = 0;
|
||||
|
||||
switch (OUT2BUF[cmd_id_index] /* Command ID */) {
|
||||
case CMD_SCAN_IN:
|
||||
usb_out_bytecount = 5;
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
jtag_scan_in(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_SCAN_OUT:
|
||||
usb_out_bytecount = OUT2BUF[cmd_id_index + 1] + 5;
|
||||
jtag_scan_out(cmd_id_index + 1);
|
||||
break;
|
||||
case CMD_SCAN_IO:
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
usb_out_bytecount = usb_in_bytecount + 5;
|
||||
jtag_scan_io(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_CLOCK_TMS:
|
||||
usb_out_bytecount = 2;
|
||||
jtag_clock_tms(OUT2BUF[cmd_id_index + 1], OUT2BUF[cmd_id_index + 2]);
|
||||
break;
|
||||
case CMD_CLOCK_TCK:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
jtag_clock_tck(count);
|
||||
break;
|
||||
case CMD_SLOW_SCAN_IN:
|
||||
usb_out_bytecount = 5;
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
jtag_slow_scan_in(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_SLOW_SCAN_OUT:
|
||||
usb_out_bytecount = OUT2BUF[cmd_id_index + 1] + 5;
|
||||
jtag_slow_scan_out(cmd_id_index + 1);
|
||||
break;
|
||||
case CMD_SLOW_SCAN_IO:
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
usb_out_bytecount = usb_in_bytecount + 5;
|
||||
jtag_slow_scan_io(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_SLOW_CLOCK_TMS:
|
||||
usb_out_bytecount = 2;
|
||||
jtag_slow_clock_tms(OUT2BUF[cmd_id_index + 1], OUT2BUF[cmd_id_index + 2]);
|
||||
break;
|
||||
case CMD_SLOW_CLOCK_TCK:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
jtag_slow_clock_tck(count);
|
||||
break;
|
||||
case CMD_SLEEP_US:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
delay_us(count);
|
||||
break;
|
||||
case CMD_SLEEP_MS:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
delay_ms(count);
|
||||
break;
|
||||
case CMD_GET_SIGNALS:
|
||||
usb_out_bytecount = 0;
|
||||
usb_in_bytecount = 2;
|
||||
signal_state = jtag_get_signals();
|
||||
IN2BUF[payload_index_in] = (signal_state >> 8) & 0x00FF;
|
||||
IN2BUF[payload_index_in + 1] = signal_state & 0x00FF;
|
||||
break;
|
||||
case CMD_SET_SIGNALS:
|
||||
usb_out_bytecount = 2;
|
||||
jtag_set_signals(OUT2BUF[cmd_id_index + 1], OUT2BUF[cmd_id_index + 2]);
|
||||
break;
|
||||
case CMD_CONFIGURE_TCK_FREQ:
|
||||
usb_out_bytecount = 5;
|
||||
jtag_configure_tck_delay(
|
||||
OUT2BUF[cmd_id_index + 1], /* scan_in */
|
||||
OUT2BUF[cmd_id_index + 2], /* scan_out */
|
||||
OUT2BUF[cmd_id_index + 3], /* scan_io */
|
||||
OUT2BUF[cmd_id_index + 4], /* clock_tck */
|
||||
OUT2BUF[cmd_id_index + 5]); /* clock_tms */
|
||||
break;
|
||||
case CMD_SET_LEDS:
|
||||
usb_out_bytecount = 1;
|
||||
execute_set_led_command();
|
||||
break;
|
||||
case CMD_TEST:
|
||||
usb_out_bytecount = 1;
|
||||
/* Do nothing... This command is only used to test if the device is ready
|
||||
* to accept new commands */
|
||||
break;
|
||||
default:
|
||||
/* Should never be reached */
|
||||
usb_out_bytecount = 0;
|
||||
break;
|
||||
}
|
||||
switch (OUT2BUF[cmd_id_index] /* Command ID */) {
|
||||
case CMD_SCAN_IN:
|
||||
usb_out_bytecount = 5;
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
jtag_scan_in(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_SCAN_OUT:
|
||||
usb_out_bytecount = OUT2BUF[cmd_id_index + 1] + 5;
|
||||
jtag_scan_out(cmd_id_index + 1);
|
||||
break;
|
||||
case CMD_SCAN_IO:
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
usb_out_bytecount = usb_in_bytecount + 5;
|
||||
jtag_scan_io(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_CLOCK_TMS:
|
||||
usb_out_bytecount = 2;
|
||||
jtag_clock_tms(OUT2BUF[cmd_id_index + 1], OUT2BUF[cmd_id_index + 2]);
|
||||
break;
|
||||
case CMD_CLOCK_TCK:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
jtag_clock_tck(count);
|
||||
break;
|
||||
case CMD_SLOW_SCAN_IN:
|
||||
usb_out_bytecount = 5;
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
jtag_slow_scan_in(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_SLOW_SCAN_OUT:
|
||||
usb_out_bytecount = OUT2BUF[cmd_id_index + 1] + 5;
|
||||
jtag_slow_scan_out(cmd_id_index + 1);
|
||||
break;
|
||||
case CMD_SLOW_SCAN_IO:
|
||||
usb_in_bytecount = OUT2BUF[cmd_id_index + 1];
|
||||
usb_out_bytecount = usb_in_bytecount + 5;
|
||||
jtag_slow_scan_io(cmd_id_index + 1, payload_index_in);
|
||||
break;
|
||||
case CMD_SLOW_CLOCK_TMS:
|
||||
usb_out_bytecount = 2;
|
||||
jtag_slow_clock_tms(OUT2BUF[cmd_id_index + 1], OUT2BUF[cmd_id_index + 2]);
|
||||
break;
|
||||
case CMD_SLOW_CLOCK_TCK:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
jtag_slow_clock_tck(count);
|
||||
break;
|
||||
case CMD_SLEEP_US:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
delay_us(count);
|
||||
break;
|
||||
case CMD_SLEEP_MS:
|
||||
usb_out_bytecount = 2;
|
||||
count = (uint16_t)OUT2BUF[cmd_id_index + 1];
|
||||
count |= ((uint16_t)OUT2BUF[cmd_id_index + 2]) << 8;
|
||||
delay_ms(count);
|
||||
break;
|
||||
case CMD_GET_SIGNALS:
|
||||
usb_out_bytecount = 0;
|
||||
usb_in_bytecount = 2;
|
||||
signal_state = jtag_get_signals();
|
||||
IN2BUF[payload_index_in] = (signal_state >> 8) & 0x00FF;
|
||||
IN2BUF[payload_index_in + 1] = signal_state & 0x00FF;
|
||||
break;
|
||||
case CMD_SET_SIGNALS:
|
||||
usb_out_bytecount = 2;
|
||||
jtag_set_signals(OUT2BUF[cmd_id_index + 1], OUT2BUF[cmd_id_index + 2]);
|
||||
break;
|
||||
case CMD_CONFIGURE_TCK_FREQ:
|
||||
usb_out_bytecount = 5;
|
||||
jtag_configure_tck_delay(
|
||||
OUT2BUF[cmd_id_index + 1], /* scan_in */
|
||||
OUT2BUF[cmd_id_index + 2], /* scan_out */
|
||||
OUT2BUF[cmd_id_index + 3], /* scan_io */
|
||||
OUT2BUF[cmd_id_index + 4], /* clock_tck */
|
||||
OUT2BUF[cmd_id_index + 5]); /* clock_tms */
|
||||
break;
|
||||
case CMD_SET_LEDS:
|
||||
usb_out_bytecount = 1;
|
||||
execute_set_led_command();
|
||||
break;
|
||||
case CMD_TEST:
|
||||
usb_out_bytecount = 1;
|
||||
/* Do nothing... This command is only used to test if the device is ready
|
||||
* to accept new commands */
|
||||
break;
|
||||
default:
|
||||
/* Should never be reached */
|
||||
usb_out_bytecount = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Update EP2 Bulk-IN data byte count */
|
||||
payload_index_in += usb_in_bytecount;
|
||||
/* Update EP2 Bulk-IN data byte count */
|
||||
payload_index_in += usb_in_bytecount;
|
||||
|
||||
/* Determine if this was the last command */
|
||||
if ((cmd_id_index + usb_out_bytecount + 1) >= OUT2BC) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
/* Not the last command, update cmd_id_index */
|
||||
cmd_id_index += (usb_out_bytecount + 1);
|
||||
return false;
|
||||
}
|
||||
/* Determine if this was the last command */
|
||||
if ((cmd_id_index + usb_out_bytecount + 1) >= OUT2BC)
|
||||
return true;
|
||||
else {
|
||||
/* Not the last command, update cmd_id_index */
|
||||
cmd_id_index += (usb_out_bytecount + 1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,35 +206,36 @@ bool execute_command(void)
|
|||
*/
|
||||
void command_loop(void)
|
||||
{
|
||||
bool last_command;
|
||||
bool last_command;
|
||||
|
||||
while (1) {
|
||||
cmd_id_index = 0;
|
||||
payload_index_in = 0;
|
||||
while (1) {
|
||||
cmd_id_index = 0;
|
||||
payload_index_in = 0;
|
||||
|
||||
/* Wait until host sends EP2 Bulk-OUT packet */
|
||||
while (!EP2_out);
|
||||
EP2_out = 0;
|
||||
/* Wait until host sends EP2 Bulk-OUT packet */
|
||||
while (!EP2_out)
|
||||
;
|
||||
EP2_out = 0;
|
||||
|
||||
/* Turn on COM LED to indicate command execution */
|
||||
SET_COM_LED();
|
||||
/* Turn on COM LED to indicate command execution */
|
||||
SET_COM_LED();
|
||||
|
||||
/* Execute the commands */
|
||||
last_command = false;
|
||||
while (last_command == false) {
|
||||
last_command = execute_command();
|
||||
}
|
||||
/* Execute the commands */
|
||||
last_command = false;
|
||||
while (last_command == false)
|
||||
last_command = execute_command();
|
||||
|
||||
CLEAR_COM_LED();
|
||||
|
||||
/* Send back EP2 Bulk-IN packet if required */
|
||||
if (payload_index_in > 0) {
|
||||
IN2BC = payload_index_in;
|
||||
while (!EP2_in);
|
||||
EP2_in = 0;
|
||||
}
|
||||
CLEAR_COM_LED();
|
||||
|
||||
/* Re-arm EP2-OUT after command execution */
|
||||
OUT2BC = 0;
|
||||
}
|
||||
/* Send back EP2 Bulk-IN packet if required */
|
||||
if (payload_index_in > 0) {
|
||||
IN2BC = payload_index_in;
|
||||
while (!EP2_in)
|
||||
;
|
||||
EP2_in = 0;
|
||||
}
|
||||
|
||||
/* Re-arm EP2-OUT after command execution */
|
||||
OUT2BC = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@
|
|||
|
||||
/* Also update external declarations in "include/usb.h" if making changes to
|
||||
* these variables! */
|
||||
volatile bool EP2_out = 0;
|
||||
volatile bool EP2_in = 0;
|
||||
volatile bool EP2_out;
|
||||
volatile bool EP2_in;
|
||||
|
||||
volatile __xdata __at 0x7FE8 struct setup_data setup_data;
|
||||
|
||||
/* Define number of endpoints (except Control Endpoint 0) in a central place.
|
||||
* Be sure to include the neccessary endpoint descriptors! */
|
||||
#define NUM_ENDPOINTS 2
|
||||
#define NUM_ENDPOINTS 2
|
||||
|
||||
/*
|
||||
* Normally, we would initialize the descriptor structures in C99 style:
|
||||
|
@ -57,145 +57,185 @@ volatile __xdata __at 0x7FE8 struct setup_data setup_data;
|
|||
*/
|
||||
|
||||
__code struct usb_device_descriptor device_descriptor = {
|
||||
/* .bLength = */ sizeof(struct usb_device_descriptor),
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_DEVICE,
|
||||
/* .bcdUSB = */ 0x0110, /* BCD: 01.00 (Version 1.0 USB spec) */
|
||||
/* .bDeviceClass = */ 0xFF, /* 0xFF = vendor-specific */
|
||||
/* .bDeviceSubClass = */ 0xFF,
|
||||
/* .bDeviceProtocol = */ 0xFF,
|
||||
/* .bMaxPacketSize0 = */ 64,
|
||||
/* .idVendor = */ 0xC251,
|
||||
/* .idProduct = */ 0x2710,
|
||||
/* .bcdDevice = */ 0x0100,
|
||||
/* .iManufacturer = */ 1,
|
||||
/* .iProduct = */ 2,
|
||||
/* .iSerialNumber = */ 3,
|
||||
/* .bNumConfigurations = */ 1
|
||||
/* .bLength = */ sizeof(struct usb_device_descriptor),
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_DEVICE,
|
||||
/* .bcdUSB = */ 0x0110, /* BCD: 01.00 (Version 1.0 USB spec) */
|
||||
/* .bDeviceClass = */ 0xFF, /* 0xFF = vendor-specific */
|
||||
/* .bDeviceSubClass = */ 0xFF,
|
||||
/* .bDeviceProtocol = */ 0xFF,
|
||||
/* .bMaxPacketSize0 = */ 64,
|
||||
/* .idVendor = */ 0xC251,
|
||||
/* .idProduct = */ 0x2710,
|
||||
/* .bcdDevice = */ 0x0100,
|
||||
/* .iManufacturer = */ 1,
|
||||
/* .iProduct = */ 2,
|
||||
/* .iSerialNumber = */ 3,
|
||||
/* .bNumConfigurations = */ 1
|
||||
};
|
||||
|
||||
/* WARNING: ALL config, interface and endpoint descriptors MUST be adjacent! */
|
||||
|
||||
__code struct usb_config_descriptor config_descriptor = {
|
||||
/* .bLength = */ sizeof(struct usb_config_descriptor),
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_CONFIGURATION,
|
||||
/* .wTotalLength = */ sizeof(struct usb_config_descriptor) +
|
||||
sizeof(struct usb_interface_descriptor) +
|
||||
(NUM_ENDPOINTS *
|
||||
sizeof(struct usb_endpoint_descriptor)),
|
||||
/* .bNumInterfaces = */ 1,
|
||||
/* .bConfigurationValue = */ 1,
|
||||
/* .iConfiguration = */ 4, /* String describing this configuration */
|
||||
/* .bmAttributes = */ 0x80, /* Only MSB set according to USB spec */
|
||||
/* .MaxPower = */ 50 /* 100 mA */
|
||||
/* .bLength = */ sizeof(struct usb_config_descriptor),
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_CONFIGURATION,
|
||||
/* .wTotalLength = */ sizeof(struct usb_config_descriptor) +
|
||||
sizeof(struct usb_interface_descriptor) +
|
||||
(NUM_ENDPOINTS *
|
||||
sizeof(struct usb_endpoint_descriptor)),
|
||||
/* .bNumInterfaces = */ 1,
|
||||
/* .bConfigurationValue = */ 1,
|
||||
/* .iConfiguration = */ 4, /* String describing this configuration */
|
||||
/* .bmAttributes = */ 0x80, /* Only MSB set according to USB spec */
|
||||
/* .MaxPower = */ 50 /* 100 mA */
|
||||
};
|
||||
|
||||
__code struct usb_interface_descriptor interface_descriptor00 = {
|
||||
/* .bLength = */ sizeof(struct usb_interface_descriptor),
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_INTERFACE,
|
||||
/* .bInterfaceNumber = */ 0,
|
||||
/* .bAlternateSetting = */ 0,
|
||||
/* .bNumEndpoints = */ NUM_ENDPOINTS,
|
||||
/* .bInterfaceClass = */ 0xFF,
|
||||
/* .bInterfaceSubclass = */ 0xFF,
|
||||
/* .bInterfaceProtocol = */ 0xFF,
|
||||
/* .iInterface = */ 0
|
||||
/* .bLength = */ sizeof(struct usb_interface_descriptor),
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_INTERFACE,
|
||||
/* .bInterfaceNumber = */ 0,
|
||||
/* .bAlternateSetting = */ 0,
|
||||
/* .bNumEndpoints = */ NUM_ENDPOINTS,
|
||||
/* .bInterfaceClass = */ 0xFF,
|
||||
/* .bInterfaceSubclass = */ 0xFF,
|
||||
/* .bInterfaceProtocol = */ 0xFF,
|
||||
/* .iInterface = */ 0
|
||||
};
|
||||
|
||||
__code struct usb_endpoint_descriptor Bulk_EP2_IN_Endpoint_Descriptor = {
|
||||
/* .bLength = */ sizeof(struct usb_endpoint_descriptor),
|
||||
/* .bDescriptorType = */ 0x05,
|
||||
/* .bEndpointAddress = */ 2 | USB_DIR_IN,
|
||||
/* .bmAttributes = */ 0x02,
|
||||
/* .wMaxPacketSize = */ 64,
|
||||
/* .bInterval = */ 0
|
||||
/* .bLength = */ sizeof(struct usb_endpoint_descriptor),
|
||||
/* .bDescriptorType = */ 0x05,
|
||||
/* .bEndpointAddress = */ 2 | USB_DIR_IN,
|
||||
/* .bmAttributes = */ 0x02,
|
||||
/* .wMaxPacketSize = */ 64,
|
||||
/* .bInterval = */ 0
|
||||
};
|
||||
|
||||
__code struct usb_endpoint_descriptor Bulk_EP2_OUT_Endpoint_Descriptor = {
|
||||
/* .bLength = */ sizeof(struct usb_endpoint_descriptor),
|
||||
/* .bDescriptorType = */ 0x05,
|
||||
/* .bEndpointAddress = */ 2 | USB_DIR_OUT,
|
||||
/* .bmAttributes = */ 0x02,
|
||||
/* .wMaxPacketSize = */ 64,
|
||||
/* .bInterval = */ 0
|
||||
/* .bLength = */ sizeof(struct usb_endpoint_descriptor),
|
||||
/* .bDescriptorType = */ 0x05,
|
||||
/* .bEndpointAddress = */ 2 | USB_DIR_OUT,
|
||||
/* .bmAttributes = */ 0x02,
|
||||
/* .wMaxPacketSize = */ 64,
|
||||
/* .bInterval = */ 0
|
||||
};
|
||||
|
||||
__code struct usb_language_descriptor language_descriptor = {
|
||||
/* .bLength = */ 4,
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_STRING,
|
||||
/* .wLANGID = */ {0x0409 /* US English */}
|
||||
/* .bLength = */ 4,
|
||||
/* .bDescriptorType = */ DESCRIPTOR_TYPE_STRING,
|
||||
/* .wLANGID = */ {0x0409 /* US English */}
|
||||
};
|
||||
|
||||
__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 =
|
||||
STR_DESCR(9,'O','p','e','n','U','L','I','N','K');
|
||||
__code struct usb_string_descriptor strProduct =
|
||||
STR_DESCR(9, 'O', 'p', 'e', 'n', 'U', 'L', 'I', 'N', 'K');
|
||||
|
||||
__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 =
|
||||
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 */
|
||||
__code struct usb_string_descriptor* __code en_string_descriptors[4] = {
|
||||
&strManufacturer,
|
||||
&strProduct,
|
||||
&strSerialNumber,
|
||||
&strConfigDescr
|
||||
__code struct usb_string_descriptor *__code en_string_descriptors[4] = {
|
||||
&strManufacturer,
|
||||
&strProduct,
|
||||
&strSerialNumber,
|
||||
&strConfigDescr
|
||||
};
|
||||
|
||||
void sudav_isr(void) __interrupt SUDAV_ISR
|
||||
{
|
||||
CLEAR_IRQ();
|
||||
CLEAR_IRQ();
|
||||
|
||||
usb_handle_setup_data();
|
||||
usb_handle_setup_data();
|
||||
|
||||
USBIRQ = SUDAVIR;
|
||||
EP0CS |= HSNAK;
|
||||
USBIRQ = SUDAVIR;
|
||||
EP0CS |= HSNAK;
|
||||
}
|
||||
|
||||
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 ibn_isr(void) __interrupt IBN_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 ibn_isr(void) __interrupt IBN_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 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
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* EP2 IN: called after the transfer from uC->Host has finished: we sent data
|
||||
*/
|
||||
void ep2in_isr(void) __interrupt EP2IN_ISR {
|
||||
EP2_in = 1;
|
||||
void ep2in_isr(void) __interrupt EP2IN_ISR
|
||||
{
|
||||
EP2_in = 1;
|
||||
|
||||
CLEAR_IRQ();
|
||||
IN07IRQ = IN2IR; // Clear OUT2 IRQ
|
||||
CLEAR_IRQ();
|
||||
IN07IRQ = IN2IR;/* Clear OUT2 IRQ */
|
||||
}
|
||||
|
||||
/**
|
||||
* EP2 OUT: called after the transfer from Host->uC has finished: we got data
|
||||
*/
|
||||
void ep2out_isr(void) __interrupt EP2OUT_ISR {
|
||||
EP2_out = 1;
|
||||
void ep2out_isr(void) __interrupt EP2OUT_ISR
|
||||
{
|
||||
EP2_out = 1;
|
||||
|
||||
CLEAR_IRQ();
|
||||
OUT07IRQ = OUT2IR; // Clear OUT2 IRQ
|
||||
CLEAR_IRQ();
|
||||
OUT07IRQ = OUT2IR; /* Clear OUT2 IRQ */
|
||||
}
|
||||
|
||||
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 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 { }
|
||||
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 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
|
||||
|
@ -205,60 +245,60 @@ void ep7out_isr(void) __interrupt EP7OUT_ISR { }
|
|||
* specified in \a ep
|
||||
* @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 */
|
||||
uint8_t ep_num = ep & 0x7F;
|
||||
/* Mask direction bit */
|
||||
uint8_t ep_num = ep & 0x7F;
|
||||
|
||||
switch (ep_num) {
|
||||
case 0:
|
||||
return &EP0CS;
|
||||
break;
|
||||
case 1:
|
||||
return ep & 0x80 ? &IN1CS : &OUT1CS;
|
||||
break;
|
||||
case 2:
|
||||
return ep & 0x80 ? &IN2CS : &OUT2CS;
|
||||
break;
|
||||
case 3:
|
||||
return ep & 0x80 ? &IN3CS : &OUT3CS;
|
||||
break;
|
||||
case 4:
|
||||
return ep & 0x80 ? &IN4CS : &OUT4CS;
|
||||
break;
|
||||
case 5:
|
||||
return ep & 0x80 ? &IN5CS : &OUT5CS;
|
||||
break;
|
||||
case 6:
|
||||
return ep & 0x80 ? &IN6CS : &OUT6CS;
|
||||
break;
|
||||
case 7:
|
||||
return ep & 0x80 ? &IN7CS : &OUT7CS;
|
||||
break;
|
||||
}
|
||||
switch (ep_num) {
|
||||
case 0:
|
||||
return &EP0CS;
|
||||
break;
|
||||
case 1:
|
||||
return ep & 0x80 ? &IN1CS : &OUT1CS;
|
||||
break;
|
||||
case 2:
|
||||
return ep & 0x80 ? &IN2CS : &OUT2CS;
|
||||
break;
|
||||
case 3:
|
||||
return ep & 0x80 ? &IN3CS : &OUT3CS;
|
||||
break;
|
||||
case 4:
|
||||
return ep & 0x80 ? &IN4CS : &OUT4CS;
|
||||
break;
|
||||
case 5:
|
||||
return ep & 0x80 ? &IN5CS : &OUT5CS;
|
||||
break;
|
||||
case 6:
|
||||
return ep & 0x80 ? &IN6CS : &OUT6CS;
|
||||
break;
|
||||
case 7:
|
||||
return ep & 0x80 ? &IN7CS : &OUT7CS;
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void usb_reset_data_toggle(uint8_t ep)
|
||||
{
|
||||
/* TOGCTL register:
|
||||
+----+-----+-----+------+-----+-------+-------+-------+
|
||||
| Q | S | R | IO | 0 | EP2 | EP1 | EP0 |
|
||||
+----+-----+-----+------+-----+-------+-------+-------+
|
||||
/* TOGCTL register:
|
||||
+----+-----+-----+------+-----+-------+-------+-------+
|
||||
| Q | S | R | IO | 0 | EP2 | EP1 | EP0 |
|
||||
+----+-----+-----+------+-----+-------+-------+-------+
|
||||
|
||||
To reset data toggle bits, we have to write the endpoint direction (IN/OUT)
|
||||
to the IO bit and the endpoint number to the EP2..EP0 bits. Then, in a
|
||||
separate write cycle, the R bit needs to be set.
|
||||
*/
|
||||
uint8_t togctl_value = (ep & 0x80 >> 3) | (ep & 0x7);
|
||||
To reset data toggle bits, we have to write the endpoint direction (IN/OUT)
|
||||
to the IO bit and the endpoint number to the EP2..EP0 bits. Then, in a
|
||||
separate write cycle, the R bit needs to be set.
|
||||
*/
|
||||
uint8_t togctl_value = (ep & 0x80 >> 3) | (ep & 0x7);
|
||||
|
||||
/* First step: Write EP number and direction bit */
|
||||
TOGCTL = togctl_value;
|
||||
/* First step: Write EP number and direction bit */
|
||||
TOGCTL = togctl_value;
|
||||
|
||||
/* Second step: Set R bit */
|
||||
togctl_value |= TOG_R;
|
||||
TOGCTL = togctl_value;
|
||||
/* Second step: Set R bit */
|
||||
togctl_value |= TOG_R;
|
||||
TOGCTL = togctl_value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,49 +309,47 @@ void usb_reset_data_toggle(uint8_t ep)
|
|||
*/
|
||||
bool usb_handle_get_status(void)
|
||||
{
|
||||
uint8_t *ep_cs;
|
||||
uint8_t *ep_cs;
|
||||
|
||||
switch (setup_data.bmRequestType) {
|
||||
case GS_DEVICE:
|
||||
/* Two byte response: Byte 0, Bit 0 = self-powered, Bit 1 = remote wakeup.
|
||||
* Byte 1: reserved, reset to zero */
|
||||
IN0BUF[0] = 0;
|
||||
IN0BUF[1] = 0;
|
||||
switch (setup_data.bmRequestType) {
|
||||
case GS_DEVICE:
|
||||
/* Two byte response: Byte 0, Bit 0 = self-powered, Bit 1 = remote wakeup.
|
||||
* Byte 1: reserved, reset to zero */
|
||||
IN0BUF[0] = 0;
|
||||
IN0BUF[1] = 0;
|
||||
|
||||
/* Send response */
|
||||
IN0BC = 2;
|
||||
break;
|
||||
case GS_INTERFACE:
|
||||
/* Always return two zero bytes according to USB 1.1 spec, p. 191 */
|
||||
IN0BUF[0] = 0;
|
||||
IN0BUF[1] = 0;
|
||||
/* Send response */
|
||||
IN0BC = 2;
|
||||
break;
|
||||
case GS_INTERFACE:
|
||||
/* Always return two zero bytes according to USB 1.1 spec, p. 191 */
|
||||
IN0BUF[0] = 0;
|
||||
IN0BUF[1] = 0;
|
||||
|
||||
/* Send response */
|
||||
IN0BC = 2;
|
||||
break;
|
||||
case GS_ENDPOINT:
|
||||
/* Get stall bit for endpoint specified in low byte of wIndex */
|
||||
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex & 0xff);
|
||||
/* Send response */
|
||||
IN0BC = 2;
|
||||
break;
|
||||
case GS_ENDPOINT:
|
||||
/* Get stall bit for endpoint specified in low byte of wIndex */
|
||||
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex & 0xff);
|
||||
|
||||
if (*ep_cs & EPSTALL) {
|
||||
IN0BUF[0] = 0x01;
|
||||
}
|
||||
else {
|
||||
IN0BUF[0] = 0x00;
|
||||
}
|
||||
if (*ep_cs & EPSTALL)
|
||||
IN0BUF[0] = 0x01;
|
||||
else
|
||||
IN0BUF[0] = 0x00;
|
||||
|
||||
/* Second byte sent has to be always zero */
|
||||
IN0BUF[1] = 0;
|
||||
/* Second byte sent has to be always zero */
|
||||
IN0BUF[1] = 0;
|
||||
|
||||
/* Send response */
|
||||
IN0BC = 2;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
/* Send response */
|
||||
IN0BC = 2;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -322,32 +360,30 @@ bool usb_handle_get_status(void)
|
|||
*/
|
||||
bool usb_handle_clear_feature(void)
|
||||
{
|
||||
__xdata uint8_t *ep_cs;
|
||||
__xdata uint8_t *ep_cs;
|
||||
|
||||
switch (setup_data.bmRequestType) {
|
||||
case CF_DEVICE:
|
||||
/* Clear remote wakeup not supported: stall EP0 */
|
||||
STALL_EP0();
|
||||
break;
|
||||
case CF_ENDPOINT:
|
||||
if (setup_data.wValue == 0) {
|
||||
/* Unstall the endpoint specified in wIndex */
|
||||
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex);
|
||||
if (!ep_cs) {
|
||||
return false;
|
||||
}
|
||||
*ep_cs &= ~EPSTALL;
|
||||
}
|
||||
else {
|
||||
/* Unsupported feature, stall EP0 */
|
||||
STALL_EP0();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Vendor commands... */
|
||||
}
|
||||
switch (setup_data.bmRequestType) {
|
||||
case CF_DEVICE:
|
||||
/* Clear remote wakeup not supported: stall EP0 */
|
||||
STALL_EP0();
|
||||
break;
|
||||
case CF_ENDPOINT:
|
||||
if (setup_data.wValue == 0) {
|
||||
/* Unstall the endpoint specified in wIndex */
|
||||
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex);
|
||||
if (!ep_cs)
|
||||
return false;
|
||||
*ep_cs &= ~EPSTALL;
|
||||
} else {
|
||||
/* Unsupported feature, stall EP0 */
|
||||
STALL_EP0();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Vendor commands... */
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -358,34 +394,31 @@ bool usb_handle_clear_feature(void)
|
|||
*/
|
||||
bool usb_handle_set_feature(void)
|
||||
{
|
||||
__xdata uint8_t *ep_cs;
|
||||
__xdata uint8_t *ep_cs;
|
||||
|
||||
switch (setup_data.bmRequestType) {
|
||||
case SF_DEVICE:
|
||||
if (setup_data.wValue == 2) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case SF_ENDPOINT:
|
||||
if (setup_data.wValue == 0) {
|
||||
/* Stall the endpoint specified in wIndex */
|
||||
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex);
|
||||
if (!ep_cs) {
|
||||
return false;
|
||||
}
|
||||
*ep_cs |= EPSTALL;
|
||||
}
|
||||
else {
|
||||
/* Unsupported endpoint feature */
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Vendor commands... */
|
||||
break;
|
||||
}
|
||||
switch (setup_data.bmRequestType) {
|
||||
case SF_DEVICE:
|
||||
if (setup_data.wValue == 2)
|
||||
return true;
|
||||
break;
|
||||
case SF_ENDPOINT:
|
||||
if (setup_data.wValue == 0) {
|
||||
/* Stall the endpoint specified in wIndex */
|
||||
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex);
|
||||
if (!ep_cs)
|
||||
return false;
|
||||
*ep_cs |= EPSTALL;
|
||||
} else {
|
||||
/* Unsupported endpoint feature */
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Vendor commands... */
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -396,43 +429,40 @@ bool usb_handle_set_feature(void)
|
|||
*/
|
||||
bool usb_handle_get_descriptor(void)
|
||||
{
|
||||
__xdata uint8_t descriptor_type;
|
||||
__xdata uint8_t descriptor_index;
|
||||
__xdata uint8_t descriptor_type;
|
||||
__xdata uint8_t descriptor_index;
|
||||
|
||||
descriptor_type = (setup_data.wValue & 0xff00) >> 8;
|
||||
descriptor_index = setup_data.wValue & 0x00ff;
|
||||
descriptor_type = (setup_data.wValue & 0xff00) >> 8;
|
||||
descriptor_index = setup_data.wValue & 0x00ff;
|
||||
|
||||
switch (descriptor_type) {
|
||||
case DESCRIPTOR_TYPE_DEVICE:
|
||||
SUDPTRH = HI8(&device_descriptor);
|
||||
SUDPTRL = LO8(&device_descriptor);
|
||||
break;
|
||||
case DESCRIPTOR_TYPE_CONFIGURATION:
|
||||
SUDPTRH = HI8(&config_descriptor);
|
||||
SUDPTRL = LO8(&config_descriptor);
|
||||
break;
|
||||
case DESCRIPTOR_TYPE_STRING:
|
||||
if (setup_data.wIndex == 0) {
|
||||
/* Supply language descriptor */
|
||||
SUDPTRH = HI8(&language_descriptor);
|
||||
SUDPTRL = LO8(&language_descriptor);
|
||||
}
|
||||
else if (setup_data.wIndex == 0x0409 /* US English */) {
|
||||
/* Supply string descriptor */
|
||||
SUDPTRH = HI8(en_string_descriptors[descriptor_index - 1]);
|
||||
SUDPTRL = LO8(en_string_descriptors[descriptor_index - 1]);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Unsupported descriptor type */
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
switch (descriptor_type) {
|
||||
case DESCRIPTOR_TYPE_DEVICE:
|
||||
SUDPTRH = HI8(&device_descriptor);
|
||||
SUDPTRL = LO8(&device_descriptor);
|
||||
break;
|
||||
case DESCRIPTOR_TYPE_CONFIGURATION:
|
||||
SUDPTRH = HI8(&config_descriptor);
|
||||
SUDPTRL = LO8(&config_descriptor);
|
||||
break;
|
||||
case DESCRIPTOR_TYPE_STRING:
|
||||
if (setup_data.wIndex == 0) {
|
||||
/* Supply language descriptor */
|
||||
SUDPTRH = HI8(&language_descriptor);
|
||||
SUDPTRL = LO8(&language_descriptor);
|
||||
} else if (setup_data.wIndex == 0x0409 /* US English */) {
|
||||
/* Supply string descriptor */
|
||||
SUDPTRH = HI8(en_string_descriptors[descriptor_index - 1]);
|
||||
SUDPTRL = LO8(en_string_descriptors[descriptor_index - 1]);
|
||||
} else
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
/* Unsupported descriptor type */
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -440,16 +470,16 @@ bool usb_handle_get_descriptor(void)
|
|||
*/
|
||||
void usb_handle_set_interface(void)
|
||||
{
|
||||
/* Reset Data Toggle */
|
||||
usb_reset_data_toggle(USB_DIR_IN | 2);
|
||||
usb_reset_data_toggle(USB_DIR_OUT | 2);
|
||||
/* Reset Data Toggle */
|
||||
usb_reset_data_toggle(USB_DIR_IN | 2);
|
||||
usb_reset_data_toggle(USB_DIR_OUT | 2);
|
||||
|
||||
/* Unstall & clear busy flag of all valid IN endpoints */
|
||||
IN2CS = 0 | EPBSY;
|
||||
|
||||
/* Unstall all valid OUT endpoints, reset bytecounts */
|
||||
OUT2CS = 0;
|
||||
OUT2BC = 0;
|
||||
/* Unstall & clear busy flag of all valid IN endpoints */
|
||||
IN2CS = 0 | EPBSY;
|
||||
|
||||
/* Unstall all valid OUT endpoints, reset bytecounts */
|
||||
OUT2CS = 0;
|
||||
OUT2BC = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -457,95 +487,92 @@ void usb_handle_set_interface(void)
|
|||
*/
|
||||
void usb_handle_setup_data(void)
|
||||
{
|
||||
switch (setup_data.bRequest) {
|
||||
case GET_STATUS:
|
||||
if (!usb_handle_get_status()) {
|
||||
STALL_EP0();
|
||||
}
|
||||
break;
|
||||
case CLEAR_FEATURE:
|
||||
if (!usb_handle_clear_feature()) {
|
||||
STALL_EP0();
|
||||
}
|
||||
break;
|
||||
case 2: case 4:
|
||||
/* Reserved values */
|
||||
STALL_EP0();
|
||||
break;
|
||||
case SET_FEATURE:
|
||||
if (!usb_handle_set_feature()) {
|
||||
STALL_EP0();
|
||||
}
|
||||
break;
|
||||
case SET_ADDRESS:
|
||||
/* Handled by USB core */
|
||||
break;
|
||||
case SET_DESCRIPTOR:
|
||||
/* Set Descriptor not supported. */
|
||||
STALL_EP0();
|
||||
break;
|
||||
case GET_DESCRIPTOR:
|
||||
if (!usb_handle_get_descriptor()) {
|
||||
STALL_EP0();
|
||||
}
|
||||
break;
|
||||
case GET_CONFIGURATION:
|
||||
/* OpenULINK has only one configuration, return its index */
|
||||
IN0BUF[0] = config_descriptor.bConfigurationValue;
|
||||
IN0BC = 1;
|
||||
break;
|
||||
case SET_CONFIGURATION:
|
||||
/* OpenULINK has only one configuration -> nothing to do */
|
||||
break;
|
||||
case GET_INTERFACE:
|
||||
/* OpenULINK only has one interface, return its number */
|
||||
IN0BUF[0] = interface_descriptor00.bInterfaceNumber;
|
||||
IN0BC = 1;
|
||||
break;
|
||||
case SET_INTERFACE:
|
||||
usb_handle_set_interface();
|
||||
break;
|
||||
case SYNCH_FRAME:
|
||||
/* Isochronous endpoints not used -> nothing to do */
|
||||
break;
|
||||
default:
|
||||
/* Any other requests: do nothing */
|
||||
break;
|
||||
}
|
||||
switch (setup_data.bRequest) {
|
||||
case GET_STATUS:
|
||||
if (!usb_handle_get_status())
|
||||
STALL_EP0();
|
||||
break;
|
||||
case CLEAR_FEATURE:
|
||||
if (!usb_handle_clear_feature())
|
||||
STALL_EP0();
|
||||
break;
|
||||
case 2: case 4:
|
||||
/* Reserved values */
|
||||
STALL_EP0();
|
||||
break;
|
||||
case SET_FEATURE:
|
||||
if (!usb_handle_set_feature())
|
||||
STALL_EP0();
|
||||
break;
|
||||
case SET_ADDRESS:
|
||||
/* Handled by USB core */
|
||||
break;
|
||||
case SET_DESCRIPTOR:
|
||||
/* Set Descriptor not supported. */
|
||||
STALL_EP0();
|
||||
break;
|
||||
case GET_DESCRIPTOR:
|
||||
if (!usb_handle_get_descriptor())
|
||||
STALL_EP0();
|
||||
break;
|
||||
case GET_CONFIGURATION:
|
||||
/* OpenULINK has only one configuration, return its index */
|
||||
IN0BUF[0] = config_descriptor.bConfigurationValue;
|
||||
IN0BC = 1;
|
||||
break;
|
||||
case SET_CONFIGURATION:
|
||||
/* OpenULINK has only one configuration -> nothing to do */
|
||||
break;
|
||||
case GET_INTERFACE:
|
||||
/* OpenULINK only has one interface, return its number */
|
||||
IN0BUF[0] = interface_descriptor00.bInterfaceNumber;
|
||||
IN0BC = 1;
|
||||
break;
|
||||
case SET_INTERFACE:
|
||||
usb_handle_set_interface();
|
||||
break;
|
||||
case SYNCH_FRAME:
|
||||
/* Isochronous endpoints not used -> nothing to do */
|
||||
break;
|
||||
default:
|
||||
/* Any other requests: do nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* USB initialization. Configures USB interrupts, endpoints and performs
|
||||
* ReNumeration.
|
||||
*/
|
||||
void usb_init(void) {
|
||||
/* Mark endpoint 2 IN & OUT as valid */
|
||||
IN07VAL = IN2VAL;
|
||||
OUT07VAL = OUT2VAL;
|
||||
void usb_init(void)
|
||||
{
|
||||
/* Mark endpoint 2 IN & OUT as valid */
|
||||
IN07VAL = IN2VAL;
|
||||
OUT07VAL = OUT2VAL;
|
||||
|
||||
/* Make sure no isochronous endpoints are marked valid */
|
||||
INISOVAL = 0;
|
||||
OUTISOVAL = 0;
|
||||
/* Make sure no isochronous endpoints are marked valid */
|
||||
INISOVAL = 0;
|
||||
OUTISOVAL = 0;
|
||||
|
||||
/* Disable isochronous endpoints. This makes the isochronous data buffers
|
||||
* available as 8051 XDATA memory at address 0x2000 - 0x27FF */
|
||||
ISOCTL = ISODISAB;
|
||||
/* Disable isochronous endpoints. This makes the isochronous data buffers
|
||||
* available as 8051 XDATA memory at address 0x2000 - 0x27FF */
|
||||
ISOCTL = ISODISAB;
|
||||
|
||||
/* Enable USB Autovectoring */
|
||||
USBBAV |= AVEN;
|
||||
|
||||
/* Enable SUDAV interrupt */
|
||||
USBIEN |= SUDAVIE;
|
||||
/* Enable USB Autovectoring */
|
||||
USBBAV |= AVEN;
|
||||
|
||||
/* Enable EP2 OUT & IN interrupts */
|
||||
OUT07IEN = OUT2IEN;
|
||||
IN07IEN = IN2IEN;
|
||||
/* Enable SUDAV interrupt */
|
||||
USBIEN |= SUDAVIE;
|
||||
|
||||
/* Enable USB interrupt (EIE register) */
|
||||
EUSB = 1;
|
||||
/* Enable EP2 OUT & IN interrupts */
|
||||
OUT07IEN = OUT2IEN;
|
||||
IN07IEN = IN2IEN;
|
||||
|
||||
/* Perform ReNumeration */
|
||||
USBCS = DISCON | RENUM;
|
||||
delay_ms(200);
|
||||
USBCS = DISCOE | RENUM;
|
||||
/* Enable USB interrupt (EIE register) */
|
||||
EUSB = 1;
|
||||
|
||||
/* Perform ReNumeration */
|
||||
USBCS = DISCON | RENUM;
|
||||
delay_ms(200);
|
||||
USBCS = DISCOE | RENUM;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -27,7 +28,7 @@
|
|||
#include <linux/parport.h>
|
||||
#include <linux/ppdev.h>
|
||||
#include <sys/ioctl.h>
|
||||
#else /* not PARPORT_USE_PPDEV */
|
||||
#else /* not PARPORT_USE_PPDEV */
|
||||
#ifndef _WIN32
|
||||
#include <sys/io.h>
|
||||
#endif
|
||||
|
@ -53,11 +54,11 @@ static uint16_t amt_jtagaccel_port;
|
|||
|
||||
/* 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_baudrate = 0x20;
|
||||
|
||||
static int rtck_enabled = 0;
|
||||
static int rtck_enabled;
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
static int device_handle;
|
||||
|
@ -70,7 +71,7 @@ static const int addr_mode = IEEE1284_MODE_EPP | IEEE1284_ADDR;
|
|||
do { \
|
||||
int __retval; \
|
||||
\
|
||||
__retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
|
||||
__retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
|
||||
assert(__retval >= 0); \
|
||||
__retval = write(device_handle, &val, 1); \
|
||||
assert(__retval >= 0); \
|
||||
|
@ -79,7 +80,7 @@ static const int addr_mode = IEEE1284_MODE_EPP | IEEE1284_ADDR;
|
|||
do { \
|
||||
int __retval; \
|
||||
\
|
||||
__retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
|
||||
__retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
|
||||
assert(__retval >= 0); \
|
||||
__retval = read(device_handle, &val, 1); \
|
||||
assert(__retval >= 0); \
|
||||
|
@ -91,7 +92,7 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
|
|||
do { \
|
||||
int __retval; \
|
||||
\
|
||||
__retval = ioctl(device_handle, PPSETMODE, &data_mode); \
|
||||
__retval = ioctl(device_handle, PPSETMODE, &data_mode); \
|
||||
assert(__retval >= 0); \
|
||||
__retval = write(device_handle, &val, 1); \
|
||||
assert(__retval >= 0); \
|
||||
|
@ -100,7 +101,7 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
|
|||
do { \
|
||||
int __retval; \
|
||||
\
|
||||
__retval = ioctl(device_handle, PPSETMODE, &data_mode); \
|
||||
__retval = ioctl(device_handle, PPSETMODE, &data_mode); \
|
||||
assert(__retval >= 0); \
|
||||
__retval = read(device_handle, &val, 1); \
|
||||
assert(__retval >= 0); \
|
||||
|
@ -108,12 +109,12 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
|
|||
|
||||
#else
|
||||
|
||||
#define AMT_AW(val) do { outb(val, amt_jtagaccel_port + 3); } while (0)
|
||||
#define AMT_AR(val) do { val = inb(amt_jtagaccel_port + 3); } 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_AW(val) do { outb(val, amt_jtagaccel_port + 3); } while (0)
|
||||
#define AMT_AR(val) do { val = inb(amt_jtagaccel_port + 3); } 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)
|
||||
|
||||
#endif // PARPORT_USE_PPDEV
|
||||
#endif /* PARPORT_USE_PPDEV */
|
||||
|
||||
/* tap_move[i][j]: tap movement command to go from state i to state j
|
||||
* 0: Test-Logic-Reset
|
||||
|
@ -123,18 +124,16 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
|
|||
* 4: Shift-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 */
|
||||
{{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}, {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}, {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}, {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}, {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}, {0x0d, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x00, 0x00}, {0x01, 0x00} }, /* IRSHIFT */
|
||||
{ {0x1f, 0x00}, {0x0c, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x08, 0x00}, {0x00, 0x00} }, /* IRPAUSE */
|
||||
};
|
||||
|
||||
|
||||
static void amt_jtagaccel_reset(int trst, int srst)
|
||||
{
|
||||
if (trst == 1)
|
||||
|
@ -163,8 +162,7 @@ static void amt_jtagaccel_end_state(tap_state_t state)
|
|||
{
|
||||
if (tap_is_state_stable(state))
|
||||
tap_set_end_state(state);
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("BUG: %i is not a valid end state", state);
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -179,9 +177,11 @@ static void amt_wait_scan_busy(void)
|
|||
while (((ar_status) & 0x80) && (timeout-- > 0))
|
||||
AMT_AR(ar_status);
|
||||
|
||||
if (ar_status & 0x80)
|
||||
{
|
||||
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);
|
||||
if (ar_status & 0x80) {
|
||||
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);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
@ -191,22 +191,21 @@ static void amt_jtagaccel_state_move(void)
|
|||
uint8_t aw_scan_tms_5;
|
||||
uint8_t tms_scan[2];
|
||||
|
||||
tap_state_t cur_state = tap_get_state();
|
||||
tap_state_t end_state = tap_get_end_state();
|
||||
tap_state_t cur_state = tap_get_state();
|
||||
tap_state_t end_state = tap_get_end_state();
|
||||
|
||||
tms_scan[0] = amt_jtagaccel_tap_move[tap_move_ndx(cur_state)][tap_move_ndx(end_state)][0];
|
||||
tms_scan[1] = amt_jtagaccel_tap_move[tap_move_ndx(cur_state)][tap_move_ndx(end_state)][1];
|
||||
|
||||
aw_scan_tms_5 = 0x40 | (tms_scan[0] & 0x1f);
|
||||
AMT_AW(aw_scan_tms_5);
|
||||
int jtag_speed=0;
|
||||
int jtag_speed = 0;
|
||||
int retval = jtag_get_speed(&jtag_speed);
|
||||
assert(retval == ERROR_OK);
|
||||
if (jtag_speed > 3 || rtck_enabled)
|
||||
amt_wait_scan_busy();
|
||||
|
||||
if (tms_scan[0] & 0x80)
|
||||
{
|
||||
if (tms_scan[0] & 0x80) {
|
||||
aw_scan_tms_5 = 0x40 | (tms_scan[1] & 0x1f);
|
||||
AMT_AW(aw_scan_tms_5);
|
||||
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();
|
||||
|
||||
/* 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_state_move();
|
||||
}
|
||||
|
||||
while (num_cycles - i >= 5)
|
||||
{
|
||||
while (num_cycles - i >= 5) {
|
||||
aw_scan_tms_5 = 0x40;
|
||||
AMT_AW(aw_scan_tms_5);
|
||||
i += 5;
|
||||
}
|
||||
|
||||
if (num_cycles - i > 0)
|
||||
{
|
||||
if (num_cycles - i > 0) {
|
||||
aw_scan_tms_1to4 = 0x80 | ((num_cycles - i - 1) & 0x3) << 4;
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
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)
|
||||
amt_wait_scan_busy();
|
||||
|
||||
if ((type == SCAN_IN) || (type == SCAN_IO))
|
||||
{
|
||||
if ((type == SCAN_IN) || (type == SCAN_IO)) {
|
||||
AMT_DR(dr_tdo);
|
||||
dr_tdo = dr_tdo >> (8 - ((scan_size - 1) % 8));
|
||||
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;
|
||||
}
|
||||
|
||||
while (bits_left - 1 >= 8)
|
||||
{
|
||||
while (bits_left - 1 >= 8) {
|
||||
dw_tdi_scan = buf_get_u32(buffer, bit_count, 8) & 0xff;
|
||||
AMT_DW(dw_tdi_scan);
|
||||
if (jtag_speed_var > 3 || rtck_enabled)
|
||||
amt_wait_scan_busy();
|
||||
|
||||
if ((type == SCAN_IN) || (type == SCAN_IO))
|
||||
{
|
||||
if ((type == SCAN_IN) || (type == SCAN_IO)) {
|
||||
AMT_DR(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;
|
||||
}
|
||||
|
||||
tms_scan[0] = 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];
|
||||
tms_scan[0] =
|
||||
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);
|
||||
AMT_AW(aw_tms_scan);
|
||||
if (jtag_speed_var > 3 || rtck_enabled)
|
||||
amt_wait_scan_busy();
|
||||
|
||||
if ((type == SCAN_IN) || (type == SCAN_IO))
|
||||
{
|
||||
if ((type == SCAN_IN) || (type == SCAN_IO)) {
|
||||
AMT_DR(dr_tdo);
|
||||
dr_tdo = dr_tdo >> 7;
|
||||
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);
|
||||
AMT_AW(aw_tms_scan);
|
||||
if (jtag_speed_var > 3 || rtck_enabled)
|
||||
|
@ -336,7 +328,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
|
|||
|
||||
static int amt_jtagaccel_execute_queue(void)
|
||||
{
|
||||
struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
|
||||
struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
|
||||
int scan_size;
|
||||
enum scan_type type;
|
||||
uint8_t *buffer;
|
||||
|
@ -347,23 +339,23 @@ static int amt_jtagaccel_execute_queue(void)
|
|||
*/
|
||||
retval = ERROR_OK;
|
||||
|
||||
while (cmd)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
while (cmd) {
|
||||
switch (cmd->type) {
|
||||
case JTAG_RESET:
|
||||
#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
|
||||
if (cmd->cmd.reset->trst == 1)
|
||||
{
|
||||
tap_set_state(TAP_RESET);
|
||||
}
|
||||
amt_jtagaccel_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
break;
|
||||
case JTAG_RUNTEST:
|
||||
#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
|
||||
amt_jtagaccel_end_state(cmd->cmd.runtest->end_state);
|
||||
amt_jtagaccel_runtest(cmd->cmd.runtest->num_cycles);
|
||||
|
@ -412,16 +404,22 @@ int amt_jtagaccel_get_giveio_access(void)
|
|||
|
||||
version.dwOSVersionInfoSize = sizeof version;
|
||||
if (!GetVersionEx(&version)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
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) {
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
CloseHandle(h);
|
||||
|
@ -442,8 +440,7 @@ static int amt_jtagaccel_init(void)
|
|||
uint8_t ar_status;
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
if (device_handle > 0)
|
||||
{
|
||||
if (device_handle > 0) {
|
||||
LOG_ERROR("device is already opened");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -451,23 +448,21 @@ static int amt_jtagaccel_init(void)
|
|||
snprintf(buffer, 256, "/dev/parport%d", amt_jtagaccel_port);
|
||||
device_handle = open(buffer, O_RDWR);
|
||||
|
||||
if (device_handle < 0)
|
||||
{
|
||||
LOG_ERROR("cannot open device. check it exists and that user read and write rights are set");
|
||||
if (device_handle < 0) {
|
||||
LOG_ERROR(
|
||||
"cannot open device. check it exists and that user read and write rights are set");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
i = ioctl(device_handle, PPCLAIM);
|
||||
if (i < 0)
|
||||
{
|
||||
if (i < 0) {
|
||||
LOG_ERROR("cannot claim device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
i = IEEE1284_MODE_EPP;
|
||||
i = ioctl(device_handle, PPSETMODE, & i);
|
||||
if (i < 0)
|
||||
{
|
||||
i = ioctl(device_handle, PPSETMODE, &i);
|
||||
if (i < 0) {
|
||||
LOG_ERROR(" cannot set compatible mode to device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -479,23 +474,22 @@ static int amt_jtagaccel_init(void)
|
|||
i = ioctl(device_handle, PPWCONTROL, &control_port);
|
||||
|
||||
#else
|
||||
if (amt_jtagaccel_port == 0)
|
||||
{
|
||||
if (amt_jtagaccel_port == 0) {
|
||||
amt_jtagaccel_port = 0x378;
|
||||
LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
|
||||
}
|
||||
|
||||
#if PARPORT_USE_GIVEIO == 1
|
||||
if (amt_jtagaccel_get_giveio_access() != 0) {
|
||||
#else /* PARPORT_USE_GIVEIO */
|
||||
#else /* PARPORT_USE_GIVEIO */
|
||||
if (ioperm(amt_jtagaccel_port, 5, 1) != 0) {
|
||||
#endif /* PARPORT_USE_GIVEIO */
|
||||
#endif /* PARPORT_USE_GIVEIO */
|
||||
LOG_ERROR("missing privileges for direct i/o");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
/* prepare epp port */
|
||||
/* clear timeout */
|
||||
/* prepare epp port
|
||||
* clear timeout */
|
||||
status_port = inb(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);
|
||||
#endif
|
||||
|
||||
if (rtck_enabled)
|
||||
{
|
||||
if (rtck_enabled) {
|
||||
/* set RTCK enable bit */
|
||||
aw_control_fsm |= 0x02;
|
||||
}
|
||||
|
@ -542,17 +535,13 @@ static int amt_jtagaccel_quit(void)
|
|||
|
||||
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 */
|
||||
if (amt_jtagaccel_port == 0)
|
||||
{
|
||||
if (amt_jtagaccel_port == 0) {
|
||||
uint16_t port;
|
||||
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], port);
|
||||
amt_jtagaccel_port = port;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_ERROR("The parport port was already configured!");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -565,21 +554,16 @@ COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command)
|
|||
|
||||
COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command)
|
||||
{
|
||||
if (CMD_ARGC == 0)
|
||||
{
|
||||
command_print(CMD_CTX, "amt_jtagaccel RTCK feature %s", (rtck_enabled) ? "enabled" : "disabled");
|
||||
if (CMD_ARGC == 0) {
|
||||
command_print(CMD_CTX,
|
||||
"amt_jtagaccel RTCK feature %s",
|
||||
(rtck_enabled) ? "enabled" : "disabled");
|
||||
return ERROR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (strcmp(CMD_ARGV[0], "enabled") == 0)
|
||||
{
|
||||
rtck_enabled = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rtck_enabled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
|
|
|
@ -59,9 +59,13 @@ static void armjtagew_end_state(tap_state_t state);
|
|||
static void armjtagew_state_move(void);
|
||||
static void armjtagew_path_move(int num_states, tap_state_t *path);
|
||||
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_simple_command(uint8_t command);
|
||||
/* static void armjtagew_simple_command(uint8_t command); */
|
||||
static int armjtagew_get_status(void);
|
||||
|
||||
/* 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 */
|
||||
struct armjtagew {
|
||||
struct usb_dev_handle* usb_handle;
|
||||
struct usb_dev_handle *usb_handle;
|
||||
};
|
||||
|
||||
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);
|
||||
#endif
|
||||
|
||||
static struct armjtagew* armjtagew_handle;
|
||||
static struct armjtagew *armjtagew_handle;
|
||||
|
||||
/***************************************************************************/
|
||||
/* External interface implementation */
|
||||
/**************************************************************************
|
||||
* External interface implementation */
|
||||
|
||||
static int armjtagew_execute_queue(void)
|
||||
{
|
||||
|
@ -101,13 +105,12 @@ static int armjtagew_execute_queue(void)
|
|||
enum scan_type type;
|
||||
uint8_t *buffer;
|
||||
|
||||
while (cmd != NULL)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
while (cmd != NULL) {
|
||||
switch (cmd->type) {
|
||||
case JTAG_RUNTEST:
|
||||
DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \
|
||||
cmd->cmd.runtest->end_state);
|
||||
DEBUG_JTAG_IO("runtest %i cycles, end in %i",
|
||||
cmd->cmd.runtest->num_cycles, \
|
||||
cmd->cmd.runtest->end_state);
|
||||
|
||||
armjtagew_end_state(cmd->cmd.runtest->end_state);
|
||||
armjtagew_runtest(cmd->cmd.runtest->num_cycles);
|
||||
|
@ -122,10 +125,11 @@ static int armjtagew_execute_queue(void)
|
|||
|
||||
case JTAG_PATHMOVE:
|
||||
DEBUG_JTAG_IO("pathmove: %i states, end in %i", \
|
||||
cmd->cmd.pathmove->num_states, \
|
||||
cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
|
||||
cmd->cmd.pathmove->num_states, \
|
||||
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;
|
||||
|
||||
case JTAG_SCAN:
|
||||
|
@ -140,18 +144,20 @@ static int armjtagew_execute_queue(void)
|
|||
armjtagew_debug_buffer(buffer, (scan_size + 7) / 8);
|
||||
#endif
|
||||
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;
|
||||
|
||||
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();
|
||||
|
||||
if (cmd->cmd.reset->trst == 1)
|
||||
{
|
||||
tap_set_state(TAP_RESET);
|
||||
}
|
||||
armjtagew_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
break;
|
||||
|
||||
|
@ -183,8 +189,7 @@ static int armjtagew_speed(int speed)
|
|||
|
||||
result = armjtagew_usb_message(armjtagew_handle, 5, 4);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
if (result < 0) {
|
||||
LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -192,15 +197,11 @@ static int armjtagew_speed(int speed)
|
|||
usb_out_buffer[0] = CMD_GET_TCK_FREQUENCY;
|
||||
result = armjtagew_usb_message(armjtagew_handle, 1, 4);
|
||||
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);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real);
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -212,7 +213,7 @@ static int armjtagew_khz(int khz, int *jtag_speed)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static int armjtagew_speed_div(int speed, int* khz)
|
||||
static int armjtagew_speed_div(int speed, int *khz)
|
||||
{
|
||||
*khz = speed;
|
||||
|
||||
|
@ -225,17 +226,15 @@ static int armjtagew_init(void)
|
|||
|
||||
armjtagew_handle = armjtagew_usb_open();
|
||||
|
||||
if (armjtagew_handle == 0)
|
||||
{
|
||||
LOG_ERROR("Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
|
||||
if (armjtagew_handle == 0) {
|
||||
LOG_ERROR(
|
||||
"Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
check_cnt = 0;
|
||||
while (check_cnt < 3)
|
||||
{
|
||||
if (armjtagew_get_version_info() == ERROR_OK)
|
||||
{
|
||||
while (check_cnt < 3) {
|
||||
if (armjtagew_get_version_info() == ERROR_OK) {
|
||||
/* attempt to get status */
|
||||
armjtagew_get_status();
|
||||
break;
|
||||
|
@ -245,9 +244,7 @@ static int armjtagew_init(void)
|
|||
}
|
||||
|
||||
if (check_cnt == 3)
|
||||
{
|
||||
LOG_INFO("ARM-JTAG-EW initial read failed, don't worry");
|
||||
}
|
||||
|
||||
/* Initial JTAG speed (for reset and initialization): 32 kHz */
|
||||
armjtagew_speed(32);
|
||||
|
@ -266,17 +263,14 @@ static int armjtagew_quit(void)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/* Queue command implementations */
|
||||
/**************************************************************************
|
||||
* Queue command implementations */
|
||||
|
||||
static void armjtagew_end_state(tap_state_t state)
|
||||
{
|
||||
if (tap_is_state_stable(state))
|
||||
{
|
||||
tap_set_end_state(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("BUG: %i is not a valid end state", state);
|
||||
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());
|
||||
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;
|
||||
armjtagew_tap_append_step(tms, 0);
|
||||
}
|
||||
|
@ -303,24 +296,19 @@ static void armjtagew_path_move(int num_states, tap_state_t *path)
|
|||
{
|
||||
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.
|
||||
* Either handle that here, or update the documentation with examples
|
||||
* how to fix that in the configuration files.
|
||||
*/
|
||||
if (path[i] == tap_state_transition(tap_get_state(), false))
|
||||
{
|
||||
armjtagew_tap_append_step(0, 0);
|
||||
}
|
||||
else if (path[i] == tap_state_transition(tap_get_state(), true))
|
||||
{
|
||||
armjtagew_tap_append_step(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(path[i]));
|
||||
else {
|
||||
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
|
||||
tap_state_name(tap_get_state()), tap_state_name(path[i]));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -337,27 +325,26 @@ static void armjtagew_runtest(int num_cycles)
|
|||
tap_state_t saved_end_state = tap_get_end_state();
|
||||
|
||||
/* 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_state_move();
|
||||
}
|
||||
|
||||
/* execute num_cycles */
|
||||
for (i = 0; i < num_cycles; i++)
|
||||
{
|
||||
armjtagew_tap_append_step(0, 0);
|
||||
}
|
||||
|
||||
/* finish in end_state */
|
||||
armjtagew_end_state(saved_end_state);
|
||||
if (tap_get_state() != tap_get_end_state())
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
if (tap_get_state() != tap_get_end_state())
|
||||
{
|
||||
armjtagew_state_move();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (srst == 0)
|
||||
{
|
||||
if (srst == 0) {
|
||||
val |= srst_mask;
|
||||
outp_en &= ~srst_mask; /* tristate */
|
||||
change_mask |= srst_mask;
|
||||
}
|
||||
else if (srst == 1)
|
||||
{
|
||||
} else if (srst == 1) {
|
||||
val &= ~srst_mask;
|
||||
outp_en |= srst_mask;
|
||||
change_mask |= srst_mask;
|
||||
}
|
||||
|
||||
if (trst == 0)
|
||||
{
|
||||
if (trst == 0) {
|
||||
val |= trst_mask;
|
||||
outp_en &= ~trst_mask; /* tristate */
|
||||
change_mask |= trst_mask;
|
||||
}
|
||||
else if (trst == 1)
|
||||
{
|
||||
} else if (trst == 1) {
|
||||
val &= ~trst_mask;
|
||||
outp_en |= trst_mask;
|
||||
change_mask |= trst_mask;
|
||||
|
@ -428,9 +407,7 @@ static void armjtagew_reset(int trst, int srst)
|
|||
usb_out_buffer[3] = change_mask;
|
||||
result = armjtagew_usb_write(armjtagew_handle, 4);
|
||||
if (result != 4)
|
||||
{
|
||||
LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
|
||||
}
|
||||
}
|
||||
|
||||
static int armjtagew_get_status(void)
|
||||
|
@ -440,27 +417,22 @@ static int armjtagew_get_status(void)
|
|||
usb_out_buffer[0] = CMD_GET_TAPHW_STATE;
|
||||
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);
|
||||
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 + 2, 0, 16)),
|
||||
(int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
|
||||
(int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
|
||||
usb_in_buffer[9],
|
||||
usb_in_buffer[11] ? "OVERCURRENT" : "OK",
|
||||
usb_in_buffer[10] ? "enabled" : "disabled");
|
||||
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 + 2, 0, 16)),
|
||||
(int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
|
||||
(int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
|
||||
usb_in_buffer[9],
|
||||
usb_in_buffer[11] ? "OVERCURRENT" : "OK",
|
||||
usb_in_buffer[10] ? "enabled" : "disabled");
|
||||
|
||||
if (u_tg < 1500)
|
||||
{
|
||||
LOG_ERROR("Vref too low. Check Target Power");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -475,34 +447,35 @@ static int armjtagew_get_version_info(void)
|
|||
usb_out_buffer[0] = CMD_GET_VERSION;
|
||||
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);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
memcpy(sn, usb_in_buffer + 4, 15);
|
||||
sn[15] = '\0';
|
||||
memcpy(auxinfo, usb_in_buffer + 4+15, 256);
|
||||
auxinfo[256] = '\0';
|
||||
|
||||
LOG_INFO("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', \
|
||||
sn, auxinfo);
|
||||
LOG_INFO(
|
||||
"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', \
|
||||
sn,
|
||||
auxinfo);
|
||||
|
||||
if (1 != usb_in_buffer[1] || 6 != usb_in_buffer[0])
|
||||
{
|
||||
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]);
|
||||
}
|
||||
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]);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
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 */
|
||||
armjtagew_get_status();
|
||||
}
|
||||
|
@ -532,8 +505,8 @@ struct jtag_interface armjtagew_interface = {
|
|||
.quit = armjtagew_quit,
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/* ARM-JTAG-EW tap functions */
|
||||
/**************************************************************************
|
||||
* ARM-JTAG-EW tap functions */
|
||||
|
||||
/* 2048 is the max value we can use here */
|
||||
#define ARMJTAGEW_TAP_BUFFER_SIZE 2048
|
||||
|
@ -545,8 +518,8 @@ static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE];
|
|||
|
||||
struct pending_scan_result {
|
||||
int first; /* First bit position in tdo_buffer to read */
|
||||
int length; /* Number of bits to read */
|
||||
struct scan_command *command; /* Corresponding scan command */
|
||||
int length; /* Number of bits to read */
|
||||
struct scan_command *command; /* Corresponding scan command */
|
||||
uint8_t *buffer;
|
||||
};
|
||||
|
||||
|
@ -569,9 +542,7 @@ static void armjtagew_tap_ensure_space(int scans, int bits)
|
|||
int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length;
|
||||
|
||||
if (scans > available_scans || bits > available_bits)
|
||||
{
|
||||
armjtagew_tap_execute();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
uint8_t bit = 1 << bit_index;
|
||||
|
||||
if (tms)
|
||||
{
|
||||
tms_buffer[index_local] |= bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
tms_buffer[index_local] &= ~bit;
|
||||
}
|
||||
|
||||
if (tdi)
|
||||
{
|
||||
tdi_buffer[index_local] |= bit;
|
||||
}
|
||||
else
|
||||
{
|
||||
tdi_buffer[index_local] &= ~bit;
|
||||
}
|
||||
|
||||
tap_length++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
LOG_ERROR("armjtagew_tap_append_step, overflow");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1);
|
||||
}
|
||||
pending_scan_results_length++;
|
||||
}
|
||||
|
||||
|
@ -637,11 +595,9 @@ static int armjtagew_tap_execute(void)
|
|||
int i;
|
||||
int result;
|
||||
|
||||
if (tap_length > 0)
|
||||
{
|
||||
if (tap_length > 0) {
|
||||
/* 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,
|
||||
* analogous to free-running JTAG interfaces. */
|
||||
armjtagew_tap_append_step(last_tms, 0);
|
||||
|
@ -654,36 +610,33 @@ static int armjtagew_tap_execute(void)
|
|||
|
||||
tms_offset = 3;
|
||||
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;
|
||||
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;
|
||||
|
||||
stat_local = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32);
|
||||
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;
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[i];
|
||||
for (i = 0; i < pending_scan_results_length; i++) {
|
||||
struct pending_scan_result *pending_scan_result =
|
||||
&pending_scan_results_buffer[i];
|
||||
uint8_t *buffer = pending_scan_result->buffer;
|
||||
int length = pending_scan_result->length;
|
||||
int first = pending_scan_result->first;
|
||||
|
@ -698,21 +651,18 @@ static int armjtagew_tap_execute(void)
|
|||
armjtagew_debug_buffer(buffer, byte_length);
|
||||
#endif
|
||||
|
||||
if (jtag_read_buffer(buffer, command) != ERROR_OK)
|
||||
{
|
||||
if (jtag_read_buffer(buffer, command) != ERROR_OK) {
|
||||
armjtagew_tap_init();
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
}
|
||||
|
||||
if (pending_scan_result->buffer != NULL)
|
||||
{
|
||||
free(pending_scan_result->buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d", result, byte_length);
|
||||
} else {
|
||||
LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
|
||||
result,
|
||||
byte_length);
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
}
|
||||
|
||||
|
@ -722,10 +672,10 @@ static int armjtagew_tap_execute(void)
|
|||
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();
|
||||
|
||||
|
@ -765,17 +715,15 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in
|
|||
int result;
|
||||
|
||||
result = armjtagew_usb_write(armjtagew, out_length);
|
||||
if (result == out_length)
|
||||
{
|
||||
if (result == out_length) {
|
||||
result = armjtagew_usb_read(armjtagew, in_length);
|
||||
if (result != in_length)
|
||||
{
|
||||
LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", in_length, result);
|
||||
if (result != in_length) {
|
||||
LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)",
|
||||
in_length,
|
||||
result);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
|
||||
return -1;
|
||||
}
|
||||
|
@ -787,14 +735,15 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
|
|||
{
|
||||
int result;
|
||||
|
||||
if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE)
|
||||
{
|
||||
LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)", out_length, ARMJTAGEW_OUT_BUFFER_SIZE);
|
||||
if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) {
|
||||
LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
|
||||
out_length,
|
||||
ARMJTAGEW_OUT_BUFFER_SIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
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);
|
||||
|
||||
|
@ -828,17 +777,15 @@ static void armjtagew_debug_buffer(uint8_t *buffer, int length)
|
|||
int i;
|
||||
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);
|
||||
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]);
|
||||
strcat(line, s);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -26,7 +27,6 @@
|
|||
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
/* AT91RM9200 */
|
||||
#define AT91C_BASE_SYS (0xfffff000)
|
||||
|
||||
|
@ -78,9 +78,8 @@
|
|||
#define P30 (1 << 30)
|
||||
#define P31 (1 << 31)
|
||||
|
||||
struct device_t
|
||||
{
|
||||
char* name;
|
||||
struct device_t {
|
||||
char *name;
|
||||
int TDO_PIO; /* PIO holding TDO */
|
||||
uint32_t TDO_MASK; /* TDO bitmask */
|
||||
int TRST_PIO; /* PIO holding TRST */
|
||||
|
@ -95,21 +94,20 @@ struct device_t
|
|||
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 },
|
||||
{ .name = NULL },
|
||||
};
|
||||
|
||||
/* configuration */
|
||||
static char* at91rm9200_device;
|
||||
static char *at91rm9200_device;
|
||||
|
||||
/* interface variables
|
||||
*/
|
||||
static struct device_t* device;
|
||||
static struct device_t *device;
|
||||
static int dev_mem_fd;
|
||||
static void *sys_controller;
|
||||
static uint32_t* pio_base;
|
||||
static uint32_t *pio_base;
|
||||
|
||||
/* low level command set
|
||||
*/
|
||||
|
@ -121,8 +119,7 @@ static int at91rm9200_speed(int speed);
|
|||
static int at91rm9200_init(void);
|
||||
static int at91rm9200_quit(void);
|
||||
|
||||
static struct bitbang_interface at91rm9200_bitbang =
|
||||
{
|
||||
static struct bitbang_interface at91rm9200_bitbang = {
|
||||
.read = at91rm9200_read,
|
||||
.write = at91rm9200_write,
|
||||
.reset = at91rm9200_reset,
|
||||
|
@ -178,8 +175,7 @@ COMMAND_HANDLER(at91rm9200_handle_device_command)
|
|||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
/* 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));
|
||||
strcpy(at91rm9200_device, CMD_ARGV[0]);
|
||||
}
|
||||
|
@ -197,12 +193,9 @@ static const struct command_registration at91rm9200_command_handlers[] = {
|
|||
COMMAND_REGISTRATION_DONE
|
||||
};
|
||||
|
||||
struct jtag_interface at91rm9200_interface =
|
||||
{
|
||||
struct jtag_interface at91rm9200_interface = {
|
||||
.name = "at91rm9200",
|
||||
|
||||
.execute_queue = bitbang_execute_queue,
|
||||
|
||||
.speed = at91rm9200_speed,
|
||||
.commands = at91rm9200_command_handlers,
|
||||
.init = at91rm9200_init,
|
||||
|
@ -215,24 +208,20 @@ static int at91rm9200_init(void)
|
|||
|
||||
cur_device = devices;
|
||||
|
||||
if (at91rm9200_device == NULL || at91rm9200_device[0] == 0)
|
||||
{
|
||||
if (at91rm9200_device == NULL || at91rm9200_device[0] == 0) {
|
||||
at91rm9200_device = "rea_ecr";
|
||||
LOG_WARNING("No at91rm9200 device specified, using default 'rea_ecr'");
|
||||
}
|
||||
|
||||
while (cur_device->name)
|
||||
{
|
||||
if (strcmp(cur_device->name, at91rm9200_device) == 0)
|
||||
{
|
||||
while (cur_device->name) {
|
||||
if (strcmp(cur_device->name, at91rm9200_device) == 0) {
|
||||
device = cur_device;
|
||||
break;
|
||||
}
|
||||
cur_device++;
|
||||
}
|
||||
|
||||
if (!device)
|
||||
{
|
||||
if (!device) {
|
||||
LOG_ERROR("No matching device found for %s", at91rm9200_device);
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -252,7 +241,7 @@ static int at91rm9200_init(void)
|
|||
close(dev_mem_fd);
|
||||
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
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -38,7 +39,6 @@
|
|||
*/
|
||||
static void bitbang_stableclocks(int num_cycles);
|
||||
|
||||
|
||||
struct bitbang_interface *bitbang_interface;
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
/* The bitbang driver leaves the TCK 0 when in idle */
|
||||
static void bitbang_end_state(tap_state_t state)
|
||||
{
|
||||
if (tap_is_state_stable(state))
|
||||
tap_set_end_state(state);
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("BUG: %i is not a valid end state", state);
|
||||
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());
|
||||
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;
|
||||
bitbang_interface->write(0, tms, 0);
|
||||
bitbang_interface->write(1, tms, 0);
|
||||
|
@ -91,21 +88,19 @@ static void bitbang_state_move(int skip)
|
|||
tap_set_state(tap_get_end_state());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG
|
||||
* (or SWD) state machine.
|
||||
*/
|
||||
static int bitbang_execute_tms(struct jtag_command *cmd)
|
||||
{
|
||||
unsigned num_bits = cmd->cmd.tms->num_bits;
|
||||
const uint8_t *bits = cmd->cmd.tms->bits;
|
||||
unsigned num_bits = cmd->cmd.tms->num_bits;
|
||||
const uint8_t *bits = cmd->cmd.tms->bits;
|
||||
|
||||
DEBUG_JTAG_IO("TMS: %d bits", num_bits);
|
||||
|
||||
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);
|
||||
bitbang_interface->write(0, tms, 0);
|
||||
bitbang_interface->write(1, tms, 0);
|
||||
|
@ -115,7 +110,6 @@ static int bitbang_execute_tms(struct jtag_command *cmd)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
static void bitbang_path_move(struct pathmove_command *cmd)
|
||||
{
|
||||
int num_states = cmd->num_states;
|
||||
|
@ -123,19 +117,15 @@ static void bitbang_path_move(struct pathmove_command *cmd)
|
|||
int tms = 0;
|
||||
|
||||
state_count = 0;
|
||||
while (num_states)
|
||||
{
|
||||
while (num_states) {
|
||||
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
|
||||
{
|
||||
tms = 0;
|
||||
}
|
||||
else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
|
||||
{
|
||||
tms = 1;
|
||||
}
|
||||
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]));
|
||||
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]));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -159,15 +149,13 @@ static void bitbang_runtest(int num_cycles)
|
|||
tap_state_t saved_end_state = tap_get_end_state();
|
||||
|
||||
/* 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_state_move(0);
|
||||
}
|
||||
|
||||
/* 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(1, 0, 0);
|
||||
}
|
||||
|
@ -179,29 +167,26 @@ static void bitbang_runtest(int num_cycles)
|
|||
bitbang_state_move(0);
|
||||
}
|
||||
|
||||
|
||||
static void bitbang_stableclocks(int num_cycles)
|
||||
{
|
||||
int tms = (tap_get_state() == TAP_RESET ? 1 : 0);
|
||||
int i;
|
||||
|
||||
/* 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(0, tms, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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();
|
||||
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)
|
||||
bitbang_end_state(TAP_IRSHIFT);
|
||||
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);
|
||||
}
|
||||
|
||||
for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++)
|
||||
{
|
||||
for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
|
||||
int val = 0;
|
||||
int tms = (bit_cnt == scan_size-1) ? 1 : 0;
|
||||
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);
|
||||
|
||||
if (type != SCAN_OUT)
|
||||
{
|
||||
if (type != SCAN_OUT) {
|
||||
if (val)
|
||||
buffer[bytec] |= bcval;
|
||||
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
|
||||
* the shift state, so we skip the first state
|
||||
* and move directly to the end state.
|
||||
|
@ -255,14 +237,13 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
|
|||
|
||||
int bitbang_execute_queue(void)
|
||||
{
|
||||
struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
|
||||
struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
|
||||
int scan_size;
|
||||
enum scan_type type;
|
||||
uint8_t *buffer;
|
||||
int retval;
|
||||
|
||||
if (!bitbang_interface)
|
||||
{
|
||||
if (!bitbang_interface) {
|
||||
LOG_ERROR("BUG: Bitbang interface called, but not yet initialized");
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -275,23 +256,24 @@ int bitbang_execute_queue(void)
|
|||
if (bitbang_interface->blink)
|
||||
bitbang_interface->blink(1);
|
||||
|
||||
while (cmd)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
while (cmd) {
|
||||
switch (cmd->type) {
|
||||
case JTAG_RESET:
|
||||
#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
|
||||
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);
|
||||
}
|
||||
bitbang_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
break;
|
||||
case JTAG_RUNTEST:
|
||||
#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
|
||||
bitbang_end_state(cmd->cmd.runtest->end_state);
|
||||
bitbang_runtest(cmd->cmd.runtest->num_cycles);
|
||||
|
@ -306,21 +288,25 @@ int bitbang_execute_queue(void)
|
|||
|
||||
case JTAG_TLR_RESET:
|
||||
#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
|
||||
bitbang_end_state(cmd->cmd.statemove->end_state);
|
||||
bitbang_state_move(0);
|
||||
break;
|
||||
case JTAG_PATHMOVE:
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
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]));
|
||||
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]));
|
||||
#endif
|
||||
bitbang_path_move(cmd->cmd.pathmove);
|
||||
break;
|
||||
case JTAG_SCAN:
|
||||
#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
|
||||
bitbang_end_state(cmd->cmd.scan->end_state);
|
||||
scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef BITBANG_H
|
||||
#define BITBANG_H
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -25,8 +26,7 @@
|
|||
#include "bitq.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 */
|
||||
struct bitq_state {
|
||||
|
@ -44,29 +44,23 @@ static struct bitq_state bitq_in_state;
|
|||
static void bitq_in_proc(void)
|
||||
{
|
||||
/* loop through the queue */
|
||||
while (bitq_in_state.cmd)
|
||||
{
|
||||
while (bitq_in_state.cmd) {
|
||||
/* 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 */
|
||||
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;
|
||||
field = &bitq_in_state.cmd->cmd.scan->fields[bitq_in_state.field_idx];
|
||||
if (field->in_value)
|
||||
{
|
||||
if (field->in_value) {
|
||||
/* 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 */
|
||||
int in_idx = bitq_in_state.bit_pos / 8;
|
||||
/* mask of next bit to be scanned */
|
||||
uint8_t in_mask = 1 << (bitq_in_state.bit_pos % 8);
|
||||
|
||||
int tdo = bitq_interface->in();
|
||||
if (tdo < 0)
|
||||
{
|
||||
if (tdo < 0) {
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("bitq in EOF");
|
||||
#endif
|
||||
|
@ -89,7 +83,6 @@ static void bitq_in_proc(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void bitq_io(int tms, int tdi, int 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();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
exit(-1);
|
||||
}
|
||||
tap_set_end_state(state);
|
||||
}
|
||||
|
||||
|
||||
static void bitq_state_move(tap_state_t new_state)
|
||||
{
|
||||
int i = 0;
|
||||
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");
|
||||
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);
|
||||
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);
|
||||
tms_scan >>= 1;
|
||||
}
|
||||
|
@ -133,19 +121,16 @@ static void bitq_state_move(tap_state_t new_state)
|
|||
tap_set_state(new_state);
|
||||
}
|
||||
|
||||
|
||||
static void bitq_path_move(struct pathmove_command *cmd)
|
||||
{
|
||||
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])
|
||||
bitq_io(0, 0, 0);
|
||||
else if (tap_state_transition(tap_get_state(), true) == cmd->path[i])
|
||||
bitq_io(1, 0, 0);
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(
|
||||
tap_get_state()), tap_state_name(cmd->path[i]));
|
||||
exit(-1);
|
||||
|
@ -157,7 +142,6 @@ static void bitq_path_move(struct pathmove_command *cmd)
|
|||
tap_set_end_state(tap_get_state());
|
||||
}
|
||||
|
||||
|
||||
static void bitq_runtest(int num_cycles)
|
||||
{
|
||||
int i;
|
||||
|
@ -175,13 +159,12 @@ static void bitq_runtest(int num_cycles)
|
|||
bitq_state_move(tap_get_end_state());
|
||||
}
|
||||
|
||||
|
||||
static void bitq_scan_field(struct scan_field *field, int do_pause)
|
||||
{
|
||||
int bit_cnt;
|
||||
int tdo_req;
|
||||
|
||||
const uint8_t* out_ptr;
|
||||
const uint8_t *out_ptr;
|
||||
uint8_t out_mask;
|
||||
|
||||
if (field->in_value)
|
||||
|
@ -189,36 +172,29 @@ static void bitq_scan_field(struct scan_field *field, int do_pause)
|
|||
else
|
||||
tdo_req = 0;
|
||||
|
||||
if (field->out_value == NULL)
|
||||
{
|
||||
if (field->out_value == NULL) {
|
||||
/* just send zeros and request data from TDO */
|
||||
for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--)
|
||||
bitq_io(0, 0, tdo_req);
|
||||
|
||||
bitq_io(do_pause, 0, tdo_req);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* send data, and optionally request TDO */
|
||||
out_mask = 0x01;
|
||||
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);
|
||||
if (out_mask == 0x80)
|
||||
{
|
||||
if (out_mask == 0x80) {
|
||||
out_mask = 0x01;
|
||||
out_ptr++;
|
||||
}
|
||||
else
|
||||
} else
|
||||
out_mask <<= 1;
|
||||
}
|
||||
|
||||
bitq_io(do_pause, ((*out_ptr) & out_mask) != 0, tdo_req);
|
||||
}
|
||||
|
||||
if (do_pause)
|
||||
{
|
||||
if (do_pause) {
|
||||
bitq_io(0, 0, 0);
|
||||
if (tap_get_state() == TAP_IRSHIFT)
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
|
@ -243,28 +218,25 @@ static void bitq_scan(struct scan_command *cmd)
|
|||
bitq_scan_field(&cmd->fields[i], 1);
|
||||
}
|
||||
|
||||
|
||||
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.field_idx = 0;
|
||||
bitq_in_state.bit_pos = 0;
|
||||
bitq_in_state.status = ERROR_OK;
|
||||
|
||||
while (cmd)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
while (cmd) {
|
||||
switch (cmd->type) {
|
||||
case JTAG_RESET:
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
#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);
|
||||
}
|
||||
bitq_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
if (bitq_interface->in_rdy())
|
||||
bitq_in_proc();
|
||||
|
@ -328,13 +300,11 @@ int bitq_execute_queue(void)
|
|||
bitq_interface->flush();
|
||||
bitq_in_proc();
|
||||
|
||||
if (bitq_in_state.cmd)
|
||||
{
|
||||
if (bitq_in_state.cmd) {
|
||||
LOG_ERROR("missing data from bitq interface");
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
}
|
||||
if (bitq_interface->in() >= 0)
|
||||
{
|
||||
if (bitq_interface->in() >= 0) {
|
||||
LOG_ERROR("extra data from bitq interface");
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
}
|
||||
|
@ -342,7 +312,6 @@ int bitq_execute_queue(void)
|
|||
return bitq_in_state.status;
|
||||
}
|
||||
|
||||
|
||||
void bitq_cleanup(void)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -17,13 +17,14 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef BITQ_H
|
||||
#define BITQ_H
|
||||
|
||||
#include <jtag/commands.h>
|
||||
|
||||
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 (*flush)(void);
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ static void buspirate_runtest(int num_cycles);
|
|||
static void buspirate_scan(bool ir_scan, enum scan_type type,
|
||||
uint8_t *buffer, int scan_size, struct scan_command *command);
|
||||
|
||||
|
||||
#define CMD_UNKNOWN 0x00
|
||||
#define CMD_PORT_MODE 0x01
|
||||
#define CMD_FEATURE 0x02
|
||||
|
@ -84,7 +83,6 @@ enum {
|
|||
SERIAL_FAST = 1
|
||||
};
|
||||
|
||||
|
||||
static int buspirate_fd = -1;
|
||||
static int buspirate_pinmode = MODE_JTAG_OD;
|
||||
static int buspirate_baudrate = SERIAL_NORMAL;
|
||||
|
@ -92,7 +90,6 @@ static int buspirate_vreg;
|
|||
static int buspirate_pullup;
|
||||
static char *buspirate_port;
|
||||
|
||||
|
||||
/* TAP interface */
|
||||
static void buspirate_tap_init(void);
|
||||
static int buspirate_tap_execute(void);
|
||||
|
@ -279,9 +276,8 @@ COMMAND_HANDLER(buspirate_handle_adc_command)
|
|||
|
||||
COMMAND_HANDLER(buspirate_handle_vreg_command)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
if (CMD_ARGC < 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (atoi(CMD_ARGV[0]) == 1)
|
||||
buspirate_vreg = 1;
|
||||
|
@ -296,9 +292,8 @@ COMMAND_HANDLER(buspirate_handle_vreg_command)
|
|||
|
||||
COMMAND_HANDLER(buspirate_handle_pullup_command)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
if (CMD_ARGC < 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (atoi(CMD_ARGV[0]) == 1)
|
||||
buspirate_pullup = 1;
|
||||
|
@ -313,9 +308,8 @@ COMMAND_HANDLER(buspirate_handle_pullup_command)
|
|||
|
||||
COMMAND_HANDLER(buspirate_handle_led_command)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
if (CMD_ARGC < 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (atoi(CMD_ARGV[0]) == 1) {
|
||||
/* enable led */
|
||||
|
@ -335,9 +329,8 @@ COMMAND_HANDLER(buspirate_handle_led_command)
|
|||
|
||||
COMMAND_HANDLER(buspirate_handle_mode_command)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
if (CMD_ARGC < 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (CMD_ARGV[0][0] == 'n')
|
||||
buspirate_pinmode = MODE_JTAG;
|
||||
|
@ -352,9 +345,8 @@ COMMAND_HANDLER(buspirate_handle_mode_command)
|
|||
|
||||
COMMAND_HANDLER(buspirate_handle_speed_command)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
if (CMD_ARGC < 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (CMD_ARGV[0][0] == 'n')
|
||||
buspirate_baudrate = SERIAL_NORMAL;
|
||||
|
@ -369,9 +361,8 @@ COMMAND_HANDLER(buspirate_handle_speed_command)
|
|||
|
||||
COMMAND_HANDLER(buspirate_handle_port_command)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
if (CMD_ARGC < 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (buspirate_port == NULL)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -37,8 +38,7 @@
|
|||
#include <jtag/minidriver.h>
|
||||
#include <helper/command.h>
|
||||
|
||||
struct jtag_callback_entry
|
||||
{
|
||||
struct jtag_callback_entry {
|
||||
struct jtag_callback_entry *next;
|
||||
|
||||
jtag_callback_t callback;
|
||||
|
@ -48,8 +48,8 @@ struct jtag_callback_entry
|
|||
jtag_callback_data_t data3;
|
||||
};
|
||||
|
||||
static struct jtag_callback_entry *jtag_callback_queue_head = NULL;
|
||||
static struct jtag_callback_entry *jtag_callback_queue_tail = NULL;
|
||||
static struct jtag_callback_entry *jtag_callback_queue_head;
|
||||
static struct jtag_callback_entry *jtag_callback_queue_tail;
|
||||
|
||||
static void jtag_callback_queue_reset(void)
|
||||
{
|
||||
|
@ -62,60 +62,56 @@ static void jtag_callback_queue_reset(void)
|
|||
*
|
||||
* 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->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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_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 jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_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));
|
||||
|
||||
jtag_queue_command(cmd);
|
||||
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
|
||||
scan->ir_scan = true;
|
||||
scan->num_fields = num_taps; /* one field per device */
|
||||
scan->fields = out_fields;
|
||||
scan->end_state = state;
|
||||
scan->ir_scan = true;
|
||||
scan->num_fields = num_taps; /* one field per device */
|
||||
scan->fields = out_fields;
|
||||
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 */
|
||||
|
||||
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 */
|
||||
|
||||
if (tap == active)
|
||||
{
|
||||
if (tap == active) {
|
||||
/* if TAP is listed in input fields, copy the value */
|
||||
tap->bypass = 0;
|
||||
|
||||
cmd_queue_scan_field_clone(field, in_fields);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
/* if a TAP isn't listed in input fields, set it to BYPASS */
|
||||
|
||||
tap->bypass = 1;
|
||||
|
||||
field->num_bits = tap->ir_length;
|
||||
field->out_value = buf_set_ones(cmd_queue_alloc(DIV_ROUND_UP(tap->ir_length, 8)), tap->ir_length);
|
||||
field->in_value = NULL; /* do not collect input for tap's in bypass */
|
||||
field->num_bits = tap->ir_length;
|
||||
field->out_value = buf_set_ones(cmd_queue_alloc(DIV_ROUND_UP(tap->ir_length, 8)), tap->ir_length);
|
||||
field->in_value = NULL; /* do not collect input for tap's in bypass */
|
||||
}
|
||||
|
||||
/* update device information */
|
||||
|
@ -123,8 +119,8 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
|
|||
|
||||
field++;
|
||||
}
|
||||
|
||||
assert(field == out_fields + num_taps); /* paranoia: jtag_tap_count_enabled() and jtag_tap_next_enabled() not in sync */
|
||||
/* paranoia: jtag_tap_count_enabled() and jtag_tap_next_enabled() not in sync */
|
||||
assert(field == out_fields + num_taps);
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -133,51 +129,47 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
|
|||
* 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 */
|
||||
|
||||
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)
|
||||
bypass_devices++;
|
||||
}
|
||||
|
||||
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_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 jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_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));
|
||||
|
||||
jtag_queue_command(cmd);
|
||||
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
|
||||
scan->ir_scan = false;
|
||||
scan->num_fields = in_num_fields + bypass_devices;
|
||||
scan->fields = out_fields;
|
||||
scan->end_state = state;
|
||||
scan->ir_scan = false;
|
||||
scan->num_fields = in_num_fields + bypass_devices;
|
||||
scan->fields = out_fields;
|
||||
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 */
|
||||
|
||||
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->bypass)
|
||||
{
|
||||
if (!tap->bypass) {
|
||||
assert(active == tap);
|
||||
#ifndef NDEBUG
|
||||
/* remember initial position for assert() */
|
||||
struct scan_field *start_field = field;
|
||||
#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);
|
||||
|
||||
field++;
|
||||
|
@ -187,11 +179,10 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
|
|||
}
|
||||
|
||||
/* if a TAP is bypassed, generated a dummy bit*/
|
||||
else
|
||||
{
|
||||
field->num_bits = 1;
|
||||
field->out_value = NULL;
|
||||
field->in_value = NULL;
|
||||
else {
|
||||
field->num_bits = 1;
|
||||
field->out_value = NULL;
|
||||
field->in_value = NULL;
|
||||
|
||||
field++;
|
||||
}
|
||||
|
@ -202,8 +193,6 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate a DR SCAN using the array of output values passed to the function
|
||||
*
|
||||
|
@ -228,65 +217,60 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
|
|||
|
||||
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)
|
||||
bypass_devices++;
|
||||
}
|
||||
|
||||
|
||||
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_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 jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_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));
|
||||
|
||||
jtag_queue_command(cmd);
|
||||
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
|
||||
scan->ir_scan = false;
|
||||
scan->num_fields = in_num_fields + bypass_devices;
|
||||
scan->fields = out_fields;
|
||||
scan->end_state = end_state;
|
||||
scan->ir_scan = false;
|
||||
scan->num_fields = in_num_fields + bypass_devices;
|
||||
scan->fields = out_fields;
|
||||
scan->end_state = end_state;
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
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->bypass)
|
||||
{
|
||||
if (!tap->bypass) {
|
||||
assert(tap == target_tap); /* target_tap must match the one not bypassed TAP */
|
||||
|
||||
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];
|
||||
size_t scan_size = num_bits[j];
|
||||
buf_set_u32(out_value, 0, scan_size, value[j]);
|
||||
|
||||
field->num_bits = scan_size;
|
||||
field->out_value = buf_cpy(out_value, cmd_queue_alloc(DIV_ROUND_UP(scan_size, 8)), scan_size);
|
||||
field->in_value = NULL;
|
||||
field->num_bits = scan_size;
|
||||
field->out_value = buf_cpy(out_value, cmd_queue_alloc(DIV_ROUND_UP(scan_size, 8)), scan_size);
|
||||
field->in_value = NULL;
|
||||
|
||||
field++;
|
||||
}
|
||||
}
|
||||
|
||||
/* if a TAP is bypassed, generated a dummy bit*/
|
||||
else
|
||||
{
|
||||
else {
|
||||
|
||||
field->num_bits = 1;
|
||||
field->out_value = NULL;
|
||||
field->in_value = NULL;
|
||||
field->num_bits = 1;
|
||||
field->out_value = NULL;
|
||||
field->in_value = NULL;
|
||||
|
||||
field++;
|
||||
}
|
||||
|
@ -298,23 +282,23 @@ 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,
|
||||
uint8_t *in_bits, tap_state_t state, bool ir_scan)
|
||||
{
|
||||
struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_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 jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
|
||||
struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
|
||||
struct scan_field *out_fields = cmd_queue_alloc(sizeof(struct scan_field));
|
||||
|
||||
jtag_queue_command(cmd);
|
||||
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
cmd->type = JTAG_SCAN;
|
||||
cmd->cmd.scan = scan;
|
||||
|
||||
scan->ir_scan = ir_scan;
|
||||
scan->num_fields = 1;
|
||||
scan->fields = out_fields;
|
||||
scan->end_state = state;
|
||||
scan->ir_scan = ir_scan;
|
||||
scan->num_fields = 1;
|
||||
scan->fields = out_fields;
|
||||
scan->end_state = state;
|
||||
|
||||
out_fields->num_bits = num_bits;
|
||||
out_fields->out_value = buf_cpy(out_bits, cmd_queue_alloc(DIV_ROUND_UP(num_bits, 8)), num_bits);
|
||||
out_fields->in_value = in_bits;
|
||||
out_fields->num_bits = num_bits;
|
||||
out_fields->out_value = buf_cpy(out_bits, cmd_queue_alloc(DIV_ROUND_UP(num_bits, 8)), num_bits);
|
||||
out_fields->in_value = in_bits;
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -334,7 +318,7 @@ int interface_jtag_add_tlr(void)
|
|||
tap_state_t state = TAP_RESET;
|
||||
|
||||
/* 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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
/* 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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
/* 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);
|
||||
|
||||
|
@ -409,7 +393,7 @@ int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
|
|||
int interface_jtag_add_clocks(int num_cycles)
|
||||
{
|
||||
/* 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);
|
||||
|
||||
|
@ -424,7 +408,7 @@ int interface_jtag_add_clocks(int num_cycles)
|
|||
int interface_jtag_add_reset(int req_trst, int req_srst)
|
||||
{
|
||||
/* 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);
|
||||
|
||||
|
@ -440,7 +424,7 @@ int interface_jtag_add_reset(int req_trst, int req_srst)
|
|||
int interface_jtag_add_sleep(uint32_t us)
|
||||
{
|
||||
/* 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);
|
||||
|
||||
|
@ -453,7 +437,9 @@ int interface_jtag_add_sleep(uint32_t us)
|
|||
}
|
||||
|
||||
/* 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));
|
||||
|
||||
|
@ -464,12 +450,10 @@ void interface_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t
|
|||
entry->data2 = data2;
|
||||
entry->data3 = data3;
|
||||
|
||||
if (jtag_callback_queue_head == NULL)
|
||||
{
|
||||
if (jtag_callback_queue_head == NULL) {
|
||||
jtag_callback_queue_head = entry;
|
||||
jtag_callback_queue_tail = entry;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
jtag_callback_queue_tail->next = 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)
|
||||
{
|
||||
static int reentry = 0;
|
||||
static int reentry;
|
||||
|
||||
assert(reentry==0);
|
||||
assert(reentry == 0);
|
||||
reentry++;
|
||||
|
||||
int retval = default_interface_jtag_execute_queue();
|
||||
if (retval == ERROR_OK)
|
||||
{
|
||||
if (retval == ERROR_OK) {
|
||||
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);
|
||||
if (retval != ERROR_OK)
|
||||
break;
|
||||
|
@ -502,7 +484,8 @@ int interface_jtag_execute_queue(void)
|
|||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/* A minidriver can use use an inline versions of this API level fn */
|
||||
void jtag_add_dr_out(struct jtag_tap* tap,
|
||||
int num_fields, const int* num_bits, const uint32_t* value,
|
||||
void jtag_add_dr_out(struct jtag_tap *tap,
|
||||
int num_fields, const int *num_bits, const uint32_t *value,
|
||||
tap_state_t end_state)
|
||||
{
|
||||
assert(end_state != TAP_RESET);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -25,17 +26,15 @@
|
|||
#include "bitbang.h"
|
||||
#include "hello.h"
|
||||
|
||||
|
||||
/* my private tap controller state, which tracks state for calling code */
|
||||
static tap_state_t dummy_state = TAP_RESET;
|
||||
|
||||
static int dummy_clock; /* edge detector */
|
||||
static int dummy_clock; /* edge detector */
|
||||
|
||||
static int clock_count; /* count clocks in any stable state, only stable states */
|
||||
static int clock_count; /* count clocks in any stable state, only stable states */
|
||||
|
||||
static uint32_t dummy_data;
|
||||
|
||||
|
||||
static int dummy_read(void)
|
||||
{
|
||||
int data = 1 & dummy_data;
|
||||
|
@ -43,21 +42,16 @@ static int dummy_read(void)
|
|||
return data;
|
||||
}
|
||||
|
||||
|
||||
static void dummy_write(int tck, int tms, int tdi)
|
||||
{
|
||||
/* TAP standard: "state transitions occur on rising edge of clock" */
|
||||
if (tck != dummy_clock)
|
||||
{
|
||||
if (tck)
|
||||
{
|
||||
if (tck != dummy_clock) {
|
||||
if (tck) {
|
||||
tap_state_t old_state = dummy_state;
|
||||
dummy_state = tap_state_transition(old_state, tms);
|
||||
|
||||
if (old_state != dummy_state)
|
||||
{
|
||||
if (clock_count)
|
||||
{
|
||||
if (old_state != dummy_state) {
|
||||
if (clock_count) {
|
||||
LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
|
||||
clock_count = 0;
|
||||
}
|
||||
|
@ -68,9 +62,7 @@ static void dummy_write(int tck, int tms, int tdi)
|
|||
if (dummy_state == TAP_DRCAPTURE)
|
||||
dummy_data = 0x01255043;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* this is a stable state clock edge, no change of state here,
|
||||
* simply increment clock_count for subsequent logging
|
||||
*/
|
||||
|
@ -102,30 +94,21 @@ static struct bitbang_interface dummy_bitbang = {
|
|||
.blink = &dummy_led,
|
||||
};
|
||||
|
||||
|
||||
static int dummy_khz(int khz, int *jtag_speed)
|
||||
{
|
||||
if (khz == 0)
|
||||
{
|
||||
*jtag_speed = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*jtag_speed = 64000/khz;
|
||||
}
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static int dummy_speed_div(int speed, int *khz)
|
||||
{
|
||||
if (speed == 0)
|
||||
{
|
||||
*khz = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*khz = 64000/speed;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -34,7 +35,7 @@
|
|||
|
||||
#include <sys/mman.h>
|
||||
|
||||
static uint8_t output_value = 0x0;
|
||||
static uint8_t output_value;
|
||||
static int dev_mem_fd;
|
||||
static void *gpio_controller;
|
||||
static volatile uint8_t *gpio_data_register;
|
||||
|
@ -52,8 +53,7 @@ static int ep93xx_quit(void);
|
|||
|
||||
struct timespec ep93xx_zzzz;
|
||||
|
||||
struct jtag_interface ep93xx_interface =
|
||||
{
|
||||
struct jtag_interface ep93xx_interface = {
|
||||
.name = "ep93xx",
|
||||
|
||||
.supported = DEBUG_CAP_TMS_SEQ,
|
||||
|
@ -64,8 +64,7 @@ struct jtag_interface ep93xx_interface =
|
|||
.quit = ep93xx_quit,
|
||||
};
|
||||
|
||||
static struct bitbang_interface ep93xx_bitbang =
|
||||
{
|
||||
static struct bitbang_interface ep93xx_bitbang = {
|
||||
.read = ep93xx_read,
|
||||
.write = ep93xx_write,
|
||||
.reset = ep93xx_reset,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,8 +27,7 @@
|
|||
|
||||
static const char *ftd2xx_status_string(FT_STATUS status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
switch (status) {
|
||||
case FT_OK: return "OK";
|
||||
case FT_INVALID_HANDLE: return "invalid handle";
|
||||
case FT_DEVICE_NOT_FOUND: return "device not found";
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -24,7 +25,6 @@
|
|||
#include <jtag/interface.h>
|
||||
#include <jtag/commands.h>
|
||||
|
||||
|
||||
#if 1
|
||||
#define _DEBUG_GW16012_IO_
|
||||
#endif
|
||||
|
@ -35,14 +35,13 @@
|
|||
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#define ioperm(startport,length,enable)\
|
||||
i386_set_ioperm((startport), (length), (enable))
|
||||
#define ioperm(startport, length, enable) \
|
||||
386_set_ioperm((startport), (length), (enable))
|
||||
|
||||
#else
|
||||
|
||||
#endif /* __FreeBSD__, __FreeBSD_kernel__ */
|
||||
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
#include <dev/ppbus/ppi.h>
|
||||
|
@ -65,14 +64,13 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* configuration */
|
||||
uint16_t gw16012_port;
|
||||
|
||||
/* interface variables
|
||||
*/
|
||||
static uint8_t gw16012_msb = 0x0;
|
||||
static uint8_t gw16012_control_value = 0x0;
|
||||
static uint8_t gw16012_msb;
|
||||
static uint8_t gw16012_control_value;
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
static int device_handle;
|
||||
|
@ -100,8 +98,7 @@ static void gw16012_data(uint8_t value)
|
|||
|
||||
static void gw16012_control(uint8_t value)
|
||||
{
|
||||
if (value != gw16012_control_value)
|
||||
{
|
||||
if (value != gw16012_control_value) {
|
||||
gw16012_control_value = value;
|
||||
|
||||
#ifdef _DEBUG_GW16012_IO_
|
||||
|
@ -159,8 +156,7 @@ static void gw16012_end_state(tap_state_t state)
|
|||
{
|
||||
if (tap_is_state_stable(state))
|
||||
tap_set_end_state(state);
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("BUG: %i is not a valid end state", state);
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -174,8 +170,7 @@ static void gw16012_state_move(void)
|
|||
|
||||
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;
|
||||
gw16012_data(tms << 1); /* output next TMS bit */
|
||||
}
|
||||
|
@ -189,20 +184,15 @@ static void gw16012_path_move(struct pathmove_command *cmd)
|
|||
int state_count;
|
||||
|
||||
state_count = 0;
|
||||
while (num_states)
|
||||
{
|
||||
while (num_states) {
|
||||
gw16012_control(0x0); /* single-bit mode */
|
||||
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
|
||||
{
|
||||
gw16012_data(0x0); /* TCK cycle with TMS low */
|
||||
}
|
||||
else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
|
||||
{
|
||||
gw16012_data(0x2); /* TCK cycle with TMS high */
|
||||
}
|
||||
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]));
|
||||
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]));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -220,14 +210,12 @@ static void gw16012_runtest(int num_cycles)
|
|||
int i;
|
||||
|
||||
/* 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_state_move();
|
||||
}
|
||||
|
||||
for (i = 0; i < num_cycles; i++)
|
||||
{
|
||||
for (i = 0; i < num_cycles; i++) {
|
||||
gw16012_control(0x0); /* single-bit mode */
|
||||
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;
|
||||
|
||||
/* 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)
|
||||
gw16012_end_state(TAP_IRSHIFT);
|
||||
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);
|
||||
}
|
||||
|
||||
while (type == SCAN_OUT && ((bits_left - 1) > 7))
|
||||
{
|
||||
while (type == SCAN_OUT && ((bits_left - 1) > 7)) {
|
||||
gw16012_control(0x2); /* seven-bit mode */
|
||||
scan_out = buf_get_u32(buffer, bit_count, 7);
|
||||
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 */
|
||||
while (bits_left-- > 0)
|
||||
{
|
||||
while (bits_left-- > 0) {
|
||||
uint8_t tms = 0;
|
||||
|
||||
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))
|
||||
|| (!ir_scan && (tap_get_end_state() == TAP_DRSHIFT)))
|
||||
{
|
||||
tms = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tms = 2;
|
||||
}
|
||||
}
|
||||
|
||||
gw16012_data(scan_out | tms);
|
||||
|
||||
if (type != SCAN_OUT)
|
||||
{
|
||||
if (type != SCAN_OUT) {
|
||||
gw16012_input(&scan_in);
|
||||
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)) ||
|
||||
(!ir_scan && (tap_get_end_state() == TAP_DRSHIFT))))
|
||||
{
|
||||
(!ir_scan && (tap_get_end_state() == TAP_DRSHIFT)))) {
|
||||
gw16012_data(0x0);
|
||||
if (ir_scan)
|
||||
tap_set_state(TAP_IRPAUSE);
|
||||
|
@ -323,23 +302,20 @@ static int gw16012_execute_queue(void)
|
|||
*/
|
||||
retval = ERROR_OK;
|
||||
|
||||
while (cmd)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
while (cmd) {
|
||||
switch (cmd->type) {
|
||||
case JTAG_RESET:
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
#endif
|
||||
if (cmd->cmd.reset->trst == 1)
|
||||
{
|
||||
tap_set_state(TAP_RESET);
|
||||
}
|
||||
gw16012_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
break;
|
||||
case JTAG_RUNTEST:
|
||||
#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
|
||||
gw16012_end_state(cmd->cmd.runtest->end_state);
|
||||
gw16012_runtest(cmd->cmd.runtest->num_cycles);
|
||||
|
@ -353,7 +329,8 @@ static int gw16012_execute_queue(void)
|
|||
break;
|
||||
case JTAG_PATHMOVE:
|
||||
#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
|
||||
gw16012_path_move(cmd->cmd.pathmove);
|
||||
break;
|
||||
|
@ -401,7 +378,8 @@ static int gw16012_get_giveio_access(void)
|
|||
if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
|
||||
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) {
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
|
@ -423,24 +401,21 @@ static int gw16012_init_ioctls(void)
|
|||
{
|
||||
int temp = 0;
|
||||
temp = ioctl(device_handle, PPCLAIM);
|
||||
if (temp < 0)
|
||||
{
|
||||
if (temp < 0) {
|
||||
LOG_ERROR("cannot claim device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
temp = PARPORT_MODE_COMPAT;
|
||||
temp = ioctl(device_handle, PPSETMODE, &temp);
|
||||
if (temp < 0)
|
||||
{
|
||||
if (temp < 0) {
|
||||
LOG_ERROR(" cannot set compatible mode to device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
temp = IEEE1284_MODE_COMPAT;
|
||||
temp = ioctl(device_handle, PPNEGOT, &temp);
|
||||
if (temp < 0)
|
||||
{
|
||||
if (temp < 0) {
|
||||
LOG_ERROR("cannot set compatible 1284 mode to device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -455,15 +430,14 @@ static int gw16012_init_ioctls(void)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
#endif // defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
|
||||
|
||||
static int gw16012_init_device(void)
|
||||
{
|
||||
const char *device_name = GW16012_PPDEV_NAME;
|
||||
char buffer[256];
|
||||
|
||||
if (device_handle > 0)
|
||||
{
|
||||
if (device_handle > 0) {
|
||||
LOG_ERROR("device is already opened");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -472,8 +446,7 @@ static int gw16012_init_device(void)
|
|||
LOG_DEBUG("opening %s...", buffer);
|
||||
|
||||
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");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -486,23 +459,21 @@ static int gw16012_init_device(void)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
#else // PARPORT_USE_PPDEV
|
||||
#else /* PARPORT_USE_PPDEV */
|
||||
|
||||
static int gw16012_init_device(void)
|
||||
{
|
||||
if (gw16012_port == 0)
|
||||
{
|
||||
if (gw16012_port == 0) {
|
||||
gw16012_port = 0x378;
|
||||
LOG_WARNING("No gw16012 port specified, using default '0x378' (LPT1)");
|
||||
}
|
||||
|
||||
LOG_DEBUG("requesting privileges for parallel port 0x%lx...", (long unsigned)(gw16012_port));
|
||||
#if PARPORT_USE_GIVEIO == 1
|
||||
if (gw16012_get_giveio_access() != 0)
|
||||
if (gw16012_get_giveio_access() != 0) {
|
||||
#else /* PARPORT_USE_GIVEIO */
|
||||
if (ioperm(gw16012_port, 3, 1) != 0)
|
||||
if (ioperm(gw16012_port, 3, 1) != 0) {
|
||||
#endif /* PARPORT_USE_GIVEIO */
|
||||
{
|
||||
LOG_ERROR("missing privileges for direct i/o");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -517,7 +488,7 @@ static int gw16012_init_device(void)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
#endif // PARPORT_USE_PPDEV
|
||||
#endif /* PARPORT_USE_PPDEV */
|
||||
|
||||
static int gw16012_init(void)
|
||||
{
|
||||
|
@ -542,15 +513,11 @@ static int gw16012_quit(void)
|
|||
|
||||
COMMAND_HANDLER(gw16012_handle_parport_port_command)
|
||||
{
|
||||
if (CMD_ARGC == 1)
|
||||
{
|
||||
if (CMD_ARGC == 1) {
|
||||
/* only if the port wasn't overwritten by cmdline */
|
||||
if (gw16012_port == 0)
|
||||
{
|
||||
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], gw16012_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("The parport port was already configured!");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
|
|
@ -33,11 +33,10 @@
|
|||
#include "libusb_common.h"
|
||||
|
||||
/* See Segger's public documentation:
|
||||
* Reference manual for J-Link USB Protocol
|
||||
* Document RM08001-R6 Date: June 16, 2009
|
||||
* (Or newer, with some SWD information).
|
||||
|
||||
http://www.segger.com/cms/admin/uploads/productDocs/RM08001_JLinkUSBProtocol.pdf
|
||||
* Reference manual for J-Link USB Protocol
|
||||
* Document RM08001-R6 Date: June 16, 2009
|
||||
* (Or newer, with some SWD information).
|
||||
* 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)
|
||||
*/
|
||||
|
||||
#define VID 0x1366, 0x1366, 0x1366, 0x1366
|
||||
#define PID 0x0101, 0x0102, 0x0103, 0x0104
|
||||
|
||||
|
@ -56,16 +56,16 @@ static unsigned int jlink_write_ep = JLINK_WRITE_ENDPOINT;
|
|||
static unsigned int jlink_read_ep = JLINK_READ_ENDPOINT;
|
||||
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 */
|
||||
#define JLINK_TAP_BUFFER_SIZE 2048
|
||||
//#define JLINK_TAP_BUFFER_SIZE 256
|
||||
//#define JLINK_TAP_BUFFER_SIZE 384
|
||||
/*#define JLINK_TAP_BUFFER_SIZE 256*/
|
||||
/*#define JLINK_TAP_BUFFER_SIZE 384*/
|
||||
|
||||
#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
|
||||
|
||||
/* 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 struct jlink* jlink_handle;
|
||||
static struct jlink *jlink_handle;
|
||||
|
||||
/* pid could be specified at runtime */
|
||||
static uint16_t vids[] = { VID, 0 };
|
||||
|
@ -320,17 +320,28 @@ static void jlink_execute_sleep(struct jtag_command *cmd)
|
|||
|
||||
static void jlink_execute_command(struct jtag_command *cmd)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
case JTAG_RUNTEST: jlink_execute_runtest(cmd); break;
|
||||
case JTAG_TLR_RESET: jlink_execute_statemove(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:
|
||||
LOG_ERROR("BUG: unknown JTAG command type encountered");
|
||||
exit(-1);
|
||||
switch (cmd->type) {
|
||||
case JTAG_RUNTEST:
|
||||
jlink_execute_runtest(cmd);
|
||||
break;
|
||||
case JTAG_TLR_RESET:
|
||||
jlink_execute_statemove(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:
|
||||
LOG_ERROR("BUG: unknown JTAG command type encountered");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,8 +349,7 @@ static int jlink_execute_queue(void)
|
|||
{
|
||||
struct jtag_command *cmd = jtag_command_queue;
|
||||
|
||||
while (cmd != NULL)
|
||||
{
|
||||
while (cmd != NULL) {
|
||||
jlink_execute_command(cmd);
|
||||
cmd = cmd->next;
|
||||
}
|
||||
|
@ -352,8 +362,7 @@ static int jlink_speed(int speed)
|
|||
{
|
||||
int result;
|
||||
|
||||
if (speed > JLINK_MAX_SPEED)
|
||||
{
|
||||
if (speed > JLINK_MAX_SPEED) {
|
||||
LOG_INFO("reduce speed request: %dkHz to %dkHz maximum",
|
||||
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;
|
||||
|
||||
result = jlink_usb_write(jlink_handle, 3);
|
||||
if (result != 3)
|
||||
{
|
||||
if (result != 3) {
|
||||
LOG_ERROR("J-Link setting speed failed (%d)", result);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -377,7 +385,7 @@ static int jlink_speed(int speed)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static int jlink_speed_div(int speed, int* khz)
|
||||
static int jlink_speed_div(int speed, int *khz)
|
||||
{
|
||||
*khz = speed;
|
||||
|
||||
|
@ -397,8 +405,7 @@ static int jlink_init(void)
|
|||
|
||||
jlink_handle = jlink_usb_open();
|
||||
|
||||
if (jlink_handle == 0)
|
||||
{
|
||||
if (jlink_handle == 0) {
|
||||
LOG_ERROR("Cannot find jlink Interface! Please check "
|
||||
"connection and permissions.");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
|
@ -428,8 +435,7 @@ static int jlink_init(void)
|
|||
|
||||
jlink_hw_jtag_version = 2;
|
||||
|
||||
if (jlink_get_version_info() == ERROR_OK)
|
||||
{
|
||||
if (jlink_get_version_info() == ERROR_OK) {
|
||||
/* attempt to 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
|
||||
* 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_execute();
|
||||
|
||||
return ERROR_OK;
|
||||
|
@ -462,11 +467,8 @@ static int jlink_quit(void)
|
|||
static void jlink_end_state(tap_state_t state)
|
||||
{
|
||||
if (tap_is_state_stable(state))
|
||||
{
|
||||
tap_set_end_state(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("BUG: %i is not a valid end state", state);
|
||||
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_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;
|
||||
jlink_tap_append_step(tms, 0);
|
||||
}
|
||||
|
@ -493,18 +494,12 @@ static void jlink_path_move(int num_states, tap_state_t *path)
|
|||
{
|
||||
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))
|
||||
{
|
||||
jlink_tap_append_step(0, 0);
|
||||
}
|
||||
else if (path[i] == tap_state_transition(tap_get_state(), true))
|
||||
{
|
||||
jlink_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]));
|
||||
exit(-1);
|
||||
|
@ -522,28 +517,23 @@ static void jlink_runtest(int num_cycles)
|
|||
|
||||
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 */
|
||||
if (tap_get_state() != TAP_IDLE)
|
||||
{
|
||||
if (tap_get_state() != TAP_IDLE) {
|
||||
jlink_end_state(TAP_IDLE);
|
||||
jlink_state_move();
|
||||
// num_cycles--;
|
||||
/* num_cycles--; */
|
||||
}
|
||||
|
||||
/* execute num_cycles */
|
||||
for (i = 0; i < num_cycles; i++)
|
||||
{
|
||||
jlink_tap_append_step(0, 0);
|
||||
}
|
||||
|
||||
/* finish in end_state */
|
||||
jlink_end_state(saved_end_state);
|
||||
if (tap_get_state() != tap_get_end_state())
|
||||
{
|
||||
jlink_state_move();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (tap_get_state() != tap_get_end_state())
|
||||
{
|
||||
jlink_state_move();
|
||||
}
|
||||
}
|
||||
|
||||
static void jlink_reset(int trst, int srst)
|
||||
|
@ -584,23 +572,16 @@ static void jlink_reset(int trst, int srst)
|
|||
|
||||
/* Signals are active low */
|
||||
if (srst == 0)
|
||||
{
|
||||
jlink_simple_command(EMU_CMD_HW_RESET1);
|
||||
}
|
||||
|
||||
if (srst == 1)
|
||||
{
|
||||
jlink_simple_command(EMU_CMD_HW_RESET0);
|
||||
}
|
||||
|
||||
if (trst == 1)
|
||||
{
|
||||
jlink_simple_command(EMU_CMD_HW_TRST0);
|
||||
}
|
||||
|
||||
if (trst == 0)
|
||||
{
|
||||
jlink_simple_command(EMU_CMD_HW_TRST1);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (result != 1)
|
||||
{
|
||||
LOG_ERROR("J-Link command 0x%02x failed (%d)", command, result);
|
||||
}
|
||||
}
|
||||
|
||||
static int jlink_get_status(void)
|
||||
|
@ -625,8 +604,7 @@ static int jlink_get_status(void)
|
|||
jlink_simple_command(EMU_CMD_GET_STATE);
|
||||
|
||||
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);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -643,14 +621,13 @@ static int jlink_get_status(void)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
#define jlink_dump_printf(context, expr ...) \
|
||||
do { \
|
||||
if (context) \
|
||||
command_print(context, expr); \
|
||||
else \
|
||||
LOG_INFO(expr); \
|
||||
} while(0);
|
||||
|
||||
#define jlink_dump_printf(context, expr ...) \
|
||||
do { \
|
||||
if (context) \
|
||||
command_print(context, expr); \
|
||||
else \
|
||||
LOG_INFO(expr); \
|
||||
} while (0);
|
||||
|
||||
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_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_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);
|
||||
|
||||
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);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -755,8 +730,7 @@ static int jlink_set_config(struct jlink_config *cfg)
|
|||
memcpy(usb_out_buffer, cfg, 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);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -774,22 +748,19 @@ static int jlink_get_version_info(void)
|
|||
jlink_simple_command(EMU_CMD_VERSION);
|
||||
|
||||
result = jlink_usb_read(jlink_handle, 2);
|
||||
if (2 != result)
|
||||
{
|
||||
if (2 != result) {
|
||||
LOG_ERROR("J-Link command EMU_CMD_VERSION failed (%d)", result);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
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);
|
||||
len = JLINK_IN_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
result = jlink_usb_read(jlink_handle, len);
|
||||
if (result != len)
|
||||
{
|
||||
if (result != len) {
|
||||
LOG_ERROR("J-Link command EMU_CMD_VERSION failed (%d)", result);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -801,8 +772,7 @@ static int jlink_get_version_info(void)
|
|||
jlink_simple_command(EMU_CMD_GET_CAPS);
|
||||
|
||||
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);
|
||||
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);
|
||||
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 */
|
||||
jlink_simple_command(EMU_CMD_GET_HW_VERSION);
|
||||
|
||||
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);
|
||||
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]);
|
||||
}
|
||||
|
||||
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 */
|
||||
jlink_simple_command(EMU_CMD_GET_MAX_MEM_BLOCK);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
if (jlink_caps & (1 << EMU_CAP_READ_CONFIG))
|
||||
{
|
||||
if (jlink_caps & (1 << EMU_CAP_READ_CONFIG)) {
|
||||
if (jlink_get_config(&jlink_cfg) != ERROR_OK)
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
|
||||
|
@ -865,8 +830,7 @@ static int jlink_get_version_info(void)
|
|||
|
||||
COMMAND_HANDLER(jlink_pid_command)
|
||||
{
|
||||
if (CMD_ARGC != 1)
|
||||
{
|
||||
if (CMD_ARGC != 1) {
|
||||
LOG_ERROR("Need exactly one argument to jlink_pid");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -880,8 +844,7 @@ COMMAND_HANDLER(jlink_pid_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 */
|
||||
jlink_get_status();
|
||||
}
|
||||
|
@ -899,22 +862,23 @@ COMMAND_HANDLER(jlink_handle_jlink_caps_command)
|
|||
COMMAND_HANDLER(jlink_handle_jlink_hw_jtag_command)
|
||||
{
|
||||
switch (CMD_ARGC) {
|
||||
case 0:
|
||||
command_print(CMD_CTX, "J-Link hw jtag %i", jlink_hw_jtag_version);
|
||||
break;
|
||||
case 1: {
|
||||
int request_version = atoi(CMD_ARGV[0]);
|
||||
switch (request_version) {
|
||||
case 2: case 3:
|
||||
jlink_hw_jtag_version = request_version;
|
||||
case 0:
|
||||
command_print(CMD_CTX, "J-Link hw jtag %i", jlink_hw_jtag_version);
|
||||
break;
|
||||
case 1: {
|
||||
int request_version = atoi(CMD_ARGV[0]);
|
||||
switch (request_version) {
|
||||
case 2:
|
||||
case 3:
|
||||
jlink_hw_jtag_version = request_version;
|
||||
break;
|
||||
default:
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
|
@ -924,8 +888,7 @@ COMMAND_HANDLER(jlink_handle_jlink_kickstart_command)
|
|||
{
|
||||
uint32_t kickstart;
|
||||
|
||||
if (CMD_ARGC < 1)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
jlink_config_kickstart_dump(CMD_CTX, &jlink_cfg);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -943,8 +906,7 @@ COMMAND_HANDLER(jlink_handle_jlink_mac_address_command)
|
|||
char *e;
|
||||
const char *str;
|
||||
|
||||
if (CMD_ARGC < 1)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
jlink_config_mac_address_dump(CMD_CTX, &jlink_cfg);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -952,26 +914,22 @@ COMMAND_HANDLER(jlink_handle_jlink_mac_address_command)
|
|||
str = CMD_ARGV[0];
|
||||
|
||||
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");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
for (i = 5; i >= 0; i--)
|
||||
{
|
||||
for (i = 5; i >= 0; i--) {
|
||||
addr[i] = strtoul(str, &e, 16);
|
||||
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");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (!(0x01 & addr[0]))
|
||||
{
|
||||
if (!(0x01 & addr[0])) {
|
||||
command_print(CMD_CTX, "invalid it's a multicat mac_address");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
@ -1022,13 +980,12 @@ COMMAND_HANDLER(jlink_handle_jlink_ip_command)
|
|||
int ret;
|
||||
uint8_t subnet_bits = 24;
|
||||
|
||||
if (CMD_ARGC < 1)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
jlink_config_ip_dump(CMD_CTX, &jlink_cfg);
|
||||
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)
|
||||
return ret;
|
||||
|
||||
|
@ -1036,18 +993,14 @@ COMMAND_HANDLER(jlink_handle_jlink_ip_command)
|
|||
|
||||
/* check for this format A.B.C.D/E */
|
||||
|
||||
if (i < len)
|
||||
{
|
||||
if (i < len) {
|
||||
if (CMD_ARGV[0][i] != '/')
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0] + i + 1, subnet_bits);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CMD_ARGC > 1)
|
||||
{
|
||||
ret = string_to_ip(CMD_ARGV[1], (uint8_t*)&subnet_mask, &i);
|
||||
} else {
|
||||
if (CMD_ARGC > 1) {
|
||||
ret = string_to_ip(CMD_ARGV[1], (uint8_t *)&subnet_mask, &i);
|
||||
if (ret != ERROR_OK)
|
||||
return ret;
|
||||
}
|
||||
|
@ -1055,10 +1008,10 @@ COMMAND_HANDLER(jlink_handle_jlink_ip_command)
|
|||
|
||||
if (!subnet_mask)
|
||||
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.subnet_mask, (uint8_t*)&subnet_mask);
|
||||
cpy_ip(jlink_cfg.ip_address, (uint8_t *)&ip_address);
|
||||
cpy_ip(jlink_cfg.subnet_mask, (uint8_t *)&subnet_mask);
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -1071,8 +1024,7 @@ COMMAND_HANDLER(jlink_handle_jlink_reset_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");
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -1085,16 +1037,14 @@ COMMAND_HANDLER(jlink_handle_jlink_usb_address_command)
|
|||
{
|
||||
uint32_t address;
|
||||
|
||||
if (CMD_ARGC < 1)
|
||||
{
|
||||
if (CMD_ARGC < 1) {
|
||||
jlink_config_usb_address_dump(CMD_CTX, &jlink_cfg);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
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");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
@ -1108,17 +1058,15 @@ COMMAND_HANDLER(jlink_handle_jlink_config_command)
|
|||
struct jlink_config cfg;
|
||||
int ret = ERROR_OK;
|
||||
|
||||
if (CMD_ARGC == 0)
|
||||
{
|
||||
if (!(jlink_caps & (1 << EMU_CAP_READ_CONFIG)))
|
||||
{
|
||||
if (CMD_ARGC == 0) {
|
||||
if (!(jlink_caps & (1 << EMU_CAP_READ_CONFIG))) {
|
||||
command_print(CMD_CTX, "J-Link read emulator configuration not supported");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = jlink_get_config(&cfg);
|
||||
|
||||
if ( ret != ERROR_OK)
|
||||
if (ret != ERROR_OK)
|
||||
command_print(CMD_CTX, "J-Link read emulator configuration failled");
|
||||
else
|
||||
jlink_config_dump(CMD_CTX, &jlink_cfg);
|
||||
|
@ -1239,7 +1187,7 @@ struct jtag_interface jlink_interface = {
|
|||
/* 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 tdi_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;
|
||||
|
||||
if (scans > available_scans || bits > available_bits)
|
||||
{
|
||||
jlink_tap_execute();
|
||||
}
|
||||
}
|
||||
|
||||
static void jlink_tap_append_step(int tms, int tdi)
|
||||
{
|
||||
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");
|
||||
*(uint32_t *)0xFFFFFFFF = 0;
|
||||
exit(-1);
|
||||
|
@ -1287,11 +1232,9 @@ static void jlink_tap_append_step(int tms, int tdi)
|
|||
int bit_index = tap_length % 8;
|
||||
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)
|
||||
{
|
||||
tms_buffer[index_var] = tdi_buffer[index_var] = 0;
|
||||
}
|
||||
|
||||
if (tms)
|
||||
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->buffer = buffer;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
for (i = 0; i < length; i++) {
|
||||
int tms = (i < (length - 1)) ? 0 : 1;
|
||||
int tdi = (buffer[i / 8] & (1 << (i % 8))) != 0;
|
||||
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.
|
||||
* WARNING: This will interfere with tap state counting. */
|
||||
while ((DIV_ROUND_UP(tap_length, 8) % 64) == 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);
|
||||
|
||||
bool use_jtag3 = jlink_hw_jtag_version >= 3;
|
||||
|
@ -1361,8 +1301,7 @@ static int jlink_tap_execute(void)
|
|||
tap_length, jlink_last_state);
|
||||
|
||||
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)",
|
||||
result, byte_length);
|
||||
jlink_tap_init();
|
||||
|
@ -1371,8 +1310,7 @@ static int jlink_tap_execute(void)
|
|||
|
||||
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];
|
||||
uint8_t *buffer = pending_scan_result->buffer;
|
||||
int length = pending_scan_result->length;
|
||||
|
@ -1386,16 +1324,13 @@ static int jlink_tap_execute(void)
|
|||
|
||||
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();
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
}
|
||||
|
||||
if (pending_scan_result->buffer != NULL)
|
||||
{
|
||||
free(pending_scan_result->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
jlink_tap_init();
|
||||
|
@ -1405,7 +1340,7 @@ static int jlink_tap_execute(void)
|
|||
/*****************************************************************************/
|
||||
/* JLink USB low-level functions */
|
||||
|
||||
static struct jlink* jlink_usb_open()
|
||||
static struct jlink *jlink_usb_open()
|
||||
{
|
||||
struct jtag_libusb_device_handle *devh;
|
||||
if (jtag_libusb_open(vids, pids, &devh) != ERROR_OK)
|
||||
|
@ -1432,13 +1367,11 @@ static struct jlink* jlink_usb_open()
|
|||
/* reopen jlink after usb_reset
|
||||
* on win32 this may take a second or two to re-enumerate */
|
||||
int retval;
|
||||
while ((retval = jtag_libusb_open(vids, pids, &devh)) != ERROR_OK)
|
||||
{
|
||||
while ((retval = jtag_libusb_open(vids, pids, &devh)) != ERROR_OK) {
|
||||
usleep(1000);
|
||||
timeout--;
|
||||
if (!timeout) {
|
||||
if (!timeout)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ERROR_OK != retval)
|
||||
return NULL;
|
||||
|
@ -1478,16 +1411,14 @@ static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length)
|
|||
int result;
|
||||
|
||||
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)",
|
||||
out_length, result);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
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)",
|
||||
in_length, result);
|
||||
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;
|
||||
|
||||
int result2 = ERROR_OK;
|
||||
if (result == in_length)
|
||||
{
|
||||
if (result == in_length) {
|
||||
/* Must read the result from the EMU too */
|
||||
result2 = jlink_usb_read_emu_result(jlink);
|
||||
if (1 != result2)
|
||||
{
|
||||
if (1 != result2) {
|
||||
LOG_ERROR("jlink_usb_read_emu_result retried requested = 1, "
|
||||
"result=%d, in_length=%i", result2, in_length);
|
||||
/* Try again once, should only happen if (in_length%64 == 0) */
|
||||
result2 = jlink_usb_read_emu_result(jlink);
|
||||
if (1 != result2)
|
||||
{
|
||||
if (1 != result2) {
|
||||
LOG_ERROR("jlink_usb_read_emu_result failed "
|
||||
"(requested = 1, result=%d)", result2);
|
||||
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 */
|
||||
result2 = usb_emu_result_buffer[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Save the result, then remove it from return value */
|
||||
result2 = usb_in_buffer[result--];
|
||||
}
|
||||
|
||||
if (result2)
|
||||
{
|
||||
if (result2) {
|
||||
LOG_ERROR("jlink_usb_message failed with result=%d)", result2);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -1542,8 +1467,7 @@ static int usb_bulk_with_retries(
|
|||
{
|
||||
int tries = 3, count = 0;
|
||||
|
||||
while (tries && (count < size))
|
||||
{
|
||||
while (tries && (count < size)) {
|
||||
int result = f(dev, ep, bytes + count, size - count, timeout);
|
||||
if (result > 0)
|
||||
count += result;
|
||||
|
@ -1554,7 +1478,7 @@ static int usb_bulk_with_retries(
|
|||
}
|
||||
|
||||
static int wrap_usb_bulk_write(jtag_libusb_device_handle *dev, int ep,
|
||||
char *buff, int size, int timeout)
|
||||
char *buff, int size, int timeout)
|
||||
{
|
||||
/* usb_bulk_write() takes const char *buff */
|
||||
return jtag_libusb_bulk_write(dev, ep, buff, size, timeout);
|
||||
|
@ -1579,8 +1503,7 @@ static int jlink_usb_write(struct jlink *jlink, int out_length)
|
|||
{
|
||||
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)",
|
||||
out_length, JLINK_OUT_BUFFER_SIZE);
|
||||
return -1;
|
||||
|
@ -1631,11 +1554,9 @@ static void jlink_debug_buffer(uint8_t *buffer, int length)
|
|||
int i;
|
||||
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);
|
||||
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]);
|
||||
strcat(line, s);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
|
|||
struct usb_bus *busses = usb_get_busses();
|
||||
for (struct usb_bus *bus = busses; bus; bus = bus->next) {
|
||||
for (struct usb_device *dev = bus->devices;
|
||||
dev; dev = dev->next) {
|
||||
dev; dev = dev->next) {
|
||||
if (!jtag_libusb_match(dev, vids, pids))
|
||||
continue;
|
||||
|
||||
|
@ -68,19 +68,19 @@ void jtag_libusb_close(jtag_libusb_device_handle *dev)
|
|||
}
|
||||
|
||||
int jtag_libusb_bulk_write(jtag_libusb_device_handle *dev, int ep, char *bytes,
|
||||
int size, int timeout)
|
||||
int size, int timeout)
|
||||
{
|
||||
return usb_bulk_write(dev, ep, bytes, size, timeout);
|
||||
}
|
||||
|
||||
int jtag_libusb_bulk_read(jtag_libusb_device_handle *dev, int ep, char *bytes,
|
||||
int size, int timeout)
|
||||
int size, int timeout)
|
||||
{
|
||||
return usb_bulk_read(dev, ep, bytes, size, timeout);
|
||||
}
|
||||
|
||||
int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
|
||||
int configuration)
|
||||
int configuration)
|
||||
{
|
||||
struct jtag_libusb_device *udev = jtag_libusb_get_device(devh);
|
||||
|
||||
|
@ -89,8 +89,8 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
|
|||
}
|
||||
|
||||
int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep)
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep)
|
||||
{
|
||||
struct usb_interface *iface = udev->config->interface;
|
||||
struct usb_interface_descriptor *desc = iface->altsetting;
|
||||
|
|
|
@ -43,16 +43,16 @@ static inline int jtag_libusb_claim_interface(jtag_libusb_device_handle *devh,
|
|||
};
|
||||
|
||||
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
|
||||
struct jtag_libusb_device_handle **out);
|
||||
struct jtag_libusb_device_handle **out);
|
||||
void jtag_libusb_close(jtag_libusb_device_handle *dev);
|
||||
int jtag_libusb_bulk_write(struct jtag_libusb_device_handle *dev, int ep,
|
||||
char *bytes, int size, int timeout);
|
||||
char *bytes, int size, int timeout);
|
||||
int jtag_libusb_bulk_read(struct jtag_libusb_device_handle *dev, int ep,
|
||||
char *bytes, int size, int timeout);
|
||||
char *bytes, int size, int timeout);
|
||||
int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
|
||||
int configuration);
|
||||
int configuration);
|
||||
int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep);
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep);
|
||||
|
||||
#endif /* JTAG_USB_COMMON_H */
|
||||
|
|
|
@ -80,7 +80,7 @@ void jtag_libusb_close(jtag_libusb_device_handle *dev)
|
|||
}
|
||||
|
||||
int jtag_libusb_bulk_write(jtag_libusb_device_handle *dev, int ep, char *bytes,
|
||||
int size, int timeout)
|
||||
int size, int timeout)
|
||||
{
|
||||
int transferred = 0;
|
||||
|
||||
|
@ -90,7 +90,7 @@ int jtag_libusb_bulk_write(jtag_libusb_device_handle *dev, int ep, char *bytes,
|
|||
}
|
||||
|
||||
int jtag_libusb_bulk_read(jtag_libusb_device_handle *dev, int ep, char *bytes,
|
||||
int size, int timeout)
|
||||
int size, int timeout)
|
||||
{
|
||||
int transferred = 0;
|
||||
|
||||
|
@ -100,7 +100,7 @@ int jtag_libusb_bulk_read(jtag_libusb_device_handle *dev, int ep, char *bytes,
|
|||
}
|
||||
|
||||
int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
|
||||
int configuration)
|
||||
int configuration)
|
||||
{
|
||||
struct jtag_libusb_device *udev = jtag_libusb_get_device(devh);
|
||||
int retCode = -99;
|
||||
|
@ -116,8 +116,8 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
|
|||
}
|
||||
|
||||
int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep)
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep)
|
||||
{
|
||||
const struct libusb_interface *inter;
|
||||
const struct libusb_interface_descriptor *interdesc;
|
||||
|
|
|
@ -37,22 +37,22 @@
|
|||
#define jtag_libusb_get_device(devh) libusb_get_device(devh)
|
||||
|
||||
static inline int jtag_libusb_claim_interface(jtag_libusb_device_handle *devh,
|
||||
int iface)
|
||||
int iface)
|
||||
{
|
||||
return libusb_claim_interface(devh, iface);
|
||||
};
|
||||
|
||||
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
|
||||
struct jtag_libusb_device_handle **out);
|
||||
struct jtag_libusb_device_handle **out);
|
||||
void jtag_libusb_close(jtag_libusb_device_handle *dev);
|
||||
int jtag_libusb_bulk_write(struct jtag_libusb_device_handle *dev, int ep,
|
||||
char *bytes, int size, int timeout);
|
||||
char *bytes, int size, int timeout);
|
||||
int jtag_libusb_bulk_read(struct jtag_libusb_device_handle *dev, int ep,
|
||||
char *bytes, int size, int timeout);
|
||||
char *bytes, int size, int timeout);
|
||||
int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
|
||||
int configuration);
|
||||
int configuration);
|
||||
int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep);
|
||||
unsigned int *usb_read_ep,
|
||||
unsigned int *usb_write_ep);
|
||||
|
||||
#endif /* JTAG_USB_COMMON_H */
|
||||
|
|
|
@ -29,23 +29,23 @@ static inline void interface_jtag_add_scan_check_alloc(struct scan_field *field)
|
|||
field->in_value = (uint8_t *)cmd_queue_alloc(num_bytes);
|
||||
}
|
||||
|
||||
void interface_jtag_add_dr_out(struct jtag_tap* tap,
|
||||
int num_fields, const int* num_bits, const uint32_t* value,
|
||||
tap_state_t end_state);
|
||||
void interface_jtag_add_dr_out(struct jtag_tap *tap,
|
||||
int num_fields, const int *num_bits, const uint32_t *value,
|
||||
tap_state_t end_state);
|
||||
|
||||
void interface_jtag_add_callback(jtag_callback1_t f, jtag_callback_data_t data0);
|
||||
|
||||
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 data3);
|
||||
jtag_callback_data_t data1, jtag_callback_data_t data2,
|
||||
jtag_callback_data_t data3);
|
||||
|
||||
void jtag_add_dr_out(struct jtag_tap* tap,
|
||||
int num_fields, const int* num_bits, const uint32_t* value,
|
||||
tap_state_t end_state);
|
||||
void jtag_add_dr_out(struct jtag_tap *tap,
|
||||
int num_fields, const int *num_bits, const uint32_t *value,
|
||||
tap_state_t end_state);
|
||||
|
||||
|
||||
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 data3);
|
||||
jtag_callback_data_t data1, jtag_callback_data_t data2,
|
||||
jtag_callback_data_t data3);
|
||||
|
||||
#endif // MINIDRIVER_IMP_H
|
||||
#endif /* MINIDRIVER_IMP_H */
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -31,8 +32,8 @@
|
|||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#define ioperm(startport,length,enable)\
|
||||
i386_set_ioperm((startport), (length), (enable))
|
||||
#define ioperm(startport, length, enable)\
|
||||
i386_set_ioperm((startport), (length), (enable))
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
|
@ -56,11 +57,10 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* parallel port cable description
|
||||
*/
|
||||
struct cable {
|
||||
char* name;
|
||||
char *name;
|
||||
uint8_t TDO_MASK; /* status port bit containing current TDO value */
|
||||
uint8_t TRST_MASK; /* data port bit for TRST */
|
||||
uint8_t TMS_MASK; /* data port bit for TMS */
|
||||
|
@ -74,8 +74,7 @@ struct cable {
|
|||
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 */
|
||||
{ "wiggler", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x80, 0x00 },
|
||||
{ "wiggler2", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x00, 0x20 },
|
||||
|
@ -83,8 +82,8 @@ static struct cable cables[] =
|
|||
{ "old_amt_wiggler", 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x11, 0x80, 0x80, 0x80, 0x00 },
|
||||
{ "arm-jtag", 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x01, 0x80, 0x80, 0x80, 0x00 },
|
||||
{ "chameleon", 0x80, 0x00, 0x04, 0x01, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 },
|
||||
{ "dlc5", 0x10, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00 },
|
||||
{ "triton", 0x80, 0x08, 0x04, 0x01, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 },
|
||||
{ "dlc5", 0x10, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00 },
|
||||
{ "triton", 0x80, 0x08, 0x04, 0x01, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 },
|
||||
{ "lattice", 0x40, 0x10, 0x04, 0x02, 0x01, 0x08, 0x00, 0x00, 0x18, 0x18, 0x00 },
|
||||
{ "flashlink", 0x20, 0x10, 0x02, 0x01, 0x04, 0x20, 0x30, 0x20, 0x00, 0x00, 0x00 },
|
||||
/* Altium Universal JTAG cable. Set the cable to Xilinx Mode and wire to target as follows:
|
||||
|
@ -100,16 +99,16 @@ static struct cable cables[] =
|
|||
};
|
||||
|
||||
/* configuration */
|
||||
static char* parport_cable = NULL;
|
||||
static char *parport_cable;
|
||||
static uint16_t parport_port;
|
||||
static bool parport_exit = 0;
|
||||
static bool parport_exit;
|
||||
static uint32_t parport_toggling_time_ns = 1000;
|
||||
static int wait_states;
|
||||
|
||||
/* interface variables
|
||||
*/
|
||||
static struct cable* cable;
|
||||
static uint8_t dataport_value = 0x0;
|
||||
static struct cable *cable;
|
||||
static uint8_t dataport_value;
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
static int device_handle;
|
||||
|
@ -123,7 +122,7 @@ static int parport_read(void)
|
|||
int data = 0;
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
ioctl(device_handle, PPRSTATUS, & data);
|
||||
ioctl(device_handle, PPRSTATUS, &data);
|
||||
#else
|
||||
data = inb(statusport);
|
||||
#endif
|
||||
|
@ -134,7 +133,7 @@ static int parport_read(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static __inline__ void parport_write_data(void)
|
||||
static inline void parport_write_data(void)
|
||||
{
|
||||
uint8_t output;
|
||||
output = dataport_value ^ cable->OUTPUT_INVERT;
|
||||
|
@ -208,7 +207,7 @@ static int parport_speed(int speed)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static int parport_khz(int khz, int* jtag_speed)
|
||||
static int parport_khz(int khz, int *jtag_speed)
|
||||
{
|
||||
if (khz == 0) {
|
||||
LOG_DEBUG("RCLK not supported");
|
||||
|
@ -219,7 +218,7 @@ static int parport_khz(int khz, int* jtag_speed)
|
|||
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;
|
||||
|
||||
|
@ -269,24 +268,20 @@ static int parport_init(void)
|
|||
|
||||
cur_cable = cables;
|
||||
|
||||
if ((parport_cable == NULL) || (parport_cable[0] == 0))
|
||||
{
|
||||
if ((parport_cable == NULL) || (parport_cable[0] == 0)) {
|
||||
parport_cable = "wiggler";
|
||||
LOG_WARNING("No parport cable specified, using default 'wiggler'");
|
||||
}
|
||||
|
||||
while (cur_cable->name)
|
||||
{
|
||||
if (strcmp(cur_cable->name, parport_cable) == 0)
|
||||
{
|
||||
while (cur_cable->name) {
|
||||
if (strcmp(cur_cable->name, parport_cable) == 0) {
|
||||
cable = cur_cable;
|
||||
break;
|
||||
}
|
||||
cur_cable++;
|
||||
}
|
||||
|
||||
if (!cable)
|
||||
{
|
||||
if (!cable) {
|
||||
LOG_ERROR("No matching cable found for %s", parport_cable);
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -294,8 +289,7 @@ static int parport_init(void)
|
|||
dataport_value = cable->PORT_INIT;
|
||||
|
||||
#if PARPORT_USE_PPDEV == 1
|
||||
if (device_handle > 0)
|
||||
{
|
||||
if (device_handle > 0) {
|
||||
LOG_ERROR("device is already opened");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -312,8 +306,7 @@ static int parport_init(void)
|
|||
device_handle = open(buffer, O_WRONLY);
|
||||
#endif /* __FreeBSD__, __FreeBSD_kernel__ */
|
||||
|
||||
if (device_handle < 0)
|
||||
{
|
||||
if (device_handle < 0) {
|
||||
int err = errno;
|
||||
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;
|
||||
|
@ -324,32 +317,28 @@ static int parport_init(void)
|
|||
#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
|
||||
int i = ioctl(device_handle, PPCLAIM);
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
if (i < 0) {
|
||||
LOG_ERROR("cannot claim device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
i = PARPORT_MODE_COMPAT;
|
||||
i= ioctl(device_handle, PPSETMODE, & i);
|
||||
if (i < 0)
|
||||
{
|
||||
i = ioctl(device_handle, PPSETMODE, &i);
|
||||
if (i < 0) {
|
||||
LOG_ERROR(" cannot set compatible mode to device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
i = IEEE1284_MODE_COMPAT;
|
||||
i = ioctl(device_handle, PPNEGOT, & i);
|
||||
if (i < 0)
|
||||
{
|
||||
i = ioctl(device_handle, PPNEGOT, &i);
|
||||
if (i < 0) {
|
||||
LOG_ERROR("cannot set compatible 1284 mode to device");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
#endif /* not __FreeBSD__, __FreeBSD_kernel__ */
|
||||
|
||||
#else /* not PARPORT_USE_PPDEV */
|
||||
if (parport_port == 0)
|
||||
{
|
||||
if (parport_port == 0) {
|
||||
parport_port = 0x378;
|
||||
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);
|
||||
#if PARPORT_USE_GIVEIO == 1
|
||||
if (parport_get_giveio_access() != 0)
|
||||
if (parport_get_giveio_access() != 0) {
|
||||
#else /* PARPORT_USE_GIVEIO */
|
||||
if (ioperm(dataport, 3, 1) != 0)
|
||||
if (ioperm(dataport, 3, 1) != 0) {
|
||||
#endif /* PARPORT_USE_GIVEIO */
|
||||
{
|
||||
LOG_ERROR("missing privileges for direct i/o");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -391,14 +379,12 @@ static int parport_quit(void)
|
|||
{
|
||||
parport_led(0);
|
||||
|
||||
if (parport_exit)
|
||||
{
|
||||
if (parport_exit) {
|
||||
dataport_value = cable->PORT_EXIT;
|
||||
parport_write_data();
|
||||
}
|
||||
|
||||
if (parport_cable)
|
||||
{
|
||||
if (parport_cable) {
|
||||
free(parport_cable);
|
||||
parport_cable = NULL;
|
||||
}
|
||||
|
@ -408,15 +394,11 @@ static int parport_quit(void)
|
|||
|
||||
COMMAND_HANDLER(parport_handle_parport_port_command)
|
||||
{
|
||||
if (CMD_ARGC == 1)
|
||||
{
|
||||
if (CMD_ARGC == 1) {
|
||||
/* only if the port wasn't overwritten by cmdline */
|
||||
if (parport_port == 0)
|
||||
{
|
||||
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], parport_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("The parport port was already configured!");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -433,8 +415,7 @@ COMMAND_HANDLER(parport_handle_parport_cable_command)
|
|||
return ERROR_OK;
|
||||
|
||||
/* 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[] ... */
|
||||
parport_cable = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
|
||||
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)
|
||||
{
|
||||
if (CMD_ARGC != 1)
|
||||
{
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
COMMAND_PARSE_ON_OFF(CMD_ARGV[0], parport_exit);
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include <helper/time_support.h>
|
||||
#include "bitq.h"
|
||||
|
||||
|
||||
/* PRESTO access library includes */
|
||||
#if BUILD_PRESTO_FTD2XX == 1
|
||||
#include <ftd2xx.h>
|
||||
|
@ -72,16 +71,16 @@ struct presto {
|
|||
int buff_out_pos;
|
||||
|
||||
uint8_t buff_in[BUFFER_SIZE];
|
||||
int buff_in_exp; /* expected in buffer length */
|
||||
int buff_in_len; /* length of data received */
|
||||
int buff_in_exp;/* expected in buffer length */
|
||||
int buff_in_len;/* length of data received */
|
||||
int buff_in_pos;
|
||||
|
||||
unsigned long total_out;
|
||||
unsigned long total_in;
|
||||
|
||||
int jtag_tms; /* last tms state */
|
||||
int jtag_tck; /* last tck state */
|
||||
int jtag_rst; /* last trst state */
|
||||
int jtag_tms; /* last tms state */
|
||||
int jtag_tck; /* last tck state */
|
||||
int jtag_rst; /* last trst state */
|
||||
|
||||
int jtag_tdi_data;
|
||||
int jtag_tdi_count;
|
||||
|
@ -92,8 +91,7 @@ struct presto {
|
|||
static struct 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
|
||||
};
|
||||
|
||||
|
@ -101,38 +99,37 @@ static int presto_write(uint8_t *buf, uint32_t size)
|
|||
{
|
||||
#if BUILD_PRESTO_FTD2XX == 1
|
||||
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));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
#elif BUILD_PRESTO_LIBFTDI == 1
|
||||
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));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
ftbytes = presto->retval;
|
||||
#endif
|
||||
|
||||
if (ftbytes != size)
|
||||
{
|
||||
if (ftbytes != size) {
|
||||
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_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
|
||||
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));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -142,28 +139,28 @@ static int presto_read(uint8_t* buf, uint32_t size)
|
|||
|
||||
struct timeval timeout, now;
|
||||
gettimeofday(&timeout, NULL);
|
||||
timeval_add_time(&timeout, 1, 0); /* one second timeout */
|
||||
timeval_add_time(&timeout, 1, 0); /* one second timeout */
|
||||
|
||||
while (ftbytes < size)
|
||||
{
|
||||
if ((presto->retval = ftdi_read_data(&presto->ftdic, buf + ftbytes, size - ftbytes)) < 0)
|
||||
{
|
||||
while (ftbytes < size) {
|
||||
presto->retval = ftdi_read_data(&presto->ftdic, buf + ftbytes, size - ftbytes);
|
||||
if (presto->retval < 0) {
|
||||
LOG_ERROR("ftdi_read_data: %s", ftdi_get_error_string(&presto->ftdic));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
ftbytes += presto->retval;
|
||||
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ftbytes != size)
|
||||
{
|
||||
/* this is just a warning, there might have been timeout when detecting PRESTO, which is not fatal */
|
||||
if (ftbytes != size) {
|
||||
/* this is just a warning, there might have been timeout when detecting PRESTO,
|
||||
*which is not fatal */
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -186,39 +183,39 @@ static int presto_open_ftd2xx(char *req_serial)
|
|||
|
||||
#if IS_WIN32 == 0
|
||||
/* 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");
|
||||
exit(-1);
|
||||
}
|
||||
#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));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
LOG_DEBUG("FTDI devices available: %" PRIu32, (uint32_t)numdevs);
|
||||
for (i = 0; i < numdevs; i++)
|
||||
{
|
||||
if ((presto->status = FT_Open(i, &(presto->handle))) != FT_OK)
|
||||
{
|
||||
/* this is not fatal, the device may be legitimately open by other process, hence debug message only */
|
||||
for (i = 0; i < numdevs; i++) {
|
||||
presto->status = FT_Open(i, &(presto->handle));
|
||||
if (presto->status != FT_OK) {
|
||||
/* this is not fatal, the device may be legitimately open by other process,
|
||||
*hence debug message only */
|
||||
LOG_DEBUG("FT_Open failed: %s", ftd2xx_status_string(presto->status));
|
||||
continue;
|
||||
}
|
||||
LOG_DEBUG("FTDI device %i open", (int)i);
|
||||
|
||||
if ((presto->status = FT_GetDeviceInfo(presto->handle, &device, &vidpid,
|
||||
presto->serial, devname, NULL)) == FT_OK)
|
||||
{
|
||||
if (vidpid == PRESTO_VID_PID
|
||||
&& (req_serial == NULL || !strcmp(presto->serial, req_serial)))
|
||||
presto->status = FT_GetDeviceInfo(presto->handle, &device,
|
||||
&vidpid, presto->serial, devname, NULL);
|
||||
if (presto->status == FT_OK) {
|
||||
if (vidpid == PRESTO_VID_PID && (req_serial == NULL ||
|
||||
!strcmp(presto->serial, req_serial)))
|
||||
break;
|
||||
}
|
||||
else
|
||||
LOG_DEBUG("FT_GetDeviceInfo failed: %s", ftd2xx_status_string(presto->status));
|
||||
} else
|
||||
LOG_DEBUG("FT_GetDeviceInfo failed: %s", ftd2xx_status_string(
|
||||
presto->status));
|
||||
|
||||
LOG_DEBUG("FTDI device %i does not match, closing", (int)i);
|
||||
FT_Close(presto->handle);
|
||||
|
@ -226,74 +223,87 @@ static int presto_open_ftd2xx(char *req_serial)
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
if ((presto->status = FT_SetTimeouts(presto->handle, 100, 0)) != FT_OK)
|
||||
presto->status = FT_SetTimeouts(presto->handle, 100, 0);
|
||||
if (presto->status != FT_OK)
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
/* delay between first write/read turnaround (after purge?) necessary under Linux for unknown reason,
|
||||
probably a bug in library threading */
|
||||
/* delay between first write/read turnaround (after purge?) necessary
|
||||
* under Linux for unknown reason,
|
||||
* probably a bug in library threading */
|
||||
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;
|
||||
|
||||
if (ftbytes != 1)
|
||||
{
|
||||
if (ftbytes != 1) {
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
|
||||
presto_data = 0;
|
||||
for (i = 0; i < 4 * 62; i++)
|
||||
if ((presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes)) != FT_OK)
|
||||
for (i = 0; i < 4 * 62; i++) {
|
||||
presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
|
||||
if (presto->status != FT_OK)
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
/* delay between first write/read turnaround (after purge?) necessary under Linux for unknown reason,
|
||||
probably a bug in library threading */
|
||||
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;
|
||||
|
||||
if (ftbytes != 1)
|
||||
{
|
||||
if (ftbytes != 1) {
|
||||
LOG_DEBUG("PRESTO not responding");
|
||||
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;
|
||||
|
||||
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))
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
|
||||
|
@ -308,46 +318,39 @@ static int presto_open_libftdi(char *req_serial)
|
|||
LOG_DEBUG("searching for PRESTO using libftdi");
|
||||
|
||||
/* 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);
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
|
||||
if (ftdi_usb_purge_buffers(&presto->ftdic) < 0)
|
||||
|
@ -357,22 +360,20 @@ static int presto_open_libftdi(char *req_serial)
|
|||
if (presto_write(&presto_data, 1) != ERROR_OK)
|
||||
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");
|
||||
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");
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
#endif /* BUILD_PRESTO_LIBFTDI == 1 */
|
||||
#endif /* BUILD_PRESTO_LIBFTDI == 1 */
|
||||
|
||||
static int presto_open(char *req_serial)
|
||||
{
|
||||
|
@ -414,27 +415,35 @@ static int presto_close(void)
|
|||
if (presto->status != FT_OK)
|
||||
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))
|
||||
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;
|
||||
|
||||
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;
|
||||
else
|
||||
presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE;
|
||||
|
||||
#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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
else
|
||||
ftdi_deinit(&presto->ftdic);
|
||||
|
@ -449,17 +458,15 @@ static int presto_flush(void)
|
|||
return ERROR_OK;
|
||||
|
||||
#if BUILD_PRESTO_FTD2XX == 1
|
||||
if (presto->status != FT_OK)
|
||||
if (presto->status != FT_OK) {
|
||||
#elif BUILD_PRESTO_LIBFTDI == 1
|
||||
if (presto->retval < 0)
|
||||
if (presto->retval < 0) {
|
||||
#endif
|
||||
{
|
||||
LOG_DEBUG("error in previous communication, canceling I/O operation");
|
||||
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;
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -473,8 +480,7 @@ static int presto_flush(void)
|
|||
presto->buff_in_pos = 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;
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -488,21 +494,21 @@ static int presto_flush(void)
|
|||
|
||||
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;
|
||||
if (((data & 0xC0) == 0x40) || ((data & 0xD0)== 0xD0))
|
||||
if (((data & 0xC0) == 0x40) || ((data & 0xD0) == 0xD0))
|
||||
presto->buff_in_exp++;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
|
||||
#if BUILD_PRESTO_FTD2XX == 1
|
||||
if (presto->buff_out_pos >= BUFFER_SIZE)
|
||||
#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)
|
||||
#endif
|
||||
return presto_flush();
|
||||
|
@ -536,8 +542,7 @@ static int presto_tdi_flush(void)
|
|||
if (presto->jtag_tdi_count == 0)
|
||||
return 0;
|
||||
|
||||
if (presto->jtag_tck == 0)
|
||||
{
|
||||
if (presto->jtag_tck == 0) {
|
||||
LOG_ERROR("BUG: unexpected TAP condition, TCK low");
|
||||
return -1;
|
||||
}
|
||||
|
@ -552,8 +557,7 @@ static int presto_tdi_flush(void)
|
|||
|
||||
static int presto_tck_idle(void)
|
||||
{
|
||||
if (presto->jtag_tck == 1)
|
||||
{
|
||||
if (presto->jtag_tck == 1) {
|
||||
presto_sendbyte(0xCA);
|
||||
presto->jtag_tck = 0;
|
||||
}
|
||||
|
@ -569,11 +573,8 @@ static int presto_bitq_out(int tms, int tdi, int tdo_req)
|
|||
unsigned char cmd;
|
||||
|
||||
if (presto->jtag_tck == 0)
|
||||
{
|
||||
presto_sendbyte(0xA4); /* LED idicator - JTAG active */
|
||||
}
|
||||
else if (presto->jtag_speed == 0 && !tdo_req && tms == presto->jtag_tms)
|
||||
{
|
||||
presto_sendbyte(0xA4); /* LED idicator - JTAG active */
|
||||
else if (presto->jtag_speed == 0 && !tdo_req && tms == presto->jtag_tms) {
|
||||
presto->jtag_tdi_data |= (tdi != 0) << presto->jtag_tdi_count;
|
||||
|
||||
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;
|
||||
presto_sendbyte(cmd);
|
||||
|
||||
if (tms != presto->jtag_tms)
|
||||
{
|
||||
if (tms != presto->jtag_tms) {
|
||||
presto_sendbyte((tms ? 0xEC : 0xE8) | (presto->jtag_rst ? 0x02 : 0));
|
||||
presto->jtag_tms = tms;
|
||||
}
|
||||
|
@ -614,7 +614,7 @@ static int presto_bitq_flush(void)
|
|||
presto_tdi_flush();
|
||||
presto_tck_idle();
|
||||
|
||||
presto_sendbyte(0xA0); /* LED idicator - JTAG idle */
|
||||
presto_sendbyte(0xA0); /* LED idicator - JTAG idle */
|
||||
|
||||
return presto_flush();
|
||||
}
|
||||
|
@ -630,7 +630,8 @@ static int presto_bitq_in(void)
|
|||
{
|
||||
if (presto->buff_in_pos >= presto->buff_in_len)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -641,8 +642,7 @@ static int presto_bitq_sleep(unsigned long us)
|
|||
presto_tdi_flush();
|
||||
presto_tck_idle();
|
||||
|
||||
if (us > 100000)
|
||||
{
|
||||
if (us > 100000) {
|
||||
presto_bitq_flush();
|
||||
jtag_sleep(us);
|
||||
return 0;
|
||||
|
@ -671,40 +671,42 @@ static int presto_bitq_reset(int trst, int srst)
|
|||
}
|
||||
|
||||
static struct bitq_interface presto_bitq = {
|
||||
.out = &presto_bitq_out,
|
||||
.flush = &presto_bitq_flush,
|
||||
.sleep = &presto_bitq_sleep,
|
||||
.reset = &presto_bitq_reset,
|
||||
.in_rdy = &presto_bitq_in_rdy,
|
||||
.in = &presto_bitq_in,
|
||||
};
|
||||
.out = &presto_bitq_out,
|
||||
.flush = &presto_bitq_flush,
|
||||
.sleep = &presto_bitq_sleep,
|
||||
.reset = &presto_bitq_reset,
|
||||
.in_rdy = &presto_bitq_in_rdy,
|
||||
.in = &presto_bitq_in,
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static int presto_adapter_khz(int khz, int *jtag_speed)
|
||||
{
|
||||
if (khz < 0)
|
||||
{
|
||||
if (khz < 0) {
|
||||
*jtag_speed = 0;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (khz >= 3000) *jtag_speed = 0;
|
||||
else *jtag_speed = (1000 + khz-1)/khz;
|
||||
if (khz >= 3000)
|
||||
*jtag_speed = 0;
|
||||
else
|
||||
*jtag_speed = (1000 + khz-1)/khz;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int presto_jtag_speed_div(int speed, int *khz)
|
||||
{
|
||||
if ((speed < 0) || (speed > 1000))
|
||||
{
|
||||
if ((speed < 0) || (speed > 1000)) {
|
||||
*khz = 0;
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (speed == 0) *khz = 3000;
|
||||
else *khz = 1000/speed;
|
||||
if (speed == 0)
|
||||
*khz = 3000;
|
||||
else
|
||||
*khz = 1000/speed;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -714,9 +716,7 @@ static int presto_jtag_speed(int speed)
|
|||
int khz;
|
||||
|
||||
if (presto_jtag_speed_div(speed, &khz))
|
||||
{
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
presto->jtag_speed = speed;
|
||||
|
||||
|
@ -732,16 +732,12 @@ static char *presto_serial;
|
|||
|
||||
COMMAND_HANDLER(presto_handle_serial_command)
|
||||
{
|
||||
if (CMD_ARGC == 1)
|
||||
{
|
||||
if (CMD_ARGC == 1) {
|
||||
if (presto_serial)
|
||||
free(presto_serial);
|
||||
presto_serial = strdup(CMD_ARGV[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
} else
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -759,8 +755,7 @@ static const struct command_registration presto_command_handlers[] = {
|
|||
|
||||
static int presto_jtag_init(void)
|
||||
{
|
||||
if (presto_open(presto_serial) != ERROR_OK)
|
||||
{
|
||||
if (presto_open(presto_serial) != ERROR_OK) {
|
||||
presto_close();
|
||||
if (presto_serial != NULL)
|
||||
LOG_ERROR("Cannot open PRESTO, serial number '%s'", presto_serial);
|
||||
|
@ -780,8 +775,7 @@ static int presto_jtag_quit(void)
|
|||
presto_close();
|
||||
LOG_INFO("PRESTO closed");
|
||||
|
||||
if (presto_serial)
|
||||
{
|
||||
if (presto_serial) {
|
||||
free(presto_serial);
|
||||
presto_serial = NULL;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -27,26 +28,29 @@
|
|||
#include <jtag/interface.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
|
||||
|
||||
// arbitrary limit on host name length:
|
||||
/* arbitrary limit on host name length: */
|
||||
#define REMOTE_BITBANG_HOST_MAX 255
|
||||
|
||||
#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 uint16_t remote_bitbang_port = 0;
|
||||
static uint16_t remote_bitbang_port;
|
||||
|
||||
FILE* remote_bitbang_in;
|
||||
FILE* remote_bitbang_out;
|
||||
FILE *remote_bitbang_in;
|
||||
FILE *remote_bitbang_out;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
static int remote_bitbang_quit(void)
|
||||
|
@ -60,9 +64,9 @@ static int remote_bitbang_quit(void)
|
|||
LOG_ERROR("fflush: %s", strerror(errno));
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
// We only need to close one of the FILE*s, because they both use the same
|
||||
// underlying file descriptor.
|
||||
|
||||
/* We only need to close one of the FILE*s, because they both use the same */
|
||||
/* underlying file descriptor. */
|
||||
if (EOF == fclose(remote_bitbang_out)) {
|
||||
LOG_ERROR("fclose: %s", strerror(errno));
|
||||
return ERROR_FAIL;
|
||||
|
@ -72,7 +76,7 @@ static int remote_bitbang_quit(void)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
// Get the next read response.
|
||||
/* Get the next read response. */
|
||||
static int remote_bitbang_rread(void)
|
||||
{
|
||||
if (EOF == fflush(remote_bitbang_out)) {
|
||||
|
@ -82,12 +86,14 @@ static int remote_bitbang_rread(void)
|
|||
|
||||
int c = fgetc(remote_bitbang_in);
|
||||
switch (c) {
|
||||
case '0': return 0;
|
||||
case '1': return 1;
|
||||
case '0':
|
||||
return 0;
|
||||
case '1':
|
||||
return 1;
|
||||
default:
|
||||
remote_bitbang_quit();
|
||||
REMOTE_BITBANG_RAISE_ERROR(
|
||||
"remote_bitbang: invalid read response: %c(%i)", c, c);
|
||||
"remote_bitbang: invalid read response: %c(%i)", c, c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,14 +142,22 @@ static int remote_bitbang_init_tcp(void)
|
|||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
struct hostent* hent = gethostbyname(remote_bitbang_host);
|
||||
struct hostent *hent = gethostbyname(remote_bitbang_host);
|
||||
if (hent == NULL) {
|
||||
char* errorstr = "???";
|
||||
char *errorstr = "???";
|
||||
switch (h_errno) {
|
||||
case HOST_NOT_FOUND: errorstr = "host not found"; break;
|
||||
case NO_ADDRESS: errorstr = "no address"; break;
|
||||
case NO_RECOVERY: errorstr = "no recovery"; break;
|
||||
case TRY_AGAIN: errorstr = "try again"; break;
|
||||
case HOST_NOT_FOUND:
|
||||
errorstr = "host not found";
|
||||
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);
|
||||
return ERROR_FAIL;
|
||||
|
@ -152,8 +166,8 @@ static int remote_bitbang_init_tcp(void)
|
|||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(remote_bitbang_port);
|
||||
addr.sin_addr = *(struct in_addr*)hent->h_addr;
|
||||
if (connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) < 0) {
|
||||
addr.sin_addr = *(struct in_addr *)hent->h_addr;
|
||||
if (connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
|
||||
LOG_ERROR("connect: %s", strerror(errno));
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -188,7 +202,7 @@ static int remote_bitbang_init_unix(void)
|
|||
strncpy(addr.sun_path, remote_bitbang_host, UNIX_PATH_MAX);
|
||||
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));
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -214,21 +228,20 @@ static int remote_bitbang_init(void)
|
|||
bitbang_interface = &remote_bitbang_bitbang;
|
||||
|
||||
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_tcp();
|
||||
}
|
||||
|
||||
static int remote_bitbang_khz(int khz, int* jtag_speed)
|
||||
static int remote_bitbang_khz(int khz, int *jtag_speed)
|
||||
{
|
||||
*jtag_speed = 0;
|
||||
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;
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,7 +18,8 @@
|
|||
* 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))
|
||||
/* Shift 1-16 bytes out TMS. TDI is 0. */
|
||||
|
@ -46,10 +47,15 @@
|
|||
) | (\
|
||||
(tdo) ? (1 << 3) : 0 \
|
||||
))
|
||||
/* Single bit shift. */
|
||||
/* 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 */
|
||||
/* 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. */
|
||||
/* Single bit shift.
|
||||
* 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
|
||||
* 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))
|
||||
/* Shift 1-8 bits out TMS. */
|
||||
|
@ -60,7 +66,8 @@
|
|||
/* 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. */
|
||||
|
||||
|
||||
#define DTC_CMD_STOP (0xf << 4)
|
||||
/* 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. */
|
||||
|
|
|
@ -95,7 +95,7 @@ const struct rlink_speed_table rlink_speed_table[] = {{
|
|||
dtc_8, sizeof(dtc_8), (ST7_FOSC * 2) / (1000 * 8), 8
|
||||
}, {
|
||||
dtc_2, sizeof(dtc_2), (ST7_FOSC * 2) / (1000 * 2), 2
|
||||
}};
|
||||
} };
|
||||
|
||||
const size_t rlink_speed_table_size = ARRAY_SIZE(rlink_speed_table);
|
||||
|
||||
|
|
|
@ -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_
|
||||
#define _STLINK_USB_H_
|
||||
|
||||
/** */
|
||||
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
|
@ -89,7 +89,7 @@
|
|||
|
||||
#if (BUILD_USB_BLASTER_FTD2XX == 1 && BUILD_USB_BLASTER_LIBFTDI == 1)
|
||||
#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)
|
||||
#error "BUILD_USB_BLASTER_FTD2XX || BUILD_USB_BLASTER_LIBFTDI must be chosen"
|
||||
#endif
|
||||
|
@ -106,15 +106,15 @@
|
|||
#include <time.h>
|
||||
|
||||
static char *usb_blaster_device_desc;
|
||||
static uint16_t usb_blaster_vid = 0x09fb; /* Altera */
|
||||
static uint16_t usb_blaster_pid = 0x6001; /* USB-Blaster */
|
||||
static uint16_t usb_blaster_vid = 0x09fb; /* Altera */
|
||||
static uint16_t usb_blaster_pid = 0x6001; /* USB-Blaster */
|
||||
|
||||
/* last output byte in simple bit banging (legacy) mode */
|
||||
static uint8_t out_value;
|
||||
/* 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 uint16_t out_count = 0;
|
||||
static uint16_t out_count;
|
||||
|
||||
#if BUILD_USB_BLASTER_FTD2XX == 1
|
||||
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);
|
||||
#endif
|
||||
status = FT_Write(ftdih, buf, size, &dw_bytes_written);
|
||||
if (status != FT_OK)
|
||||
{
|
||||
if (status != FT_OK) {
|
||||
*bytes_written = dw_bytes_written;
|
||||
LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(status));
|
||||
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);
|
||||
#endif
|
||||
retval = ftdi_write_data(&ftdic, buf, size);
|
||||
if (retval < 0)
|
||||
{
|
||||
if (retval < 0) {
|
||||
*bytes_written = 0;
|
||||
LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&ftdic));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
|
@ -158,16 +156,14 @@ static int usb_blaster_buf_write(
|
|||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
|
||||
static int usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
|
||||
{
|
||||
#if BUILD_USB_BLASTER_FTD2XX == 1
|
||||
DWORD dw_bytes_read;
|
||||
FT_STATUS status;
|
||||
|
||||
status = FT_Read(ftdih, buf, size, &dw_bytes_read);
|
||||
if (status != FT_OK)
|
||||
{
|
||||
if (status != FT_OK) {
|
||||
*bytes_read = dw_bytes_read;
|
||||
LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(status));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
|
@ -183,15 +179,13 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
|
|||
int timeout = 100;
|
||||
|
||||
*bytes_read = 0;
|
||||
while ((*bytes_read < size) && timeout--)
|
||||
{
|
||||
while ((*bytes_read < size) && timeout--) {
|
||||
retval = ftdi_read_data(&ftdic, buf + *bytes_read,
|
||||
size - *bytes_read);
|
||||
if (retval < 0)
|
||||
{
|
||||
if (retval < 0) {
|
||||
*bytes_read = 0;
|
||||
LOG_ERROR("ftdi_read_data: %s",
|
||||
ftdi_get_error_string(&ftdic));
|
||||
ftdi_get_error_string(&ftdic));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
}
|
||||
*bytes_read += retval;
|
||||
|
@ -249,13 +243,13 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
|
|||
|
||||
#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;
|
||||
usb_blaster_buf_write(buf, len, &bytes_written);
|
||||
out_count = 0;
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("---- WROTE %d",bytes_written);
|
||||
LOG_DEBUG("---- WROTE %d", bytes_written);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -263,7 +257,7 @@ static void usb_blaster_addtowritebuffer(uint8_t value, bool forcewrite)
|
|||
{
|
||||
out_buffer[out_count] = value;
|
||||
out_count += 1;
|
||||
if(out_count == BUF_LEN || forcewrite)
|
||||
if (out_count == BUF_LEN || forcewrite)
|
||||
usb_blaster_write_databuffer(out_buffer, out_count);
|
||||
}
|
||||
|
||||
|
@ -273,7 +267,7 @@ static int usb_blaster_read_data(void)
|
|||
uint8_t buf[1];
|
||||
uint32_t bytes_read;
|
||||
|
||||
if(out_count > 0)
|
||||
if (out_count > 0)
|
||||
usb_blaster_write_databuffer(out_buffer, out_count);
|
||||
|
||||
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
|
||||
* 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",
|
||||
ftdi_get_error_string(&ftdic));
|
||||
return ERROR_JTAG_DEVICE_ERROR;
|
||||
};
|
||||
}
|
||||
;
|
||||
#endif
|
||||
|
||||
return ERROR_OK;
|
||||
|
@ -327,13 +321,13 @@ static int usb_blaster_speed(int speed)
|
|||
static void usb_blaster_reset(int trst, int srst)
|
||||
{
|
||||
LOG_DEBUG("TODO: usb_blaster_reset(%d,%d) isn't implemented!",
|
||||
trst, srst);
|
||||
trst, srst);
|
||||
}
|
||||
|
||||
static void usb_blaster_blink(int state)
|
||||
{
|
||||
out_value = 0x00;
|
||||
if(state)
|
||||
if (state)
|
||||
out_value |= LED;
|
||||
|
||||
usb_blaster_addtowritebuffer(out_value, true);
|
||||
|
@ -362,18 +356,16 @@ static int usb_blaster_init(void)
|
|||
|
||||
#if BUILD_USB_BLASTER_FTD2XX == 1
|
||||
/* Open by device description */
|
||||
if (usb_blaster_device_desc == NULL)
|
||||
{
|
||||
if (usb_blaster_device_desc == NULL) {
|
||||
LOG_WARNING("no usb_blaster device description specified, "
|
||||
"using default 'USB-Blaster'");
|
||||
"using default 'USB-Blaster'");
|
||||
usb_blaster_device_desc = "USB-Blaster";
|
||||
}
|
||||
|
||||
#if IS_WIN32 == 0
|
||||
/* Add non-standard Vid/Pid to the linux driver */
|
||||
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",
|
||||
usb_blaster_vid, usb_blaster_pid);
|
||||
}
|
||||
|
@ -381,18 +373,16 @@ static int usb_blaster_init(void)
|
|||
|
||||
status = FT_OpenEx(usb_blaster_device_desc, FT_OPEN_BY_DESCRIPTION,
|
||||
&ftdih);
|
||||
if (status != FT_OK)
|
||||
{
|
||||
if (status != FT_OK) {
|
||||
DWORD num_devices;
|
||||
|
||||
LOG_ERROR("unable to open ftdi device: %s",
|
||||
ftd2xx_status_string(status));
|
||||
ftd2xx_status_string(status));
|
||||
status = FT_ListDevices(&num_devices, NULL,
|
||||
FT_LIST_NUMBER_ONLY);
|
||||
if (status == FT_OK)
|
||||
{
|
||||
if (status == FT_OK) {
|
||||
char **desc_array = malloc(sizeof(char *)
|
||||
* (num_devices + 1));
|
||||
* (num_devices + 1));
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < num_devices; i++)
|
||||
|
@ -400,10 +390,9 @@ static int usb_blaster_init(void)
|
|||
desc_array[num_devices] = NULL;
|
||||
|
||||
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);
|
||||
for (i = 0; i < num_devices; i++)
|
||||
LOG_ERROR("%i: %s", i, desc_array[i]);
|
||||
|
@ -412,36 +401,30 @@ static int usb_blaster_init(void)
|
|||
for (i = 0; i < num_devices; i++)
|
||||
free(desc_array[i]);
|
||||
free(desc_array);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
printf("ListDevices: NONE\n");
|
||||
}
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
status = FT_SetLatencyTimer(ftdih, 2);
|
||||
if (status != FT_OK)
|
||||
{
|
||||
if (status != FT_OK) {
|
||||
LOG_ERROR("unable to set latency timer: %s",
|
||||
ftd2xx_status_string(status));
|
||||
ftd2xx_status_string(status));
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
status = FT_GetLatencyTimer(ftdih, &latency_timer);
|
||||
if (status != FT_OK)
|
||||
{
|
||||
if (status != FT_OK) {
|
||||
LOG_ERROR("unable to get latency timer: %s",
|
||||
ftd2xx_status_string(status));
|
||||
ftd2xx_status_string(status));
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
LOG_DEBUG("current latency timer: %i", latency_timer);
|
||||
|
||||
status = FT_SetBitMode(ftdih, 0x00, 0);
|
||||
if (status != FT_OK)
|
||||
{
|
||||
if (status != FT_OK) {
|
||||
LOG_ERROR("unable to disable bit i/o mode: %s",
|
||||
ftd2xx_status_string(status));
|
||||
ftd2xx_status_string(status));
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
#elif BUILD_USB_BLASTER_LIBFTDI == 1
|
||||
|
@ -449,26 +432,22 @@ static int usb_blaster_init(void)
|
|||
return ERROR_JTAG_INIT_FAILED;
|
||||
|
||||
/* 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);
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
||||
if (ftdi_usb_reset(&ftdic) < 0)
|
||||
{
|
||||
if (ftdi_usb_reset(&ftdic) < 0) {
|
||||
LOG_ERROR("unable to reset ftdi device");
|
||||
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");
|
||||
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");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -481,14 +460,13 @@ static int usb_blaster_init(void)
|
|||
|
||||
#if 0
|
||||
#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);
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
#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);
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -500,7 +478,7 @@ static int usb_blaster_init(void)
|
|||
|
||||
static int usb_blaster_quit(void)
|
||||
{
|
||||
if(out_count > 0)
|
||||
if (out_count > 0)
|
||||
usb_blaster_write_databuffer(out_buffer, out_count);
|
||||
|
||||
#if BUILD_USB_BLASTER_FTD2XX == 1
|
||||
|
@ -521,25 +499,22 @@ COMMAND_HANDLER(usb_blaster_handle_device_desc_command)
|
|||
usb_blaster_device_desc = strdup(CMD_ARGV[0]);
|
||||
else
|
||||
LOG_ERROR("require exactly one argument to "
|
||||
"usb_blaster_device_desc <description>");
|
||||
"usb_blaster_device_desc <description>");
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
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 "
|
||||
"(maximum is 1 pair)");
|
||||
"(maximum is 1 pair)");
|
||||
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[1], usb_blaster_pid);
|
||||
}
|
||||
else
|
||||
} else
|
||||
LOG_WARNING("incomplete usb_blaster_vid_pid configuration");
|
||||
|
||||
return ERROR_OK;
|
||||
|
@ -547,9 +522,8 @@ COMMAND_HANDLER(usb_blaster_handle_vid_pid_command)
|
|||
|
||||
COMMAND_HANDLER(usb_blaster_handle_pin_command)
|
||||
{
|
||||
if (CMD_ARGC == 2)
|
||||
{
|
||||
const char * const pin_name = CMD_ARGV[0];
|
||||
if (CMD_ARGC == 2) {
|
||||
const char *const pin_name = CMD_ARGV[0];
|
||||
uint8_t mask;
|
||||
unsigned int state;
|
||||
|
||||
|
@ -557,34 +531,26 @@ COMMAND_HANDLER(usb_blaster_handle_pin_command)
|
|||
mask = NCE;
|
||||
else if (!strcmp(pin_name, "pin8"))
|
||||
mask = NCS;
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("%s: pin name must be \"pin6\" or \"pin8\"",
|
||||
CMD_NAME);
|
||||
CMD_NAME);
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], state);
|
||||
if (state == 0)
|
||||
{
|
||||
if (state == 0) {
|
||||
out_value &= ~mask;
|
||||
usb_blaster_addtowritebuffer(out_value, true);
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
} else if (state == 1) {
|
||||
out_value |= mask;
|
||||
usb_blaster_addtowritebuffer(out_value, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_ERROR("%s: pin state must be 0 or 1", CMD_NAME);
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_ERROR("%s takes exactly two arguments", CMD_NAME);
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
|
|
@ -26,13 +26,10 @@
|
|||
static bool jtag_usb_match(struct usb_device *dev,
|
||||
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] &&
|
||||
dev->descriptor.idProduct == pids[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -44,10 +41,8 @@ int jtag_usb_open(const uint16_t vids[], const uint16_t pids[],
|
|||
usb_find_devices();
|
||||
|
||||
struct usb_bus *busses = usb_get_busses();
|
||||
for (struct usb_bus *bus = busses; bus; bus = bus->next)
|
||||
{
|
||||
for (struct usb_device *dev = bus->devices; dev; dev = dev->next)
|
||||
{
|
||||
for (struct usb_bus *bus = busses; bus; bus = bus->next) {
|
||||
for (struct usb_device *dev = bus->devices; dev; dev = dev->next) {
|
||||
if (!jtag_usb_match(dev, vids, pids))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -27,4 +27,4 @@
|
|||
int jtag_usb_open(const uint16_t vids[], const uint16_t pids[],
|
||||
struct usb_dev_handle **out);
|
||||
|
||||
#endif // JTAG_USB_COMMON_H
|
||||
#endif /* JTAG_USB_COMMON_H */
|
||||
|
|
|
@ -38,15 +38,14 @@
|
|||
#include <jtag/commands.h>
|
||||
#include "usb_common.h"
|
||||
|
||||
|
||||
#define VID 0x1781
|
||||
#define PID 0x0c63
|
||||
|
||||
/* Pins at usbprog */
|
||||
#define TDO_BIT 0
|
||||
#define TDI_BIT 3
|
||||
#define TCK_BIT 2
|
||||
#define TMS_BIT 1
|
||||
#define TDO_BIT 0
|
||||
#define TDI_BIT 3
|
||||
#define TCK_BIT 2
|
||||
#define TMS_BIT 1
|
||||
|
||||
static void usbprog_end_state(tap_state_t state);
|
||||
static void usbprog_state_move(void);
|
||||
|
@ -54,33 +53,32 @@ static void usbprog_path_move(struct pathmove_command *cmd);
|
|||
static void usbprog_runtest(int num_cycles);
|
||||
static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size);
|
||||
|
||||
#define UNKNOWN_COMMAND 0x00
|
||||
#define PORT_DIRECTION 0x01
|
||||
#define PORT_SET 0x02
|
||||
#define PORT_GET 0x03
|
||||
#define PORT_SETBIT 0x04
|
||||
#define PORT_GETBIT 0x05
|
||||
#define WRITE_TDI 0x06
|
||||
#define READ_TDO 0x07
|
||||
#define WRITE_AND_READ 0x08
|
||||
#define WRITE_TMS 0x09
|
||||
#define WRITE_TMS_CHAIN 0x0A
|
||||
#define UNKNOWN_COMMAND 0x00
|
||||
#define PORT_DIRECTION 0x01
|
||||
#define PORT_SET 0x02
|
||||
#define PORT_GET 0x03
|
||||
#define PORT_SETBIT 0x04
|
||||
#define PORT_GETBIT 0x05
|
||||
#define WRITE_TDI 0x06
|
||||
#define READ_TDO 0x07
|
||||
#define WRITE_AND_READ 0x08
|
||||
#define WRITE_TMS 0x09
|
||||
#define WRITE_TMS_CHAIN 0x0A
|
||||
|
||||
struct usbprog_jtag
|
||||
{
|
||||
struct usb_dev_handle* usb_handle;
|
||||
struct usbprog_jtag {
|
||||
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 void usbprog_jtag_close(struct usbprog_jtag *usbprog_jtag);
|
||||
static struct usbprog_jtag *usbprog_jtag_open(void);
|
||||
/* static void usbprog_jtag_close(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 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_and_read(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_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 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_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 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 int usbprog_jtag_get_bit(struct usbprog_jtag *usbprog_jtag, int bit);
|
||||
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 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_speed(int speed)
|
||||
{
|
||||
|
@ -105,68 +103,69 @@ static int usbprog_speed(int speed)
|
|||
|
||||
static int usbprog_execute_queue(void)
|
||||
{
|
||||
struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
|
||||
struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
|
||||
int scan_size;
|
||||
enum scan_type type;
|
||||
uint8_t *buffer;
|
||||
|
||||
while (cmd)
|
||||
{
|
||||
switch (cmd->type)
|
||||
{
|
||||
case JTAG_RESET:
|
||||
while (cmd) {
|
||||
switch (cmd->type) {
|
||||
case JTAG_RESET:
|
||||
#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
|
||||
if (cmd->cmd.reset->trst == 1)
|
||||
{
|
||||
tap_set_state(TAP_RESET);
|
||||
}
|
||||
usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
break;
|
||||
case JTAG_RUNTEST:
|
||||
if (cmd->cmd.reset->trst == 1)
|
||||
tap_set_state(TAP_RESET);
|
||||
usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
|
||||
break;
|
||||
case JTAG_RUNTEST:
|
||||
#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
|
||||
usbprog_end_state(cmd->cmd.runtest->end_state);
|
||||
usbprog_runtest(cmd->cmd.runtest->num_cycles);
|
||||
break;
|
||||
case JTAG_TLR_RESET:
|
||||
usbprog_end_state(cmd->cmd.runtest->end_state);
|
||||
usbprog_runtest(cmd->cmd.runtest->num_cycles);
|
||||
break;
|
||||
case JTAG_TLR_RESET:
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state);
|
||||
LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state);
|
||||
#endif
|
||||
usbprog_end_state(cmd->cmd.statemove->end_state);
|
||||
usbprog_state_move();
|
||||
break;
|
||||
case JTAG_PATHMOVE:
|
||||
usbprog_end_state(cmd->cmd.statemove->end_state);
|
||||
usbprog_state_move();
|
||||
break;
|
||||
case JTAG_PATHMOVE:
|
||||
#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
|
||||
usbprog_path_move(cmd->cmd.pathmove);
|
||||
break;
|
||||
case JTAG_SCAN:
|
||||
usbprog_path_move(cmd->cmd.pathmove);
|
||||
break;
|
||||
case JTAG_SCAN:
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state);
|
||||
LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state);
|
||||
#endif
|
||||
usbprog_end_state(cmd->cmd.scan->end_state);
|
||||
scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
|
||||
type = jtag_scan_type(cmd->cmd.scan);
|
||||
usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
||||
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
break;
|
||||
case JTAG_SLEEP:
|
||||
usbprog_end_state(cmd->cmd.scan->end_state);
|
||||
scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
|
||||
type = jtag_scan_type(cmd->cmd.scan);
|
||||
usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
|
||||
if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
break;
|
||||
case JTAG_SLEEP:
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
LOG_DEBUG("sleep %i", cmd->cmd.sleep->us);
|
||||
LOG_DEBUG("sleep %i", cmd->cmd.sleep->us);
|
||||
#endif
|
||||
jtag_sleep(cmd->cmd.sleep->us);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("BUG: unknown JTAG command type encountered");
|
||||
exit(-1);
|
||||
jtag_sleep(cmd->cmd.sleep->us);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("BUG: unknown JTAG command type encountered");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
cmd = cmd->next;
|
||||
|
@ -180,8 +179,7 @@ static int usbprog_init(void)
|
|||
usbprog_jtag_handle = usbprog_jtag_open();
|
||||
|
||||
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.");
|
||||
return ERROR_JTAG_INIT_FAILED;
|
||||
}
|
||||
|
@ -205,8 +203,7 @@ static void usbprog_end_state(tap_state_t state)
|
|||
{
|
||||
if (tap_is_state_stable(state))
|
||||
tap_set_end_state(state);
|
||||
else
|
||||
{
|
||||
else {
|
||||
LOG_ERROR("BUG: %i is not a valid end state", state);
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -231,23 +228,20 @@ static void usbprog_path_move(struct pathmove_command *cmd)
|
|||
usbprog_jtag_tms_send(usbprog_jtag_handle);
|
||||
|
||||
state_count = 0;
|
||||
while (num_states)
|
||||
{
|
||||
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
|
||||
{
|
||||
while (num_states) {
|
||||
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) {
|
||||
/* LOG_INFO("1"); */
|
||||
usbprog_write(0, 0, 0);
|
||||
usbprog_write(1, 0, 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]) {
|
||||
/* LOG_INFO("2"); */
|
||||
usbprog_write(0, 1, 0);
|
||||
usbprog_write(1, 1, 0);
|
||||
}
|
||||
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]));
|
||||
} 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]));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -264,32 +258,28 @@ static void usbprog_runtest(int num_cycles)
|
|||
int i;
|
||||
|
||||
/* 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_state_move();
|
||||
}
|
||||
|
||||
/* execute num_cycles */
|
||||
if (num_cycles > 0)
|
||||
{
|
||||
if (num_cycles > 0) {
|
||||
usbprog_jtag_tms_send(usbprog_jtag_handle);
|
||||
usbprog_write(0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
usbprog_jtag_tms_send(usbprog_jtag_handle);
|
||||
/* 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(0, 0, 0);
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
/* finish in end_state */
|
||||
|
@ -317,14 +307,20 @@ static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
|
|||
|
||||
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) {
|
||||
case SCAN_OUT: f = &usbprog_jtag_write_tdi; break;
|
||||
case SCAN_IN: f = &usbprog_jtag_read_tdo; break;
|
||||
case SCAN_IO: f = &usbprog_jtag_write_and_read; break;
|
||||
default:
|
||||
LOG_ERROR("unknown scan type: %i", type);
|
||||
exit(-1);
|
||||
case SCAN_OUT:
|
||||
f = &usbprog_jtag_write_tdi;
|
||||
break;
|
||||
case SCAN_IN:
|
||||
f = &usbprog_jtag_read_tdo;
|
||||
break;
|
||||
case SCAN_IO:
|
||||
f = &usbprog_jtag_write_and_read;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("unknown scan type: %i", type);
|
||||
exit(-1);
|
||||
}
|
||||
f(usbprog_jtag_handle, (char *)buffer, scan_size);
|
||||
|
||||
|
@ -351,7 +347,7 @@ static void usbprog_write(int tck, int tms, int tdi)
|
|||
if (tck)
|
||||
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 */
|
||||
|
@ -374,7 +370,7 @@ static void usbprog_reset(int trst, int srst)
|
|||
|
||||
struct usb_bus *busses;
|
||||
|
||||
struct usbprog_jtag* usbprog_jtag_open(void)
|
||||
struct usbprog_jtag *usbprog_jtag_open(void)
|
||||
{
|
||||
usb_set_debug(10);
|
||||
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)
|
||||
{
|
||||
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) || \
|
||||
(msg[0] == 6) || (msg[0] == 0x0A) || (msg[0] == 9))
|
||||
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) || \
|
||||
(msg[0] == 6) || (msg[0] == 0x0A) || (msg[0] == 9))
|
||||
return 1;
|
||||
if (res == msglen)
|
||||
{
|
||||
if (res == msglen) {
|
||||
/* 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)
|
||||
return (unsigned char)msg[1];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -428,7 +422,7 @@ static void usbprog_jtag_init(struct usbprog_jtag *usbprog_jtag)
|
|||
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 */
|
||||
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;
|
||||
/* 61 byte can be transfered (488 bit) */
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
if (size > 488)
|
||||
{
|
||||
while (size > 0) {
|
||||
if (size > 488) {
|
||||
send_bits = 488;
|
||||
size = size - 488;
|
||||
loops = 61;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
send_bits = size;
|
||||
loops = size / 8;
|
||||
loops++;
|
||||
|
@ -455,34 +445,30 @@ static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char
|
|||
tmp[1] = (char)(send_bits >> 8); /* high */
|
||||
tmp[2] = (char)(send_bits); /* low */
|
||||
|
||||
for (i = 0; i < loops; i++)
|
||||
{
|
||||
for (i = 0; i < loops; i++) {
|
||||
tmp[3 + i] = buffer[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]); */
|
||||
usleep(1);
|
||||
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++;
|
||||
if (timeout > 10)
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < loops; i++)
|
||||
{
|
||||
swap = tmp[3 + i];
|
||||
for (i = 0; i < loops; i++) {
|
||||
swap = tmp[3 + i];
|
||||
buffer[fillindex++] = swap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
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;
|
||||
/* 61 byte can be transfered (488 bit) */
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
if (size > 488)
|
||||
{
|
||||
while (size > 0) {
|
||||
if (size > 488) {
|
||||
send_bits = 488;
|
||||
size = size - 488;
|
||||
loops = 61;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
send_bits = size;
|
||||
loops = size / 8;
|
||||
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]); */
|
||||
int timeout = 0;
|
||||
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++;
|
||||
if (timeout > 10)
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < loops; i++)
|
||||
{
|
||||
for (i = 0; i < loops; i++) {
|
||||
swap = tmp[3 + i];
|
||||
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 */
|
||||
int send_bits, bufindex = 0, i, loops;
|
||||
|
||||
/* 61 byte can be transfered (488 bit) */
|
||||
while (size > 0)
|
||||
{
|
||||
if (size > 488)
|
||||
{
|
||||
while (size > 0) {
|
||||
if (size > 488) {
|
||||
send_bits = 488;
|
||||
size = size - 488;
|
||||
loops = 61;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
send_bits = size;
|
||||
loops = size/8;
|
||||
/* 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[2] = (char)(send_bits); /* low */
|
||||
|
||||
for (i = 0; i < loops; i++)
|
||||
{
|
||||
for (i = 0; i < loops; i++) {
|
||||
tmp[3 + i] = buffer[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);
|
||||
}
|
||||
|
||||
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];
|
||||
tmp[0] = PORT_SET;
|
||||
|
@ -595,7 +570,7 @@ static unsigned char usbprog_jtag_get_port(struct usbprog_jtag *usbprog_jtag)
|
|||
}
|
||||
#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];
|
||||
tmp[0] = PORT_SETBIT;
|
||||
|
@ -631,8 +606,7 @@ static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag)
|
|||
{
|
||||
int i;
|
||||
/* LOG_INFO("TMS SEND"); */
|
||||
if (tms_chain_index > 0)
|
||||
{
|
||||
if (tms_chain_index > 0) {
|
||||
char tmp[tms_chain_index + 2];
|
||||
tmp[0] = WRITE_TMS_CHAIN;
|
||||
tmp[1] = (char)(tms_chain_index);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -39,62 +40,58 @@ RESULT usbtogpio_fini(uint8_t interface_index)
|
|||
}
|
||||
|
||||
RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask,
|
||||
uint32_t dir_mask, uint32_t pull_en_mask,
|
||||
uint32_t input_pull_mask)
|
||||
uint32_t dir_mask, uint32_t pull_en_mask,
|
||||
uint32_t input_pull_mask)
|
||||
{
|
||||
uint8_t conf[8];
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
dir_mask &= mask;
|
||||
SET_LE_U16(&conf[0], mask);
|
||||
SET_LE_U16(&conf[2], dir_mask);
|
||||
SET_LE_U16(&conf[4], pull_en_mask);
|
||||
SET_LE_U16(&conf[6], input_pull_mask);
|
||||
|
||||
|
||||
return usbtoxxx_conf_command(USB_TO_GPIO, interface_index, conf,
|
||||
sizeof(conf));
|
||||
sizeof(conf));
|
||||
}
|
||||
|
||||
RESULT usbtogpio_in(uint8_t interface_index, uint32_t mask, uint32_t *value)
|
||||
{
|
||||
uint8_t buf[2];
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SET_LE_U16(&buf[0], mask);
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
uint8_t buf[4];
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SET_LE_U16(&buf[0], mask);
|
||||
SET_LE_U16(&buf[2], value);
|
||||
|
||||
|
||||
return usbtoxxx_out_command(USB_TO_GPIO, interface_index, buf, 4, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -41,44 +42,39 @@ RESULT usbtojtagraw_fini(uint8_t interface_index)
|
|||
RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t kHz)
|
||||
{
|
||||
uint8_t cfg_buf[4];
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SET_LE_U32(&cfg_buf[0], kHz);
|
||||
|
||||
|
||||
return usbtoxxx_conf_command(USB_TO_JTAG_RAW, interface_index, cfg_buf, 4);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
uint16_t bytelen;
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (bitlen > 8 * 0xFFFF)
|
||||
{
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
bytelen = (uint16_t)((bitlen + 7) >> 3);
|
||||
|
||||
|
||||
SET_LE_U32(&versaloon_cmd_buf[0], bitlen);
|
||||
memcpy(versaloon_cmd_buf + 4, tdi, bytelen);
|
||||
memcpy(versaloon_cmd_buf + 4 + bytelen, tms, bytelen);
|
||||
|
||||
return usbtoxxx_inout_command(USB_TO_JTAG_RAW, interface_index,
|
||||
versaloon_cmd_buf, 4 + bytelen * 2, bytelen, tdo, 0, bytelen, 0);
|
||||
}
|
||||
|
||||
return usbtoxxx_inout_command(USB_TO_JTAG_RAW, interface_index,
|
||||
versaloon_cmd_buf, 4 + bytelen * 2, bytelen, tdo, 0, bytelen, 0);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -41,27 +42,24 @@ RESULT usbtopwr_fini(uint8_t interface_index)
|
|||
RESULT usbtopwr_config(uint8_t interface_index)
|
||||
{
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return usbtoxxx_conf_command(USB_TO_POWER, interface_index, NULL, 0);
|
||||
}
|
||||
|
||||
RESULT usbtopwr_output(uint8_t interface_index, uint16_t mV)
|
||||
{
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return usbtoxxx_out_command(USB_TO_POWER, interface_index, (uint8_t *)&mV,
|
||||
2, 0);
|
||||
}
|
||||
|
||||
return usbtoxxx_out_command(USB_TO_POWER, interface_index, (uint8_t *)&mV,
|
||||
2, 0);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -32,14 +33,12 @@
|
|||
RESULT usbtoswd_callback(void *p, uint8_t *src, uint8_t *processed)
|
||||
{
|
||||
struct versaloon_pending_t *pending = (struct versaloon_pending_t *)p;
|
||||
|
||||
|
||||
processed = processed;
|
||||
|
||||
|
||||
if (pending->extra_data != NULL)
|
||||
{
|
||||
*((uint8_t *)pending->extra_data) = src[0];
|
||||
}
|
||||
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
@ -54,77 +53,73 @@ RESULT usbtoswd_fini(uint8_t interface_index)
|
|||
}
|
||||
|
||||
RESULT usbtoswd_config(uint8_t interface_index, uint8_t trn, uint16_t retry,
|
||||
uint16_t dly)
|
||||
uint16_t dly)
|
||||
{
|
||||
uint8_t cfg_buf[5];
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
cfg_buf[0] = trn;
|
||||
SET_LE_U16(&cfg_buf[1], retry);
|
||||
SET_LE_U16(&cfg_buf[3], dly);
|
||||
|
||||
|
||||
return usbtoxxx_conf_command(USB_TO_SWD, interface_index, cfg_buf, 5);
|
||||
}
|
||||
|
||||
RESULT usbtoswd_seqout(uint8_t interface_index, uint8_t *data, uint16_t bitlen)
|
||||
{
|
||||
uint16_t bytelen = (bitlen + 7) >> 3;
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SET_LE_U16(&versaloon_cmd_buf[0], bitlen);
|
||||
memcpy(versaloon_cmd_buf + 2, data, bytelen);
|
||||
|
||||
|
||||
return usbtoxxx_out_command(USB_TO_SWD, interface_index,
|
||||
versaloon_cmd_buf, bytelen + 2, 0);
|
||||
versaloon_cmd_buf, bytelen + 2, 0);
|
||||
}
|
||||
|
||||
RESULT usbtoswd_seqin(uint8_t interface_index, uint8_t *data, uint16_t bitlen)
|
||||
{
|
||||
uint16_t bytelen = (bitlen + 7) >> 3;
|
||||
uint8_t buff[2];
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SET_LE_U16(&buff[0], bitlen);
|
||||
|
||||
|
||||
return usbtoxxx_in_command(USB_TO_SWD, interface_index, buff, 2, bytelen,
|
||||
data, 0, bytelen, 0);
|
||||
data, 0, bytelen, 0);
|
||||
}
|
||||
|
||||
RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request,
|
||||
uint32_t *data, uint8_t *ack)
|
||||
uint32_t *data, uint8_t *ack)
|
||||
{
|
||||
uint8_t parity;
|
||||
uint8_t buff[5];
|
||||
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (interface_index > 7)
|
||||
{
|
||||
if (interface_index > 7) {
|
||||
LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
parity = (request >> 1) & 1;
|
||||
parity += (request >> 2) & 1;
|
||||
parity += (request >> 3) & 1;
|
||||
|
@ -132,27 +127,19 @@ RESULT usbtoswd_transact(uint8_t interface_index, uint8_t request,
|
|||
parity &= 1;
|
||||
buff[0] = (request | 0x81 | (parity << 5)) & ~0x40;
|
||||
if (data != NULL)
|
||||
{
|
||||
SET_LE_U32(&buff[1], *data);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(buff + 1, 0, 4);
|
||||
}
|
||||
|
||||
|
||||
versaloon_set_extra_data(ack);
|
||||
versaloon_set_callback(usbtoswd_callback);
|
||||
if (request & 0x04)
|
||||
{
|
||||
// read
|
||||
if (request & 0x04) {
|
||||
/* read */
|
||||
return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5,
|
||||
(uint8_t *)data, 1, 4, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// write
|
||||
(uint8_t *)data, 1, 4, 0);
|
||||
} else {
|
||||
/* write */
|
||||
return usbtoxxx_inout_command(USB_TO_SWD, interface_index, buff, 5, 5,
|
||||
NULL, 0, 0, 0);
|
||||
NULL, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -28,40 +29,39 @@
|
|||
#include "usbtoxxx.h"
|
||||
#include "usbtoxxx_internal.h"
|
||||
|
||||
#define N_A "n/a"
|
||||
const char* types_name[96] =
|
||||
{
|
||||
"usbtousart", "usbtospi", "usbtoi2c", "usbtogpio", "usbtocan", "usbtopwm",
|
||||
"usbtoadc", "usbtodac",
|
||||
"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,
|
||||
"usbtojtagll", "usbtojtaghl", "usbtoissp", "usbtoc2", "usbtosbw",
|
||||
"usbtolpcicp", "usbtoswd", "usbtojtagraw",
|
||||
"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,
|
||||
"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,
|
||||
N_A, N_A, N_A, N_A, N_A, N_A, N_A, "usbtoall"
|
||||
#define N_A "n/a"
|
||||
|
||||
const char *types_name[96] = {
|
||||
"usbtousart", "usbtospi", "usbtoi2c", "usbtogpio", "usbtocan", "usbtopwm",
|
||||
"usbtoadc", "usbtodac",
|
||||
"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,
|
||||
"usbtojtagll", "usbtojtaghl", "usbtoissp", "usbtoc2", "usbtosbw",
|
||||
"usbtolpcicp", "usbtoswd", "usbtojtagraw",
|
||||
"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,
|
||||
"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,
|
||||
N_A, N_A, N_A, N_A, N_A, N_A, N_A, "usbtoall"
|
||||
};
|
||||
|
||||
uint8_t usbtoxxx_abilities[USB_TO_XXX_ABILITIES_LEN];
|
||||
|
||||
#define usbtoxxx_get_type_name(type) \
|
||||
types_name[((type) - VERSALOON_USB_TO_XXX_CMD_START) \
|
||||
% (sizeof(types_name) / sizeof(types_name[0]))]
|
||||
types_name[((type) - VERSALOON_USB_TO_XXX_CMD_START) \
|
||||
% (sizeof(types_name) / sizeof(types_name[0]))]
|
||||
|
||||
static uint8_t type_pre = 0;
|
||||
static uint16_t usbtoxxx_buffer_index = 0;
|
||||
static uint16_t usbtoxxx_current_cmd_index = 0;
|
||||
static uint8_t *usbtoxxx_buffer = NULL;
|
||||
static uint8_t type_pre;
|
||||
static uint16_t usbtoxxx_buffer_index;
|
||||
static uint16_t usbtoxxx_current_cmd_index;
|
||||
static uint8_t *usbtoxxx_buffer;
|
||||
|
||||
uint16_t collect_index = 0;
|
||||
uint16_t collect_index;
|
||||
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 *usbtoxxx_buffer;
|
||||
uint16_t usbtoxxx_current_cmd_index;
|
||||
|
@ -90,93 +90,78 @@ static void usbtoxxx_pop_context(struct usbtoxxx_context_t *c)
|
|||
|
||||
RESULT usbtoxxx_validate_current_command_type(void)
|
||||
{
|
||||
if (type_pre > 0)
|
||||
{
|
||||
// not the first command
|
||||
if (NULL == usbtoxxx_buffer)
|
||||
{
|
||||
if (type_pre > 0) {
|
||||
/* not the first command */
|
||||
if (NULL == usbtoxxx_buffer) {
|
||||
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(usbtoxxx_buffer));
|
||||
return ERRCODE_INVALID_BUFFER;
|
||||
}
|
||||
|
||||
|
||||
usbtoxxx_buffer[0] = type_pre;
|
||||
SET_LE_U16(&usbtoxxx_buffer[1], usbtoxxx_current_cmd_index);
|
||||
|
||||
|
||||
usbtoxxx_buffer_index += usbtoxxx_current_cmd_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
// first command
|
||||
} else {
|
||||
/* first command */
|
||||
usbtoxxx_buffer_index = 3;
|
||||
}
|
||||
|
||||
// prepare for next command
|
||||
|
||||
/* prepare for next command */
|
||||
usbtoxxx_current_cmd_index = 3;
|
||||
usbtoxxx_buffer = versaloon_buf + usbtoxxx_buffer_index;
|
||||
|
||||
|
||||
collect_index = 0;
|
||||
collect_cmd = 0;
|
||||
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RESULT usbtoxxx_execute_command(void)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t inlen;
|
||||
RESULT result = ERROR_OK;
|
||||
|
||||
if (poll_nesting)
|
||||
{
|
||||
|
||||
if (poll_nesting) {
|
||||
LOG_BUG(ERRMSG_INVALID_USAGE, "USB_TO_POLL");
|
||||
versaloon_free_want_pos();
|
||||
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");
|
||||
versaloon_free_want_pos();
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
if (3 == usbtoxxx_buffer_index)
|
||||
{
|
||||
if (3 == usbtoxxx_buffer_index) {
|
||||
versaloon_free_want_pos();
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
versaloon_buf[0] = USB_TO_ALL;
|
||||
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();
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
// process return data
|
||||
|
||||
/* process return data */
|
||||
usbtoxxx_buffer_index = 0;
|
||||
for (i = 0; i < versaloon_pending_idx; i++)
|
||||
{
|
||||
// check result
|
||||
for (i = 0; i < versaloon_pending_idx; i++) {
|
||||
/* check result */
|
||||
if ((0 == i) || !((versaloon_pending[i].collect)
|
||||
&& (versaloon_pending[i - 1].collect)
|
||||
&& (versaloon_pending[i].cmd
|
||||
== versaloon_pending[i - 1].cmd)))
|
||||
{
|
||||
&& (versaloon_pending[i - 1].collect)
|
||||
&& (versaloon_pending[i].cmd
|
||||
== versaloon_pending[i - 1].cmd))) {
|
||||
if (USB_TO_XXX_CMD_NOT_SUPPORT
|
||||
== versaloon_buf[usbtoxxx_buffer_index])
|
||||
{
|
||||
== versaloon_buf[usbtoxxx_buffer_index]) {
|
||||
LOG_ERROR(ERRMSG_NOT_SUPPORT_BY,
|
||||
usbtoxxx_get_type_name(versaloon_pending[i].type),
|
||||
"current dongle");
|
||||
usbtoxxx_get_type_name(versaloon_pending[i].type),
|
||||
"current dongle");
|
||||
result = ERROR_FAIL;
|
||||
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",
|
||||
usbtoxxx_get_type_name(versaloon_pending[i].type),
|
||||
versaloon_pending[i].cmd,
|
||||
|
@ -186,28 +171,25 @@ RESULT usbtoxxx_execute_command(void)
|
|||
}
|
||||
usbtoxxx_buffer_index++;
|
||||
}
|
||||
|
||||
// get result data
|
||||
if (versaloon_pending[i].pos != NULL)
|
||||
{
|
||||
|
||||
/* get result data */
|
||||
if (versaloon_pending[i].pos != NULL) {
|
||||
uint8_t processed = 0;
|
||||
|
||||
if (versaloon_pending[i].callback != NULL)
|
||||
{
|
||||
|
||||
if (versaloon_pending[i].callback != NULL) {
|
||||
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;
|
||||
|
||||
|
||||
tmp = versaloon_pending[i].pos;
|
||||
while (tmp != NULL)
|
||||
{
|
||||
if ((tmp->buff != NULL) && (tmp->size > 0))
|
||||
{
|
||||
memcpy(tmp->buff, versaloon_buf + usbtoxxx_buffer_index
|
||||
+ tmp->offset, tmp->size);
|
||||
while (tmp != NULL) {
|
||||
if ((tmp->buff != NULL) && (tmp->size > 0)) {
|
||||
memcpy(tmp->buff,
|
||||
versaloon_buf + usbtoxxx_buffer_index
|
||||
+ tmp->offset,
|
||||
tmp->size);
|
||||
}
|
||||
struct versaloon_want_pos_t *free_tmp;
|
||||
free_tmp = tmp;
|
||||
|
@ -216,53 +198,44 @@ RESULT usbtoxxx_execute_command(void)
|
|||
}
|
||||
versaloon_pending[i].pos = NULL;
|
||||
}
|
||||
}
|
||||
else if ((versaloon_pending[i].want_data_size > 0)
|
||||
&& (versaloon_pending[i].data_buffer != NULL))
|
||||
{
|
||||
} else if ((versaloon_pending[i].want_data_size > 0)
|
||||
&& (versaloon_pending[i].data_buffer != NULL)) {
|
||||
uint8_t processed = 0;
|
||||
|
||||
if (versaloon_pending[i].callback != NULL)
|
||||
{
|
||||
|
||||
if (versaloon_pending[i].callback != NULL) {
|
||||
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,
|
||||
versaloon_buf + usbtoxxx_buffer_index
|
||||
+ versaloon_pending[i].want_data_pos,
|
||||
versaloon_pending[i].want_data_size);
|
||||
versaloon_buf + usbtoxxx_buffer_index
|
||||
+ versaloon_pending[i].want_data_pos,
|
||||
versaloon_pending[i].want_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",
|
||||
usbtoxxx_get_type_name(versaloon_pending[i].type),
|
||||
versaloon_pending[i].cmd);
|
||||
usbtoxxx_get_type_name(versaloon_pending[i].type),
|
||||
versaloon_pending[i].cmd);
|
||||
result = ERROR_FAIL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// data is not the right size
|
||||
if (inlen != usbtoxxx_buffer_index)
|
||||
{
|
||||
|
||||
/* data is not the right size */
|
||||
if (inlen != usbtoxxx_buffer_index) {
|
||||
LOG_ERROR(ERRMSG_INVALID_TARGET, "length of return data");
|
||||
result = ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
if (versaloon_pending_idx > 0)
|
||||
{
|
||||
versaloon_pending_idx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no receive data, avoid collision
|
||||
else {
|
||||
/* no receive data, avoid collision */
|
||||
sleep_ms(10);
|
||||
}
|
||||
|
||||
|
||||
type_pre = 0;
|
||||
collect_cmd = 0;
|
||||
collect_index = 0;
|
||||
|
@ -273,12 +246,10 @@ RESULT usbtoxxx_execute_command(void)
|
|||
RESULT usbtoxxx_init(void)
|
||||
{
|
||||
versaloon_pending_idx = 0;
|
||||
|
||||
|
||||
if ((ERROR_OK != usbtoinfo_get_abilities(usbtoxxx_abilities)) ||
|
||||
(ERROR_OK != usbtoxxx_execute_command()))
|
||||
{
|
||||
(ERROR_OK != usbtoxxx_execute_command()))
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
LOG_INFO("USB_TO_XXX abilities: 0x%08X:0x%08X:0x%08X",
|
||||
GET_LE_U32(&usbtoxxx_abilities[0]),
|
||||
GET_LE_U32(&usbtoxxx_abilities[4]),
|
||||
|
@ -296,61 +267,51 @@ RESULT usbtoxxx_fini(void)
|
|||
bool usbtoxxx_interface_supported(uint8_t cmd)
|
||||
{
|
||||
if ((cmd < VERSALOON_USB_TO_XXX_CMD_START) ||
|
||||
(cmd > VERSALOON_USB_TO_XXX_CMD_END))
|
||||
{
|
||||
(cmd > VERSALOON_USB_TO_XXX_CMD_END))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
cmd -= VERSALOON_USB_TO_XXX_CMD_START;
|
||||
return (usbtoxxx_abilities[cmd / 8] & (1 << (cmd % 8))) > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)
|
||||
>= versaloon_buf_size)
|
||||
|| (versaloon_pending_idx >= VERSALOON_MAX_PENDING_NUMBER))
|
||||
{
|
||||
|| (versaloon_pending_idx >= VERSALOON_MAX_PENDING_NUMBER)) {
|
||||
struct usbtoxxx_context_t context_tmp;
|
||||
uint8_t poll_nesting_tmp = 0;
|
||||
|
||||
|
||||
memset(&context_tmp, 0, sizeof(context_tmp));
|
||||
if (poll_nesting)
|
||||
{
|
||||
if (0 == poll_context.type_pre)
|
||||
{
|
||||
if (poll_nesting) {
|
||||
if (0 == poll_context.type_pre) {
|
||||
LOG_BUG("USB_TO_POLL toooooo long");
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
usbtoxxx_save_context(&context_tmp);
|
||||
usbtoxxx_pop_context(&poll_context);
|
||||
poll_nesting_tmp = poll_nesting;
|
||||
poll_nesting = 0;
|
||||
}
|
||||
|
||||
|
||||
if (usbtoxxx_execute_command() != ERROR_OK)
|
||||
{
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
if (poll_nesting_tmp)
|
||||
{
|
||||
|
||||
if (poll_nesting_tmp) {
|
||||
uint16_t newlen, oldlen;
|
||||
|
||||
|
||||
newlen = context_tmp.versaloon_pending_idx
|
||||
- poll_context.versaloon_pending_idx;
|
||||
- poll_context.versaloon_pending_idx;
|
||||
memcpy(&versaloon_pending[0],
|
||||
&versaloon_pending[poll_context.versaloon_pending_idx],
|
||||
sizeof(versaloon_pending[0]) * newlen);
|
||||
&versaloon_pending[poll_context.versaloon_pending_idx],
|
||||
sizeof(versaloon_pending[0]) * newlen);
|
||||
context_tmp.versaloon_pending_idx = newlen;
|
||||
oldlen = poll_context.usbtoxxx_buffer_index
|
||||
+ poll_context.usbtoxxx_current_cmd_index;
|
||||
+ poll_context.usbtoxxx_current_cmd_index;
|
||||
newlen = context_tmp.usbtoxxx_buffer_index
|
||||
+ context_tmp.usbtoxxx_current_cmd_index;
|
||||
+ context_tmp.usbtoxxx_current_cmd_index;
|
||||
memcpy(versaloon_buf + 3, versaloon_buf + oldlen, newlen - oldlen);
|
||||
oldlen -= 3;
|
||||
context_tmp.usbtoxxx_buffer -= oldlen;
|
||||
|
@ -363,250 +324,198 @@ RESULT usbtoxxx_ensure_buffer_size(uint16_t cmdlen)
|
|||
}
|
||||
|
||||
RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf,
|
||||
uint16_t cmdlen, uint16_t retlen, uint8_t *wantbuf,
|
||||
uint16_t wantpos, uint16_t wantlen, uint8_t collect)
|
||||
uint16_t cmdlen, uint16_t retlen, uint8_t *wantbuf,
|
||||
uint16_t wantpos, uint16_t wantlen, uint8_t collect)
|
||||
{
|
||||
uint16_t len_tmp;
|
||||
|
||||
// 3 more bytes by usbtoxxx_validate_current_command_type
|
||||
// 3 more bytes when ((0 == collect_index) || (collect_cmd != cmd))
|
||||
|
||||
/* 3 more bytes by usbtoxxx_validate_current_command_type */
|
||||
/* 3 more bytes when ((0 == collect_index) || (collect_cmd != cmd)) */
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(cmdlen + 6))
|
||||
{
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
if ((type_pre != type) || (NULL == usbtoxxx_buffer))
|
||||
{
|
||||
if (ERROR_OK != usbtoxxx_validate_current_command_type())
|
||||
{
|
||||
|
||||
if ((type_pre != type) || (NULL == usbtoxxx_buffer)) {
|
||||
if (ERROR_OK != usbtoxxx_validate_current_command_type()) {
|
||||
LOG_BUG(ERRMSG_FAILURE_OPERATION, "validate previous commands");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
type_pre = type;
|
||||
}
|
||||
|
||||
if ((0 == collect_index) || (collect_cmd != cmd))
|
||||
{
|
||||
|
||||
if ((0 == collect_index) || (collect_cmd != cmd)) {
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = cmd;
|
||||
|
||||
if (collect)
|
||||
{
|
||||
|
||||
if (collect) {
|
||||
collect_index = usbtoxxx_current_cmd_index;
|
||||
collect_cmd = cmd;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
collect_index = 0;
|
||||
collect_cmd = 0;
|
||||
}
|
||||
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], cmdlen);
|
||||
usbtoxxx_current_cmd_index += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
len_tmp = GET_LE_U16(&usbtoxxx_buffer[collect_index]) + cmdlen;
|
||||
SET_LE_U16(&usbtoxxx_buffer[collect_index], len_tmp);
|
||||
}
|
||||
|
||||
if (cmdbuf != NULL)
|
||||
{
|
||||
|
||||
if (cmdbuf != NULL) {
|
||||
memcpy(usbtoxxx_buffer + usbtoxxx_current_cmd_index, cmdbuf, cmdlen);
|
||||
usbtoxxx_current_cmd_index += cmdlen;
|
||||
}
|
||||
|
||||
|
||||
return versaloon_add_pending(type, cmd, retlen, wantpos, wantlen,
|
||||
wantbuf, collect);
|
||||
wantbuf, collect);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RESULT usbtoinfo_get_abilities(uint8_t abilities[USB_TO_XXX_ABILITIES_LEN])
|
||||
{
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3))
|
||||
{
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
type_pre = USB_TO_INFO;
|
||||
|
||||
|
||||
return versaloon_add_pending(USB_TO_INFO, 0, USB_TO_XXX_ABILITIES_LEN, 0,
|
||||
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)
|
||||
{
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 5))
|
||||
{
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
if (!poll_nesting)
|
||||
{
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
poll_nesting++;
|
||||
type_pre = USB_TO_POLL;
|
||||
|
||||
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = USB_TO_POLL_START;
|
||||
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], retry_cnt);
|
||||
usbtoxxx_current_cmd_index += 2;
|
||||
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], interval_us);
|
||||
usbtoxxx_current_cmd_index += 2;
|
||||
|
||||
|
||||
return versaloon_add_pending(USB_TO_POLL, 0, 0, 0, 0, NULL, 0);
|
||||
}
|
||||
|
||||
RESULT usbtopoll_end(void)
|
||||
{
|
||||
if (!poll_nesting)
|
||||
{
|
||||
if (!poll_nesting) {
|
||||
LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 1))
|
||||
{
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
|
||||
|
||||
poll_nesting--;
|
||||
type_pre = USB_TO_POLL;
|
||||
|
||||
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = USB_TO_POLL_END;
|
||||
|
||||
|
||||
return versaloon_add_pending(USB_TO_POLL, 0, 0, 0, 0, NULL, 0);
|
||||
}
|
||||
|
||||
RESULT usbtopoll_checkok(uint8_t equ, uint16_t offset, uint8_t size,
|
||||
uint32_t mask, uint32_t value)
|
||||
uint32_t mask, uint32_t value)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if (size > 4)
|
||||
{
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
|
||||
|
||||
if (size > 4) {
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
|
||||
return ERRCODE_INVALID_PARAMETER;
|
||||
}
|
||||
if (!poll_nesting)
|
||||
{
|
||||
if (!poll_nesting) {
|
||||
LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 4 + 2 * size))
|
||||
{
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
|
||||
|
||||
type_pre = USB_TO_POLL;
|
||||
|
||||
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = USB_TO_POLL_CHECKOK;
|
||||
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], offset);
|
||||
usbtoxxx_current_cmd_index += 2;
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = size;
|
||||
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;
|
||||
}
|
||||
for (i =0; i < size; i++)
|
||||
{
|
||||
for (i = 0; i < size; i++)
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (value >> (8 * i)) & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
RESULT usbtopoll_checkfail(uint8_t equ, uint16_t offset, uint8_t size,
|
||||
uint32_t mask, uint32_t value)
|
||||
uint32_t mask, uint32_t value)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if (size > 4)
|
||||
{
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
|
||||
|
||||
if (size > 4) {
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
|
||||
return ERRCODE_INVALID_PARAMETER;
|
||||
}
|
||||
if (!poll_nesting)
|
||||
{
|
||||
if (!poll_nesting) {
|
||||
LOG_BUG(ERRMSG_FAILURE_OPERATION, "check poll nesting");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 4 + 2 * size))
|
||||
{
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
|
||||
|
||||
type_pre = USB_TO_POLL;
|
||||
|
||||
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = USB_TO_POLL_CHECKFAIL;
|
||||
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], offset);
|
||||
usbtoxxx_current_cmd_index += 2;
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = size;
|
||||
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;
|
||||
}
|
||||
for (i =0; i < size; i++)
|
||||
{
|
||||
for (i = 0; i < size; i++)
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = (value >> (8 * i)) & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 5 + size))
|
||||
{
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
|
||||
|
||||
type_pre = USB_TO_POLL;
|
||||
|
||||
|
||||
usbtoxxx_buffer[usbtoxxx_current_cmd_index++] = USB_TO_POLL_VERIFYBUFF;
|
||||
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], offset);
|
||||
usbtoxxx_current_cmd_index += 2;
|
||||
|
@ -614,30 +523,24 @@ RESULT usbtopoll_verifybuff(uint16_t offset, uint16_t size, uint8_t *buff)
|
|||
usbtoxxx_current_cmd_index += 2;
|
||||
memcpy(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], buff, size);
|
||||
usbtoxxx_current_cmd_index += size;
|
||||
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
RESULT usbtodelay_delay(uint16_t dly)
|
||||
{
|
||||
if (ERROR_OK != usbtoxxx_ensure_buffer_size(3 + 2))
|
||||
{
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
type_pre = USB_TO_DELAY;
|
||||
|
||||
|
||||
SET_LE_U16(&usbtoxxx_buffer[usbtoxxx_current_cmd_index], dly);
|
||||
usbtoxxx_current_cmd_index += 2;
|
||||
|
||||
|
||||
return versaloon_add_pending(USB_TO_DELAY, 0, 0, 0, 0, NULL, 0);
|
||||
}
|
||||
|
||||
|
@ -650,4 +553,3 @@ RESULT usbtodelay_delayus(uint16_t us)
|
|||
{
|
||||
return usbtodelay_delay(us & 0x7FFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __USBTOXXX_H_INCLUDED__
|
||||
#define __USBTOXXX_H_INCLUDED__
|
||||
|
||||
|
@ -23,62 +24,54 @@ RESULT usbtoxxx_init(void);
|
|||
RESULT usbtoxxx_fini(void);
|
||||
RESULT usbtoxxx_execute_command(void);
|
||||
|
||||
#define USB_TO_XXX_ABILITIES_LEN 12
|
||||
#define USB_TO_XXX_ABILITIES_LEN 12
|
||||
extern uint8_t usbtoxxx_abilities[USB_TO_XXX_ABILITIES_LEN];
|
||||
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]);
|
||||
|
||||
// USB_TO_DELAY
|
||||
/* USB_TO_DELAY */
|
||||
RESULT usbtodelay_delay(uint16_t dly);
|
||||
RESULT usbtodelay_delayms(uint16_t ms);
|
||||
RESULT usbtodelay_delayus(uint16_t us);
|
||||
|
||||
|
||||
|
||||
// USB_TO_USART
|
||||
/* USB_TO_USART */
|
||||
RESULT usbtousart_init(uint8_t interface_index);
|
||||
RESULT usbtousart_fini(uint8_t interface_index);
|
||||
RESULT usbtousart_config(uint8_t interface_index, uint32_t baudrate,
|
||||
uint8_t datalength, uint8_t mode);
|
||||
uint8_t datalength, uint8_t mode);
|
||||
RESULT usbtousart_send(uint8_t interface_index, uint8_t *buf, uint16_t len);
|
||||
RESULT usbtousart_receive(uint8_t interface_index, uint8_t *buf, uint16_t len);
|
||||
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_fini(uint8_t interface_index);
|
||||
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,
|
||||
uint16_t bytelen);
|
||||
uint16_t bytelen);
|
||||
|
||||
|
||||
|
||||
// USB_TO_GPIO
|
||||
/* USB_TO_GPIO */
|
||||
RESULT usbtogpio_init(uint8_t interface_index);
|
||||
RESULT usbtogpio_fini(uint8_t interface_index);
|
||||
RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask,
|
||||
uint32_t dir_mask, uint32_t pull_en_mask,
|
||||
uint32_t input_pull_mask);
|
||||
uint32_t dir_mask, uint32_t pull_en_mask,
|
||||
uint32_t input_pull_mask);
|
||||
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);
|
||||
|
||||
|
||||
|
||||
// USB_TO_ISSP
|
||||
/* USB_TO_ISSP */
|
||||
RESULT usbtoissp_init(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_leave_program_mode(uint8_t interface_index, uint8_t mode);
|
||||
RESULT usbtoissp_wait_and_poll(uint8_t interface_index);
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtolpcicp_config(uint8_t interface_index);
|
||||
|
@ -86,51 +79,42 @@ RESULT usbtolpcicp_enter_program_mode(uint8_t interface_index);
|
|||
RESULT usbtolpcicp_in(uint8_t interface_index, uint8_t *buff, uint16_t len);
|
||||
RESULT usbtolpcicp_out(uint8_t interface_index, uint8_t *buff, uint16_t len);
|
||||
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_fini(uint8_t interface_index);
|
||||
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_clocks(uint8_t interface_index, uint32_t bytelen,
|
||||
uint8_t tms);
|
||||
RESULT usbtojtagll_scan(uint8_t interface_index, uint8_t* data,
|
||||
uint16_t bitlen, uint8_t tms_before_valid,
|
||||
uint8_t tms_before, uint8_t tms_after0,
|
||||
uint8_t tms_after1);
|
||||
uint8_t tms);
|
||||
RESULT usbtojtagll_scan(uint8_t interface_index, uint8_t *data,
|
||||
uint16_t bitlen, uint8_t tms_before_valid,
|
||||
uint8_t tms_before, uint8_t tms_after0,
|
||||
uint8_t tms_after1);
|
||||
|
||||
|
||||
|
||||
// USB_TO_JTAG_HL
|
||||
/* USB_TO_JTAG_HL */
|
||||
RESULT usbtojtaghl_init(uint8_t interface_index);
|
||||
RESULT usbtojtaghl_fini(uint8_t interface_index);
|
||||
RESULT usbtojtaghl_config(uint8_t interface_index, uint32_t kHz, uint8_t ub,
|
||||
uint8_t ua, uint16_t bb, uint16_t ba);
|
||||
uint8_t ua, uint16_t bb, uint16_t ba);
|
||||
RESULT usbtojtaghl_ir(uint8_t interface_index, uint8_t *ir, uint16_t bitlen,
|
||||
uint8_t idle, uint8_t want_ret);
|
||||
uint8_t idle, uint8_t want_ret);
|
||||
RESULT usbtojtaghl_dr(uint8_t interface_index, uint8_t *dr, uint16_t bitlen,
|
||||
uint8_t idle, uint8_t want_ret);
|
||||
uint8_t idle, uint8_t want_ret);
|
||||
RESULT usbtojtaghl_tms(uint8_t interface_index, uint8_t *tms, uint16_t bitlen);
|
||||
RESULT usbtojtaghl_runtest(uint8_t interface_index, uint32_t cycles);
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t kHz);
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtoc2_writeaddr(uint8_t interface_index, uint8_t addr);
|
||||
|
@ -138,141 +122,117 @@ 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_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_fini(uint8_t interface_index);
|
||||
RESULT usbtoi2c_config(uint8_t interface_index, uint16_t kHz,
|
||||
uint16_t byte_interval, uint16_t max_dly);
|
||||
uint16_t byte_interval, uint16_t max_dly);
|
||||
RESULT usbtoi2c_read(uint8_t interface_index, uint16_t chip_addr,
|
||||
uint8_t *data, uint16_t data_len, uint8_t stop,
|
||||
bool nacklast);
|
||||
uint8_t *data, uint16_t data_len, uint8_t stop,
|
||||
bool nacklast);
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtomsp430jtag_config(uint8_t interface_index, uint8_t has_test);
|
||||
RESULT usbtomsp430jtag_ir(uint8_t interface_index, uint8_t *ir,
|
||||
uint8_t want_ret);
|
||||
uint8_t want_ret);
|
||||
RESULT usbtomsp430jtag_dr(uint8_t interface_index, uint32_t *dr,
|
||||
uint8_t bitlen, uint8_t want_ret);
|
||||
uint8_t bitlen, uint8_t want_ret);
|
||||
RESULT usbtomsp430jtag_tclk(uint8_t interface_index, uint8_t value);
|
||||
RESULT usbtomsp430jtag_tclk_strobe(uint8_t interface_index, uint16_t cnt);
|
||||
RESULT usbtomsp430jtag_reset(uint8_t interface_index);
|
||||
RESULT usbtomsp430jtag_poll(uint8_t interface_index, uint32_t dr,
|
||||
uint32_t mask, uint32_t value, uint8_t len,
|
||||
uint16_t poll_cnt, uint8_t toggle_tclk);
|
||||
uint32_t mask, uint32_t value, uint8_t len,
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtomsp430sbw_config(uint8_t interface_index, uint8_t has_test);
|
||||
RESULT usbtomsp430sbw_ir(uint8_t interface_index, uint8_t *ir,
|
||||
uint8_t want_ret);
|
||||
uint8_t want_ret);
|
||||
RESULT usbtomsp430sbw_dr(uint8_t interface_index, uint32_t *dr,
|
||||
uint8_t bitlen, uint8_t want_ret);
|
||||
uint8_t bitlen, uint8_t want_ret);
|
||||
RESULT usbtomsp430sbw_tclk(uint8_t interface_index, uint8_t value);
|
||||
RESULT usbtomsp430sbw_tclk_strobe(uint8_t interface_index, uint16_t cnt);
|
||||
RESULT usbtomsp430sbw_reset(uint8_t interface_index);
|
||||
RESULT usbtomsp430sbw_poll(uint8_t interface_index, uint32_t dr, uint32_t mask,
|
||||
uint32_t value, uint8_t len, uint16_t poll_cnt,
|
||||
uint8_t toggle_tclk);
|
||||
uint32_t value, uint8_t len, uint16_t poll_cnt,
|
||||
uint8_t toggle_tclk);
|
||||
|
||||
|
||||
|
||||
// USB_TO_POWER
|
||||
/* USB_TO_POWER */
|
||||
RESULT usbtopwr_init(uint8_t interface_index);
|
||||
RESULT usbtopwr_fini(uint8_t interface_index);
|
||||
RESULT usbtopwr_config(uint8_t interface_index);
|
||||
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_end(void);
|
||||
RESULT usbtopoll_checkok(uint8_t equ, uint16_t offset, uint8_t size,
|
||||
uint32_t mask, uint32_t value);
|
||||
uint32_t mask, uint32_t value);
|
||||
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);
|
||||
|
||||
|
||||
|
||||
// USB_TO_SWD
|
||||
/* USB_TO_SWD */
|
||||
RESULT usbtoswd_init(uint8_t interface_index);
|
||||
RESULT usbtoswd_fini(uint8_t interface_index);
|
||||
RESULT usbtoswd_config(uint8_t interface_index, uint8_t trn, uint16_t retry,
|
||||
uint16_t dly);
|
||||
uint16_t dly);
|
||||
RESULT usbtoswd_seqout(uint8_t interface_index, uint8_t *data, uint16_t bitlen);
|
||||
RESULT usbtoswd_seqin(uint8_t interface_index, uint8_t *data, uint16_t bitlen);
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtoswim_config(uint8_t interface_index, uint8_t mHz, uint8_t cnt0,
|
||||
uint8_t cnt1);
|
||||
uint8_t cnt1);
|
||||
RESULT usbtoswim_srst(uint8_t interface_index);
|
||||
RESULT usbtoswim_wotf(uint8_t interface_index, uint8_t *data,
|
||||
uint16_t bytelen, uint32_t addr);
|
||||
uint16_t bytelen, uint32_t addr);
|
||||
RESULT usbtoswim_rotf(uint8_t interface_index, uint8_t *data,
|
||||
uint16_t bytelen, uint32_t addr);
|
||||
uint16_t bytelen, uint32_t addr);
|
||||
RESULT usbtoswim_sync(uint8_t interface_index, uint8_t mHz);
|
||||
RESULT usbtoswim_enable(uint8_t interface_index);
|
||||
|
||||
|
||||
|
||||
|
||||
// USB_TO_BDM
|
||||
/* USB_TO_BDM */
|
||||
RESULT usbtobdm_init(uint8_t interface_index);
|
||||
RESULT usbtobdm_fini(uint8_t interface_index);
|
||||
RESULT usbtobdm_sync(uint8_t interface_index, uint16_t *khz);
|
||||
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_fini(uint8_t interface_index);
|
||||
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,
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtomicrowire_config(uint8_t interface_index, uint16_t kHz,
|
||||
uint8_t sel_polarity);
|
||||
uint8_t sel_polarity);
|
||||
RESULT usbtomicrowire_transport(uint8_t interface_index,
|
||||
uint32_t opcode, uint8_t opcode_bitlen,
|
||||
uint32_t addr, uint8_t addr_bitlen,
|
||||
uint32_t data, uint8_t data_bitlen,
|
||||
uint8_t *reply, uint8_t reply_bitlen);
|
||||
uint32_t opcode, uint8_t opcode_bitlen,
|
||||
uint32_t addr, uint8_t addr_bitlen,
|
||||
uint32_t data, uint8_t data_bitlen,
|
||||
uint8_t *reply, uint8_t reply_bitlen);
|
||||
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_fini(uint8_t interface_index);
|
||||
RESULT usbtopwm_config(uint8_t interface_index, uint16_t kHz, uint8_t mode);
|
||||
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);
|
||||
|
||||
#endif /* __USBTOXXX_H_INCLUDED__ */
|
||||
|
||||
#endif /* __USBTOXXX_H_INCLUDED__ */
|
||||
|
|
|
@ -16,154 +16,148 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __USBTOXXX_INTERNAL_H_INCLUDED__
|
||||
#define __USBTOXXX_INTERNAL_H_INCLUDED__
|
||||
|
||||
// USB_TO_XXX USB Commands
|
||||
// Page0
|
||||
#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_I2C (VERSALOON_USB_TO_XXX_CMD_START + 0x02)
|
||||
#define USB_TO_GPIO (VERSALOON_USB_TO_XXX_CMD_START + 0x03)
|
||||
#define USB_TO_CAN (VERSALOON_USB_TO_XXX_CMD_START + 0x04)
|
||||
#define USB_TO_PWM (VERSALOON_USB_TO_XXX_CMD_START + 0x05)
|
||||
#define USB_TO_ADC (VERSALOON_USB_TO_XXX_CMD_START + 0x06)
|
||||
#define USB_TO_DAC (VERSALOON_USB_TO_XXX_CMD_START + 0x07)
|
||||
#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_DUSI (VERSALOON_USB_TO_XXX_CMD_START + 0x0A)
|
||||
// Page1
|
||||
#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_ISSP (VERSALOON_USB_TO_XXX_CMD_START + 0x22)
|
||||
#define USB_TO_C2 (VERSALOON_USB_TO_XXX_CMD_START + 0x23)
|
||||
#define USB_TO_SBW (VERSALOON_USB_TO_XXX_CMD_START + 0x24)
|
||||
#define USB_TO_LPCICP (VERSALOON_USB_TO_XXX_CMD_START + 0x25)
|
||||
#define USB_TO_SWD (VERSALOON_USB_TO_XXX_CMD_START + 0x26)
|
||||
#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_MSP430_JTAG (VERSALOON_USB_TO_XXX_CMD_START + 0x38)
|
||||
// Page2
|
||||
#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_POLL (VERSALOON_USB_TO_XXX_CMD_START + 0x42)
|
||||
#define USB_TO_INFO (VERSALOON_USB_TO_XXX_CMD_START + 0x5E)
|
||||
#define USB_TO_ALL (VERSALOON_USB_TO_XXX_CMD_START + 0x5F)
|
||||
/* USB_TO_XXX USB Commands */
|
||||
/* Page0 */
|
||||
#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_I2C (VERSALOON_USB_TO_XXX_CMD_START + 0x02)
|
||||
#define USB_TO_GPIO (VERSALOON_USB_TO_XXX_CMD_START + 0x03)
|
||||
#define USB_TO_CAN (VERSALOON_USB_TO_XXX_CMD_START + 0x04)
|
||||
#define USB_TO_PWM (VERSALOON_USB_TO_XXX_CMD_START + 0x05)
|
||||
#define USB_TO_ADC (VERSALOON_USB_TO_XXX_CMD_START + 0x06)
|
||||
#define USB_TO_DAC (VERSALOON_USB_TO_XXX_CMD_START + 0x07)
|
||||
#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_DUSI (VERSALOON_USB_TO_XXX_CMD_START + 0x0A)
|
||||
/* Page1 */
|
||||
#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_ISSP (VERSALOON_USB_TO_XXX_CMD_START + 0x22)
|
||||
#define USB_TO_C2 (VERSALOON_USB_TO_XXX_CMD_START + 0x23)
|
||||
#define USB_TO_SBW (VERSALOON_USB_TO_XXX_CMD_START + 0x24)
|
||||
#define USB_TO_LPCICP (VERSALOON_USB_TO_XXX_CMD_START + 0x25)
|
||||
#define USB_TO_SWD (VERSALOON_USB_TO_XXX_CMD_START + 0x26)
|
||||
#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_MSP430_JTAG (VERSALOON_USB_TO_XXX_CMD_START + 0x38)
|
||||
/* Page2 */
|
||||
#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_POLL (VERSALOON_USB_TO_XXX_CMD_START + 0x42)
|
||||
#define USB_TO_INFO (VERSALOON_USB_TO_XXX_CMD_START + 0x5E)
|
||||
#define USB_TO_ALL (VERSALOON_USB_TO_XXX_CMD_START + 0x5F)
|
||||
|
||||
/* USB_TO_XXX Masks */
|
||||
#define USB_TO_XXX_CMDMASK 0xF8
|
||||
#define USB_TO_XXX_CMDSHIFT 3
|
||||
#define USB_TO_XXX_IDXMASK 0x07
|
||||
/* USB_TO_XXX Sub Commands */
|
||||
/* Common Sub Commands */
|
||||
#define USB_TO_XXX_INIT (0x00 << 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_GETHWINFO (0x03 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_STATUS (0X04 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_IN_OUT (0x05 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_IN (0x06 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_OUT (0x07 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_POLL (0x08 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_SPECIAL (0x09 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_RESET (0x0A << 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_DISABLE (0x0D << USB_TO_XXX_CMDSHIFT)
|
||||
/* USB_TO_POLL */
|
||||
#define USB_TO_POLL_START 0x00
|
||||
#define USB_TO_POLL_END 0x01
|
||||
#define USB_TO_POLL_CHECKOK 0x02
|
||||
#define USB_TO_POLL_CHECKFAIL 0x03
|
||||
#define USB_TO_POLL_VERIFYBUFF 0x04
|
||||
|
||||
/* USB_TO_XXX Replys */
|
||||
#define USB_TO_XXX_OK 0x00
|
||||
#define USB_TO_XXX_FAILED 0x01
|
||||
#define USB_TO_XXX_TIME_OUT 0x02
|
||||
#define USB_TO_XXX_INVALID_INDEX 0x03
|
||||
#define USB_TO_XXX_INVALID_PARA 0x04
|
||||
#define USB_TO_XXX_INVALID_CMD 0x05
|
||||
#define USB_TO_XXX_CMD_NOT_SUPPORT 0x06
|
||||
|
||||
// USB_TO_XXX Masks
|
||||
#define USB_TO_XXX_CMDMASK 0xF8
|
||||
#define USB_TO_XXX_CMDSHIFT 3
|
||||
#define USB_TO_XXX_IDXMASK 0x07
|
||||
// USB_TO_XXX Sub Commands
|
||||
// Common Sub Commands
|
||||
#define USB_TO_XXX_INIT (0x00 << 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_GETHWINFO (0x03 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_STATUS (0X04 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_IN_OUT (0x05 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_IN (0x06 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_OUT (0x07 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_POLL (0x08 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_SPECIAL (0x09 << USB_TO_XXX_CMDSHIFT)
|
||||
#define USB_TO_XXX_RESET (0x0A << 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_DISABLE (0x0D << USB_TO_XXX_CMDSHIFT)
|
||||
// USB_TO_POLL
|
||||
#define USB_TO_POLL_START 0x00
|
||||
#define USB_TO_POLL_END 0x01
|
||||
#define USB_TO_POLL_CHECKOK 0x02
|
||||
#define USB_TO_POLL_CHECKFAIL 0x03
|
||||
#define USB_TO_POLL_VERIFYBUFF 0x04
|
||||
|
||||
|
||||
|
||||
// USB_TO_XXX Replys
|
||||
#define USB_TO_XXX_OK 0x00
|
||||
#define USB_TO_XXX_FAILED 0x01
|
||||
#define USB_TO_XXX_TIME_OUT 0x02
|
||||
#define USB_TO_XXX_INVALID_INDEX 0x03
|
||||
#define USB_TO_XXX_INVALID_PARA 0x04
|
||||
#define USB_TO_XXX_INVALID_CMD 0x05
|
||||
#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
|
||||
actual_szie, uint16_t want_pos,
|
||||
uint16_t want_size, uint8_t *buffer);
|
||||
actual_szie, uint16_t want_pos,
|
||||
uint16_t want_size, uint8_t *buffer);
|
||||
|
||||
RESULT usbtoxxx_add_command(uint8_t type, uint8_t cmd, uint8_t *cmdbuf,
|
||||
uint16_t cmdlen, uint16_t retlen,
|
||||
uint8_t *wantbuf, uint16_t wantpos,
|
||||
uint16_t wantlen, uint8_t collect);
|
||||
uint16_t cmdlen, uint16_t retlen,
|
||||
uint8_t *wantbuf, uint16_t wantpos,
|
||||
uint16_t wantlen, uint8_t collect);
|
||||
|
||||
#define usbtoxxx_init_command(type, port) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_INIT | (port)), \
|
||||
NULL, 0, 0, NULL, 0, 0, 0)
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_INIT | (port)), \
|
||||
NULL, 0, 0, NULL, 0, 0, 0)
|
||||
#define usbtoxxx_fini_command(type, port) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_FINI | (port)), \
|
||||
NULL, 0, 0, NULL, 0, 0, 0)
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_FINI | (port)), \
|
||||
NULL, 0, 0, NULL, 0, 0, 0)
|
||||
#define usbtoxxx_conf_command(type, port, cmdbuf, cmdlen) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_CONFIG | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_CONFIG | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
#define usbtoxxx_inout_command(type, port, cmdbuf, cmdlen, retlen, wantbuf, \
|
||||
wantpos, wantlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_IN_OUT | (port)), \
|
||||
(cmdbuf), (cmdlen), (retlen), (wantbuf), \
|
||||
(wantpos), (wantlen), (c))
|
||||
wantpos, wantlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_IN_OUT | (port)), \
|
||||
(cmdbuf), (cmdlen), (retlen), (wantbuf), \
|
||||
(wantpos), (wantlen), (c))
|
||||
#define usbtoxxx_in_command(type, port, cmdbuf, cmdlen, retlen, wantbuf, \
|
||||
wantpos, wantlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_IN | (port)), (cmdbuf), \
|
||||
(cmdlen), (retlen), (wantbuf), (wantpos), \
|
||||
(wantlen), (c))
|
||||
wantpos, wantlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_IN | (port)), (cmdbuf), \
|
||||
(cmdlen), (retlen), (wantbuf), (wantpos), \
|
||||
(wantlen), (c))
|
||||
#define usbtoxxx_out_command(type, port, cmdbuf, cmdlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_OUT | (port)), (cmdbuf), \
|
||||
(cmdlen), 0, NULL, 0, 0, (c))
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_OUT | (port)), (cmdbuf), \
|
||||
(cmdlen), 0, NULL, 0, 0, (c))
|
||||
#define usbtoxxx_poll_command(type, port, cmdbuf, cmdlen, retbuf, retlen) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_POLL | (port)), (cmdbuf),\
|
||||
(cmdlen), (retlen), (retbuf), 0, (retlen), 0)
|
||||
#define usbtoxxx_status_command(type, port, retlen, wantbuf, wantpos, wantlen, c)\
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_STATUS | (port)), \
|
||||
NULL, 0, (retlen), (wantbuf), (wantpos), \
|
||||
(wantlen), (c))
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_POLL | (port)), (cmdbuf), \
|
||||
(cmdlen), (retlen), (retbuf), 0, (retlen), 0)
|
||||
#define usbtoxxx_status_command(type, port, retlen, wantbuf, wantpos, wantlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_STATUS | (port)), \
|
||||
NULL, 0, (retlen), (wantbuf), (wantpos), \
|
||||
(wantlen), (c))
|
||||
#define usbtoxxx_special_command(type, port, cmdbuf, cmdlen, retlen, wantbuf, \
|
||||
wantpos, wantlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_SPECIAL | (port)), \
|
||||
(cmdbuf), (cmdlen), retlen, wantbuf, \
|
||||
wantpos, wantlen, (c))
|
||||
wantpos, wantlen, c) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_SPECIAL | (port)), \
|
||||
(cmdbuf), (cmdlen), retlen, wantbuf, \
|
||||
wantpos, wantlen, (c))
|
||||
#define usbtoxxx_reset_command(type, port, cmdbuf, cmdlen) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_RESET | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_RESET | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
#define usbtoxxx_sync_command(type, port, cmdbuf, cmdlen, retlen, wantbuf) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_SYNC | (port)), \
|
||||
(cmdbuf), (cmdlen), (retlen), (wantbuf), 0, \
|
||||
(retlen), 0)
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_SYNC | (port)), \
|
||||
(cmdbuf), (cmdlen), (retlen), (wantbuf), 0, \
|
||||
(retlen), 0)
|
||||
#define usbtoxxx_enable_command(type, port, cmdbuf, cmdlen) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_ENABLE | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_ENABLE | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
#define usbtoxxx_disable_command(type, port, cmdbuf, cmdlen) \
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_DISABLE | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
usbtoxxx_add_command((type), (USB_TO_XXX_DISABLE | (port)), \
|
||||
(cmdbuf), (cmdlen), 0, NULL, 0, 0, 0)
|
||||
|
||||
// USB_TO_SPI
|
||||
/* USB_TO_SPI */
|
||||
#define USB_TO_SPI_BAUDRATE_MSK 0x1F
|
||||
#define USB_TO_SPI_CPOL_MSK 0x20
|
||||
#define USB_TO_SPI_CPHA_MSK 0x40
|
||||
#define USB_TO_SPI_MSB_FIRST 0x80
|
||||
|
||||
// USB_TO_DUSI
|
||||
/* USB_TO_DUSI */
|
||||
#define USB_TO_DUSI_BAUDRATE_MSK 0x1F
|
||||
#define USB_TO_DUSI_CPOL_MSK 0x20
|
||||
#define USB_TO_DUSI_CPHA_MSK 0x40
|
||||
#define USB_TO_DUSI_MSB_FIRST 0x80
|
||||
|
||||
// USB_TO_GPIO
|
||||
/* USB_TO_GPIO */
|
||||
#define USB_TO_GPIO_DIR_MSK 0x01
|
||||
|
||||
#endif /* __USBTOXXX_INTERNAL_H_INCLUDED__ */
|
||||
|
||||
#endif /* __USBTOXXX_INTERNAL_H_INCLUDED__ */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -28,14 +29,14 @@
|
|||
#include "versaloon_internal.h"
|
||||
#include "usbtoxxx/usbtoxxx.h"
|
||||
|
||||
uint8_t *versaloon_buf = NULL;
|
||||
uint8_t *versaloon_cmd_buf = NULL;
|
||||
uint8_t *versaloon_buf;
|
||||
uint8_t *versaloon_cmd_buf;
|
||||
uint16_t versaloon_buf_size;
|
||||
|
||||
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;
|
||||
|
||||
RESULT versaloon_init(void);
|
||||
|
@ -44,58 +45,59 @@ RESULT versaloon_get_target_voltage(uint16_t *voltage);
|
|||
RESULT versaloon_set_target_voltage(uint16_t voltage);
|
||||
RESULT versaloon_delay_ms(uint16_t ms);
|
||||
RESULT versaloon_delay_us(uint16_t us);
|
||||
struct versaloon_interface_t versaloon_interface =
|
||||
{
|
||||
.init = versaloon_init,
|
||||
.fini = versaloon_fini,
|
||||
{// adaptors
|
||||
{// target_voltage
|
||||
.get = versaloon_get_target_voltage,
|
||||
.set = versaloon_set_target_voltage,
|
||||
|
||||
struct versaloon_interface_t versaloon_interface = {
|
||||
.init = versaloon_init,
|
||||
.fini = versaloon_fini,
|
||||
{ /* adaptors */
|
||||
{ /* target_voltage */
|
||||
.get = versaloon_get_target_voltage,
|
||||
.set = versaloon_set_target_voltage,
|
||||
},
|
||||
{// gpio
|
||||
.init = usbtogpio_init,
|
||||
.fini = usbtogpio_fini,
|
||||
.config = usbtogpio_config,
|
||||
.out = usbtogpio_out,
|
||||
.in = usbtogpio_in,
|
||||
{ /* gpio */
|
||||
.init = usbtogpio_init,
|
||||
.fini = usbtogpio_fini,
|
||||
.config = usbtogpio_config,
|
||||
.out = usbtogpio_out,
|
||||
.in = usbtogpio_in,
|
||||
},
|
||||
{// delay
|
||||
.delayms = versaloon_delay_ms,
|
||||
.delayus = versaloon_delay_us,
|
||||
{ /* delay */
|
||||
.delayms = versaloon_delay_ms,
|
||||
.delayus = versaloon_delay_us,
|
||||
},
|
||||
{// swd
|
||||
.init = usbtoswd_init,
|
||||
.fini = usbtoswd_fini,
|
||||
.config = usbtoswd_config,
|
||||
.seqout = usbtoswd_seqout,
|
||||
.seqin = usbtoswd_seqin,
|
||||
.transact = usbtoswd_transact,
|
||||
{ /* swd */
|
||||
.init = usbtoswd_init,
|
||||
.fini = usbtoswd_fini,
|
||||
.config = usbtoswd_config,
|
||||
.seqout = usbtoswd_seqout,
|
||||
.seqin = usbtoswd_seqin,
|
||||
.transact = usbtoswd_transact,
|
||||
},
|
||||
{// jtag_raw
|
||||
.init = usbtojtagraw_init,
|
||||
.fini = usbtojtagraw_fini,
|
||||
.config = usbtojtagraw_config,
|
||||
.execute = usbtojtagraw_execute,
|
||||
{ /* jtag_raw */
|
||||
.init = usbtojtagraw_init,
|
||||
.fini = usbtojtagraw_fini,
|
||||
.config = usbtojtagraw_config,
|
||||
.execute = usbtojtagraw_execute,
|
||||
},
|
||||
.peripheral_commit = usbtoxxx_execute_command,
|
||||
.peripheral_commit = usbtoxxx_execute_command,
|
||||
},
|
||||
{// usb_setting
|
||||
.vid = VERSALOON_VID,
|
||||
.pid = VERSALOON_PID,
|
||||
.ep_out = VERSALOON_OUTP,
|
||||
.ep_in = VERSALOON_INP,
|
||||
.interface = VERSALOON_IFACE,
|
||||
.serialstring = NULL,
|
||||
.buf_size = 256,
|
||||
{ /* usb_setting */
|
||||
.vid = VERSALOON_VID,
|
||||
.pid = VERSALOON_PID,
|
||||
.ep_out = VERSALOON_OUTP,
|
||||
.ep_in = VERSALOON_INP,
|
||||
.interface = VERSALOON_IFACE,
|
||||
.serialstring = NULL,
|
||||
.buf_size = 256,
|
||||
}
|
||||
};
|
||||
|
||||
// programmer_cmd
|
||||
static uint32_t versaloon_pending_id = 0;
|
||||
static versaloon_callback_t versaloon_callback = NULL;
|
||||
static void *versaloon_extra_data = NULL;
|
||||
static struct versaloon_want_pos_t *versaloon_want_pos = NULL;
|
||||
/* programmer_cmd */
|
||||
static uint32_t versaloon_pending_id;
|
||||
static versaloon_callback_t versaloon_callback;
|
||||
static void *versaloon_extra_data;
|
||||
static struct versaloon_want_pos_t *versaloon_want_pos;
|
||||
|
||||
void versaloon_set_pending_id(uint32_t id)
|
||||
{
|
||||
versaloon_pending_id = id;
|
||||
|
@ -104,7 +106,7 @@ void versaloon_set_callback(versaloon_callback_t callback)
|
|||
{
|
||||
versaloon_callback = callback;
|
||||
}
|
||||
void versaloon_set_extra_data(void * p)
|
||||
void versaloon_set_extra_data(void *p)
|
||||
{
|
||||
versaloon_extra_data = p;
|
||||
}
|
||||
|
@ -115,19 +117,16 @@ void versaloon_free_want_pos(void)
|
|||
struct versaloon_want_pos_t *tmp, *free_tmp;
|
||||
|
||||
tmp = versaloon_want_pos;
|
||||
while (tmp != NULL)
|
||||
{
|
||||
while (tmp != NULL) {
|
||||
free_tmp = tmp;
|
||||
tmp = tmp->next;
|
||||
free(free_tmp);
|
||||
}
|
||||
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;
|
||||
while (tmp != NULL)
|
||||
{
|
||||
while (tmp != NULL) {
|
||||
free_tmp = tmp;
|
||||
tmp = tmp->next;
|
||||
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;
|
||||
|
||||
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);
|
||||
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;
|
||||
|
||||
if (NULL == versaloon_want_pos)
|
||||
{
|
||||
versaloon_want_pos = new_pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
struct versaloon_want_pos_t *tmp = versaloon_want_pos;
|
||||
|
||||
while (tmp->next != NULL)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
}
|
||||
tmp->next = new_pos;
|
||||
}
|
||||
|
||||
|
@ -173,10 +166,9 @@ 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)
|
||||
{
|
||||
#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,
|
||||
"versaloon pending data");
|
||||
"versaloon pending data");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
@ -206,83 +198,68 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen)
|
|||
int ret;
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (NULL == versaloon_buf)
|
||||
{
|
||||
if (NULL == versaloon_buf) {
|
||||
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
|
||||
return ERRCODE_INVALID_BUFFER;
|
||||
}
|
||||
if ((0 == out_len) || (out_len > versaloon_interface.usb_setting.buf_size))
|
||||
{
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
|
||||
if ((0 == out_len) || (out_len > versaloon_interface.usb_setting.buf_size)) {
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
|
||||
return ERRCODE_INVALID_PARAMETER;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = usb_bulk_write(versaloon_usb_device_handle,
|
||||
versaloon_interface.usb_setting.ep_out, (char *)versaloon_buf,
|
||||
out_len, versaloon_usb_to);
|
||||
if (ret != out_len)
|
||||
{
|
||||
versaloon_interface.usb_setting.ep_out, (char *)versaloon_buf,
|
||||
out_len, versaloon_usb_to);
|
||||
if (ret != out_len) {
|
||||
LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "send usb data",
|
||||
usb_strerror());
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
|
||||
if (inlen != NULL)
|
||||
{
|
||||
if (inlen != NULL) {
|
||||
ret = usb_bulk_read(versaloon_usb_device_handle,
|
||||
versaloon_interface.usb_setting.ep_in, (char *)versaloon_buf,
|
||||
versaloon_interface.usb_setting.buf_size, versaloon_usb_to);
|
||||
if (ret > 0)
|
||||
{
|
||||
versaloon_interface.usb_setting.ep_in, (char *)versaloon_buf,
|
||||
versaloon_interface.usb_setting.buf_size, versaloon_usb_to);
|
||||
if (ret > 0) {
|
||||
*inlen = (uint16_t)ret;
|
||||
return ERROR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "receive usb data",
|
||||
usb_strerror());
|
||||
usb_strerror());
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
return ERROR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#define VERSALOON_RETRY_CNT 10
|
||||
#define VERSALOON_RETRY_CNT 10
|
||||
RESULT versaloon_init(void)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
uint8_t retry;
|
||||
uint32_t timeout_tmp;
|
||||
|
||||
// malloc temporary buffer
|
||||
/* malloc temporary buffer */
|
||||
versaloon_buf =
|
||||
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
|
||||
if (NULL == versaloon_buf)
|
||||
{
|
||||
if (NULL == versaloon_buf) {
|
||||
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
|
||||
return ERRCODE_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// connect to versaloon
|
||||
/* connect to versaloon */
|
||||
timeout_tmp = versaloon_usb_to;
|
||||
// not output error message when connectting
|
||||
// 100ms delay when connect
|
||||
/* not output error message when connectting */
|
||||
/* 100ms delay when connect */
|
||||
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;
|
||||
if ((ERROR_OK == versaloon_send_command(1, &ret)) && (ret >= 3))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
versaloon_usb_to = timeout_tmp;
|
||||
if (VERSALOON_RETRY_CNT == retry)
|
||||
{
|
||||
if (VERSALOON_RETRY_CNT == retry) {
|
||||
versaloon_fini();
|
||||
LOG_ERROR(ERRMSG_FAILURE_OPERATION, "communicate with versaloon");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
|
@ -293,28 +270,25 @@ RESULT versaloon_init(void)
|
|||
versaloon_interface.usb_setting.buf_size = versaloon_buf_size;
|
||||
LOG_INFO("%s", versaloon_buf + 2);
|
||||
|
||||
// free temporary buffer
|
||||
/* free temporary buffer */
|
||||
free(versaloon_buf);
|
||||
versaloon_buf = NULL;
|
||||
|
||||
versaloon_buf =
|
||||
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
|
||||
if (NULL == versaloon_buf)
|
||||
{
|
||||
if (NULL == versaloon_buf) {
|
||||
versaloon_fini();
|
||||
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
|
||||
return ERRCODE_NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
versaloon_cmd_buf =
|
||||
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size - 3);
|
||||
if (NULL == versaloon_cmd_buf)
|
||||
{
|
||||
if (NULL == versaloon_cmd_buf) {
|
||||
versaloon_fini();
|
||||
LOG_ERROR(ERRMSG_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");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -323,20 +297,17 @@ RESULT versaloon_init(void)
|
|||
|
||||
RESULT versaloon_fini(void)
|
||||
{
|
||||
if (versaloon_usb_device_handle != NULL)
|
||||
{
|
||||
if (versaloon_usb_device_handle != NULL) {
|
||||
usbtoxxx_fini();
|
||||
versaloon_free_want_pos();
|
||||
|
||||
versaloon_usb_device_handle = NULL;
|
||||
|
||||
if (versaloon_buf != NULL)
|
||||
{
|
||||
if (versaloon_buf != NULL) {
|
||||
free(versaloon_buf);
|
||||
versaloon_buf = NULL;
|
||||
}
|
||||
if (versaloon_cmd_buf != NULL)
|
||||
{
|
||||
if (versaloon_cmd_buf != NULL) {
|
||||
free(versaloon_cmd_buf);
|
||||
versaloon_cmd_buf = NULL;
|
||||
}
|
||||
|
@ -360,27 +331,22 @@ RESULT versaloon_get_target_voltage(uint16_t *voltage)
|
|||
uint16_t inlen;
|
||||
|
||||
#if PARAM_CHECK
|
||||
if (NULL == versaloon_buf)
|
||||
{
|
||||
if (NULL == versaloon_buf) {
|
||||
LOG_BUG(ERRMSG_INVALID_BUFFER, TO_STR(versaloon_buf));
|
||||
return ERRCODE_INVALID_BUFFER;
|
||||
}
|
||||
if (NULL == voltage)
|
||||
{
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
|
||||
if (NULL == voltage) {
|
||||
LOG_BUG(ERRMSG_INVALID_PARAMETER, __func__);
|
||||
return ERRCODE_INVALID_PARAMETER;
|
||||
}
|
||||
#endif
|
||||
|
||||
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");
|
||||
return ERRCODE_FAILURE_OPERATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*voltage = versaloon_buf[0] + (versaloon_buf[1] << 8);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -395,4 +361,3 @@ RESULT versaloon_delay_us(uint16_t us)
|
|||
{
|
||||
return usbtodelay_delay(us & 0x7FFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __VERSALOON_H_INCLUDED__
|
||||
#define __VERSALOON_H_INCLUDED__
|
||||
|
||||
struct usart_status_t
|
||||
{
|
||||
struct usart_status_t {
|
||||
uint32_t tx_buff_avail;
|
||||
uint32_t tx_buff_size;
|
||||
uint32_t rx_buff_avail;
|
||||
|
@ -29,7 +29,7 @@ struct usart_status_t
|
|||
|
||||
#include "usbtoxxx/usbtoxxx.h"
|
||||
|
||||
// GPIO pins
|
||||
/* GPIO pins */
|
||||
#define GPIO_SRST (1 << 0)
|
||||
#define GPIO_TRST (1 << 1)
|
||||
#define GPIO_USR1 (1 << 2)
|
||||
|
@ -39,61 +39,55 @@ struct usart_status_t
|
|||
#define GPIO_TDI (1 << 6)
|
||||
#define GPIO_RTCK (1 << 7)
|
||||
#define GPIO_TMS (1 << 8)
|
||||
struct interface_gpio_t
|
||||
{
|
||||
RESULT (*init)(uint8_t interface_index);
|
||||
RESULT (*fini)(uint8_t interface_index);
|
||||
RESULT (*config)(uint8_t interface_index, uint32_t pin_mask, uint32_t io,
|
||||
uint32_t pull_en_mask, uint32_t input_pull_mask);
|
||||
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);
|
||||
|
||||
struct interface_gpio_t {
|
||||
RESULT(*init)(uint8_t interface_index);
|
||||
RESULT(*fini)(uint8_t interface_index);
|
||||
RESULT(*config)(uint8_t interface_index, uint32_t pin_mask, uint32_t io,
|
||||
uint32_t pull_en_mask, uint32_t input_pull_mask);
|
||||
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);
|
||||
};
|
||||
|
||||
struct interface_delay_t
|
||||
{
|
||||
RESULT (*delayms)(uint16_t ms);
|
||||
RESULT (*delayus)(uint16_t us);
|
||||
struct interface_delay_t {
|
||||
RESULT(*delayms)(uint16_t ms);
|
||||
RESULT(*delayus)(uint16_t us);
|
||||
};
|
||||
|
||||
struct interface_swd_t
|
||||
{
|
||||
RESULT (*init)(uint8_t interface_index);
|
||||
RESULT (*fini)(uint8_t interface_index);
|
||||
RESULT (*config)(uint8_t interface_index, uint8_t trn, uint16_t retry,
|
||||
struct interface_swd_t {
|
||||
RESULT(*init)(uint8_t interface_index);
|
||||
RESULT(*fini)(uint8_t interface_index);
|
||||
RESULT(*config)(uint8_t interface_index, uint8_t trn, uint16_t retry,
|
||||
uint16_t dly);
|
||||
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 (*transact)(uint8_t interface_index, uint8_t request,
|
||||
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(*transact)(uint8_t interface_index, uint8_t request,
|
||||
uint32_t *data, uint8_t *ack);
|
||||
};
|
||||
|
||||
struct interface_jtag_raw_t
|
||||
{
|
||||
RESULT (*init)(uint8_t interface_index);
|
||||
RESULT (*fini)(uint8_t interface_index);
|
||||
RESULT (*config)(uint8_t interface_index, uint32_t kHz);
|
||||
RESULT (*execute)(uint8_t interface_index, uint8_t* tdi, uint8_t* tms,
|
||||
struct interface_jtag_raw_t {
|
||||
RESULT(*init)(uint8_t interface_index);
|
||||
RESULT(*fini)(uint8_t interface_index);
|
||||
RESULT(*config)(uint8_t interface_index, uint32_t kHz);
|
||||
RESULT(*execute)(uint8_t interface_index, uint8_t *tdi, uint8_t *tms,
|
||||
uint8_t *tdo, uint32_t bitlen);
|
||||
};
|
||||
|
||||
struct interface_target_voltage_t
|
||||
{
|
||||
RESULT (*get)(uint16_t *voltage);
|
||||
RESULT (*set)(uint16_t voltage);
|
||||
struct interface_target_voltage_t {
|
||||
RESULT(*get)(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_gpio_t gpio;
|
||||
struct interface_delay_t delay;
|
||||
struct interface_swd_t swd;
|
||||
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 pid;
|
||||
uint8_t ep_out;
|
||||
|
@ -104,10 +98,9 @@ struct versaloon_usb_setting_t
|
|||
uint16_t buf_size;
|
||||
};
|
||||
|
||||
struct versaloon_interface_t
|
||||
{
|
||||
RESULT (*init)(void);
|
||||
RESULT (*fini)(void);
|
||||
struct versaloon_interface_t {
|
||||
RESULT(*init)(void);
|
||||
RESULT(*fini)(void);
|
||||
struct versaloon_adaptors_t adaptors;
|
||||
struct versaloon_usb_setting_t usb_setting;
|
||||
};
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 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/commands.h>
|
||||
#include "usb_common.h"
|
||||
|
@ -31,7 +32,7 @@
|
|||
#define RESULT int
|
||||
#define LOG_BUG LOG_ERROR
|
||||
|
||||
// Common error messages
|
||||
/* Common error messages */
|
||||
#define ERRMSG_NOT_ENOUGH_MEMORY "Lack of memory."
|
||||
#define ERRCODE_NOT_ENOUGH_MEMORY ERROR_FAIL
|
||||
|
||||
|
@ -52,38 +53,38 @@
|
|||
#define ERRMSG_FAILURE_OPERATION_MESSAGE "Fail to %s, %s"
|
||||
#define ERRCODE_FAILURE_OPERATION ERROR_FAIL
|
||||
|
||||
#define GET_U16_MSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 8) | \
|
||||
((*((uint8_t *)(p) + 1)) << 0))
|
||||
#define GET_U32_MSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 24) | \
|
||||
((*((uint8_t *)(p) + 1)) << 16) | \
|
||||
((*((uint8_t *)(p) + 2)) << 8) | \
|
||||
((*((uint8_t *)(p) + 3)) << 0))
|
||||
#define GET_U16_LSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 0) | \
|
||||
((*((uint8_t *)(p) + 1)) << 8))
|
||||
#define GET_U32_LSBFIRST(p) ( ((*((uint8_t *)(p) + 0)) << 0) | \
|
||||
((*((uint8_t *)(p) + 1)) << 8) | \
|
||||
((*((uint8_t *)(p) + 2)) << 16) | \
|
||||
((*((uint8_t *)(p) + 3)) << 24))
|
||||
#define GET_U16_MSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 8) | \
|
||||
((*((uint8_t *)(p) + 1)) << 0))
|
||||
#define GET_U32_MSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 24) | \
|
||||
((*((uint8_t *)(p) + 1)) << 16) | \
|
||||
((*((uint8_t *)(p) + 2)) << 8) | \
|
||||
((*((uint8_t *)(p) + 3)) << 0))
|
||||
#define GET_U16_LSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 0) | \
|
||||
((*((uint8_t *)(p) + 1)) << 8))
|
||||
#define GET_U32_LSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 0) | \
|
||||
((*((uint8_t *)(p) + 1)) << 8) | \
|
||||
((*((uint8_t *)(p) + 2)) << 16) | \
|
||||
((*((uint8_t *)(p) + 3)) << 24))
|
||||
|
||||
#define SET_U16_MSBFIRST(p, v) \
|
||||
do{\
|
||||
do {\
|
||||
*((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 8) & 0xFF;\
|
||||
*((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 0) & 0xFF;\
|
||||
} while (0)
|
||||
#define SET_U32_MSBFIRST(p, v) \
|
||||
do{\
|
||||
do {\
|
||||
*((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 24) & 0xFF;\
|
||||
*((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 16) & 0xFF;\
|
||||
*((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 8) & 0xFF;\
|
||||
*((uint8_t *)(p) + 3) = (((uint32_t)(v)) >> 0) & 0xFF;\
|
||||
} while (0)
|
||||
#define SET_U16_LSBFIRST(p, v) \
|
||||
do{\
|
||||
do {\
|
||||
*((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 0) & 0xFF;\
|
||||
*((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 8) & 0xFF;\
|
||||
} while (0)
|
||||
#define SET_U32_LSBFIRST(p, v) \
|
||||
do{\
|
||||
do {\
|
||||
*((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 0) & 0xFF;\
|
||||
*((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 8) & 0xFF;\
|
||||
*((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 16) & 0xFF;\
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __VERSALOON_INTERNAL_H_INCLUDED__
|
||||
#define __VERSALOON_INTERNAL_H_INCLUDED__
|
||||
|
||||
|
@ -37,8 +38,8 @@
|
|||
#define VERSALOON_TIMEOUT 5000
|
||||
#define VERSALOON_TIMEOUT_LONG 60000
|
||||
|
||||
// USB Commands
|
||||
// Common Commands
|
||||
/* USB Commands */
|
||||
/* Common Commands */
|
||||
#define VERSALOON_COMMON_CMD_START 0x00
|
||||
#define VERSALOON_COMMON_CMD_END 0x0F
|
||||
|
||||
|
@ -52,40 +53,34 @@
|
|||
#define VERSALOON_FW_UPDATE 0x0F
|
||||
#define VERSALOON_FW_UPDATE_KEY 0xAA
|
||||
|
||||
// MCU Command
|
||||
/* MCU Command */
|
||||
#define VERSALOON_MCU_CMD_START 0x10
|
||||
#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_END 0x7F
|
||||
|
||||
// VSLLink Command
|
||||
/* VSLLink Command */
|
||||
#define VERSALOON_VSLLINK_CMD_START 0x80
|
||||
#define VERSALOON_VSLLINK_CMD_END 0xFF
|
||||
|
||||
|
||||
|
||||
// Mass-product
|
||||
/* Mass-product */
|
||||
#define MP_OK 0x00
|
||||
#define MP_FAIL 0x01
|
||||
|
||||
#define MP_ISSP 0x11
|
||||
|
||||
|
||||
|
||||
// pending struct
|
||||
/* pending struct */
|
||||
#define VERSALOON_MAX_PENDING_NUMBER 4096
|
||||
typedef RESULT (*versaloon_callback_t)(void *, uint8_t *, uint8_t *);
|
||||
struct versaloon_want_pos_t
|
||||
{
|
||||
typedef RESULT(*versaloon_callback_t)(void *, uint8_t *, uint8_t *);
|
||||
struct versaloon_want_pos_t {
|
||||
uint16_t offset;
|
||||
uint16_t size;
|
||||
uint8_t *buff;
|
||||
struct versaloon_want_pos_t *next;
|
||||
};
|
||||
struct versaloon_pending_t
|
||||
{
|
||||
struct versaloon_pending_t {
|
||||
uint8_t type;
|
||||
uint8_t cmd;
|
||||
uint16_t want_data_pos;
|
||||
|
@ -99,14 +94,14 @@ struct versaloon_pending_t
|
|||
versaloon_callback_t callback;
|
||||
};
|
||||
extern struct versaloon_pending_t \
|
||||
versaloon_pending[VERSALOON_MAX_PENDING_NUMBER];
|
||||
versaloon_pending[VERSALOON_MAX_PENDING_NUMBER];
|
||||
extern uint16_t versaloon_pending_idx;
|
||||
void versaloon_set_pending_id(uint32_t id);
|
||||
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_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);
|
||||
void versaloon_free_want_pos(void);
|
||||
|
||||
RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen);
|
||||
|
@ -115,4 +110,3 @@ extern uint8_t *versaloon_cmd_buf;
|
|||
extern uint16_t versaloon_buf_size;
|
||||
|
||||
#endif /* __VERSALOON_INTERNAL_H_INCLUDED__ */
|
||||
|
||||
|
|
|
@ -38,18 +38,18 @@ static int vsllink_tms_offset;
|
|||
struct pending_scan_result {
|
||||
int src_offset;
|
||||
int dest_offset;
|
||||
int length; /* Number of bits to read */
|
||||
struct scan_command *command; /* Corresponding scan command */
|
||||
int length; /* Number of bits to read */
|
||||
struct scan_command *command; /* Corresponding scan command */
|
||||
uint8_t *ack;
|
||||
uint8_t *buffer;
|
||||
bool last; /* indicate the last scan pending */
|
||||
bool last; /* indicate the last scan pending */
|
||||
};
|
||||
|
||||
#define MAX_PENDING_SCAN_RESULTS 256
|
||||
|
||||
static int pending_scan_results_length;
|
||||
static struct pending_scan_result
|
||||
pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS];
|
||||
pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS];
|
||||
|
||||
/* Queue command functions */
|
||||
static void vsllink_end_state(tap_state_t state);
|
||||
|
@ -59,7 +59,7 @@ static void vsllink_tms(int num_bits, const uint8_t *bits);
|
|||
static void vsllink_runtest(int num_cycles);
|
||||
static void vsllink_stableclocks(int num_cycles, int tms);
|
||||
static void vsllink_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);
|
||||
static void vsllink_reset(int trst, int srst);
|
||||
|
||||
/* VSLLink tap buffer functions */
|
||||
|
@ -105,9 +105,8 @@ static int vsllink_execute_queue(void)
|
|||
switch (cmd->type) {
|
||||
case JTAG_RUNTEST:
|
||||
DEBUG_JTAG_IO("runtest %i cycles, end in %s",
|
||||
cmd->cmd.runtest->num_cycles,
|
||||
tap_state_name(cmd->cmd.runtest
|
||||
->end_state));
|
||||
cmd->cmd.runtest->num_cycles,
|
||||
tap_state_name(cmd->cmd.runtest->end_state));
|
||||
|
||||
vsllink_end_state(cmd->cmd.runtest->end_state);
|
||||
vsllink_runtest(cmd->cmd.runtest->num_cycles);
|
||||
|
@ -115,24 +114,18 @@ static int vsllink_execute_queue(void)
|
|||
|
||||
case JTAG_TLR_RESET:
|
||||
DEBUG_JTAG_IO("statemove end in %s",
|
||||
tap_state_name(cmd->cmd.statemove
|
||||
->end_state));
|
||||
tap_state_name(cmd->cmd.statemove->end_state));
|
||||
|
||||
vsllink_end_state(cmd->cmd.statemove
|
||||
->end_state);
|
||||
vsllink_end_state(cmd->cmd.statemove->end_state);
|
||||
vsllink_state_move();
|
||||
break;
|
||||
|
||||
case JTAG_PATHMOVE:
|
||||
DEBUG_JTAG_IO("pathmove: %i states, end in %s",
|
||||
cmd->cmd.pathmove->num_states,
|
||||
tap_state_name(cmd->cmd.pathmove
|
||||
->path[cmd->cmd.pathmove
|
||||
->num_states - 1]));
|
||||
cmd->cmd.pathmove->num_states,
|
||||
tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
|
||||
|
||||
vsllink_path_move(
|
||||
cmd->cmd.pathmove->num_states,
|
||||
cmd->cmd.pathmove->path);
|
||||
vsllink_path_move(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
|
||||
break;
|
||||
|
||||
case JTAG_SCAN:
|
||||
|
@ -141,27 +134,25 @@ static int vsllink_execute_queue(void)
|
|||
vsllink_end_state(cmd->cmd.scan->end_state);
|
||||
|
||||
scan_size = jtag_build_buffer(
|
||||
cmd->cmd.scan, &buffer);
|
||||
cmd->cmd.scan, &buffer);
|
||||
|
||||
if (cmd->cmd.scan->ir_scan)
|
||||
DEBUG_JTAG_IO(
|
||||
"JTAG Scan write IR(%d bits), "
|
||||
"end in %s:",
|
||||
scan_size,
|
||||
tap_state_name(cmd->cmd.scan
|
||||
->end_state));
|
||||
"JTAG Scan write IR(%d bits), "
|
||||
"end in %s:",
|
||||
scan_size,
|
||||
tap_state_name(cmd->cmd.scan->end_state));
|
||||
|
||||
else
|
||||
DEBUG_JTAG_IO(
|
||||
"JTAG Scan write DR(%d bits), "
|
||||
"end in %s:",
|
||||
scan_size,
|
||||
tap_state_name(cmd->cmd.scan
|
||||
->end_state));
|
||||
"JTAG Scan write DR(%d bits), "
|
||||
"end in %s:",
|
||||
scan_size,
|
||||
tap_state_name(cmd->cmd.scan->end_state));
|
||||
|
||||
#ifdef _DEBUG_JTAG_IO_
|
||||
vsllink_debug_buffer(buffer,
|
||||
DIV_ROUND_UP(scan_size, 8));
|
||||
DIV_ROUND_UP(scan_size, 8));
|
||||
#endif
|
||||
|
||||
type = jtag_scan_type(cmd->cmd.scan);
|
||||
|
@ -193,7 +184,7 @@ static int vsllink_execute_queue(void)
|
|||
|
||||
case JTAG_STABLECLOCKS:
|
||||
DEBUG_JTAG_IO("add %d clocks",
|
||||
cmd->cmd.stableclocks->num_cycles);
|
||||
cmd->cmd.stableclocks->num_cycles);
|
||||
|
||||
switch (tap_get_state()) {
|
||||
case TAP_RESET:
|
||||
|
@ -210,29 +201,28 @@ static int vsllink_execute_queue(void)
|
|||
/* else, tms should be '0' */
|
||||
scan_size = 0;
|
||||
break;
|
||||
/* above stable states are OK */
|
||||
/* above stable states are OK */
|
||||
default:
|
||||
LOG_ERROR("jtag_add_clocks() "
|
||||
"in non-stable state \"%s\"",
|
||||
tap_state_name(tap_get_state())
|
||||
);
|
||||
exit(-1);
|
||||
LOG_ERROR("jtag_add_clocks() "
|
||||
"in non-stable state \"%s\"",
|
||||
tap_state_name(tap_get_state())
|
||||
);
|
||||
exit(-1);
|
||||
}
|
||||
vsllink_stableclocks(cmd->cmd.stableclocks
|
||||
->num_cycles, scan_size);
|
||||
vsllink_stableclocks(cmd->cmd.stableclocks->num_cycles, scan_size);
|
||||
break;
|
||||
|
||||
case JTAG_TMS:
|
||||
DEBUG_JTAG_IO("add %d jtag tms",
|
||||
cmd->cmd.tms->num_bits);
|
||||
case JTAG_TMS:
|
||||
DEBUG_JTAG_IO("add %d jtag tms",
|
||||
cmd->cmd.tms->num_bits);
|
||||
|
||||
vsllink_tms(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits);
|
||||
break;
|
||||
vsllink_tms(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits);
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_ERROR("BUG: unknown JTAG command type "
|
||||
"encountered: %d", cmd->type);
|
||||
exit(-1);
|
||||
default:
|
||||
LOG_ERROR("BUG: unknown JTAG command type "
|
||||
"encountered: %d", cmd->type);
|
||||
exit(-1);
|
||||
}
|
||||
cmd = cmd->next;
|
||||
}
|
||||
|
@ -262,18 +252,15 @@ static int vsllink_speed_div(int jtag_speed, int *khz)
|
|||
|
||||
static void vsllink_free_buffer(void)
|
||||
{
|
||||
if (tdi_buffer != NULL)
|
||||
{
|
||||
if (tdi_buffer != NULL) {
|
||||
free(tdi_buffer);
|
||||
tdi_buffer = NULL;
|
||||
}
|
||||
if (tdo_buffer != NULL)
|
||||
{
|
||||
if (tdo_buffer != NULL) {
|
||||
free(tdo_buffer);
|
||||
tdo_buffer = NULL;
|
||||
}
|
||||
if (tms_buffer != NULL)
|
||||
{
|
||||
if (tms_buffer != NULL) {
|
||||
free(tms_buffer);
|
||||
tms_buffer = NULL;
|
||||
}
|
||||
|
@ -298,33 +285,29 @@ static int vsllink_init(void)
|
|||
{
|
||||
vsllink_handle = vsllink_usb_open();
|
||||
if (vsllink_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;
|
||||
}
|
||||
LOG_DEBUG("vsllink found on %04X:%04X",
|
||||
versaloon_interface.usb_setting.vid,
|
||||
versaloon_interface.usb_setting.pid);
|
||||
versaloon_interface.usb_setting.vid,
|
||||
versaloon_interface.usb_setting.pid);
|
||||
versaloon_usb_device_handle = vsllink_handle->usb_handle;
|
||||
|
||||
if (ERROR_OK != versaloon_interface.init())
|
||||
{
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
if (versaloon_interface.usb_setting.buf_size < 32)
|
||||
{
|
||||
if (versaloon_interface.usb_setting.buf_size < 32) {
|
||||
versaloon_interface.fini();
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
// malloc buffer size for tap
|
||||
/* malloc buffer size for tap */
|
||||
tap_buffer_size = versaloon_interface.usb_setting.buf_size - 32;
|
||||
vsllink_free_buffer();
|
||||
tdi_buffer = (uint8_t *)malloc(tap_buffer_size);
|
||||
tdo_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();
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -333,19 +316,17 @@ static int vsllink_init(void)
|
|||
versaloon_interface.adaptors.jtag_raw.config(0, jtag_get_speed_khz());
|
||||
versaloon_interface.adaptors.gpio.init(0);
|
||||
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())
|
||||
{
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
vsllink_reset(0, 0);
|
||||
vsllink_tap_init();
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/* Queue command implementations */
|
||||
/**************************************************************************
|
||||
* Queue command implementations */
|
||||
|
||||
static void vsllink_end_state(tap_state_t state)
|
||||
{
|
||||
|
@ -362,9 +343,9 @@ static void vsllink_state_move(void)
|
|||
{
|
||||
int i;
|
||||
uint8_t tms_scan = tap_get_tms_path(tap_get_state(),
|
||||
tap_get_end_state());
|
||||
tap_get_end_state());
|
||||
uint8_t tms_scan_bits = tap_get_tms_path_len(tap_get_state(),
|
||||
tap_get_end_state());
|
||||
tap_get_end_state());
|
||||
|
||||
for (i = 0; i < tms_scan_bits; i++)
|
||||
vsllink_tap_append_step((tms_scan >> i) & 1, 0);
|
||||
|
@ -381,8 +362,8 @@ static void vsllink_path_move(int num_states, tap_state_t *path)
|
|||
vsllink_tap_append_step(1, 0);
|
||||
else {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static void vsllink_stableclocks(int num_cycles, int tms)
|
||||
|
@ -419,15 +399,15 @@ static void vsllink_runtest(int num_cycles)
|
|||
|
||||
vsllink_stableclocks(num_cycles, 0);
|
||||
|
||||
// post-process
|
||||
// set end_state
|
||||
/* post-process */
|
||||
/* set end_state */
|
||||
vsllink_end_state(saved_end_state);
|
||||
if (tap_get_end_state() != tap_get_end_state())
|
||||
vsllink_state_move();
|
||||
}
|
||||
|
||||
static void vsllink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer,
|
||||
int scan_size, struct scan_command *command)
|
||||
int scan_size, struct scan_command *command)
|
||||
{
|
||||
tap_state_t saved_end_state;
|
||||
|
||||
|
@ -471,9 +451,8 @@ static void vsllink_reset(int trst, int srst)
|
|||
|
||||
COMMAND_HANDLER(vsllink_handle_usb_vid_command)
|
||||
{
|
||||
if (CMD_ARGC != 1) {
|
||||
if (CMD_ARGC != 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0],
|
||||
versaloon_interface.usb_setting.vid);
|
||||
|
@ -482,9 +461,8 @@ COMMAND_HANDLER(vsllink_handle_usb_vid_command)
|
|||
|
||||
COMMAND_HANDLER(vsllink_handle_usb_pid_command)
|
||||
{
|
||||
if (CMD_ARGC != 1) {
|
||||
if (CMD_ARGC != 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0],
|
||||
versaloon_interface.usb_setting.pid);
|
||||
return ERROR_OK;
|
||||
|
@ -492,9 +470,8 @@ COMMAND_HANDLER(vsllink_handle_usb_pid_command)
|
|||
|
||||
COMMAND_HANDLER(vsllink_handle_usb_bulkin_command)
|
||||
{
|
||||
if (CMD_ARGC != 1) {
|
||||
if (CMD_ARGC != 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0],
|
||||
versaloon_interface.usb_setting.ep_in);
|
||||
|
@ -506,9 +483,8 @@ COMMAND_HANDLER(vsllink_handle_usb_bulkin_command)
|
|||
|
||||
COMMAND_HANDLER(vsllink_handle_usb_bulkout_command)
|
||||
{
|
||||
if (CMD_ARGC != 1) {
|
||||
if (CMD_ARGC != 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0],
|
||||
versaloon_interface.usb_setting.ep_out);
|
||||
|
@ -520,17 +496,16 @@ COMMAND_HANDLER(vsllink_handle_usb_bulkout_command)
|
|||
|
||||
COMMAND_HANDLER(vsllink_handle_usb_interface_command)
|
||||
{
|
||||
if (CMD_ARGC != 1) {
|
||||
if (CMD_ARGC != 1)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0],
|
||||
versaloon_interface.usb_setting.interface);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/* VSLLink tap functions */
|
||||
/**************************************************************************
|
||||
* VSLLink tap functions */
|
||||
|
||||
static void vsllink_tap_init(void)
|
||||
{
|
||||
|
@ -542,7 +517,7 @@ static void vsllink_tap_init(void)
|
|||
static void vsllink_tap_ensure_pending(int scans)
|
||||
{
|
||||
int available_scans =
|
||||
MAX_PENDING_SCAN_RESULTS - pending_scan_results_length;
|
||||
MAX_PENDING_SCAN_RESULTS - pending_scan_results_length;
|
||||
|
||||
if (scans > available_scans)
|
||||
vsllink_tap_execute();
|
||||
|
@ -572,7 +547,7 @@ static void vsllink_tap_append_step(int tms, int tdi)
|
|||
}
|
||||
|
||||
static void vsllink_tap_append_scan(int length, uint8_t *buffer,
|
||||
struct scan_command *command)
|
||||
struct scan_command *command)
|
||||
{
|
||||
struct pending_scan_result *pending_scan_result;
|
||||
int len_tmp, len_all, i;
|
||||
|
@ -581,8 +556,8 @@ static void vsllink_tap_append_scan(int length, uint8_t *buffer,
|
|||
while (len_all < length) {
|
||||
vsllink_tap_ensure_pending(1);
|
||||
pending_scan_result =
|
||||
&pending_scan_results_buffer[
|
||||
pending_scan_results_length];
|
||||
&pending_scan_results_buffer[
|
||||
pending_scan_results_length];
|
||||
|
||||
if ((length - len_all) > (tap_buffer_size * 8 - tap_length)) {
|
||||
/* Use all memory available
|
||||
|
@ -602,9 +577,9 @@ static void vsllink_tap_append_scan(int length, uint8_t *buffer,
|
|||
|
||||
for (i = 0; i < len_tmp; i++) {
|
||||
vsllink_tap_append_step(((len_all + i) < length-1
|
||||
? 0 : 1),
|
||||
(buffer[(len_all + i)/8]
|
||||
>> ((len_all + i)%8)) & 1);
|
||||
? 0 : 1),
|
||||
(buffer[(len_all + i)/8]
|
||||
>> ((len_all + i)%8)) & 1);
|
||||
}
|
||||
|
||||
len_all += len_tmp;
|
||||
|
@ -619,7 +594,7 @@ static int vsllink_jtag_execute(void)
|
|||
if (tap_length <= 0)
|
||||
return ERROR_OK;
|
||||
|
||||
versaloon_interface.adaptors.jtag_raw.execute(0, tdi_buffer, tms_buffer,
|
||||
versaloon_interface.adaptors.jtag_raw.execute(0, tdi_buffer, tms_buffer,
|
||||
tdo_buffer, tap_length);
|
||||
|
||||
result = versaloon_interface.adaptors.peripheral_commit();
|
||||
|
@ -644,12 +619,12 @@ static int vsllink_jtag_execute(void)
|
|||
"JTAG scan read(%d bits, from src %d bits to dest %d bits):",
|
||||
length, src_first, dest_first);
|
||||
vsllink_debug_buffer(buffer + dest_first / 8,
|
||||
DIV_ROUND_UP(length, 7));
|
||||
DIV_ROUND_UP(length, 7));
|
||||
#endif
|
||||
|
||||
if (last) {
|
||||
if (jtag_read_buffer(buffer, command)
|
||||
!= ERROR_OK) {
|
||||
!= ERROR_OK) {
|
||||
vsllink_tap_init();
|
||||
return ERROR_JTAG_QUEUE_FAILED;
|
||||
}
|
||||
|
@ -673,22 +648,20 @@ static int vsllink_tap_execute(void)
|
|||
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,
|
||||
char * string, char * buff, uint16_t buf_size)
|
||||
char *string, char *buff, uint16_t buf_size)
|
||||
{
|
||||
int len;
|
||||
uint8_t alloced = 0;
|
||||
uint8_t ret = 1;
|
||||
|
||||
if (NULL == buff)
|
||||
{
|
||||
if (NULL == buff) {
|
||||
buf_size = 256;
|
||||
buff = (char*)malloc(buf_size);
|
||||
if (NULL == buff)
|
||||
{
|
||||
buff = (char *)malloc(buf_size);
|
||||
if (NULL == buff) {
|
||||
ret = 0;
|
||||
goto free_and_return;
|
||||
}
|
||||
|
@ -697,31 +670,28 @@ static uint8_t usb_check_string(usb_dev_handle *usb, uint8_t stringidx,
|
|||
|
||||
strcpy(buff, "");
|
||||
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;
|
||||
goto free_and_return;
|
||||
}
|
||||
|
||||
buff[len] = '\0';
|
||||
if ((string != NULL) && strcmp((const char *)buff, string))
|
||||
{
|
||||
if ((string != NULL) && strcmp((const char *)buff, string)) {
|
||||
ret = 0;
|
||||
goto free_and_return;
|
||||
}
|
||||
|
||||
free_and_return:
|
||||
if (alloced && (buff != NULL))
|
||||
{
|
||||
if (alloced && (buff != NULL)) {
|
||||
free(buff);
|
||||
buff = NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static usb_dev_handle* find_usb_device(uint16_t VID, uint16_t PID,
|
||||
uint8_t interface, int8_t serialindex, char *serialstring,
|
||||
int8_t productindex, char *productstring)
|
||||
static usb_dev_handle *find_usb_device(uint16_t VID, uint16_t PID,
|
||||
uint8_t interface, int8_t serialindex, char *serialstring,
|
||||
int8_t productindex, char *productstring)
|
||||
{
|
||||
usb_dev_handle *dev_handle = NULL;
|
||||
struct usb_bus *busses;
|
||||
|
@ -733,47 +703,39 @@ static usb_dev_handle* find_usb_device(uint16_t VID, uint16_t PID,
|
|||
usb_find_devices();
|
||||
busses = usb_get_busses();
|
||||
|
||||
for (bus = busses; bus; bus = bus->next)
|
||||
{
|
||||
for (dev = bus->devices; dev; dev = dev->next)
|
||||
{
|
||||
for (bus = busses; bus; bus = bus->next) {
|
||||
for (dev = bus->devices; dev; dev = dev->next) {
|
||||
if ((dev->descriptor.idVendor == VID)
|
||||
&& (dev->descriptor.idProduct == PID))
|
||||
{
|
||||
&& (dev->descriptor.idProduct == PID)) {
|
||||
dev_handle = usb_open(dev);
|
||||
if (NULL == dev_handle)
|
||||
{
|
||||
if (NULL == dev_handle) {
|
||||
LOG_ERROR("failed to open %04X:%04X, %s", VID, PID,
|
||||
usb_strerror());
|
||||
usb_strerror());
|
||||
continue;
|
||||
}
|
||||
|
||||
// check description string
|
||||
/* check description string */
|
||||
if (((productstring != NULL) && (productindex >= 0)
|
||||
&& !usb_check_string(dev_handle, productindex,
|
||||
productstring, NULL, 0))
|
||||
|| ((serialstring != NULL) && (serialindex >= 0)
|
||||
&& !usb_check_string(dev_handle, serialindex,
|
||||
serialstring, NULL, 0)))
|
||||
{
|
||||
productstring, NULL, 0))
|
||||
|| ((serialstring != NULL) && (serialindex >= 0)
|
||||
&& !usb_check_string(dev_handle, serialindex,
|
||||
serialstring, NULL, 0))) {
|
||||
usb_close(dev_handle);
|
||||
dev_handle = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (usb_claim_interface(dev_handle, interface) != 0)
|
||||
{
|
||||
if (usb_claim_interface(dev_handle, interface) != 0) {
|
||||
LOG_ERROR(ERRMSG_FAILURE_OPERATION_MESSAGE,
|
||||
"claim interface", usb_strerror());
|
||||
"claim interface", usb_strerror());
|
||||
usb_close(dev_handle);
|
||||
dev_handle = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dev_handle != NULL)
|
||||
{
|
||||
return dev_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -788,9 +750,9 @@ static struct vsllink *vsllink_usb_open(void)
|
|||
struct usb_dev_handle *dev;
|
||||
|
||||
dev = find_usb_device(versaloon_interface.usb_setting.vid,
|
||||
versaloon_interface.usb_setting.pid,
|
||||
versaloon_interface.usb_setting.interface,
|
||||
0, NULL, 2, "Versaloon");
|
||||
versaloon_interface.usb_setting.pid,
|
||||
versaloon_interface.usb_setting.interface,
|
||||
0, NULL, 2, "Versaloon");
|
||||
if (NULL == dev)
|
||||
return NULL;
|
||||
|
||||
|
@ -807,7 +769,7 @@ static void vsllink_usb_close(struct vsllink *vsllink)
|
|||
versaloon_interface.usb_setting.interface);
|
||||
if (ret != 0) {
|
||||
LOG_ERROR("fail to release interface %d, %d returned",
|
||||
versaloon_interface.usb_setting.interface, ret);
|
||||
versaloon_interface.usb_setting.interface, ret);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -839,7 +801,7 @@ static void vsllink_debug_buffer(uint8_t *buffer, int length)
|
|||
LOG_DEBUG("%s", line);
|
||||
}
|
||||
}
|
||||
#endif /* _DEBUG_JTAG_IO_ */
|
||||
#endif /* _DEBUG_JTAG_IO_ */
|
||||
|
||||
static const struct command_registration vsllink_command_handlers[] = {
|
||||
{
|
||||
|
|
|
@ -18,13 +18,14 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef MINIDRIVER_IMP_H
|
||||
#define MINIDRIVER_IMP_H
|
||||
|
||||
#include <jtag/jtag_minidriver.h>
|
||||
|
||||
static inline void jtag_add_dr_out(struct jtag_tap* tap,
|
||||
int num_fields, const int* num_bits, const uint32_t* value,
|
||||
static inline void jtag_add_dr_out(struct jtag_tap *tap,
|
||||
int num_fields, const int *num_bits, const uint32_t *value,
|
||||
tap_state_t 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_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 */
|
||||
|
|
|
@ -17,10 +17,7 @@
|
|||
* 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,
|
||||
const int *num_bits,
|
||||
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 */
|
||||
}
|
||||
|
||||
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,
|
||||
const int *num_bits,
|
||||
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_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))
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -25,8 +26,7 @@
|
|||
#include <jtag/minidriver.h>
|
||||
#include <jtag/interface.h>
|
||||
|
||||
struct jtag_interface minidummy_interface =
|
||||
{
|
||||
struct jtag_interface minidummy_interface = {
|
||||
.name = "minidummy",
|
||||
.execute_queue = NULL,
|
||||
.speed = NULL,
|
||||
|
@ -46,29 +46,32 @@ int interface_jtag_execute_queue(void)
|
|||
return ERROR_OK;
|
||||
}
|
||||
|
||||
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)
|
||||
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_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 */
|
||||
|
||||
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 */
|
||||
|
||||
|
@ -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;
|
||||
|
||||
while (num_states)
|
||||
{
|
||||
while (num_states) {
|
||||
if (tap_state_transition(cur_state, false) == path[state_count])
|
||||
{
|
||||
tms = 0;
|
||||
}
|
||||
else if (tap_state_transition(cur_state, true) == path[state_count])
|
||||
{
|
||||
tms = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state), tap_state_name(path[state_count]));
|
||||
else {
|
||||
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
|
||||
tap_state_name(cur_state), tap_state_name(path[state_count]));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -154,18 +152,20 @@ int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state
|
|||
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;
|
||||
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));
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _STLINK_INTERFACE_
|
||||
#define _STLINK_INTERFACE_
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _STLINK_LAYOUT_H_
|
||||
#define _STLINK_LAYOUT_H_
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _STLINK_TCL_
|
||||
#define _STLINK_TCL_
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _STLINK_TRANSPORT_
|
||||
#define _STLINK_TRANSPORT_
|
||||
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
#if BUILD_ZY1000_MASTER
|
||||
|
||||
#if BUILD_ECOSBOARD
|
||||
#include <cyg/hal/hal_io.h> // low level i/o
|
||||
#include <cyg/hal/hal_intr.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 */
|
||||
#define ZY1000_PEEK(a, b) HAL_READ_UINT32(a, b)
|
||||
#define ZY1000_POKE(a, b) HAL_WRITE_UINT32(a, b)
|
||||
#else
|
||||
#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_PEEK(a, b) do {b = *((volatile uint32_t *)(a)); } while (0)
|
||||
#define ZY1000_POKE(a, b) do {*((volatile uint32_t *)(a)) = b; } while (0)
|
||||
extern volatile void *zy1000_jtag_master;
|
||||
#define ZY1000_JTAG_BASE ((unsigned long)zy1000_jtag_master)
|
||||
#endif
|
||||
|
@ -41,29 +41,26 @@ extern volatile void *zy1000_jtag_master;
|
|||
#define ZY1000_JTAG_BASE 0
|
||||
extern void zy1000_tcpout(uint32_t address, uint32_t data);
|
||||
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)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if BUILD_ZY1000_MASTER
|
||||
// FIFO empty?
|
||||
static __inline__ void waitIdle(void)
|
||||
/* FIFO empty? */
|
||||
static inline void waitIdle(void)
|
||||
{
|
||||
uint32_t empty;
|
||||
do
|
||||
{
|
||||
do {
|
||||
ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, empty);
|
||||
} while ((empty & 0x100) == 0);
|
||||
}
|
||||
|
||||
static __inline__ void zy1000_flush_readqueue(void)
|
||||
static inline void zy1000_flush_readqueue(void)
|
||||
{
|
||||
/* Not used w/hardware fifo */
|
||||
}
|
||||
static __inline__ void zy1000_flush_callbackqueue(void)
|
||||
static inline void zy1000_flush_callbackqueue(void)
|
||||
{
|
||||
/* Not used w/hardware fifo */
|
||||
}
|
||||
|
@ -71,16 +68,20 @@ static __inline__ void zy1000_flush_callbackqueue(void)
|
|||
extern void waitIdle(void);
|
||||
void zy1000_flush_readqueue(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);
|
||||
#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
|
||||
uint32_t dummy;
|
||||
|
@ -89,17 +90,16 @@ static __inline__ void sampleShiftRegister(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static __inline__ void setCurrentState(enum tap_state state)
|
||||
static inline void setCurrentState(enum tap_state state)
|
||||
{
|
||||
uint32_t a;
|
||||
a = state;
|
||||
int repeat = 0;
|
||||
if (state == TAP_RESET)
|
||||
{
|
||||
// The FPGA nor we know the current state of the CPU TAP
|
||||
// controller. This will move it to TAP for sure.
|
||||
//
|
||||
// 5 should be enough here, 7 is what OpenOCD uses
|
||||
if (state == TAP_RESET) {
|
||||
/* The FPGA nor we know the current state of the CPU TAP */
|
||||
/* controller. This will move it to TAP for sure. */
|
||||
/* */
|
||||
/* 5 should be enough here, 7 is what OpenOCD uses */
|
||||
repeat = 7;
|
||||
}
|
||||
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
|
||||
* 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;
|
||||
b = endState;
|
||||
waitQueue();
|
||||
|
@ -122,44 +125,42 @@ static __inline__ void shiftValueInner(const enum tap_state state, const enum ta
|
|||
ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value);
|
||||
#if 1
|
||||
#if TEST_MANUAL()
|
||||
if ((state == TAP_DRSHIFT) && (endState != TAP_DRSHIFT))
|
||||
{
|
||||
if ((state == TAP_DRSHIFT) && (endState != TAP_DRSHIFT)) {
|
||||
int i;
|
||||
setCurrentState(state);
|
||||
for (i = 0; i < repeat; i++)
|
||||
{
|
||||
for (i = 0; i < repeat; i++) {
|
||||
int tms;
|
||||
tms = 0;
|
||||
if ((i == repeat-1) && (state != endState))
|
||||
{
|
||||
tms = 1;
|
||||
}
|
||||
/* shift out value */
|
||||
/* shift out value */
|
||||
waitIdle();
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, (((value >> i)&1) << 1) | tms);
|
||||
}
|
||||
waitIdle();
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0);
|
||||
waitIdle();
|
||||
//ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT); // set this state and things 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.
|
||||
/* ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT); // set this state and things
|
||||
* 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);
|
||||
} else
|
||||
{
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
|
||||
}
|
||||
|
||||
#else
|
||||
/* fast version */
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
|
||||
#endif
|
||||
#else
|
||||
/* maximum debug version */
|
||||
if ((repeat > 0) && ((state == TAP_DRSHIFT)||(state == TAP_SI)))
|
||||
{
|
||||
if ((repeat > 0) && ((state == TAP_DRSHIFT) || (state == TAP_SI))) {
|
||||
int i;
|
||||
/* sample shift register for every bit. */
|
||||
for (i = 0; i < repeat-1; i++)
|
||||
{
|
||||
for (i = 0; i < repeat-1; i++) {
|
||||
sampleShiftRegister();
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> i);
|
||||
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();
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> (repeat-1));
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | b);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
sampleShiftRegister();
|
||||
ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b);
|
||||
}
|
||||
|
@ -176,69 +176,62 @@ static __inline__ void shiftValueInner(const enum tap_state state, const enum ta
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
static __inline__ void interface_jtag_add_dr_out_core(struct jtag_tap *target_tap,
|
||||
int num_fields,
|
||||
const int *num_bits,
|
||||
const uint32_t *value,
|
||||
enum tap_state end_state)
|
||||
static inline void interface_jtag_add_dr_out_core(struct jtag_tap *target_tap,
|
||||
int num_fields,
|
||||
const int *num_bits,
|
||||
const uint32_t *value,
|
||||
enum tap_state end_state)
|
||||
{
|
||||
enum tap_state pause_state = TAP_DRSHIFT;
|
||||
|
||||
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);
|
||||
if (nextTap == NULL)
|
||||
{
|
||||
pause_state = end_state;
|
||||
}
|
||||
if (tap == target_tap)
|
||||
{
|
||||
if (tap == target_tap) {
|
||||
int j;
|
||||
for (j = 0; j < (num_fields-1); j++)
|
||||
{
|
||||
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 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 */
|
||||
shiftValueInner(TAP_DRSHIFT, pause_state, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static __inline__ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
|
||||
int num_fields,
|
||||
const int *num_bits,
|
||||
const uint32_t *value,
|
||||
enum tap_state end_state)
|
||||
static inline void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
|
||||
int num_fields,
|
||||
const int *num_bits,
|
||||
const uint32_t *value,
|
||||
enum tap_state end_state)
|
||||
{
|
||||
|
||||
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() */
|
||||
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[0], value[0]);
|
||||
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[1], value[1]);
|
||||
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 */
|
||||
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, num_bits[0], value[0]);
|
||||
shiftValueInner(TAP_DRSHIFT, end_state, num_bits[1], value[1]);
|
||||
} else
|
||||
{
|
||||
interface_jtag_add_dr_out_core(target_tap, num_fields, num_bits, value, end_state);
|
||||
}
|
||||
}
|
||||
|
||||
#if BUILD_ZY1000_MASTER
|
||||
#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
|
||||
#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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue