#include <stdint.h>
-#define NOP {__asm nop __endasm;}
+#define NOP { __asm nop __endasm; }
void delay_5us(void);
void delay_1ms(void);
/* 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
#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)
#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
#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);
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
#define bmBit6 0x40
#define bmBit7 0x80
-/***************************************************************************/
-/************************ Special Function Registers ***********************/
-/***************************************************************************/
+/**************************************************************************
+ ************************ Special Function Registers **********************
+ ***************************************************************************/
/* See EZ-USB TRM, pp. A-9 - A-10 */
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,
#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
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);
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'
-
-/***************************************************************************/
-/***************************** XDATA Registers *****************************/
-/***************************************************************************/
+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 ****************************
+ ***************************************************************************/
/************************ Endpoint 0-7 Data Buffers ************************/
SFRX(OUT7BUF[64], 0x7B40);
SFRX(IN1BUF[64], 0x7E80);
SFRX(OUT0BUF[64], 0x7EC0);
SFRX(IN0BUF[64], 0x7F00);
-// 0x7F40 - 0x7F5F reserved
+/* 0x7F40 - 0x7F5F reserved */
/**************************** Isochronous Data *****************************/
SFRX(OUT8DATA, 0x7F60);
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
#define OEC6 bmBit6
#define OEC7 bmBit7
-// 0x7F9F reserved
+/* 0x7F9F reserved */
/****************** Isochronous Control/Status Registers *******************/
SFRX(ISOERR, 0x7FA0);
#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
#define EP14 bmBit6
#define EP15 bmBit7
-// 0x7FA3 reserved
-// 0x7FA4 reserved
+/* 0x7FA3 reserved */
+/* 0x7FA4 reserved */
/****************************** I2C Registers ******************************/
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
#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
#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);
#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);
SFRX(IN6BC, 0x7FC1);
SFRX(IN7CS, 0x7FC2);
SFRX(IN7BC, 0x7FC3);
-// 0x7FC4 reserved
+/* 0x7FC4 reserved */
SFRX(OUT0BC, 0x7FC5);
SFRX(OUT1CS, 0x7FC6);
SFRX(OUT1BC, 0x7FC7);
#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
SFRX(USBFRAMEL, 0x7FD8);
SFRX(USBFRAMEH, 0x7FD9);
-// 0x7FDA reserved
+/* 0x7FDA reserved */
SFRX(FNADDR, 0x7FDB);
-// 0x7FDC reserved
+/* 0x7FDC reserved */
SFRX(USBPAIR, 0x7FDD);
#define PR2IN bmBit0
#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
#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
SFRX(AUTOPTRH, 0x7FE3);
SFRX(AUTOPTRL, 0x7FE4);
SFRX(AUTODATA, 0x7FE5);
-// 0x7FE6 reserved
-// 0x7FE7 reserved
+/* 0x7FE6 reserved */
+/* 0x7FE7 reserved */
/******************************* Setup Data ********************************/
SFRX(SETUPDAT[8], 0x7FE8);
#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 **********/
#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
/* 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
/** 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);
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();
}
#include <stdbool.h>
/** Delay value for SCAN_IN operations with less than maximum TCK frequency */
-uint8_t delay_scan_in = 0;
+uint8_t delay_scan_in;
/** Delay value for SCAN_OUT operations with less than maximum TCK frequency */
-uint8_t delay_scan_out = 0;
+uint8_t delay_scan_out;
/** Delay value for SCAN_IO operations with less than maximum TCK frequency */
-uint8_t delay_scan_io = 0;
+uint8_t delay_scan_io;
/** Delay value for CLOCK_TCK operations with less than maximum frequency */
-uint8_t delay_tck = 0;
+uint8_t delay_tck;
/** Delay value for CLOCK_TMS operations with less than maximum frequency */
-uint8_t delay_tms = 0;
+uint8_t delay_tms;
/**
* Perform JTAG SCAN-IN operation at maximum TCK frequency.
*/
void jtag_scan_in(uint8_t out_offset, uint8_t in_offset)
{
- uint8_t scan_size_bytes, bits_last_byte;
- uint8_t tms_count_start, tms_count_end;
- uint8_t tms_sequence_start, tms_sequence_end;
- uint8_t tdo_data, i, j;
-
- uint8_t outb_buffer;
-
- /* Get parameters from OUT2BUF */
- scan_size_bytes = OUT2BUF[out_offset];
- bits_last_byte = OUT2BUF[out_offset + 1];
- tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
- tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
- tms_sequence_start = OUT2BUF[out_offset + 3];
- tms_sequence_end = OUT2BUF[out_offset + 4];
-
- if (tms_count_start > 0) {
- jtag_clock_tms(tms_count_start, tms_sequence_start);
- }
-
- outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
-
- /* Shift all bytes except the last byte */
- for (i = 0; i < scan_size_bytes - 1; i++) {
- tdo_data = 0;
-
- for (j = 0; j < 8; j++) {
- OUTB = outb_buffer; /* TCK changes here */
- tdo_data = tdo_data >> 1;
- OUTB = (outb_buffer | PIN_TCK);
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
- }
-
- tdo_data = 0;
-
- /* Shift the last byte */
- for (j = 0; j < bits_last_byte; j++) {
- /* Assert TMS signal if requested and this is the last bit */
- if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
- outb_buffer |= PIN_TMS;
- tms_count_end--;
- tms_sequence_end = tms_sequence_end >> 1;
- }
-
- OUTB = outb_buffer; /* TCK change here */
- tdo_data = tdo_data >> 1;
- OUTB = (outb_buffer | PIN_TCK);
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
- tdo_data = tdo_data >> (8 - bits_last_byte);
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
-
- /* Move to correct end state */
- if (tms_count_end > 0) {
- jtag_clock_tms(tms_count_end, tms_sequence_end);
- }
+ uint8_t scan_size_bytes, bits_last_byte;
+ uint8_t tms_count_start, tms_count_end;
+ uint8_t tms_sequence_start, tms_sequence_end;
+ uint8_t tdo_data, i, j;
+
+ uint8_t outb_buffer;
+
+ /* Get parameters from OUT2BUF */
+ scan_size_bytes = OUT2BUF[out_offset];
+ bits_last_byte = OUT2BUF[out_offset + 1];
+ tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
+ tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
+ tms_sequence_start = OUT2BUF[out_offset + 3];
+ tms_sequence_end = OUT2BUF[out_offset + 4];
+
+ if (tms_count_start > 0)
+ jtag_clock_tms(tms_count_start, tms_sequence_start);
+
+ outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
+
+ /* Shift all bytes except the last byte */
+ for (i = 0; i < scan_size_bytes - 1; i++) {
+ tdo_data = 0;
+
+ for (j = 0; j < 8; j++) {
+ OUTB = outb_buffer; /* TCK changes here */
+ tdo_data = tdo_data >> 1;
+ OUTB = (outb_buffer | PIN_TCK);
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+ }
+
+ tdo_data = 0;
+
+ /* Shift the last byte */
+ for (j = 0; j < bits_last_byte; j++) {
+ /* Assert TMS signal if requested and this is the last bit */
+ if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
+ outb_buffer |= PIN_TMS;
+ tms_count_end--;
+ tms_sequence_end = tms_sequence_end >> 1;
+ }
+
+ OUTB = outb_buffer; /* TCK change here */
+ tdo_data = tdo_data >> 1;
+ OUTB = (outb_buffer | PIN_TCK);
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+ tdo_data = tdo_data >> (8 - bits_last_byte);
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+
+ /* Move to correct end state */
+ if (tms_count_end > 0)
+ jtag_clock_tms(tms_count_end, tms_sequence_end);
}
/**
*/
void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
{
- uint8_t scan_size_bytes, bits_last_byte;
- uint8_t tms_count_start, tms_count_end;
- uint8_t tms_sequence_start, tms_sequence_end;
- uint8_t tdo_data, i, j, k;
-
- uint8_t outb_buffer;
-
- /* Get parameters from OUT2BUF */
- scan_size_bytes = OUT2BUF[out_offset];
- bits_last_byte = OUT2BUF[out_offset + 1];
- tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
- tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
- tms_sequence_start = OUT2BUF[out_offset + 3];
- tms_sequence_end = OUT2BUF[out_offset + 4];
-
- if (tms_count_start > 0) {
- jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
- }
-
- outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
-
- /* Shift all bytes except the last byte */
- for (i = 0; i < scan_size_bytes - 1; i++) {
- tdo_data = 0;
-
- for (j = 0; j < 8; j++) {
- OUTB = outb_buffer; /* TCK changes here */
- for (k = 0; k < delay_scan_in; k++);
- tdo_data = tdo_data >> 1;
-
- OUTB = (outb_buffer | PIN_TCK);
- for (k = 0; k < delay_scan_in; k++);
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
- }
-
- tdo_data = 0;
-
- /* Shift the last byte */
- for (j = 0; j < bits_last_byte; j++) {
- /* Assert TMS signal if requested and this is the last bit */
- if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
- outb_buffer |= PIN_TMS;
- tms_count_end--;
- tms_sequence_end = tms_sequence_end >> 1;
- }
-
- OUTB = outb_buffer; /* TCK change here */
- for (k = 0; k < delay_scan_in; k++);
- tdo_data = tdo_data >> 1;
-
- OUTB = (outb_buffer | PIN_TCK);
- for (k = 0; k < delay_scan_in; k++);
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
- tdo_data = tdo_data >> (8 - bits_last_byte);
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
-
- /* Move to correct end state */
- if (tms_count_end > 0) {
- jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
- }
+ uint8_t scan_size_bytes, bits_last_byte;
+ uint8_t tms_count_start, tms_count_end;
+ uint8_t tms_sequence_start, tms_sequence_end;
+ uint8_t tdo_data, i, j, k;
+
+ uint8_t outb_buffer;
+
+ /* Get parameters from OUT2BUF */
+ scan_size_bytes = OUT2BUF[out_offset];
+ bits_last_byte = OUT2BUF[out_offset + 1];
+ tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
+ tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
+ tms_sequence_start = OUT2BUF[out_offset + 3];
+ tms_sequence_end = OUT2BUF[out_offset + 4];
+
+ if (tms_count_start > 0)
+ jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
+
+ outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
+
+ /* Shift all bytes except the last byte */
+ for (i = 0; i < scan_size_bytes - 1; i++) {
+ tdo_data = 0;
+
+ for (j = 0; j < 8; j++) {
+ OUTB = outb_buffer; /* TCK changes here */
+ for (k = 0; k < delay_scan_in; k++)
+ ;
+ tdo_data = tdo_data >> 1;
+
+ OUTB = (outb_buffer | PIN_TCK);
+ for (k = 0; k < delay_scan_in; k++)
+ ;
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+ }
+
+ tdo_data = 0;
+
+ /* Shift the last byte */
+ for (j = 0; j < bits_last_byte; j++) {
+ /* Assert TMS signal if requested and this is the last bit */
+ if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
+ outb_buffer |= PIN_TMS;
+ tms_count_end--;
+ tms_sequence_end = tms_sequence_end >> 1;
+ }
+
+ OUTB = outb_buffer; /* TCK change here */
+ for (k = 0; k < delay_scan_in; k++)
+ ;
+ tdo_data = tdo_data >> 1;
+
+ OUTB = (outb_buffer | PIN_TCK);
+ for (k = 0; k < delay_scan_in; k++)
+ ;
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+ tdo_data = tdo_data >> (8 - bits_last_byte);
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+
+ /* Move to correct end state */
+ if (tms_count_end > 0)
+ jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
/**
*/
void jtag_scan_out(uint8_t out_offset)
{
- uint8_t scan_size_bytes, bits_last_byte;
- uint8_t tms_count_start, tms_count_end;
- uint8_t tms_sequence_start, tms_sequence_end;
- uint8_t tdi_data, i, j;
-
- uint8_t outb_buffer;
-
- /* Get parameters from OUT2BUF */
- scan_size_bytes = OUT2BUF[out_offset];
- bits_last_byte = OUT2BUF[out_offset + 1];
- tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
- tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
- tms_sequence_start = OUT2BUF[out_offset + 3];
- tms_sequence_end = OUT2BUF[out_offset + 4];
-
- if (tms_count_start > 0) {
- jtag_clock_tms(tms_count_start, tms_sequence_start);
- }
-
- outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
-
- /* Shift all bytes except the last byte */
- for (i = 0; i < scan_size_bytes - 1; i++) {
- tdi_data = OUT2BUF[i + out_offset + 5];
-
- for (j = 0; j < 8; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- tdi_data = tdi_data >> 1;
- OUTB = (outb_buffer | PIN_TCK);
- }
- }
-
- tdi_data = OUT2BUF[i + out_offset + 5];
-
- /* Shift the last byte */
- for (j = 0; j < bits_last_byte; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- /* Assert TMS signal if requested and this is the last bit */
- if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
- outb_buffer |= PIN_TMS;
- tms_count_end--;
- tms_sequence_end = tms_sequence_end >> 1;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- tdi_data = tdi_data >> 1;
- OUTB = (outb_buffer | PIN_TCK);
- }
-
- /* Move to correct end state */
- if (tms_count_end > 0) {
- jtag_clock_tms(tms_count_end, tms_sequence_end);
- }
+ uint8_t scan_size_bytes, bits_last_byte;
+ uint8_t tms_count_start, tms_count_end;
+ uint8_t tms_sequence_start, tms_sequence_end;
+ uint8_t tdi_data, i, j;
+
+ uint8_t outb_buffer;
+
+ /* Get parameters from OUT2BUF */
+ scan_size_bytes = OUT2BUF[out_offset];
+ bits_last_byte = OUT2BUF[out_offset + 1];
+ tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
+ tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
+ tms_sequence_start = OUT2BUF[out_offset + 3];
+ tms_sequence_end = OUT2BUF[out_offset + 4];
+
+ if (tms_count_start > 0)
+ jtag_clock_tms(tms_count_start, tms_sequence_start);
+
+ outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
+
+ /* Shift all bytes except the last byte */
+ for (i = 0; i < scan_size_bytes - 1; i++) {
+ tdi_data = OUT2BUF[i + out_offset + 5];
+
+ for (j = 0; j < 8; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ tdi_data = tdi_data >> 1;
+ OUTB = (outb_buffer | PIN_TCK);
+ }
+ }
+
+ tdi_data = OUT2BUF[i + out_offset + 5];
+
+ /* Shift the last byte */
+ for (j = 0; j < bits_last_byte; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ /* Assert TMS signal if requested and this is the last bit */
+ if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
+ outb_buffer |= PIN_TMS;
+ tms_count_end--;
+ tms_sequence_end = tms_sequence_end >> 1;
+ }
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ tdi_data = tdi_data >> 1;
+ OUTB = (outb_buffer | PIN_TCK);
+ }
+
+ /* Move to correct end state */
+ if (tms_count_end > 0)
+ jtag_clock_tms(tms_count_end, tms_sequence_end);
}
/**
*/
void jtag_slow_scan_out(uint8_t out_offset)
{
- uint8_t scan_size_bytes, bits_last_byte;
- uint8_t tms_count_start, tms_count_end;
- uint8_t tms_sequence_start, tms_sequence_end;
- uint8_t tdi_data, i, j, k;
-
- uint8_t outb_buffer;
-
- /* Get parameters from OUT2BUF */
- scan_size_bytes = OUT2BUF[out_offset];
- bits_last_byte = OUT2BUF[out_offset + 1];
- tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
- tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
- tms_sequence_start = OUT2BUF[out_offset + 3];
- tms_sequence_end = OUT2BUF[out_offset + 4];
-
- if (tms_count_start > 0) {
- jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
- }
-
- outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
-
- /* Shift all bytes except the last byte */
- for (i = 0; i < scan_size_bytes - 1; i++) {
- tdi_data = OUT2BUF[i + out_offset + 5];
-
- for (j = 0; j < 8; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- for (k = 0; k < delay_scan_out; k++);
- tdi_data = tdi_data >> 1;
-
- OUTB = (outb_buffer | PIN_TCK);
- for (k = 0; k < delay_scan_out; k++);
- }
- }
-
- tdi_data = OUT2BUF[i + out_offset + 5];
-
- /* Shift the last byte */
- for (j = 0; j < bits_last_byte; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- /* Assert TMS signal if requested and this is the last bit */
- if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
- outb_buffer |= PIN_TMS;
- tms_count_end--;
- tms_sequence_end = tms_sequence_end >> 1;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- for (k = 0; k < delay_scan_out; k++);
- tdi_data = tdi_data >> 1;
-
- OUTB = (outb_buffer | PIN_TCK);
- for (k = 0; k < delay_scan_out; k++);
- }
-
- /* Move to correct end state */
- if (tms_count_end > 0) {
- jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
- }
+ uint8_t scan_size_bytes, bits_last_byte;
+ uint8_t tms_count_start, tms_count_end;
+ uint8_t tms_sequence_start, tms_sequence_end;
+ uint8_t tdi_data, i, j, k;
+
+ uint8_t outb_buffer;
+
+ /* Get parameters from OUT2BUF */
+ scan_size_bytes = OUT2BUF[out_offset];
+ bits_last_byte = OUT2BUF[out_offset + 1];
+ tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
+ tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
+ tms_sequence_start = OUT2BUF[out_offset + 3];
+ tms_sequence_end = OUT2BUF[out_offset + 4];
+
+ if (tms_count_start > 0)
+ jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
+
+ outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
+
+ /* Shift all bytes except the last byte */
+ for (i = 0; i < scan_size_bytes - 1; i++) {
+ tdi_data = OUT2BUF[i + out_offset + 5];
+
+ for (j = 0; j < 8; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ for (k = 0; k < delay_scan_out; k++)
+ ;
+ tdi_data = tdi_data >> 1;
+
+ OUTB = (outb_buffer | PIN_TCK);
+ for (k = 0; k < delay_scan_out; k++)
+ ;
+ }
+ }
+
+ tdi_data = OUT2BUF[i + out_offset + 5];
+
+ /* Shift the last byte */
+ for (j = 0; j < bits_last_byte; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ /* Assert TMS signal if requested and this is the last bit */
+ if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
+ outb_buffer |= PIN_TMS;
+ tms_count_end--;
+ tms_sequence_end = tms_sequence_end >> 1;
+ }
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ for (k = 0; k < delay_scan_out; k++)
+ ;
+ tdi_data = tdi_data >> 1;
+
+ OUTB = (outb_buffer | PIN_TCK);
+ for (k = 0; k < delay_scan_out; k++)
+ ;
+ }
+
+ /* Move to correct end state */
+ if (tms_count_end > 0)
+ jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
/**
*/
void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
{
- uint8_t scan_size_bytes, bits_last_byte;
- uint8_t tms_count_start, tms_count_end;
- uint8_t tms_sequence_start, tms_sequence_end;
- uint8_t tdi_data, tdo_data, i, j;
-
- uint8_t outb_buffer;
-
- /* Get parameters from OUT2BUF */
- scan_size_bytes = OUT2BUF[out_offset];
- bits_last_byte = OUT2BUF[out_offset + 1];
- tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
- tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
- tms_sequence_start = OUT2BUF[out_offset + 3];
- tms_sequence_end = OUT2BUF[out_offset + 4];
-
- if (tms_count_start > 0) {
- jtag_clock_tms(tms_count_start, tms_sequence_start);
- }
-
- outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
-
- /* Shift all bytes except the last byte */
- for (i = 0; i < scan_size_bytes - 1; i++) {
- tdi_data = OUT2BUF[i + out_offset + 5];
- tdo_data = 0;
-
- for (j = 0; j < 8; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- tdi_data = tdi_data >> 1;
- OUTB = (outb_buffer | PIN_TCK);
- tdo_data = tdo_data >> 1;
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
- }
-
- tdi_data = OUT2BUF[i + out_offset + 5];
- tdo_data = 0;
-
- /* Shift the last byte */
- for (j = 0; j < bits_last_byte; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- /* Assert TMS signal if requested and this is the last bit */
- if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
- outb_buffer |= PIN_TMS;
- tms_count_end--;
- tms_sequence_end = tms_sequence_end >> 1;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- tdi_data = tdi_data >> 1;
- OUTB = (outb_buffer | PIN_TCK);
- tdo_data = tdo_data >> 1;
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
- tdo_data = tdo_data >> (8 - bits_last_byte);
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
-
- /* Move to correct end state */
- if (tms_count_end > 0) {
- jtag_clock_tms(tms_count_end, tms_sequence_end);
- }
+ uint8_t scan_size_bytes, bits_last_byte;
+ uint8_t tms_count_start, tms_count_end;
+ uint8_t tms_sequence_start, tms_sequence_end;
+ uint8_t tdi_data, tdo_data, i, j;
+
+ uint8_t outb_buffer;
+
+ /* Get parameters from OUT2BUF */
+ scan_size_bytes = OUT2BUF[out_offset];
+ bits_last_byte = OUT2BUF[out_offset + 1];
+ tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
+ tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
+ tms_sequence_start = OUT2BUF[out_offset + 3];
+ tms_sequence_end = OUT2BUF[out_offset + 4];
+
+ if (tms_count_start > 0)
+ jtag_clock_tms(tms_count_start, tms_sequence_start);
+
+ outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
+
+ /* Shift all bytes except the last byte */
+ for (i = 0; i < scan_size_bytes - 1; i++) {
+ tdi_data = OUT2BUF[i + out_offset + 5];
+ tdo_data = 0;
+
+ for (j = 0; j < 8; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ tdi_data = tdi_data >> 1;
+ OUTB = (outb_buffer | PIN_TCK);
+ tdo_data = tdo_data >> 1;
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+ }
+
+ tdi_data = OUT2BUF[i + out_offset + 5];
+ tdo_data = 0;
+
+ /* Shift the last byte */
+ for (j = 0; j < bits_last_byte; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ /* Assert TMS signal if requested and this is the last bit */
+ if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
+ outb_buffer |= PIN_TMS;
+ tms_count_end--;
+ tms_sequence_end = tms_sequence_end >> 1;
+ }
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ tdi_data = tdi_data >> 1;
+ OUTB = (outb_buffer | PIN_TCK);
+ tdo_data = tdo_data >> 1;
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+ tdo_data = tdo_data >> (8 - bits_last_byte);
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+
+ /* Move to correct end state */
+ if (tms_count_end > 0)
+ jtag_clock_tms(tms_count_end, tms_sequence_end);
}
/**
*/
void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
{
- uint8_t scan_size_bytes, bits_last_byte;
- uint8_t tms_count_start, tms_count_end;
- uint8_t tms_sequence_start, tms_sequence_end;
- uint8_t tdi_data, tdo_data, i, j, k;
-
- uint8_t outb_buffer;
-
- /* Get parameters from OUT2BUF */
- scan_size_bytes = OUT2BUF[out_offset];
- bits_last_byte = OUT2BUF[out_offset + 1];
- tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
- tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
- tms_sequence_start = OUT2BUF[out_offset + 3];
- tms_sequence_end = OUT2BUF[out_offset + 4];
-
- if (tms_count_start > 0) {
- jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
- }
-
- outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
-
- /* Shift all bytes except the last byte */
- for (i = 0; i < scan_size_bytes - 1; i++) {
- tdi_data = OUT2BUF[i + out_offset + 5];
- tdo_data = 0;
-
- for (j = 0; j < 8; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- for (k = 0; k < delay_scan_io; k++);
- tdi_data = tdi_data >> 1;
-
- OUTB = (outb_buffer | PIN_TCK);
- for (k = 0; k < delay_scan_io; k++);
- tdo_data = tdo_data >> 1;
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
- }
-
- tdi_data = OUT2BUF[i + out_offset + 5];
- tdo_data = 0;
-
- /* Shift the last byte */
- for (j = 0; j < bits_last_byte; j++) {
- if (tdi_data & 0x01) {
- outb_buffer |= PIN_TDI;
- }
- else {
- outb_buffer &= ~PIN_TDI;
- }
-
- /* Assert TMS signal if requested and this is the last bit */
- if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
- outb_buffer |= PIN_TMS;
- tms_count_end--;
- tms_sequence_end = tms_sequence_end >> 1;
- }
-
- OUTB = outb_buffer; /* TDI and TCK change here */
- for (k = 0; k < delay_scan_io; k++);
- tdi_data = tdi_data >> 1;
-
- OUTB = (outb_buffer | PIN_TCK);
- for (k = 0; k < delay_scan_io; k++);
- tdo_data = tdo_data >> 1;
-
- if (GET_TDO()) {
- tdo_data |= 0x80;
- }
- }
- tdo_data = tdo_data >> (8 - bits_last_byte);
-
- /* Copy TDO data to IN2BUF */
- IN2BUF[i + in_offset] = tdo_data;
-
- /* Move to correct end state */
- if (tms_count_end > 0) {
- jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
- }
+ uint8_t scan_size_bytes, bits_last_byte;
+ uint8_t tms_count_start, tms_count_end;
+ uint8_t tms_sequence_start, tms_sequence_end;
+ uint8_t tdi_data, tdo_data, i, j, k;
+
+ uint8_t outb_buffer;
+
+ /* Get parameters from OUT2BUF */
+ scan_size_bytes = OUT2BUF[out_offset];
+ bits_last_byte = OUT2BUF[out_offset + 1];
+ tms_count_start = (OUT2BUF[out_offset + 2] >> 4) & 0x0F;
+ tms_count_end = OUT2BUF[out_offset + 2] & 0x0F;
+ tms_sequence_start = OUT2BUF[out_offset + 3];
+ tms_sequence_end = OUT2BUF[out_offset + 4];
+
+ if (tms_count_start > 0)
+ jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
+
+ outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
+
+ /* Shift all bytes except the last byte */
+ for (i = 0; i < scan_size_bytes - 1; i++) {
+ tdi_data = OUT2BUF[i + out_offset + 5];
+ tdo_data = 0;
+
+ for (j = 0; j < 8; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ for (k = 0; k < delay_scan_io; k++)
+ ;
+ tdi_data = tdi_data >> 1;
+
+ OUTB = (outb_buffer | PIN_TCK);
+ for (k = 0; k < delay_scan_io; k++)
+ ;
+ tdo_data = tdo_data >> 1;
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+ }
+
+ tdi_data = OUT2BUF[i + out_offset + 5];
+ tdo_data = 0;
+
+ /* Shift the last byte */
+ for (j = 0; j < bits_last_byte; j++) {
+ if (tdi_data & 0x01)
+ outb_buffer |= PIN_TDI;
+ else
+ outb_buffer &= ~PIN_TDI;
+
+ /* Assert TMS signal if requested and this is the last bit */
+ if ((j == bits_last_byte - 1) && (tms_count_end > 0)) {
+ outb_buffer |= PIN_TMS;
+ tms_count_end--;
+ tms_sequence_end = tms_sequence_end >> 1;
+ }
+
+ OUTB = outb_buffer; /* TDI and TCK change here */
+ for (k = 0; k < delay_scan_io; k++)
+ ;
+ tdi_data = tdi_data >> 1;
+
+ OUTB = (outb_buffer | PIN_TCK);
+ for (k = 0; k < delay_scan_io; k++)
+ ;
+ tdo_data = tdo_data >> 1;
+
+ if (GET_TDO())
+ tdo_data |= 0x80;
+ }
+ tdo_data = tdo_data >> (8 - bits_last_byte);
+
+ /* Copy TDO data to IN2BUF */
+ IN2BUF[i + in_offset] = tdo_data;
+
+ /* Move to correct end state */
+ if (tms_count_end > 0)
+ jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
/**
*/
void jtag_clock_tck(uint16_t count)
{
- uint16_t i;
- uint8_t outb_buffer = OUTB & ~(PIN_TCK);
+ uint16_t i;
+ uint8_t outb_buffer = OUTB & ~(PIN_TCK);
- for ( i = 0; i < count; i++ ) {
- OUTB = outb_buffer;
- OUTB = outb_buffer | PIN_TCK;
- }
+ for (i = 0; i < count; i++) {
+ OUTB = outb_buffer;
+ OUTB = outb_buffer | PIN_TCK;
+ }
}
/**
*/
void jtag_slow_clock_tck(uint16_t count)
{
- uint16_t i;
- uint8_t j;
- uint8_t outb_buffer = OUTB & ~(PIN_TCK);
-
- for ( i = 0; i < count; i++ ) {
- OUTB = outb_buffer;
- for (j = 0; j < delay_tck; j++);
- OUTB = outb_buffer | PIN_TCK;
- for (j = 0; j < delay_tck; j++);
- }
+ uint16_t i;
+ uint8_t j;
+ uint8_t outb_buffer = OUTB & ~(PIN_TCK);
+
+ for (i = 0; i < count; i++) {
+ OUTB = outb_buffer;
+ for (j = 0; j < delay_tck; j++)
+ ;
+ OUTB = outb_buffer | PIN_TCK;
+ for (j = 0; j < delay_tck; j++)
+ ;
+ }
}
/**
*/
void jtag_clock_tms(uint8_t count, uint8_t sequence)
{
- uint8_t outb_buffer = OUTB & ~(PIN_TCK);
- uint8_t i;
-
- for ( i = 0; i < count; i++ ) {
- /* Set TMS pin according to sequence parameter */
- if ( sequence & 0x1 ) {
- outb_buffer |= PIN_TMS;
- }
- else {
- outb_buffer &= ~PIN_TMS;
- }
-
- OUTB = outb_buffer;
- sequence = sequence >> 1;
- OUTB = outb_buffer | PIN_TCK;
- }
+ uint8_t outb_buffer = OUTB & ~(PIN_TCK);
+ uint8_t i;
+
+ for (i = 0; i < count; i++) {
+ /* Set TMS pin according to sequence parameter */
+ if (sequence & 0x1)
+ outb_buffer |= PIN_TMS;
+ else
+ outb_buffer &= ~PIN_TMS;
+
+ OUTB = outb_buffer;
+ sequence = sequence >> 1;
+ OUTB = outb_buffer | PIN_TCK;
+ }
}
/**
*/
void jtag_slow_clock_tms(uint8_t count, uint8_t sequence)
{
- uint8_t outb_buffer = OUTB & ~(PIN_TCK);
- uint8_t i, j;
-
- for (i = 0; i < count; i++) {
- /* Set TMS pin according to sequence parameter */
- if ( sequence & 0x1 ) {
- outb_buffer |= PIN_TMS;
- }
- else {
- outb_buffer &= ~PIN_TMS;
- }
-
- OUTB = outb_buffer;
- for (j = 0; j < delay_tms; j++);
- sequence = sequence >> 1;
- OUTB = outb_buffer | PIN_TCK;
- for (j = 0; j < delay_tms; j++);
- }
+ uint8_t outb_buffer = OUTB & ~(PIN_TCK);
+ uint8_t i, j;
+
+ for (i = 0; i < count; i++) {
+ /* Set TMS pin according to sequence parameter */
+ if (sequence & 0x1)
+ outb_buffer |= PIN_TMS;
+ else
+ outb_buffer &= ~PIN_TMS;
+
+ OUTB = outb_buffer;
+ for (j = 0; j < delay_tms; j++)
+ ;
+ sequence = sequence >> 1;
+ OUTB = outb_buffer | PIN_TCK;
+ for (j = 0; j < delay_tms; j++)
+ ;
+ }
}
/**
*/
uint16_t jtag_get_signals(void)
{
- uint8_t input_signal_state, output_signal_state;
-
- input_signal_state = 0;
- output_signal_state = 0;
-
- /* Get states of input pins */
- if (GET_TDO()) {
- input_signal_state |= SIGNAL_TDO;
- }
- if (GET_BRKOUT()) {
- input_signal_state |= SIGNAL_BRKOUT;
- }
- if (GET_TRAP()) {
- input_signal_state |= SIGNAL_TRAP;
- }
- if (GET_RTCK()) {
- /* Using RTCK this way would be extremely slow,
- * implemented only for the sake of completeness */
- input_signal_state |= SIGNAL_RTCK;
- }
-
- /* Get states of output pins */
- output_signal_state = PINSB & MASK_PORTB_DIRECTION_OUT;
-
- return ((uint16_t)input_signal_state << 8) | ((uint16_t)output_signal_state);
+ uint8_t input_signal_state, output_signal_state;
+
+ input_signal_state = 0;
+ output_signal_state = 0;
+
+ /* Get states of input pins */
+ if (GET_TDO())
+ input_signal_state |= SIGNAL_TDO;
+ if (GET_BRKOUT())
+ input_signal_state |= SIGNAL_BRKOUT;
+ if (GET_TRAP())
+ input_signal_state |= SIGNAL_TRAP;
+ if (GET_RTCK()) {
+ /* Using RTCK this way would be extremely slow,
+ * implemented only for the sake of completeness */
+ input_signal_state |= SIGNAL_RTCK;
+ }
+
+ /* Get states of output pins */
+ output_signal_state = PINSB & MASK_PORTB_DIRECTION_OUT;
+
+ return ((uint16_t)input_signal_state << 8) | ((uint16_t)output_signal_state);
}
/**
*/
void jtag_set_signals(uint8_t low, uint8_t high)
{
- OUTB &= ~(low & MASK_PORTB_DIRECTION_OUT);
- OUTB |= (high & MASK_PORTB_DIRECTION_OUT);
+ OUTB &= ~(low & MASK_PORTB_DIRECTION_OUT);
+ OUTB |= (high & MASK_PORTB_DIRECTION_OUT);
}
/**
* @param tms number of delay cycles in clock_tms operations.
*/
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)
{
- delay_scan_in = scan_in;
- delay_scan_out = scan_out;
- delay_scan_io = scan_io;
- delay_tck = tck;
- delay_tms = tms;
+ delay_scan_in = scan_in;
+ delay_scan_out = scan_out;
+ delay_scan_io = scan_io;
+ delay_tck = tck;
+ delay_tms = tms;
}
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;
}
* 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
*/
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();
}
/**
*/
bool execute_command(void)
{
- 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;
-
- 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;
-
- /* 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;
- }
+ 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;
+
+ 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;
+
+ /* 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;
+ }
}
/**
*/
void command_loop(void)
{
- bool last_command;
-
- while (1) {
- cmd_id_index = 0;
- payload_index_in = 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();
-
- /* 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;
- }
-
- /* Re-arm EP2-OUT after command execution */
- OUT2BC = 0;
- }
+ bool last_command;
+
+ while (1) {
+ cmd_id_index = 0;
+ payload_index_in = 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();
+
+ /* 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;
+ }
+
+ /* Re-arm EP2-OUT after command execution */
+ OUT2BC = 0;
+ }
}
/* 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:
*/
__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
* 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;
-
- 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;
+ /* 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;
+ }
+
+ return NULL;
}
void usb_reset_data_toggle(uint8_t ep)
{
- /* 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);
-
- /* First step: Write EP number and direction bit */
- TOGCTL = togctl_value;
-
- /* Second step: Set R bit */
- togctl_value |= TOG_R;
- TOGCTL = togctl_value;
+ /* 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);
+
+ /* First step: Write EP number and direction bit */
+ TOGCTL = togctl_value;
+
+ /* Second step: Set R bit */
+ togctl_value |= TOG_R;
+ TOGCTL = togctl_value;
}
/**
*/
bool usb_handle_get_status(void)
{
- 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;
-
- /* 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);
-
- if (*ep_cs & EPSTALL) {
- IN0BUF[0] = 0x01;
- }
- else {
- IN0BUF[0] = 0x00;
- }
-
- /* Second byte sent has to be always zero */
- IN0BUF[1] = 0;
-
- /* Send response */
- IN0BC = 2;
- break;
- default:
- return false;
- break;
- }
-
- return true;
+ 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;
+
+ /* 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);
+
+ if (*ep_cs & EPSTALL)
+ IN0BUF[0] = 0x01;
+ else
+ IN0BUF[0] = 0x00;
+
+ /* Second byte sent has to be always zero */
+ IN0BUF[1] = 0;
+
+ /* Send response */
+ IN0BC = 2;
+ break;
+ default:
+ return false;
+ break;
+ }
+
+ return true;
}
/**
*/
bool usb_handle_clear_feature(void)
{
- __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... */
- }
-
- return true;
+ __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... */
+ }
+
+ return true;
}
/**
*/
bool usb_handle_set_feature(void)
{
- __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;
- }
-
- return true;
+ __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;
+ }
+
+ return true;
}
/**
*/
bool usb_handle_get_descriptor(void)
{
- __xdata uint8_t descriptor_type;
- __xdata uint8_t descriptor_index;
-
- 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;
- }
-
- return true;
+ __xdata uint8_t descriptor_type;
+ __xdata uint8_t descriptor_index;
+
+ 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;
+ }
+
+ return true;
}
/**
*/
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);
-
- /* Unstall & clear busy flag of all valid IN endpoints */
- IN2CS = 0 | EPBSY;
-
- /* Unstall all valid OUT endpoints, reset bytecounts */
- OUT2CS = 0;
- OUT2BC = 0;
+ /* 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;
}
/**
*/
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;
-
- /* 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;
-
- /* Enable USB Autovectoring */
- USBBAV |= AVEN;
-
- /* Enable SUDAV interrupt */
- USBIEN |= SUDAVIE;
-
- /* Enable EP2 OUT & IN interrupts */
- OUT07IEN = OUT2IEN;
- IN07IEN = IN2IEN;
-
- /* Enable USB interrupt (EIE register) */
- EUSB = 1;
-
- /* Perform ReNumeration */
- USBCS = DISCON | RENUM;
- delay_ms(200);
- USBCS = DISCOE | RENUM;
+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;
+
+ /* 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 EP2 OUT & IN interrupts */
+ OUT07IEN = OUT2IEN;
+ IN07IEN = IN2IEN;
+
+ /* Enable USB interrupt (EIE register) */
+ EUSB = 1;
+
+ /* Perform ReNumeration */
+ USBCS = DISCON | RENUM;
+ delay_ms(200);
+ USBCS = DISCOE | RENUM;
}
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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
/* 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;
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); \
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); \
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); \
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); \
#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
* 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)
{
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);
}
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);
}
}
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)
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);
}
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);
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);
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);
}
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)
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;
*/
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);
version.dwOSVersionInfoSize = sizeof version;
if (!GetVersionEx(&version)) {
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
- return 0;
-
- h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ return 0;
+
+ 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);
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;
}
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;
}
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);
outb(0x04, amt_jtagaccel_port + 2);
#endif
- if (rtck_enabled)
- {
+ if (rtck_enabled) {
/* set RTCK enable bit */
aw_control_fsm |= 0x02;
}
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;
}
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;
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 */
/* 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);
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)
{
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);
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:
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;
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;
}
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;
}
return ERROR_OK;
}
-static int armjtagew_speed_div(int speed, int* khz)
+static int armjtagew_speed_div(int speed, int *khz)
{
*khz = speed;
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;
}
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);
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);
}
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);
}
{
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);
}
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;
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)
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;
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)
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;
}
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();
}
.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
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;
};
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)
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;
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++;
}
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);
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;
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;
}
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();
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;
}
{
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);
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);
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();
}
}
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/mman.h>
-
/* AT91RM9200 */
#define AT91C_BASE_SYS (0xfffff000)
#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 */
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
*/
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,
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]);
}
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,
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;
}
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
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
*/
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!
*/
#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);
}
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);
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);
return ERROR_OK;
}
-
static void bitbang_path_move(struct pathmove_command *cmd)
{
int num_states = cmd->num_states;
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);
}
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);
}
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
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;
bitbang_interface->write(1, tms, tdi);
- if (type != SCAN_OUT)
- {
+ if (type != SCAN_OUT) {
if (val)
buffer[bytec] |= bcval;
else
}
}
- 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.
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);
}
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);
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);
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifndef BITBANG_H
#define BITBANG_H
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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 {
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
}
}
-
static void bitq_io(int tms, int tdi, int tdo_req)
{
bitq_interface->out(tms, tdi, 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);
}
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;
}
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);
tap_set_end_state(tap_get_state());
}
-
static void bitq_runtest(int num_cycles)
{
int i;
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)
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);
}
}
-
static void bitq_scan(struct scan_command *cmd)
{
int i;
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();
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;
}
return bitq_in_state.status;
}
-
void bitq_cleanup(void)
{
}
* 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);
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
SERIAL_FAST = 1
};
-
static int buspirate_fd = -1;
static int buspirate_pinmode = MODE_JTAG_OD;
static int buspirate_baudrate = SERIAL_NORMAL;
static int buspirate_pullup;
static char *buspirate_port;
-
/* TAP interface */
static void buspirate_tap_init(void);
static int buspirate_tap_execute(void);
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;
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;
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 */
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;
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;
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]);
}
}
- if (line[0] != 0) {
+ if (line[0] != 0)
LOG_DEBUG("%s", line);
- }
}
-
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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;
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)
{
*
* 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 */
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;
}
* 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++;
}
/* 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++;
}
return ERROR_OK;
}
-
-
/**
* Generate a DR SCAN using the array of output values passed to the function
*
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++;
}
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;
}
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);
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);
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);
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);
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);
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);
}
/* 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));
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;
}
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;
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;
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);
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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;
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;
}
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
*/
.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;
}
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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;
struct timespec ep93xx_zzzz;
-struct jtag_interface ep93xx_interface =
-{
+struct jtag_interface ep93xx_interface = {
.name = "ep93xx",
.supported = DEBUG_CAP_TMS_SEQ,
.quit = ep93xx_quit,
};
-static struct bitbang_interface ep93xx_bitbang =
-{
+static struct bitbang_interface ep93xx_bitbang = {
.read = ep93xx_read,
.write = ep93xx_write,
.reset = ep93xx_reset,
#include <ftd2xx.h>
#include "ftd2xx_common.h"
-enum ftdi_interface
-{
- INTERFACE_ANY = 0,
- INTERFACE_A = 1,
- INTERFACE_B = 2,
- INTERFACE_C = 3,
- INTERFACE_D = 4
+enum ftdi_interface {
+ INTERFACE_ANY = 0,
+ INTERFACE_A = 1,
+ INTERFACE_B = 2,
+ INTERFACE_C = 3,
+ INTERFACE_D = 4
};
#elif BUILD_FT2232_LIBFTDI == 1
/* max TCK for the high speed devices 30000 kHz */
#define FTDI_2232H_4232H_MAX_TCK 30000
/* max TCK for the full speed devices 6000 kHz */
-#define FTDI_2232C_MAX_TCK 6000
+#define FTDI_2232C_MAX_TCK 6000
/* this speed value tells that RTCK is requested */
#define RTCK_SPEED -1
*
* @returns ERROR_OK on success, or ERROR_JTAG_QUEUE_FAILED on failure.
*/
-static int ft2232_stableclocks(int num_cycles, struct jtag_command* cmd);
+static int ft2232_stableclocks(int num_cycles, struct jtag_command *cmd);
-static char * ft2232_device_desc_A = NULL;
-static char* ft2232_device_desc = NULL;
-static char* ft2232_serial = NULL;
-static uint8_t ft2232_latency = 2;
-static unsigned ft2232_max_tck = FTDI_2232C_MAX_TCK;
+static char *ft2232_device_desc_A;
+static char *ft2232_device_desc;
+static char *ft2232_serial;
+static uint8_t ft2232_latency = 2;
+static unsigned ft2232_max_tck = FTDI_2232C_MAX_TCK;
#define MAX_USB_IDS 8
/* vid = pid = 0 marks the end of the list */
static uint16_t ft2232_pid[MAX_USB_IDS + 1] = { 0x6010, 0 };
struct ft2232_layout {
- char* name;
+ char *name;
int (*init)(void);
void (*reset)(int trst, int srst);
void (*blink)(void);
/* common transport support options */
-//static const char *jtag_and_swd[] = { "jtag", "swd", NULL };
+/* static const char *jtag_and_swd[] = { "jtag", "swd", NULL }; */
-static const struct ft2232_layout ft2232_layouts[] =
-{
+static const struct ft2232_layout ft2232_layouts[] = {
{ .name = "usbjtag",
.init = usbjtag_init,
.reset = ftx23_reset,
},
{ .name = "redbee-usb",
.init = redbee_init,
- .reset = redbee_reset,
- .channel = INTERFACE_B,
+ .reset = redbee_reset,
+ .channel = INTERFACE_B,
},
{ .name = "lisa-l",
.init = lisa_l_init,
};
/* bitmask used to drive nTRST; usually a GPIOLx signal */
-static uint8_t nTRST;
-static uint8_t nTRSTnOE;
+static uint8_t nTRST;
+static uint8_t nTRSTnOE;
/* bitmask used to drive nSRST; usually a GPIOLx signal */
-static uint8_t nSRST;
-static uint8_t nSRSTnOE;
+static uint8_t nSRST;
+static uint8_t nSRSTnOE;
/** the layout being used with this debug session */
static const struct ft2232_layout *layout;
/** default bitmask values driven on DBUS: TCK/TDI/TDO/TMS and GPIOL(0..4) */
-static uint8_t low_output = 0x0;
+static uint8_t low_output;
/* note that direction bit == 1 means that signal is an output */
/** default direction bitmask for DBUS: TCK/TDI/TDO/TMS and GPIOL(0..4) */
-static uint8_t low_direction = 0x0;
+static uint8_t low_direction;
/** default value bitmask for CBUS GPIOH(0..4) */
-static uint8_t high_output = 0x0;
+static uint8_t high_output;
/** default direction bitmask for CBUS GPIOH(0..4) */
-static uint8_t high_direction = 0x0;
+static uint8_t high_direction;
#if BUILD_FT2232_FTD2XX == 1
-static FT_HANDLE ftdih = NULL;
-static FT_DEVICE ftdi_device = 0;
+static FT_HANDLE ftdih;
+static FT_DEVICE ftdi_device;
#elif BUILD_FT2232_LIBFTDI == 1
static struct ftdi_context ftdic;
static enum ftdi_chip_type ftdi_device;
#endif
-static struct jtag_command* first_unsent; /* next command that has to be sent */
-static int require_send;
+static struct jtag_command *first_unsent; /* next command that has to be sent */
+static int require_send;
/* http://urjtag.wiki.sourceforge.net/Cable + FT2232 says:
*/
#if BUILD_FT2232_FTD2XX == 1
-#define FT2232_BUFFER_READ_QUEUE_SIZE (64*64)
+#define FT2232_BUFFER_READ_QUEUE_SIZE (64*64)
#else
-#define FT2232_BUFFER_READ_QUEUE_SIZE (64*4)
+#define FT2232_BUFFER_READ_QUEUE_SIZE (64*4)
#endif
#define FT2232_BUFFER_SIZE 131072
-static uint8_t* ft2232_buffer = NULL;
-static int ft2232_buffer_size = 0;
-static int ft2232_read_pointer = 0;
-static int ft2232_expect_read = 0;
+static uint8_t *ft2232_buffer;
+static int ft2232_buffer_size;
+static int ft2232_read_pointer;
+static int ft2232_expect_read;
/**
* Function buffer_write
*/
static void clock_tms(uint8_t mpsse_cmd, int tms_bits, int tms_count, bool tdi_bit)
{
- uint8_t tms_byte;
- int i;
- int tms_ndx; /* bit index into tms_byte */
+ uint8_t tms_byte;
+ int i;
+ int tms_ndx; /* bit index into tms_byte */
assert(tms_count > 0);
DEBUG_JTAG_IO("mpsse cmd=%02x, tms_bits = 0x%08x, bit_count=%d",
- mpsse_cmd, tms_bits, tms_count);
+ mpsse_cmd, tms_bits, tms_count);
- for (tms_byte = tms_ndx = i = 0; i < tms_count; ++i, tms_bits>>=1)
- {
+ for (tms_byte = tms_ndx = i = 0; i < tms_count; ++i, tms_bits >>= 1) {
bool bit = tms_bits & 1;
if (bit)
tap_set_state(tap_state_transition(tap_get_state(), bit));
/* we wrote a bit to tms_byte just above, increment bit index. if bit was zero
- also increment.
+ * also increment.
*/
++tms_ndx;
- if (tms_ndx == 7 || i == tms_count-1)
- {
+ if (tms_ndx == 7 || i == tms_count-1) {
buffer_write(mpsse_cmd);
buffer_write(tms_ndx - 1);
/* Bit 7 of the byte is passed on to TDI/DO before the first TCK/SK of
- TMS/CS and is held static for the duration of TMS/CS clocking.
+ * TMS/CS and is held static for the duration of TMS/CS clocking.
*/
buffer_write(tms_byte | (tdi_bit << 7));
}
*/
static void move_to_state(tap_state_t goal_state)
{
- tap_state_t start_state = tap_get_state();
+ tap_state_t start_state = tap_get_state();
/* goal_state is 1/2 of a tuple/pair of states which allow convenient
- lookup of the required TMS pattern to move to this state from the
- start state.
+ * lookup of the required TMS pattern to move to this state from the start state.
*/
/* do the 2 lookups */
clock_tms(0x4b, tms_bits, tms_count, 0);
}
-static int ft2232_write(uint8_t* buf, int size, uint32_t* bytes_written)
+static int ft2232_write(uint8_t *buf, int size, uint32_t *bytes_written)
{
#if BUILD_FT2232_FTD2XX == 1
FT_STATUS status;
DWORD dw_bytes_written = 0;
- if ((status = FT_Write(ftdih, buf, size, &dw_bytes_written)) != FT_OK)
- {
+ status = FT_Write(ftdih, buf, size, &dw_bytes_written);
+ if (status != FT_OK) {
*bytes_written = dw_bytes_written;
LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
- }
- else
- {
+ } else
*bytes_written = dw_bytes_written;
- }
+
#elif BUILD_FT2232_LIBFTDI == 1
- int retval;
- if ((retval = ftdi_write_data(&ftdic, buf, size)) < 0)
- {
+ int retval = ftdi_write_data(&ftdic, buf, size);
+ if (retval < 0) {
*bytes_written = 0;
LOG_ERROR("ftdi_write_data: %s", ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR;
- }
- else
- {
+ } else
*bytes_written = retval;
- }
+
#endif
if (*bytes_written != (uint32_t)size)
- {
return ERROR_JTAG_DEVICE_ERROR;
- }
return ERROR_OK;
}
-static int ft2232_read(uint8_t* buf, uint32_t size, uint32_t* bytes_read)
+static int ft2232_read(uint8_t *buf, uint32_t size, uint32_t *bytes_read)
{
#if BUILD_FT2232_FTD2XX == 1
DWORD dw_bytes_read;
int timeout = 5;
*bytes_read = 0;
- while ((*bytes_read < size) && timeout--)
- {
- if ((status = FT_Read(ftdih, buf + *bytes_read, size -
- *bytes_read, &dw_bytes_read)) != FT_OK)
- {
+ while ((*bytes_read < size) && timeout--) {
+ status = FT_Read(ftdih, buf + *bytes_read, size -
+ *bytes_read, &dw_bytes_read);
+ if (status != FT_OK) {
*bytes_read = 0;
LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
int timeout = LIBFTDI_READ_RETRY_COUNT;
*bytes_read = 0;
- while ((*bytes_read < size) && timeout--)
- {
- if ((retval = ftdi_read_data(&ftdic, buf + *bytes_read, size - *bytes_read)) < 0)
- {
+ while ((*bytes_read < size) && timeout--) {
+ retval = ftdi_read_data(&ftdic, buf + *bytes_read, size - *bytes_read);
+ if (retval < 0) {
*bytes_read = 0;
LOG_ERROR("ftdi_read_data: %s", ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR;
#endif
- if (*bytes_read < size)
- {
+ if (*bytes_read < size) {
LOG_ERROR("couldn't read enough bytes from "
- "FT2232 device (%i < %i)",
- (unsigned)*bytes_read,
- (unsigned)size);
+ "FT2232 device (%i < %i)",
+ (unsigned)*bytes_read,
+ (unsigned)size);
return ERROR_JTAG_DEVICE_ERROR;
}
uint32_t bytes_written;
int retval;
- if ((retval = ft2232_write(&buf, sizeof(buf), &bytes_written)) != ERROR_OK)
- {
+ retval = ft2232_write(&buf, sizeof(buf), &bytes_written);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't write command to %s adaptive clocking"
, enable ? "enable" : "disable");
return retval;
uint32_t bytes_written;
uint8_t buf = enable ? 0x8b : 0x8a;
- if (ft2232_write(&buf, sizeof(buf), &bytes_written) != ERROR_OK)
- {
+ if (ft2232_write(&buf, sizeof(buf), &bytes_written) != ERROR_OK) {
LOG_ERROR("couldn't write command to %s clk divide by 5"
, enable ? "enable" : "disable");
return ERROR_JTAG_INIT_FAILED;
bool enable_adaptive_clocking = (RTCK_SPEED == speed);
if (ft2232_device_is_highspeed())
retval = ft2232h_ft4232h_adaptive_clocking(enable_adaptive_clocking);
- else if (enable_adaptive_clocking)
- {
+ else if (enable_adaptive_clocking) {
LOG_ERROR("ft2232 device %lu does not support RTCK"
, (long unsigned int)ftdi_device);
return ERROR_FAIL;
buf[2] = (speed >> 8) & 0xff; /* valueH */
LOG_DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
- if ((retval = ft2232_write(buf, sizeof(buf), &bytes_written)) != ERROR_OK)
- {
+ retval = ft2232_write(buf, sizeof(buf), &bytes_written);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't set FT2232 TCK speed");
return retval;
}
return ERROR_OK;
}
-static int ft2232_speed_div(int speed, int* khz)
+static int ft2232_speed_div(int speed, int *khz)
{
/* Take a look in the FT2232 manual,
* AN2232C-01 Command Processor for
return ERROR_OK;
}
-static int ft2232_khz(int khz, int* jtag_speed)
+static int ft2232_khz(int khz, int *jtag_speed)
{
- if (khz == 0)
- {
- if (ft2232_device_is_highspeed())
- {
+ if (khz == 0) {
+ if (ft2232_device_is_highspeed()) {
*jtag_speed = RTCK_SPEED;
return ERROR_OK;
- }
- else
- {
+ } else {
LOG_DEBUG("RCLK not supported");
return ERROR_FAIL;
}
* We will calc here with a multiplier
* of 10 for better rounding later. */
- /* Calc speed, (ft2232_max_tck / khz) - 1 */
- /* Use 65000 for better rounding */
+ /* Calc speed, (ft2232_max_tck / khz) - 1
+ * Use 65000 for better rounding */
*jtag_speed = ((ft2232_max_tck*10) / khz) - 10;
/* Add 0.9 for rounding */
/* Check if speed is greater than 0 */
if (*jtag_speed < 0)
- {
*jtag_speed = 0;
- }
/* Check max value */
if (*jtag_speed > 0xFFFF)
- {
*jtag_speed = 0xFFFF;
- }
return ERROR_OK;
}
{
if (tap_is_state_stable(state))
tap_set_end_state(state);
- else
- {
+ else {
LOG_ERROR("BUG: %s is not a stable end state", tap_state_name(state));
exit(-1);
}
}
-static void ft2232_read_scan(enum scan_type type, uint8_t* buffer, int scan_size)
+static void ft2232_read_scan(enum scan_type type, uint8_t *buffer, int scan_size)
{
int num_bytes = (scan_size + 7) / 8;
int bits_left = scan_size;
int cur_byte = 0;
- while (num_bytes-- > 1)
- {
+ while (num_bytes-- > 1) {
buffer[cur_byte++] = buffer_read();
bits_left -= 8;
}
/* There is one more partial byte left from the clock data in/out instructions */
if (bits_left > 1)
- {
buffer[cur_byte] = buffer_read() >> 1;
- }
- /* This shift depends on the length of the clock data to tms instruction, insterted at end of the scan, now fixed to a two step transition in ft2232_add_scan */
+ /* This shift depends on the length of the
+ *clock data to tms instruction, insterted
+ *at end of the scan, now fixed to a two
+ *step transition in ft2232_add_scan */
buffer[cur_byte] = (buffer[cur_byte] | (((buffer_read()) << 1) & 0x80)) >> (8 - bits_left);
}
{
int i;
char line[256];
- char* line_p = line;
-
- for (i = 0; i < ft2232_buffer_size; i++)
- {
- line_p += snprintf(line_p, sizeof(line) - (line_p - line), "%2.2x ", ft2232_buffer[i]);
- if (i % 16 == 15)
- {
+ char *line_p = line;
+
+ for (i = 0; i < ft2232_buffer_size; i++) {
+ line_p += snprintf(line_p,
+ sizeof(line) - (line_p - line),
+ "%2.2x ",
+ ft2232_buffer[i]);
+ if (i % 16 == 15) {
LOG_DEBUG("%s", line);
line_p = line;
}
LOG_DEBUG("%s", line);
}
-static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command* last)
+static int ft2232_send_and_recv(struct jtag_command *first, struct jtag_command *last)
{
- struct jtag_command* cmd;
- uint8_t* buffer;
+ struct jtag_command *cmd;
+ uint8_t *buffer;
int scan_size;
- enum scan_type type;
+ enum scan_type type;
int retval;
uint32_t bytes_written = 0;
uint32_t bytes_read = 0;
#ifdef _DEBUG_USB_IO_
- struct timeval start, inter, inter2, end;
- struct timeval d_inter, d_inter2, d_end;
+ struct timeval start, inter, inter2, end;
+ struct timeval d_inter, d_inter2, d_end;
#endif
#ifdef _DEBUG_USB_COMMS_
gettimeofday(&start, NULL);
#endif
- if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
- {
+ retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't write MPSSE commands to FT2232");
return retval;
}
gettimeofday(&inter, NULL);
#endif
- if (ft2232_expect_read)
- {
+ if (ft2232_expect_read) {
/* FIXME this "timeout" is never changed ... */
int timeout = LIBFTDI_READ_RETRY_COUNT;
ft2232_buffer_size = 0;
gettimeofday(&inter2, NULL);
#endif
- if ((retval = ft2232_read(ft2232_buffer, ft2232_expect_read, &bytes_read)) != ERROR_OK)
- {
+ retval = ft2232_read(ft2232_buffer, ft2232_expect_read, &bytes_read);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't read from FT2232");
return retval;
}
ft2232_buffer_size = bytes_read;
- if (ft2232_expect_read != ft2232_buffer_size)
- {
+ if (ft2232_expect_read != ft2232_buffer_size) {
LOG_ERROR("ft2232_expect_read (%i) != "
- "ft2232_buffer_size (%i) "
- "(%i retries)",
- ft2232_expect_read,
- ft2232_buffer_size,
- LIBFTDI_READ_RETRY_COUNT - timeout);
+ "ft2232_buffer_size (%i) "
+ "(%i retries)",
+ ft2232_expect_read,
+ ft2232_buffer_size,
+ LIBFTDI_READ_RETRY_COUNT - timeout);
ft2232_debug_dump_buffer();
exit(-1);
#ifdef _DEBUG_USB_COMMS_
LOG_DEBUG("read buffer (%i retries): %i bytes",
- LIBFTDI_READ_RETRY_COUNT - timeout,
- ft2232_buffer_size);
+ LIBFTDI_READ_RETRY_COUNT - timeout,
+ ft2232_buffer_size);
ft2232_debug_dump_buffer();
#endif
}
retval = ERROR_OK;
cmd = first;
- while (cmd != last)
- {
- switch (cmd->type)
- {
- case JTAG_SCAN:
- type = jtag_scan_type(cmd->cmd.scan);
- if (type != SCAN_OUT)
- {
- scan_size = jtag_scan_size(cmd->cmd.scan);
- buffer = calloc(DIV_ROUND_UP(scan_size, 8), 1);
- ft2232_read_scan(type, buffer, scan_size);
- if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
- retval = ERROR_JTAG_QUEUE_FAILED;
- free(buffer);
- }
- break;
-
- default:
- break;
+ while (cmd != last) {
+ switch (cmd->type) {
+ case JTAG_SCAN:
+ type = jtag_scan_type(cmd->cmd.scan);
+ if (type != SCAN_OUT) {
+ scan_size = jtag_scan_size(cmd->cmd.scan);
+ buffer = calloc(DIV_ROUND_UP(scan_size, 8), 1);
+ ft2232_read_scan(type, buffer, scan_size);
+ if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK)
+ retval = ERROR_JTAG_QUEUE_FAILED;
+ free(buffer);
+ }
+ break;
+
+ default:
+ break;
}
cmd = cmd->next;
* ending with the last state at path[num_states-1]
* @param num_states is the count of state steps to move through
*/
-static void ft2232_add_pathmove(tap_state_t* path, int num_states)
+static void ft2232_add_pathmove(tap_state_t *path, int num_states)
{
int state_count = 0;
DEBUG_JTAG_IO("-");
/* this loop verifies that the path is legal and logs each state in the path */
- while (num_states)
- {
- unsigned char tms_byte = 0; /* zero this on each MPSSE batch */
- int bit_count = 0;
- int num_states_batch = num_states > 7 ? 7 : num_states;
+ while (num_states) {
+ unsigned char tms_byte = 0; /* zero this on each MPSSE batch */
+ int bit_count = 0;
+ int num_states_batch = num_states > 7 ? 7 : num_states;
/* command "Clock Data to TMS/CS Pin (no Read)" */
buffer_write(0x4b);
while (num_states_batch--) {
/* either TMS=0 or TMS=1 must work ... */
- if (tap_state_transition(tap_get_state(), false)
- == path[state_count])
+ if (tap_state_transition(tap_get_state(), false) == path[state_count])
buf_set_u32(&tms_byte, bit_count++, 1, 0x0);
- else if (tap_state_transition(tap_get_state(), true)
- == path[state_count])
+ else if (tap_state_transition(tap_get_state(), true) == path[state_count])
buf_set_u32(&tms_byte, bit_count++, 1, 0x1);
/* ... or else the caller goofed BADLY */
else {
LOG_ERROR("BUG: %s -> %s isn't a valid "
- "TAP state transition",
+ "TAP state transition",
tap_state_name(tap_get_state()),
tap_state_name(path[state_count]));
exit(-1);
tap_set_end_state(tap_get_state());
}
-static void ft2232_add_scan(bool ir_scan, enum scan_type type, uint8_t* buffer, int scan_size)
+static void ft2232_add_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
{
int num_bytes = (scan_size + 7) / 8;
int bits_left = scan_size;
int cur_byte = 0;
int last_bit;
- if (!ir_scan)
- {
+ if (!ir_scan) {
if (tap_get_state() != TAP_DRSHIFT)
- {
move_to_state(TAP_DRSHIFT);
- }
- }
- else
- {
+ } else {
if (tap_get_state() != TAP_IRSHIFT)
- {
move_to_state(TAP_IRSHIFT);
- }
}
/* add command for complete bytes */
- while (num_bytes > 1)
- {
+ while (num_bytes > 1) {
int thisrun_bytes;
- if (type == SCAN_IO)
- {
+ if (type == SCAN_IO) {
/* Clock Data Bytes In and Out LSB First */
buffer_write(0x39);
/* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
- }
- else if (type == SCAN_OUT)
- {
+ } else if (type == SCAN_OUT) {
/* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
buffer_write(0x19);
/* LOG_DEBUG("added TDI bytes (o)"); */
- }
- else if (type == SCAN_IN)
- {
+ } else if (type == SCAN_IN) {
/* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
buffer_write(0x28);
/* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
}
thisrun_bytes = (num_bytes > 65537) ? 65536 : (num_bytes - 1);
- num_bytes -= thisrun_bytes;
+ num_bytes -= thisrun_bytes;
buffer_write((uint8_t) (thisrun_bytes - 1));
buffer_write((uint8_t) ((thisrun_bytes - 1) >> 8));
- if (type != SCAN_IN)
- {
+ if (type != SCAN_IN) {
/* add complete bytes */
- while (thisrun_bytes-- > 0)
- {
+ while (thisrun_bytes-- > 0) {
buffer_write(buffer[cur_byte++]);
bits_left -= 8;
}
- }
- else /* (type == SCAN_IN) */
- {
+ } else /* (type == SCAN_IN) */
bits_left -= 8 * (thisrun_bytes);
- }
}
/* the most signifcant bit is scanned during TAP movement */
last_bit = 0;
/* process remaining bits but the last one */
- if (bits_left > 1)
- {
- if (type == SCAN_IO)
- {
+ if (bits_left > 1) {
+ if (type == SCAN_IO) {
/* Clock Data Bits In and Out LSB First */
buffer_write(0x3b);
/* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
- }
- else if (type == SCAN_OUT)
- {
+ } else if (type == SCAN_OUT) {
/* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
buffer_write(0x1b);
/* LOG_DEBUG("added TDI bits (o)"); */
- }
- else if (type == SCAN_IN)
- {
+ } else if (type == SCAN_IN) {
/* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
buffer_write(0x2a);
/* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
}
if ((ir_scan && (tap_get_end_state() == TAP_IRSHIFT))
- || (!ir_scan && (tap_get_end_state() == TAP_DRSHIFT)))
- {
- if (type == SCAN_IO)
- {
+ || (!ir_scan && (tap_get_end_state() == TAP_DRSHIFT))) {
+ if (type == SCAN_IO) {
/* Clock Data Bits In and Out LSB First */
buffer_write(0x3b);
/* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
- }
- else if (type == SCAN_OUT)
- {
+ } else if (type == SCAN_OUT) {
/* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
buffer_write(0x1b);
/* LOG_DEBUG("added TDI bits (o)"); */
- }
- else if (type == SCAN_IN)
- {
+ } else if (type == SCAN_IN) {
/* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
buffer_write(0x2a);
/* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
}
buffer_write(0x0);
buffer_write(last_bit);
- }
- else
- {
+ } else {
int tms_bits;
int tms_count;
- uint8_t mpsse_cmd;
+ uint8_t mpsse_cmd;
/* move from Shift-IR/DR to end state */
- if (type != SCAN_OUT)
- {
- /* We always go to the PAUSE state in two step at the end of an IN or IO scan */
- /* This must be coordinated with the bit shifts in ft2232_read_scan */
+ if (type != SCAN_OUT) {
+ /* We always go to the PAUSE state in two step at the end of an IN or IO
+ *scan
+ * This must be coordinated with the bit shifts in ft2232_read_scan */
tms_bits = 0x01;
tms_count = 2;
/* Clock Data to TMS/CS Pin with Read */
mpsse_cmd = 0x6b;
- }
- else
- {
+ } else {
tms_bits = tap_get_tms_path(tap_get_state(), tap_get_end_state());
tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
/* Clock Data to TMS/CS Pin (no Read) */
}
if (tap_get_state() != tap_get_end_state())
- {
move_to_state(tap_get_end_state());
- }
}
-static int ft2232_large_scan(struct scan_command* cmd, enum scan_type type, uint8_t* buffer, int scan_size)
+static int ft2232_large_scan(struct scan_command *cmd,
+ enum scan_type type,
+ uint8_t *buffer,
+ int scan_size)
{
int num_bytes = (scan_size + 7) / 8;
int bits_left = scan_size;
int cur_byte = 0;
int last_bit;
- uint8_t* receive_buffer = malloc(DIV_ROUND_UP(scan_size, 8));
- uint8_t* receive_pointer = receive_buffer;
+ uint8_t *receive_buffer = malloc(DIV_ROUND_UP(scan_size, 8));
+ uint8_t *receive_pointer = receive_buffer;
uint32_t bytes_written;
uint32_t bytes_read;
int retval;
int thisrun_read = 0;
- if (cmd->ir_scan)
- {
+ if (cmd->ir_scan) {
LOG_ERROR("BUG: large IR scans are not supported");
exit(-1);
}
if (tap_get_state() != TAP_DRSHIFT)
- {
move_to_state(TAP_DRSHIFT);
- }
- if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
- {
+ retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't write MPSSE commands to FT2232");
exit(-1);
}
LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i",
- ft2232_buffer_size, (int)bytes_written);
+ ft2232_buffer_size, (int)bytes_written);
ft2232_buffer_size = 0;
/* add command for complete bytes */
- while (num_bytes > 1)
- {
+ while (num_bytes > 1) {
int thisrun_bytes;
- if (type == SCAN_IO)
- {
+ if (type == SCAN_IO) {
/* Clock Data Bytes In and Out LSB First */
buffer_write(0x39);
/* LOG_DEBUG("added TDI bytes (io %i)", num_bytes); */
- }
- else if (type == SCAN_OUT)
- {
+ } else if (type == SCAN_OUT) {
/* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
buffer_write(0x19);
/* LOG_DEBUG("added TDI bytes (o)"); */
- }
- else if (type == SCAN_IN)
- {
+ } else if (type == SCAN_IN) {
/* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
buffer_write(0x28);
/* LOG_DEBUG("added TDI bytes (i %i)", num_bytes); */
buffer_write((uint8_t) (thisrun_bytes - 1));
buffer_write((uint8_t) ((thisrun_bytes - 1) >> 8));
- if (type != SCAN_IN)
- {
+ if (type != SCAN_IN) {
/* add complete bytes */
- while (thisrun_bytes-- > 0)
- {
+ while (thisrun_bytes-- > 0) {
buffer_write(buffer[cur_byte]);
cur_byte++;
bits_left -= 8;
}
- }
- else /* (type == SCAN_IN) */
- {
+ } else /* (type == SCAN_IN) */
bits_left -= 8 * (thisrun_bytes);
- }
- if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
- {
+ retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't write MPSSE commands to FT2232");
exit(-1);
}
LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i",
- ft2232_buffer_size,
- (int)bytes_written);
+ ft2232_buffer_size,
+ (int)bytes_written);
ft2232_buffer_size = 0;
- if (type != SCAN_OUT)
- {
- if ((retval = ft2232_read(receive_pointer, thisrun_read, &bytes_read)) != ERROR_OK)
- {
+ if (type != SCAN_OUT) {
+ retval = ft2232_read(receive_pointer, thisrun_read, &bytes_read);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't read from FT2232");
exit(-1);
}
LOG_DEBUG("thisrun_read: %i, bytes_read: %i",
- thisrun_read,
- (int)bytes_read);
+ thisrun_read,
+ (int)bytes_read);
receive_pointer += bytes_read;
}
}
last_bit = 0;
/* process remaining bits but the last one */
- if (bits_left > 1)
- {
- if (type == SCAN_IO)
- {
+ if (bits_left > 1) {
+ if (type == SCAN_IO) {
/* Clock Data Bits In and Out LSB First */
buffer_write(0x3b);
/* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
- }
- else if (type == SCAN_OUT)
- {
+ } else if (type == SCAN_OUT) {
/* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
buffer_write(0x1b);
/* LOG_DEBUG("added TDI bits (o)"); */
- }
- else if (type == SCAN_IN)
- {
+ } else if (type == SCAN_IN) {
/* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
buffer_write(0x2a);
/* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
thisrun_read += 2;
}
- if (tap_get_end_state() == TAP_DRSHIFT)
- {
- if (type == SCAN_IO)
- {
+ if (tap_get_end_state() == TAP_DRSHIFT) {
+ if (type == SCAN_IO) {
/* Clock Data Bits In and Out LSB First */
buffer_write(0x3b);
/* LOG_DEBUG("added TDI bits (io) %i", bits_left - 1); */
- }
- else if (type == SCAN_OUT)
- {
+ } else if (type == SCAN_OUT) {
/* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
buffer_write(0x1b);
/* LOG_DEBUG("added TDI bits (o)"); */
- }
- else if (type == SCAN_IN)
- {
+ } else if (type == SCAN_IN) {
/* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
buffer_write(0x2a);
/* LOG_DEBUG("added TDI bits (i %i)", bits_left - 1); */
}
buffer_write(0x0);
buffer_write(last_bit);
- }
- else
- {
+ } else {
int tms_bits = 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());
- uint8_t mpsse_cmd;
+ uint8_t mpsse_cmd;
/* move from Shift-IR/DR to end state */
- if (type != SCAN_OUT)
- {
+ if (type != SCAN_OUT) {
/* Clock Data to TMS/CS Pin with Read */
mpsse_cmd = 0x6b;
/* LOG_DEBUG("added TMS scan (read)"); */
- }
- else
- {
+ } else {
/* Clock Data to TMS/CS Pin (no Read) */
mpsse_cmd = 0x4b;
/* LOG_DEBUG("added TMS scan (no read)"); */
if (type != SCAN_OUT)
thisrun_read += 1;
- if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
- {
+ retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't write MPSSE commands to FT2232");
exit(-1);
}
LOG_DEBUG("ft2232_buffer_size: %i, bytes_written: %i",
- ft2232_buffer_size,
- (int)bytes_written);
+ ft2232_buffer_size,
+ (int)bytes_written);
ft2232_buffer_size = 0;
- if (type != SCAN_OUT)
- {
- if ((retval = ft2232_read(receive_pointer, thisrun_read, &bytes_read)) != ERROR_OK)
- {
+ if (type != SCAN_OUT) {
+ retval = ft2232_read(receive_pointer, thisrun_read, &bytes_read);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't read from FT2232");
exit(-1);
}
LOG_DEBUG("thisrun_read: %i, bytes_read: %i",
- thisrun_read,
- (int)bytes_read);
+ thisrun_read,
+ (int)bytes_read);
}
return ERROR_OK;
int num_bytes = (scan_size - 1) / 8;
if (tap_get_state() != TAP_DRSHIFT)
- predicted_size += get_tms_buffer_requirements(tap_get_tms_path_len(tap_get_state(), TAP_DRSHIFT));
+ predicted_size += get_tms_buffer_requirements(
+ tap_get_tms_path_len(tap_get_state(), TAP_DRSHIFT));
- if (type == SCAN_IN) /* only from device to host */
- {
+ if (type == SCAN_IN) { /* only from device to host */
/* complete bytes */
predicted_size += DIV_ROUND_UP(num_bytes, 65536) * 3;
/* remaining bits - 1 (up to 7) */
predicted_size += ((scan_size - 1) % 8) ? 2 : 0;
- }
- else /* host to device, or bidirectional */
- {
- /* complete bytes */
+ } else {/* host to device, or bidirectional
+ * complete bytes */
predicted_size += num_bytes + DIV_ROUND_UP(num_bytes, 65536) * 3;
/* remaining bits -1 (up to 7) */
{
int predicted_size = 0;
- if (type != SCAN_OUT)
- {
+ if (type != SCAN_OUT) {
/* complete bytes */
- predicted_size += (DIV_ROUND_UP(scan_size, 8) > 1) ? (DIV_ROUND_UP(scan_size, 8) - 1) : 0;
+ predicted_size +=
+ (DIV_ROUND_UP(scan_size, 8) > 1) ? (DIV_ROUND_UP(scan_size, 8) - 1) : 0;
/* remaining bits - 1 */
predicted_size += ((scan_size - 1) % 8) ? 1 : 0;
static void ftx23_reset(int trst, int srst)
{
enum reset_types jtag_reset_config = jtag_get_reset_config();
- if (trst == 1)
- {
+ if (trst == 1) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
low_direction |= nTRSTnOE; /* switch to output pin (output is low) */
else
low_output &= ~nTRST; /* switch output low */
- }
- else if (trst == 0)
- {
+ } else if (trst == 0) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- low_direction &= ~nTRSTnOE; /* switch to input pin (high-Z + internal and external pullup) */
+ low_direction &= ~nTRSTnOE; /* switch to input pin (high-Z + internal
+ *and external pullup) */
else
low_output |= nTRST; /* switch output high */
}
- if (srst == 1)
- {
+ if (srst == 1) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
low_output &= ~nSRST; /* switch output low */
else
low_direction |= nSRSTnOE; /* switch to output pin (output is low) */
- }
- else if (srst == 0)
- {
+ } else if (srst == 0) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
low_output |= nSRST; /* switch output high */
else
static void jtagkey_reset(int trst, int srst)
{
enum reset_types jtag_reset_config = jtag_get_reset_config();
- if (trst == 1)
- {
+ if (trst == 1) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
high_output &= ~nTRSTnOE;
else
high_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
high_output |= nTRSTnOE;
else
high_output |= nTRST;
}
- if (srst == 1)
- {
+ if (srst == 1) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
high_output &= ~nSRST;
else
high_output &= ~nSRSTnOE;
- }
- else if (srst == 0)
- {
+ } else if (srst == 0) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
high_output |= nSRST;
else
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
- LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
- high_direction);
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
+ trst,
+ srst,
+ high_output,
+ high_direction);
}
static void olimex_jtag_reset(int trst, int srst)
{
enum reset_types jtag_reset_config = jtag_get_reset_config();
- if (trst == 1)
- {
+ if (trst == 1) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
high_output &= ~nTRSTnOE;
else
high_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
high_output |= nTRSTnOE;
else
}
if (srst == 1)
- {
high_output |= nSRST;
- }
else if (srst == 0)
- {
high_output &= ~nSRST;
- }
/* command "set data bits high byte" */
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
- LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
- high_direction);
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
+ trst,
+ srst,
+ high_output,
+ high_direction);
}
static void axm0432_jtag_reset(int trst, int srst)
{
- if (trst == 1)
- {
+ if (trst == 1) {
tap_set_state(TAP_RESET);
high_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0)
high_output |= nTRST;
- }
if (srst == 1)
- {
high_output &= ~nSRST;
- }
else if (srst == 0)
- {
high_output |= nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
- LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
- high_direction);
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
+ trst,
+ srst,
+ high_output,
+ high_direction);
}
static void flyswatter_reset(int trst, int srst)
{
if (trst == 1)
- {
low_output &= ~nTRST;
- }
else if (trst == 0)
- {
low_output |= nTRST;
- }
if (srst == 1)
- {
low_output |= nSRST;
- }
else if (srst == 0)
- {
low_output &= ~nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x80);
buffer_write(low_output);
buffer_write(low_direction);
- LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst, srst, low_output, low_direction);
+ LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
+ trst,
+ srst,
+ low_output,
+ low_direction);
}
static void flyswatter1_reset(int trst, int srst)
static void minimodule_reset(int trst, int srst)
{
if (srst == 1)
- {
low_output &= ~nSRST;
- }
else if (srst == 0)
- {
low_output |= nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x80);
buffer_write(low_output);
buffer_write(low_direction);
- LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst, srst, low_output, low_direction);
+ LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
+ trst,
+ srst,
+ low_output,
+ low_direction);
}
static void turtle_reset(int trst, int srst)
trst = trst;
if (srst == 1)
- {
low_output |= nSRST;
- }
else if (srst == 0)
- {
low_output &= ~nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x80);
buffer_write(low_output);
buffer_write(low_direction);
- LOG_DEBUG("srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", srst, low_output, low_direction);
+ LOG_DEBUG("srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
+ srst,
+ low_output,
+ low_direction);
}
static void comstick_reset(int trst, int srst)
{
if (trst == 1)
- {
high_output &= ~nTRST;
- }
else if (trst == 0)
- {
high_output |= nTRST;
- }
if (srst == 1)
- {
high_output &= ~nSRST;
- }
else if (srst == 0)
- {
high_output |= nSRST;
- }
/* command "set data bits high byte" */
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
- LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
- high_direction);
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
+ trst,
+ srst,
+ high_output,
+ high_direction);
}
static void stm32stick_reset(int trst, int srst)
{
if (trst == 1)
- {
high_output &= ~nTRST;
- }
else if (trst == 0)
- {
high_output |= nTRST;
- }
if (srst == 1)
- {
low_output &= ~nSRST;
- }
else if (srst == 0)
- {
low_output |= nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x80);
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
- LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,
- high_direction);
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
+ trst,
+ srst,
+ high_output,
+ high_direction);
}
static void sheevaplug_reset(int trst, int srst)
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
- LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction);
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
+ trst,
+ srst,
+ high_output,
+ high_direction);
}
static void redbee_reset(int trst, int srst)
{
- if (trst == 1)
- {
+ if (trst == 1) {
tap_set_state(TAP_RESET);
high_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0)
high_output |= nTRST;
- }
if (srst == 1)
- {
high_output &= ~nSRST;
- }
else if (srst == 0)
- {
high_output |= nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, "
- "high_direction: 0x%2.2x", trst, srst, high_output,
- high_direction);
+ "high_direction: 0x%2.2x", trst, srst, high_output,
+ high_direction);
}
static void xds100v2_reset(int trst, int srst)
{
- if (trst == 1)
- {
+ if (trst == 1) {
tap_set_state(TAP_RESET);
high_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0)
high_output |= nTRST;
- }
if (srst == 1)
- {
high_output |= nSRST;
- }
else if (srst == 0)
- {
high_output &= ~nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x82);
buffer_write(high_output);
buffer_write(high_direction);
LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, "
- "high_direction: 0x%2.2x", trst, srst, high_output,
- high_direction);
+ "high_direction: 0x%2.2x", trst, srst, high_output,
+ high_direction);
}
static int ft2232_execute_runtest(struct jtag_command *cmd)
retval = ERROR_OK;
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));
/* only send the maximum buffer size that FT2232C can handle */
predicted_size = 0;
predicted_size += 3;
if (tap_get_end_state() != TAP_IDLE)
predicted_size += 3;
- if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
- {
+ if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE) {
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
require_send = 0;
first_unsent = cmd;
}
- if (tap_get_state() != TAP_IDLE)
- {
+ if (tap_get_state() != TAP_IDLE) {
move_to_state(TAP_IDLE);
require_send = 1;
}
i = cmd->cmd.runtest->num_cycles;
- while (i > 0)
- {
+ while (i > 0) {
/* there are no state transitions in this code, so omit state tracking */
/* command "Clock Data to TMS/CS Pin (no Read)" */
ft2232_end_state(cmd->cmd.runtest->end_state);
if (tap_get_state() != tap_get_end_state())
- {
move_to_state(tap_get_end_state());
- }
require_send = 1;
DEBUG_JTAG_IO("runtest: %i, end in %s",
- cmd->cmd.runtest->num_cycles,
- tap_state_name(tap_get_end_state()));
+ cmd->cmd.runtest->num_cycles,
+ tap_state_name(tap_get_end_state()));
return retval;
}
static int ft2232_execute_statemove(struct jtag_command *cmd)
{
- int predicted_size = 0;
- int retval = ERROR_OK;
+ int predicted_size = 0;
+ int retval = ERROR_OK;
DEBUG_JTAG_IO("statemove end in %s",
- tap_state_name(cmd->cmd.statemove->end_state));
+ tap_state_name(cmd->cmd.statemove->end_state));
/* only send the maximum buffer size that FT2232C can handle */
predicted_size = 3;
- if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
- {
+ if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE) {
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
require_send = 0;
clock_tms(0x4b, 0xff, 5, 0);
require_send = 1;
- /* shortest-path move to desired end state */
- } else if (tap_get_state() != tap_get_end_state())
- {
+ /* shortest-path move to desired end state */
+ } else if (tap_get_state() != tap_get_end_state()) {
move_to_state(tap_get_end_state());
require_send = 1;
}
*/
static int ft2232_execute_tms(struct jtag_command *cmd)
{
- int retval = ERROR_OK;
- unsigned num_bits = cmd->cmd.tms->num_bits;
- const uint8_t *bits = cmd->cmd.tms->bits;
- unsigned count;
+ int retval = ERROR_OK;
+ unsigned num_bits = cmd->cmd.tms->num_bits;
+ const uint8_t *bits = cmd->cmd.tms->bits;
+ unsigned count;
DEBUG_JTAG_IO("TMS: %d bits", num_bits);
static int ft2232_execute_pathmove(struct jtag_command *cmd)
{
- int predicted_size = 0;
- int retval = ERROR_OK;
+ int predicted_size = 0;
+ int retval = ERROR_OK;
- tap_state_t* path = cmd->cmd.pathmove->path;
- int num_states = cmd->cmd.pathmove->num_states;
+ tap_state_t *path = cmd->cmd.pathmove->path;
+ int num_states = cmd->cmd.pathmove->num_states;
DEBUG_JTAG_IO("pathmove: %i states, current: %s end: %s", num_states,
- tap_state_name(tap_get_state()),
- tap_state_name(path[num_states-1]));
+ tap_state_name(tap_get_state()),
+ tap_state_name(path[num_states-1]));
/* only send the maximum buffer size that FT2232C can handle */
predicted_size = 3 * DIV_ROUND_UP(num_states, 7);
- if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
- {
+ if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE) {
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
static int ft2232_execute_scan(struct jtag_command *cmd)
{
- uint8_t* buffer;
+ uint8_t *buffer;
int scan_size; /* size of IR or DR scan */
int predicted_size = 0;
int retval = ERROR_OK;
- enum scan_type type = jtag_scan_type(cmd->cmd.scan);
+ enum scan_type type = jtag_scan_type(cmd->cmd.scan);
DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", type);
scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
predicted_size = ft2232_predict_scan_out(scan_size, type);
- if ((predicted_size + 1) > FT2232_BUFFER_SIZE)
- {
+ if ((predicted_size + 1) > FT2232_BUFFER_SIZE) {
LOG_DEBUG("oversized ft2232 scan (predicted_size > FT2232_BUFFER_SIZE)");
/* unsent commands before this */
if (first_unsent != cmd)
if (buffer)
free(buffer);
return retval;
- }
- else if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
- {
- LOG_DEBUG("ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)",
- first_unsent,
- cmd);
+ } else if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE) {
+ LOG_DEBUG(
+ "ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)",
+ first_unsent,
+ cmd);
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
require_send = 0;
if (buffer)
free(buffer);
DEBUG_JTAG_IO("%s scan, %i bits, end in %s",
- (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
- tap_state_name(tap_get_end_state()));
+ (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size,
+ tap_state_name(tap_get_end_state()));
return retval;
}
retval = ERROR_OK;
DEBUG_JTAG_IO("reset trst: %i srst %i",
- cmd->cmd.reset->trst, cmd->cmd.reset->srst);
+ cmd->cmd.reset->trst, cmd->cmd.reset->srst);
/* only send the maximum buffer size that FT2232C can handle */
predicted_size = 3;
- if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
- {
+ if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE) {
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
require_send = 0;
first_unsent = cmd;
}
- 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);
- }
layout->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
require_send = 1;
DEBUG_JTAG_IO("trst: %i, srst: %i",
- cmd->cmd.reset->trst, cmd->cmd.reset->srst);
+ cmd->cmd.reset->trst, cmd->cmd.reset->srst);
return retval;
}
DEBUG_JTAG_IO("sleep %" PRIi32, cmd->cmd.sleep->us);
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
- retval = ERROR_JTAG_QUEUE_FAILED;
+ retval = ERROR_JTAG_QUEUE_FAILED;
first_unsent = cmd->next;
jtag_sleep(cmd->cmd.sleep->us);
DEBUG_JTAG_IO("sleep %" PRIi32 " usec while in %s",
- cmd->cmd.sleep->us,
- tap_state_name(tap_get_state()));
+ cmd->cmd.sleep->us,
+ tap_state_name(tap_get_state()));
return retval;
}
if (ft2232_stableclocks(cmd->cmd.stableclocks->num_cycles, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
DEBUG_JTAG_IO("clocks %i while in %s",
- cmd->cmd.stableclocks->num_cycles,
- tap_state_name(tap_get_state()));
+ cmd->cmd.stableclocks->num_cycles,
+ tap_state_name(tap_get_state()));
return retval;
}
{
int retval;
- switch (cmd->type)
- {
- case JTAG_RESET: retval = ft2232_execute_reset(cmd); break;
- case JTAG_RUNTEST: retval = ft2232_execute_runtest(cmd); break;
- case JTAG_TLR_RESET: retval = ft2232_execute_statemove(cmd); break;
- case JTAG_PATHMOVE: retval = ft2232_execute_pathmove(cmd); break;
- case JTAG_SCAN: retval = ft2232_execute_scan(cmd); break;
- case JTAG_SLEEP: retval = ft2232_execute_sleep(cmd); break;
- case JTAG_STABLECLOCKS: retval = ft2232_execute_stableclocks(cmd); break;
- case JTAG_TMS:
- retval = ft2232_execute_tms(cmd);
- break;
- default:
- LOG_ERROR("BUG: unknown JTAG command type encountered");
- retval = ERROR_JTAG_QUEUE_FAILED;
- break;
- }
- return retval;
-}
-
-static int ft2232_execute_queue(void)
-{
- struct jtag_command* cmd = jtag_command_queue; /* currently processed command */
+ switch (cmd->type) {
+ case JTAG_RESET:
+ retval = ft2232_execute_reset(cmd);
+ break;
+ case JTAG_RUNTEST:
+ retval = ft2232_execute_runtest(cmd);
+ break;
+ case JTAG_TLR_RESET:
+ retval = ft2232_execute_statemove(cmd);
+ break;
+ case JTAG_PATHMOVE:
+ retval = ft2232_execute_pathmove(cmd);
+ break;
+ case JTAG_SCAN:
+ retval = ft2232_execute_scan(cmd);
+ break;
+ case JTAG_SLEEP:
+ retval = ft2232_execute_sleep(cmd);
+ break;
+ case JTAG_STABLECLOCKS:
+ retval = ft2232_execute_stableclocks(cmd);
+ break;
+ case JTAG_TMS:
+ retval = ft2232_execute_tms(cmd);
+ break;
+ default:
+ LOG_ERROR("BUG: unknown JTAG command type encountered");
+ retval = ERROR_JTAG_QUEUE_FAILED;
+ break;
+ }
+ return retval;
+}
+
+static int ft2232_execute_queue(void)
+{
+ struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
int retval;
first_unsent = cmd; /* next command that has to be sent */
if (layout->blink)
layout->blink();
- while (cmd)
- {
+ while (cmd) {
/* fill the write buffer with the desired command */
if (ft2232_execute_command(cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
*/
cmd = cmd->next;
- if (ft2232_expect_read >= FT2232_BUFFER_READ_QUEUE_SIZE )
- {
- if (ft2232_expect_read > (FT2232_BUFFER_READ_QUEUE_SIZE+1) )
- LOG_DEBUG("read buffer size looks too high %d/%d",ft2232_expect_read,(FT2232_BUFFER_READ_QUEUE_SIZE+1));
+ if (ft2232_expect_read >= FT2232_BUFFER_READ_QUEUE_SIZE) {
+ if (ft2232_expect_read > (FT2232_BUFFER_READ_QUEUE_SIZE+1))
+ LOG_DEBUG("read buffer size looks too high %d/%d",
+ ft2232_expect_read,
+ (FT2232_BUFFER_READ_QUEUE_SIZE+1));
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
first_unsent = cmd;
}
#if BUILD_FT2232_FTD2XX == 1
-static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_more)
+static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int *try_more)
{
- FT_STATUS status;
- DWORD deviceID;
- char SerialNumber[16];
- char Description[64];
- DWORD openex_flags = 0;
- char* openex_string = NULL;
- uint8_t latency_timer;
+ FT_STATUS status;
+ DWORD deviceID;
+ char SerialNumber[16];
+ char Description[64];
+ DWORD openex_flags = 0;
+ char *openex_string = NULL;
+ uint8_t latency_timer;
if (layout == NULL) {
LOG_WARNING("No ft2232 layout specified'");
return ERROR_JTAG_INIT_FAILED;
}
- LOG_DEBUG("'ft2232' interface using FTD2XX with '%s' layout (%4.4x:%4.4x)", layout->name, vid, pid);
+ LOG_DEBUG("'ft2232' interface using FTD2XX with '%s' layout (%4.4x:%4.4x)",
+ layout->name, vid, pid);
#if IS_WIN32 == 0
/* Add non-standard Vid/Pid to the linux driver */
- if ((status = FT_SetVIDPID(vid, pid)) != FT_OK)
- {
+ status = FT_SetVIDPID(vid, pid);
+ if (status != FT_OK)
LOG_WARNING("couldn't add %4.4x:%4.4x", vid, pid);
- }
+
#endif
- if (ft2232_device_desc && ft2232_serial)
- {
- LOG_WARNING("can't open by device description and serial number, giving precedence to serial");
+ if (ft2232_device_desc && ft2232_serial) {
+ LOG_WARNING(
+ "can't open by device description and serial number, giving precedence to serial");
ft2232_device_desc = NULL;
}
- if (ft2232_device_desc)
- {
+ if (ft2232_device_desc) {
openex_string = ft2232_device_desc;
openex_flags = FT_OPEN_BY_DESCRIPTION;
- }
- else if (ft2232_serial)
- {
+ } else if (ft2232_serial) {
openex_string = ft2232_serial;
openex_flags = FT_OPEN_BY_SERIAL_NUMBER;
- }
- else
- {
+ } else {
LOG_ERROR("neither device description nor serial number specified");
- LOG_ERROR("please add \"ft2232_device_desc <string>\" or \"ft2232_serial <string>\" to your .cfg file");
+ LOG_ERROR(
+ "please add \"ft2232_device_desc <string>\" or \"ft2232_serial <string>\" to your .cfg file");
return ERROR_JTAG_INIT_FAILED;
}
/* drat, give the user a meaningfull message.
* telling the use we tried *BOTH* methods. */
LOG_WARNING("Unable to open FTDI Device tried: '%s' and '%s'",
- ft2232_device_desc,
- ft2232_device_desc_A);
+ ft2232_device_desc,
+ ft2232_device_desc_A);
}
}
}
- if (status != FT_OK)
- {
+ if (status != FT_OK) {
DWORD num_devices;
- if (more)
- {
+ if (more) {
LOG_WARNING("unable to open ftdi device (trying more): %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
*try_more = 1;
return ERROR_JTAG_INIT_FAILED;
}
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)
- {
- char** desc_array = malloc(sizeof(char*) * (num_devices + 1));
+ if (status == FT_OK) {
+ char **desc_array = malloc(sizeof(char *) * (num_devices + 1));
uint32_t i;
for (i = 0; i < num_devices; i++)
status = FT_ListDevices(desc_array, &num_devices, FT_LIST_ALL | openex_flags);
- 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("%" PRIu32 ": \"%s\"", i, desc_array[i]);
free(desc_array[i]);
free(desc_array);
- }
- else
- {
+ } else
LOG_ERROR("ListDevices: NONE");
- }
return ERROR_JTAG_INIT_FAILED;
}
- if ((status = FT_SetLatencyTimer(ftdih, ft2232_latency)) != FT_OK)
- {
+ status = FT_SetLatencyTimer(ftdih, ft2232_latency);
+ 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;
}
- if ((status = FT_GetLatencyTimer(ftdih, &latency_timer)) != FT_OK)
- {
+ status = FT_GetLatencyTimer(ftdih, &latency_timer);
+ if (status != FT_OK) {
/* ftd2xx 1.04 (linux) has a bug when calling FT_GetLatencyTimer
* so ignore errors if using this driver version */
DWORD dw_version;
status = FT_GetDriverVersion(ftdih, &dw_version);
LOG_ERROR("unable to get latency timer: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
if ((status == FT_OK) && (dw_version == 0x10004)) {
LOG_ERROR("ftd2xx 1.04 detected - this has known issues " \
- "with FT_GetLatencyTimer, upgrade to a newer version");
- }
- else {
+ "with FT_GetLatencyTimer, upgrade to a newer version");
+ } else
return ERROR_JTAG_INIT_FAILED;
- }
- }
- else
- {
+ } else
LOG_DEBUG("current latency timer: %i", latency_timer);
- }
- if ((status = FT_SetTimeouts(ftdih, 5000, 5000)) != FT_OK)
- {
+ status = FT_SetTimeouts(ftdih, 5000, 5000);
+ if (status != FT_OK) {
LOG_ERROR("unable to set timeouts: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_INIT_FAILED;
}
- if ((status = FT_SetBitMode(ftdih, 0x0b, 2)) != FT_OK)
- {
+ status = FT_SetBitMode(ftdih, 0x0b, 2);
+ if (status != FT_OK) {
LOG_ERROR("unable to enable bit i/o mode: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_INIT_FAILED;
}
- if ((status = FT_GetDeviceInfo(ftdih, &ftdi_device, &deviceID, SerialNumber, Description, NULL)) != FT_OK)
- {
+ status = FT_GetDeviceInfo(ftdih, &ftdi_device, &deviceID,
+ SerialNumber, Description, NULL);
+ if (status != FT_OK) {
LOG_ERROR("unable to get FT_GetDeviceInfo: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_INIT_FAILED;
- }
- else
- {
- static const char* type_str[] =
- {"BM", "AM", "100AX", "UNKNOWN", "2232C", "232R", "2232H", "4232H"};
+ } else {
+ static const char *type_str[] = {
+ "BM", "AM", "100AX", "UNKNOWN", "2232C", "232R", "2232H", "4232H"
+ };
unsigned no_of_known_types = ARRAY_SIZE(type_str) - 1;
unsigned type_index = ((unsigned)ftdi_device <= no_of_known_types)
? ftdi_device : FT_DEVICE_UNKNOWN;
{
FT_STATUS status;
- 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: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_INIT_FAILED;
}
return ERROR_OK;
}
-#endif /* BUILD_FT2232_FTD2XX == 1 */
+#endif /* BUILD_FT2232_FTD2XX == 1 */
#if BUILD_FT2232_LIBFTDI == 1
-static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int* try_more, int channel)
+static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int *try_more, int channel)
{
uint8_t latency_timer;
}
LOG_DEBUG("'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)",
- layout->name, vid, pid);
+ layout->name, vid, pid);
if (ftdi_init(&ftdic) < 0)
return ERROR_JTAG_INIT_FAILED;
/* default to INTERFACE_A */
- if(channel == INTERFACE_ANY) { channel = INTERFACE_A; }
-
- if (ftdi_set_interface(&ftdic, channel) < 0)
- {
+ if (channel == INTERFACE_ANY)
+ channel = INTERFACE_A;
+ if (ftdi_set_interface(&ftdic, channel) < 0) {
LOG_ERROR("unable to select FT2232 channel A: %s", ftdic.error_str);
return ERROR_JTAG_INIT_FAILED;
}
/* context, vendor id, product id */
- if (ftdi_usb_open_desc(&ftdic, vid, pid, ft2232_device_desc,
- ft2232_serial) < 0)
- {
+ if (ftdi_usb_open_desc(&ftdic, vid, pid, ft2232_device_desc, ft2232_serial) < 0) {
if (more)
LOG_WARNING("unable to open ftdi device (trying more): %s",
- ftdic.error_str);
+ ftdic.error_str);
else
LOG_ERROR("unable to open ftdi device: %s", ftdic.error_str);
*try_more = 1;
}
/* There is already a reset in ftdi_usb_open_desc, this should be redundant */
- 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, ft2232_latency) < 0)
- {
+ if (ftdi_set_latency_timer(&ftdic, ft2232_latency) < 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;
- }
- else
- {
+ } else
LOG_DEBUG("current latency timer: %i", latency_timer);
- }
- ftdi_set_bitmode(&ftdic, 0x0b, 2); /* ctx, JTAG I/O mask */
+ ftdi_set_bitmode(&ftdic, 0x0b, 2); /* ctx, JTAG I/O mask */
ftdi_device = ftdic.type;
- static const char* type_str[] =
- {"AM", "BM", "2232C", "R", "2232H", "4232H", "Unknown"};
+ static const char *type_str[] = {
+ "AM", "BM", "2232C", "R", "2232H", "4232H", "Unknown"
+ };
unsigned no_of_known_types = ARRAY_SIZE(type_str) - 1;
unsigned type_index = ((unsigned)ftdi_device < no_of_known_types)
? ftdi_device : no_of_known_types;
static int ft2232_purge_libftdi(void)
{
- 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;
}
return ERROR_OK;
}
-#endif /* BUILD_FT2232_LIBFTDI == 1 */
+#endif /* BUILD_FT2232_LIBFTDI == 1 */
-static int ft2232_set_data_bits_low_byte( uint8_t value, uint8_t direction )
+static int ft2232_set_data_bits_low_byte(uint8_t value, uint8_t direction)
{
- uint8_t buf[3];
+ uint8_t buf[3];
uint32_t bytes_written;
buf[0] = 0x80; /* command "set data bits low byte" */
LOG_DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
- if (ft2232_write(buf, sizeof(buf), &bytes_written) != ERROR_OK)
- {
+ if (ft2232_write(buf, sizeof(buf), &bytes_written) != ERROR_OK) {
LOG_ERROR("couldn't initialize data bits low byte");
return ERROR_JTAG_INIT_FAILED;
}
return ERROR_OK;
}
-static int ft2232_set_data_bits_high_byte( uint8_t value, uint8_t direction )
+static int ft2232_set_data_bits_high_byte(uint8_t value, uint8_t direction)
{
- uint8_t buf[3];
+ uint8_t buf[3];
uint32_t bytes_written;
buf[0] = 0x82; /* command "set data bits high byte" */
LOG_DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
- if (ft2232_write(buf, sizeof(buf), &bytes_written) != ERROR_OK)
- {
+ if (ft2232_write(buf, sizeof(buf), &bytes_written) != ERROR_OK) {
LOG_ERROR("couldn't initialize data bits high byte");
return ERROR_JTAG_INIT_FAILED;
}
static int ft2232_init(void)
{
- uint8_t buf[1];
+ uint8_t buf[1];
int retval;
uint32_t bytes_written;
- if (tap_get_tms_path_len(TAP_IRPAUSE,TAP_IRPAUSE) == 7)
- {
+ if (tap_get_tms_path_len(TAP_IRPAUSE, TAP_IRPAUSE) == 7)
LOG_DEBUG("ft2232 interface using 7 step jtag state transitions");
- }
else
- {
LOG_DEBUG("ft2232 interface using shortest path jtag state transitions");
-
- }
if (layout == NULL) {
LOG_WARNING("No ft2232 layout specified'");
return ERROR_JTAG_INIT_FAILED;
}
- for (int i = 0; 1; i++)
- {
+ for (int i = 0; 1; i++) {
/*
* "more indicates that there are more IDs to try, so we should
* not print an error for an ID mismatch (but for anything
* ID mismatch (and nothing else) and that we should proceeed
* with the next ID pair.
*/
- int more = ft2232_vid[i + 1] || ft2232_pid[i + 1];
+ int more = ft2232_vid[i + 1] || ft2232_pid[i + 1];
int try_more = 0;
#if BUILD_FT2232_FTD2XX == 1
more, &try_more);
#elif BUILD_FT2232_LIBFTDI == 1
retval = ft2232_init_libftdi(ft2232_vid[i], ft2232_pid[i],
- more, &try_more, layout->channel);
+ more, &try_more, layout->channel);
#endif
if (retval >= 0)
break;
if (layout->init() != ERROR_OK)
return ERROR_JTAG_INIT_FAILED;
- if (ft2232_device_is_highspeed())
- {
+ if (ft2232_device_is_highspeed()) {
#ifndef BUILD_FT2232_HIGHSPEED
#if BUILD_FT2232_FTD2XX == 1
- LOG_WARNING("High Speed device found - You need a newer FTD2XX driver (version 2.04.16 or later)");
+ LOG_WARNING(
+ "High Speed device found - You need a newer FTD2XX driver (version 2.04.16 or later)");
#elif BUILD_FT2232_LIBFTDI == 1
- LOG_WARNING("High Speed device found - You need a newer libftdi version (0.16 or later)");
+ LOG_WARNING(
+ "High Speed device found - You need a newer libftdi version (0.16 or later)");
#endif
#endif
/* make sure the legacy mode is disabled */
return ERROR_JTAG_INIT_FAILED;
}
- buf[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
- if ((retval = ft2232_write(buf, 1, &bytes_written)) != ERROR_OK)
- {
+ buf[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
+ retval = ft2232_write(buf, 1, &bytes_written);
+ if (retval != ERROR_OK) {
LOG_ERROR("couldn't write to FT2232 to disable loopback");
return ERROR_JTAG_INIT_FAILED;
}
static int ftx232_dbus_write(void)
{
enum reset_types jtag_reset_config = jtag_get_reset_config();
- if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
- low_direction &= ~nTRSTnOE; /* nTRST input */
- low_output &= ~nTRST; /* nTRST = 0 */
- }
- else
- {
- low_direction |= nTRSTnOE; /* nTRST output */
- low_output |= nTRST; /* nTRST = 1 */
+ if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) {
+ low_direction &= ~nTRSTnOE; /* nTRST input */
+ low_output &= ~nTRST; /* nTRST = 0 */
+ } else {
+ low_direction |= nTRSTnOE; /* nTRST output */
+ low_output |= nTRST; /* nTRST = 1 */
}
- if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
- low_direction |= nSRSTnOE; /* nSRST output */
- low_output |= nSRST; /* nSRST = 1 */
- }
- else
- {
- low_direction &= ~nSRSTnOE; /* nSRST input */
- low_output &= ~nSRST; /* nSRST = 0 */
+ if (jtag_reset_config & RESET_SRST_PUSH_PULL) {
+ low_direction |= nSRSTnOE; /* nSRST output */
+ low_output |= nSRST; /* nSRST = 1 */
+ } else {
+ low_direction &= ~nSRSTnOE; /* nSRST input */
+ low_output &= ~nSRST; /* nSRST = 0 */
}
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 DBUS");
return ERROR_JTAG_INIT_FAILED;
}
/* GPIOs on second channel/interface (UART) ... */
#define ICDI_SWO_EN (1 << 4) /* BDBUS 4 */
-#define ICDI_TX_SWO (1 << 1) /* BDBUS 1 */
-#define ICDI_VCP_RX (1 << 0) /* BDBUS 0 (to stellaris UART) */
+#define ICDI_TX_SWO (1 << 1) /* BDBUS 1 */
+#define ICDI_VCP_RX (1 << 0) /* BDBUS 0 (to stellaris UART) */
nTRST = 0x0;
nTRSTnOE = 0x00;
low_direction = 0x2b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
return ERROR_JTAG_INIT_FAILED;
}
- if (strcmp(layout->name, "axm0432_jtag") == 0)
- {
+ if (strcmp(layout->name, "axm0432_jtag") == 0) {
nTRST = 0x08;
- nTRSTnOE = 0x0; /* No output enable for TRST*/
+ nTRSTnOE = 0x0; /* No output enable for TRST*/
nSRST = 0x04;
- nSRSTnOE = 0x0; /* No output enable for SRST*/
- }
- else
- {
+ nSRSTnOE = 0x0; /* No output enable for SRST*/
+ } else {
LOG_ERROR("BUG: axm0432_jtag_init called for non axm0432 layout");
exit(-1);
}
enum reset_types jtag_reset_config = jtag_get_reset_config();
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
LOG_ERROR("can't set nTRSTOE to push-pull on the Dicarlo jtag");
- }
else
- {
high_output |= nTRST;
- }
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
LOG_ERROR("can't set nSRST to push-pull on the Dicarlo jtag");
- }
else
- {
high_output |= nSRST;
- }
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'Dicarlo' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x2b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'redbee' layout");
return ERROR_JTAG_INIT_FAILED;
}
nTRST = 0x08;
- nTRSTnOE = 0x0; /* No output enable for TRST*/
+ nTRSTnOE = 0x0; /* No output enable for TRST*/
nSRST = 0x04;
- nSRSTnOE = 0x0; /* No output enable for SRST*/
+ nSRSTnOE = 0x0; /* No output enable for SRST*/
high_output = 0x0;
high_direction = 0x0c;
enum reset_types jtag_reset_config = jtag_get_reset_config();
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
LOG_ERROR("can't set nTRSTOE to push-pull on redbee");
- }
else
- {
high_output |= nTRST;
- }
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
LOG_ERROR("can't set nSRST to push-pull on redbee");
- }
else
- {
high_output |= nSRST;
- }
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'redbee' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x1b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
return ERROR_JTAG_INIT_FAILED;
}
- if (strcmp(layout->name, "jtagkey") == 0)
- {
+ if (strcmp(layout->name, "jtagkey") == 0) {
nTRST = 0x01;
nTRSTnOE = 0x4;
nSRST = 0x02;
nSRSTnOE = 0x08;
- }
- else if ((strcmp(layout->name, "jtagkey_prototype_v1") == 0)
- || (strcmp(layout->name, "oocdlink") == 0))
- {
+ } else if ((strcmp(layout->name, "jtagkey_prototype_v1") == 0)
+ || (strcmp(layout->name, "oocdlink") == 0)) {
nTRST = 0x02;
nTRSTnOE = 0x1;
nSRST = 0x08;
nSRSTnOE = 0x04;
- }
- else
- {
+ } else {
LOG_ERROR("BUG: jtagkey_init called for non jtagkey layout");
exit(-1);
}
high_direction = 0x0f;
enum reset_types jtag_reset_config = jtag_get_reset_config();
- if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
+ if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) {
high_output |= nTRSTnOE;
high_output &= ~nTRST;
- }
- else
- {
+ } else {
high_output &= ~nTRSTnOE;
high_output |= nTRST;
}
- if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
+ if (jtag_reset_config & RESET_SRST_PUSH_PULL) {
high_output &= ~nSRSTnOE;
high_output |= nSRST;
- }
- else
- {
+ } else {
high_output |= nSRSTnOE;
high_output &= ~nSRST;
}
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x1b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'Olimex' layout");
return ERROR_JTAG_INIT_FAILED;
}
nTRST = 0x01;
nTRSTnOE = 0x4;
nSRST = 0x02;
- nSRSTnOE = 0x00; /* no output enable for nSRST */
+ nSRSTnOE = 0x00;/* no output enable for nSRST */
high_output = 0x0;
high_direction = 0x0f;
enum reset_types jtag_reset_config = jtag_get_reset_config();
- if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
+ if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) {
high_output |= nTRSTnOE;
high_output &= ~nTRST;
- }
- else
- {
+ } else {
high_output &= ~nTRSTnOE;
high_output |= nTRST;
}
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
LOG_ERROR("can't set nSRST to push-pull on the Olimex ARM-USB-OCD");
- }
else
- {
high_output &= ~nSRST;
- }
/* turn red LED on */
high_output |= 0x08;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'Olimex' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction |= 1 << 7;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
return ERROR_JTAG_INIT_FAILED;
}
nTRST = 0x10;
- nTRSTnOE = 0x0; /* not output enable for nTRST */
+ nTRSTnOE = 0x0; /* not output enable for nTRST */
nSRST = 0x20;
- nSRSTnOE = 0x00; /* no output enable for nSRST */
+ nSRSTnOE = 0x00; /* no output enable for nSRST */
high_output = 0x00;
high_output |= 0x08;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'flyswatter' layout");
return ERROR_JTAG_INIT_FAILED;
}
static int minimodule_init(void)
{
- low_output = 0x18;//check if srst should be 1 or 0 initially. (0x08) (flyswatter was 0x18)
- low_direction = 0xfb;//0xfb;
+ low_output = 0x18; /* check if srst should be 1 or 0 initially. (0x08) (flyswatter was
+ * 0x18) */
+ low_direction = 0xfb; /* 0xfb; */
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'minimodule' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_direction = 0x05;
/* turn red LED3 on, LED2 off */
- //high_output |= 0x08;
+ /* high_output |= 0x08; */
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'minimodule' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x5b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_direction = 0x0C;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x0b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
return ERROR_JTAG_INIT_FAILED;
}
nTRST = 0x01;
- nTRSTnOE = 0x00; /* no output enable for nTRST */
+ nTRSTnOE = 0x00; /* no output enable for nTRST */
nSRST = 0x02;
- nSRSTnOE = 0x00; /* no output enable for nSRST */
+ nSRSTnOE = 0x00; /* no output enable for nSRST */
high_output = 0x03;
high_direction = 0x03;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'comstick' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x8b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
return ERROR_JTAG_INIT_FAILED;
}
nTRST = 0x01;
- nTRSTnOE = 0x00; /* no output enable for nTRST */
+ nTRSTnOE = 0x00; /* no output enable for nTRST */
nSRST = 0x80;
- nSRSTnOE = 0x00; /* no output enable for nSRST */
+ nSRSTnOE = 0x00; /* no output enable for nSRST */
high_output = 0x01;
high_direction = 0x03;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'stm32stick' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x1b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_output &= ~nSRST;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'sheevaplug' layout");
return ERROR_JTAG_INIT_FAILED;
}
low_direction = 0x1b;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'cortino' layout");
return ERROR_JTAG_INIT_FAILED;
}
nTRST = 0x01;
- nTRSTnOE = 0x00; /* no output enable for nTRST */
+ nTRSTnOE = 0x00; /* no output enable for nTRST */
nSRST = 0x02;
- nSRSTnOE = 0x00; /* no output enable for nSRST */
+ nSRSTnOE = 0x00; /* no output enable for nSRST */
high_output = 0x03;
high_direction = 0x03;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'cortino' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_direction = 0x18;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'lisa_l' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_direction = 0x18;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'Floss-JTAG' layout");
return ERROR_JTAG_INIT_FAILED;
}
* * CPLD logic: Disable loopback
* * ACBUS6/SPARE2 = LOOPBACK = 0
*/
-#define XDS100_nEMU_EN (1<<5)
-#define XDS100_nEMU0 (1<<6)
+#define XDS100_nEMU_EN (1<<5)
+#define XDS100_nEMU0 (1<<6)
-#define XDS100_PWR_RST (1<<3)
-#define XDS100_nEMU1 (1<<4)
-#define XDS100_LOOPBACK (1<<6)
+#define XDS100_PWR_RST (1<<3)
+#define XDS100_nEMU1 (1<<4)
+#define XDS100_LOOPBACK (1<<6)
static int xds100v2_init(void)
{
/* These are in the lower byte */
nTRST = 0x10;
nTRSTnOE = 0x10;
- /* These aren't actually used on 14 pin connectors */
- /* These are in the upper byte */
+ /* These aren't actually used on 14 pin connectors
+ * These are in the upper byte */
nSRST = 0x01;
nSRSTnOE = 0x01;
low_output = 0x08 | nTRST | XDS100_nEMU_EN;
low_direction = 0x0b | nTRSTnOE | XDS100_nEMU_EN | XDS100_nEMU0;
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'xds100v2' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_direction = nSRSTnOE | XDS100_LOOPBACK | XDS100_PWR_RST | XDS100_nEMU1;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't put CPLD in to reset with 'xds100v2' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_output |= XDS100_PWR_RST;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't bring CPLD out of reset with 'xds100v2' layout");
return ERROR_JTAG_INIT_FAILED;
}
* Turtelizer2 has two LEDs connected to ACBUS2 and ACBUS3
*/
if (high_output & 0x08)
- {
high_output = 0x04;
- }
else
- {
high_output = 0x08;
- }
buffer_write(0x82);
buffer_write(high_output);
* Lisa/L has two LEDs connected to BCBUS3 and BCBUS4
*/
if (high_output & 0x10)
- {
high_output = 0x08;
- }
else
- {
high_output = 0x10;
- }
buffer_write(0x82);
buffer_write(high_output);
* Floss-JTAG has two LEDs connected to ACBUS3 and ACBUS4
*/
if (high_output & 0x10)
- {
high_output = 0x08;
- }
else
- {
high_output = 0x10;
- }
buffer_write(0x82);
buffer_write(high_output);
{
char *cp;
char buf[200];
- if (CMD_ARGC == 1)
- {
+ if (CMD_ARGC == 1) {
ft2232_device_desc = strdup(CMD_ARGV[0]);
cp = strchr(ft2232_device_desc, 0);
/* under Win32, the FTD2XX driver appends an "A" to the end
* of the description, this examines the given desc
* and creates the 'missing' _A or non_A variable. */
- if ((cp[-1] == 'A') && (cp[-2]==' ')) {
+ if ((cp[-1] == 'A') && (cp[-2] == ' ')) {
/* it was, so make this the "A" version. */
ft2232_device_desc_A = ft2232_device_desc;
/* and *CREATE* the non-A version. */
strcpy(buf, ft2232_device_desc);
cp = strchr(buf, 0);
cp[-2] = 0;
- ft2232_device_desc = strdup(buf);
+ ft2232_device_desc = strdup(buf);
} else {
/* <space > A not defined
* so create it */
sprintf(buf, "%s A", ft2232_device_desc);
ft2232_device_desc_A = strdup(buf);
}
- }
- else
- {
+ } else
LOG_ERROR("expected exactly one argument to ft2232_device_desc <description>");
- }
return ERROR_OK;
}
COMMAND_HANDLER(ft2232_handle_serial_command)
{
if (CMD_ARGC == 1)
- {
ft2232_serial = strdup(CMD_ARGV[0]);
- }
else
- {
return ERROR_COMMAND_SYNTAX_ERROR;
- }
return ERROR_OK;
}
COMMAND_HANDLER(ft2232_handle_layout_command)
{
- if (CMD_ARGC != 1) {
+ if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- }
if (layout) {
LOG_ERROR("already specified ft2232_layout %s",
- layout->name);
+ layout->name);
return (strcmp(layout->name, CMD_ARGV[0]) != 0)
- ? ERROR_FAIL
- : ERROR_OK;
+ ? ERROR_FAIL
+ : ERROR_OK;
}
for (const struct ft2232_layout *l = ft2232_layouts; l->name; l++) {
COMMAND_HANDLER(ft2232_handle_vid_pid_command)
{
- if (CMD_ARGC > MAX_USB_IDS * 2)
- {
+ if (CMD_ARGC > MAX_USB_IDS * 2) {
LOG_WARNING("ignoring extra IDs in ft2232_vid_pid "
- "(maximum is %d pairs)", MAX_USB_IDS);
+ "(maximum is %d pairs)", MAX_USB_IDS);
CMD_ARGC = MAX_USB_IDS * 2;
}
- if (CMD_ARGC < 2 || (CMD_ARGC & 1))
- {
+ if (CMD_ARGC < 2 || (CMD_ARGC & 1)) {
LOG_WARNING("incomplete ft2232_vid_pid configuration directive");
if (CMD_ARGC < 2)
return ERROR_COMMAND_SYNTAX_ERROR;
}
unsigned i;
- for (i = 0; i < CMD_ARGC; i += 2)
- {
+ for (i = 0; i < CMD_ARGC; i += 2) {
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i], ft2232_vid[i >> 1]);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], ft2232_pid[i >> 1]);
}
COMMAND_HANDLER(ft2232_handle_latency_command)
{
if (CMD_ARGC == 1)
- {
ft2232_latency = atoi(CMD_ARGV[0]);
- }
else
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
+ return ERROR_COMMAND_SYNTAX_ERROR;
return ERROR_OK;
}
-static int ft2232_stableclocks(int num_cycles, struct jtag_command* cmd)
+static int ft2232_stableclocks(int num_cycles, struct jtag_command *cmd)
{
int retval = 0;
/* 7 bits of either ones or zeros. */
- uint8_t tms = (tap_get_state() == TAP_RESET ? 0x7F : 0x00);
+ uint8_t tms = (tap_get_state() == TAP_RESET ? 0x7F : 0x00);
- while (num_cycles > 0)
- {
+ while (num_cycles > 0) {
/* the command 0x4b, "Clock Data to TMS/CS Pin (no Read)" handles
* at most 7 bits per invocation. Here we invoke it potentially
* several times.
*/
int bitcount_per_command = (num_cycles > 7) ? 7 : num_cycles;
- if (ft2232_buffer_size + 3 >= FT2232_BUFFER_SIZE)
- {
+ if (ft2232_buffer_size + 3 >= FT2232_BUFFER_SIZE) {
if (ft2232_send_and_recv(first_unsent, cmd) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
* ADBUS6 - VCC
* ADBUS7 - GND
*/
-static int icebear_jtag_init(void) {
- low_direction = 0x0b; /* output: TCK TDI TMS; input: TDO */
- low_output = 0x08; /* high: TMS; low: TCK TDI */
- nTRST = 0x10;
- nSRST = 0x20;
+static int icebear_jtag_init(void)
+{
+ low_direction = 0x0b; /* output: TCK TDI TMS; input: TDO */
+ low_output = 0x08; /* high: TMS; low: TCK TDI */
+ nTRST = 0x10;
+ nSRST = 0x20;
enum reset_types jtag_reset_config = jtag_get_reset_config();
- if ((jtag_reset_config & RESET_TRST_OPEN_DRAIN) != 0) {
- low_direction &= ~nTRST; /* nTRST high impedance */
- }
+ if ((jtag_reset_config & RESET_TRST_OPEN_DRAIN) != 0)
+ low_direction &= ~nTRST; /* nTRST high impedance */
else {
- low_direction |= nTRST;
- low_output |= nTRST;
+ low_direction |= nTRST;
+ low_output |= nTRST;
}
- low_direction |= nSRST;
- low_output |= nSRST;
+ low_direction |= nSRST;
+ low_output |= nSRST;
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK) {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'IceBear' layout (low)");
return ERROR_JTAG_INIT_FAILED;
}
high_direction = 0x00;
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK) {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'IceBear' layout (high)");
return ERROR_JTAG_INIT_FAILED;
}
return ERROR_OK;
}
-static void icebear_jtag_reset(int trst, int srst) {
-
+static void icebear_jtag_reset(int trst, int srst)
+{
if (trst == 1) {
- low_direction |= nTRST;
- low_output &= ~nTRST;
- }
- else if (trst == 0) {
+ low_direction |= nTRST;
+ low_output &= ~nTRST;
+ } else if (trst == 0) {
enum reset_types jtag_reset_config = jtag_get_reset_config();
if ((jtag_reset_config & RESET_TRST_OPEN_DRAIN) != 0)
- low_direction &= ~nTRST;
+ low_direction &= ~nTRST;
else
- low_output |= nTRST;
+ low_output |= nTRST;
}
- if (srst == 1) {
+ if (srst == 1)
low_output &= ~nSRST;
- }
- else if (srst == 0) {
+ else if (srst == 0)
low_output |= nSRST;
- }
/* command "set data bits low byte" */
buffer_write(0x80);
buffer_write(low_output);
buffer_write(low_direction);
- LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst, srst, low_output, low_direction);
+ LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x",
+ trst,
+ srst,
+ low_output,
+ low_direction);
}
/* ---------------------------------------------------------------------
#if BUILD_FT2232_FTD2XX == 1
FT_STATUS status;
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
- ((uint32_t)(channel << 8) | led))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ ((uint32_t)(channel << 8) | led));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- (SIGNALYZER_DATA_BUFFER_ADDR + 1),
- ((uint32_t)(on_time << 8) | off_time))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write((SIGNALYZER_DATA_BUFFER_ADDR + 1),
+ ((uint32_t)(on_time << 8) | off_time));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- (SIGNALYZER_DATA_BUFFER_ADDR + 2),
- ((uint32_t)cycles))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write((SIGNALYZER_DATA_BUFFER_ADDR + 2),
+ ((uint32_t)cycles));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_LED_SET)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_LED_SET);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
#elif BUILD_FT2232_LIBFTDI == 1
int retval;
- if ((retval = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
- ((uint32_t)(channel << 8) | led))) < 0)
- {
+ retval = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ ((uint32_t)(channel << 8) | led));
+ if (retval < 0) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftdi_get_error_string(&ftdic));
+ ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((retval = signalyzer_h_ctrl_write(
- (SIGNALYZER_DATA_BUFFER_ADDR + 1),
- ((uint32_t)(on_time << 8) | off_time))) < 0)
- {
+ retval = signalyzer_h_ctrl_write((SIGNALYZER_DATA_BUFFER_ADDR + 1),
+ ((uint32_t)(on_time << 8) | off_time));
+ if (retval < 0) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftdi_get_error_string(&ftdic));
+ ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((retval = signalyzer_h_ctrl_write(
- (SIGNALYZER_DATA_BUFFER_ADDR + 2),
- (uint32_t)cycles)) < 0)
- {
+ retval = signalyzer_h_ctrl_write((SIGNALYZER_DATA_BUFFER_ADDR + 2),
+ (uint32_t)cycles);
+ if (retval < 0) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftdi_get_error_string(&ftdic));
+ ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((retval = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_LED_SET)) < 0)
- {
+ retval = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_LED_SET);
+ if (retval < 0) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftdi_get_error_string(&ftdic));
+ ftdi_get_error_string(&ftdic));
return ERROR_JTAG_DEVICE_ERROR;
}
/* turn on center green led */
signalyzer_h_led_set(SIGNALYZER_CHAN_C, SIGNALYZER_LED_GREEN,
- 0xFFFF, 0x00, 0x00);
+ 0xFFFF, 0x00, 0x00);
/* determine what channel config wants to open
* TODO: change me... current implementation is made to work
*/
end_of_desc = strrchr(ft2232_device_desc, 0x00);
- if (end_of_desc)
- {
+ if (end_of_desc) {
signalyzer_h_side = *(end_of_desc - 1);
if (signalyzer_h_side == 'B')
signalyzer_h_side = SIGNALYZER_CHAN_B;
else
signalyzer_h_side = SIGNALYZER_CHAN_A;
- }
- else
- {
+ } else {
LOG_ERROR("No Channel was specified");
return ERROR_FAIL;
}
signalyzer_h_led_set(signalyzer_h_side, SIGNALYZER_LED_GREEN,
- 1000, 1000, 0xFF);
+ 1000, 1000, 0xFF);
#if BUILD_FT2232_FTD2XX == 1
/* read signalyzer versionining information */
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_VERSION)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_VERSION);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- for (i = 0; i < 10; i++)
- {
- if ((status = signalyzer_h_ctrl_read(
- (SIGNALYZER_DATA_BUFFER_ADDR + i),
- &read_buf[i])) != FT_OK)
- {
+ for (i = 0; i < 10; i++) {
+ status = signalyzer_h_ctrl_read((SIGNALYZER_DATA_BUFFER_ADDR + i),
+ &read_buf[i]);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_read returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
}
LOG_INFO("Signalyzer: ID info: { %.4x %.4x %.4x %.4x %.4x %.4x %.4x }",
- read_buf[0], read_buf[1], read_buf[2], read_buf[3],
- read_buf[4], read_buf[5], read_buf[6]);
+ read_buf[0], read_buf[1], read_buf[2], read_buf[3],
+ read_buf[4], read_buf[5], read_buf[6]);
/* set gpio register */
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
- (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ (uint32_t)(signalyzer_h_side << 8));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR + 1,
- 0x0404)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0404);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_GPIO_STATE)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_GPIO_STATE);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
/* read adapter type information */
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
- ((uint32_t)(signalyzer_h_side << 8) | 0x01))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ ((uint32_t)(signalyzer_h_side << 8) | 0x01));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- (SIGNALYZER_DATA_BUFFER_ADDR + 1), 0xA000)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(
+ (SIGNALYZER_DATA_BUFFER_ADDR + 1), 0xA000);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- (SIGNALYZER_DATA_BUFFER_ADDR + 2), 0x0008)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(
+ (SIGNALYZER_DATA_BUFFER_ADDR + 2), 0x0008);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_I2C)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_I2C);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
usleep(100000);
- if ((status = signalyzer_h_ctrl_read(SIGNALYZER_COMMAND_ADDR,
- &read_buf[0])) != FT_OK)
- {
+ status = signalyzer_h_ctrl_read(SIGNALYZER_COMMAND_ADDR, &read_buf[0]);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_read returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
if (read_buf[0] != 0x0498)
signalyzer_h_adapter_type = 0x0000;
- else
- {
- for (i = 0; i < 4; i++)
- {
- if ((status = signalyzer_h_ctrl_read(
- (SIGNALYZER_DATA_BUFFER_ADDR + i),
- &read_buf[i])) != FT_OK)
- {
+ else {
+ for (i = 0; i < 4; i++) {
+ status = signalyzer_h_ctrl_read((SIGNALYZER_DATA_BUFFER_ADDR + i), &read_buf[i]);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_read returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
}
enum reset_types jtag_reset_config = jtag_get_reset_config();
/* ADAPTOR: EM_LT16_A */
- if (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_LT16_A)
- {
+ if (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_LT16_A) {
LOG_INFO("Signalyzer: EM-LT (16-channel level translator) "
"detected. (HW: %2x).", (read_buf[1] >> 8));
high_output = 0x0;
high_direction = 0x0;
- if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
- low_direction &= ~nTRSTnOE; /* nTRST input */
- low_output &= ~nTRST; /* nTRST = 0 */
- }
- else
- {
- low_direction |= nTRSTnOE; /* nTRST output */
- low_output |= nTRST; /* nTRST = 1 */
+ if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) {
+ low_direction &= ~nTRSTnOE; /* nTRST input */
+ low_output &= ~nTRST; /* nTRST = 0 */
+ } else {
+ low_direction |= nTRSTnOE; /* nTRST output */
+ low_output |= nTRST; /* nTRST = 1 */
}
- if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
- low_direction |= nSRSTnOE; /* nSRST output */
- low_output |= nSRST; /* nSRST = 1 */
- }
- else
- {
- low_direction &= ~nSRSTnOE; /* nSRST input */
- low_output &= ~nSRST; /* nSRST = 0 */
+ if (jtag_reset_config & RESET_SRST_PUSH_PULL) {
+ low_direction |= nSRSTnOE; /* nSRST output */
+ low_output |= nSRST; /* nSRST = 1 */
+ } else {
+ low_direction &= ~nSRSTnOE; /* nSRST input */
+ low_output &= ~nSRST; /* nSRST = 0 */
}
#if BUILD_FT2232_FTD2XX == 1
/* enable power to the module */
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR,
- ((uint32_t)(signalyzer_h_side << 8) | 0x01)))
- != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ ((uint32_t)(signalyzer_h_side << 8) | 0x01));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_POWERCONTROL_SET)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_POWERCONTROL_SET);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
/* set gpio mode register */
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR,
- (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ (uint32_t)(signalyzer_h_side << 8));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0000))
- != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0000);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_GPIO_MODE)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR, SIGNALYZER_COMMAND_GPIO_MODE);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
/* set gpio register */
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR,
- (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ (uint32_t)(signalyzer_h_side << 8));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x4040))
- != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x4040);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_GPIO_STATE)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_GPIO_STATE);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
#endif
}
-
/* ADAPTOR: EM_ARM_JTAG, EM_ARM_JTAG_P, EM_JTAG, EM_JTAG_P */
else if ((signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG) ||
- (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG_P) ||
- (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG) ||
- (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG_P))
- {
+ (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG_P) ||
+ (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG) ||
+ (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG_P)) {
if (signalyzer_h_adapter_type
- == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG)
+ == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG)
LOG_INFO("Signalyzer: EM-ARM-JTAG (ARM JTAG) "
"detected. (HW: %2x).", (read_buf[1] >> 8));
else if (signalyzer_h_adapter_type
- == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG_P)
+ == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG_P)
LOG_INFO("Signalyzer: EM-ARM-JTAG_P "
"(ARM JTAG with PSU) detected. (HW: %2x).",
(read_buf[1] >> 8));
else if (signalyzer_h_adapter_type
- == SIGNALYZER_MODULE_TYPE_EM_JTAG)
+ == SIGNALYZER_MODULE_TYPE_EM_JTAG)
LOG_INFO("Signalyzer: EM-JTAG (Generic JTAG) "
"detected. (HW: %2x).", (read_buf[1] >> 8));
else if (signalyzer_h_adapter_type
- == SIGNALYZER_MODULE_TYPE_EM_JTAG_P)
+ == SIGNALYZER_MODULE_TYPE_EM_JTAG_P)
LOG_INFO("Signalyzer: EM-JTAG-P "
"(Generic JTAG with PSU) detected. (HW: %2x).",
(read_buf[1] >> 8));
high_output = 0x0;
high_direction = 0x1f;
- if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
+ if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) {
high_output |= nTRSTnOE;
high_output &= ~nTRST;
- }
- else
- {
+ } else {
high_output &= ~nTRSTnOE;
high_output |= nTRST;
}
- if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
+ if (jtag_reset_config & RESET_SRST_PUSH_PULL) {
high_output &= ~nSRSTnOE;
high_output |= nSRST;
- }
- else
- {
+ } else {
high_output |= nSRSTnOE;
high_output &= ~nSRST;
}
#if BUILD_FT2232_FTD2XX == 1
/* enable power to the module */
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR,
- ((uint32_t)(signalyzer_h_side << 8) | 0x01)))
- != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ ((uint32_t)(signalyzer_h_side << 8) | 0x01));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_POWERCONTROL_SET)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
+ SIGNALYZER_COMMAND_POWERCONTROL_SET);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
/* set gpio mode register (IO_16 and IO_17 set as analog
* inputs, other is gpio)
*/
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR,
- (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ (uint32_t)(signalyzer_h_side << 8));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0060))
- != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0060);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_GPIO_MODE)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR, SIGNALYZER_COMMAND_GPIO_MODE);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
/* set gpio register (all inputs, for -P modules,
* PSU will be turned off)
*/
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR,
- (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
+ (uint32_t)(signalyzer_h_side << 8));
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0000))
- != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0000);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
- if ((status = signalyzer_h_ctrl_write(
- SIGNALYZER_COMMAND_ADDR,
- SIGNALYZER_COMMAND_GPIO_STATE)) != FT_OK)
- {
+ status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR, SIGNALYZER_COMMAND_GPIO_STATE);
+ if (status != FT_OK) {
LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
- ftd2xx_status_string(status));
+ ftd2xx_status_string(status));
return ERROR_JTAG_DEVICE_ERROR;
}
#endif
- }
-
- else if (signalyzer_h_adapter_type == 0x0000)
- {
+ } else if (signalyzer_h_adapter_type == 0x0000) {
LOG_INFO("Signalyzer: No external modules were detected.");
nTRST = 0x10;
high_output = 0x0;
high_direction = 0x0;
- if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
- {
- low_direction &= ~nTRSTnOE; /* nTRST input */
- low_output &= ~nTRST; /* nTRST = 0 */
- }
- else
- {
- low_direction |= nTRSTnOE; /* nTRST output */
- low_output |= nTRST; /* nTRST = 1 */
+ if (jtag_reset_config & RESET_TRST_OPEN_DRAIN) {
+ low_direction &= ~nTRSTnOE; /* nTRST input */
+ low_output &= ~nTRST; /* nTRST = 0 */
+ } else {
+ low_direction |= nTRSTnOE; /* nTRST output */
+ low_output |= nTRST; /* nTRST = 1 */
}
- if (jtag_reset_config & RESET_SRST_PUSH_PULL)
- {
- low_direction |= nSRSTnOE; /* nSRST output */
- low_output |= nSRST; /* nSRST = 1 */
- }
- else
- {
- low_direction &= ~nSRSTnOE; /* nSRST input */
- low_output &= ~nSRST; /* nSRST = 0 */
+ if (jtag_reset_config & RESET_SRST_PUSH_PULL) {
+ low_direction |= nSRSTnOE; /* nSRST output */
+ low_output |= nSRST; /* nSRST = 1 */
+ } else {
+ low_direction &= ~nSRSTnOE; /* nSRST input */
+ low_output &= ~nSRST; /* nSRST = 0 */
}
- }
- else
- {
+ } else {
LOG_ERROR("Unknown module type is detected: %.4x",
- signalyzer_h_adapter_type);
+ signalyzer_h_adapter_type);
return ERROR_JTAG_DEVICE_ERROR;
}
/* initialize low byte of controller for jtag operation */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize Signalyzer-H layout");
return ERROR_JTAG_INIT_FAILED;
}
#if BUILD_FT2232_FTD2XX == 1
- if (ftdi_device == FT_DEVICE_2232H)
- {
+ if (ftdi_device == FT_DEVICE_2232H) {
/* initialize high byte of controller for jtag operation */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize Signalyzer-H layout");
return ERROR_JTAG_INIT_FAILED;
}
}
#elif BUILD_FT2232_LIBFTDI == 1
- if (ftdi_device == TYPE_2232H)
- {
+ if (ftdi_device == TYPE_2232H) {
/* initialize high byte of controller for jtag operation */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize Signalyzer-H layout");
return ERROR_JTAG_INIT_FAILED;
}
enum reset_types jtag_reset_config = jtag_get_reset_config();
/* ADAPTOR: EM_LT16_A */
- if (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_LT16_A)
- {
- if (trst == 1)
- {
+ if (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_LT16_A) {
+ if (trst == 1) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
/* switch to output pin (output is low) */
low_direction |= nTRSTnOE;
else
/* switch output low */
low_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
/* switch to input pin (high-Z + internal
* and external pullup) */
low_output |= nTRST;
}
- if (srst == 1)
- {
+ if (srst == 1) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
/* switch output low */
low_output &= ~nSRST;
else
/* switch to output pin (output is low) */
low_direction |= nSRSTnOE;
- }
- else if (srst == 0)
- {
+ } else if (srst == 0) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
/* switch output high */
low_output |= nSRST;
buffer_write(low_output);
buffer_write(low_direction);
LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, "
- "low_direction: 0x%2.2x",
- trst, srst, low_output, low_direction);
+ "low_direction: 0x%2.2x",
+ trst, srst, low_output, low_direction);
}
/* ADAPTOR: EM_ARM_JTAG, EM_ARM_JTAG_P, EM_JTAG, EM_JTAG_P */
else if ((signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG) ||
- (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG_P) ||
- (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG) ||
- (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG_P))
- {
- if (trst == 1)
- {
+ (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_ARM_JTAG_P) ||
+ (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG) ||
+ (signalyzer_h_adapter_type == SIGNALYZER_MODULE_TYPE_EM_JTAG_P)) {
+ if (trst == 1) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
high_output &= ~nTRSTnOE;
else
high_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
high_output |= nTRSTnOE;
else
high_output |= nTRST;
}
- if (srst == 1)
- {
+ if (srst == 1) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
high_output &= ~nSRST;
else
high_output &= ~nSRSTnOE;
- }
- else if (srst == 0)
- {
+ } else if (srst == 0) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
high_output |= nSRST;
else
buffer_write(high_output);
buffer_write(high_direction);
LOG_INFO("trst: %i, srst: %i, high_output: 0x%2.2x, "
- "high_direction: 0x%2.2x",
- trst, srst, high_output, high_direction);
- }
- else if (signalyzer_h_adapter_type == 0x0000)
- {
- if (trst == 1)
- {
+ "high_direction: 0x%2.2x",
+ trst, srst, high_output, high_direction);
+ } else if (signalyzer_h_adapter_type == 0x0000) {
+ if (trst == 1) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
/* switch to output pin (output is low) */
low_direction |= nTRSTnOE;
else
/* switch output low */
low_output &= ~nTRST;
- }
- else if (trst == 0)
- {
+ } else if (trst == 0) {
if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
/* switch to input pin (high-Z + internal
* and external pullup) */
low_output |= nTRST;
}
- if (srst == 1)
- {
+ if (srst == 1) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
/* switch output low */
low_output &= ~nSRST;
else
/* switch to output pin (output is low) */
low_direction |= nSRSTnOE;
- }
- else if (srst == 0)
- {
+ } else if (srst == 0) {
if (jtag_reset_config & RESET_SRST_PUSH_PULL)
/* switch output high */
low_output |= nSRST;
buffer_write(low_output);
buffer_write(low_direction);
LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, "
- "low_direction: 0x%2.2x",
- trst, srst, low_output, low_direction);
+ "low_direction: 0x%2.2x",
+ trst, srst, low_output, low_direction);
}
}
*******************************************************************/
static int ktlink_init(void)
{
- uint8_t swd_en = 0x20; //0x20 SWD disable, 0x00 SWD enable (ADBUS5)
+ uint8_t swd_en = 0x20; /* 0x20 SWD disable, 0x00 SWD enable (ADBUS5) */
- low_output = 0x08 | swd_en; // value; TMS=1,TCK=0,TDI=0,SWD=swd_en
- low_direction = 0x3B; // out=1; TCK/TDI/TMS=out,TDO=in,SWD=out,RTCK=in,SRSTIN=in
+ low_output = 0x08 | swd_en; /* value; TMS=1,TCK=0,TDI=0,SWD=swd_en */
+ low_direction = 0x3B; /* out=1; TCK/TDI/TMS=out,TDO=in,SWD=out,RTCK=in,SRSTIN=in */
/* initialize low byte for jtag */
- if (ft2232_set_data_bits_low_byte(low_output,low_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_low_byte(low_output, low_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'ktlink' layout");
return ERROR_JTAG_INIT_FAILED;
}
nTRSTnOE = 0x04;
nSRSTnOE = 0x08;
- high_output = 0x80; // turn LED on
- high_direction = 0xFF; // all outputs
+ high_output = 0x80; /* turn LED on */
+ high_direction = 0xFF; /* all outputs */
enum reset_types jtag_reset_config = jtag_get_reset_config();
}
/* initialize high byte for jtag */
- if (ft2232_set_data_bits_high_byte(high_output,high_direction) != ERROR_OK)
- {
+ if (ft2232_set_data_bits_high_byte(high_output, high_direction) != ERROR_OK) {
LOG_ERROR("couldn't initialize FT2232 with 'ktlink' layout");
return ERROR_JTAG_INIT_FAILED;
}
high_output |= nSRSTnOE;
}
- buffer_write(0x82); // command "set data bits high byte"
+ buffer_write(0x82); /* command "set data bits high byte" */
buffer_write(high_output);
buffer_write(high_direction);
- LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output,high_direction);
+ LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x",
+ trst,
+ srst,
+ high_output,
+ high_direction);
}
static void ktlink_blink(void)
/* LED connected to ACBUS7 */
high_output ^= 0x80;
- buffer_write(0x82); // command "set data bits high byte"
+ buffer_write(0x82); /* command "set data bits high byte" */
buffer_write(high_output);
buffer_write(high_direction);
}
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";
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <jtag/interface.h>
#include <jtag/commands.h>
-
#if 1
#define _DEBUG_GW16012_IO_
#endif
#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>
#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;
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_
{
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);
}
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 */
}
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);
}
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 */
}
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
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);
}
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));
}
}
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);
*/
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);
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;
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;
{
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;
}
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;
}
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;
}
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;
}
return ERROR_OK;
}
-#endif // PARPORT_USE_PPDEV
+#endif /* PARPORT_USE_PPDEV */
static int gw16012_init(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;
}
#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
*/
/*
*
* pid = ( usb_address > 0x4) ? 0x0101 : (0x101 + usb_address)
*/
+
#define VID 0x1366, 0x1366, 0x1366, 0x1366
#define PID 0x0101, 0x0102, 0x0103, 0x0104
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 */
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 };
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);
}
}
{
struct jtag_command *cmd = jtag_command_queue;
- while (cmd != NULL)
- {
+ while (cmd != NULL) {
jlink_execute_command(cmd);
cmd = cmd->next;
}
{
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;
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;
}
return ERROR_OK;
}
-static int jlink_speed_div(int speed, int* khz)
+static int jlink_speed_div(int speed, int *khz)
{
*khz = speed;
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;
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();
}
/* 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;
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);
}
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);
}
{
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);
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,
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)
/* 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)
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)
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;
}
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)
{
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);
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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;
}
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();
}
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;
{
uint32_t kickstart;
- if (CMD_ARGC < 1)
- {
+ if (CMD_ARGC < 1) {
jlink_config_kickstart_dump(CMD_CTX, &jlink_cfg);
return ERROR_OK;
}
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;
}
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;
}
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;
/* 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;
}
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;
}
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;
}
{
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;
}
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);
/* 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];
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);
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;
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);
* 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;
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();
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;
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();
/*****************************************************************************/
/* 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)
/* 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;
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;
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;
/* 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;
}
{
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;
}
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);
{
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;
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);
}
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;
}
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);
}
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;
};
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 */
}
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;
}
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;
}
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;
}
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;
#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 */
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 */
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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
#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 */
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 },
{ "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:
};
/* 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;
int data = 0;
#if PARPORT_USE_PPDEV == 1
- ioctl(device_handle, PPRSTATUS, & data);
+ ioctl(device_handle, PPRSTATUS, &data);
#else
data = inb(statusport);
#endif
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;
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");
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;
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;
}
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;
}
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;
#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)");
}
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;
}
{
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;
}
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;
}
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]);
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);
#include <helper/time_support.h>
#include "bitq.h"
-
/* PRESTO access library includes */
#if BUILD_PRESTO_FTD2XX == 1
#include <ftd2xx.h>
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;
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
};
{
#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;
}
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;
}
#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);
}
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;
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)
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)
{
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);
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;
}
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;
}
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();
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;
}
static int presto_tck_idle(void)
{
- if (presto->jtag_tck == 1)
- {
+ if (presto->jtag_tck == 1) {
presto_sendbyte(0xCA);
presto->jtag_tck = 0;
}
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)
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;
}
presto_tdi_flush();
presto_tck_idle();
- presto_sendbyte(0xA0); /* LED idicator - JTAG idle */
+ presto_sendbyte(0xA0); /* LED idicator - JTAG idle */
return presto_flush();
}
{
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;
}
presto_tdi_flush();
presto_tck_idle();
- if (us > 100000)
- {
+ if (us > 100000) {
presto_bitq_flush();
jtag_sleep(us);
return 0;
}
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;
}
int khz;
if (presto_jtag_speed_div(speed, &khz))
- {
return ERROR_COMMAND_SYNTAX_ERROR;
- }
presto->jtag_speed = speed;
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;
}
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);
presto_close();
LOG_INFO("PRESTO closed");
- if (presto_serial)
- {
+ if (presto_serial) {
free(presto_serial);
presto_serial = NULL;
}
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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)
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;
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)) {
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);
}
}
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;
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;
}
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;
}
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;
}
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "rlink_dtc_cmd.h"
#include "usb_common.h"
-
-/* This feature is made useless by running the DTC all the time. When automatic, the LED is on whenever the DTC is running. Otherwise, USB messages are sent to turn it on and off. */
+/* This feature is made useless by running the DTC all the time. When automatic, the LED is on
+ *whenever the DTC is running. Otherwise, USB messages are sent to turn it on and off. */
#undef AUTOMATIC_BUSY_LED
/* This feature may require derating the speed due to reduced hold time. */
#undef USE_HARDWARE_SHIFTER_FOR_TMS
+#define INTERFACE_NAME "RLink"
-#define INTERFACE_NAME "RLink"
-
-#define USB_IDVENDOR (0x138e)
-#define USB_IDPRODUCT (0x9000)
-
-#define USB_EP1OUT_ADDR (0x01)
-#define USB_EP1OUT_SIZE (16)
-#define USB_EP1IN_ADDR (USB_EP1OUT_ADDR | 0x80)
-#define USB_EP1IN_SIZE (USB_EP1OUT_SIZE)
+#define USB_IDVENDOR (0x138e)
+#define USB_IDPRODUCT (0x9000)
-#define USB_EP2OUT_ADDR (0x02)
-#define USB_EP2OUT_SIZE (64)
-#define USB_EP2IN_ADDR (USB_EP2OUT_ADDR | 0x80)
-#define USB_EP2IN_SIZE (USB_EP2OUT_SIZE)
-#define USB_EP2BANK_SIZE (512)
+#define USB_EP1OUT_ADDR (0x01)
+#define USB_EP1OUT_SIZE (16)
+#define USB_EP1IN_ADDR (USB_EP1OUT_ADDR | 0x80)
+#define USB_EP1IN_SIZE (USB_EP1OUT_SIZE)
-#define USB_TIMEOUT_MS (3 * 1000)
+#define USB_EP2OUT_ADDR (0x02)
+#define USB_EP2OUT_SIZE (64)
+#define USB_EP2IN_ADDR (USB_EP2OUT_ADDR | 0x80)
+#define USB_EP2IN_SIZE (USB_EP2OUT_SIZE)
+#define USB_EP2BANK_SIZE (512)
-#define DTC_STATUS_POLL_BYTE (ST7_USB_BUF_EP0OUT + 0xff)
+#define USB_TIMEOUT_MS (3 * 1000)
+#define DTC_STATUS_POLL_BYTE (ST7_USB_BUF_EP0OUT + 0xff)
-#define ST7_PD_NBUSY_LED ST7_PD0
-#define ST7_PD_NRUN_LED ST7_PD1
+#define ST7_PD_NBUSY_LED ST7_PD0
+#define ST7_PD_NRUN_LED ST7_PD1
/* low enables VPP at adapter header, high connects it to GND instead */
-#define ST7_PD_VPP_SEL ST7_PD6
+#define ST7_PD_VPP_SEL ST7_PD6
/* low: VPP = 12v, high: VPP <= 5v */
-#define ST7_PD_VPP_SHDN ST7_PD7
+#define ST7_PD_VPP_SHDN ST7_PD7
/* These pins are connected together */
-#define ST7_PE_ADAPTER_SENSE_IN ST7_PE3
-#define ST7_PE_ADAPTER_SENSE_OUT ST7_PE4
+#define ST7_PE_ADAPTER_SENSE_IN ST7_PE3
+#define ST7_PE_ADAPTER_SENSE_OUT ST7_PE4
/* Symbolic mapping between port pins and numbered IO lines */
-#define ST7_PA_IO1 ST7_PA1
-#define ST7_PA_IO2 ST7_PA2
-#define ST7_PA_IO4 ST7_PA4
-#define ST7_PA_IO8 ST7_PA6
-#define ST7_PA_IO10 ST7_PA7
-#define ST7_PB_IO5 ST7_PB5
-#define ST7_PC_IO9 ST7_PC1
-#define ST7_PC_IO3 ST7_PC2
-#define ST7_PC_IO7 ST7_PC3
-#define ST7_PE_IO6 ST7_PE5
+#define ST7_PA_IO1 ST7_PA1
+#define ST7_PA_IO2 ST7_PA2
+#define ST7_PA_IO4 ST7_PA4
+#define ST7_PA_IO8 ST7_PA6
+#define ST7_PA_IO10 ST7_PA7
+#define ST7_PB_IO5 ST7_PB5
+#define ST7_PC_IO9 ST7_PC1
+#define ST7_PC_IO3 ST7_PC2
+#define ST7_PC_IO7 ST7_PC3
+#define ST7_PE_IO6 ST7_PE5
/* Symbolic mapping between numbered IO lines and adapter signals */
-#define ST7_PA_RTCK ST7_PA_IO0
-#define ST7_PA_NTRST ST7_PA_IO1
-#define ST7_PC_TDI ST7_PC_IO3
-#define ST7_PA_DBGRQ ST7_PA_IO4
-#define ST7_PB_NSRST ST7_PB_IO5
-#define ST7_PE_TMS ST7_PE_IO6
-#define ST7_PC_TCK ST7_PC_IO7
-#define ST7_PC_TDO ST7_PC_IO9
-#define ST7_PA_DBGACK ST7_PA_IO10
+#define ST7_PA_RTCK ST7_PA_IO0
+#define ST7_PA_NTRST ST7_PA_IO1
+#define ST7_PC_TDI ST7_PC_IO3
+#define ST7_PA_DBGRQ ST7_PA_IO4
+#define ST7_PB_NSRST ST7_PB_IO5
+#define ST7_PE_TMS ST7_PE_IO6
+#define ST7_PC_TCK ST7_PC_IO7
+#define ST7_PC_TDO ST7_PC_IO9
+#define ST7_PA_DBGACK ST7_PA_IO10
static usb_dev_handle *pHDev;
-
/*
* ep1 commands are up to USB_EP1OUT_SIZE bytes in length.
* This function takes care of zeroing the unused bytes before sending the packet.
* Any reply packet is not handled by this function.
*/
-static
-int
-ep1_generic_commandl(
- usb_dev_handle *pHDev_param,
- size_t length,
- ...
-) {
- uint8_t usb_buffer[USB_EP1OUT_SIZE];
- uint8_t *usb_buffer_p;
- va_list ap;
- int usb_ret;
-
- if (length > sizeof(usb_buffer)) {
+static int ep1_generic_commandl(usb_dev_handle *pHDev_param, size_t length, ...)
+{
+ uint8_t usb_buffer[USB_EP1OUT_SIZE];
+ uint8_t *usb_buffer_p;
+ va_list ap;
+ int usb_ret;
+
+ if (length > sizeof(usb_buffer))
length = sizeof(usb_buffer);
- }
usb_buffer_p = usb_buffer;
}
memset(
- usb_buffer_p,
- 0,
- sizeof(usb_buffer) - (usb_buffer_p - usb_buffer)
- );
+ usb_buffer_p,
+ 0,
+ sizeof(usb_buffer) - (usb_buffer_p - usb_buffer)
+ );
usb_ret = usb_bulk_write(
pHDev_param,
USB_EP1OUT_ADDR,
(char *)usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
- );
+ );
- return(usb_ret);
+ return usb_ret;
}
-
-
#if 0
-static
-ssize_t
-ep1_memory_read(
- usb_dev_handle *pHDev,
- uint16_t addr,
- size_t length,
- uint8_t *buffer
-) {
- uint8_t usb_buffer[USB_EP1OUT_SIZE];
- int usb_ret;
- size_t remain;
- ssize_t count;
+static ssize_t ep1_memory_read(
+ usb_dev_handle *pHDev, uint16_t addr,
+ size_t length, uint8_t *buffer)
+{
+ uint8_t usb_buffer[USB_EP1OUT_SIZE];
+ int usb_ret;
+ size_t remain;
+ ssize_t count;
usb_buffer[0] = EP1_CMD_MEMORY_READ;
memset(
- usb_buffer + 4,
- 0,
- sizeof(usb_buffer) - 4
- );
+ usb_buffer + 4,
+ 0,
+ sizeof(usb_buffer) - 4
+ );
remain = length;
count = 0;
while (remain) {
- if (remain > sizeof(usb_buffer)) {
+ if (remain > sizeof(usb_buffer))
length = sizeof(usb_buffer);
- } else {
+ else
length = remain;
- }
usb_buffer[1] = addr >> 8;
usb_buffer[2] = addr;
pHDev, USB_EP1OUT_ADDR,
usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
- );
+ );
- if (usb_ret < sizeof(usb_buffer)) {
+ if (usb_ret < sizeof(usb_buffer))
break;
- }
usb_ret = usb_bulk_read(
pHDev, USB_EP1IN_ADDR,
buffer, length,
USB_TIMEOUT_MS
- );
+ );
- if (usb_ret < length) {
+ if (usb_ret < length)
break;
- }
addr += length;
buffer += length;
remain -= length;
}
- return(count);
+ return count;
}
#endif
-
-
-static
-ssize_t
-ep1_memory_write(
- usb_dev_handle *pHDev_param,
- uint16_t addr,
- size_t length,
- uint8_t const *buffer
-) {
- uint8_t usb_buffer[USB_EP1OUT_SIZE];
- int usb_ret;
- size_t remain;
- ssize_t count;
+static ssize_t ep1_memory_write(usb_dev_handle *pHDev_param, uint16_t addr,
+ size_t length, uint8_t const *buffer)
+{
+ uint8_t usb_buffer[USB_EP1OUT_SIZE];
+ int usb_ret;
+ size_t remain;
+ ssize_t count;
usb_buffer[0] = EP1_CMD_MEMORY_WRITE;
count = 0;
while (remain) {
- if (remain > (sizeof(usb_buffer) - 4)) {
+ if (remain > (sizeof(usb_buffer) - 4))
length = (sizeof(usb_buffer) - 4);
- } else {
+ else
length = remain;
- }
usb_buffer[1] = addr >> 8;
usb_buffer[2] = addr;
usb_buffer[3] = length;
memcpy(
- usb_buffer + 4,
- buffer,
- length
- );
+ usb_buffer + 4,
+ buffer,
+ length
+ );
memset(
- usb_buffer + 4 + length,
- 0,
- sizeof(usb_buffer) - 4 - length
- );
+ usb_buffer + 4 + length,
+ 0,
+ sizeof(usb_buffer) - 4 - length
+ );
usb_ret = usb_bulk_write(
pHDev_param, USB_EP1OUT_ADDR,
(char *)usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
- );
+ );
- if ((size_t)usb_ret < sizeof(usb_buffer)) {
+ if ((size_t)usb_ret < sizeof(usb_buffer))
break;
- }
addr += length;
buffer += length;
remain -= length;
}
- return(count);
+ return count;
}
#if 0
-static
-ssize_t
-ep1_memory_writel(
- usb_dev_handle *pHDev,
- uint16_t addr,
- size_t length,
- ...
-) {
- uint8_t buffer[USB_EP1OUT_SIZE - 4];
- uint8_t *buffer_p;
- va_list ap;
- size_t remain;
-
- if (length > sizeof(buffer)) {
+static ssize_t ep1_memory_writel(usb_dev_handle *pHDev, uint16_t addr,
+ size_t length, ...)
+{
+ uint8_t buffer[USB_EP1OUT_SIZE - 4];
+ uint8_t *buffer_p;
+ va_list ap;
+ size_t remain;
+
+ if (length > sizeof(buffer))
length = sizeof(buffer);
- }
remain = length;
buffer_p = buffer;
remain--;
}
- return(ep1_memory_write(pHDev, addr, length, buffer));
+ return ep1_memory_write(pHDev, addr, length, buffer);
}
#endif
+#define DTCLOAD_COMMENT (0)
+#define DTCLOAD_ENTRY (1)
+#define DTCLOAD_LOAD (2)
+#define DTCLOAD_RUN (3)
+#define DTCLOAD_LUT_START (4)
+#define DTCLOAD_LUT (5)
-#define DTCLOAD_COMMENT (0)
-#define DTCLOAD_ENTRY (1)
-#define DTCLOAD_LOAD (2)
-#define DTCLOAD_RUN (3)
-#define DTCLOAD_LUT_START (4)
-#define DTCLOAD_LUT (5)
-
-#define DTC_LOAD_BUFFER ST7_USB_BUF_EP2UIDO
+#define DTC_LOAD_BUFFER ST7_USB_BUF_EP2UIDO
/* This gets set by the DTC loader */
static uint8_t dtc_entry_download;
-
/* The buffer is specially formatted to represent a valid image to load into the DTC. */
-static
-int
-dtc_load_from_buffer(
- usb_dev_handle *pHDev_param,
- const uint8_t *buffer,
- size_t length
-) {
+static int dtc_load_from_buffer(usb_dev_handle *pHDev_param, const uint8_t *buffer,
+ size_t length)
+{
struct header_s {
- uint8_t type;
- uint8_t length;
+ uint8_t type;
+ uint8_t length;
};
- int usb_err;
- struct header_s *header;
- uint8_t lut_start = 0xc0;
+ int usb_err;
+ struct header_s *header;
+ uint8_t lut_start = 0xc0;
dtc_entry_download = 0;
usb_err = ep1_generic_commandl(
pHDev_param, 1,
EP1_CMD_DTC_STOP
- );
- if (usb_err < 0) return(usb_err);
+ );
+ if (usb_err < 0)
+ return usb_err;
while (length) {
if (length < sizeof(*header)) {
}
switch (header->type) {
- case DTCLOAD_COMMENT:
- break;
-
- case DTCLOAD_ENTRY:
- /* store entry addresses somewhere */
- if (!strncmp("download", (char *)buffer + 1, 8)) {
- dtc_entry_download = buffer[0];
- }
- break;
-
- case DTCLOAD_LOAD:
- /* Send the DTC program to ST7 RAM. */
- usb_err = ep1_memory_write(
- pHDev_param,
- DTC_LOAD_BUFFER,
- header->length + 1, buffer
- );
- if (usb_err < 0) return(usb_err);
-
- /* Load it into the DTC. */
- usb_err = ep1_generic_commandl(
- pHDev_param, 3,
- EP1_CMD_DTC_LOAD,
- (DTC_LOAD_BUFFER >> 8),
- DTC_LOAD_BUFFER
- );
- if (usb_err < 0) return(usb_err);
-
- break;
-
- case DTCLOAD_RUN:
- usb_err = ep1_generic_commandl(
- pHDev_param, 3,
- EP1_CMD_DTC_CALL,
- buffer[0],
- EP1_CMD_DTC_WAIT
- );
- if (usb_err < 0) return(usb_err);
-
- break;
-
- case DTCLOAD_LUT_START:
- lut_start = buffer[0];
- break;
-
- case DTCLOAD_LUT:
- usb_err = ep1_memory_write(
- pHDev_param,
- ST7_USB_BUF_EP0OUT + lut_start,
- header->length + 1, buffer
- );
- if (usb_err < 0) return(usb_err);
- break;
-
- default:
- LOG_ERROR("Invalid DTC image record type: 0x%02x", header->type);
- exit(1);
- break;
+ case DTCLOAD_COMMENT:
+ break;
+
+ case DTCLOAD_ENTRY:
+ /* store entry addresses somewhere */
+ if (!strncmp("download", (char *)buffer + 1, 8))
+ dtc_entry_download = buffer[0];
+ break;
+
+ case DTCLOAD_LOAD:
+ /* Send the DTC program to ST7 RAM. */
+ usb_err = ep1_memory_write(
+ pHDev_param,
+ DTC_LOAD_BUFFER,
+ header->length + 1, buffer
+ );
+ if (usb_err < 0)
+ return usb_err;
+
+ /* Load it into the DTC. */
+ usb_err = ep1_generic_commandl(
+ pHDev_param, 3,
+ EP1_CMD_DTC_LOAD,
+ (DTC_LOAD_BUFFER >> 8),
+ DTC_LOAD_BUFFER
+ );
+ if (usb_err < 0)
+ return usb_err;
+
+ break;
+
+ case DTCLOAD_RUN:
+ usb_err = ep1_generic_commandl(
+ pHDev_param, 3,
+ EP1_CMD_DTC_CALL,
+ buffer[0],
+ EP1_CMD_DTC_WAIT
+ );
+ if (usb_err < 0)
+ return usb_err;
+
+ break;
+
+ case DTCLOAD_LUT_START:
+ lut_start = buffer[0];
+ break;
+
+ case DTCLOAD_LUT:
+ usb_err = ep1_memory_write(
+ pHDev_param,
+ ST7_USB_BUF_EP0OUT + lut_start,
+ header->length + 1, buffer
+ );
+ if (usb_err < 0)
+ return usb_err;
+ break;
+
+ default:
+ LOG_ERROR("Invalid DTC image record type: 0x%02x", header->type);
+ exit(1);
+ break;
}
buffer += (header->length + 1);
length -= (header->length + 1);
}
- return(0);
+ return 0;
}
-
/*
* Start the DTC running in download mode (waiting for 512 byte command packets on ep2).
*/
-static
-int
-dtc_start_download(void) {
- int usb_err;
- uint8_t ep2txr;
+static int dtc_start_download(void)
+{
+ int usb_err;
+ uint8_t ep2txr;
/* set up for download mode and make sure EP2 is set up to transmit */
usb_err = ep1_generic_commandl(
ST7_EP2TXR >> 8,
ST7_EP2TXR,
1
- );
- if (usb_err < 0) return(usb_err);
+ );
+ if (usb_err < 0)
+ return usb_err;
/* read back ep2txr */
usb_err = usb_bulk_read(
pHDev, USB_EP1IN_ADDR,
(char *)&ep2txr, 1,
USB_TIMEOUT_MS
- );
- if (usb_err < 0) return(usb_err);
+ );
+ if (usb_err < 0)
+ return usb_err;
usb_err = ep1_generic_commandl(
pHDev, 13,
EP1_CMD_DTC_CALL, /* start running the DTC */
dtc_entry_download,
EP1_CMD_DTC_GET_CACHED_STATUS
- );
- if (usb_err < 0) return(usb_err);
+ );
+ if (usb_err < 0)
+ return usb_err;
/* wait for completion */
usb_err = usb_bulk_read(
pHDev, USB_EP1IN_ADDR,
(char *)&ep2txr, 1,
USB_TIMEOUT_MS
- );
+ );
- return(usb_err);
+ return usb_err;
}
-
-static
-int
-dtc_run_download(
- usb_dev_handle *pHDev_param,
- uint8_t *command_buffer,
- int command_buffer_size,
- uint8_t *reply_buffer,
- int reply_buffer_size
-) {
+static int dtc_run_download(
+ usb_dev_handle *pHDev_param,
+ uint8_t *command_buffer,
+ int command_buffer_size,
+ uint8_t *reply_buffer,
+ int reply_buffer_size
+ )
+{
char dtc_status;
- int usb_err;
- int i;
+ int usb_err;
+ int i;
LOG_DEBUG("%d/%d", command_buffer_size, reply_buffer_size);
USB_EP2OUT_ADDR,
(char *)command_buffer, USB_EP2BANK_SIZE,
USB_TIMEOUT_MS
- );
- if (usb_err < 0) return(usb_err);
+ );
+ if (usb_err < 0)
+ return usb_err;
/* Wait for DTC to finish running command buffer */
- for (i = 10;;) {
+ for (i = 10;; ) {
usb_err = ep1_generic_commandl(
pHDev_param, 4,
DTC_STATUS_POLL_BYTE >> 8,
DTC_STATUS_POLL_BYTE,
1
- );
- if (usb_err < 0) return(usb_err);
+ );
+ if (usb_err < 0)
+ return usb_err;
usb_err = usb_bulk_read(
pHDev_param,
USB_EP1IN_ADDR,
&dtc_status, 1,
USB_TIMEOUT_MS
- );
- if (usb_err < 0) return(usb_err);
+ );
+ if (usb_err < 0)
+ return usb_err;
- if (dtc_status & 0x01) break;
+ if (dtc_status & 0x01)
+ break;
if (!--i) {
LOG_ERROR("too many retries waiting for DTC status");
- return(-ETIMEDOUT);
+ return -ETIMEDOUT;
}
}
USB_EP2IN_ADDR,
(char *)reply_buffer, reply_buffer_size,
USB_TIMEOUT_MS
- );
+ );
if (usb_err < reply_buffer_size) {
LOG_ERROR("Read of endpoint 2 returned %d, expected %d",
- usb_err, reply_buffer_size
- );
- return(usb_err);
+ usb_err, reply_buffer_size
+ );
+ return usb_err;
}
}
- return(usb_err);
+ return usb_err;
}
-
/*
- * The dtc reply queue is a singly linked list that describes what to do with the reply packet that comes from the DTC. Only SCAN_IN and SCAN_IO generate these entries.
+ * The dtc reply queue is a singly linked list that describes what to do
+ * with the reply packet that comes from the DTC. Only SCAN_IN and SCAN_IO generate
+ * these entries.
*/
struct dtc_reply_queue_entry {
- struct dtc_reply_queue_entry *next;
- struct jtag_command *cmd; /* the command that resulted in this entry */
+ struct dtc_reply_queue_entry *next;
+ struct jtag_command *cmd; /* the command that resulted in this entry */
struct {
- uint8_t *buffer; /* the scan buffer */
- int size; /* size of the scan buffer in bits */
- int offset; /* how many bits were already done before this? */
- int length; /* how many bits are processed in this operation? */
- enum scan_type type; /* SCAN_IN/SCAN_OUT/SCAN_IO */
+ uint8_t *buffer; /* the scan buffer */
+ int size; /* size of the scan buffer in bits */
+ int offset; /* how many bits were already done before this? */
+ int length; /* how many bits are processed in this operation? */
+ enum scan_type type; /* SCAN_IN/SCAN_OUT/SCAN_IO */
} scan;
};
* rlink_scan and tap_state_run add to the command buffer and maybe to the reply queue.
*/
-static
-struct {
- struct dtc_reply_queue_entry *rq_head;
- struct dtc_reply_queue_entry *rq_tail;
- uint32_t cmd_index;
- uint32_t reply_index;
- uint8_t cmd_buffer[USB_EP2BANK_SIZE];
+static struct {
+ struct dtc_reply_queue_entry *rq_head;
+ struct dtc_reply_queue_entry *rq_tail;
+ uint32_t cmd_index;
+ uint32_t reply_index;
+ uint8_t cmd_buffer[USB_EP2BANK_SIZE];
} dtc_queue;
-
/*
- * The tap state queue is for accumulating TAP state changes wiithout needlessly flushing the dtc_queue. When it fills or is run, it adds the accumulated bytes to the dtc_queue.
+ * The tap state queue is for accumulating TAP state changes wiithout needlessly
+ * flushing the dtc_queue. When it fills or is run, it adds the accumulated bytes to
+ * the dtc_queue.
*/
-static
-struct {
- uint32_t length;
- uint32_t buffer;
+static struct {
+ uint32_t length;
+ uint32_t buffer;
} tap_state_queue;
-
-
-static
-int
-dtc_queue_init(void) {
+static int dtc_queue_init(void)
+{
dtc_queue.rq_head = NULL;
dtc_queue.rq_tail = NULL;
dtc_queue.cmd_index = 0;
dtc_queue.reply_index = 0;
- return(0);
+ return 0;
}
-
-static
-inline
-struct dtc_reply_queue_entry *
-dtc_queue_enqueue_reply(
- enum scan_type type,
- uint8_t *buffer,
- int size,
- int offset,
- int length,
- struct jtag_command *cmd
-) {
- struct dtc_reply_queue_entry *rq_entry;
+static inline struct dtc_reply_queue_entry *dtc_queue_enqueue_reply(
+ enum scan_type type, uint8_t *buffer, int size, int offset,
+ int length, struct jtag_command *cmd)
+{
+ struct dtc_reply_queue_entry *rq_entry;
rq_entry = malloc(sizeof(struct dtc_reply_queue_entry));
if (rq_entry != NULL) {
dtc_queue.rq_tail = rq_entry;
}
- return(rq_entry);
+ return rq_entry;
}
-
/*
- * Running the queue means that any pending command buffer is run and any reply data dealt with. The command buffer is then cleared for subsequent processing.
+ * Running the queue means that any pending command buffer is run
+ * and any reply data dealt with. The command buffer is then cleared for subsequent processing.
* The queue is automatically run by append when it is necessary to get space for the append.
*/
-static
-int
-dtc_queue_run(void) {
- struct dtc_reply_queue_entry *rq_p, *rq_next;
- int retval;
- int usb_err;
- int bit_cnt;
- int x;
- uint8_t *dtc_p, *tdo_p;
- uint8_t dtc_mask, tdo_mask;
- uint8_t reply_buffer[USB_EP2IN_SIZE];
+static int dtc_queue_run(void)
+{
+ struct dtc_reply_queue_entry *rq_p, *rq_next;
+ int retval;
+ int usb_err;
+ int bit_cnt;
+ int x;
+ uint8_t *dtc_p, *tdo_p;
+ uint8_t dtc_mask, tdo_mask;
+ uint8_t reply_buffer[USB_EP2IN_SIZE];
assert((dtc_queue.rq_head != 0) == (dtc_queue.reply_index > 0));
assert(dtc_queue.cmd_index < USB_EP2BANK_SIZE);
retval = ERROR_OK;
- if (dtc_queue.cmd_index < 1) return(retval);
+ if (dtc_queue.cmd_index < 1)
+ return retval;
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] = DTC_CMD_STOP;
usb_err = dtc_run_download(pHDev,
dtc_queue.cmd_buffer, dtc_queue.cmd_index,
reply_buffer, dtc_queue.reply_index
- );
+ );
if (usb_err < 0) {
LOG_ERROR("dtc_run_download: %s", usb_strerror());
exit(1);
/* process the reply, which empties the reply queue and frees its entries */
dtc_p = reply_buffer;
- /* The rigamarole with the masks and doing it bit-by-bit is due to the fact that the scan buffer is LSb-first and the DTC code is MSb-first for hardware reasons. It was that or craft a function to do the reversal, and that wouldn't work with bit-stuffing (supplying extra bits to use mostly byte operations), or any other scheme which would throw the byte alignment off. */
+ /* The rigamarole with the masks and doing it bit-by-bit is due to the fact that the
+ *scan buffer is LSb-first and the DTC code is MSb-first for hardware reasons. It
+ *was that or craft a function to do the reversal, and that wouldn't work with
+ *bit-stuffing (supplying extra bits to use mostly byte operations), or any other
+ *scheme which would throw the byte alignment off. */
for (
- rq_p = dtc_queue.rq_head;
- rq_p != NULL;
- rq_p = rq_next
- ) {
+ rq_p = dtc_queue.rq_head;
+ rq_p != NULL;
+ rq_p = rq_next
+ ) {
tdo_p = rq_p->scan.buffer + (rq_p->scan.offset / 8);
tdo_mask = 1 << (rq_p->scan.offset % 8);
dtc_mask = 1 << (8 - 1);
for (
- ;
- bit_cnt;
- bit_cnt--
- ) {
- if (*dtc_p & dtc_mask) {
+ ;
+ bit_cnt;
+ bit_cnt--
+ ) {
+ if (*dtc_p & dtc_mask)
*tdo_p |= tdo_mask;
- } else {
- *tdo_p &=~ tdo_mask;
- }
+ else
+ *tdo_p &= ~tdo_mask;
dtc_mask >>= 1;
if (dtc_mask == 0) {
/* extra bits or last bit */
x = *dtc_p++;
- if ((
- rq_p->scan.type == SCAN_IN
- ) && (
+ if ((rq_p->scan.type == SCAN_IN) && (
rq_p->scan.offset != rq_p->scan.size - 1
- )) {
- /* extra bits were sent as a full byte with padding on the end */
+ )) {
+ /* extra bits were sent as a full byte with padding on the
+ *end */
dtc_mask = 1 << (8 - 1);
- } else {
+ } else
dtc_mask = 1 << (bit_cnt - 1);
- }
for (
- ;
- bit_cnt;
- bit_cnt--
- ) {
- if (x & dtc_mask) {
+ ;
+ bit_cnt;
+ bit_cnt--
+ ) {
+ if (x & dtc_mask)
*tdo_p |= tdo_mask;
- } else {
- *tdo_p &=~ tdo_mask;
- }
+ else
+ *tdo_p &= ~tdo_mask;
dtc_mask >>= 1;
if ((rq_p->scan.offset + rq_p->scan.length) >= rq_p->scan.size) {
/* feed scan buffer back into openocd and free it */
- if (jtag_read_buffer(rq_p->scan.buffer, rq_p->cmd->cmd.scan) != ERROR_OK) {
+ if (jtag_read_buffer(rq_p->scan.buffer,
+ rq_p->cmd->cmd.scan) != ERROR_OK)
retval = ERROR_JTAG_QUEUE_FAILED;
- }
free(rq_p->scan.buffer);
}
dtc_queue.rq_tail = NULL;
}
-
/* reset state for new appends */
dtc_queue.cmd_index = 0;
dtc_queue.reply_index = 0;
- return(retval);
+ return retval;
}
/* runs the queue if it cannot take reserved_cmd bytes of command data
* or reserved_reply bytes of reply data */
-static
-int
-dtc_queue_run_if_full(
- int reserved_cmd,
- int reserved_reply
-) {
+static int dtc_queue_run_if_full(int reserved_cmd, int reserved_reply)
+{
/* reserve one additional byte for the STOP cmd appended during run */
if (dtc_queue.cmd_index + reserved_cmd + 1 > USB_EP2BANK_SIZE)
return dtc_queue_run();
return ERROR_OK;
}
-static
-int
-tap_state_queue_init(void) {
+static int tap_state_queue_init(void)
+{
tap_state_queue.length = 0;
tap_state_queue.buffer = 0;
- return(0);
+ return 0;
}
-
-static
-int
-tap_state_queue_run(void) {
- int i;
- int bits;
- uint8_t byte_param;
- int retval;
+static int tap_state_queue_run(void)
+{
+ int i;
+ int bits;
+ uint8_t byte_param;
+ int retval;
retval = 0;
- if (!tap_state_queue.length) return(retval);
+ if (!tap_state_queue.length)
+ return retval;
bits = 1;
byte_param = 0;
- for (i = tap_state_queue.length; i--;) {
+ for (i = tap_state_queue.length; i--; ) {
byte_param <<= 1;
- if (tap_state_queue.buffer & 1) {
+ if (tap_state_queue.buffer & 1)
byte_param |= 1;
- }
if ((bits >= 8) || !i) {
byte_param <<= (8 - bits);
#ifdef USE_HARDWARE_SHIFTER_FOR_TMS
if (bits == 8) {
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- DTC_CMD_SHIFT_TMS_BYTES(1);
+ DTC_CMD_SHIFT_TMS_BYTES(1);
} else {
#endif
- dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- DTC_CMD_SHIFT_TMS_BITS(bits);
+ dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
+ DTC_CMD_SHIFT_TMS_BITS(bits);
#ifdef USE_HARDWARE_SHIFTER_FOR_TMS
- }
+ }
#endif
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- byte_param;
+ byte_param;
byte_param = 0;
bits = 1;
- } else {
+ } else
bits++;
- }
tap_state_queue.buffer >>= 1;
}
retval = tap_state_queue_init();
- return(retval);
+ return retval;
}
-
-static
-int
-tap_state_queue_append(
- uint8_t tms
-) {
- int retval;
+static int tap_state_queue_append(uint8_t tms)
+{
+ int retval;
if (tap_state_queue.length >= sizeof(tap_state_queue.buffer) * 8) {
retval = tap_state_queue_run();
- if (retval != 0) return(retval);
+ if (retval != 0)
+ return retval;
}
- if (tms) {
+ if (tms)
tap_state_queue.buffer |= (1 << tap_state_queue.length);
- }
tap_state_queue.length++;
- return(0);
+ return 0;
}
-
-static
-void rlink_end_state(tap_state_t state)
+static void rlink_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);
}
}
-
-static
-void rlink_state_move(void) {
+static void rlink_state_move(void)
+{
int i = 0, tms = 0;
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;
tap_state_queue_append(tms);
}
tap_set_state(tap_get_end_state());
}
-static
-void rlink_path_move(struct pathmove_command *cmd)
+static void rlink_path_move(struct pathmove_command *cmd)
{
int num_states = cmd->num_states;
int state_count;
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);
}
tap_set_end_state(tap_get_state());
}
-
-static
-void rlink_runtest(int num_cycles)
+static void rlink_runtest(int num_cycles)
{
int i;
tap_state_t saved_end_state = tap_get_end_state();
/* only do a state_move when we're not already in RTI */
- if (tap_get_state() != TAP_IDLE)
- {
+ if (tap_get_state() != TAP_IDLE) {
rlink_end_state(TAP_IDLE);
rlink_state_move();
}
/* execute num_cycles */
for (i = 0; i < num_cycles; i++)
- {
tap_state_queue_append(0);
- }
/* finish in end_state */
rlink_end_state(saved_end_state);
rlink_state_move();
}
-
/* (1) assert or (0) deassert reset lines */
-static
-void rlink_reset(int trst, int srst)
+static void rlink_reset(int trst, int srst)
{
- uint8_t bitmap;
- int usb_err;
+ uint8_t bitmap;
+ int usb_err;
/* Read port A for bit op */
usb_err = ep1_generic_commandl(
ST7_PADR >> 8,
ST7_PADR,
1
- );
+ );
if (usb_err < 0) {
LOG_ERROR("%s", usb_strerror());
exit(1);
pHDev, USB_EP1IN_ADDR,
(char *)&bitmap, 1,
USB_TIMEOUT_MS
- );
+ );
if (usb_err < 1) {
LOG_ERROR("%s", usb_strerror());
exit(1);
}
- if (trst) {
+ if (trst)
bitmap &= ~ST7_PA_NTRST;
- } else {
+ else
bitmap |= ST7_PA_NTRST;
- }
- /* Write port A and read port B for bit op */
- /* port B has no OR, and we want to emulate open drain on NSRST, so we initialize DR to 0 and assert NSRST by setting DDR to 1. */
+ /* Write port A and read port B for bit op
+ * port B has no OR, and we want to emulate open drain on NSRST, so we initialize DR to 0
+ *and assert NSRST by setting DDR to 1. */
usb_err = ep1_generic_commandl(
pHDev, 9,
EP1_CMD_MEMORY_WRITE,
ST7_PBDDR >> 8,
ST7_PBDDR,
1
- );
+ );
if (usb_err < 0) {
LOG_ERROR("%s", usb_strerror());
exit(1);
pHDev, USB_EP1IN_ADDR,
(char *)&bitmap, 1,
USB_TIMEOUT_MS
- );
+ );
if (usb_err < 1) {
LOG_ERROR("%s", usb_strerror());
exit(1);
}
- if (srst) {
+ if (srst)
bitmap |= ST7_PB_NSRST;
- } else {
+ else
bitmap &= ~ST7_PB_NSRST;
- }
/* write port B and read dummy to ensure completion before returning */
usb_err = ep1_generic_commandl(
1,
bitmap,
EP1_CMD_DTC_GET_CACHED_STATUS
- );
+ );
if (usb_err < 0) {
LOG_ERROR("%s", usb_strerror());
exit(1);
pHDev, USB_EP1IN_ADDR,
(char *)&bitmap, 1,
USB_TIMEOUT_MS
- );
+ );
if (usb_err < 1) {
LOG_ERROR("%s", usb_strerror());
exit(1);
}
}
-
-static
-int
-rlink_scan(
- struct jtag_command *cmd,
- enum scan_type type,
- uint8_t *buffer,
- int scan_size
-) {
- bool ir_scan;
- tap_state_t saved_end_state;
- int byte_bits;
- int extra_bits;
- int chunk_bits;
- int chunk_bytes;
- int x;
-
- int tdi_bit_offset;
- uint8_t tdi_mask, *tdi_p;
- uint8_t dtc_mask;
+static int rlink_scan(struct jtag_command *cmd, enum scan_type type,
+ uint8_t *buffer, int scan_size)
+{
+ bool ir_scan;
+ tap_state_t saved_end_state;
+ int byte_bits;
+ int extra_bits;
+ int chunk_bits;
+ int chunk_bytes;
+ int x;
+
+ int tdi_bit_offset;
+ uint8_t tdi_mask, *tdi_p;
+ uint8_t dtc_mask;
if (scan_size < 1) {
LOG_ERROR("scan_size cannot be less than 1 bit");
ir_scan = cmd->cmd.scan->ir_scan;
/* Move to the proper state before starting to shift TDI/TDO. */
- 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)))) {
saved_end_state = tap_get_end_state();
rlink_end_state(ir_scan ? TAP_IRSHIFT : TAP_DRSHIFT);
rlink_state_move();
#if 0
printf("scan_size = %d, type = 0x%x\n", scan_size, type);
{
- int i;
+ int i;
- /* clear unused bits in scan buffer for ease of debugging */
- /* (it makes diffing output easier) */
+ /* clear unused bits in scan buffer for ease of debugging
+ * (it makes diffing output easier) */
buffer[scan_size / 8] &= ((1 << ((scan_size - 1) % 8) + 1) - 1);
printf("before scan:");
- for (i = 0; i < (scan_size + 7) / 8; i++) {
+ for (i = 0; i < (scan_size + 7) / 8; i++)
printf(" %02x", buffer[i]);
- }
printf("\n");
}
#endif
tdi_mask = 1;
if (extra_bits && (type == SCAN_OUT)) {
- /* Schedule any extra bits into the DTC command buffer, padding as needed */
- /* For SCAN_OUT, this comes before the full bytes so the (leading) padding bits will fall off the end */
+ /* Schedule any extra bits into the DTC command buffer, padding as needed
+ * For SCAN_OUT, this comes before the full bytes so the (leading) padding bits will
+ *fall off the end */
/* make sure there's room for two cmd bytes */
dtc_queue_run_if_full(2, 0);
dtc_mask = 1 << (extra_bits - 1);
while (extra_bits--) {
- if (*tdi_p & tdi_mask) {
+ if (*tdi_p & tdi_mask)
x |= dtc_mask;
- }
dtc_mask >>= 1;
}
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- DTC_CMD_SHIFT_TDI_BYTES(1);
+ DTC_CMD_SHIFT_TDI_BYTES(1);
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] = x;
}
chunk_bits = byte_bits;
/* we can only use up to 16 bytes at a time */
- if (chunk_bits > (16 * 8)) chunk_bits = (16 * 8);
+ if (chunk_bits > (16 * 8))
+ chunk_bits = (16 * 8);
if (type != SCAN_IN) {
/* how much is there room for, considering stop and byte op? */
x = (sizeof(dtc_queue.cmd_buffer) - (dtc_queue.cmd_index + 1 + 1)) * 8;
- if (chunk_bits > x) chunk_bits = x;
+ if (chunk_bits > x)
+ chunk_bits = x;
}
if (type != SCAN_OUT) {
/* how much is there room for in the reply buffer? */
x = (USB_EP2IN_SIZE - dtc_queue.reply_index) * 8;
- if (chunk_bits > x) chunk_bits = x;
+ if (chunk_bits > x)
+ chunk_bits = x;
}
/* so the loop will end */
type, buffer, scan_size, tdi_bit_offset,
chunk_bits,
cmd
- ) == NULL) {
+ ) == NULL) {
LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
exit(1);
}
chunk_bytes = chunk_bits / 8;
switch (type) {
- case SCAN_IN:
- x = DTC_CMD_SHIFT_TDO_BYTES(chunk_bytes);
- break;
- case SCAN_OUT:
- x = DTC_CMD_SHIFT_TDI_BYTES(chunk_bytes);
- break;
- default:
- x = DTC_CMD_SHIFT_TDIO_BYTES(chunk_bytes);
- break;
+ case SCAN_IN:
+ x = DTC_CMD_SHIFT_TDO_BYTES(chunk_bytes);
+ break;
+ case SCAN_OUT:
+ x = DTC_CMD_SHIFT_TDI_BYTES(chunk_bytes);
+ break;
+ default:
+ x = DTC_CMD_SHIFT_TDIO_BYTES(chunk_bytes);
+ break;
}
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] = x;
dtc_mask = 1 << (8 - 1);
while (chunk_bits--) {
- if (*tdi_p & tdi_mask) {
+ if (*tdi_p & tdi_mask)
x |= dtc_mask;
- }
dtc_mask >>= 1;
if (dtc_mask == 0) {
type, buffer, scan_size, tdi_bit_offset,
extra_bits,
cmd
- ) == NULL) {
+ ) == NULL) {
LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
exit(1);
}
if (type == SCAN_IN) {
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- DTC_CMD_SHIFT_TDO_BYTES(1);
+ DTC_CMD_SHIFT_TDO_BYTES(1);
} else {
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- DTC_CMD_SHIFT_TDIO_BITS(extra_bits);
+ DTC_CMD_SHIFT_TDIO_BITS(extra_bits);
x = 0;
dtc_mask = 1 << (8 - 1);
while (extra_bits--) {
- if (*tdi_p & tdi_mask) {
+ if (*tdi_p & tdi_mask)
x |= dtc_mask;
- }
dtc_mask >>= 1;
if (type == SCAN_OUT) {
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- DTC_CMD_SHIFT_TMS_TDI_BIT_PAIR(1, (*tdi_p & tdi_mask), 0);
+ DTC_CMD_SHIFT_TMS_TDI_BIT_PAIR(1, (*tdi_p & tdi_mask), 0);
} else {
if (dtc_queue_enqueue_reply(
type, buffer, scan_size, tdi_bit_offset,
1,
cmd
- ) == NULL) {
+ ) == NULL) {
LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
exit(1);
}
dtc_queue.reply_index++;
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- DTC_CMD_SHIFT_TMS_TDI_BIT_PAIR(1, (*tdi_p & tdi_mask), 1);
+ DTC_CMD_SHIFT_TMS_TDI_BIT_PAIR(1, (*tdi_p & tdi_mask), 1);
}
/* Move to pause state */
tap_state_queue_append(0);
tap_set_state(ir_scan ? TAP_IRPAUSE : TAP_DRPAUSE);
- if (tap_get_state() != tap_get_end_state()) rlink_state_move();
+ if (tap_get_state() != tap_get_end_state())
+ rlink_state_move();
- return(0);
+ return 0;
}
-
-static
-int rlink_execute_queue(void)
+static int rlink_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;
#ifndef AUTOMATIC_BUSY_LED
/* turn LED on */
ep1_generic_commandl(pHDev, 2,
- EP1_CMD_SET_PORTD_LEDS,
- ~(ST7_PD_NBUSY_LED)
- );
+ EP1_CMD_SET_PORTD_LEDS,
+ ~(ST7_PD_NBUSY_LED)
+ );
#endif
- while (cmd)
- {
- switch (cmd->type)
- {
- case JTAG_RUNTEST:
- case JTAG_TLR_RESET:
- case JTAG_PATHMOVE:
- case JTAG_SCAN:
- break;
-
- default:
- /* some events, such as resets, need a queue flush to ensure consistency */
- tap_state_queue_run();
- dtc_queue_run();
- break;
+ while (cmd) {
+ switch (cmd->type) {
+ case JTAG_RUNTEST:
+ case JTAG_TLR_RESET:
+ case JTAG_PATHMOVE:
+ case JTAG_SCAN:
+ break;
+
+ default:
+ /* some events, such as resets, need a queue flush to ensure
+ *consistency */
+ tap_state_queue_run();
+ dtc_queue_run();
+ break;
}
- switch (cmd->type)
- {
- case JTAG_RESET:
+ 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)))
- {
- tap_set_state(TAP_RESET);
- }
- rlink_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
- break;
- case JTAG_RUNTEST:
+ if ((cmd->cmd.reset->trst == 1) ||
+ (cmd->cmd.reset->srst &&
+ (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
+ tap_set_state(TAP_RESET);
+ rlink_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
- if (cmd->cmd.runtest->end_state != -1)
- rlink_end_state(cmd->cmd.runtest->end_state);
- rlink_runtest(cmd->cmd.runtest->num_cycles);
- break;
- case JTAG_TLR_RESET:
+ if (cmd->cmd.runtest->end_state != -1)
+ rlink_end_state(cmd->cmd.runtest->end_state);
+ rlink_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
- if (cmd->cmd.statemove->end_state != -1)
- rlink_end_state(cmd->cmd.statemove->end_state);
- rlink_state_move();
- break;
- case JTAG_PATHMOVE:
+ if (cmd->cmd.statemove->end_state != -1)
+ rlink_end_state(cmd->cmd.statemove->end_state);
+ rlink_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
- rlink_path_move(cmd->cmd.pathmove);
- break;
- case JTAG_SCAN:
+ rlink_path_move(cmd->cmd.pathmove);
+ break;
+ case JTAG_SCAN:
#ifdef _DEBUG_JTAG_IO_
- LOG_DEBUG("%s scan end in %i", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", cmd->cmd.scan->end_state);
+ LOG_DEBUG("%s scan end in %i",
+ (cmd->cmd.scan->ir_scan) ? "IR" : "DR",
+ cmd->cmd.scan->end_state);
#endif
- if (cmd->cmd.scan->end_state != -1)
- rlink_end_state(cmd->cmd.scan->end_state);
- scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
- type = jtag_scan_type(cmd->cmd.scan);
- if (rlink_scan(cmd, type, buffer, scan_size) != ERROR_OK) {
- retval = ERROR_FAIL;
- }
- break;
- case JTAG_SLEEP:
+ if (cmd->cmd.scan->end_state != -1)
+ rlink_end_state(cmd->cmd.scan->end_state);
+ scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
+ type = jtag_scan_type(cmd->cmd.scan);
+ if (rlink_scan(cmd, type, buffer, scan_size) != ERROR_OK)
+ retval = ERROR_FAIL;
+ 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;
}
- /* Flush the DTC queue to make sure any pending reads have been done before exiting this function */
+ /* Flush the DTC queue to make sure any pending reads have been done before exiting this
+ *function */
tap_state_queue_run();
tmp_retval = dtc_queue_run();
- if (tmp_retval != ERROR_OK) {
+ if (tmp_retval != ERROR_OK)
retval = tmp_retval;
- }
#ifndef AUTOMATIC_BUSY_LED
/* turn LED onff */
ep1_generic_commandl(pHDev, 2,
- EP1_CMD_SET_PORTD_LEDS,
- ~0
- );
+ EP1_CMD_SET_PORTD_LEDS,
+ ~0
+ );
#endif
return retval;
}
+/* Using an unindexed table because it is infrequently accessed and it is short. The table must be
+ *in order of ascending speed (and descending prescaler), as it is scanned in reverse. */
-/* Using an unindexed table because it is infrequently accessed and it is short. The table must be in order of ascending speed (and descending prescaler), as it is scanned in reverse. */
-
-static
-int rlink_speed(int speed)
+static int rlink_speed(int speed)
{
- int i;
+ int i;
if (speed == 0) {
/* fastest speed */
speed = rlink_speed_table[rlink_speed_table_size - 1].prescaler;
}
- for (i = rlink_speed_table_size; i--;) {
+ for (i = rlink_speed_table_size; i--; ) {
if (rlink_speed_table[i].prescaler == speed) {
- if (dtc_load_from_buffer(pHDev, rlink_speed_table[i].dtc, rlink_speed_table[i].dtc_size) != 0) {
- LOG_ERROR("An error occurred while trying to load DTC code for speed \"%d\".", speed);
+ if (dtc_load_from_buffer(pHDev, rlink_speed_table[i].dtc,
+ rlink_speed_table[i].dtc_size) != 0) {
+ LOG_ERROR(
+ "An error occurred while trying to load DTC code for speed \"%d\".",
+ speed);
exit(1);
}
}
LOG_ERROR("%d is not a supported speed", speed);
- return(ERROR_FAIL);
+ return ERROR_FAIL;
}
+static int rlink_speed_div(int speed, int *khz)
+{
+ int i;
-static
-int rlink_speed_div(
- int speed,
- int *khz
-) {
- int i;
-
- for (i = rlink_speed_table_size; i--;) {
+ for (i = rlink_speed_table_size; i--; ) {
if (rlink_speed_table[i].prescaler == speed) {
*khz = rlink_speed_table[i].khz;
- return(ERROR_OK);
+ return ERROR_OK;
}
}
LOG_ERROR("%d is not a supported speed", speed);
- return(ERROR_FAIL);
+ return ERROR_FAIL;
}
-
-static
-int rlink_khz(
- int khz,
- int *speed
-) {
- int i;
+static int rlink_khz(int khz, int *speed)
+{
+ int i;
if (khz == 0) {
LOG_ERROR("RCLK not supported");
return ERROR_FAIL;
}
- for (i = rlink_speed_table_size; i--;) {
+ for (i = rlink_speed_table_size; i--; ) {
if (rlink_speed_table[i].khz <= khz) {
*speed = rlink_speed_table[i].prescaler;
- return(ERROR_OK);
+ return ERROR_OK;
}
}
LOG_WARNING("The lowest supported JTAG speed is %d KHz", rlink_speed_table[0].khz);
*speed = rlink_speed_table[0].prescaler;
- return(ERROR_OK);
+ return ERROR_OK;
}
-
-static
-int rlink_init(void)
+static int rlink_init(void)
{
int i, j, retries;
uint8_t reply_buffer[USB_EP1IN_SIZE];
return ERROR_FAIL;
struct usb_device *dev = usb_device(pHDev);
- if (dev->descriptor.bNumConfigurations > 1)
- {
+ if (dev->descriptor.bNumConfigurations > 1) {
LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...");
return ERROR_FAIL;
}
- if (dev->config->bNumInterfaces > 1)
- {
+ if (dev->config->bNumInterfaces > 1) {
LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...");
return ERROR_FAIL;
}
usb_set_configuration(pHDev, dev->config[0].bConfigurationValue);
retries = 3;
- do
- {
- i = usb_claim_interface(pHDev,0);
- if (i)
- {
+ do {
+ i = usb_claim_interface(pHDev, 0);
+ if (i) {
LOG_ERROR("usb_claim_interface: %s", usb_strerror());
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
j = usb_detach_kernel_driver_np(pHDev, 0);
if (j)
LOG_ERROR("detach kernel driver: %s", usb_strerror());
#endif
- }
- else
- {
+ } else {
LOG_DEBUG("interface claimed!");
break;
}
} while (--retries);
- if (i)
- {
+ if (i) {
LOG_ERROR("Initialisation failed.");
return ERROR_FAIL;
}
- if (usb_set_altinterface(pHDev,0) != 0)
- {
+ if (usb_set_altinterface(pHDev, 0) != 0) {
LOG_ERROR("Failed to set interface.");
return ERROR_FAIL;
}
j = ep1_generic_commandl(
pHDev, 1,
EP1_CMD_GET_FWREV
- );
+ );
if (j < USB_EP1OUT_SIZE) {
LOG_ERROR("USB write error: %s", usb_strerror());
- return(ERROR_FAIL);
+ return ERROR_FAIL;
}
j = usb_bulk_read(
pHDev, USB_EP1IN_ADDR,
(char *)reply_buffer, sizeof(reply_buffer),
200
- );
- if (j != -ETIMEDOUT) break;
+ );
+ if (j != -ETIMEDOUT)
+ break;
}
if (j < (int)sizeof(reply_buffer)) {
LOG_ERROR("USB read error: %s", usb_strerror());
- return(ERROR_FAIL);
+ return ERROR_FAIL;
}
- LOG_DEBUG(INTERFACE_NAME" firmware version: %d.%d.%d", reply_buffer[0], reply_buffer[1], reply_buffer[2]);
+ LOG_DEBUG(INTERFACE_NAME " firmware version: %d.%d.%d",
+ reply_buffer[0],
+ reply_buffer[1],
+ reply_buffer[2]);
- if ((reply_buffer[0] != 0) || (reply_buffer[1] != 0) || (reply_buffer[2] != 3)) {
- LOG_WARNING("The rlink device is not of the version that the developers have played with. It may or may not work.");
- }
+ if ((reply_buffer[0] != 0) || (reply_buffer[1] != 0) || (reply_buffer[2] != 3))
+ LOG_WARNING(
+ "The rlink device is not of the version that the developers have played with. It may or may not work.");
/* Probe port E for adapter presence */
ep1_generic_commandl(
- pHDev, 16,
- EP1_CMD_MEMORY_WRITE, /* Drive sense pin with 0 */
- ST7_PEDR >> 8,
- ST7_PEDR,
- 3,
- 0x00, /* DR */
- ST7_PE_ADAPTER_SENSE_OUT, /* DDR */
- ST7_PE_ADAPTER_SENSE_OUT, /* OR */
- EP1_CMD_MEMORY_READ, /* Read back */
- ST7_PEDR >> 8,
- ST7_PEDR,
- 1,
- EP1_CMD_MEMORY_WRITE, /* Drive sense pin with 1 */
- ST7_PEDR >> 8,
- ST7_PEDR,
- 1,
- ST7_PE_ADAPTER_SENSE_OUT
- );
+ pHDev, 16,
+ EP1_CMD_MEMORY_WRITE, /* Drive sense pin with 0 */
+ ST7_PEDR >> 8,
+ ST7_PEDR,
+ 3,
+ 0x00, /* DR */
+ ST7_PE_ADAPTER_SENSE_OUT, /* DDR */
+ ST7_PE_ADAPTER_SENSE_OUT, /* OR */
+ EP1_CMD_MEMORY_READ, /* Read back */
+ ST7_PEDR >> 8,
+ ST7_PEDR,
+ 1,
+ EP1_CMD_MEMORY_WRITE, /* Drive sense pin with 1 */
+ ST7_PEDR >> 8,
+ ST7_PEDR,
+ 1,
+ ST7_PE_ADAPTER_SENSE_OUT
+ );
usb_bulk_read(
- pHDev, USB_EP1IN_ADDR,
- (char *)reply_buffer, 1,
- USB_TIMEOUT_MS
- );
+ pHDev, USB_EP1IN_ADDR,
+ (char *)reply_buffer, 1,
+ USB_TIMEOUT_MS
+ );
- if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) != 0) {
+ if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) != 0)
LOG_WARNING("target detection problem");
- }
ep1_generic_commandl(
- pHDev, 11,
- EP1_CMD_MEMORY_READ, /* Read back */
- ST7_PEDR >> 8,
- ST7_PEDR,
- 1,
- EP1_CMD_MEMORY_WRITE, /* float port E */
- ST7_PEDR >> 8,
- ST7_PEDR,
- 3,
- 0x00, /* DR */
- 0x00, /* DDR */
- 0x00 /* OR */
- );
+ pHDev, 11,
+ EP1_CMD_MEMORY_READ, /* Read back */
+ ST7_PEDR >> 8,
+ ST7_PEDR,
+ 1,
+ EP1_CMD_MEMORY_WRITE, /* float port E */
+ ST7_PEDR >> 8,
+ ST7_PEDR,
+ 3,
+ 0x00, /* DR */
+ 0x00, /* DDR */
+ 0x00 /* OR */
+ );
usb_bulk_read(
- pHDev, USB_EP1IN_ADDR,
- (char *)reply_buffer, 1,
- USB_TIMEOUT_MS
- );
+ pHDev, USB_EP1IN_ADDR,
+ (char *)reply_buffer, 1,
+ USB_TIMEOUT_MS
+ );
- if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) == 0) {
+ if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) == 0)
LOG_WARNING("target not plugged in");
- }
/* float ports A and B */
ep1_generic_commandl(
- pHDev, 11,
- EP1_CMD_MEMORY_WRITE,
- ST7_PADDR >> 8,
- ST7_PADDR,
- 2,
- 0x00,
- 0x00,
- EP1_CMD_MEMORY_WRITE,
- ST7_PBDDR >> 8,
- ST7_PBDDR,
- 1,
- 0x00
- );
+ pHDev, 11,
+ EP1_CMD_MEMORY_WRITE,
+ ST7_PADDR >> 8,
+ ST7_PADDR,
+ 2,
+ 0x00,
+ 0x00,
+ EP1_CMD_MEMORY_WRITE,
+ ST7_PBDDR >> 8,
+ ST7_PBDDR,
+ 1,
+ 0x00
+ );
/* make sure DTC is stopped, set VPP control, set up ports A and B */
ep1_generic_commandl(
- pHDev, 14,
- EP1_CMD_DTC_STOP,
- EP1_CMD_SET_PORTD_VPP,
- ~(ST7_PD_VPP_SHDN),
- EP1_CMD_MEMORY_WRITE,
- ST7_PADR >> 8,
- ST7_PADR,
- 2,
- ((~(0)) & (ST7_PA_NTRST)),
- (ST7_PA_NTRST),
- /* port B has no OR, and we want to emulate open drain on NSRST, so we set DR to 0 here and later assert NSRST by setting DDR bit to 1. */
- EP1_CMD_MEMORY_WRITE,
- ST7_PBDR >> 8,
- ST7_PBDR,
- 1,
- 0x00
- );
+ pHDev, 14,
+ EP1_CMD_DTC_STOP,
+ EP1_CMD_SET_PORTD_VPP,
+ ~(ST7_PD_VPP_SHDN),
+ EP1_CMD_MEMORY_WRITE,
+ ST7_PADR >> 8,
+ ST7_PADR,
+ 2,
+ ((~(0)) & (ST7_PA_NTRST)),
+ (ST7_PA_NTRST),
+ /* port B has no OR, and we want to emulate open drain on NSRST, so we set DR to 0
+ *here and later assert NSRST by setting DDR bit to 1. */
+ EP1_CMD_MEMORY_WRITE,
+ ST7_PBDR >> 8,
+ ST7_PBDR,
+ 1,
+ 0x00
+ );
/* set LED updating mode and make sure they're unlit */
ep1_generic_commandl(
- pHDev, 3,
+ pHDev, 3,
#ifdef AUTOMATIC_BUSY_LED
- EP1_CMD_LEDUE_BUSY,
+ EP1_CMD_LEDUE_BUSY,
#else
- EP1_CMD_LEDUE_NONE,
+ EP1_CMD_LEDUE_NONE,
#endif
- EP1_CMD_SET_PORTD_LEDS,
- ~0
- );
+ EP1_CMD_SET_PORTD_LEDS,
+ ~0
+ );
tap_state_queue_init();
dtc_queue_init();
return ERROR_OK;
}
-
-static
-int rlink_quit(void)
+static int rlink_quit(void)
{
/* stop DTC and make sure LEDs are off */
ep1_generic_commandl(
- pHDev, 6,
- EP1_CMD_DTC_STOP,
- EP1_CMD_LEDUE_NONE,
- EP1_CMD_SET_PORTD_LEDS,
- ~0,
- EP1_CMD_SET_PORTD_VPP,
- ~0
- );
-
- usb_release_interface(pHDev,0);
- usb_close(pHDev);
+ pHDev, 6,
+ EP1_CMD_DTC_STOP,
+ EP1_CMD_LEDUE_NONE,
+ EP1_CMD_SET_PORTD_LEDS,
+ ~0,
+ EP1_CMD_SET_PORTD_VPP,
+ ~0
+ );
+ usb_release_interface(pHDev, 0);
+ usb_close(pHDev);
return ERROR_OK;
}
-
-struct jtag_interface rlink_interface =
-{
- .name = "rlink",
- .init = rlink_init,
- .quit = rlink_quit,
- .speed = rlink_speed,
- .speed_div = rlink_speed_div,
- .khz = rlink_khz,
- .execute_queue = rlink_execute_queue,
+struct jtag_interface rlink_interface = {
+ .name = "rlink",
+ .init = rlink_init,
+ .quit = rlink_quit,
+ .speed = rlink_speed,
+ .speed_div = rlink_speed_div,
+ .khz = rlink_khz,
+ .execute_queue = rlink_execute_queue,
};
* 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. */
) | (\
(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. */
/* 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. */
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);
+/***************************************************************************
+ * 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_ */
#define SPLIT_SCAN_THRESHOLD 10
/** ULINK hardware type */
-enum ulink_type
-{
- /** Original ULINK adapter, based on Cypress EZ-USB (AN2131):
- * Full JTAG support, no SWD support. */
- ULINK_1,
+enum ulink_type {
+ /** Original ULINK adapter, based on Cypress EZ-USB (AN2131):
+ * Full JTAG support, no SWD support. */
+ ULINK_1,
- /** Newer ULINK adapter, based on NXP LPC2148. Currently unsupported. */
- ULINK_2,
+ /** Newer ULINK adapter, based on NXP LPC2148. Currently unsupported. */
+ ULINK_2,
- /** Newer ULINK adapter, based on EZ-USB FX2 + FPGA. Currently unsupported. */
- ULINK_PRO,
+ /** Newer ULINK adapter, based on EZ-USB FX2 + FPGA. Currently unsupported. */
+ ULINK_PRO,
- /** Newer ULINK adapter, possibly based on ULINK 2. Currently unsupported. */
- ULINK_ME
+ /** Newer ULINK adapter, possibly based on ULINK 2. Currently unsupported. */
+ ULINK_ME
};
-enum ulink_payload_direction
-{
- PAYLOAD_DIRECTION_OUT,
- PAYLOAD_DIRECTION_IN
+enum ulink_payload_direction {
+ PAYLOAD_DIRECTION_OUT,
+ PAYLOAD_DIRECTION_IN
};
-enum ulink_delay_type
-{
- DELAY_CLOCK_TCK,
- DELAY_CLOCK_TMS,
- DELAY_SCAN_IN,
- DELAY_SCAN_OUT,
- DELAY_SCAN_IO
+enum ulink_delay_type {
+ DELAY_CLOCK_TCK,
+ DELAY_CLOCK_TMS,
+ DELAY_SCAN_IN,
+ DELAY_SCAN_OUT,
+ DELAY_SCAN_IO
};
/**
* The last command sets #needs_postprocessing to true.
*/
struct ulink_cmd {
- uint8_t id; ///< ULINK command ID
+ uint8_t id; /* /< ULINK command ID */
- uint8_t *payload_out; ///< OUT direction payload data
- uint8_t payload_out_size; ///< OUT direction payload size for this command
+ uint8_t *payload_out; /* /< OUT direction payload data */
+ uint8_t payload_out_size; /* /< OUT direction payload size for this command */
- uint8_t *payload_in_start; ///< Pointer to first element of IN payload array
- uint8_t *payload_in; ///< Pointer where IN payload shall be stored
- uint8_t payload_in_size; ///< IN direction payload size for this command
+ uint8_t *payload_in_start; /* /< Pointer to first element of IN payload array */
+ uint8_t *payload_in; /* /< Pointer where IN payload shall be stored */
+ uint8_t payload_in_size;/* /< IN direction payload size for this command */
- /** Indicates if this command needs post-processing */
- bool needs_postprocessing;
+ /** Indicates if this command needs post-processing */
+ bool needs_postprocessing;
- /** Indicates if ulink_clear_queue() should free payload_in_start */
- bool free_payload_in_start;
+ /** Indicates if ulink_clear_queue() should free payload_in_start */
+ bool free_payload_in_start;
- /** Pointer to corresponding OpenOCD command for post-processing */
- struct jtag_command *cmd_origin;
+ /** Pointer to corresponding OpenOCD command for post-processing */
+ struct jtag_command *cmd_origin;
- struct ulink_cmd *next; ///< Pointer to next command (linked list)
+ struct ulink_cmd *next; /* /< Pointer to next command (linked list) */
};
/** Describes one driver instance */
-struct ulink
-{
- struct usb_dev_handle *usb_handle;
- enum ulink_type type;
-
- int delay_scan_in; ///< Delay value for SCAN_IN commands
- int delay_scan_out; ///< Delay value for SCAN_OUT commands
- int delay_scan_io; ///< Delay value for SCAN_IO commands
- int delay_clock_tck; ///< Delay value for CLOCK_TMS commands
- int delay_clock_tms; ///< Delay value for CLOCK_TCK commands
-
- int commands_in_queue; ///< Number of commands in queue
- struct ulink_cmd *queue_start; ///< Pointer to first command in queue
- struct ulink_cmd *queue_end; ///< Pointer to last command in queue
+struct ulink {
+ struct usb_dev_handle *usb_handle;
+ enum ulink_type type;
+
+ int delay_scan_in; /* /< Delay value for SCAN_IN commands */
+ int delay_scan_out; /* /< Delay value for SCAN_OUT commands */
+ int delay_scan_io; /* /< Delay value for SCAN_IO commands */
+ int delay_clock_tck; /* /< Delay value for CLOCK_TMS commands */
+ int delay_clock_tms; /* /< Delay value for CLOCK_TCK commands */
+
+ int commands_in_queue; /* /< Number of commands in queue */
+ struct ulink_cmd *queue_start; /* /< Pointer to first command in queue */
+ struct ulink_cmd *queue_end; /* /< Pointer to last command in queue */
};
/**************************** Function Prototypes *****************************/
/* ULINK MCU (Cypress EZ-USB) specific functions */
int ulink_cpu_reset(struct ulink *device, char reset_bit);
int ulink_load_firmware_and_renumerate(struct ulink **device, char *filename,
- uint32_t delay);
+ uint32_t delay);
int ulink_load_firmware(struct ulink *device, char *filename);
int ulink_write_firmware_section(struct ulink *device,
- struct image *firmware_image, int section_index);
+ struct image *firmware_image, int section_index);
/* Generic helper functions */
void ulink_print_signal_states(uint8_t input_signals, uint8_t output_signals);
/* OpenULINK command generation helper functions */
int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size,
- enum ulink_payload_direction direction);
+ enum ulink_payload_direction direction);
/* OpenULINK command queue helper functions */
int ulink_get_queue_size(struct ulink *device,
- enum ulink_payload_direction direction);
+ enum ulink_payload_direction direction);
void ulink_clear_queue(struct ulink *device);
int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd);
int ulink_execute_queued_commands(struct ulink *device, int timeout);
#ifdef _DEBUG_JTAG_IO_
-const char * ulink_cmd_id_string(uint8_t id);
+const char *ulink_cmd_id_string(uint8_t id);
void ulink_print_command(struct ulink_cmd *ulink_cmd);
void ulink_print_queue(struct ulink *device);
#endif
-int ulink_append_scan_cmd(struct ulink *device, enum scan_type scan_type,
- int scan_size_bits, uint8_t *tdi, uint8_t *tdo_start, uint8_t *tdo,
- uint8_t tms_count_start, uint8_t tms_sequence_start, uint8_t tms_count_end,
- uint8_t tms_sequence_end, struct jtag_command *origin, bool postprocess);
+int ulink_append_scan_cmd(struct ulink *device,
+ enum scan_type scan_type,
+ int scan_size_bits,
+ uint8_t *tdi,
+ uint8_t *tdo_start,
+ uint8_t *tdo,
+ uint8_t tms_count_start,
+ uint8_t tms_sequence_start,
+ uint8_t tms_count_end,
+ uint8_t tms_sequence_end,
+ struct jtag_command *origin,
+ bool postprocess);
int ulink_append_clock_tms_cmd(struct ulink *device, uint8_t count,
- uint8_t sequence);
+ uint8_t sequence);
int ulink_append_clock_tck_cmd(struct ulink *device, uint16_t count);
int ulink_append_get_signals_cmd(struct ulink *device);
int ulink_append_set_signals_cmd(struct ulink *device, uint8_t low,
- uint8_t high);
+ uint8_t high);
int ulink_append_sleep_cmd(struct ulink *device, uint32_t us);
-int ulink_append_configure_tck_cmd(struct ulink *device, int delay_scan_in,
- int delay_scan_out, int delay_scan_io, int delay_tck, int delay_tms);
+int ulink_append_configure_tck_cmd(struct ulink *device,
+ int delay_scan_in,
+ int delay_scan_out,
+ int delay_scan_io,
+ int delay_tck,
+ int delay_tms);
int ulink_append_led_cmd(struct ulink *device, uint8_t led_state);
int ulink_append_test_cmd(struct ulink *device);
*/
int ulink_usb_open(struct ulink **device)
{
- int ret;
- struct usb_dev_handle *usb_handle;
+ int ret;
+ struct usb_dev_handle *usb_handle;
- /* Currently, only original ULINK is supported */
- uint16_t vids[] = { ULINK_VID, 0 };
- uint16_t pids[] = { ULINK_PID, 0 };
+ /* Currently, only original ULINK is supported */
+ uint16_t vids[] = { ULINK_VID, 0 };
+ uint16_t pids[] = { ULINK_PID, 0 };
- ret = jtag_usb_open(vids, pids, &usb_handle);
+ ret = jtag_usb_open(vids, pids, &usb_handle);
- if (ret != ERROR_OK) {
- return ret;
- }
+ if (ret != ERROR_OK)
+ return ret;
- ret = usb_claim_interface(usb_handle, 0);
+ ret = usb_claim_interface(usb_handle, 0);
- if (ret != 0) {
- return ret;
- }
+ if (ret != 0)
+ return ret;
- (*device)->usb_handle = usb_handle;
- (*device)->type = ULINK_1;
+ (*device)->usb_handle = usb_handle;
+ (*device)->type = ULINK_1;
- return ERROR_OK;
+ return ERROR_OK;
}
/**
*/
int ulink_usb_close(struct ulink **device)
{
- if (usb_release_interface((*device)->usb_handle, 0) != 0) {
- return ERROR_FAIL;
- }
+ if (usb_release_interface((*device)->usb_handle, 0) != 0)
+ return ERROR_FAIL;
- if (usb_close((*device)->usb_handle) != 0) {
- return ERROR_FAIL;
- }
+ if (usb_close((*device)->usb_handle) != 0)
+ return ERROR_FAIL;
- (*device)->usb_handle = NULL;
+ (*device)->usb_handle = NULL;
- return ERROR_OK;
+ return ERROR_OK;
}
/******************* ULINK CPU (EZ-USB) specific functions ********************/
*/
int ulink_cpu_reset(struct ulink *device, char reset_bit)
{
- int ret;
-
- ret = usb_control_msg(device->usb_handle,
- (USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE),
- REQUEST_FIRMWARE_LOAD, CPUCS_REG, 0, &reset_bit, 1, USB_TIMEOUT);
-
- /* usb_control_msg() returns the number of bytes transferred during the
- * DATA stage of the control transfer - must be exactly 1 in this case! */
- if (ret != 1) {
- return ERROR_FAIL;
- }
- return ERROR_OK;
+ int ret;
+
+ ret = usb_control_msg(device->usb_handle,
+ (USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE),
+ REQUEST_FIRMWARE_LOAD, CPUCS_REG, 0, &reset_bit, 1, USB_TIMEOUT);
+
+ /* usb_control_msg() returns the number of bytes transferred during the
+ * DATA stage of the control transfer - must be exactly 1 in this case! */
+ if (ret != 1)
+ return ERROR_FAIL;
+ return ERROR_OK;
}
/**
* @return on failure: ERROR_FAIL
*/
int ulink_load_firmware_and_renumerate(struct ulink **device,
- char *filename, uint32_t delay)
+ char *filename, uint32_t delay)
{
- int ret;
+ int ret;
- /* Basic process: After downloading the firmware, the ULINK will disconnect
- * itself and re-connect after a short amount of time so we have to close
- * the handle and re-enumerate USB devices */
+ /* Basic process: After downloading the firmware, the ULINK will disconnect
+ * itself and re-connect after a short amount of time so we have to close
+ * the handle and re-enumerate USB devices */
- ret = ulink_load_firmware(*device, filename);
- if (ret != ERROR_OK) {
- return ret;
- }
+ ret = ulink_load_firmware(*device, filename);
+ if (ret != ERROR_OK)
+ return ret;
- ret = ulink_usb_close(device);
- if (ret != ERROR_OK) {
- return ret;
- }
+ ret = ulink_usb_close(device);
+ if (ret != ERROR_OK)
+ return ret;
- usleep(delay);
+ usleep(delay);
- ret = ulink_usb_open(device);
- if (ret != ERROR_OK) {
- return ret;
- }
+ ret = ulink_usb_open(device);
+ if (ret != ERROR_OK)
+ return ret;
- return ERROR_OK;
+ return ERROR_OK;
}
/**
*/
int ulink_load_firmware(struct ulink *device, char *filename)
{
- struct image ulink_firmware_image;
- int ret, i;
-
- ret = ulink_cpu_reset(device, CPU_RESET);
- if (ret != ERROR_OK) {
- LOG_ERROR("Could not halt ULINK CPU");
- return ret;
- }
-
- ulink_firmware_image.base_address = 0;
- ulink_firmware_image.base_address_set = 0;
-
- ret = image_open(&ulink_firmware_image, filename, "ihex");
- if (ret != ERROR_OK) {
- LOG_ERROR("Could not load firmware image");
- return ret;
- }
-
- /* Download all sections in the image to ULINK */
- for (i = 0; i < ulink_firmware_image.num_sections; i++) {
- ret = ulink_write_firmware_section(device, &ulink_firmware_image, i);
- if (ret != ERROR_OK) {
- return ret;
- }
- }
-
- image_close(&ulink_firmware_image);
-
- ret = ulink_cpu_reset(device, CPU_START);
- if (ret != ERROR_OK) {
- LOG_ERROR("Could not restart ULINK CPU");
- return ret;
- }
-
- return ERROR_OK;
+ struct image ulink_firmware_image;
+ int ret, i;
+
+ ret = ulink_cpu_reset(device, CPU_RESET);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not halt ULINK CPU");
+ return ret;
+ }
+
+ ulink_firmware_image.base_address = 0;
+ ulink_firmware_image.base_address_set = 0;
+
+ ret = image_open(&ulink_firmware_image, filename, "ihex");
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not load firmware image");
+ return ret;
+ }
+
+ /* Download all sections in the image to ULINK */
+ for (i = 0; i < ulink_firmware_image.num_sections; i++) {
+ ret = ulink_write_firmware_section(device, &ulink_firmware_image, i);
+ if (ret != ERROR_OK)
+ return ret;
+ }
+
+ image_close(&ulink_firmware_image);
+
+ ret = ulink_cpu_reset(device, CPU_START);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not restart ULINK CPU");
+ return ret;
+ }
+
+ return ERROR_OK;
}
/**
* @return on failure: ERROR_FAIL
*/
int ulink_write_firmware_section(struct ulink *device,
- struct image *firmware_image, int section_index)
+ struct image *firmware_image, int section_index)
{
- uint16_t addr, size, bytes_remaining, chunk_size;
- uint8_t data[SECTION_BUFFERSIZE];
- uint8_t *data_ptr = data;
- size_t size_read;
- int ret;
-
- size = (uint16_t)firmware_image->sections[section_index].size;
- addr = (uint16_t)firmware_image->sections[section_index].base_address;
-
- LOG_DEBUG("section %02i at addr 0x%04x (size 0x%04x)", section_index, addr,
- size);
-
- if (data == NULL) {
- return ERROR_FAIL;
- }
-
- /* Copy section contents to local buffer */
- ret = image_read_section(firmware_image, section_index, 0, size, data,
- &size_read);
-
- if ((ret != ERROR_OK) || (size_read != size)) {
- /* Propagating the return code would return '0' (misleadingly indicating
- * successful execution of the function) if only the size check fails. */
- return ERROR_FAIL;
- }
-
- bytes_remaining = size;
-
- /* Send section data in chunks of up to 64 bytes to ULINK */
- while (bytes_remaining > 0) {
- if (bytes_remaining > 64) {
- chunk_size = 64;
- }
- else {
- chunk_size = bytes_remaining;
- }
-
- ret = usb_control_msg(device->usb_handle,
- (USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE),
- REQUEST_FIRMWARE_LOAD, addr, FIRMWARE_ADDR, (char *)data_ptr,
- chunk_size, USB_TIMEOUT);
-
- if (ret != (int)chunk_size) {
- /* Abort if libusb sent less data than requested */
- return ERROR_FAIL;
- }
-
- bytes_remaining -= chunk_size;
- addr += chunk_size;
- data_ptr += chunk_size;
- }
-
- return ERROR_OK;
+ uint16_t addr, size, bytes_remaining, chunk_size;
+ uint8_t data[SECTION_BUFFERSIZE];
+ uint8_t *data_ptr = data;
+ size_t size_read;
+ int ret;
+
+ size = (uint16_t)firmware_image->sections[section_index].size;
+ addr = (uint16_t)firmware_image->sections[section_index].base_address;
+
+ LOG_DEBUG("section %02i at addr 0x%04x (size 0x%04x)", section_index, addr,
+ size);
+
+ if (data == NULL)
+ return ERROR_FAIL;
+
+ /* Copy section contents to local buffer */
+ ret = image_read_section(firmware_image, section_index, 0, size, data,
+ &size_read);
+
+ if ((ret != ERROR_OK) || (size_read != size)) {
+ /* Propagating the return code would return '0' (misleadingly indicating
+ * successful execution of the function) if only the size check fails. */
+ return ERROR_FAIL;
+ }
+
+ bytes_remaining = size;
+
+ /* Send section data in chunks of up to 64 bytes to ULINK */
+ while (bytes_remaining > 0) {
+ if (bytes_remaining > 64)
+ chunk_size = 64;
+ else
+ chunk_size = bytes_remaining;
+
+ ret = usb_control_msg(device->usb_handle,
+ (USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE),
+ REQUEST_FIRMWARE_LOAD, addr, FIRMWARE_ADDR, (char *)data_ptr,
+ chunk_size, USB_TIMEOUT);
+
+ if (ret != (int)chunk_size) {
+ /* Abort if libusb sent less data than requested */
+ return ERROR_FAIL;
+ }
+
+ bytes_remaining -= chunk_size;
+ addr += chunk_size;
+ data_ptr += chunk_size;
+ }
+
+ return ERROR_OK;
}
/************************** Generic helper functions **************************/
*/
void ulink_print_signal_states(uint8_t input_signals, uint8_t output_signals)
{
- LOG_INFO("ULINK signal states: TDI: %i, TDO: %i, TMS: %i, TCK: %i, TRST: %i,"
- " SRST: %i",
- (output_signals & SIGNAL_TDI ? 1 : 0),
- (input_signals & SIGNAL_TDO ? 1 : 0),
- (output_signals & SIGNAL_TMS ? 1 : 0),
- (output_signals & SIGNAL_TCK ? 1 : 0),
- (output_signals & SIGNAL_TRST ? 0 : 1), // TRST and RESET are inverted
- (output_signals & SIGNAL_RESET ? 0 : 1)); // by hardware
+ LOG_INFO("ULINK signal states: TDI: %i, TDO: %i, TMS: %i, TCK: %i, TRST: %i,"
+ " SRST: %i",
+ (output_signals & SIGNAL_TDI ? 1 : 0),
+ (input_signals & SIGNAL_TDO ? 1 : 0),
+ (output_signals & SIGNAL_TMS ? 1 : 0),
+ (output_signals & SIGNAL_TCK ? 1 : 0),
+ (output_signals & SIGNAL_TRST ? 0 : 1),/* TRST and RESET are inverted */
+ (output_signals & SIGNAL_RESET ? 0 : 1)); /* by hardware */
}
/**************** OpenULINK command generation helper functions ***************/
* @return on failure: ERROR_FAIL
*/
int ulink_allocate_payload(struct ulink_cmd *ulink_cmd, int size,
- enum ulink_payload_direction direction)
+ enum ulink_payload_direction direction)
{
- uint8_t *payload;
-
- payload = calloc(size, sizeof(uint8_t));
-
- if (payload == NULL) {
- LOG_ERROR("Could not allocate OpenULINK command payload: out of memory");
- return ERROR_FAIL;
- }
-
- switch (direction) {
- case PAYLOAD_DIRECTION_OUT:
- if (ulink_cmd->payload_out != NULL) {
- LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
- return ERROR_FAIL;
- }
- else {
- ulink_cmd->payload_out = payload;
- ulink_cmd->payload_out_size = size;
- }
- break;
- case PAYLOAD_DIRECTION_IN:
- if (ulink_cmd->payload_in_start != NULL) {
- LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
- return ERROR_FAIL;
- }
- else {
- ulink_cmd->payload_in_start = payload;
- ulink_cmd->payload_in = payload;
- ulink_cmd->payload_in_size = size;
-
- /* By default, free payload_in_start in ulink_clear_queue(). Commands
- * that do not want this behavior (e. g. split scans) must turn it off
- * separately! */
- ulink_cmd->free_payload_in_start = true;
- }
- break;
- }
-
- return ERROR_OK;
+ uint8_t *payload;
+
+ payload = calloc(size, sizeof(uint8_t));
+
+ if (payload == NULL) {
+ LOG_ERROR("Could not allocate OpenULINK command payload: out of memory");
+ return ERROR_FAIL;
+ }
+
+ switch (direction) {
+ case PAYLOAD_DIRECTION_OUT:
+ if (ulink_cmd->payload_out != NULL) {
+ LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
+ return ERROR_FAIL;
+ } else {
+ ulink_cmd->payload_out = payload;
+ ulink_cmd->payload_out_size = size;
+ }
+ break;
+ case PAYLOAD_DIRECTION_IN:
+ if (ulink_cmd->payload_in_start != NULL) {
+ LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
+ return ERROR_FAIL;
+ } else {
+ ulink_cmd->payload_in_start = payload;
+ ulink_cmd->payload_in = payload;
+ ulink_cmd->payload_in_size = size;
+
+ /* By default, free payload_in_start in ulink_clear_queue(). Commands
+ * that do not want this behavior (e. g. split scans) must turn it off
+ * separately! */
+ ulink_cmd->free_payload_in_start = true;
+ }
+ break;
+ }
+
+ return ERROR_OK;
}
/****************** OpenULINK command queue helper functions ******************/
* direction.
*/
int ulink_get_queue_size(struct ulink *device,
- enum ulink_payload_direction direction)
+ enum ulink_payload_direction direction)
{
- struct ulink_cmd *current = device->queue_start;
- int sum = 0;
-
- while (current != NULL) {
- switch (direction) {
- case PAYLOAD_DIRECTION_OUT:
- sum += current->payload_out_size + 1; // + 1 byte for Command ID
- break;
- case PAYLOAD_DIRECTION_IN:
- sum += current->payload_in_size;
- break;
- }
-
- current = current->next;
- }
-
- return sum;
+ struct ulink_cmd *current = device->queue_start;
+ int sum = 0;
+
+ while (current != NULL) {
+ switch (direction) {
+ case PAYLOAD_DIRECTION_OUT:
+ sum += current->payload_out_size + 1; /* + 1 byte for Command ID */
+ break;
+ case PAYLOAD_DIRECTION_IN:
+ sum += current->payload_in_size;
+ break;
+ }
+
+ current = current->next;
+ }
+
+ return sum;
}
/**
*/
void ulink_clear_queue(struct ulink *device)
{
- struct ulink_cmd *current = device->queue_start;
- struct ulink_cmd *next = NULL;
-
- while (current != NULL) {
- /* Save pointer to next element */
- next = current->next;
-
- /* Free payloads: OUT payload can be freed immediately */
- free(current->payload_out);
- current->payload_out = NULL;
-
- /* IN payload MUST be freed ONLY if no other commands use the
- * payload_in_start buffer */
- if (current->free_payload_in_start == true) {
- free(current->payload_in_start);
- current->payload_in_start = NULL;
- current->payload_in = NULL;
- }
-
- /* Free queue element */
- free(current);
-
- /* Proceed with next element */
- current = next;
- }
-
- device->commands_in_queue = 0;
- device->queue_start = NULL;
- device->queue_end = NULL;
+ struct ulink_cmd *current = device->queue_start;
+ struct ulink_cmd *next = NULL;
+
+ while (current != NULL) {
+ /* Save pointer to next element */
+ next = current->next;
+
+ /* Free payloads: OUT payload can be freed immediately */
+ free(current->payload_out);
+ current->payload_out = NULL;
+
+ /* IN payload MUST be freed ONLY if no other commands use the
+ * payload_in_start buffer */
+ if (current->free_payload_in_start == true) {
+ free(current->payload_in_start);
+ current->payload_in_start = NULL;
+ current->payload_in = NULL;
+ }
+
+ /* Free queue element */
+ free(current);
+
+ /* Proceed with next element */
+ current = next;
+ }
+
+ device->commands_in_queue = 0;
+ device->queue_start = NULL;
+ device->queue_end = NULL;
}
/**
*/
int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd)
{
- int newsize_out, newsize_in;
- int ret;
-
- newsize_out = ulink_get_queue_size(device, PAYLOAD_DIRECTION_OUT) + 1
- + ulink_cmd->payload_out_size;
-
- newsize_in = ulink_get_queue_size(device, PAYLOAD_DIRECTION_IN)
- + ulink_cmd->payload_in_size;
-
- /* Check if the current command can be appended to the queue */
- if ((newsize_out > 64) || (newsize_in > 64)) {
- /* New command does not fit. Execute all commands in queue before starting
- * new queue with the current command as first entry. */
- ret = ulink_execute_queued_commands(device, USB_TIMEOUT);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ret = ulink_post_process_queue(device);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ulink_clear_queue(device);
- }
-
- if (device->queue_start == NULL) {
- /* Queue was empty */
- device->commands_in_queue = 1;
-
- device->queue_start = ulink_cmd;
- device->queue_end = ulink_cmd;
- }
- else {
- /* There are already commands in the queue */
- device->commands_in_queue++;
-
- device->queue_end->next = ulink_cmd;
- device->queue_end = ulink_cmd;
- }
-
- return ERROR_OK;
+ int newsize_out, newsize_in;
+ int ret;
+
+ newsize_out = ulink_get_queue_size(device, PAYLOAD_DIRECTION_OUT) + 1
+ + ulink_cmd->payload_out_size;
+
+ newsize_in = ulink_get_queue_size(device, PAYLOAD_DIRECTION_IN)
+ + ulink_cmd->payload_in_size;
+
+ /* Check if the current command can be appended to the queue */
+ if ((newsize_out > 64) || (newsize_in > 64)) {
+ /* New command does not fit. Execute all commands in queue before starting
+ * new queue with the current command as first entry. */
+ ret = ulink_execute_queued_commands(device, USB_TIMEOUT);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = ulink_post_process_queue(device);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ulink_clear_queue(device);
+ }
+
+ if (device->queue_start == NULL) {
+ /* Queue was empty */
+ device->commands_in_queue = 1;
+
+ device->queue_start = ulink_cmd;
+ device->queue_end = ulink_cmd;
+ } else {
+ /* There are already commands in the queue */
+ device->commands_in_queue++;
+
+ device->queue_end->next = ulink_cmd;
+ device->queue_end = ulink_cmd;
+ }
+
+ return ERROR_OK;
}
/**
*/
int ulink_execute_queued_commands(struct ulink *device, int timeout)
{
- struct ulink_cmd *current;
- int ret, i, index_out, index_in, count_out, count_in;
- uint8_t buffer[64];
+ struct ulink_cmd *current;
+ int ret, i, index_out, index_in, count_out, count_in;
+ uint8_t buffer[64];
#ifdef _DEBUG_JTAG_IO_
- ulink_print_queue(device);
+ ulink_print_queue(device);
#endif
- index_out = 0;
- count_out = 0;
- count_in = 0;
-
- for (current = device->queue_start; current; current = current->next) {
- /* Add command to packet */
- buffer[index_out] = current->id;
- index_out++;
- count_out++;
-
- for (i = 0; i < current->payload_out_size; i++) {
- buffer[index_out + i] = current->payload_out[i];
- }
- index_out += current->payload_out_size;
- count_in += current->payload_in_size;
- count_out += current->payload_out_size;
- }
-
- /* Send packet to ULINK */
- ret = usb_bulk_write(device->usb_handle, (2 | USB_ENDPOINT_OUT),
- (char *)buffer, count_out, timeout);
- if (ret < 0) {
- return ERROR_FAIL;
- }
- if (ret != count_out) {
- return ERROR_FAIL;
- }
-
- /* Wait for response if commands contain IN payload data */
- if (count_in > 0) {
- ret = usb_bulk_read(device->usb_handle, (2 | USB_ENDPOINT_IN),
- (char *)buffer, 64, timeout);
- if (ret < 0) {
- return ERROR_FAIL;
- }
- if (ret != count_in) {
- return ERROR_FAIL;
- }
-
- /* Write back IN payload data */
- index_in = 0;
- for (current = device->queue_start; current; current = current->next) {
- for (i = 0; i < current->payload_in_size; i++) {
- current->payload_in[i] = buffer[index_in];
- index_in++;
- }
- }
- }
-
- return ERROR_OK;
+ index_out = 0;
+ count_out = 0;
+ count_in = 0;
+
+ for (current = device->queue_start; current; current = current->next) {
+ /* Add command to packet */
+ buffer[index_out] = current->id;
+ index_out++;
+ count_out++;
+
+ for (i = 0; i < current->payload_out_size; i++)
+ buffer[index_out + i] = current->payload_out[i];
+ index_out += current->payload_out_size;
+ count_in += current->payload_in_size;
+ count_out += current->payload_out_size;
+ }
+
+ /* Send packet to ULINK */
+ ret = usb_bulk_write(device->usb_handle, (2 | USB_ENDPOINT_OUT),
+ (char *)buffer, count_out, timeout);
+ if (ret < 0)
+ return ERROR_FAIL;
+ if (ret != count_out)
+ return ERROR_FAIL;
+
+ /* Wait for response if commands contain IN payload data */
+ if (count_in > 0) {
+ ret = usb_bulk_read(device->usb_handle, (2 | USB_ENDPOINT_IN),
+ (char *)buffer, 64, timeout);
+ if (ret < 0)
+ return ERROR_FAIL;
+ if (ret != count_in)
+ return ERROR_FAIL;
+
+ /* Write back IN payload data */
+ index_in = 0;
+ for (current = device->queue_start; current; current = current->next) {
+ for (i = 0; i < current->payload_in_size; i++) {
+ current->payload_in[i] = buffer[index_in];
+ index_in++;
+ }
+ }
+ }
+
+ return ERROR_OK;
}
#ifdef _DEBUG_JTAG_IO_
* @param id the OpenULINK command ID.
* @return the corresponding human-readable string.
*/
-const char * ulink_cmd_id_string(uint8_t id)
+const char *ulink_cmd_id_string(uint8_t id)
{
- switch (id) {
- case CMD_SCAN_IN:
- return "CMD_SCAN_IN";
- break;
- case CMD_SLOW_SCAN_IN:
- return "CMD_SLOW_SCAN_IN";
- break;
- case CMD_SCAN_OUT:
- return "CMD_SCAN_OUT";
- break;
- case CMD_SLOW_SCAN_OUT:
- return "CMD_SLOW_SCAN_OUT";
- break;
- case CMD_SCAN_IO:
- return "CMD_SCAN_IO";
- break;
- case CMD_SLOW_SCAN_IO:
- return "CMD_SLOW_SCAN_IO";
- break;
- case CMD_CLOCK_TMS:
- return "CMD_CLOCK_TMS";
- break;
- case CMD_SLOW_CLOCK_TMS:
- return "CMD_SLOW_CLOCK_TMS";
- break;
- case CMD_CLOCK_TCK:
- return "CMD_CLOCK_TCK";
- break;
- case CMD_SLOW_CLOCK_TCK:
- return "CMD_SLOW_CLOCK_TCK";
- break;
- case CMD_SLEEP_US:
- return "CMD_SLEEP_US";
- break;
- case CMD_SLEEP_MS:
- return "CMD_SLEEP_MS";
- break;
- case CMD_GET_SIGNALS:
- return "CMD_GET_SIGNALS";
- break;
- case CMD_SET_SIGNALS:
- return "CMD_SET_SIGNALS";
- break;
- case CMD_CONFIGURE_TCK_FREQ:
- return "CMD_CONFIGURE_TCK_FREQ";
- break;
- case CMD_SET_LEDS:
- return "CMD_SET_LEDS";
- break;
- case CMD_TEST:
- return "CMD_TEST";
- break;
- default:
- return "CMD_UNKNOWN";
- break;
- }
+ switch (id) {
+ case CMD_SCAN_IN:
+ return "CMD_SCAN_IN";
+ break;
+ case CMD_SLOW_SCAN_IN:
+ return "CMD_SLOW_SCAN_IN";
+ break;
+ case CMD_SCAN_OUT:
+ return "CMD_SCAN_OUT";
+ break;
+ case CMD_SLOW_SCAN_OUT:
+ return "CMD_SLOW_SCAN_OUT";
+ break;
+ case CMD_SCAN_IO:
+ return "CMD_SCAN_IO";
+ break;
+ case CMD_SLOW_SCAN_IO:
+ return "CMD_SLOW_SCAN_IO";
+ break;
+ case CMD_CLOCK_TMS:
+ return "CMD_CLOCK_TMS";
+ break;
+ case CMD_SLOW_CLOCK_TMS:
+ return "CMD_SLOW_CLOCK_TMS";
+ break;
+ case CMD_CLOCK_TCK:
+ return "CMD_CLOCK_TCK";
+ break;
+ case CMD_SLOW_CLOCK_TCK:
+ return "CMD_SLOW_CLOCK_TCK";
+ break;
+ case CMD_SLEEP_US:
+ return "CMD_SLEEP_US";
+ break;
+ case CMD_SLEEP_MS:
+ return "CMD_SLEEP_MS";
+ break;
+ case CMD_GET_SIGNALS:
+ return "CMD_GET_SIGNALS";
+ break;
+ case CMD_SET_SIGNALS:
+ return "CMD_SET_SIGNALS";
+ break;
+ case CMD_CONFIGURE_TCK_FREQ:
+ return "CMD_CONFIGURE_TCK_FREQ";
+ break;
+ case CMD_SET_LEDS:
+ return "CMD_SET_LEDS";
+ break;
+ case CMD_TEST:
+ return "CMD_TEST";
+ break;
+ default:
+ return "CMD_UNKNOWN";
+ break;
+ }
}
/**
*/
void ulink_print_command(struct ulink_cmd *ulink_cmd)
{
- int i;
+ int i;
- printf(" %-22s | OUT size = %i, bytes = 0x",
- ulink_cmd_id_string(ulink_cmd->id), ulink_cmd->payload_out_size);
+ printf(" %-22s | OUT size = %i, bytes = 0x",
+ ulink_cmd_id_string(ulink_cmd->id), ulink_cmd->payload_out_size);
- for (i = 0; i < ulink_cmd->payload_out_size; i++) {
- printf("%02X ", ulink_cmd->payload_out[i]);
- }
- printf("\n | IN size = %i\n",
- ulink_cmd->payload_in_size);
+ for (i = 0; i < ulink_cmd->payload_out_size; i++)
+ printf("%02X ", ulink_cmd->payload_out[i]);
+ printf("\n | IN size = %i\n",
+ ulink_cmd->payload_in_size);
}
/**
*/
void ulink_print_queue(struct ulink *device)
{
- struct ulink_cmd *current;
+ struct ulink_cmd *current;
- printf("OpenULINK command queue:\n");
+ printf("OpenULINK command queue:\n");
- for (current = device->queue_start; current; current = current->next) {
- ulink_print_command(current);
- }
+ for (current = device->queue_start; current; current = current->next)
+ ulink_print_command(current);
}
-#endif /* _DEBUG_JTAG_IO_ */
+#endif /* _DEBUG_JTAG_IO_ */
/**
* Perform JTAG scan
* @return on failure: ERROR_FAIL
*/
int ulink_append_scan_cmd(struct ulink *device, enum scan_type scan_type,
- int scan_size_bits, uint8_t *tdi, uint8_t *tdo_start, uint8_t *tdo,
- uint8_t tms_count_start, uint8_t tms_sequence_start, uint8_t tms_count_end,
- uint8_t tms_sequence_end, struct jtag_command *origin, bool postprocess)
+ int scan_size_bits, uint8_t *tdi, uint8_t *tdo_start, uint8_t *tdo,
+ uint8_t tms_count_start, uint8_t tms_sequence_start, uint8_t tms_count_end,
+ uint8_t tms_sequence_end, struct jtag_command *origin, bool postprocess)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret, i, scan_size_bytes;
- uint8_t bits_last_byte;
-
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
-
- /* Check size of command. USB buffer can hold 64 bytes, 1 byte is command ID,
- * 5 bytes are setup data -> 58 remaining payload bytes for TDI data */
- if (scan_size_bits > (58 * 8)) {
- LOG_ERROR("BUG: Tried to create CMD_SCAN_IO OpenULINK command with too"
- " large payload");
- return ERROR_FAIL;
- }
-
- scan_size_bytes = DIV_ROUND_UP(scan_size_bits, 8);
-
- bits_last_byte = scan_size_bits % 8;
- if (bits_last_byte == 0) {
- bits_last_byte = 8;
- }
-
- /* Allocate out_payload depending on scan type */
- switch (scan_type) {
- case SCAN_IN:
- if (device->delay_scan_in < 0) {
- cmd->id = CMD_SCAN_IN;
- }
- else {
- cmd->id = CMD_SLOW_SCAN_IN;
- }
- ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
- break;
- case SCAN_OUT:
- if (device->delay_scan_out < 0) {
- cmd->id = CMD_SCAN_OUT;
- }
- else {
- cmd->id = CMD_SLOW_SCAN_OUT;
- }
- ret = ulink_allocate_payload(cmd, scan_size_bytes + 5, PAYLOAD_DIRECTION_OUT);
- break;
- case SCAN_IO:
- if (device->delay_scan_io < 0) {
- cmd->id = CMD_SCAN_IO;
- }
- else {
- cmd->id = CMD_SLOW_SCAN_IO;
- }
- ret = ulink_allocate_payload(cmd, scan_size_bytes + 5, PAYLOAD_DIRECTION_OUT);
- break;
- default:
- LOG_ERROR("BUG: ulink_append_scan_cmd() encountered an unknown scan type");
- ret = ERROR_FAIL;
- break;
- }
-
- if (ret != ERROR_OK) {
- return ret;
- }
-
- /* Build payload_out that is common to all scan types */
- cmd->payload_out[0] = scan_size_bytes & 0xFF;
- cmd->payload_out[1] = bits_last_byte & 0xFF;
- cmd->payload_out[2] = ((tms_count_start & 0x0F) << 4) | (tms_count_end & 0x0F);
- cmd->payload_out[3] = tms_sequence_start;
- cmd->payload_out[4] = tms_sequence_end;
-
- /* Setup payload_out for types with OUT transfer */
- if ((scan_type == SCAN_OUT) || (scan_type == SCAN_IO)) {
- for (i = 0; i < scan_size_bytes; i++) {
- cmd->payload_out[i + 5] = tdi[i];
- }
- }
-
- /* Setup payload_in pointers for types with IN transfer */
- if ((scan_type == SCAN_IN) || (scan_type == SCAN_IO)) {
- cmd->payload_in_start = tdo_start;
- cmd->payload_in = tdo;
- cmd->payload_in_size = scan_size_bytes;
- }
-
- cmd->needs_postprocessing = postprocess;
- cmd->cmd_origin = origin;
-
- /* For scan commands, we free payload_in_start only when the command is
- * the last in a series of split commands or a stand-alone command */
- cmd->free_payload_in_start = postprocess;
-
- return ulink_append_queue(device, cmd);
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret, i, scan_size_bytes;
+ uint8_t bits_last_byte;
+
+ if (cmd == NULL)
+ return ERROR_FAIL;
+
+ /* Check size of command. USB buffer can hold 64 bytes, 1 byte is command ID,
+ * 5 bytes are setup data -> 58 remaining payload bytes for TDI data */
+ if (scan_size_bits > (58 * 8)) {
+ LOG_ERROR("BUG: Tried to create CMD_SCAN_IO OpenULINK command with too"
+ " large payload");
+ return ERROR_FAIL;
+ }
+
+ scan_size_bytes = DIV_ROUND_UP(scan_size_bits, 8);
+
+ bits_last_byte = scan_size_bits % 8;
+ if (bits_last_byte == 0)
+ bits_last_byte = 8;
+
+ /* Allocate out_payload depending on scan type */
+ switch (scan_type) {
+ case SCAN_IN:
+ if (device->delay_scan_in < 0)
+ cmd->id = CMD_SCAN_IN;
+ else
+ cmd->id = CMD_SLOW_SCAN_IN;
+ ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
+ break;
+ case SCAN_OUT:
+ if (device->delay_scan_out < 0)
+ cmd->id = CMD_SCAN_OUT;
+ else
+ cmd->id = CMD_SLOW_SCAN_OUT;
+ ret = ulink_allocate_payload(cmd, scan_size_bytes + 5, PAYLOAD_DIRECTION_OUT);
+ break;
+ case SCAN_IO:
+ if (device->delay_scan_io < 0)
+ cmd->id = CMD_SCAN_IO;
+ else
+ cmd->id = CMD_SLOW_SCAN_IO;
+ ret = ulink_allocate_payload(cmd, scan_size_bytes + 5, PAYLOAD_DIRECTION_OUT);
+ break;
+ default:
+ LOG_ERROR("BUG: ulink_append_scan_cmd() encountered an unknown scan type");
+ ret = ERROR_FAIL;
+ break;
+ }
+
+ if (ret != ERROR_OK)
+ return ret;
+
+ /* Build payload_out that is common to all scan types */
+ cmd->payload_out[0] = scan_size_bytes & 0xFF;
+ cmd->payload_out[1] = bits_last_byte & 0xFF;
+ cmd->payload_out[2] = ((tms_count_start & 0x0F) << 4) | (tms_count_end & 0x0F);
+ cmd->payload_out[3] = tms_sequence_start;
+ cmd->payload_out[4] = tms_sequence_end;
+
+ /* Setup payload_out for types with OUT transfer */
+ if ((scan_type == SCAN_OUT) || (scan_type == SCAN_IO)) {
+ for (i = 0; i < scan_size_bytes; i++)
+ cmd->payload_out[i + 5] = tdi[i];
+ }
+
+ /* Setup payload_in pointers for types with IN transfer */
+ if ((scan_type == SCAN_IN) || (scan_type == SCAN_IO)) {
+ cmd->payload_in_start = tdo_start;
+ cmd->payload_in = tdo;
+ cmd->payload_in_size = scan_size_bytes;
+ }
+
+ cmd->needs_postprocessing = postprocess;
+ cmd->cmd_origin = origin;
+
+ /* For scan commands, we free payload_in_start only when the command is
+ * the last in a series of split commands or a stand-alone command */
+ cmd->free_payload_in_start = postprocess;
+
+ return ulink_append_queue(device, cmd);
}
/**
* @return on failure: ERROR_FAIL
*/
int ulink_append_clock_tms_cmd(struct ulink *device, uint8_t count,
- uint8_t sequence)
+ uint8_t sequence)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
-
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
-
- if (device->delay_clock_tms < 0) {
- cmd->id = CMD_CLOCK_TMS;
- }
- else {
- cmd->id = CMD_SLOW_CLOCK_TMS;
- }
-
- /* CMD_CLOCK_TMS has two OUT payload bytes and zero IN payload bytes */
- ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- cmd->payload_out[0] = count;
- cmd->payload_out[1] = sequence;
-
- return ulink_append_queue(device, cmd);
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
+
+ if (cmd == NULL)
+ return ERROR_FAIL;
+
+ if (device->delay_clock_tms < 0)
+ cmd->id = CMD_CLOCK_TMS;
+ else
+ cmd->id = CMD_SLOW_CLOCK_TMS;
+
+ /* CMD_CLOCK_TMS has two OUT payload bytes and zero IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
+ if (ret != ERROR_OK)
+ return ret;
+
+ cmd->payload_out[0] = count;
+ cmd->payload_out[1] = sequence;
+
+ return ulink_append_queue(device, cmd);
}
/**
*/
int ulink_append_clock_tck_cmd(struct ulink *device, uint16_t count)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
-
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
-
- if (device->delay_clock_tck < 0) {
- cmd->id = CMD_CLOCK_TCK;
- }
- else {
- cmd->id = CMD_SLOW_CLOCK_TCK;
- }
-
- /* CMD_CLOCK_TCK has two OUT payload bytes and zero IN payload bytes */
- ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- cmd->payload_out[0] = count & 0xff;
- cmd->payload_out[1] = (count >> 8) & 0xff;
-
- return ulink_append_queue(device, cmd);
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
+
+ if (cmd == NULL)
+ return ERROR_FAIL;
+
+ if (device->delay_clock_tck < 0)
+ cmd->id = CMD_CLOCK_TCK;
+ else
+ cmd->id = CMD_SLOW_CLOCK_TCK;
+
+ /* CMD_CLOCK_TCK has two OUT payload bytes and zero IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
+ if (ret != ERROR_OK)
+ return ret;
+
+ cmd->payload_out[0] = count & 0xff;
+ cmd->payload_out[1] = (count >> 8) & 0xff;
+
+ return ulink_append_queue(device, cmd);
}
/**
*/
int ulink_append_get_signals_cmd(struct ulink *device)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
+ if (cmd == NULL)
+ return ERROR_FAIL;
- cmd->id = CMD_GET_SIGNALS;
- cmd->needs_postprocessing = true;
+ cmd->id = CMD_GET_SIGNALS;
+ cmd->needs_postprocessing = true;
- /* CMD_GET_SIGNALS has two IN payload bytes */
- ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_IN);
+ /* CMD_GET_SIGNALS has two IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_IN);
- if (ret != ERROR_OK) {
- return ret;
- }
+ if (ret != ERROR_OK)
+ return ret;
- return ulink_append_queue(device, cmd);
+ return ulink_append_queue(device, cmd);
}
/**
* @return on failure: ERROR_FAIL
*/
int ulink_append_set_signals_cmd(struct ulink *device, uint8_t low,
- uint8_t high)
+ uint8_t high)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
+ if (cmd == NULL)
+ return ERROR_FAIL;
- cmd->id = CMD_SET_SIGNALS;
+ cmd->id = CMD_SET_SIGNALS;
- /* CMD_SET_SIGNALS has two OUT payload bytes and zero IN payload bytes */
- ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
+ /* CMD_SET_SIGNALS has two OUT payload bytes and zero IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- return ret;
- }
+ if (ret != ERROR_OK)
+ return ret;
- cmd->payload_out[0] = low;
- cmd->payload_out[1] = high;
+ cmd->payload_out[0] = low;
+ cmd->payload_out[1] = high;
- return ulink_append_queue(device, cmd);
+ return ulink_append_queue(device, cmd);
}
/**
*/
int ulink_append_sleep_cmd(struct ulink *device, uint32_t us)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
+ if (cmd == NULL)
+ return ERROR_FAIL;
- cmd->id = CMD_SLEEP_US;
+ cmd->id = CMD_SLEEP_US;
- /* CMD_SLEEP_US has two OUT payload bytes and zero IN payload bytes */
- ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
+ /* CMD_SLEEP_US has two OUT payload bytes and zero IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- return ret;
- }
+ if (ret != ERROR_OK)
+ return ret;
- cmd->payload_out[0] = us & 0x00ff;
- cmd->payload_out[1] = (us >> 8) & 0x00ff;
+ cmd->payload_out[0] = us & 0x00ff;
+ cmd->payload_out[1] = (us >> 8) & 0x00ff;
- return ulink_append_queue(device, cmd);
+ return ulink_append_queue(device, cmd);
}
/**
* @return on failure: ERROR_FAIL
*/
int ulink_append_configure_tck_cmd(struct ulink *device, int delay_scan_in,
- int delay_scan_out, int delay_scan_io, int delay_tck, int delay_tms)
+ int delay_scan_out, int delay_scan_io, int delay_tck, int delay_tms)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
-
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
-
- cmd->id = CMD_CONFIGURE_TCK_FREQ;
-
- /* CMD_CONFIGURE_TCK_FREQ has five OUT payload bytes and zero
- * IN payload bytes */
- ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- if (delay_scan_in < 0) {
- cmd->payload_out[0] = 0;
- }
- else {
- cmd->payload_out[0] = (uint8_t)delay_scan_in;
- }
-
- if (delay_scan_out < 0) {
- cmd->payload_out[1] = 0;
- }
- else {
- cmd->payload_out[1] = (uint8_t)delay_scan_out;
- }
-
- if (delay_scan_io < 0) {
- cmd->payload_out[2] = 0;
- }
- else {
- cmd->payload_out[2] = (uint8_t)delay_scan_io;
- }
-
- if (delay_tck < 0) {
- cmd->payload_out[3] = 0;
- }
- else {
- cmd->payload_out[3] = (uint8_t)delay_tck;
- }
-
- if (delay_tms < 0) {
- cmd->payload_out[4] = 0;
- }
- else {
- cmd->payload_out[4] = (uint8_t)delay_tms;
- }
-
- return ulink_append_queue(device, cmd);
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
+
+ if (cmd == NULL)
+ return ERROR_FAIL;
+
+ cmd->id = CMD_CONFIGURE_TCK_FREQ;
+
+ /* CMD_CONFIGURE_TCK_FREQ has five OUT payload bytes and zero
+ * IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
+ if (ret != ERROR_OK)
+ return ret;
+
+ if (delay_scan_in < 0)
+ cmd->payload_out[0] = 0;
+ else
+ cmd->payload_out[0] = (uint8_t)delay_scan_in;
+
+ if (delay_scan_out < 0)
+ cmd->payload_out[1] = 0;
+ else
+ cmd->payload_out[1] = (uint8_t)delay_scan_out;
+
+ if (delay_scan_io < 0)
+ cmd->payload_out[2] = 0;
+ else
+ cmd->payload_out[2] = (uint8_t)delay_scan_io;
+
+ if (delay_tck < 0)
+ cmd->payload_out[3] = 0;
+ else
+ cmd->payload_out[3] = (uint8_t)delay_tck;
+
+ if (delay_tms < 0)
+ cmd->payload_out[4] = 0;
+ else
+ cmd->payload_out[4] = (uint8_t)delay_tms;
+
+ return ulink_append_queue(device, cmd);
}
/**
*/
int ulink_append_led_cmd(struct ulink *device, uint8_t led_state)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
+ if (cmd == NULL)
+ return ERROR_FAIL;
- cmd->id = CMD_SET_LEDS;
+ cmd->id = CMD_SET_LEDS;
- /* CMD_SET_LEDS has one OUT payload byte and zero IN payload bytes */
- ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- return ret;
- }
+ /* CMD_SET_LEDS has one OUT payload byte and zero IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
+ if (ret != ERROR_OK)
+ return ret;
- cmd->payload_out[0] = led_state;
+ cmd->payload_out[0] = led_state;
- return ulink_append_queue(device, cmd);
+ return ulink_append_queue(device, cmd);
}
/**
*/
int ulink_append_test_cmd(struct ulink *device)
{
- struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
- int ret;
+ struct ulink_cmd *cmd = calloc(1, sizeof(struct ulink_cmd));
+ int ret;
- if (cmd == NULL) {
- return ERROR_FAIL;
- }
+ if (cmd == NULL)
+ return ERROR_FAIL;
- cmd->id = CMD_TEST;
+ cmd->id = CMD_TEST;
- /* CMD_TEST has one OUT payload byte and zero IN payload bytes */
- ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- return ret;
- }
+ /* CMD_TEST has one OUT payload byte and zero IN payload bytes */
+ ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
+ if (ret != ERROR_OK)
+ return ret;
- cmd->payload_out[0] = 0xAA;
+ cmd->payload_out[0] = 0xAA;
- return ulink_append_queue(device, cmd);
+ return ulink_append_queue(device, cmd);
}
/****************** OpenULINK TCK frequency helper functions ******************/
*/
int ulink_calculate_delay(enum ulink_delay_type type, long f, int *delay)
{
- float t, x, x_ceil;
-
- /* Calculate period of requested TCK frequency */
- t = 1.0 / (float)(f);
-
- switch (type) {
- case DELAY_CLOCK_TCK:
- x = (t - (float)(6E-6)) / (float)(4E-6);
- break;
- case DELAY_CLOCK_TMS:
- x = (t - (float)(8.5E-6)) / (float)(4E-6);
- break;
- case DELAY_SCAN_IN:
- x = (t - (float)(8.8308E-6)) / (float)(4E-6);
- break;
- case DELAY_SCAN_OUT:
- x = (t - (float)(1.0527E-5)) / (float)(4E-6);
- break;
- case DELAY_SCAN_IO:
- x = (t - (float)(1.3132E-5)) / (float)(4E-6);
- break;
- default:
- return ERROR_FAIL;
- break;
- }
-
- /* Check if the delay value is negative. This happens when a frequency is
- * requested that is too high for the delay loop implementation. In this
- * case, set delay value to zero. */
- if (x < 0) {
- x = 0;
- }
-
- /* We need to convert the exact delay value to an integer. Therefore, we
- * round the exact value UP to ensure that the resulting frequency is NOT
- * higher than the requested frequency. */
- x_ceil = ceilf(x);
-
- /* Check if the value is within limits */
- if (x_ceil > 255) {
- return ERROR_FAIL;
- }
-
- *delay = (int)x_ceil;
-
- return ERROR_OK;
+ float t, x, x_ceil;
+
+ /* Calculate period of requested TCK frequency */
+ t = 1.0 / (float)(f);
+
+ switch (type) {
+ case DELAY_CLOCK_TCK:
+ x = (t - (float)(6E-6)) / (float)(4E-6);
+ break;
+ case DELAY_CLOCK_TMS:
+ x = (t - (float)(8.5E-6)) / (float)(4E-6);
+ break;
+ case DELAY_SCAN_IN:
+ x = (t - (float)(8.8308E-6)) / (float)(4E-6);
+ break;
+ case DELAY_SCAN_OUT:
+ x = (t - (float)(1.0527E-5)) / (float)(4E-6);
+ break;
+ case DELAY_SCAN_IO:
+ x = (t - (float)(1.3132E-5)) / (float)(4E-6);
+ break;
+ default:
+ return ERROR_FAIL;
+ break;
+ }
+
+ /* Check if the delay value is negative. This happens when a frequency is
+ * requested that is too high for the delay loop implementation. In this
+ * case, set delay value to zero. */
+ if (x < 0)
+ x = 0;
+
+ /* We need to convert the exact delay value to an integer. Therefore, we
+ * round the exact value UP to ensure that the resulting frequency is NOT
+ * higher than the requested frequency. */
+ x_ceil = ceilf(x);
+
+ /* Check if the value is within limits */
+ if (x_ceil > 255)
+ return ERROR_FAIL;
+
+ *delay = (int)x_ceil;
+
+ return ERROR_OK;
}
/**
*/
int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long *f)
{
- float t, f_float, f_rounded;
-
- if (delay > 255) {
- return ERROR_FAIL;
- }
-
- switch (type) {
- case DELAY_CLOCK_TCK:
- if (delay < 0) {
- t = (float)(2.666E-6);
- }
- else {
- t = (float)(4E-6) * (float)(delay) + (float)(6E-6);
- }
- break;
- case DELAY_CLOCK_TMS:
- if (delay < 0) {
- t = (float)(5.666E-6);
- }
- else {
- t = (float)(4E-6) * (float)(delay) + (float)(8.5E-6);
- }
- break;
- case DELAY_SCAN_IN:
- if (delay < 0) {
- t = (float)(5.5E-6);
- }
- else {
- t = (float)(4E-6) * (float)(delay) + (float)(8.8308E-6);
- }
- break;
- case DELAY_SCAN_OUT:
- if (delay < 0) {
- t = (float)(7.0E-6);
- }
- else {
- t = (float)(4E-6) * (float)(delay) + (float)(1.0527E-5);
- }
- break;
- case DELAY_SCAN_IO:
- if (delay < 0) {
- t = (float)(9.926E-6);
- }
- else {
- t = (float)(4E-6) * (float)(delay) + (float)(1.3132E-5);
- }
- break;
- default:
- return ERROR_FAIL;
- break;
- }
-
- f_float = 1.0 / t;
- f_rounded = roundf(f_float);
- *f = (long)f_rounded;
-
- return ERROR_OK;
+ float t, f_float, f_rounded;
+
+ if (delay > 255)
+ return ERROR_FAIL;
+
+ switch (type) {
+ case DELAY_CLOCK_TCK:
+ if (delay < 0)
+ t = (float)(2.666E-6);
+ else
+ t = (float)(4E-6) * (float)(delay) + (float)(6E-6);
+ break;
+ case DELAY_CLOCK_TMS:
+ if (delay < 0)
+ t = (float)(5.666E-6);
+ else
+ t = (float)(4E-6) * (float)(delay) + (float)(8.5E-6);
+ break;
+ case DELAY_SCAN_IN:
+ if (delay < 0)
+ t = (float)(5.5E-6);
+ else
+ t = (float)(4E-6) * (float)(delay) + (float)(8.8308E-6);
+ break;
+ case DELAY_SCAN_OUT:
+ if (delay < 0)
+ t = (float)(7.0E-6);
+ else
+ t = (float)(4E-6) * (float)(delay) + (float)(1.0527E-5);
+ break;
+ case DELAY_SCAN_IO:
+ if (delay < 0)
+ t = (float)(9.926E-6);
+ else
+ t = (float)(4E-6) * (float)(delay) + (float)(1.3132E-5);
+ break;
+ default:
+ return ERROR_FAIL;
+ break;
+ }
+
+ f_float = 1.0 / t;
+ f_rounded = roundf(f_float);
+ *f = (long)f_rounded;
+
+ return ERROR_OK;
}
/******************* Interface between OpenULINK and OpenOCD ******************/
*/
static void ulink_set_end_state(tap_state_t endstate)
{
- if (tap_is_state_stable(endstate)) {
- tap_set_end_state(endstate);
- }
- else {
- LOG_ERROR("BUG: %s is not a valid end state", tap_state_name(endstate));
- exit( EXIT_FAILURE);
- }
+ if (tap_is_state_stable(endstate))
+ tap_set_end_state(endstate);
+ else {
+ LOG_ERROR("BUG: %s is not a valid end state", tap_state_name(endstate));
+ exit(EXIT_FAILURE);
+ }
}
/**
*/
int ulink_queue_statemove(struct ulink *device)
{
- uint8_t tms_sequence, tms_count;
- int ret;
+ uint8_t tms_sequence, tms_count;
+ int ret;
- if (tap_get_state() == tap_get_end_state()) {
- /* Do nothing if we are already there */
- return ERROR_OK;
- }
+ if (tap_get_state() == tap_get_end_state()) {
+ /* Do nothing if we are already there */
+ return ERROR_OK;
+ }
- tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
- tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+ tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+ tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
- ret = ulink_append_clock_tms_cmd(device, tms_count, tms_sequence);
+ ret = ulink_append_clock_tms_cmd(device, tms_count, tms_sequence);
- if (ret == ERROR_OK) {
- tap_set_state(tap_get_end_state());
- }
+ if (ret == ERROR_OK)
+ tap_set_state(tap_get_end_state());
- return ret;
+ return ret;
}
/**
*/
int ulink_queue_scan(struct ulink *device, struct jtag_command *cmd)
{
- uint32_t scan_size_bits, scan_size_bytes, bits_last_scan;
- uint32_t scans_max_payload, bytecount;
- uint8_t *tdi_buffer_start = NULL, *tdi_buffer = NULL;
- uint8_t *tdo_buffer_start = NULL, *tdo_buffer = NULL;
-
- uint8_t first_tms_count, first_tms_sequence;
- uint8_t last_tms_count, last_tms_sequence;
-
- uint8_t tms_count_pause, tms_sequence_pause;
- uint8_t tms_count_resume, tms_sequence_resume;
-
- uint8_t tms_count_start, tms_sequence_start;
- uint8_t tms_count_end, tms_sequence_end;
-
- enum scan_type type;
- int ret;
-
- /* Determine scan size */
- scan_size_bits = jtag_scan_size(cmd->cmd.scan);
- scan_size_bytes = DIV_ROUND_UP(scan_size_bits, 8);
-
- /* Determine scan type (IN/OUT/IO) */
- type = jtag_scan_type(cmd->cmd.scan);
-
- /* Determine number of scan commands with maximum payload */
- scans_max_payload = scan_size_bytes / 58;
-
- /* Determine size of last shift command */
- bits_last_scan = scan_size_bits - (scans_max_payload * 58 * 8);
-
- /* Allocate TDO buffer if required */
- if ((type == SCAN_IN) || (type == SCAN_IO)) {
- tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes);
-
- if (tdo_buffer_start == NULL) {
- return ERROR_FAIL;
- }
-
- tdo_buffer = tdo_buffer_start;
- }
-
- /* Fill TDI buffer if required */
- if ((type == SCAN_OUT) || (type == SCAN_IO)) {
- jtag_build_buffer(cmd->cmd.scan, &tdi_buffer_start);
- tdi_buffer = tdi_buffer_start;
- }
-
- /* Get TAP state transitions */
- if (cmd->cmd.scan->ir_scan) {
- ulink_set_end_state(TAP_IRSHIFT);
- first_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
- first_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
-
- tap_set_state(TAP_IRSHIFT);
- tap_set_end_state(cmd->cmd.scan->end_state);
- last_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
- last_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
-
- /* TAP state transitions for split scans */
- tms_count_pause = tap_get_tms_path_len(TAP_IRSHIFT, TAP_IRPAUSE);
- tms_sequence_pause = tap_get_tms_path(TAP_IRSHIFT, TAP_IRPAUSE);
- tms_count_resume = tap_get_tms_path_len(TAP_IRPAUSE, TAP_IRSHIFT);
- tms_sequence_resume = tap_get_tms_path(TAP_IRPAUSE, TAP_IRSHIFT);
- }
- else {
- ulink_set_end_state(TAP_DRSHIFT);
- first_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
- first_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
-
- tap_set_state(TAP_DRSHIFT);
- tap_set_end_state(cmd->cmd.scan->end_state);
- last_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
- last_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
-
- /* TAP state transitions for split scans */
- tms_count_pause = tap_get_tms_path_len(TAP_DRSHIFT, TAP_DRPAUSE);
- tms_sequence_pause = tap_get_tms_path(TAP_DRSHIFT, TAP_DRPAUSE);
- tms_count_resume = tap_get_tms_path_len(TAP_DRPAUSE, TAP_DRSHIFT);
- tms_sequence_resume = tap_get_tms_path(TAP_DRPAUSE, TAP_DRSHIFT);
- }
-
- /* Generate scan commands */
- bytecount = scan_size_bytes;
- while (bytecount > 0) {
- if (bytecount == scan_size_bytes) {
- /* This is the first scan */
- tms_count_start = first_tms_count;
- tms_sequence_start = first_tms_sequence;
- }
- else {
- /* Resume from previous scan */
- tms_count_start = tms_count_resume;
- tms_sequence_start = tms_sequence_resume;
- }
-
- if (bytecount > 58) { /* Full scan, at least one scan will follow */
- tms_count_end = tms_count_pause;
- tms_sequence_end = tms_sequence_pause;
-
- ret = ulink_append_scan_cmd(device, type, 58 * 8, tdi_buffer,
- tdo_buffer_start, tdo_buffer, tms_count_start, tms_sequence_start,
- tms_count_end, tms_sequence_end, cmd, false);
-
- bytecount -= 58;
-
- /* Update TDI and TDO buffer pointers */
- if (tdi_buffer_start != NULL) {
- tdi_buffer += 58;
- }
- if (tdo_buffer_start != NULL) {
- tdo_buffer += 58;
- }
- }
- else if (bytecount == 58) { /* Full scan, no further scans */
- tms_count_end = last_tms_count;
- tms_sequence_end = last_tms_sequence;
-
- ret = ulink_append_scan_cmd(device, type, 58 * 8, tdi_buffer,
- tdo_buffer_start, tdo_buffer, tms_count_start, tms_sequence_start,
- tms_count_end, tms_sequence_end, cmd, true);
-
- bytecount = 0;
- }
- else { /* Scan with less than maximum payload, no further scans */
- tms_count_end = last_tms_count;
- tms_sequence_end = last_tms_sequence;
-
- ret = ulink_append_scan_cmd(device, type, bits_last_scan, tdi_buffer,
- tdo_buffer_start, tdo_buffer, tms_count_start, tms_sequence_start,
- tms_count_end, tms_sequence_end, cmd, true);
-
- bytecount = 0;
- }
-
- if (ret != ERROR_OK) {
- free(tdi_buffer_start);
- return ret;
- }
- }
-
- free(tdi_buffer_start);
-
- /* Set current state to the end state requested by the command */
- tap_set_state(cmd->cmd.scan->end_state);
-
- return ERROR_OK;
+ uint32_t scan_size_bits, scan_size_bytes, bits_last_scan;
+ uint32_t scans_max_payload, bytecount;
+ uint8_t *tdi_buffer_start = NULL, *tdi_buffer = NULL;
+ uint8_t *tdo_buffer_start = NULL, *tdo_buffer = NULL;
+
+ uint8_t first_tms_count, first_tms_sequence;
+ uint8_t last_tms_count, last_tms_sequence;
+
+ uint8_t tms_count_pause, tms_sequence_pause;
+ uint8_t tms_count_resume, tms_sequence_resume;
+
+ uint8_t tms_count_start, tms_sequence_start;
+ uint8_t tms_count_end, tms_sequence_end;
+
+ enum scan_type type;
+ int ret;
+
+ /* Determine scan size */
+ scan_size_bits = jtag_scan_size(cmd->cmd.scan);
+ scan_size_bytes = DIV_ROUND_UP(scan_size_bits, 8);
+
+ /* Determine scan type (IN/OUT/IO) */
+ type = jtag_scan_type(cmd->cmd.scan);
+
+ /* Determine number of scan commands with maximum payload */
+ scans_max_payload = scan_size_bytes / 58;
+
+ /* Determine size of last shift command */
+ bits_last_scan = scan_size_bits - (scans_max_payload * 58 * 8);
+
+ /* Allocate TDO buffer if required */
+ if ((type == SCAN_IN) || (type == SCAN_IO)) {
+ tdo_buffer_start = calloc(sizeof(uint8_t), scan_size_bytes);
+
+ if (tdo_buffer_start == NULL)
+ return ERROR_FAIL;
+
+ tdo_buffer = tdo_buffer_start;
+ }
+
+ /* Fill TDI buffer if required */
+ if ((type == SCAN_OUT) || (type == SCAN_IO)) {
+ jtag_build_buffer(cmd->cmd.scan, &tdi_buffer_start);
+ tdi_buffer = tdi_buffer_start;
+ }
+
+ /* Get TAP state transitions */
+ if (cmd->cmd.scan->ir_scan) {
+ ulink_set_end_state(TAP_IRSHIFT);
+ first_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+ first_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+
+ tap_set_state(TAP_IRSHIFT);
+ tap_set_end_state(cmd->cmd.scan->end_state);
+ last_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+ last_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+
+ /* TAP state transitions for split scans */
+ tms_count_pause = tap_get_tms_path_len(TAP_IRSHIFT, TAP_IRPAUSE);
+ tms_sequence_pause = tap_get_tms_path(TAP_IRSHIFT, TAP_IRPAUSE);
+ tms_count_resume = tap_get_tms_path_len(TAP_IRPAUSE, TAP_IRSHIFT);
+ tms_sequence_resume = tap_get_tms_path(TAP_IRPAUSE, TAP_IRSHIFT);
+ } else {
+ ulink_set_end_state(TAP_DRSHIFT);
+ first_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+ first_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+
+ tap_set_state(TAP_DRSHIFT);
+ tap_set_end_state(cmd->cmd.scan->end_state);
+ last_tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+ last_tms_sequence = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+
+ /* TAP state transitions for split scans */
+ tms_count_pause = tap_get_tms_path_len(TAP_DRSHIFT, TAP_DRPAUSE);
+ tms_sequence_pause = tap_get_tms_path(TAP_DRSHIFT, TAP_DRPAUSE);
+ tms_count_resume = tap_get_tms_path_len(TAP_DRPAUSE, TAP_DRSHIFT);
+ tms_sequence_resume = tap_get_tms_path(TAP_DRPAUSE, TAP_DRSHIFT);
+ }
+
+ /* Generate scan commands */
+ bytecount = scan_size_bytes;
+ while (bytecount > 0) {
+ if (bytecount == scan_size_bytes) {
+ /* This is the first scan */
+ tms_count_start = first_tms_count;
+ tms_sequence_start = first_tms_sequence;
+ } else {
+ /* Resume from previous scan */
+ tms_count_start = tms_count_resume;
+ tms_sequence_start = tms_sequence_resume;
+ }
+
+ if (bytecount > 58) { /* Full scan, at least one scan will follow */
+ tms_count_end = tms_count_pause;
+ tms_sequence_end = tms_sequence_pause;
+
+ ret = ulink_append_scan_cmd(device,
+ type,
+ 58 * 8,
+ tdi_buffer,
+ tdo_buffer_start,
+ tdo_buffer,
+ tms_count_start,
+ tms_sequence_start,
+ tms_count_end,
+ tms_sequence_end,
+ cmd,
+ false);
+
+ bytecount -= 58;
+
+ /* Update TDI and TDO buffer pointers */
+ if (tdi_buffer_start != NULL)
+ tdi_buffer += 58;
+ if (tdo_buffer_start != NULL)
+ tdo_buffer += 58;
+ } else if (bytecount == 58) { /* Full scan, no further scans */
+ tms_count_end = last_tms_count;
+ tms_sequence_end = last_tms_sequence;
+
+ ret = ulink_append_scan_cmd(device,
+ type,
+ 58 * 8,
+ tdi_buffer,
+ tdo_buffer_start,
+ tdo_buffer,
+ tms_count_start,
+ tms_sequence_start,
+ tms_count_end,
+ tms_sequence_end,
+ cmd,
+ true);
+
+ bytecount = 0;
+ } else {/* Scan with less than maximum payload, no further scans */
+ tms_count_end = last_tms_count;
+ tms_sequence_end = last_tms_sequence;
+
+ ret = ulink_append_scan_cmd(device,
+ type,
+ bits_last_scan,
+ tdi_buffer,
+ tdo_buffer_start,
+ tdo_buffer,
+ tms_count_start,
+ tms_sequence_start,
+ tms_count_end,
+ tms_sequence_end,
+ cmd,
+ true);
+
+ bytecount = 0;
+ }
+
+ if (ret != ERROR_OK) {
+ free(tdi_buffer_start);
+ return ret;
+ }
+ }
+
+ free(tdi_buffer_start);
+
+ /* Set current state to the end state requested by the command */
+ tap_set_state(cmd->cmd.scan->end_state);
+
+ return ERROR_OK;
}
/**
*/
int ulink_queue_tlr_reset(struct ulink *device, struct jtag_command *cmd)
{
- int ret;
+ int ret;
- ret = ulink_append_clock_tms_cmd(device, 5, 0xff);
+ ret = ulink_append_clock_tms_cmd(device, 5, 0xff);
- if (ret == ERROR_OK) {
- tap_set_state(TAP_RESET);
- }
+ if (ret == ERROR_OK)
+ tap_set_state(TAP_RESET);
- return ret;
+ return ret;
}
/**
*/
int ulink_queue_runtest(struct ulink *device, struct jtag_command *cmd)
{
- int ret;
-
- /* Only perform statemove if the TAP currently isn't in the TAP_IDLE state */
- if (tap_get_state() != TAP_IDLE) {
- ulink_set_end_state(TAP_IDLE);
- ulink_queue_statemove(device);
- }
-
- /* Generate the clock cycles */
- ret = ulink_append_clock_tck_cmd(device, cmd->cmd.runtest->num_cycles);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- /* Move to end state specified in command */
- if (cmd->cmd.runtest->end_state != tap_get_state()) {
- tap_set_end_state(cmd->cmd.runtest->end_state);
- ulink_queue_statemove(device);
- }
-
- return ERROR_OK;
+ int ret;
+
+ /* Only perform statemove if the TAP currently isn't in the TAP_IDLE state */
+ if (tap_get_state() != TAP_IDLE) {
+ ulink_set_end_state(TAP_IDLE);
+ ulink_queue_statemove(device);
+ }
+
+ /* Generate the clock cycles */
+ ret = ulink_append_clock_tck_cmd(device, cmd->cmd.runtest->num_cycles);
+ if (ret != ERROR_OK)
+ return ret;
+
+ /* Move to end state specified in command */
+ if (cmd->cmd.runtest->end_state != tap_get_state()) {
+ tap_set_end_state(cmd->cmd.runtest->end_state);
+ ulink_queue_statemove(device);
+ }
+
+ return ERROR_OK;
}
/**
*/
int ulink_queue_reset(struct ulink *device, struct jtag_command *cmd)
{
- uint8_t low = 0, high = 0;
-
- if (cmd->cmd.reset->trst) {
- tap_set_state(TAP_RESET);
- high |= SIGNAL_TRST;
- }
- else {
- low |= SIGNAL_TRST;
- }
-
- if (cmd->cmd.reset->srst) {
- high |= SIGNAL_RESET;
- }
- else {
- low |= SIGNAL_RESET;
- }
-
- return ulink_append_set_signals_cmd(device, low, high);
+ uint8_t low = 0, high = 0;
+
+ if (cmd->cmd.reset->trst) {
+ tap_set_state(TAP_RESET);
+ high |= SIGNAL_TRST;
+ } else
+ low |= SIGNAL_TRST;
+
+ if (cmd->cmd.reset->srst)
+ high |= SIGNAL_RESET;
+ else
+ low |= SIGNAL_RESET;
+
+ return ulink_append_set_signals_cmd(device, low, high);
}
/**
*/
int ulink_queue_pathmove(struct ulink *device, struct jtag_command *cmd)
{
- int ret, i, num_states, batch_size, state_count;
- tap_state_t *path;
- uint8_t tms_sequence;
-
- num_states = cmd->cmd.pathmove->num_states;
- path = cmd->cmd.pathmove->path;
- state_count = 0;
-
- while (num_states > 0) {
- tms_sequence = 0;
-
- /* Determine batch size */
- if (num_states >= 8) {
- batch_size = 8;
- }
- else {
- batch_size = num_states;
- }
-
- for (i = 0; i < batch_size; i++) {
- if (tap_state_transition(tap_get_state(), false) == path[state_count]) {
- /* Append '0' transition: clear bit 'i' in tms_sequence */
- buf_set_u32(&tms_sequence, i, 1, 0x0);
- }
- else if (tap_state_transition(tap_get_state(), true)
- == path[state_count]) {
- /* Append '1' transition: set bit 'i' in tms_sequence */
- buf_set_u32(&tms_sequence, i, 1, 0x1);
- }
- else {
- /* Invalid state transition */
- LOG_ERROR("BUG: %s -> %s isn't a valid TAP state transition",
- tap_state_name(tap_get_state()),
- tap_state_name(path[state_count]));
- return ERROR_FAIL;
- }
-
- tap_set_state(path[state_count]);
- state_count++;
- num_states--;
- }
-
- /* Append CLOCK_TMS command to OpenULINK command queue */
- LOG_INFO(
- "pathmove batch: count = %i, sequence = 0x%x", batch_size, tms_sequence);
- ret = ulink_append_clock_tms_cmd(ulink_handle, batch_size, tms_sequence);
- if (ret != ERROR_OK) {
- return ret;
- }
- }
-
- return ERROR_OK;
+ int ret, i, num_states, batch_size, state_count;
+ tap_state_t *path;
+ uint8_t tms_sequence;
+
+ num_states = cmd->cmd.pathmove->num_states;
+ path = cmd->cmd.pathmove->path;
+ state_count = 0;
+
+ while (num_states > 0) {
+ tms_sequence = 0;
+
+ /* Determine batch size */
+ if (num_states >= 8)
+ batch_size = 8;
+ else
+ batch_size = num_states;
+
+ for (i = 0; i < batch_size; i++) {
+ if (tap_state_transition(tap_get_state(), false) == path[state_count]) {
+ /* Append '0' transition: clear bit 'i' in tms_sequence */
+ buf_set_u32(&tms_sequence, i, 1, 0x0);
+ } else if (tap_state_transition(tap_get_state(), true)
+ == path[state_count]) {
+ /* Append '1' transition: set bit 'i' in tms_sequence */
+ buf_set_u32(&tms_sequence, i, 1, 0x1);
+ } else {
+ /* Invalid state transition */
+ LOG_ERROR("BUG: %s -> %s isn't a valid TAP state transition",
+ tap_state_name(tap_get_state()),
+ tap_state_name(path[state_count]));
+ return ERROR_FAIL;
+ }
+
+ tap_set_state(path[state_count]);
+ state_count++;
+ num_states--;
+ }
+
+ /* Append CLOCK_TMS command to OpenULINK command queue */
+ LOG_INFO(
+ "pathmove batch: count = %i, sequence = 0x%x", batch_size, tms_sequence);
+ ret = ulink_append_clock_tms_cmd(ulink_handle, batch_size, tms_sequence);
+ if (ret != ERROR_OK)
+ return ret;
+ }
+
+ return ERROR_OK;
}
/**
*/
int ulink_queue_sleep(struct ulink *device, struct jtag_command *cmd)
{
- /* IMPORTANT! Due to the time offset in command execution introduced by
- * command queueing, this needs to be implemented in the ULINK device */
- return ulink_append_sleep_cmd(device, cmd->cmd.sleep->us);
+ /* IMPORTANT! Due to the time offset in command execution introduced by
+ * command queueing, this needs to be implemented in the ULINK device */
+ return ulink_append_sleep_cmd(device, cmd->cmd.sleep->us);
}
/**
*/
int ulink_queue_stableclocks(struct ulink *device, struct jtag_command *cmd)
{
- int ret;
- unsigned num_cycles;
-
- if (!tap_is_state_stable(tap_get_state())) {
- LOG_ERROR("JTAG_STABLECLOCKS: state not stable");
- return ERROR_FAIL;
- }
-
- num_cycles = cmd->cmd.stableclocks->num_cycles;
-
- /* TMS stays either high (Test Logic Reset state) or low (all other states) */
- if (tap_get_state() == TAP_RESET) {
- ret = ulink_append_set_signals_cmd(device, 0, SIGNAL_TMS);
- }
- else {
- ret = ulink_append_set_signals_cmd(device, SIGNAL_TMS, 0);
- }
-
- if (ret != ERROR_OK) {
- return ret;
- }
-
- while (num_cycles > 0) {
- if (num_cycles > 0xFFFF) {
- /* OpenULINK CMD_CLOCK_TCK can generate up to 0xFFFF (uint16_t) cycles */
- ret = ulink_append_clock_tck_cmd(device, 0xFFFF);
- num_cycles -= 0xFFFF;
- }
- else {
- ret = ulink_append_clock_tck_cmd(device, num_cycles);
- num_cycles = 0;
- }
-
- if (ret != ERROR_OK) {
- return ret;
- }
- }
-
- return ERROR_OK;
+ int ret;
+ unsigned num_cycles;
+
+ if (!tap_is_state_stable(tap_get_state())) {
+ LOG_ERROR("JTAG_STABLECLOCKS: state not stable");
+ return ERROR_FAIL;
+ }
+
+ num_cycles = cmd->cmd.stableclocks->num_cycles;
+
+ /* TMS stays either high (Test Logic Reset state) or low (all other states) */
+ if (tap_get_state() == TAP_RESET)
+ ret = ulink_append_set_signals_cmd(device, 0, SIGNAL_TMS);
+ else
+ ret = ulink_append_set_signals_cmd(device, SIGNAL_TMS, 0);
+
+ if (ret != ERROR_OK)
+ return ret;
+
+ while (num_cycles > 0) {
+ if (num_cycles > 0xFFFF) {
+ /* OpenULINK CMD_CLOCK_TCK can generate up to 0xFFFF (uint16_t) cycles */
+ ret = ulink_append_clock_tck_cmd(device, 0xFFFF);
+ num_cycles -= 0xFFFF;
+ } else {
+ ret = ulink_append_clock_tck_cmd(device, num_cycles);
+ num_cycles = 0;
+ }
+
+ if (ret != ERROR_OK)
+ return ret;
+ }
+
+ return ERROR_OK;
}
/**
*/
int ulink_post_process_scan(struct ulink_cmd *ulink_cmd)
{
- struct jtag_command *cmd = ulink_cmd->cmd_origin;
- int ret;
-
- switch (jtag_scan_type(cmd->cmd.scan)) {
- case SCAN_IN:
- case SCAN_IO:
- ret = jtag_read_buffer(ulink_cmd->payload_in_start, cmd->cmd.scan);
- break;
- case SCAN_OUT:
- /* Nothing to do for OUT scans */
- ret = ERROR_OK;
- break;
- default:
- LOG_ERROR("BUG: ulink_post_process_scan() encountered an unknown"
- " JTAG scan type");
- ret = ERROR_FAIL;
- break;
- }
-
- return ret;
+ struct jtag_command *cmd = ulink_cmd->cmd_origin;
+ int ret;
+
+ switch (jtag_scan_type(cmd->cmd.scan)) {
+ case SCAN_IN:
+ case SCAN_IO:
+ ret = jtag_read_buffer(ulink_cmd->payload_in_start, cmd->cmd.scan);
+ break;
+ case SCAN_OUT:
+ /* Nothing to do for OUT scans */
+ ret = ERROR_OK;
+ break;
+ default:
+ LOG_ERROR("BUG: ulink_post_process_scan() encountered an unknown"
+ " JTAG scan type");
+ ret = ERROR_FAIL;
+ break;
+ }
+
+ return ret;
}
/**
*/
int ulink_post_process_queue(struct ulink *device)
{
- struct ulink_cmd *current;
- struct jtag_command *openocd_cmd;
- int ret;
-
- current = device->queue_start;
-
- while (current != NULL) {
- openocd_cmd = current->cmd_origin;
-
- /* Check if a corresponding OpenOCD command is stored for this
- * OpenULINK command */
- if ((current->needs_postprocessing == true) && (openocd_cmd != NULL)) {
- switch (openocd_cmd->type) {
- case JTAG_SCAN:
- ret = ulink_post_process_scan(current);
- break;
- case JTAG_TLR_RESET:
- case JTAG_RUNTEST:
- case JTAG_RESET:
- case JTAG_PATHMOVE:
- case JTAG_SLEEP:
- case JTAG_STABLECLOCKS:
- /* Nothing to do for these commands */
- ret = ERROR_OK;
- break;
- default:
- ret = ERROR_FAIL;
- LOG_ERROR("BUG: ulink_post_process_queue() encountered unknown JTAG "
- "command type");
- break;
- }
-
- if (ret != ERROR_OK) {
- return ret;
- }
- }
-
- current = current->next;
- }
-
- return ERROR_OK;
+ struct ulink_cmd *current;
+ struct jtag_command *openocd_cmd;
+ int ret;
+
+ current = device->queue_start;
+
+ while (current != NULL) {
+ openocd_cmd = current->cmd_origin;
+
+ /* Check if a corresponding OpenOCD command is stored for this
+ * OpenULINK command */
+ if ((current->needs_postprocessing == true) && (openocd_cmd != NULL)) {
+ switch (openocd_cmd->type) {
+ case JTAG_SCAN:
+ ret = ulink_post_process_scan(current);
+ break;
+ case JTAG_TLR_RESET:
+ case JTAG_RUNTEST:
+ case JTAG_RESET:
+ case JTAG_PATHMOVE:
+ case JTAG_SLEEP:
+ case JTAG_STABLECLOCKS:
+ /* Nothing to do for these commands */
+ ret = ERROR_OK;
+ break;
+ default:
+ ret = ERROR_FAIL;
+ LOG_ERROR("BUG: ulink_post_process_queue() encountered unknown JTAG "
+ "command type");
+ break;
+ }
+
+ if (ret != ERROR_OK)
+ return ret;
+ }
+
+ current = current->next;
+ }
+
+ return ERROR_OK;
}
/**************************** JTAG driver functions ***************************/
*/
static int ulink_execute_queue(void)
{
- struct jtag_command *cmd = jtag_command_queue;
- int ret;
-
- while (cmd) {
- switch (cmd->type) {
- case JTAG_SCAN:
- ret = ulink_queue_scan(ulink_handle, cmd);
- break;
- case JTAG_TLR_RESET:
- ret = ulink_queue_tlr_reset(ulink_handle, cmd);
- break;
- case JTAG_RUNTEST:
- ret = ulink_queue_runtest(ulink_handle, cmd);
- break;
- case JTAG_RESET:
- ret = ulink_queue_reset(ulink_handle, cmd);
- break;
- case JTAG_PATHMOVE:
- ret = ulink_queue_pathmove(ulink_handle, cmd);
- break;
- case JTAG_SLEEP:
- ret = ulink_queue_sleep(ulink_handle, cmd);
- break;
- case JTAG_STABLECLOCKS:
- ret = ulink_queue_stableclocks(ulink_handle, cmd);
- break;
- default:
- ret = ERROR_FAIL;
- LOG_ERROR("BUG: encountered unknown JTAG command type");
- break;
- }
-
- if (ret != ERROR_OK) {
- return ret;
- }
-
- cmd = cmd->next;
- }
-
- if (ulink_handle->commands_in_queue > 0) {
- ret = ulink_execute_queued_commands(ulink_handle, USB_TIMEOUT);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ret = ulink_post_process_queue(ulink_handle);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ulink_clear_queue(ulink_handle);
- }
-
- return ERROR_OK;
+ struct jtag_command *cmd = jtag_command_queue;
+ int ret;
+
+ while (cmd) {
+ switch (cmd->type) {
+ case JTAG_SCAN:
+ ret = ulink_queue_scan(ulink_handle, cmd);
+ break;
+ case JTAG_TLR_RESET:
+ ret = ulink_queue_tlr_reset(ulink_handle, cmd);
+ break;
+ case JTAG_RUNTEST:
+ ret = ulink_queue_runtest(ulink_handle, cmd);
+ break;
+ case JTAG_RESET:
+ ret = ulink_queue_reset(ulink_handle, cmd);
+ break;
+ case JTAG_PATHMOVE:
+ ret = ulink_queue_pathmove(ulink_handle, cmd);
+ break;
+ case JTAG_SLEEP:
+ ret = ulink_queue_sleep(ulink_handle, cmd);
+ break;
+ case JTAG_STABLECLOCKS:
+ ret = ulink_queue_stableclocks(ulink_handle, cmd);
+ break;
+ default:
+ ret = ERROR_FAIL;
+ LOG_ERROR("BUG: encountered unknown JTAG command type");
+ break;
+ }
+
+ if (ret != ERROR_OK)
+ return ret;
+
+ cmd = cmd->next;
+ }
+
+ if (ulink_handle->commands_in_queue > 0) {
+ ret = ulink_execute_queued_commands(ulink_handle, USB_TIMEOUT);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = ulink_post_process_queue(ulink_handle);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ulink_clear_queue(ulink_handle);
+ }
+
+ return ERROR_OK;
}
/**
*/
static int ulink_khz(int khz, int *jtag_speed)
{
- int ret;
-
- if (khz == 0) {
- LOG_ERROR("RCLK not supported");
- return ERROR_FAIL;
- }
-
- /* CLOCK_TCK commands are decoupled from others. Therefore, the frequency
- * setting can be done independently from all other commands. */
- if (khz >= 375) {
- ulink_handle->delay_clock_tck = -1;
- }
- else {
- ret = ulink_calculate_delay(DELAY_CLOCK_TCK, khz * 1000,
- &ulink_handle->delay_clock_tck);
- if (ret != ERROR_OK) {
- return ret;
- }
- }
-
- /* SCAN_{IN,OUT,IO} commands invoke CLOCK_TMS commands. Therefore, if the
- * requested frequency goes below the maximum frequency for SLOW_CLOCK_TMS
- * commands, all SCAN commands MUST also use the variable frequency
- * implementation! */
- if (khz >= 176) {
- ulink_handle->delay_clock_tms = -1;
- ulink_handle->delay_scan_in = -1;
- ulink_handle->delay_scan_out = -1;
- ulink_handle->delay_scan_io = -1;
- }
- else {
- ret = ulink_calculate_delay(DELAY_CLOCK_TMS, khz * 1000,
- &ulink_handle->delay_clock_tms);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ret = ulink_calculate_delay(DELAY_SCAN_IN, khz * 1000,
- &ulink_handle->delay_scan_in);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ret = ulink_calculate_delay(DELAY_SCAN_OUT, khz * 1000,
- &ulink_handle->delay_scan_out);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ret = ulink_calculate_delay(DELAY_SCAN_IO, khz * 1000,
- &ulink_handle->delay_scan_io);
- if (ret != ERROR_OK) {
- return ret;
- }
- }
+ int ret;
+
+ if (khz == 0) {
+ LOG_ERROR("RCLK not supported");
+ return ERROR_FAIL;
+ }
+
+ /* CLOCK_TCK commands are decoupled from others. Therefore, the frequency
+ * setting can be done independently from all other commands. */
+ if (khz >= 375)
+ ulink_handle->delay_clock_tck = -1;
+ else {
+ ret = ulink_calculate_delay(DELAY_CLOCK_TCK, khz * 1000,
+ &ulink_handle->delay_clock_tck);
+ if (ret != ERROR_OK)
+ return ret;
+ }
+
+ /* SCAN_{IN,OUT,IO} commands invoke CLOCK_TMS commands. Therefore, if the
+ * requested frequency goes below the maximum frequency for SLOW_CLOCK_TMS
+ * commands, all SCAN commands MUST also use the variable frequency
+ * implementation! */
+ if (khz >= 176) {
+ ulink_handle->delay_clock_tms = -1;
+ ulink_handle->delay_scan_in = -1;
+ ulink_handle->delay_scan_out = -1;
+ ulink_handle->delay_scan_io = -1;
+ } else {
+ ret = ulink_calculate_delay(DELAY_CLOCK_TMS, khz * 1000,
+ &ulink_handle->delay_clock_tms);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = ulink_calculate_delay(DELAY_SCAN_IN, khz * 1000,
+ &ulink_handle->delay_scan_in);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = ulink_calculate_delay(DELAY_SCAN_OUT, khz * 1000,
+ &ulink_handle->delay_scan_out);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = ulink_calculate_delay(DELAY_SCAN_IO, khz * 1000,
+ &ulink_handle->delay_scan_io);
+ if (ret != ERROR_OK)
+ return ret;
+ }
#ifdef _DEBUG_JTAG_IO_
- long f_tck, f_tms, f_scan_in, f_scan_out, f_scan_io;
-
- ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck,
- &f_tck);
- ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms,
- &f_tms);
- ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in,
- &f_scan_in);
- ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out,
- &f_scan_out);
- ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io,
- &f_scan_io);
-
- DEBUG_JTAG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),",
- ulink_handle->delay_clock_tck, f_tck);
- DEBUG_JTAG_IO(" delay_tms = %i (%li Hz),",
- ulink_handle->delay_clock_tms, f_tms);
- DEBUG_JTAG_IO(" delay_scan_in = %i (%li Hz),",
- ulink_handle->delay_scan_in, f_scan_in);
- DEBUG_JTAG_IO(" delay_scan_out = %i (%li Hz),",
- ulink_handle->delay_scan_out, f_scan_out);
- DEBUG_JTAG_IO(" delay_scan_io = %i (%li Hz),",
- ulink_handle->delay_scan_io, f_scan_io);
+ long f_tck, f_tms, f_scan_in, f_scan_out, f_scan_io;
+
+ ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck,
+ &f_tck);
+ ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms,
+ &f_tms);
+ ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in,
+ &f_scan_in);
+ ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out,
+ &f_scan_out);
+ ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io,
+ &f_scan_io);
+
+ DEBUG_JTAG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),",
+ ulink_handle->delay_clock_tck, f_tck);
+ DEBUG_JTAG_IO(" delay_tms = %i (%li Hz),",
+ ulink_handle->delay_clock_tms, f_tms);
+ DEBUG_JTAG_IO(" delay_scan_in = %i (%li Hz),",
+ ulink_handle->delay_scan_in, f_scan_in);
+ DEBUG_JTAG_IO(" delay_scan_out = %i (%li Hz),",
+ ulink_handle->delay_scan_out, f_scan_out);
+ DEBUG_JTAG_IO(" delay_scan_io = %i (%li Hz),",
+ ulink_handle->delay_scan_io, f_scan_io);
#endif
- /* Configure the ULINK device with the new delay values */
- ret = ulink_append_configure_tck_cmd(ulink_handle,
- ulink_handle->delay_scan_in,
- ulink_handle->delay_scan_out,
- ulink_handle->delay_scan_io,
- ulink_handle->delay_clock_tck,
- ulink_handle->delay_clock_tms);
+ /* Configure the ULINK device with the new delay values */
+ ret = ulink_append_configure_tck_cmd(ulink_handle,
+ ulink_handle->delay_scan_in,
+ ulink_handle->delay_scan_out,
+ ulink_handle->delay_scan_io,
+ ulink_handle->delay_clock_tck,
+ ulink_handle->delay_clock_tms);
- if (ret != ERROR_OK) {
- return ret;
- }
+ if (ret != ERROR_OK)
+ return ret;
- *jtag_speed = khz;
+ *jtag_speed = khz;
- return ERROR_OK;
+ return ERROR_OK;
}
/**
*/
static int ulink_speed(int speed)
{
- int dummy;
+ int dummy;
- return ulink_khz(speed, &dummy);
+ return ulink_khz(speed, &dummy);
}
/**
*/
static int ulink_speed_div(int speed, int *khz)
{
- *khz = speed;
+ *khz = speed;
- return ERROR_OK;
+ return ERROR_OK;
}
/**
*/
static int ulink_init(void)
{
- int ret;
- char str_manufacturer[20];
- bool download_firmware = false;
- uint8_t *dummy;
- uint8_t input_signals, output_signals;
-
- ulink_handle = calloc(1, sizeof(struct ulink));
- if (ulink_handle == NULL) {
- return ERROR_FAIL;
- }
-
- usb_init();
-
- ret = ulink_usb_open(&ulink_handle);
- if (ret != ERROR_OK) {
- LOG_ERROR("Could not open ULINK device");
- return ret;
- }
-
- /* Get String Descriptor to determine if firmware needs to be loaded */
- ret = usb_get_string_simple(ulink_handle->usb_handle, 1, str_manufacturer, 20);
- if (ret < 0) {
- /* Could not get descriptor -> Unconfigured or original Keil firmware */
- download_firmware = true;
- }
- else {
- /* We got a String Descriptor, check if it is the correct one */
- if (strncmp(str_manufacturer, "OpenULINK", 9) != 0) {
- download_firmware = true;
- }
- }
-
- if (download_firmware == true) {
- LOG_INFO("Loading OpenULINK firmware. This is reversible by power-cycling"
- " ULINK device.");
- ret = ulink_load_firmware_and_renumerate(&ulink_handle,
- ULINK_FIRMWARE_FILE, ULINK_RENUMERATION_DELAY);
- if (ret != ERROR_OK) {
- LOG_ERROR("Could not download firmware and re-numerate ULINK");
- return ret;
- }
- }
- else {
- LOG_INFO("ULINK device is already running OpenULINK firmware");
- }
-
- /* Initialize OpenULINK command queue */
- ulink_clear_queue(ulink_handle);
-
- /* Issue one test command with short timeout */
- ret = ulink_append_test_cmd(ulink_handle);
- if (ret != ERROR_OK) {
- return ret;
- }
-
- ret = ulink_execute_queued_commands(ulink_handle, 200);
- if (ret != ERROR_OK) {
- /* Sending test command failed. The ULINK device may be forever waiting for
- * the host to fetch an USB Bulk IN packet (e. g. OpenOCD crashed or was
- * shut down by the user via Ctrl-C. Try to retrieve this Bulk IN packet. */
- dummy = calloc(64, sizeof(uint8_t));
-
- ret = usb_bulk_read(ulink_handle->usb_handle, (2 | USB_ENDPOINT_IN),
- (char *)dummy, 64, 200);
-
- free(dummy);
-
- if (ret < 0) {
- /* Bulk IN transfer failed -> unrecoverable error condition */
- LOG_ERROR("Cannot communicate with ULINK device. Disconnect ULINK from "
- "the USB port and re-connect, then re-run OpenOCD");
- return ERROR_FAIL;
- }
+ int ret;
+ char str_manufacturer[20];
+ bool download_firmware = false;
+ uint8_t *dummy;
+ uint8_t input_signals, output_signals;
+
+ ulink_handle = calloc(1, sizeof(struct ulink));
+ if (ulink_handle == NULL)
+ return ERROR_FAIL;
+
+ usb_init();
+
+ ret = ulink_usb_open(&ulink_handle);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not open ULINK device");
+ return ret;
+ }
+
+ /* Get String Descriptor to determine if firmware needs to be loaded */
+ ret = usb_get_string_simple(ulink_handle->usb_handle, 1, str_manufacturer, 20);
+ if (ret < 0) {
+ /* Could not get descriptor -> Unconfigured or original Keil firmware */
+ download_firmware = true;
+ } else {
+ /* We got a String Descriptor, check if it is the correct one */
+ if (strncmp(str_manufacturer, "OpenULINK", 9) != 0)
+ download_firmware = true;
+ }
+
+ if (download_firmware == true) {
+ LOG_INFO("Loading OpenULINK firmware. This is reversible by power-cycling"
+ " ULINK device.");
+ ret = ulink_load_firmware_and_renumerate(&ulink_handle,
+ ULINK_FIRMWARE_FILE, ULINK_RENUMERATION_DELAY);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not download firmware and re-numerate ULINK");
+ return ret;
+ }
+ } else
+ LOG_INFO("ULINK device is already running OpenULINK firmware");
+
+ /* Initialize OpenULINK command queue */
+ ulink_clear_queue(ulink_handle);
+
+ /* Issue one test command with short timeout */
+ ret = ulink_append_test_cmd(ulink_handle);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = ulink_execute_queued_commands(ulink_handle, 200);
+ if (ret != ERROR_OK) {
+ /* Sending test command failed. The ULINK device may be forever waiting for
+ * the host to fetch an USB Bulk IN packet (e. g. OpenOCD crashed or was
+ * shut down by the user via Ctrl-C. Try to retrieve this Bulk IN packet. */
+ dummy = calloc(64, sizeof(uint8_t));
+
+ ret = usb_bulk_read(ulink_handle->usb_handle, (2 | USB_ENDPOINT_IN),
+ (char *)dummy, 64, 200);
+
+ free(dummy);
+
+ if (ret < 0) {
+ /* Bulk IN transfer failed -> unrecoverable error condition */
+ LOG_ERROR("Cannot communicate with ULINK device. Disconnect ULINK from "
+ "the USB port and re-connect, then re-run OpenOCD");
+ return ERROR_FAIL;
+ }
#ifdef _DEBUG_USB_COMMS_
- else {
- /* Successfully received Bulk IN packet -> continue */
- LOG_INFO("Recovered from lost Bulk IN packet");
- }
+ else {
+ /* Successfully received Bulk IN packet -> continue */
+ LOG_INFO("Recovered from lost Bulk IN packet");
+ }
#endif
- }
- ulink_clear_queue(ulink_handle);
+ }
+ ulink_clear_queue(ulink_handle);
- ulink_append_get_signals_cmd(ulink_handle);
- ulink_execute_queued_commands(ulink_handle, 200);
+ ulink_append_get_signals_cmd(ulink_handle);
+ ulink_execute_queued_commands(ulink_handle, 200);
- /* Post-process the single CMD_GET_SIGNALS command */
- input_signals = ulink_handle->queue_start->payload_in[0];
- output_signals = ulink_handle->queue_start->payload_in[1];
+ /* Post-process the single CMD_GET_SIGNALS command */
+ input_signals = ulink_handle->queue_start->payload_in[0];
+ output_signals = ulink_handle->queue_start->payload_in[1];
- ulink_print_signal_states(input_signals, output_signals);
+ ulink_print_signal_states(input_signals, output_signals);
- ulink_clear_queue(ulink_handle);
+ ulink_clear_queue(ulink_handle);
- return ERROR_OK;
+ return ERROR_OK;
}
/**
*/
static int ulink_quit(void)
{
- int ret;
+ int ret;
- ret = ulink_usb_close(&ulink_handle);
- free(ulink_handle);
+ ret = ulink_usb_close(&ulink_handle);
+ free(ulink_handle);
- return ret;
+ return ret;
}
/**
*/
COMMAND_HANDLER(ulink_download_firmware_handler)
{
- int ret;
+ int ret;
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- LOG_INFO("Downloading ULINK firmware image %s", CMD_ARGV[0]);
+ LOG_INFO("Downloading ULINK firmware image %s", CMD_ARGV[0]);
- /* Download firmware image in CMD_ARGV[0] */
- ret = ulink_load_firmware_and_renumerate(&ulink_handle, (char *)CMD_ARGV[0],
- ULINK_RENUMERATION_DELAY);
+ /* Download firmware image in CMD_ARGV[0] */
+ ret = ulink_load_firmware_and_renumerate(&ulink_handle, (char *)CMD_ARGV[0],
+ ULINK_RENUMERATION_DELAY);
- return ret;
+ return ret;
}
/*************************** Command Registration **************************/
static const struct command_registration ulink_command_handlers[] = {
- {
- .name = "ulink_download_firmware",
- .handler = &ulink_download_firmware_handler,
- .mode = COMMAND_EXEC,
- .help = "download firmware image to ULINK device",
- .usage = "path/to/ulink_firmware.hex",
- },
- COMMAND_REGISTRATION_DONE,
+ {
+ .name = "ulink_download_firmware",
+ .handler = &ulink_download_firmware_handler,
+ .mode = COMMAND_EXEC,
+ .help = "download firmware image to ULINK device",
+ .usage = "path/to/ulink_firmware.hex",
+ },
+ COMMAND_REGISTRATION_DONE,
};
struct jtag_interface ulink_interface = {
- .name = "ulink",
+ .name = "ulink",
- .commands = ulink_command_handlers,
- .transports = jtag_only,
+ .commands = ulink_command_handlers,
+ .transports = jtag_only,
- .execute_queue = ulink_execute_queue,
- .khz = ulink_khz,
- .speed = ulink_speed,
- .speed_div = ulink_speed_div,
+ .execute_queue = ulink_execute_queue,
+ .khz = ulink_khz,
+ .speed = ulink_speed,
+ .speed_div = ulink_speed_div,
- .init = ulink_init,
- .quit = ulink_quit
+ .init = ulink_init,
+ .quit = ulink_quit
};
#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
#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;
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;
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;
#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;
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;
#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
}
{
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);
}
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;
/* 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;
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);
#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);
}
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++)
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]);
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
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;
}
#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;
}
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
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;
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;
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;
}
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;
}
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;
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 */
#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);
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
-
-struct usbprog_jtag
-{
- struct usb_dev_handle* usb_handle;
+#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;
};
-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];
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)
{
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;
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;
}
{
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);
}
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);
}
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 */
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);
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 */
struct usb_bus *busses;
-struct usbprog_jtag* usbprog_jtag_open(void)
+struct usbprog_jtag *usbprog_jtag_open(void)
{
usb_set_debug(10);
usb_init();
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;
}
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;
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++;
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;
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++;
/* 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) */
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++;
}
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;
}
#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;
{
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);
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
}
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);
}
-
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
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);
+ versaloon_cmd_buf, 4 + bytelen * 2, bytelen, tdo, 0, bytelen, 0);
}
-
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
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);
+ 2, 0);
}
-
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
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;
}
}
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;
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);
}
}
-
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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;
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,
}
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;
}
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;
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]),
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;
}
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;
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);
}
{
return usbtodelay_delay(us & 0x7FFF);
}
-
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifndef __USBTOXXX_H_INCLUDED__
#define __USBTOXXX_H_INCLUDED__
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);
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);
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__ */
* 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 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 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 */
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__ */
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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);
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;
{
versaloon_callback = callback;
}
-void versaloon_set_extra_data(void * p)
+void versaloon_set_extra_data(void *p)
{
versaloon_extra_data = p;
}
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);
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;
}
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;
}
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
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;
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;
}
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;
}
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;
}
{
return usbtodelay_delay(us & 0x7FFF);
}
-
* 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;
#include "usbtoxxx/usbtoxxx.h"
-// GPIO pins
+/* GPIO pins */
#define GPIO_SRST (1 << 0)
#define GPIO_TRST (1 << 1)
#define GPIO_USR1 (1 << 2)
#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;
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;
};
* 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"
#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
#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;\
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifndef __VERSALOON_INTERNAL_H_INCLUDED__
#define __VERSALOON_INTERNAL_H_INCLUDED__
#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
#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;
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);
extern uint16_t versaloon_buf_size;
#endif /* __VERSALOON_INTERNAL_H_INCLUDED__ */
-
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);
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 */
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);
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]));
-
- vsllink_path_move(
- cmd->cmd.pathmove->num_states,
- cmd->cmd.pathmove->path);
+ 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);
break;
case JTAG_SCAN:
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);
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:
/* 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;
}
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;
}
{
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;
}
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)
{
{
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);
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);
}
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)
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;
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);
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;
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);
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);
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)
{
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();
}
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;
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
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;
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();
"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;
}
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;
}
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;
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;
- }
}
}
}
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;
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);
}
LOG_DEBUG("%s", line);
}
}
-#endif /* _DEBUG_JTAG_IO_ */
+#endif /* _DEBUG_JTAG_IO_ */
static const struct command_registration vsllink_command_handlers[] = {
{
* 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;
#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 */
* 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,
/* 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,
#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))
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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,
return ERROR_OK;
}
-int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, tap_state_t state)
+int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields,
+ tap_state_t state)
{
/* synchronously do the operation here */
return ERROR_OK;
-
}
-int interface_jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
+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_dr_scan(struct jtag_tap *active, int num_fields, const struct scan_field *fields, 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)
+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 */
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);
}
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);
}
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifndef _STLINK_INTERFACE_
#define _STLINK_INTERFACE_
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifndef _STLINK_LAYOUT_H_
#define _STLINK_LAYOUT_H_
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifndef _STLINK_TCL_
#define _STLINK_TCL_
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+
#ifndef _STLINK_TRANSPORT_
#define _STLINK_TRANSPORT_
#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
#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 */
}
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;
#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();
* 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();
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);
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);
}
#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
#if BUILD_ECOSBOARD
#include "zy1000_version.h"
-#include <cyg/hal/hal_io.h> // low level i/o
+#include <cyg/hal/hal_io.h> /* low level i/o */
#include <cyg/hal/hal_diag.h>
#ifdef CYGPKG_HAL_NIOS2
#define ZYLIN_KHZ 60000
#endif
-
/* The software needs to check if it's in RCLK mode or not */
-static bool zy1000_rclk = false;
+static bool zy1000_rclk;
static int zy1000_khz(int khz, int *jtag_speed)
{
if (khz == 0)
- {
*jtag_speed = 0;
- }
- else
- {
+ else {
int speed;
/* Round speed up to nearest divisor.
*
* 64000 / 6 = 10666
*
*/
- speed = (ZYLIN_KHZ + (khz -1)) / khz;
- speed = (speed + 1 ) / 2;
+ speed = (ZYLIN_KHZ + (khz - 1)) / khz;
+ speed = (speed + 1) / 2;
speed *= 2;
- if (speed > 8190)
- {
+ if (speed > 8190) {
/* maximum dividend */
speed = 8190;
}
static int zy1000_speed_div(int speed, int *khz)
{
if (speed == 0)
- {
*khz = 0;
- }
else
- {
*khz = ZYLIN_KHZ / speed;
- }
return ERROR_OK;
}
static bool readPowerDropout(void)
{
uint32_t state;
- // sample and clear power dropout
+ /* sample and clear power dropout */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x80);
ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, state);
bool powerDropout;
static bool readSRST(void)
{
uint32_t state;
- // sample and clear SRST sensing
+ /* sample and clear SRST sensing */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x00000040);
ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, state);
bool srstAsserted;
long total = 0;
const char *mode = asserted ? "assert" : "deassert";
- for (;;)
- {
+ for (;; ) {
bool srstAsserted = readSRST();
- if ( (asserted && srstAsserted) || (!asserted && !srstAsserted) )
- {
+ if ((asserted && srstAsserted) || (!asserted && !srstAsserted)) {
if (total > 1)
- {
LOG_USER("SRST took %dms to %s", (int)total, mode);
- }
break;
}
- if (first)
- {
+ if (first) {
first = false;
start = timeval_ms();
}
keep_alive();
- if (total > 5000)
- {
+ if (total > 5000) {
LOG_ERROR("SRST took too long to %s: %dms", mode, (int)total);
break;
}
}
}
-
void zy1000_reset(int trst, int srst)
{
LOG_DEBUG("zy1000 trst=%d, srst=%d", trst, srst);
waitIdle();
if (!srst)
- {
ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x00000001);
- }
- else
- {
+ else {
/* Danger!!! if clk != 0 when in
* idle in TAP_IDLE, reset halt on str912 will fail.
*/
}
if (!trst)
- {
ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x00000002);
- }
- else
- {
+ else {
/* assert reset */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x00000002);
}
- if (trst||(srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
- {
+ if (trst || (srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) {
/* we're now in the RESET state until trst is deasserted */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_RESET);
- } else
- {
+ } else {
/* We'll get RCLK failure when we assert TRST, so clear any false positives here */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x400);
}
/* wait for srst to float back up */
- if ((!srst && ((jtag_get_reset_config() & RESET_TRST_PULLS_SRST) == 0))||
- (!srst && !trst && (jtag_get_reset_config() & RESET_TRST_PULLS_SRST)))
- {
+ if ((!srst && ((jtag_get_reset_config() & RESET_TRST_PULLS_SRST) == 0)) ||
+ (!srst && !trst && (jtag_get_reset_config() & RESET_TRST_PULLS_SRST)))
waitSRST(false);
- }
}
int zy1000_speed(int speed)
zy1000_rclk = false;
- if (speed == 0)
- {
+ if (speed == 0) {
/*0 means RCLK*/
ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x100);
zy1000_rclk = true;
LOG_DEBUG("jtag_speed using RCLK");
- }
- else
- {
- if (speed > 8190 || speed < 2)
- {
- LOG_USER("valid ZY1000 jtag_speed=[8190,2]. With divisor is %dkHz / even values between 8190-2, i.e. min %dHz, max %dMHz",
- ZYLIN_KHZ, (ZYLIN_KHZ * 1000) / 8190, ZYLIN_KHZ / (2 * 1000));
+ } else {
+ if (speed > 8190 || speed < 2) {
+ LOG_USER(
+ "valid ZY1000 jtag_speed=[8190,2]. With divisor is %dkHz / even values between 8190-2, i.e. min %dHz, max %dMHz",
+ ZYLIN_KHZ,
+ (ZYLIN_KHZ * 1000) / 8190,
+ ZYLIN_KHZ / (2 * 1000));
return ERROR_COMMAND_SYNTAX_ERROR;
}
static bool savePower;
-
static void setPower(bool power)
{
savePower = power;
if (power)
- {
ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x8);
- } else
- {
+ else
ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x8);
- }
}
COMMAND_HANDLER(handle_power_command)
{
- switch (CMD_ARGC)
- {
- case 1: {
- bool enable;
- COMMAND_PARSE_ON_OFF(CMD_ARGV[0], enable);
- setPower(enable);
- // fall through
- }
- case 0:
- LOG_INFO("Target power %s", savePower ? "on" : "off");
- break;
- default:
- return ERROR_COMMAND_SYNTAX_ERROR;
+ switch (CMD_ARGC) {
+ case 1: {
+ bool enable;
+ COMMAND_PARSE_ON_OFF(CMD_ARGV[0], enable);
+ setPower(enable);
+ /* fall through */
+ }
+ case 0:
+ LOG_INFO("Target power %s", savePower ? "on" : "off");
+ break;
+ default:
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
#if !BUILD_ZY1000_MASTER
static char *tcp_server = "notspecified";
-static int jim_zy1000_server(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+static int jim_zy1000_server(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
if (argc != 2)
return JIM_ERR;
#if BUILD_ECOSBOARD
/* Give TELNET a way to find out what version this is */
-static int jim_zy1000_version(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+static int jim_zy1000_version(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
if ((argc < 1) || (argc > 3))
return JIM_ERR;
const char *version_str = NULL;
if (argc == 1)
- {
version_str = ZYLIN_OPENOCD_VERSION;
- } else
- {
+ else {
const char *str = Jim_GetString(argv[1], NULL);
const char *str2 = NULL;
if (argc > 2)
str2 = Jim_GetString(argv[2], NULL);
if (strcmp("openocd", str) == 0)
- {
version_str = ZYLIN_OPENOCD;
- }
else if (strcmp("zy1000", str) == 0)
- {
version_str = ZYLIN_VERSION;
- }
else if (strcmp("date", str) == 0)
- {
version_str = ZYLIN_DATE;
- }
else if (strcmp("time", str) == 0)
- {
version_str = ZYLIN_TIME;
- }
- else if (strcmp("pcb", str) == 0)
- {
+ else if (strcmp("pcb", str) == 0) {
#ifdef CYGPKG_HAL_NIOS2
- version_str="c";
+ version_str = "c";
#else
- version_str="b";
+ version_str = "b";
#endif
}
#ifdef CYGPKG_HAL_NIOS2
- else if (strcmp("fpga", str) == 0)
- {
+ else if (strcmp("fpga", str) == 0) {
/* return a list of 32 bit integers to describe the expected
* and actual FPGA
uint32_t id, timestamp;
HAL_READ_UINT32(SYSID_BASE, id);
HAL_READ_UINT32(SYSID_BASE+4, timestamp);
- sprintf(fpga_id, "0x%08x 0x%08x 0x%08x 0x%08x", id, timestamp, SYSID_ID, SYSID_TIMESTAMP);
+ sprintf(fpga_id,
+ "0x%08x 0x%08x 0x%08x 0x%08x",
+ id,
+ timestamp,
+ SYSID_ID,
+ SYSID_TIMESTAMP);
version_str = fpga_id;
- if ((argc>2) && (strcmp("time", str2) == 0))
- {
- time_t last_mod = timestamp;
- char * t = ctime (&last_mod) ;
- t[strlen(t)-1] = 0;
- version_str = t;
+ if ((argc > 2) && (strcmp("time", str2) == 0)) {
+ time_t last_mod = timestamp;
+ char *t = ctime(&last_mod);
+ t[strlen(t)-1] = 0;
+ version_str = t;
}
}
#endif
else
- {
return JIM_ERR;
- }
}
Jim_SetResult(interp, Jim_NewStringObj(interp, version_str, -1));
#ifdef CYGPKG_HAL_NIOS2
-struct info_forward
-{
+struct info_forward {
void *data;
struct cyg_upgrade_info *upgraded_file;
};
-static void report_info(void *data, const char * format, va_list args)
+static void report_info(void *data, const char *format, va_list args)
{
char *s = alloc_vprintf(format, args);
LOG_USER_N("%s", s);
free(s);
}
-struct cyg_upgrade_info firmware_info =
-{
- (uint8_t *)0x84000000,
- "/ram/firmware.phi",
- "Firmware",
- 0x0300000,
- 0x1f00000 -
- 0x0300000,
- "ZylinNiosFirmware\n",
- report_info,
+struct cyg_upgrade_info firmware_info = {
+ (uint8_t *)0x84000000,
+ "/ram/firmware.phi",
+ "Firmware",
+ 0x0300000,
+ 0x1f00000 -
+ 0x0300000,
+ "ZylinNiosFirmware\n",
+ report_info,
};
-// File written to /ram/firmware.phi before arriving at this fn
-static int jim_zy1000_writefirmware(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+/* File written to /ram/firmware.phi before arriving at this fn */
+static int jim_zy1000_writefirmware(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
if (argc != 1)
return JIM_ERR;
}
#endif
-static int
-zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
- int argc,
- Jim_Obj * const *argv)
+static int zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
+ int argc,
+ Jim_Obj * const *argv)
{
- if (argc != 1)
- {
+ if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "powerstatus");
return JIM_ERR;
}
return JIM_OK;
}
-
-
int zy1000_quit(void)
{
return ERROR_OK;
}
-
-
int interface_jtag_execute_queue(void)
{
uint32_t empty;
/* and handle any callbacks... */
zy1000_flush_callbackqueue();
- if (zy1000_rclk)
- {
+ if (zy1000_rclk) {
/* Only check for errors when using RCLK to speed up
* jtag over TCP/IP
*/
/* clear JTAG error register */
ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x400);
- if ((empty&0x400) != 0)
- {
+ if ((empty&0x400) != 0) {
LOG_WARNING("RCLK timeout");
/* the error is informative only as we don't want to break the firmware if there
* is a false positive.
*/
- // return ERROR_FAIL;
+ /* return ERROR_FAIL; */
}
}
return ERROR_OK;
}
-
-
-
static void writeShiftValue(uint8_t *data, int bits);
-// here we shuffle N bits out/in
-static __inline void scanBits(const uint8_t *out_value, uint8_t *in_value, int num_bits, bool pause_now, tap_state_t shiftState, tap_state_t end_state)
+/* here we shuffle N bits out/in */
+static inline void scanBits(const uint8_t *out_value,
+ uint8_t *in_value,
+ int num_bits,
+ bool pause_now,
+ tap_state_t shiftState,
+ tap_state_t end_state)
{
tap_state_t pause_state = shiftState;
- for (int j = 0; j < num_bits; j += 32)
- {
+ for (int j = 0; j < num_bits; j += 32) {
int k = num_bits - j;
- if (k > 32)
- {
+ if (k > 32) {
k = 32;
/* we have more to shift out */
- } else if (pause_now)
- {
+ } else if (pause_now) {
/* this was the last to shift out this time */
pause_state = end_state;
}
- // we have (num_bits + 7)/8 bytes of bits to toggle out.
- // bits are pushed out LSB to MSB
+ /* we have (num_bits + 7)/8 bytes of bits to toggle out. */
+ /* bits are pushed out LSB to MSB */
uint32_t value;
value = 0;
- if (out_value != NULL)
- {
+ if (out_value != NULL) {
for (int l = 0; l < k; l += 8)
- {
- value|=out_value[(j + l)/8]<<l;
- }
+ value |= out_value[(j + l)/8]<<l;
}
/* mask away unused bits for easier debugging */
if (k < 32)
- {
- value&=~(((uint32_t)0xffffffff) << k);
- } else
- {
+ value &= ~(((uint32_t)0xffffffff) << k);
+ else {
/* Shifting by >= 32 is not defined by the C standard
* and will in fact shift by &0x1f bits on nios */
}
shiftValueInner(shiftState, pause_state, k, value);
if (in_value != NULL)
- {
writeShiftValue(in_value + (j/8), k);
- }
}
}
-static __inline void scanFields(int num_fields, const struct scan_field *fields, tap_state_t shiftState, tap_state_t end_state)
+static inline void scanFields(int num_fields,
+ const struct scan_field *fields,
+ tap_state_t shiftState,
+ tap_state_t end_state)
{
- for (int i = 0; i < num_fields; i++)
- {
+ for (int i = 0; i < num_fields; i++) {
scanBits(fields[i].out_value,
- fields[i].in_value,
- fields[i].num_bits,
- (i == num_fields-1),
- shiftState,
- end_state);
+ fields[i].in_value,
+ fields[i].num_bits,
+ (i == num_fields-1),
+ shiftState,
+ end_state);
}
}
-int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, tap_state_t state)
+int interface_jtag_add_ir_scan(struct jtag_tap *active,
+ const struct scan_field *fields,
+ tap_state_t state)
{
int scan_size = 0;
struct jtag_tap *tap, *nextTap;
tap_state_t pause_state = TAP_IRSHIFT;
- 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)
- {
+ if (nextTap == NULL)
pause_state = state;
- }
scan_size = tap->ir_length;
/* search the list */
- if (tap == active)
- {
+ if (tap == active) {
scanFields(1, fields, TAP_IRSHIFT, pause_state);
/* update device information */
buf_cpy(fields[0].out_value, tap->cur_instr, scan_size);
tap->bypass = 0;
- } else
- {
+ } else {
/* if a device isn't listed, set it to BYPASS */
assert(scan_size <= 32);
shiftValueInner(TAP_IRSHIFT, pause_state, scan_size, 0xffffffff);
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_plain_ir_scan(int num_bits,
+ const uint8_t *out_bits,
+ uint8_t *in_bits,
+ tap_state_t state)
{
scanBits(out_bits, in_bits, num_bits, true, TAP_IRSHIFT, state);
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_dr_scan(struct jtag_tap *active,
+ int num_fields,
+ const struct scan_field *fields,
+ tap_state_t state)
{
struct jtag_tap *tap, *nextTap;
tap_state_t pause_state = TAP_DRSHIFT;
- 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)
- {
+ if (nextTap == NULL)
pause_state = state;
- }
/* Find a range of fields to write to this tap */
- if (tap == active)
- {
+ if (tap == active) {
assert(!tap->bypass);
scanFields(num_fields, fields, TAP_DRSHIFT, pause_state);
- } else
- {
+ } else {
/* Shift out a 0 for disabled tap's */
assert(tap->bypass);
shiftValueInner(TAP_DRSHIFT, pause_state, 1, 0);
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_plain_dr_scan(int num_bits,
+ const uint8_t *out_bits,
+ uint8_t *in_bits,
+ tap_state_t state)
{
scanBits(out_bits, in_bits, num_bits, true, TAP_DRSHIFT, state);
return ERROR_OK;
return ERROR_OK;
}
-
int interface_jtag_add_reset(int req_trst, int req_srst)
{
zy1000_reset(req_trst, req_srst);
/* execute num_cycles, 32 at the time. */
int i;
- for (i = 0; i < num_cycles; i += 32)
- {
+ for (i = 0; i < num_cycles; i += 32) {
int num;
num = 32;
if (num_cycles-i < num)
- {
num = num_cycles-i;
- }
shiftValueInner(clockstate, clockstate, num, 0);
}
uint8_t tms_scan = tap_get_tms_path(t, 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;
waitIdle();
ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, tms);
/*wait for the fifo to be empty*/
waitIdle();
- for (unsigned i = 0; i < num_bits; i++)
- {
+ for (unsigned i = 0; i < num_bits; i++) {
int tms;
if (((seq[i/8] >> (i % 8)) & 1) == 0)
- {
tms = 0;
- }
else
- {
tms = 1;
- }
waitIdle();
ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, tms);
waitIdle();
if (state != TAP_INVALID)
- {
ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, state);
- } else
- {
- /* this would be normal if we are switching to SWD mode */
+ else {
+ /* this would be normal if
+ * we are switching to SWD mode */
}
return ERROR_OK;
}
memset(seq, 0, sizeof(seq));
assert(num_states < (int)((sizeof(seq) * 8)));
- 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);
}
bool found = false;
struct jtag_tap *cur_tap, *nextTap;
- for (cur_tap = jtag_tap_next_enabled(NULL); cur_tap!= NULL; cur_tap = nextTap)
- {
+ for (cur_tap = jtag_tap_next_enabled(NULL); cur_tap != NULL; cur_tap = nextTap) {
nextTap = jtag_tap_next_enabled(cur_tap);
if (cur_tap == tap)
- {
found = true;
- } else
- {
+ else {
if (found)
- {
post_bits++;
- } else
- {
+ else
pre_bits++;
- }
}
}
*pre = pre_bits;
*post = post_bits;
}
-/*
- static const int embeddedice_num_bits[] = {32, 6};
+#if 0
+static const int embeddedice_num_bits[] = {32, 6};
uint32_t values[2];
values[0] = value;
values[1] = (1 << 5) | reg_addr;
- jtag_add_dr_out(tap,
- 2,
- embeddedice_num_bits,
- values,
- TAP_IDLE);
-*/
+ jtag_add_dr_out(tap, 2, embeddedice_num_bits, values, TAP_IDLE);
+#endif
-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)
{
#if 0
int i;
- for (i = 0; i < count; i++)
- {
- embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little));
+ for (i = 0; i < count; i++) {
+ embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer,
+ little));
buffer += 4;
}
#else
int post_bits;
jtag_pre_post_bits(tap, &pre_bits, &post_bits);
- if ((pre_bits > 32) || (post_bits + 6 > 32))
- {
+ if ((pre_bits > 32) || (post_bits + 6 > 32)) {
int i;
- for (i = 0; i < count; i++)
- {
- embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little));
+ for (i = 0; i < count; i++) {
+ embeddedice_write_reg_inner(tap, reg_addr,
+ fast_target_buffer_get_u32(buffer, little));
buffer += 4;
}
- } else
- {
+ } else {
int i;
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
/* Fewer pokes means we get to use the FIFO more efficiently */
shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, pre_bits, 0);
- shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, little));
+ shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32,
+ fast_target_buffer_get_u32(buffer, little));
/* Danger! here we need to exit into the TAP_IDLE state to make
* DCC pick up this value.
*/
- shiftValueInner(TAP_DRSHIFT, TAP_IDLE, 6 + post_bits, (reg_addr | (1 << 5)));
+ shiftValueInner(TAP_DRSHIFT, TAP_IDLE, 6 + post_bits,
+ (reg_addr | (1 << 5)));
buffer += 4;
}
}
#endif
}
-
-
-int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap * tap, uint32_t opcode, const uint32_t * data, size_t count)
+int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap,
+ uint32_t opcode,
+ const uint32_t *data,
+ size_t count)
{
/* bypass bits before and after */
int pre_bits;
int post_bits;
jtag_pre_post_bits(tap, &pre_bits, &post_bits);
- post_bits+=2;
+ post_bits += 2;
- if ((pre_bits > 32) || (post_bits > 32))
- {
- int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *, uint32_t, const uint32_t *, size_t);
+ if ((pre_bits > 32) || (post_bits > 32)) {
+ int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *,
+ uint32_t, const uint32_t *, size_t);
return arm11_run_instr_data_to_core_noack_inner_default(tap, opcode, data, count);
- } else
- {
+ } else {
static const int bits[] = {32, 2};
uint32_t values[] = {0, 0};
* with unaligned uint32_t * pointers... */
const uint8_t *t = (const uint8_t *)data;
- while (--count > 0)
- {
+ while (--count > 0) {
#if 1
/* Danger! This code doesn't update cmd_queue_cur_state, so
* invoking jtag_add_pathmove() before jtag_add_dr_out() after
shiftValueInner(TAP_DRSHIFT, TAP_DRPAUSE, post_bits, 0);
/* copy & paste from arm11_dbgtap.c */
- //TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE, TAP_IDLE, TAP_IDLE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DRSHIFT
+ /* TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE, TAP_IDLE, TAP_IDLE, TAP_DRSELECT,
+ * TAP_DRCAPTURE, TAP_DRSHIFT */
/* KLUDGE! we have to flush the fifo or the Nios CPU locks up.
* This is probably a bug in the Avalon bus(cross clocking bridge?)
* or in the jtag registers module.
ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT);
waitIdle();
#else
- static const tap_state_t arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay[] =
- {
- TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE, TAP_IDLE, TAP_IDLE, TAP_DRSELECT, TAP_DRCAPTURE, TAP_DRSHIFT
+ static const tap_state_t arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay[] = {
+ TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE, TAP_IDLE, TAP_IDLE,
+ TAP_DRSELECT, TAP_DRCAPTURE, TAP_DRSHIFT
};
values[0] = *t++;
}
}
-
static const struct command_registration zy1000_commands[] = {
{
.name = "power",
COMMAND_REGISTRATION_DONE
};
-
#if !BUILD_ZY1000_MASTER
static int tcp_ip = -1;
static bool writeLong(uint32_t l)
{
int i;
- for (i = 0; i < 4; i++)
- {
+ for (i = 0; i < 4; i++) {
uint8_t c = (l >> (i*8))&0xff;
out_buffer[out_pos++] = c;
- if (out_pos >= sizeof(out_buffer))
- {
+ if (out_pos >= sizeof(out_buffer)) {
if (!flush_writes())
- {
return false;
- }
}
}
return true;
{
uint32_t data = 0;
int i;
- for (i = 0; i < 4; i++)
- {
+ for (i = 0; i < 4; i++) {
uint8_t c;
- if (in_pos == in_write)
- {
+ if (in_pos == in_write) {
/* If we have some data that we can send, send them before
* we wait for more data
*/
- if (out_pos > 0)
- {
+ if (out_pos > 0) {
if (!flush_writes())
- {
return false;
- }
}
/* read more */
int t;
t = read(tcp_ip, in_buffer, sizeof(in_buffer));
if (t < 1)
- {
return false;
- }
in_write = (size_t) t;
in_pos = 0;
}
return true;
}
-enum ZY1000_CMD
-{
+enum ZY1000_CMD {
ZY1000_CMD_POKE = 0x0,
ZY1000_CMD_PEEK = 0x8,
ZY1000_CMD_SLEEP = 0x1,
ZY1000_CMD_WAITIDLE = 2
};
-#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
-#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
+#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
+#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
/* We initialize this late since we need to know the server address
* first.
if (tcp_ip >= 0)
return;
- struct sockaddr_in echoServAddr; /* Echo server address */
+ struct sockaddr_in echoServAddr;/* Echo server address */
/* Create a reliable, stream socket using TCP */
- if ((tcp_ip = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
- {
+ tcp_ip = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (tcp_ip < 0) {
fprintf(stderr, "Failed to connect to zy1000 server\n");
exit(-1);
}
/* Construct the server address structure */
- memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */
- echoServAddr.sin_family = AF_INET; /* Internet address family */
- echoServAddr.sin_addr.s_addr = inet_addr(tcp_server); /* Server IP address */
- echoServAddr.sin_port = htons(7777); /* Server port */
+ memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */
+ echoServAddr.sin_family = AF_INET; /* Internet address family */
+ echoServAddr.sin_addr.s_addr = inet_addr(tcp_server); /* Server IP address */
+ echoServAddr.sin_port = htons(7777); /* Server port */
/* Establish the connection to the echo server */
- if (connect(tcp_ip, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
- {
+ if (connect(tcp_ip, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) {
fprintf(stderr, "Failed to connect to zy1000 server\n");
exit(-1);
}
int flag = 1;
setsockopt(tcp_ip, /* socket affected */
- IPPROTO_TCP, /* set option at TCP level */
- TCP_NODELAY, /* name of option */
- (char *)&flag, /* the cast is historical cruft */
- sizeof(int)); /* length of option value */
+ IPPROTO_TCP, /* set option at TCP level */
+ TCP_NODELAY, /* name of option */
+ (char *)&flag, /* the cast is historical cruft */
+ sizeof(int)); /* length of option value */
}
-
/* send a poke */
void zy1000_tcpout(uint32_t address, uint32_t data)
{
tcpip_open();
- if (!writeLong((ZY1000_CMD_POKE << 24) | address)||
- !writeLong(data))
- {
+ if (!writeLong((ZY1000_CMD_POKE << 24) | address) || !writeLong(data)) {
fprintf(stderr, "Could not write to zy1000 server\n");
exit(-1);
}
void waitIdle(void)
{
tcpip_open();
- if (!writeLong((ZY1000_CMD_WAITIDLE << 24)))
- {
+ if (!writeLong((ZY1000_CMD_WAITIDLE << 24))) {
fprintf(stderr, "Could not write to zy1000 server\n");
exit(-1);
}
zy1000_flush_readqueue();
uint32_t data;
- if (!writeLong((ZY1000_CMD_PEEK << 24) | address)||
- !readLong(&data))
- {
+ if (!writeLong((ZY1000_CMD_PEEK << 24) | address) || !readLong(&data)) {
fprintf(stderr, "Could not read from zy1000 server\n");
exit(-1);
}
int interface_jtag_add_sleep(uint32_t us)
{
tcpip_open();
- if (!writeLong((ZY1000_CMD_SLEEP << 24))||
- !writeLong(us))
- {
+ if (!writeLong((ZY1000_CMD_SLEEP << 24)) || !writeLong(us)) {
fprintf(stderr, "Could not read from zy1000 server\n");
exit(-1);
}
/* queue a readback */
#define readqueue_size 16384
-static struct
-{
+static struct {
uint8_t *dest;
int bits;
} readqueue[readqueue_size];
-static int readqueue_pos = 0;
+static int readqueue_pos;
/* flush the readqueue, this means reading any data that
* we're expecting and store them into the final position
*/
void zy1000_flush_readqueue(void)
{
- if (readqueue_pos == 0)
- {
+ if (readqueue_pos == 0) {
/* simply debugging by allowing easy breakpoints when there
* is something to do. */
return;
}
int i;
tcpip_open();
- for (i = 0; i < readqueue_pos; i++)
- {
+ for (i = 0; i < readqueue_pos; i++) {
uint32_t value;
- if (!readLong(&value))
- {
+ if (!readLong(&value)) {
fprintf(stderr, "Could not read from zy1000 server\n");
exit(-1);
}
uint8_t *in_value = readqueue[i].dest;
int k = readqueue[i].bits;
- // we're shifting in data to MSB, shift data to be aligned for returning the value
+ /* we're shifting in data to MSB, shift data to be aligned for returning the value */
value >>= 32-k;
for (int l = 0; l < k; l += 8)
- {
- in_value[l/8]=(value >> l)&0xff;
- }
+ in_value[l/8] = (value >> l)&0xff;
}
readqueue_pos = 0;
}
/* By queuing the callback's we avoid flushing the
-read queue until jtag_execute_queue(). This can
-reduce latency dramatically for cases where
-callbacks are used extensively.
+ * read queue until jtag_execute_queue(). This can
+ * reduce latency dramatically for cases where
+ * callbacks are used extensively.
*/
#define callbackqueue_size 128
-static struct callbackentry
-{
+static struct callbackentry {
jtag_callback_t callback;
jtag_callback_data_t data0;
jtag_callback_data_t data1;
jtag_callback_data_t data3;
} callbackqueue[callbackqueue_size];
-static int callbackqueue_pos = 0;
+static int callbackqueue_pos;
-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)
{
if (callbackqueue_pos >= callbackqueue_size)
- {
zy1000_flush_callbackqueue();
- }
callbackqueue[callbackqueue_pos].callback = callback;
callbackqueue[callbackqueue_pos].data0 = data0;
zy1000_flush_callbackqueue();
}
-static int zy1000_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 zy1000_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;
void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0)
{
- zy1000_jtag_add_callback4(zy1000_jtag_convert_to_callback4, data0, (jtag_callback_data_t)callback, 0, 0);
+ zy1000_jtag_add_callback4(zy1000_jtag_convert_to_callback4,
+ data0,
+ (jtag_callback_data_t)callback,
+ 0,
+ 0);
}
void zy1000_flush_callbackqueue(void)
{
/* we have to flush the read queue so we have access to
- the data the callbacks will use
+ the data the callbacks will use
*/
zy1000_flush_readqueue();
int i;
- for (i = 0; i < callbackqueue_pos; i++)
- {
+ for (i = 0; i < callbackqueue_pos; i++) {
struct callbackentry *entry = &callbackqueue[i];
- jtag_set_error(entry->callback(entry->data0, entry->data1, entry->data2, entry->data3));
+ jtag_set_error(entry->callback(entry->data0, entry->data1, entry->data2,
+ entry->data3));
}
callbackqueue_pos = 0;
}
{
waitIdle();
- if (!writeLong((ZY1000_CMD_PEEK << 24) | (ZY1000_JTAG_BASE + 0xc)))
- {
+ if (!writeLong((ZY1000_CMD_PEEK << 24) | (ZY1000_JTAG_BASE + 0xc))) {
fprintf(stderr, "Could not read from zy1000 server\n");
exit(-1);
}
if (readqueue_pos >= readqueue_size)
- {
zy1000_flush_readqueue();
- }
readqueue[readqueue_pos].dest = data;
readqueue[readqueue_pos].bits = bits;
ZY1000_PEEK(ZY1000_JTAG_BASE + 0xc, value);
VERBOSE(LOG_INFO("getShiftValue %08x", value));
- // data in, LSB to MSB
- // we're shifting in data to MSB, shift data to be aligned for returning the value
+ /* data in, LSB to MSB */
+ /* we're shifting in data to MSB, shift data to be aligned for returning the value */
value >>= 32 - bits;
for (int l = 0; l < bits; l += 8)
- {
- data[l/8]=(value >> l)&0xff;
- }
+ data[l/8] = (value >> l)&0xff;
}
#endif
{
int so_reuseaddr_option = 1;
- int fd;
- if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
- {
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd == -1) {
LOG_ERROR("error creating socket: %s", strerror(errno));
exit(-1);
}
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*) &so_reuseaddr_option,
- sizeof(int));
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &so_reuseaddr_option,
+ sizeof(int));
struct sockaddr_in sin;
unsigned int address_size;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(8888);
- if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) == -1)
- {
+ if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
LOG_ERROR("couldn't bind to socket: %s", strerror(errno));
exit(-1);
}
- if (listen(fd, 1) == -1)
- {
+ if (listen(fd, 1) == -1) {
LOG_ERROR("couldn't listen on socket: %s", strerror(errno));
exit(-1);
}
- for (;;)
- {
+ for (;; ) {
int watchdog_ip = accept(fd, (struct sockaddr *) &sin, &address_size);
/* Start watchdog, must be reset every 10 seconds. */
HAL_WRITE_UINT32(WATCHDOG_BASE + 4, 4);
- if (watchdog_ip < 0)
- {
+ if (watchdog_ip < 0) {
LOG_ERROR("couldn't open watchdog socket: %s", strerror(errno));
exit(-1);
}
int flag = 1;
setsockopt(watchdog_ip, /* socket affected */
- IPPROTO_TCP, /* set option at TCP level */
- TCP_NODELAY, /* name of option */
- (char *)&flag, /* the cast is historical cruft */
- sizeof(int)); /* length of option value */
+ IPPROTO_TCP, /* set option at TCP level */
+ TCP_NODELAY, /* name of option */
+ (char *)&flag, /* the cast is historical cruft */
+ sizeof(int)); /* length of option value */
char buf;
- for (;;)
- {
- if (read(watchdog_ip, &buf, 1) == 1)
- {
+ for (;; ) {
+ if (read(watchdog_ip, &buf, 1) == 1) {
/* Reset timer */
HAL_WRITE_UINT32(WATCHDOG_BASE + 8, 0x1234);
/* Echo so we can telnet in and see that resetting works */
write(watchdog_ip, &buf, 1);
- } else
- {
+ } else {
/* Stop tickling the watchdog, the CPU will reset in < 10 seconds
* now.
*/
#if BUILD_ECOSBOARD
LOG_USER("%s", ZYLIN_OPENOCD_VERSION);
#elif BUILD_ZY1000_MASTER
- int fd;
- if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
- {
- LOG_ERROR("No access to /dev/mem");
- return ERROR_FAIL;
- }
+ int fd = open("/dev/mem", O_RDWR | O_SYNC);
+ if (fd == -1) {
+ LOG_ERROR("No access to /dev/mem");
+ return ERROR_FAIL;
+ }
#ifndef REGISTERS_BASE
#define REGISTERS_BASE 0x9002000
#define REGISTERS_SPAN 128
#endif
-
- zy1000_jtag_master = mmap(0, REGISTERS_SPAN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, REGISTERS_BASE);
-
- if(zy1000_jtag_master == (void *) -1)
- {
- close(fd);
- LOG_ERROR("No access to /dev/mem");
- return ERROR_FAIL;
- }
-#endif
-
+ zy1000_jtag_master = mmap(0,
+ REGISTERS_SPAN,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ fd,
+ REGISTERS_BASE);
+
+ if (zy1000_jtag_master == (void *) -1) {
+ close(fd);
+ LOG_ERROR("No access to /dev/mem");
+ return ERROR_FAIL;
+ }
+#endif
- ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x30); // Turn on LED1 & LED2
-
- setPower(true); // on by default
+ ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x30); /* Turn on LED1 & LED2 */
+ setPower(true); /* on by default */
- /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
+ /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
zy1000_reset(0, 0);
#if BUILD_ZY1000_MASTER
#if BUILD_ECOSBOARD
#ifdef WATCHDOG_BASE
cyg_thread_create(1, watchdog_server, (cyg_addrword_t) 0, "watchdog tcip/ip server",
- (void *) watchdog_stack, sizeof(watchdog_stack),
- &watchdog_thread_handle, &watchdog_thread_object);
+ (void *) watchdog_stack, sizeof(watchdog_stack),
+ &watchdog_thread_handle, &watchdog_thread_object);
cyg_thread_resume(watchdog_thread_handle);
#endif
#endif
return ERROR_OK;
}
-
-
-struct jtag_interface zy1000_interface =
-{
+struct jtag_interface zy1000_interface = {
.name = "ZY1000",
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = NULL,