build: cleanup src/jtag/drivers directory
authorSpencer Oliver <spen@spen-soft.co.uk>
Thu, 2 Feb 2012 15:08:51 +0000 (15:08 +0000)
committerSpencer Oliver <spen@spen-soft.co.uk>
Mon, 6 Feb 2012 10:59:07 +0000 (10:59 +0000)
Change-Id: I99c08ec0132d5a15250050e718310f1ddd9fe546
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/425
Tested-by: jenkins
64 files changed:
src/jtag/drivers/OpenULINK/include/delay.h
src/jtag/drivers/OpenULINK/include/io.h
src/jtag/drivers/OpenULINK/include/jtag.h
src/jtag/drivers/OpenULINK/include/reg_ezusb.h
src/jtag/drivers/OpenULINK/include/usb.h
src/jtag/drivers/OpenULINK/src/delay.c
src/jtag/drivers/OpenULINK/src/jtag.c
src/jtag/drivers/OpenULINK/src/main.c
src/jtag/drivers/OpenULINK/src/protocol.c
src/jtag/drivers/OpenULINK/src/usb.c
src/jtag/drivers/amt_jtagaccel.c
src/jtag/drivers/arm-jtag-ew.c
src/jtag/drivers/at91rm9200.c
src/jtag/drivers/bitbang.c
src/jtag/drivers/bitbang.h
src/jtag/drivers/bitq.c
src/jtag/drivers/bitq.h
src/jtag/drivers/buspirate.c
src/jtag/drivers/driver.c
src/jtag/drivers/dummy.c
src/jtag/drivers/ep93xx.c
src/jtag/drivers/ft2232.c
src/jtag/drivers/ftd2xx_common.h
src/jtag/drivers/gw16012.c
src/jtag/drivers/jlink.c
src/jtag/drivers/libusb0_common.c
src/jtag/drivers/libusb0_common.h
src/jtag/drivers/libusb1_common.c
src/jtag/drivers/libusb1_common.h
src/jtag/drivers/minidriver_imp.h
src/jtag/drivers/parport.c
src/jtag/drivers/presto.c
src/jtag/drivers/remote_bitbang.c
src/jtag/drivers/rlink.c
src/jtag/drivers/rlink_dtc_cmd.h
src/jtag/drivers/rlink_speed_table.c
src/jtag/drivers/stlink_usb.h
src/jtag/drivers/ulink.c
src/jtag/drivers/usb_blaster.c
src/jtag/drivers/usb_common.c
src/jtag/drivers/usb_common.h
src/jtag/drivers/usbprog.c
src/jtag/drivers/versaloon/usbtoxxx/usbtogpio.c
src/jtag/drivers/versaloon/usbtoxxx/usbtojtagraw.c
src/jtag/drivers/versaloon/usbtoxxx/usbtopwr.c
src/jtag/drivers/versaloon/usbtoxxx/usbtoswd.c
src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.c
src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx.h
src/jtag/drivers/versaloon/usbtoxxx/usbtoxxx_internal.h
src/jtag/drivers/versaloon/versaloon.c
src/jtag/drivers/versaloon/versaloon.h
src/jtag/drivers/versaloon/versaloon_include.h
src/jtag/drivers/versaloon/versaloon_internal.h
src/jtag/drivers/vsllink.c
src/jtag/minidriver/minidriver_imp.h
src/jtag/minidummy/jtag_minidriver.h
src/jtag/minidummy/minidummy.c
src/jtag/stlink/stlink_interface.c
src/jtag/stlink/stlink_interface.h
src/jtag/stlink/stlink_layout.h
src/jtag/stlink/stlink_tcl.h
src/jtag/stlink/stlink_transport.h
src/jtag/zy1000/jtag_minidriver.h
src/jtag/zy1000/zy1000.c

index 5c36b1d..c887651 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <stdint.h>
 
-#define NOP  {__asm nop __endasm;}
+#define NOP { __asm nop __endasm; }
 
 void delay_5us(void);
 void delay_1ms(void);
index f7119b9..2dc692a 100644 (file)
 
 /* 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
index ca86671..97ec598 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <stdint.h>
 
-#define NOP {__asm nop __endasm;}
+#define NOP { __asm nop __endasm; }
 
 void jtag_scan_in(uint8_t out_offset, uint8_t in_offset);
 void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset);
@@ -43,6 +43,6 @@ uint16_t  jtag_get_signals(void);
 void jtag_set_signals(uint8_t low, uint8_t high);
 
 void jtag_configure_tck_delay(uint8_t scan_in, uint8_t scan_out,
-    uint8_t scan_io, uint8_t tck, uint8_t tms);
+               uint8_t scan_io, uint8_t tck, uint8_t tms);
 
 #endif
index 26ee018..3d5c279 100644 (file)
@@ -51,9 +51,9 @@
 #define bmBit6      0x40
 #define bmBit7      0x80
 
-/***************************************************************************/
-/************************ Special Function Registers ***********************/
-/***************************************************************************/
+/**************************************************************************
+ ************************ Special Function Registers **********************
+ ***************************************************************************/
 
 /* See EZ-USB TRM, pp. A-9 - A-10 */
 
@@ -65,33 +65,33 @@ SFR(DPL2,           0x85);
 
 SFR(DPS,            0x86);
   #define SEL       bmBit0
-  // Bit 1 read-only, always reads '0'
-  // Bit 2 read-only, always reads '0'
-  // Bit 3 read-only, always reads '0'
-  // Bit 4 read-only, always reads '0'
-  // Bit 5 read-only, always reads '0'
-  // Bit 6 read-only, always reads '0'
-  // Bit 7 read-only, always reads '0'
+/* Bit 1 read-only, always reads '0' */
+/* Bit 2 read-only, always reads '0' */
+/* Bit 3 read-only, always reads '0' */
+/* Bit 4 read-only, always reads '0' */
+/* Bit 5 read-only, always reads '0' */
+/* Bit 6 read-only, always reads '0' */
+/* Bit 7 read-only, always reads '0' */
 
 SFR(PCON,           0x87);
   #define IDLE      bmBit0
   #define STOP      bmBit1
   #define GF0       bmBit2
   #define GF1       bmBit3
-  // Bit 4 read-only, always reads '1'
-  // Bit 5 read-only, always reads '1'
-  // Bit 6 unused
+/* Bit 4 read-only, always reads '1' */
+/* Bit 5 read-only, always reads '1' */
+/* Bit 6 unused */
   #define SMOD0     bmBit7
 
 SFR(TCON,           0x88);
-  SBIT(IT0,         0x88, 0);
-  SBIT(IE0,         0x88, 1);
-  SBIT(IT1,         0x88, 2);
-  SBIT(IE1,         0x88, 3);
-  SBIT(TR0,         0x88, 4);
-  SBIT(TF0,         0x88, 5);
-  SBIT(TR1,         0x88, 6);
-  SBIT(TF1,         0x88, 7);
+SBIT(IT0,         0x88, 0);
+SBIT(IE0,         0x88, 1);
+SBIT(IT1,         0x88, 2);
+SBIT(IE1,         0x88, 3);
+SBIT(TR0,         0x88, 4);
+SBIT(TF0,         0x88, 5);
+SBIT(TR1,         0x88, 6);
+SBIT(TF1,         0x88, 7);
 
 SFR(TMOD,           0x89);
 /* Some bits in this register share the same name in the EZ-USB TRM. Therefore,
@@ -117,24 +117,24 @@ SFR(CKCON,          0x8E);
   #define T0M       bmBit3
   #define T1M       bmBit4
   #define T2M       bmBit5
-  // Bit 6 unused
-  // Bit 7 unused
+/* Bit 6 unused */
+/* Bit 7 unused */
 
 SFR(SPC_FNC,        0x8D);
   #define bmWRS     bmBit0
-  // Bit 1 read-only, always reads '0'
-  // Bit 2 read-only, always reads '0'
-  // Bit 3 read-only, always reads '0'
-  // Bit 4 read-only, always reads '0'
-  // Bit 5 read-only, always reads '0'
-  // Bit 6 read-only, always reads '0'
-  // Bit 7 read-only, always reads '0'
+/* Bit 1 read-only, always reads '0' */
+/* Bit 2 read-only, always reads '0' */
+/* Bit 3 read-only, always reads '0' */
+/* Bit 4 read-only, always reads '0' */
+/* Bit 5 read-only, always reads '0' */
+/* Bit 6 read-only, always reads '0' */
+/* Bit 7 read-only, always reads '0' */
 
 SFR(EXIF,           0x91);
-  // Bit 0 read-only, always reads '0'
-  // Bit 1 read-only, always reads '0'
-  // Bit 2 read-only, always reads '0'
-  // Bit 3 read-only, always reads '1'
+/* Bit 0 read-only, always reads '0' */
+/* Bit 1 read-only, always reads '0' */
+/* Bit 2 read-only, always reads '0' */
+/* Bit 3 read-only, always reads '1' */
   #define USBINT    bmBit4
   #define I2CINT    bmBit5
   #define IE4       bmBit6
@@ -146,58 +146,58 @@ SFR(MPAGE,          0x92);
 SFR(_XPAGE,         0x92);
 
 SFR(SCON0,          0x98);
-  SBIT(RI_0,        0x98, 0);
-  SBIT(TI_0,        0x98, 1);
-  SBIT(RB8_0,       0x98, 2);
-  SBIT(TB8_0,       0x98, 3);
-  SBIT(REN_0,       0x98, 4);
-  SBIT(SM2_0,       0x98, 5);
-  SBIT(SM1_0,       0x98, 6);
-  SBIT(SM0_0,       0x98, 7);
+SBIT(RI_0,        0x98, 0);
+SBIT(TI_0,        0x98, 1);
+SBIT(RB8_0,       0x98, 2);
+SBIT(TB8_0,       0x98, 3);
+SBIT(REN_0,       0x98, 4);
+SBIT(SM2_0,       0x98, 5);
+SBIT(SM1_0,       0x98, 6);
+SBIT(SM0_0,       0x98, 7);
 
 SFR(SBUF0,          0x99);
 
 SFR(IE,             0xA8);
-  SBIT(EX0,         0xA8, 0);
-  SBIT(ET0,         0xA8, 1);
-  SBIT(EX1,         0xA8, 2);
-  SBIT(ET1,         0xA8, 3);
-  SBIT(ES0,         0xA8, 4);
-  SBIT(ET2,         0xA8, 5);
-  SBIT(ES1,         0xA8, 6);
-  SBIT(EA,          0xA8, 7);
+SBIT(EX0,         0xA8, 0);
+SBIT(ET0,         0xA8, 1);
+SBIT(EX1,         0xA8, 2);
+SBIT(ET1,         0xA8, 3);
+SBIT(ES0,         0xA8, 4);
+SBIT(ET2,         0xA8, 5);
+SBIT(ES1,         0xA8, 6);
+SBIT(EA,          0xA8, 7);
 
 SFR(IP,             0xB8);
-  SBIT(PX0,         0xB8, 0);
-  SBIT(PT0,         0xB8, 1);
-  SBIT(PX1,         0xB8, 2);
-  SBIT(PT1,         0xB8, 3);
-  SBIT(PS0,         0xB8, 4);
-  SBIT(PT2,         0xB8, 5);
-  SBIT(PS1,         0xB8, 6);
-  // Bit 7 read-only, always reads '1'
+SBIT(PX0,         0xB8, 0);
+SBIT(PT0,         0xB8, 1);
+SBIT(PX1,         0xB8, 2);
+SBIT(PT1,         0xB8, 3);
+SBIT(PS0,         0xB8, 4);
+SBIT(PT2,         0xB8, 5);
+SBIT(PS1,         0xB8, 6);
+/* Bit 7 read-only, always reads '1' */
 
 SFR(SCON1,          0xC0);
-  SBIT(RI_1,        0xC0, 0);
-  SBIT(TI_1,        0xC0, 1);
-  SBIT(RB8_1,       0xC0, 2);
-  SBIT(TB8_1,       0xC0, 3);
-  SBIT(REN_1,       0xC0, 4);
-  SBIT(SM2_1,       0xC0, 5);
-  SBIT(SM1_1,       0xC0, 6);
-  SBIT(SM0_1,       0xC0, 7);
+SBIT(RI_1,        0xC0, 0);
+SBIT(TI_1,        0xC0, 1);
+SBIT(RB8_1,       0xC0, 2);
+SBIT(TB8_1,       0xC0, 3);
+SBIT(REN_1,       0xC0, 4);
+SBIT(SM2_1,       0xC0, 5);
+SBIT(SM1_1,       0xC0, 6);
+SBIT(SM0_1,       0xC0, 7);
 
 SFR(SBUF1,          0xC1);
 
 SFR(T2CON,          0xC8);
-  SBIT(CPRL2,       0xC8, 0);
-  SBIT(CT2,         0xC8, 1);
-  SBIT(TR2,         0xC8, 2);
-  SBIT(EXEN2,       0xC8, 3);
-  SBIT(TCLK,        0xC8, 4);
-  SBIT(RCLK,        0xC8, 5);
-  SBIT(EXF2,        0xC8, 6);
-  SBIT(TF2,         0xC8, 7);
+SBIT(CPRL2,       0xC8, 0);
+SBIT(CT2,         0xC8, 1);
+SBIT(TR2,         0xC8, 2);
+SBIT(EXEN2,       0xC8, 3);
+SBIT(TCLK,        0xC8, 4);
+SBIT(RCLK,        0xC8, 5);
+SBIT(EXF2,        0xC8, 6);
+SBIT(TF2,         0xC8, 7);
 
 SFR(RCAP2L,         0xCA);
 SFR(RCAP2H,         0xCB);
@@ -205,52 +205,52 @@ SFR(TL2,            0xCC);
 SFR(TH2,            0xCD);
 
 SFR(PSW,            0xD0);
-  SBIT(P,           0xD0, 0);
-  SBIT(F1,          0xD0, 1);
-  SBIT(OV,          0xD0, 2);
-  SBIT(RS0,         0xD0, 3);
-  SBIT(RS1,         0xD0, 4);
-  SBIT(F0,          0xD0, 5);
-  SBIT(AC,          0xD0, 6);
-  SBIT(CY,          0xD0, 7);
+SBIT(P,           0xD0, 0);
+SBIT(F1,          0xD0, 1);
+SBIT(OV,          0xD0, 2);
+SBIT(RS0,         0xD0, 3);
+SBIT(RS1,         0xD0, 4);
+SBIT(F0,          0xD0, 5);
+SBIT(AC,          0xD0, 6);
+SBIT(CY,          0xD0, 7);
 
 SFR(EICON,          0xD8);
-  // Bit 0 read-only, always reads '0'
-  // Bit 1 read-only, always reads '0'
-  // Bit 2 read-only, always reads '0'
-  SBIT(INT6,        0xD8, 3);
-  SBIT(RESI,        0xD8, 4);
-  SBIT(ERESI,       0xD8, 5);
-  // Bit 6 read-only, always reads '1'
-  SBIT(SMOD1,       0xD8, 7);
+/* Bit 0 read-only, always reads '0' */
+/* Bit 1 read-only, always reads '0' */
+/* Bit 2 read-only, always reads '0' */
+SBIT(INT6,        0xD8, 3);
+SBIT(RESI,        0xD8, 4);
+SBIT(ERESI,       0xD8, 5);
+/* Bit 6 read-only, always reads '1' */
+SBIT(SMOD1,       0xD8, 7);
 
 SFR(ACC,            0xE0);
 
 SFR(EIE,            0xE8);
-  SBIT(EUSB,        0xE8, 0);
-  SBIT(EI2C,        0xE8, 1);
-  SBIT(EX4,         0xE8, 2);
-  SBIT(EX5,         0xE8, 3);
-  SBIT(EWDI,        0xE8, 4);
-  // Bit 5 read-only, always reads '1'
-  // Bit 6 read-only, always reads '1'
-  // Bit 7 read-only, always reads '1'
+SBIT(EUSB,        0xE8, 0);
+SBIT(EI2C,        0xE8, 1);
+SBIT(EX4,         0xE8, 2);
+SBIT(EX5,         0xE8, 3);
+SBIT(EWDI,        0xE8, 4);
+/* Bit 5 read-only, always reads '1' */
+/* Bit 6 read-only, always reads '1' */
+/* Bit 7 read-only, always reads '1' */
 
 SFR(B,              0xF0);
 
 SFR(EIP,            0xF8);
-  SBIT(PUSB,        0xF8, 0);
-  SBIT(PI2C,        0xF8, 1);
-  SBIT(PX4,         0xF8, 2);
-  SBIT(PX5,         0xF8, 3);
-  SBIT(PX6,         0xF8, 4);
-  // Bit 5 read-only, always reads '1'
-  // Bit 6 read-only, always reads '1'
-  // Bit 7 read-only, always reads '1'
-
-/***************************************************************************/
-/***************************** 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);
@@ -269,7 +269,7 @@ SFRX(OUT1BUF[64],   0x7E40);
 SFRX(IN1BUF[64],    0x7E80);
 SFRX(OUT0BUF[64],   0x7EC0);
 SFRX(IN0BUF[64],    0x7F00);
-// 0x7F40 - 0x7F5F reserved
+/* 0x7F40 - 0x7F5F reserved */
 
 /**************************** Isochronous Data *****************************/
 SFRX(OUT8DATA,      0x7F60);
@@ -312,9 +312,9 @@ SFRX(OUT16BCL,      0x7F7F);
 SFRX(CPUCS,         0x7F92);
   #define RES8051   bmBit0
   #define CLK24OE   bmBit1
-  // Bit 2 read-only, always reads '0'
-  // Bit 3 read-only, always reads '0'
-  // Bits 4...7: Chip Revision
+/* Bit 2 read-only, always reads '0' */
+/* Bit 3 read-only, always reads '0' */
+/* Bits 4...7: Chip Revision */
 
 SFRX(PORTACFG,      0x7F93);
   #define T0OUT     bmBit0
@@ -437,7 +437,7 @@ SFRX(OEC,           0x7F9E);
   #define OEC6      bmBit6
   #define OEC7      bmBit7
 
-// 0x7F9F reserved
+/* 0x7F9F reserved */
 
 /****************** Isochronous Control/Status Registers *******************/
 SFRX(ISOERR,        0x7FA0);
@@ -455,10 +455,10 @@ SFRX(ISOCTL,        0x7FA1);
   #define MBZ0      bmBit1
   #define MBZ1      bmBit2
   #define PPSTAT    bmBit3
-  // Bit 4 unused
-  // Bit 5 unused
-  // Bit 6 unused
-  // Bit 7 unused
+/* Bit 4 unused */
+/* Bit 5 unused */
+/* Bit 6 unused */
+/* Bit 7 unused */
 
 SFRX(ZBCOUT,        0x7FA2);
   #define EP8       bmBit0
@@ -470,8 +470,8 @@ SFRX(ZBCOUT,        0x7FA2);
   #define EP14      bmBit6
   #define EP15      bmBit7
 
-// 0x7FA3 reserved
-// 0x7FA4 reserved
+/* 0x7FA3 reserved */
+/* 0x7FA4 reserved */
 
 /****************************** I2C Registers ******************************/
 SFRX(I2CS,          0x7FA5);
@@ -485,18 +485,18 @@ SFRX(I2CS,          0x7FA5);
   #define I2C_START bmBit7
 
 SFRX(I2DAT,         0x7FA6);
-// 0x7FA7 reserved
+/* 0x7FA7 reserved */
 
 /******************************* Interrupts ********************************/
 SFRX(IVEC,          0x7FA8);
-  // Bit 0 read-only, always reads '0'
-  // Bit 1 read-only, always reads '0'
+/* Bit 0 read-only, always reads '0' */
+/* Bit 1 read-only, always reads '0' */
   #define IV0       bmBit2
   #define IV1       bmBit3
   #define IV2       bmBit4
   #define IV3       bmBit5
   #define IV4       bmBit6
-  // Bit 7 read-only, always reads '0'
+/* Bit 7 read-only, always reads '0' */
 
 SFRX(IN07IRQ,       0x7FA9);
   #define IN0IR     bmBit0
@@ -524,9 +524,9 @@ SFRX(USBIRQ,        0x7FAB);
   #define SUTOKIR   bmBit2
   #define SUSPIR    bmBit3
   #define URESIR    bmBit4
-  // Bit 5 unused
-  // Bit 6 unused
-  // Bit 7 unused
+/* Bit 5 unused */
+/* Bit 6 unused */
+/* Bit 7 unused */
 
 SFRX(IN07IEN,       0x7FAC);
   #define IN0IEN    bmBit0
@@ -554,22 +554,22 @@ SFRX(USBIEN,        0x7FAE);
   #define SUTOKIE   bmBit2
   #define SUSPIE    bmBit3
   #define URESIE    bmBit4
-  // Bit 5 unused
-  // Bit 6 unused
-  // Bit 7 unused
+/* Bit 5 unused */
+/* Bit 6 unused */
+/* Bit 7 unused */
 
 SFRX(USBBAV,        0x7FAF);
   #define AVEN      bmBit0
   #define BPEN      bmBit1
   #define BPPULSE   bmBit2
   #define BREAK     bmBit3
-  // Bit 4 unused
-  // Bit 5 unused
-  // Bit 6 unused
-  // Bit 7 unused
+/* Bit 4 unused */
+/* Bit 5 unused */
+/* Bit 6 unused */
+/* Bit 7 unused */
 
-// 0x7FB0 reserved
-// 0x7FB1 reserved
+/* 0x7FB0 reserved */
+/* 0x7FB1 reserved */
 SFRX(BPADDRH,       0x7FB2);
 SFRX(BPADDRL,       0x7FB3);
 
@@ -579,10 +579,10 @@ SFRX(EP0CS,         0x7FB4);
   #define HSNAK     bmBit1
   #define IN0BSY    bmBit2
   #define OUT0BSY   bmBit3
-  // Bit 4 unused
-  // Bit 5 unused
-  // Bit 6 unused
-  // Bit 7 unused
+/* Bit 4 unused */
+/* Bit 5 unused */
+/* Bit 6 unused */
+/* Bit 7 unused */
 
 SFRX(IN0BC,         0x7FB5);
 SFRX(IN1CS,         0x7FB6);
@@ -599,7 +599,7 @@ SFRX(IN6CS,         0x7FC0);
 SFRX(IN6BC,         0x7FC1);
 SFRX(IN7CS,         0x7FC2);
 SFRX(IN7BC,         0x7FC3);
-// 0x7FC4 reserved
+/* 0x7FC4 reserved */
 SFRX(OUT0BC,        0x7FC5);
 SFRX(OUT1CS,        0x7FC6);
 SFRX(OUT1BC,        0x7FC7);
@@ -630,16 +630,16 @@ SFRX(USBCS,         0x7FD6);
   #define RENUM     bmBit1
   #define DISCOE    bmBit2
   #define DISCON    bmBit3
-  // Bit 4 unused
-  // Bit 5 unused
-  // Bit 6 unused
+/* Bit 4 unused */
+/* Bit 5 unused */
+/* Bit 6 unused */
   #define WAKESRC   bmBit7
 
 SFRX(TOGCTL,        0x7FD7);
   #define TOG_EP0   bmBit0
   #define TOG_EP1   bmBit1
   #define TOG_EP2   bmBit2
-  // Bit 3 is read-only, always reads '0'
+/* Bit 3 is read-only, always reads '0' */
   #define TOG_IO    bmBit4
   #define TOG_R     bmBit5
   #define TOG_S     bmBit6
@@ -647,9 +647,9 @@ SFRX(TOGCTL,        0x7FD7);
 
 SFRX(USBFRAMEL,     0x7FD8);
 SFRX(USBFRAMEH,     0x7FD9);
-// 0x7FDA reserved
+/* 0x7FDA reserved */
 SFRX(FNADDR,        0x7FDB);
-// 0x7FDC reserved
+/* 0x7FDC reserved */
 
 SFRX(USBPAIR,       0x7FDD);
   #define PR2IN     bmBit0
@@ -658,11 +658,11 @@ SFRX(USBPAIR,       0x7FDD);
   #define PR2OUT    bmBit3
   #define PR4OUT    bmBit4
   #define PR6OUT    bmBit5
-  // Bit 6 unused
+/* Bit 6 unused */
   #define ISOSEND0  bmBit7
 
 SFRX(IN07VAL,       0x7FDE);
-  // Bit 0 is read-only, always reads '1'
+/* Bit 0 is read-only, always reads '1' */
   #define IN1VAL    bmBit1
   #define IN2VAL    bmBit2
   #define IN3VAL    bmBit3
@@ -672,7 +672,7 @@ SFRX(IN07VAL,       0x7FDE);
   #define IN7VAL    bmBit7
 
 SFRX(OUT07VAL,      0x7FDF);
-  // Bit 0 is read-only, always reads '1'
+/* Bit 0 is read-only, always reads '1' */
   #define OUT1VAL   bmBit1
   #define OUT2VAL   bmBit2
   #define OUT3VAL   bmBit3
@@ -714,8 +714,8 @@ SFRX(FASTXFR,       0x7FE2);
 SFRX(AUTOPTRH,      0x7FE3);
 SFRX(AUTOPTRL,      0x7FE4);
 SFRX(AUTODATA,      0x7FE5);
-// 0x7FE6 reserved
-// 0x7FE7 reserved
+/* 0x7FE6 reserved */
+/* 0x7FE7 reserved */
 
 /******************************* Setup Data ********************************/
 SFRX(SETUPDAT[8],   0x7FE8);
index 811d6bf..3685f7d 100644 (file)
 #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
@@ -206,9 +206,9 @@ extern volatile __xdata __at 0x7FE8 struct setup_data setup_data;
 /* USB Requests (bRequest): See USB 1.1 spec, table 9-4 on page 187 */
 #define GET_STATUS               0
 #define CLEAR_FEATURE            1
-// Value '2' is reserved for future use
+/* Value '2' is reserved for future use */
 #define SET_FEATURE              3
-// Value '4' is reserved for future use
+/* Value '4' is reserved for future use */
 #define SET_ADDRESS              5
 #define GET_DESCRIPTOR           6
 #define SET_DESCRIPTOR           7
@@ -226,33 +226,33 @@ extern volatile __xdata __at 0x7FE8 struct setup_data setup_data;
 
 /** USB Interrupts. See AN2131-TRM, page 9-4 for details */
 enum usb_isr {
-  SUDAV_ISR = 13,
-  SOF_ISR,
-  SUTOK_ISR,
-  SUSPEND_ISR,
-  USBRESET_ISR,
-  IBN_ISR,
-  EP0IN_ISR,
-  EP0OUT_ISR,
-  EP1IN_ISR,
-  EP1OUT_ISR,
-  EP2IN_ISR,
-  EP2OUT_ISR,
-  EP3IN_ISR,
-  EP3OUT_ISR,
-  EP4IN_ISR,
-  EP4OUT_ISR,
-  EP5IN_ISR,
-  EP5OUT_ISR,
-  EP6IN_ISR,
-  EP6OUT_ISR,
-  EP7IN_ISR,
-  EP7OUT_ISR
+       SUDAV_ISR = 13,
+       SOF_ISR,
+       SUTOK_ISR,
+       SUSPEND_ISR,
+       USBRESET_ISR,
+       IBN_ISR,
+       EP0IN_ISR,
+       EP0OUT_ISR,
+       EP1IN_ISR,
+       EP1OUT_ISR,
+       EP2IN_ISR,
+       EP2OUT_ISR,
+       EP3IN_ISR,
+       EP3OUT_ISR,
+       EP4IN_ISR,
+       EP4OUT_ISR,
+       EP5IN_ISR,
+       EP5OUT_ISR,
+       EP6IN_ISR,
+       EP6OUT_ISR,
+       EP7IN_ISR,
+       EP7OUT_ISR
 };
 
 /*************************** Function Prototypes ***************************/
 
-__xdata uint8_tusb_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);
index 086633a..d200798 100644 (file)
 
 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();
 }
index 3c2fea2..946fdbe 100644 (file)
 #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.
@@ -53,73 +53,69 @@ uint8_t delay_tms = 0;
  */
 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);
 }
 
 /**
@@ -134,79 +130,79 @@ 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)
 {
-  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);
 }
 
 /**
@@ -222,72 +218,66 @@ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
  */
 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);
 }
 
 /**
@@ -303,78 +293,76 @@ void jtag_scan_out(uint8_t out_offset)
  */
 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);
 }
 
 /**
@@ -390,91 +378,83 @@ void jtag_slow_scan_out(uint8_t out_offset)
  */
 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);
 }
 
 /**
@@ -490,97 +470,93 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
  */
 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);
 }
 
 /**
@@ -592,13 +568,13 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
  */
 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;
+       }
 }
 
 /**
@@ -610,16 +586,18 @@ void jtag_clock_tck(uint16_t count)
  */
 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++)
+                       ;
+       }
 }
 
 /**
@@ -633,22 +611,20 @@ void jtag_slow_clock_tck(uint16_t count)
  */
 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;
+       }
 }
 
 /**
@@ -662,24 +638,24 @@ void jtag_clock_tms(uint8_t count, uint8_t sequence)
  */
 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++)
+                       ;
+       }
 }
 
 /**
@@ -691,31 +667,28 @@ void jtag_slow_clock_tms(uint8_t count, uint8_t sequence)
  */
 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);
 }
 
 /**
@@ -726,8 +699,8 @@ uint16_t jtag_get_signals(void)
  */
 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);
 }
 
 /**
@@ -740,11 +713,11 @@ void jtag_set_signals(uint8_t low, uint8_t high)
  * @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;
 }
index 067393b..5beabd1 100644 (file)
@@ -49,43 +49,43 @@ extern void ep7out_isr(void)   __interrupt;
 
 void io_init(void)
 {
-  /* PORTxCFG register bits select alternate functions (1 == alternate function,
-   *                                                    0 == standard I/O)
-   * OEx register bits turn on/off output buffer (1 == output, 0 == input)
-   * OUTx register bits determine pin state of output
-   * PINx register bits reflect pin state (high == 1, low == 0) */
+       /* PORTxCFG register bits select alternate functions (1 == alternate function,
+        *                                                    0 == standard I/O)
+        * OEx register bits turn on/off output buffer (1 == output, 0 == input)
+        * OUTx register bits determine pin state of output
+        * PINx register bits reflect pin state (high == 1, low == 0) */
 
-  /* PORT A */
-  PORTACFG = PIN_OE;
-  OEA = PIN_U_OE | PIN_OE | PIN_RUN_LED | PIN_COM_LED;
-  OUTA = PIN_RUN_LED | PIN_COM_LED;
+       /* PORT A */
+       PORTACFG = PIN_OE;
+       OEA = PIN_U_OE | PIN_OE | PIN_RUN_LED | PIN_COM_LED;
+       OUTA = PIN_RUN_LED | PIN_COM_LED;
 
-  /* PORT B */
-  PORTBCFG = 0x00;
-  OEB = PIN_TDI | PIN_TMS | PIN_TCK | PIN_TRST | PIN_BRKIN | PIN_RESET
-      | PIN_OCDSE;
+       /* PORT B */
+       PORTBCFG = 0x00;
+       OEB = PIN_TDI | PIN_TMS | PIN_TCK | PIN_TRST | PIN_BRKIN | PIN_RESET
+               | PIN_OCDSE;
 
-  /* TRST and RESET signals are low-active but inverted by hardware, so we clear
-   * these signals here! */
-  OUTB = 0x00;
+       /* TRST and RESET signals are low-active but inverted by hardware, so we clear
+        * these signals here! */
+       OUTB = 0x00;
 
-  /* PORT C */
-  PORTCCFG = PIN_WR;
-  OEC = PIN_TXD0 | PIN_WR;
-  OUTC = 0x00;
+       /* PORT C */
+       PORTCCFG = PIN_WR;
+       OEC = PIN_TXD0 | PIN_WR;
+       OUTC = 0x00;
 }
 
 int main(void)
 {
-  io_init();
-  usb_init();
+       io_init();
+       usb_init();
 
-  /* Enable Interrupts */
-  EA = 1;
+       /* Enable Interrupts */
+       EA = 1;
 
-  /* Begin executing command(s). This function never returns. */
-  command_loop();
+       /* Begin executing command(s). This function never returns. */
+       command_loop();
 
-  /* Never reached, but SDCC complains about missing return statement */
-  return 0;
+       /* Never reached, but SDCC complains about missing return statement */
+       return 0;
 }
index ae63604..1034c04 100644 (file)
  * are configured to use the maximum packet size for full-speed transfers,
  * 64 bytes. Commands always start with a command ID (see msgtypes.h for
  * command ID definitions) and contain zero or more payload data bytes in both
- * transfer directions (IN and OUT). The payload 
+ * transfer directions (IN and OUT). The payload
  *
  * Almost all commands contain a fixed number of payload data bytes. The number
  * of payload data bytes for the IN and OUT direction does not need to be the
  * same.
- * 
+ *
  * Multiple commands may be sent in one EP2 Bulk-OUT packet. Because the
  * OpenULINK firmware does not perform bounds checking for EP2 Bulk-IN packets,
  * the host MUST ensure that the commands sent in the OUT packet require a
@@ -57,23 +57,19 @@ volatile uint8_t payload_index_in;
  */
 void execute_set_led_command(void)
 {
-  uint8_t led_state = OUT2BUF[cmd_id_index + 1];
+       uint8_t led_state = OUT2BUF[cmd_id_index + 1];
 
-  if (led_state & RUN_LED_ON) {
-    SET_RUN_LED();
-  }
+       if (led_state & RUN_LED_ON)
+               SET_RUN_LED();
 
-  if (led_state & COM_LED_ON) {
-    SET_COM_LED();
-  }
+       if (led_state & COM_LED_ON)
+               SET_COM_LED();
 
-  if (led_state & RUN_LED_OFF) {
-    CLEAR_RUN_LED();
-  }
+       if (led_state & RUN_LED_OFF)
+               CLEAR_RUN_LED();
 
-  if (led_state & COM_LED_OFF) {
-    CLEAR_COM_LED();
-  }
+       if (led_state & COM_LED_OFF)
+               CLEAR_COM_LED();
 }
 
 /**
@@ -87,123 +83,122 @@ void execute_set_led_command(void)
  */
 bool execute_command(void)
 {
-  uint8_t usb_out_bytecount, usb_in_bytecount;
-  uint16_t signal_state;
-  uint16_t count;
-
-  /* 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;
+       }
 }
 
 /**
@@ -211,35 +206,36 @@ bool execute_command(void)
  */
 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;
+       }
 }
index 7a84d2a..dd791f1 100644 (file)
 
 /* Also update external declarations in "include/usb.h" if making changes to
  * these variables! */
-volatile bool EP2_out = 0;
-volatile bool EP2_in  = 0;
+volatile bool EP2_out;
+volatile bool EP2_in;
 
 volatile __xdata __at 0x7FE8 struct setup_data setup_data;
 
 /* Define number of endpoints (except Control Endpoint 0) in a central place.
  * Be sure to include the neccessary endpoint descriptors! */
-#define NUM_ENDPOINTS  2
+#define NUM_ENDPOINTS 2
 
 /*
  * Normally, we would initialize the descriptor structures in C99 style:
@@ -57,145 +57,185 @@ volatile __xdata __at 0x7FE8 struct setup_data setup_data;
  */
 
 __code struct usb_device_descriptor device_descriptor = {
-  /* .bLength = */             sizeof(struct usb_device_descriptor),
-  /* .bDescriptorType = */     DESCRIPTOR_TYPE_DEVICE,
-  /* .bcdUSB = */              0x0110, /* BCD: 01.00 (Version 1.0 USB spec) */
-  /* .bDeviceClass = */        0xFF,   /* 0xFF = vendor-specific */
-  /* .bDeviceSubClass = */     0xFF,
-  /* .bDeviceProtocol = */     0xFF,
-  /* .bMaxPacketSize0 = */     64,
-  /* .idVendor = */            0xC251,
-  /* .idProduct = */           0x2710,
-  /* .bcdDevice = */           0x0100,
-  /* .iManufacturer = */       1,
-  /* .iProduct = */            2,
-  /* .iSerialNumber = */       3,
-  /* .bNumConfigurations = */  1
+       /* .bLength = */ sizeof(struct usb_device_descriptor),
+       /* .bDescriptorType = */ DESCRIPTOR_TYPE_DEVICE,
+       /* .bcdUSB = */ 0x0110,         /* BCD: 01.00 (Version 1.0 USB spec) */
+       /* .bDeviceClass = */ 0xFF,     /* 0xFF = vendor-specific */
+       /* .bDeviceSubClass = */ 0xFF,
+       /* .bDeviceProtocol = */ 0xFF,
+       /* .bMaxPacketSize0 = */ 64,
+       /* .idVendor = */ 0xC251,
+       /* .idProduct = */ 0x2710,
+       /* .bcdDevice = */ 0x0100,
+       /* .iManufacturer = */ 1,
+       /* .iProduct = */ 2,
+       /* .iSerialNumber = */ 3,
+       /* .bNumConfigurations = */ 1
 };
 
 /* WARNING: ALL config, interface and endpoint descriptors MUST be adjacent! */
 
 __code struct usb_config_descriptor config_descriptor = {
-  /* .bLength = */             sizeof(struct usb_config_descriptor),
-  /* .bDescriptorType = */     DESCRIPTOR_TYPE_CONFIGURATION,
-  /* .wTotalLength = */        sizeof(struct usb_config_descriptor) +
-                               sizeof(struct usb_interface_descriptor) +
-                               (NUM_ENDPOINTS *
-                               sizeof(struct usb_endpoint_descriptor)),
-  /* .bNumInterfaces = */      1,
-  /* .bConfigurationValue = */ 1,
-  /* .iConfiguration = */      4,     /* String describing this configuration */
-  /* .bmAttributes = */        0x80,  /* Only MSB set according to USB spec */
-  /* .MaxPower = */            50     /* 100 mA */
+       /* .bLength = */ sizeof(struct usb_config_descriptor),
+       /* .bDescriptorType = */ DESCRIPTOR_TYPE_CONFIGURATION,
+       /* .wTotalLength = */ sizeof(struct usb_config_descriptor) +
+       sizeof(struct usb_interface_descriptor) +
+       (NUM_ENDPOINTS *
+        sizeof(struct usb_endpoint_descriptor)),
+       /* .bNumInterfaces = */ 1,
+       /* .bConfigurationValue = */ 1,
+       /* .iConfiguration = */ 4,      /* String describing this configuration */
+       /* .bmAttributes = */ 0x80,     /* Only MSB set according to USB spec */
+       /* .MaxPower = */ 50            /* 100 mA */
 };
 
 __code struct usb_interface_descriptor interface_descriptor00 = {
-  /* .bLength = */             sizeof(struct usb_interface_descriptor),
-  /* .bDescriptorType = */     DESCRIPTOR_TYPE_INTERFACE,
-  /* .bInterfaceNumber = */    0,
-  /* .bAlternateSetting = */   0,
-  /* .bNumEndpoints = */       NUM_ENDPOINTS,
-  /* .bInterfaceClass = */     0xFF,
-  /* .bInterfaceSubclass = */  0xFF,
-  /* .bInterfaceProtocol = */  0xFF,
-  /* .iInterface = */          0
+       /* .bLength = */ sizeof(struct usb_interface_descriptor),
+       /* .bDescriptorType = */ DESCRIPTOR_TYPE_INTERFACE,
+       /* .bInterfaceNumber = */ 0,
+       /* .bAlternateSetting = */ 0,
+       /* .bNumEndpoints = */ NUM_ENDPOINTS,
+       /* .bInterfaceClass = */ 0xFF,
+       /* .bInterfaceSubclass = */ 0xFF,
+       /* .bInterfaceProtocol = */ 0xFF,
+       /* .iInterface = */ 0
 };
 
 __code struct usb_endpoint_descriptor Bulk_EP2_IN_Endpoint_Descriptor = {
-  /* .bLength = */             sizeof(struct usb_endpoint_descriptor),
-  /* .bDescriptorType = */     0x05,
-  /* .bEndpointAddress = */    2 | USB_DIR_IN,
-  /* .bmAttributes = */        0x02,
-  /* .wMaxPacketSize = */      64,
-  /* .bInterval = */           0
+       /* .bLength = */ sizeof(struct usb_endpoint_descriptor),
+       /* .bDescriptorType = */ 0x05,
+       /* .bEndpointAddress = */ 2 | USB_DIR_IN,
+       /* .bmAttributes = */ 0x02,
+       /* .wMaxPacketSize = */ 64,
+       /* .bInterval = */ 0
 };
 
 __code struct usb_endpoint_descriptor Bulk_EP2_OUT_Endpoint_Descriptor = {
-  /* .bLength = */             sizeof(struct usb_endpoint_descriptor),
-  /* .bDescriptorType = */     0x05,
-  /* .bEndpointAddress = */    2 | USB_DIR_OUT,
-  /* .bmAttributes = */        0x02,
-  /* .wMaxPacketSize = */      64,
-  /* .bInterval = */           0
+       /* .bLength = */ sizeof(struct usb_endpoint_descriptor),
+       /* .bDescriptorType = */ 0x05,
+       /* .bEndpointAddress = */ 2 | USB_DIR_OUT,
+       /* .bmAttributes = */ 0x02,
+       /* .wMaxPacketSize = */ 64,
+       /* .bInterval = */ 0
 };
 
 __code struct usb_language_descriptor language_descriptor = {
-  /* .bLength =  */            4,
-  /* .bDescriptorType = */     DESCRIPTOR_TYPE_STRING,
-  /* .wLANGID = */             {0x0409 /* US English */}
+       /* .bLength =  */ 4,
+       /* .bDescriptorType = */ DESCRIPTOR_TYPE_STRING,
+       /* .wLANGID = */ {0x0409 /* US English */}
 };
 
 __code struct usb_string_descriptor strManufacturer =
-    STR_DESCR(9,'O','p','e','n','U','L','I','N','K');
+       STR_DESCR(9, 'O', 'p', 'e', 'n', 'U', 'L', 'I', 'N', 'K');
 
-__code struct usb_string_descriptor strProduct      =
-    STR_DESCR(9,'O','p','e','n','U','L','I','N','K');
+__code struct usb_string_descriptor strProduct =
+       STR_DESCR(9, 'O', 'p', 'e', 'n', 'U', 'L', 'I', 'N', 'K');
 
 __code struct usb_string_descriptor strSerialNumber =
-    STR_DESCR(6, '0','0','0','0','0','1');
+       STR_DESCR(6, '0', '0', '0', '0', '0', '1');
 
 __code struct usb_string_descriptor strConfigDescr  =
-    STR_DESCR(12, 'J','T','A','G',' ','A','d','a','p','t','e','r');
+       STR_DESCR(12, 'J', 'T', 'A', 'G', ' ', 'A', 'd', 'a', 'p', 't', 'e', 'r');
 
 /* Table containing pointers to string descriptors */
-__code struct usb_string_descriptor__code en_string_descriptors[4] = {
-  &strManufacturer,
-  &strProduct,
-  &strSerialNumber,
-  &strConfigDescr
+__code struct usb_string_descriptor *__code en_string_descriptors[4] = {
+       &strManufacturer,
+       &strProduct,
+       &strSerialNumber,
+       &strConfigDescr
 };
 
 void sudav_isr(void) __interrupt SUDAV_ISR
 {
-  CLEAR_IRQ();
+       CLEAR_IRQ();
 
-  usb_handle_setup_data();
+       usb_handle_setup_data();
 
-  USBIRQ = SUDAVIR;
-  EP0CS |= HSNAK;
+       USBIRQ = SUDAVIR;
+       EP0CS |= HSNAK;
 }
 
-void sof_isr(void)      __interrupt SOF_ISR      { }
-void sutok_isr(void)    __interrupt SUTOK_ISR    { }
-void suspend_isr(void)  __interrupt SUSPEND_ISR  { }
-void usbreset_isr(void) __interrupt USBRESET_ISR { }
-void ibn_isr(void)      __interrupt IBN_ISR      { }
+void sof_isr(void)      __interrupt SOF_ISR
+{
+}
+void sutok_isr(void)    __interrupt SUTOK_ISR
+{
+}
+void suspend_isr(void)  __interrupt SUSPEND_ISR
+{
+}
+void usbreset_isr(void) __interrupt USBRESET_ISR
+{
+}
+void ibn_isr(void)      __interrupt IBN_ISR
+{
+}
 
-void ep0in_isr(void)    __interrupt EP0IN_ISR    { }
-void ep0out_isr(void)   __interrupt EP0OUT_ISR   { }
-void ep1in_isr(void)    __interrupt EP1IN_ISR    { }
-void ep1out_isr(void)   __interrupt EP1OUT_ISR   { }
+void ep0in_isr(void)    __interrupt EP0IN_ISR
+{
+}
+void ep0out_isr(void)   __interrupt EP0OUT_ISR
+{
+}
+void ep1in_isr(void)    __interrupt EP1IN_ISR
+{
+}
+void ep1out_isr(void)   __interrupt EP1OUT_ISR
+{
+}
 
 /**
  * EP2 IN: called after the transfer from uC->Host has finished: we sent data
  */
-void ep2in_isr(void)    __interrupt EP2IN_ISR { 
-  EP2_in = 1;
+void ep2in_isr(void)    __interrupt EP2IN_ISR
+{
+       EP2_in = 1;
 
-  CLEAR_IRQ();
-  IN07IRQ = IN2IR;     // Clear OUT2 IRQ
+       CLEAR_IRQ();
+       IN07IRQ = IN2IR;/* Clear OUT2 IRQ */
 }
 
 /**
  * EP2 OUT: called after the transfer from Host->uC has finished: we got data
  */
-void ep2out_isr(void)   __interrupt EP2OUT_ISR {
-  EP2_out = 1;
+void ep2out_isr(void)   __interrupt EP2OUT_ISR
+{
+       EP2_out = 1;
 
-  CLEAR_IRQ();
-  OUT07IRQ = OUT2IR;    // Clear OUT2 IRQ
+       CLEAR_IRQ();
+       OUT07IRQ = OUT2IR;      /* Clear OUT2 IRQ */
 }
 
-void ep3in_isr(void)    __interrupt EP3IN_ISR    { }
-void ep3out_isr(void)   __interrupt EP3OUT_ISR   { }
-void ep4in_isr(void)    __interrupt EP4IN_ISR    { }
-void ep4out_isr(void)   __interrupt EP4OUT_ISR   { }
-void ep5in_isr(void)    __interrupt EP5IN_ISR    { }
-void ep5out_isr(void)   __interrupt EP5OUT_ISR   { }
-void ep6in_isr(void)    __interrupt EP6IN_ISR    { }
-void ep6out_isr(void)   __interrupt EP6OUT_ISR   { }
-void ep7in_isr(void)    __interrupt EP7IN_ISR    { }
-void ep7out_isr(void)   __interrupt EP7OUT_ISR   { }
+void ep3in_isr(void)    __interrupt EP3IN_ISR
+{
+}
+void ep3out_isr(void)   __interrupt EP3OUT_ISR
+{
+}
+void ep4in_isr(void)    __interrupt EP4IN_ISR
+{
+}
+void ep4out_isr(void)   __interrupt EP4OUT_ISR
+{
+}
+void ep5in_isr(void)    __interrupt EP5IN_ISR
+{
+}
+void ep5out_isr(void)   __interrupt EP5OUT_ISR
+{
+}
+void ep6in_isr(void)    __interrupt EP6IN_ISR
+{
+}
+void ep6out_isr(void)   __interrupt EP6OUT_ISR
+{
+}
+void ep7in_isr(void)    __interrupt EP7IN_ISR
+{
+}
+void ep7out_isr(void)   __interrupt EP7OUT_ISR
+{
+}
 
 /**
  * Return the control/status register for an endpoint
@@ -205,60 +245,60 @@ void ep7out_isr(void)   __interrupt EP7OUT_ISR   { }
  *  specified in \a ep
  * @return on failure: NULL
  */
-__xdata uint8_tusb_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;
 }
 
 /**
@@ -269,49 +309,47 @@ void usb_reset_data_toggle(uint8_t ep)
  */
 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;
 }
 
 /**
@@ -322,32 +360,30 @@ bool usb_handle_get_status(void)
  */
 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;
 }
 
 /**
@@ -358,34 +394,31 @@ bool usb_handle_clear_feature(void)
  */
 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;
 }
 
 /**
@@ -396,43 +429,40 @@ bool usb_handle_set_feature(void)
  */
 bool usb_handle_get_descriptor(void)
 {
-  __xdata uint8_t descriptor_type;
-  __xdata uint8_t descriptor_index;
-
-  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;
 }
 
 /**
@@ -440,16 +470,16 @@ bool usb_handle_get_descriptor(void)
  */
 void usb_handle_set_interface(void)
 {
-  /* Reset Data Toggle */
-  usb_reset_data_toggle(USB_DIR_IN  | 2);
-  usb_reset_data_toggle(USB_DIR_OUT | 2);
-
-  /* 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;
 }
 
 /**
@@ -457,95 +487,92 @@ void usb_handle_set_interface(void)
  */
 void usb_handle_setup_data(void)
 {
-  switch (setup_data.bRequest) {
-    case GET_STATUS:
-      if (!usb_handle_get_status()) {
-        STALL_EP0();
-      }
-      break;
-    case CLEAR_FEATURE:
-      if (!usb_handle_clear_feature()) {
-        STALL_EP0();
-      }
-      break;
-    case 2: case 4:
-      /* Reserved values */
-      STALL_EP0();
-      break;
-    case SET_FEATURE:
-      if (!usb_handle_set_feature()) {
-        STALL_EP0();
-      }
-      break;
-    case SET_ADDRESS:
-      /* Handled by USB core */
-      break;
-    case SET_DESCRIPTOR:
-      /* Set Descriptor not supported. */
-      STALL_EP0();
-      break;
-    case GET_DESCRIPTOR:
-      if (!usb_handle_get_descriptor()) {
-        STALL_EP0();
-      }
-      break;
-    case GET_CONFIGURATION:
-      /* OpenULINK has only one configuration, return its index */
-      IN0BUF[0] = config_descriptor.bConfigurationValue;
-      IN0BC = 1;
-      break;
-    case SET_CONFIGURATION:
-      /* OpenULINK has only one configuration -> nothing to do */
-      break;
-    case GET_INTERFACE:
-      /* OpenULINK only has one interface, return its number */
-      IN0BUF[0] = interface_descriptor00.bInterfaceNumber;
-      IN0BC = 1;
-      break;
-    case SET_INTERFACE:
-      usb_handle_set_interface();
-      break;
-    case SYNCH_FRAME:
-      /* Isochronous endpoints not used -> nothing to do */
-      break;
-    default:
-      /* Any other requests: do nothing */
-      break;
-  }
+       switch (setup_data.bRequest) {
+           case GET_STATUS:
+                   if (!usb_handle_get_status())
+                           STALL_EP0();
+                   break;
+           case CLEAR_FEATURE:
+                   if (!usb_handle_clear_feature())
+                           STALL_EP0();
+                   break;
+           case 2: case 4:
+                       /* Reserved values */
+                   STALL_EP0();
+                   break;
+           case SET_FEATURE:
+                   if (!usb_handle_set_feature())
+                           STALL_EP0();
+                   break;
+           case SET_ADDRESS:
+                       /* Handled by USB core */
+                   break;
+           case SET_DESCRIPTOR:
+                       /* Set Descriptor not supported. */
+                   STALL_EP0();
+                   break;
+           case GET_DESCRIPTOR:
+                   if (!usb_handle_get_descriptor())
+                           STALL_EP0();
+                   break;
+           case GET_CONFIGURATION:
+                       /* OpenULINK has only one configuration, return its index */
+                   IN0BUF[0] = config_descriptor.bConfigurationValue;
+                   IN0BC = 1;
+                   break;
+           case SET_CONFIGURATION:
+                       /* OpenULINK has only one configuration -> nothing to do */
+                   break;
+           case GET_INTERFACE:
+                       /* OpenULINK only has one interface, return its number */
+                   IN0BUF[0] = interface_descriptor00.bInterfaceNumber;
+                   IN0BC = 1;
+                   break;
+           case SET_INTERFACE:
+                   usb_handle_set_interface();
+                   break;
+           case SYNCH_FRAME:
+                       /* Isochronous endpoints not used -> nothing to do */
+                   break;
+           default:
+                       /* Any other requests: do nothing */
+                   break;
+       }
 }
 
 /**
  * USB initialization. Configures USB interrupts, endpoints and performs
  * ReNumeration.
  */
-void usb_init(void) {
-  /* Mark endpoint 2 IN & OUT as valid */
-  IN07VAL  = IN2VAL;
-  OUT07VAL = OUT2VAL;
-
-  /* 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;
 }
index 34a4ae7..d89e5ff 100644 (file)
@@ -17,6 +17,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -27,7 +28,7 @@
 #include <linux/parport.h>
 #include <linux/ppdev.h>
 #include <sys/ioctl.h>
-#else /* not PARPORT_USE_PPDEV */
+#else  /* not PARPORT_USE_PPDEV */
 #ifndef _WIN32
 #include <sys/io.h>
 #endif
@@ -53,11 +54,11 @@ static uint16_t amt_jtagaccel_port;
 
 /* interface variables
  */
-static uint8_t aw_control_rst = 0x00;
+static uint8_t aw_control_rst;
 static uint8_t aw_control_fsm = 0x10;
 static uint8_t aw_control_baudrate = 0x20;
 
-static int rtck_enabled = 0;
+static int rtck_enabled;
 
 #if PARPORT_USE_PPDEV == 1
 static int device_handle;
@@ -70,7 +71,7 @@ static const int addr_mode = IEEE1284_MODE_EPP | IEEE1284_ADDR;
        do { \
                int __retval; \
                \
-               __retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
+               __retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
                assert(__retval >= 0); \
                __retval = write(device_handle, &val, 1); \
                assert(__retval >= 0); \
@@ -79,7 +80,7 @@ static const int addr_mode = IEEE1284_MODE_EPP | IEEE1284_ADDR;
        do { \
                int __retval; \
                \
-               __retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
+               __retval = ioctl(device_handle, PPSETMODE, &addr_mode); \
                assert(__retval >= 0); \
                __retval = read(device_handle, &val, 1); \
                assert(__retval >= 0); \
@@ -91,7 +92,7 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
        do { \
                int __retval; \
                \
-               __retval = ioctl(device_handle, PPSETMODE, &data_mode); \
+               __retval = ioctl(device_handle, PPSETMODE, &data_mode); \
                assert(__retval >= 0); \
                __retval = write(device_handle, &val, 1); \
                assert(__retval >= 0); \
@@ -100,7 +101,7 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
        do { \
                int __retval; \
                \
-               __retval = ioctl(device_handle, PPSETMODE, &data_mode); \
+               __retval = ioctl(device_handle, PPSETMODE, &data_mode); \
                assert(__retval >= 0); \
                __retval = read(device_handle, &val, 1); \
                assert(__retval >= 0); \
@@ -108,12 +109,12 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
 
 #else
 
-#define AMT_AW(val)    do { outb(val, amt_jtagaccel_port + 3); } while (0)
-#define AMT_AR(val)    do { val = inb(amt_jtagaccel_port + 3); } while (0)
-#define AMT_DW(val)    do { outb(val, amt_jtagaccel_port + 4); } while (0)
-#define AMT_DR(val)    do { val = inb(amt_jtagaccel_port + 4); } while (0)
+#define AMT_AW(val) do { outb(val, amt_jtagaccel_port + 3); } while (0)
+#define AMT_AR(val) do { val = inb(amt_jtagaccel_port + 3); } while (0)
+#define AMT_DW(val) do { outb(val, amt_jtagaccel_port + 4); } while (0)
+#define AMT_DR(val) do { val = inb(amt_jtagaccel_port + 4); } while (0)
 
-#endif // PARPORT_USE_PPDEV
+#endif /* PARPORT_USE_PPDEV */
 
 /* tap_move[i][j]: tap movement command to go from state i to state j
  * 0: Test-Logic-Reset
@@ -123,18 +124,16 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
  * 4: Shift-IR
  * 5: Pause-IR
  */
-static uint8_t amt_jtagaccel_tap_move[6][6][2] =
-{
+static uint8_t amt_jtagaccel_tap_move[6][6][2] = {
        /*         RESET         IDLE        DRSHIFT       DRPAUSE       IRSHIFT       IRPAUSE             */
-       {{0x1f, 0x00}, {0x0f, 0x00}, {0x05, 0x00}, {0x0a, 0x00}, {0x06, 0x00}, {0x96, 0x00}},   /* RESET */
-       {{0x1f, 0x00}, {0x00, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x0b, 0x00}},   /* IDLE */
-       {{0x1f, 0x00}, {0x0d, 0x00}, {0x00, 0x00}, {0x01, 0x00}, {0x8f, 0x09}, {0x8f, 0x01}},   /* DRSHIFT  */
-       {{0x1f, 0x00}, {0x0c, 0x00}, {0x08, 0x00}, {0x00, 0x00}, {0x8f, 0x09}, {0x8f, 0x01}},   /* DRPAUSE  */
-       {{0x1f, 0x00}, {0x0d, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x00, 0x00}, {0x01, 0x00}},   /* IRSHIFT  */
-       {{0x1f, 0x00}, {0x0c, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x08, 0x00}, {0x00, 0x00}},   /* IRPAUSE  */
+       { {0x1f, 0x00}, {0x0f, 0x00}, {0x05, 0x00}, {0x0a, 0x00}, {0x06, 0x00}, {0x96, 0x00} }, /* RESET */
+       { {0x1f, 0x00}, {0x00, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x0b, 0x00} }, /* IDLE */
+       { {0x1f, 0x00}, {0x0d, 0x00}, {0x00, 0x00}, {0x01, 0x00}, {0x8f, 0x09}, {0x8f, 0x01} }, /* DRSHIFT  */
+       { {0x1f, 0x00}, {0x0c, 0x00}, {0x08, 0x00}, {0x00, 0x00}, {0x8f, 0x09}, {0x8f, 0x01} }, /* DRPAUSE  */
+       { {0x1f, 0x00}, {0x0d, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x00, 0x00}, {0x01, 0x00} }, /* IRSHIFT  */
+       { {0x1f, 0x00}, {0x0c, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x08, 0x00}, {0x00, 0x00} }, /* IRPAUSE  */
 };
 
-
 static void amt_jtagaccel_reset(int trst, int srst)
 {
        if (trst == 1)
@@ -163,8 +162,7 @@ static void amt_jtagaccel_end_state(tap_state_t state)
 {
        if (tap_is_state_stable(state))
                tap_set_end_state(state);
-       else
-       {
+       else {
                LOG_ERROR("BUG: %i is not a valid end state", state);
                exit(-1);
        }
@@ -179,9 +177,11 @@ static void amt_wait_scan_busy(void)
        while (((ar_status) & 0x80) && (timeout-- > 0))
                AMT_AR(ar_status);
 
-       if (ar_status & 0x80)
-       {
-               LOG_ERROR("amt_jtagaccel timed out while waiting for end of scan, rtck was %s, last AR_STATUS: 0x%2.2x", (rtck_enabled) ? "enabled" : "disabled", ar_status);
+       if (ar_status & 0x80) {
+               LOG_ERROR(
+                       "amt_jtagaccel timed out while waiting for end of scan, rtck was %s, last AR_STATUS: 0x%2.2x",
+                       (rtck_enabled) ? "enabled" : "disabled",
+                       ar_status);
                exit(-1);
        }
 }
@@ -191,22 +191,21 @@ static void amt_jtagaccel_state_move(void)
        uint8_t aw_scan_tms_5;
        uint8_t tms_scan[2];
 
-       tap_state_t     cur_state = tap_get_state();
-       tap_state_t     end_state = tap_get_end_state();
+       tap_state_t cur_state = tap_get_state();
+       tap_state_t end_state = tap_get_end_state();
 
        tms_scan[0] = amt_jtagaccel_tap_move[tap_move_ndx(cur_state)][tap_move_ndx(end_state)][0];
        tms_scan[1] = amt_jtagaccel_tap_move[tap_move_ndx(cur_state)][tap_move_ndx(end_state)][1];
 
        aw_scan_tms_5 = 0x40 | (tms_scan[0] & 0x1f);
        AMT_AW(aw_scan_tms_5);
-        int jtag_speed=0;
+       int jtag_speed = 0;
        int retval = jtag_get_speed(&jtag_speed);
        assert(retval == ERROR_OK);
        if (jtag_speed > 3 || rtck_enabled)
                amt_wait_scan_busy();
 
-       if (tms_scan[0] & 0x80)
-       {
+       if (tms_scan[0] & 0x80) {
                aw_scan_tms_5 = 0x40 | (tms_scan[1] & 0x1f);
                AMT_AW(aw_scan_tms_5);
                if (jtag_speed > 3 || rtck_enabled)
@@ -225,21 +224,18 @@ static void amt_jtagaccel_runtest(int num_cycles)
        tap_state_t saved_end_state = tap_get_end_state();
 
        /* only do a state_move when we're not already in IDLE */
-       if (tap_get_state() != TAP_IDLE)
-       {
+       if (tap_get_state() != TAP_IDLE) {
                amt_jtagaccel_end_state(TAP_IDLE);
                amt_jtagaccel_state_move();
        }
 
-       while (num_cycles - i >= 5)
-       {
+       while (num_cycles - i >= 5) {
                aw_scan_tms_5 = 0x40;
                AMT_AW(aw_scan_tms_5);
                i += 5;
        }
 
-       if (num_cycles - i > 0)
-       {
+       if (num_cycles - i > 0) {
                aw_scan_tms_1to4 = 0x80 | ((num_cycles - i - 1) & 0x3) << 4;
                AMT_AW(aw_scan_tms_1to4);
        }
@@ -272,8 +268,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
        amt_jtagaccel_end_state(saved_end_state);
 
        /* handle unaligned bits at the beginning */
-       if ((scan_size - 1) % 8)
-       {
+       if ((scan_size - 1) % 8) {
                aw_tdi_option = 0x30 | (((scan_size - 1) % 8) - 1);
                AMT_AW(aw_tdi_option);
 
@@ -282,8 +277,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
                if (jtag_speed_var > 3 || rtck_enabled)
                        amt_wait_scan_busy();
 
-               if ((type == SCAN_IN) || (type == SCAN_IO))
-               {
+               if ((type == SCAN_IN) || (type == SCAN_IO)) {
                        AMT_DR(dr_tdo);
                        dr_tdo = dr_tdo >> (8 - ((scan_size - 1) % 8));
                        buf_set_u32(buffer, bit_count, (scan_size - 1) % 8, dr_tdo);
@@ -293,15 +287,13 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
                bits_left -= (scan_size - 1) % 8;
        }
 
-       while (bits_left - 1 >= 8)
-       {
+       while (bits_left - 1 >= 8) {
                dw_tdi_scan = buf_get_u32(buffer, bit_count, 8) & 0xff;
                AMT_DW(dw_tdi_scan);
                if (jtag_speed_var > 3 || rtck_enabled)
                        amt_wait_scan_busy();
 
-               if ((type == SCAN_IN) || (type == SCAN_IO))
-               {
+               if ((type == SCAN_IN) || (type == SCAN_IO)) {
                        AMT_DR(dr_tdo);
                        buf_set_u32(buffer, bit_count, 8, dr_tdo);
                }
@@ -310,22 +302,22 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
                bits_left -= 8;
        }
 
-       tms_scan[0] = amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][0];
-       tms_scan[1] = amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][1];
+       tms_scan[0] =
+               amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][0];
+       tms_scan[1] =
+               amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][1];
        aw_tms_scan = 0x40 | (tms_scan[0] & 0x1f) | (buf_get_u32(buffer, bit_count, 1) << 5);
        AMT_AW(aw_tms_scan);
        if (jtag_speed_var > 3 || rtck_enabled)
                amt_wait_scan_busy();
 
-       if ((type == SCAN_IN) || (type == SCAN_IO))
-       {
+       if ((type == SCAN_IN) || (type == SCAN_IO)) {
                AMT_DR(dr_tdo);
                dr_tdo = dr_tdo >> 7;
                buf_set_u32(buffer, bit_count, 1, dr_tdo);
        }
 
-       if (tms_scan[0] & 0x80)
-       {
+       if (tms_scan[0] & 0x80) {
                aw_tms_scan = 0x40 | (tms_scan[1] & 0x1f);
                AMT_AW(aw_tms_scan);
                if (jtag_speed_var > 3 || rtck_enabled)
@@ -336,7 +328,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
 
 static int amt_jtagaccel_execute_queue(void)
 {
-       struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
+       struct jtag_command *cmd = jtag_command_queue;  /* currently processed command */
        int scan_size;
        enum scan_type type;
        uint8_t *buffer;
@@ -347,23 +339,23 @@ static int amt_jtagaccel_execute_queue(void)
         */
        retval = ERROR_OK;
 
-       while (cmd)
-       {
-               switch (cmd->type)
-               {
+       while (cmd) {
+               switch (cmd->type) {
                        case JTAG_RESET:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
+                               LOG_DEBUG("reset trst: %i srst %i",
+                               cmd->cmd.reset->trst,
+                               cmd->cmd.reset->srst);
 #endif
                                if (cmd->cmd.reset->trst == 1)
-                               {
                                        tap_set_state(TAP_RESET);
-                               }
                                amt_jtagaccel_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
                                break;
                        case JTAG_RUNTEST:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
+                               LOG_DEBUG("runtest %i cycles, end in %i",
+                               cmd->cmd.runtest->num_cycles,
+                               cmd->cmd.runtest->end_state);
 #endif
                                amt_jtagaccel_end_state(cmd->cmd.runtest->end_state);
                                amt_jtagaccel_runtest(cmd->cmd.runtest->num_cycles);
@@ -412,16 +404,22 @@ int amt_jtagaccel_get_giveio_access(void)
 
        version.dwOSVersionInfoSize = sizeof version;
        if (!GetVersionEx(&version)) {
-       errno = EINVAL;
-       return -1;
+               errno = EINVAL;
+               return -1;
        }
        if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
-       return 0;
-
-       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);
@@ -442,8 +440,7 @@ static int amt_jtagaccel_init(void)
        uint8_t ar_status;
 
 #if PARPORT_USE_PPDEV == 1
-       if (device_handle > 0)
-       {
+       if (device_handle > 0) {
                LOG_ERROR("device is already opened");
                return ERROR_JTAG_INIT_FAILED;
        }
@@ -451,23 +448,21 @@ static int amt_jtagaccel_init(void)
        snprintf(buffer, 256, "/dev/parport%d", amt_jtagaccel_port);
        device_handle = open(buffer, O_RDWR);
 
-       if (device_handle < 0)
-       {
-               LOG_ERROR("cannot open device. check it exists and that user read and write rights are set");
+       if (device_handle < 0) {
+               LOG_ERROR(
+                       "cannot open device. check it exists and that user read and write rights are set");
                return ERROR_JTAG_INIT_FAILED;
        }
 
        i = ioctl(device_handle, PPCLAIM);
-       if (i < 0)
-       {
+       if (i < 0) {
                LOG_ERROR("cannot claim device");
                return ERROR_JTAG_INIT_FAILED;
        }
 
        i = IEEE1284_MODE_EPP;
-       i = ioctl(device_handle, PPSETMODE, & i);
-       if (i < 0)
-       {
+       i = ioctl(device_handle, PPSETMODE, &i);
+       if (i < 0) {
                LOG_ERROR(" cannot set compatible mode to device");
                return ERROR_JTAG_INIT_FAILED;
        }
@@ -479,23 +474,22 @@ static int amt_jtagaccel_init(void)
        i = ioctl(device_handle, PPWCONTROL, &control_port);
 
 #else
-       if (amt_jtagaccel_port == 0)
-       {
+       if (amt_jtagaccel_port == 0) {
                amt_jtagaccel_port = 0x378;
                LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
        }
 
 #if PARPORT_USE_GIVEIO == 1
        if (amt_jtagaccel_get_giveio_access() != 0) {
-#else /* PARPORT_USE_GIVEIO */
+#else  /* PARPORT_USE_GIVEIO */
        if (ioperm(amt_jtagaccel_port, 5, 1) != 0) {
-#endif /* PARPORT_USE_GIVEIO */
+#endif /* PARPORT_USE_GIVEIO */
                LOG_ERROR("missing privileges for direct i/o");
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       /* prepare epp port */
-       /* clear timeout */
+       /* prepare epp port
+        * clear timeout */
        status_port = inb(amt_jtagaccel_port + 1);
        outb(status_port | 0x1, amt_jtagaccel_port + 1);
 
@@ -504,8 +498,7 @@ static int amt_jtagaccel_init(void)
        outb(0x04, amt_jtagaccel_port + 2);
 #endif
 
-       if (rtck_enabled)
-       {
+       if (rtck_enabled) {
                /* set RTCK enable bit */
                aw_control_fsm |= 0x02;
        }
@@ -542,17 +535,13 @@ static int amt_jtagaccel_quit(void)
 
 COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command)
 {
-       if (CMD_ARGC == 1)
-       {
+       if (CMD_ARGC == 1) {
                /* only if the port wasn't overwritten by cmdline */
-               if (amt_jtagaccel_port == 0)
-               {
+               if (amt_jtagaccel_port == 0) {
                        uint16_t port;
                        COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], port);
                        amt_jtagaccel_port = port;
-               }
-               else
-               {
+               } else {
                        LOG_ERROR("The parport port was already configured!");
                        return ERROR_FAIL;
                }
@@ -565,21 +554,16 @@ COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command)
 
 COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command)
 {
-       if (CMD_ARGC == 0)
-       {
-               command_print(CMD_CTX, "amt_jtagaccel RTCK feature %s", (rtck_enabled) ? "enabled" : "disabled");
+       if (CMD_ARGC == 0) {
+               command_print(CMD_CTX,
+                       "amt_jtagaccel RTCK feature %s",
+                       (rtck_enabled) ? "enabled" : "disabled");
                return ERROR_OK;
-       }
-       else
-       {
+       } else {
                if (strcmp(CMD_ARGV[0], "enabled") == 0)
-               {
                        rtck_enabled = 1;
-               }
                else
-               {
                        rtck_enabled = 0;
-               }
        }
 
        return ERROR_OK;
index b090050..35b6b92 100644 (file)
@@ -59,9 +59,13 @@ static void armjtagew_end_state(tap_state_t state);
 static void armjtagew_state_move(void);
 static void armjtagew_path_move(int num_states, tap_state_t *path);
 static void armjtagew_runtest(int num_cycles);
-static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command);
+static void armjtagew_scan(bool ir_scan,
+               enum scan_type type,
+               uint8_t *buffer,
+               int scan_size,
+               struct scan_command *command);
 static void armjtagew_reset(int trst, int srst);
-//static void armjtagew_simple_command(uint8_t command);
+/* static void armjtagew_simple_command(uint8_t command); */
 static int armjtagew_get_status(void);
 
 /* tap buffer functions */
@@ -73,7 +77,7 @@ static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_c
 
 /* ARM-JTAG-EW lowlevel functions */
 struct armjtagew {
-       struct usb_dev_handleusb_handle;
+       struct usb_dev_handle *usb_handle;
 };
 
 static struct armjtagew *armjtagew_usb_open(void);
@@ -89,10 +93,10 @@ static int armjtagew_get_version_info(void);
 static void armjtagew_debug_buffer(uint8_t *buffer, int length);
 #endif
 
-static struct armjtagewarmjtagew_handle;
+static struct armjtagew *armjtagew_handle;
 
-/***************************************************************************/
-/* External interface implementation */
+/**************************************************************************
+ * External interface implementation */
 
 static int armjtagew_execute_queue(void)
 {
@@ -101,13 +105,12 @@ static int armjtagew_execute_queue(void)
        enum scan_type type;
        uint8_t *buffer;
 
-       while (cmd != NULL)
-       {
-               switch (cmd->type)
-               {
+       while (cmd != NULL) {
+               switch (cmd->type) {
                        case JTAG_RUNTEST:
-                               DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \
-                                       cmd->cmd.runtest->end_state);
+                               DEBUG_JTAG_IO("runtest %i cycles, end in %i",
+                                               cmd->cmd.runtest->num_cycles, \
+                                               cmd->cmd.runtest->end_state);
 
                                armjtagew_end_state(cmd->cmd.runtest->end_state);
                                armjtagew_runtest(cmd->cmd.runtest->num_cycles);
@@ -122,10 +125,11 @@ static int armjtagew_execute_queue(void)
 
                        case JTAG_PATHMOVE:
                                DEBUG_JTAG_IO("pathmove: %i states, end in %i", \
-                                       cmd->cmd.pathmove->num_states, \
-                                       cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
+                                               cmd->cmd.pathmove->num_states, \
+                                               cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
 
-                               armjtagew_path_move(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
+                               armjtagew_path_move(cmd->cmd.pathmove->num_states,
+                                               cmd->cmd.pathmove->path);
                                break;
 
                        case JTAG_SCAN:
@@ -140,18 +144,20 @@ static int armjtagew_execute_queue(void)
                                armjtagew_debug_buffer(buffer, (scan_size + 7) / 8);
 #endif
                                type = jtag_scan_type(cmd->cmd.scan);
-                               armjtagew_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size, cmd->cmd.scan);
+                               armjtagew_scan(cmd->cmd.scan->ir_scan,
+                                               type, buffer,
+                                               scan_size, cmd->cmd.scan);
                                break;
 
                        case JTAG_RESET:
-                               DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
+                               DEBUG_JTAG_IO("reset trst: %i srst %i",
+                                               cmd->cmd.reset->trst,
+                                               cmd->cmd.reset->srst);
 
                                armjtagew_tap_execute();
 
                                if (cmd->cmd.reset->trst == 1)
-                               {
                                        tap_set_state(TAP_RESET);
-                               }
                                armjtagew_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
                                break;
 
@@ -183,8 +189,7 @@ static int armjtagew_speed(int speed)
 
        result = armjtagew_usb_message(armjtagew_handle, 5, 4);
 
-       if (result < 0)
-       {
+       if (result < 0) {
                LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result);
                return ERROR_JTAG_DEVICE_ERROR;
        }
@@ -192,15 +197,11 @@ static int armjtagew_speed(int speed)
        usb_out_buffer[0] = CMD_GET_TCK_FREQUENCY;
        result = armjtagew_usb_message(armjtagew_handle, 1, 4);
        speed_real = (int)buf_get_u32(usb_in_buffer, 0, 32) / 1000;
-       if (result < 0)
-       {
+       if (result < 0) {
                LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result);
                return ERROR_JTAG_DEVICE_ERROR;
-       }
-       else
-       {
+       } else
                LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real);
-       }
 
        return ERROR_OK;
 }
@@ -212,7 +213,7 @@ static int armjtagew_khz(int khz, int *jtag_speed)
        return ERROR_OK;
 }
 
-static int armjtagew_speed_div(int speed, intkhz)
+static int armjtagew_speed_div(int speed, int *khz)
 {
        *khz = speed;
 
@@ -225,17 +226,15 @@ static int armjtagew_init(void)
 
        armjtagew_handle = armjtagew_usb_open();
 
-       if (armjtagew_handle == 0)
-       {
-               LOG_ERROR("Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
+       if (armjtagew_handle == 0) {
+               LOG_ERROR(
+                       "Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
                return ERROR_JTAG_INIT_FAILED;
        }
 
        check_cnt = 0;
-       while (check_cnt < 3)
-       {
-               if (armjtagew_get_version_info() == ERROR_OK)
-               {
+       while (check_cnt < 3) {
+               if (armjtagew_get_version_info() == ERROR_OK) {
                        /* attempt to get status */
                        armjtagew_get_status();
                        break;
@@ -245,9 +244,7 @@ static int armjtagew_init(void)
        }
 
        if (check_cnt == 3)
-       {
                LOG_INFO("ARM-JTAG-EW initial read failed, don't worry");
-       }
 
        /* Initial JTAG speed (for reset and initialization): 32 kHz */
        armjtagew_speed(32);
@@ -266,17 +263,14 @@ static int armjtagew_quit(void)
        return ERROR_OK;
 }
 
-/***************************************************************************/
-/* Queue command implementations */
+/**************************************************************************
+ * Queue command implementations */
 
 static void armjtagew_end_state(tap_state_t state)
 {
        if (tap_is_state_stable(state))
-       {
                tap_set_end_state(state);
-       }
-       else
-       {
+       else {
                LOG_ERROR("BUG: %i is not a valid end state", state);
                exit(-1);
        }
@@ -290,8 +284,7 @@ static void armjtagew_state_move(void)
        uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
        int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
 
-       for (i = 0; i < tms_count; i++)
-       {
+       for (i = 0; i < tms_count; i++) {
                tms = (tms_scan >> i) & 1;
                armjtagew_tap_append_step(tms, 0);
        }
@@ -303,24 +296,19 @@ static void armjtagew_path_move(int num_states, tap_state_t *path)
 {
        int i;
 
-       for (i = 0; i < num_states; i++)
-       {
+       for (i = 0; i < num_states; i++) {
                /*
                 * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode.
                 * Either handle that here, or update the documentation with examples
                 * how to fix that in the configuration files.
                 */
                if (path[i] == tap_state_transition(tap_get_state(), false))
-               {
                        armjtagew_tap_append_step(0, 0);
-               }
                else if (path[i] == tap_state_transition(tap_get_state(), true))
-               {
                        armjtagew_tap_append_step(1, 0);
-               }
-               else
-               {
-                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(path[i]));
+               else {
+                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
+                               tap_state_name(tap_get_state()), tap_state_name(path[i]));
                        exit(-1);
                }
 
@@ -337,27 +325,26 @@ static void armjtagew_runtest(int num_cycles)
        tap_state_t saved_end_state = tap_get_end_state();
 
        /* only do a state_move when we're not already in IDLE */
-       if (tap_get_state() != TAP_IDLE)
-       {
+       if (tap_get_state() != TAP_IDLE) {
                armjtagew_end_state(TAP_IDLE);
                armjtagew_state_move();
        }
 
        /* execute num_cycles */
        for (i = 0; i < num_cycles; i++)
-       {
                armjtagew_tap_append_step(0, 0);
-       }
 
        /* finish in end_state */
        armjtagew_end_state(saved_end_state);
        if (tap_get_state() != tap_get_end_state())
-       {
                armjtagew_state_move();
-       }
 }
 
-static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
+static void armjtagew_scan(bool ir_scan,
+       enum scan_type type,
+       uint8_t *buffer,
+       int scan_size,
+       struct scan_command *command)
 {
        tap_state_t saved_end_state;
 
@@ -380,9 +367,7 @@ static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, i
        tap_set_state(ir_scan ? TAP_IRPAUSE : TAP_DRPAUSE);
 
        if (tap_get_state() != tap_get_end_state())
-       {
                armjtagew_state_move();
-       }
 }
 
 static void armjtagew_reset(int trst, int srst)
@@ -396,27 +381,21 @@ static void armjtagew_reset(int trst, int srst)
 
        LOG_DEBUG("trst: %i, srst: %i", trst, srst);
 
-       if (srst == 0)
-       {
+       if (srst == 0) {
                val |= srst_mask;
                outp_en &= ~srst_mask;          /* tristate */
                change_mask |= srst_mask;
-       }
-       else if (srst == 1)
-       {
+       } else if (srst == 1) {
                val &= ~srst_mask;
                outp_en |= srst_mask;
                change_mask |= srst_mask;
        }
 
-       if (trst == 0)
-       {
+       if (trst == 0) {
                val |= trst_mask;
                outp_en &= ~trst_mask;          /* tristate */
                change_mask |= trst_mask;
-       }
-       else if (trst == 1)
-       {
+       } else if (trst == 1) {
                val &= ~trst_mask;
                outp_en |= trst_mask;
                change_mask |= trst_mask;
@@ -428,9 +407,7 @@ static void armjtagew_reset(int trst, int srst)
        usb_out_buffer[3] = change_mask;
        result = armjtagew_usb_write(armjtagew_handle, 4);
        if (result != 4)
-       {
                LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
-       }
 }
 
 static int armjtagew_get_status(void)
@@ -440,27 +417,22 @@ static int armjtagew_get_status(void)
        usb_out_buffer[0] = CMD_GET_TAPHW_STATE;
        result = armjtagew_usb_message(armjtagew_handle, 1, 12);
 
-       if (result == 0)
-       {
+       if (result == 0) {
                unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16);
-               LOG_INFO("U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
-                        (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)),
-                        (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)),
-                        (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
-                        (int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
-                        usb_in_buffer[9],
-                        usb_in_buffer[11] ? "OVERCURRENT" : "OK",
-                        usb_in_buffer[10] ? "enabled" : "disabled");
+               LOG_INFO(
+                       "U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
+                       (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)),
+                       (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)),
+                       (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
+                       (int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
+                       usb_in_buffer[9],
+                       usb_in_buffer[11] ? "OVERCURRENT" : "OK",
+                       usb_in_buffer[10] ? "enabled" : "disabled");
 
                if (u_tg < 1500)
-               {
                        LOG_ERROR("Vref too low. Check Target Power");
-               }
-       }
-       else
-       {
+       } else
                LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
-       }
 
        return ERROR_OK;
 }
@@ -475,34 +447,35 @@ static int armjtagew_get_version_info(void)
        usb_out_buffer[0] = CMD_GET_VERSION;
        result = armjtagew_usb_message(armjtagew_handle, 1, 4 + 15 + 256);
 
-       if (result != 0)
-       {
+       if (result != 0) {
                LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result);
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
-
        memcpy(sn, usb_in_buffer + 4, 15);
        sn[15] = '\0';
        memcpy(auxinfo, usb_in_buffer + 4+15, 256);
        auxinfo[256] = '\0';
 
-       LOG_INFO("ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s", \
-                       usb_in_buffer[1], usb_in_buffer[0], \
-                       isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X', \
-                       sn, auxinfo);
+       LOG_INFO(
+               "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s", \
+               usb_in_buffer[1],
+               usb_in_buffer[0], \
+               isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X', \
+               sn,
+               auxinfo);
 
        if (1 != usb_in_buffer[1] || 6 != usb_in_buffer[0])
-       {
-               LOG_WARNING("ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.", usb_in_buffer[1], usb_in_buffer[0]);
-       }
+               LOG_WARNING(
+                       "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
+                       usb_in_buffer[1],
+                       usb_in_buffer[0]);
        return ERROR_OK;
 }
 
 COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
 {
-       if (armjtagew_get_version_info() == ERROR_OK)
-       {
+       if (armjtagew_get_version_info() == ERROR_OK) {
                /* attempt to get status */
                armjtagew_get_status();
        }
@@ -532,8 +505,8 @@ struct jtag_interface armjtagew_interface = {
        .quit = armjtagew_quit,
 };
 
-/***************************************************************************/
-/* ARM-JTAG-EW tap functions */
+/**************************************************************************
+ * ARM-JTAG-EW tap functions */
 
 /* 2048 is the max value we can use here */
 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
@@ -545,8 +518,8 @@ static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE];
 
 struct pending_scan_result {
        int first;      /* First bit position in tdo_buffer to read */
-       int length; /* Number of bits to read */
-       struct scan_command *command; /* Corresponding scan command */
+       int length;     /* Number of bits to read */
+       struct scan_command *command;   /* Corresponding scan command */
        uint8_t *buffer;
 };
 
@@ -569,9 +542,7 @@ static void armjtagew_tap_ensure_space(int scans, int bits)
        int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length;
 
        if (scans > available_scans || bits > available_bits)
-       {
                armjtagew_tap_execute();
-       }
 }
 
 static void armjtagew_tap_append_step(int tms, int tdi)
@@ -579,40 +550,29 @@ static void armjtagew_tap_append_step(int tms, int tdi)
        last_tms = tms;
        int index_local = tap_length / 8;
 
-       if (index_local < ARMJTAGEW_TAP_BUFFER_SIZE)
-       {
+       if (index_local < ARMJTAGEW_TAP_BUFFER_SIZE) {
                int bit_index = tap_length % 8;
                uint8_t bit = 1 << bit_index;
 
                if (tms)
-               {
                        tms_buffer[index_local] |= bit;
-               }
                else
-               {
                        tms_buffer[index_local] &= ~bit;
-               }
 
                if (tdi)
-               {
                        tdi_buffer[index_local] |= bit;
-               }
                else
-               {
                        tdi_buffer[index_local] &= ~bit;
-               }
 
                tap_length++;
-       }
-       else
-       {
+       } else
                LOG_ERROR("armjtagew_tap_append_step, overflow");
-       }
 }
 
 void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
 {
-       struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[pending_scan_results_length];
+       struct pending_scan_result *pending_scan_result =
+               &pending_scan_results_buffer[pending_scan_results_length];
        int i;
 
        pending_scan_result->first = tap_length;
@@ -621,9 +581,7 @@ void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command
        pending_scan_result->buffer = buffer;
 
        for (i = 0; i < length; i++)
-       {
                armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1);
-       }
        pending_scan_results_length++;
 }
 
@@ -637,11 +595,9 @@ static int armjtagew_tap_execute(void)
        int i;
        int result;
 
-       if (tap_length > 0)
-       {
+       if (tap_length > 0) {
                /* Pad last byte so that tap_length is divisible by 8 */
-               while (tap_length % 8 != 0)
-               {
+               while (tap_length % 8 != 0) {
                        /* More of the last TMS value keeps us in the same state,
                         * analogous to free-running JTAG interfaces. */
                        armjtagew_tap_append_step(last_tms, 0);
@@ -654,36 +610,33 @@ static int armjtagew_tap_execute(void)
 
                tms_offset = 3;
                for (i = 0; i < byte_length; i++)
-               {
-                       usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i],8);
-               }
+                       usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i], 8);
 
                tdi_offset = tms_offset + byte_length;
                for (i = 0; i < byte_length; i++)
-               {
-                       usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i],8);
-               }
+                       usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i], 8);
 
-               result = armjtagew_usb_message(armjtagew_handle, 3 + 2 * byte_length, byte_length + 4);
+               result = armjtagew_usb_message(armjtagew_handle,
+                               3 + 2 * byte_length,
+                               byte_length + 4);
 
-               if (result == 0)
-               {
+               if (result == 0) {
                        int stat_local;
 
                        stat_local = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32);
                        if (stat_local) {
-                               LOG_ERROR("armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command", stat_local);
+                               LOG_ERROR(
+                                       "armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
+                                       stat_local);
                                return ERROR_JTAG_QUEUE_FAILED;
                        }
 
                        for (i = 0; i < byte_length; i++)
-                       {
-                               tdo_buffer[i] = flip_u32(usb_in_buffer[i],8);
-                       }
+                               tdo_buffer[i] = flip_u32(usb_in_buffer[i], 8);
 
-                       for (i = 0; i < pending_scan_results_length; i++)
-                       {
-                               struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[i];
+                       for (i = 0; i < pending_scan_results_length; i++) {
+                               struct pending_scan_result *pending_scan_result =
+                                       &pending_scan_results_buffer[i];
                                uint8_t *buffer = pending_scan_result->buffer;
                                int length = pending_scan_result->length;
                                int first = pending_scan_result->first;
@@ -698,21 +651,18 @@ static int armjtagew_tap_execute(void)
                                armjtagew_debug_buffer(buffer, byte_length);
 #endif
 
-                               if (jtag_read_buffer(buffer, command) != ERROR_OK)
-                               {
+                               if (jtag_read_buffer(buffer, command) != ERROR_OK) {
                                        armjtagew_tap_init();
                                        return ERROR_JTAG_QUEUE_FAILED;
                                }
 
                                if (pending_scan_result->buffer != NULL)
-                               {
                                        free(pending_scan_result->buffer);
-                               }
                        }
-               }
-               else
-               {
-                       LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d", result, byte_length);
+               } else {
+                       LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
+                               result,
+                               byte_length);
                        return ERROR_JTAG_QUEUE_FAILED;
                }
 
@@ -722,10 +672,10 @@ static int armjtagew_tap_execute(void)
        return ERROR_OK;
 }
 
-/*****************************************************************************/
-/* JLink USB low-level functions */
+/****************************************************************************
+ * JLink USB low-level functions */
 
-static struct armjtagewarmjtagew_usb_open()
+static struct armjtagew *armjtagew_usb_open()
 {
        usb_init();
 
@@ -765,17 +715,15 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in
        int result;
 
        result = armjtagew_usb_write(armjtagew, out_length);
-       if (result == out_length)
-       {
+       if (result == out_length) {
                result = armjtagew_usb_read(armjtagew, in_length);
-               if (result != in_length)
-               {
-                       LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", in_length, result);
+               if (result != in_length) {
+                       LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)",
+                               in_length,
+                               result);
                        return -1;
                }
-       }
-       else
-       {
+       } else {
                LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
                return -1;
        }
@@ -787,14 +735,15 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
 {
        int result;
 
-       if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE)
-       {
-               LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)", out_length, ARMJTAGEW_OUT_BUFFER_SIZE);
+       if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) {
+               LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
+                       out_length,
+                       ARMJTAGEW_OUT_BUFFER_SIZE);
                return -1;
        }
 
        result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, \
-               (char*)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT);
+                       (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT);
 
        DEBUG_JTAG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
 
@@ -808,7 +757,7 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
 {
        int result = usb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN, \
-               (char*)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT);
+                       (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT);
 
        DEBUG_JTAG_IO("armjtagew_usb_read, result = %d", result);
 
@@ -828,17 +777,15 @@ static void armjtagew_debug_buffer(uint8_t *buffer, int length)
        int i;
        int j;
 
-       for (i = 0; i < length; i += BYTES_PER_LINE)
-       {
+       for (i = 0; i < length; i += BYTES_PER_LINE) {
                snprintf(line, 5, "%04x", i);
-               for (j = i; j < i + BYTES_PER_LINE && j < length; j++)
-               {
+               for (j = i; j < i + BYTES_PER_LINE && j < length; j++) {
                        snprintf(s, 4, " %02x", buffer[j]);
                        strcat(line, s);
                }
                LOG_DEBUG("%s", line);
 
-               // Prevent GDB timeout (writing to log might take some time)
+               /* Prevent GDB timeout (writing to log might take some time) */
                keep_alive();
        }
 }
index 6d0dfac..3bba368 100644 (file)
@@ -17,6 +17,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -26,7 +27,6 @@
 
 #include <sys/mman.h>
 
-
 /* AT91RM9200 */
 #define AT91C_BASE_SYS (0xfffff000)
 
@@ -78,9 +78,8 @@
 #define P30    (1 << 30)
 #define P31    (1 << 31)
 
-struct device_t
-{
-       char* name;
+struct device_t {
+       char *name;
        int TDO_PIO;    /* PIO holding TDO */
        uint32_t TDO_MASK;      /* TDO bitmask */
        int TRST_PIO;   /* PIO holding TRST */
@@ -95,21 +94,20 @@ struct device_t
        uint32_t SRST_MASK;     /* SRST bitmask */
 };
 
-static struct device_t devices[] =
-{
+static struct device_t devices[] = {
        { "rea_ecr", PIOD, P27, PIOA, NC, PIOD, P23, PIOD, P24, PIOD, P26, PIOC, P5 },
        { .name = NULL },
 };
 
 /* configuration */
-static charat91rm9200_device;
+static char *at91rm9200_device;
 
 /* interface variables
  */
-static struct device_tdevice;
+static struct device_t *device;
 static int dev_mem_fd;
 static void *sys_controller;
-static uint32_tpio_base;
+static uint32_t *pio_base;
 
 /* low level command set
  */
@@ -121,8 +119,7 @@ static int at91rm9200_speed(int speed);
 static int at91rm9200_init(void);
 static int at91rm9200_quit(void);
 
-static struct bitbang_interface at91rm9200_bitbang =
-{
+static struct bitbang_interface at91rm9200_bitbang = {
        .read = at91rm9200_read,
        .write = at91rm9200_write,
        .reset = at91rm9200_reset,
@@ -178,8 +175,7 @@ COMMAND_HANDLER(at91rm9200_handle_device_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        /* only if the device name wasn't overwritten by cmdline */
-       if (at91rm9200_device == 0)
-       {
+       if (at91rm9200_device == 0) {
                at91rm9200_device = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
                strcpy(at91rm9200_device, CMD_ARGV[0]);
        }
@@ -197,12 +193,9 @@ static const struct command_registration at91rm9200_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct jtag_interface at91rm9200_interface =
-{
+struct jtag_interface at91rm9200_interface = {
        .name = "at91rm9200",
-
        .execute_queue = bitbang_execute_queue,
-
        .speed = at91rm9200_speed,
        .commands = at91rm9200_command_handlers,
        .init = at91rm9200_init,
@@ -215,24 +208,20 @@ static int at91rm9200_init(void)
 
        cur_device = devices;
 
-       if (at91rm9200_device == NULL || at91rm9200_device[0] == 0)
-       {
+       if (at91rm9200_device == NULL || at91rm9200_device[0] == 0) {
                at91rm9200_device = "rea_ecr";
                LOG_WARNING("No at91rm9200 device specified, using default 'rea_ecr'");
        }
 
-       while (cur_device->name)
-       {
-               if (strcmp(cur_device->name, at91rm9200_device) == 0)
-               {
+       while (cur_device->name) {
+               if (strcmp(cur_device->name, at91rm9200_device) == 0) {
                        device = cur_device;
                        break;
                }
                cur_device++;
        }
 
-       if (!device)
-       {
+       if (!device) {
                LOG_ERROR("No matching device found for %s", at91rm9200_device);
                return ERROR_JTAG_INIT_FAILED;
        }
@@ -252,7 +241,7 @@ static int at91rm9200_init(void)
                close(dev_mem_fd);
                return ERROR_JTAG_INIT_FAILED;
        }
-       pio_base = (uint32_t*)sys_controller + 0x100;
+       pio_base = (uint32_t *)sys_controller + 0x100;
 
        /*
         * Configure TDO as an input, and TDI, TCK, TMS, TRST, SRST
index 4548cb5..8a097ca 100644 (file)
@@ -20,6 +20,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -38,7 +39,6 @@
  */
 static void bitbang_stableclocks(int num_cycles);
 
-
 struct bitbang_interface *bitbang_interface;
 
 /* DANGER!!!! clock absolutely *MUST* be 0 in idle or reset won't work!
@@ -61,14 +61,12 @@ struct bitbang_interface *bitbang_interface;
  */
 #define CLOCK_IDLE() 0
 
-
 /* The bitbang driver leaves the TCK 0 when in idle */
 static void bitbang_end_state(tap_state_t state)
 {
        if (tap_is_state_stable(state))
                tap_set_end_state(state);
-       else
-       {
+       else {
                LOG_ERROR("BUG: %i is not a valid end state", state);
                exit(-1);
        }
@@ -80,8 +78,7 @@ static void bitbang_state_move(int skip)
        uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
        int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
 
-       for (i = skip; i < tms_count; i++)
-       {
+       for (i = skip; i < tms_count; i++) {
                tms = (tms_scan >> i) & 1;
                bitbang_interface->write(0, tms, 0);
                bitbang_interface->write(1, tms, 0);
@@ -91,21 +88,19 @@ static void bitbang_state_move(int skip)
        tap_set_state(tap_get_end_state());
 }
 
-
 /**
  * Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG
  * (or SWD) state machine.
  */
 static int bitbang_execute_tms(struct jtag_command *cmd)
 {
-       unsigned        num_bits = cmd->cmd.tms->num_bits;
-       const uint8_t   *bits = cmd->cmd.tms->bits;
+       unsigned num_bits = cmd->cmd.tms->num_bits;
+       const uint8_t *bits = cmd->cmd.tms->bits;
 
        DEBUG_JTAG_IO("TMS: %d bits", num_bits);
 
        int tms = 0;
-       for (unsigned i = 0; i < num_bits; i++)
-       {
+       for (unsigned i = 0; i < num_bits; i++) {
                tms = ((bits[i/8] >> (i % 8)) & 1);
                bitbang_interface->write(0, tms, 0);
                bitbang_interface->write(1, tms, 0);
@@ -115,7 +110,6 @@ static int bitbang_execute_tms(struct jtag_command *cmd)
        return ERROR_OK;
 }
 
-
 static void bitbang_path_move(struct pathmove_command *cmd)
 {
        int num_states = cmd->num_states;
@@ -123,19 +117,15 @@ static void bitbang_path_move(struct pathmove_command *cmd)
        int tms = 0;
 
        state_count = 0;
-       while (num_states)
-       {
+       while (num_states) {
                if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
-               {
                        tms = 0;
-               }
                else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
-               {
                        tms = 1;
-               }
-               else
-               {
-                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(cmd->path[state_count]));
+               else {
+                       LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
+                               tap_state_name(tap_get_state()),
+                               tap_state_name(cmd->path[state_count]));
                        exit(-1);
                }
 
@@ -159,15 +149,13 @@ static void bitbang_runtest(int num_cycles)
        tap_state_t saved_end_state = tap_get_end_state();
 
        /* only do a state_move when we're not already in IDLE */
-       if (tap_get_state() != TAP_IDLE)
-       {
+       if (tap_get_state() != TAP_IDLE) {
                bitbang_end_state(TAP_IDLE);
                bitbang_state_move(0);
        }
 
        /* execute num_cycles */
-       for (i = 0; i < num_cycles; i++)
-       {
+       for (i = 0; i < num_cycles; i++) {
                bitbang_interface->write(0, 0, 0);
                bitbang_interface->write(1, 0, 0);
        }
@@ -179,29 +167,26 @@ static void bitbang_runtest(int num_cycles)
                bitbang_state_move(0);
 }
 
-
 static void bitbang_stableclocks(int num_cycles)
 {
        int tms = (tap_get_state() == TAP_RESET ? 1 : 0);
        int i;
 
        /* send num_cycles clocks onto the cable */
-       for (i = 0; i < num_cycles; i++)
-       {
+       for (i = 0; i < num_cycles; i++) {
                bitbang_interface->write(1, tms, 0);
                bitbang_interface->write(0, tms, 0);
        }
 }
 
-
-
 static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
 {
        tap_state_t saved_end_state = tap_get_end_state();
        int bit_cnt;
 
-       if (!((!ir_scan && (tap_get_state() == TAP_DRSHIFT)) || (ir_scan && (tap_get_state() == TAP_IRSHIFT))))
-       {
+       if (!((!ir_scan &&
+                       (tap_get_state() == TAP_DRSHIFT)) ||
+                       (ir_scan && (tap_get_state() == TAP_IRSHIFT)))) {
                if (ir_scan)
                        bitbang_end_state(TAP_IRSHIFT);
                else
@@ -211,8 +196,7 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
                bitbang_end_state(saved_end_state);
        }
 
-       for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++)
-       {
+       for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
                int val = 0;
                int tms = (bit_cnt == scan_size-1) ? 1 : 0;
                int tdi;
@@ -234,8 +218,7 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
 
                bitbang_interface->write(1, tms, tdi);
 
-               if (type != SCAN_OUT)
-               {
+               if (type != SCAN_OUT) {
                        if (val)
                                buffer[bytec] |= bcval;
                        else
@@ -243,8 +226,7 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
                }
        }
 
-       if (tap_get_state() != tap_get_end_state())
-       {
+       if (tap_get_state() != tap_get_end_state()) {
                /* we *KNOW* the above loop transitioned out of
                 * the shift state, so we skip the first state
                 * and move directly to the end state.
@@ -255,14 +237,13 @@ static void bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
 
 int bitbang_execute_queue(void)
 {
-       struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
+       struct jtag_command *cmd = jtag_command_queue;  /* currently processed command */
        int scan_size;
        enum scan_type type;
        uint8_t *buffer;
        int retval;
 
-       if (!bitbang_interface)
-       {
+       if (!bitbang_interface) {
                LOG_ERROR("BUG: Bitbang interface called, but not yet initialized");
                exit(-1);
        }
@@ -275,23 +256,24 @@ int bitbang_execute_queue(void)
        if (bitbang_interface->blink)
                bitbang_interface->blink(1);
 
-       while (cmd)
-       {
-               switch (cmd->type)
-               {
+       while (cmd) {
+               switch (cmd->type) {
                        case JTAG_RESET:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
+                               LOG_DEBUG("reset trst: %i srst %i",
+                               cmd->cmd.reset->trst,
+                               cmd->cmd.reset->srst);
 #endif
-                               if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
-                               {
+                               if ((cmd->cmd.reset->trst == 1) ||
+                                               (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
                                        tap_set_state(TAP_RESET);
-                               }
                                bitbang_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
                                break;
                        case JTAG_RUNTEST:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state));
+                               LOG_DEBUG("runtest %i cycles, end in %s",
+                                               cmd->cmd.runtest->num_cycles,
+                                               tap_state_name(cmd->cmd.runtest->end_state));
 #endif
                                bitbang_end_state(cmd->cmd.runtest->end_state);
                                bitbang_runtest(cmd->cmd.runtest->num_cycles);
@@ -306,21 +288,25 @@ int bitbang_execute_queue(void)
 
                        case JTAG_TLR_RESET:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state));
+                               LOG_DEBUG("statemove end in %s",
+                                               tap_state_name(cmd->cmd.statemove->end_state));
 #endif
                                bitbang_end_state(cmd->cmd.statemove->end_state);
                                bitbang_state_move(0);
                                break;
                        case JTAG_PATHMOVE:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states,
-                                       tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
+                               LOG_DEBUG("pathmove: %i states, end in %s",
+                                               cmd->cmd.pathmove->num_states,
+                                               tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]));
 #endif
                                bitbang_path_move(cmd->cmd.pathmove);
                                break;
                        case JTAG_SCAN:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("%s scan end in %s",  (cmd->cmd.scan->ir_scan) ? "IR" : "DR", tap_state_name(cmd->cmd.scan->end_state));
+                               LOG_DEBUG("%s scan end in %s",
+                                               (cmd->cmd.scan->ir_scan) ? "IR" : "DR",
+                                       tap_state_name(cmd->cmd.scan->end_state));
 #endif
                                bitbang_end_state(cmd->cmd.scan->end_state);
                                scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
index db5c4cb..77f6954 100644 (file)
@@ -20,6 +20,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifndef BITBANG_H
 #define BITBANG_H
 
index 87e0983..ac58190 100644 (file)
@@ -17,6 +17,7 @@
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -25,8 +26,7 @@
 #include "bitq.h"
 #include <jtag/interface.h>
 
-
-struct bitq_interface* bitq_interface;       /* low level bit queue interface */
+struct bitq_interface *bitq_interface; /* low level bit queue interface */
 
 /* state of input queue */
 struct bitq_state {
@@ -44,29 +44,23 @@ static struct bitq_state bitq_in_state;
 static void bitq_in_proc(void)
 {
        /* loop through the queue */
-       while (bitq_in_state.cmd)
-       {
+       while (bitq_in_state.cmd) {
                /* only JTAG_SCAN command may return data */
-               if (bitq_in_state.cmd->type == JTAG_SCAN)
-               {
+               if (bitq_in_state.cmd->type == JTAG_SCAN) {
                        /* loop through the fields */
-                       while (bitq_in_state.field_idx < bitq_in_state.cmd->cmd.scan->num_fields)
-                       {
+                       while (bitq_in_state.field_idx < bitq_in_state.cmd->cmd.scan->num_fields) {
                                struct scan_field *field;
                                field = &bitq_in_state.cmd->cmd.scan->fields[bitq_in_state.field_idx];
-                               if (field->in_value)
-                               {
+                               if (field->in_value) {
                                        /* field scanning */
-                                       while (bitq_in_state.bit_pos < field->num_bits)
-                                       {
+                                       while (bitq_in_state.bit_pos < field->num_bits) {
                                                /* index of byte being scanned */
                                                int in_idx = bitq_in_state.bit_pos / 8;
                                                /* mask of next bit to be scanned */
                                                uint8_t in_mask = 1 << (bitq_in_state.bit_pos % 8);
 
                                                int tdo = bitq_interface->in();
-                                               if (tdo < 0)
-                                               {
+                                               if (tdo < 0) {
 #ifdef _DEBUG_JTAG_IO_
                                                        LOG_DEBUG("bitq in EOF");
 #endif
@@ -89,7 +83,6 @@ static void bitq_in_proc(void)
        }
 }
 
-
 static void bitq_io(int tms, int tdi, int tdo_req)
 {
        bitq_interface->out(tms, tdi, tdo_req);
@@ -98,25 +91,21 @@ static void bitq_io(int tms, int tdi, int tdo_req)
                bitq_in_proc();
 }
 
-
 static void bitq_end_state(tap_state_t state)
 {
-       if (!tap_is_state_stable(state))
-       {
+       if (!tap_is_state_stable(state)) {
                LOG_ERROR("BUG: %i is not a valid end state", state);
                exit(-1);
        }
        tap_set_end_state(state);
 }
 
-
 static void bitq_state_move(tap_state_t new_state)
 {
        int i = 0;
        uint8_t  tms_scan;
 
-       if (!tap_is_state_stable(tap_get_state()) || !tap_is_state_stable(new_state))
-       {
+       if (!tap_is_state_stable(tap_get_state()) || !tap_is_state_stable(new_state)) {
                LOG_ERROR("TAP move from or to unstable state");
                exit(-1);
        }
@@ -124,8 +113,7 @@ static void bitq_state_move(tap_state_t new_state)
        tms_scan = tap_get_tms_path(tap_get_state(), new_state);
        int tms_count = tap_get_tms_path_len(tap_get_state(), new_state);
 
-       for (i = 0; i < tms_count; i++)
-       {
+       for (i = 0; i < tms_count; i++) {
                bitq_io(tms_scan & 1, 0, 0);
                tms_scan >>= 1;
        }
@@ -133,19 +121,16 @@ static void bitq_state_move(tap_state_t new_state)
        tap_set_state(new_state);
 }
 
-
 static void bitq_path_move(struct pathmove_command *cmd)
 {
        int i;
 
-       for (i = 0; i <= cmd->num_states; i++)
-       {
+       for (i = 0; i <= cmd->num_states; i++) {
                if (tap_state_transition(tap_get_state(), false) == cmd->path[i])
                        bitq_io(0, 0, 0);
                else if (tap_state_transition(tap_get_state(), true) == cmd->path[i])
                        bitq_io(1, 0, 0);
-               else
-               {
+               else {
                        LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(
                                                         tap_get_state()), tap_state_name(cmd->path[i]));
                        exit(-1);
@@ -157,7 +142,6 @@ static void bitq_path_move(struct pathmove_command *cmd)
        tap_set_end_state(tap_get_state());
 }
 
-
 static void bitq_runtest(int num_cycles)
 {
        int i;
@@ -175,13 +159,12 @@ static void bitq_runtest(int num_cycles)
                bitq_state_move(tap_get_end_state());
 }
 
-
 static void bitq_scan_field(struct scan_field *field, int do_pause)
 {
        int bit_cnt;
        int tdo_req;
 
-       const uint8_tout_ptr;
+       const uint8_t *out_ptr;
        uint8_t  out_mask;
 
        if (field->in_value)
@@ -189,36 +172,29 @@ static void bitq_scan_field(struct scan_field *field, int do_pause)
        else
                tdo_req = 0;
 
-       if (field->out_value == NULL)
-       {
+       if (field->out_value == NULL) {
                /* just send zeros and request data from TDO */
                for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--)
                        bitq_io(0, 0, tdo_req);
 
                bitq_io(do_pause, 0, tdo_req);
-       }
-       else
-       {
+       } else {
                /* send data, and optionally request TDO */
                out_mask = 0x01;
                out_ptr  = field->out_value;
-               for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--)
-               {
+               for (bit_cnt = field->num_bits; bit_cnt > 1; bit_cnt--) {
                        bitq_io(0, ((*out_ptr) & out_mask) != 0, tdo_req);
-                       if (out_mask == 0x80)
-                       {
+                       if (out_mask == 0x80) {
                                out_mask = 0x01;
                                out_ptr++;
-                       }
-                       else
+                       } else
                                out_mask <<= 1;
                }
 
                bitq_io(do_pause, ((*out_ptr) & out_mask) != 0, tdo_req);
        }
 
-       if (do_pause)
-       {
+       if (do_pause) {
                bitq_io(0, 0, 0);
                if (tap_get_state() == TAP_IRSHIFT)
                        tap_set_state(TAP_IRPAUSE);
@@ -227,7 +203,6 @@ static void bitq_scan_field(struct scan_field *field, int do_pause)
        }
 }
 
-
 static void bitq_scan(struct scan_command *cmd)
 {
        int i;
@@ -243,28 +218,25 @@ static void bitq_scan(struct scan_command *cmd)
        bitq_scan_field(&cmd->fields[i], 1);
 }
 
-
 int bitq_execute_queue(void)
 {
-       struct jtag_commandcmd = jtag_command_queue; /* currently processed command */
+       struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
 
        bitq_in_state.cmd = jtag_command_queue;
        bitq_in_state.field_idx = 0;
        bitq_in_state.bit_pos   = 0;
        bitq_in_state.status    = ERROR_OK;
 
-       while (cmd)
-       {
-               switch (cmd->type)
-               {
+       while (cmd) {
+               switch (cmd->type) {
                case JTAG_RESET:
 #ifdef _DEBUG_JTAG_IO_
                        LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
 #endif
-                       if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
-                       {
+                       if ((cmd->cmd.reset->trst == 1) ||
+                                       (cmd->cmd.reset->srst &&
+                                       (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
                                tap_set_state(TAP_RESET);
-                       }
                        bitq_interface->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
                        if (bitq_interface->in_rdy())
                                bitq_in_proc();
@@ -328,13 +300,11 @@ int bitq_execute_queue(void)
        bitq_interface->flush();
        bitq_in_proc();
 
-       if (bitq_in_state.cmd)
-       {
+       if (bitq_in_state.cmd) {
                LOG_ERROR("missing data from bitq interface");
                return ERROR_JTAG_QUEUE_FAILED;
        }
-       if (bitq_interface->in() >= 0)
-       {
+       if (bitq_interface->in() >= 0) {
                LOG_ERROR("extra data from bitq interface");
                return ERROR_JTAG_QUEUE_FAILED;
        }
@@ -342,7 +312,6 @@ int bitq_execute_queue(void)
        return bitq_in_state.status;
 }
 
-
 void bitq_cleanup(void)
 {
 }
index 75d208d..c65e931 100644 (file)
  *   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);
 
index f3edc8a..86b9882 100644 (file)
@@ -44,7 +44,6 @@ static void buspirate_runtest(int num_cycles);
 static void buspirate_scan(bool ir_scan, enum scan_type type,
        uint8_t *buffer, int scan_size, struct scan_command *command);
 
-
 #define CMD_UNKNOWN       0x00
 #define CMD_PORT_MODE     0x01
 #define CMD_FEATURE       0x02
@@ -84,7 +83,6 @@ enum {
        SERIAL_FAST = 1
 };
 
-
 static int buspirate_fd = -1;
 static int buspirate_pinmode = MODE_JTAG_OD;
 static int buspirate_baudrate = SERIAL_NORMAL;
@@ -92,7 +90,6 @@ static int buspirate_vreg;
 static int buspirate_pullup;
 static char *buspirate_port;
 
-
 /* TAP interface */
 static void buspirate_tap_init(void);
 static int buspirate_tap_execute(void);
@@ -279,9 +276,8 @@ COMMAND_HANDLER(buspirate_handle_adc_command)
 
 COMMAND_HANDLER(buspirate_handle_vreg_command)
 {
-       if (CMD_ARGC < 1) {
+       if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
        if (atoi(CMD_ARGV[0]) == 1)
                buspirate_vreg = 1;
@@ -296,9 +292,8 @@ COMMAND_HANDLER(buspirate_handle_vreg_command)
 
 COMMAND_HANDLER(buspirate_handle_pullup_command)
 {
-       if (CMD_ARGC < 1) {
+       if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
        if (atoi(CMD_ARGV[0]) == 1)
                buspirate_pullup = 1;
@@ -313,9 +308,8 @@ COMMAND_HANDLER(buspirate_handle_pullup_command)
 
 COMMAND_HANDLER(buspirate_handle_led_command)
 {
-       if (CMD_ARGC < 1) {
+       if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
        if (atoi(CMD_ARGV[0]) == 1) {
                /* enable led */
@@ -335,9 +329,8 @@ COMMAND_HANDLER(buspirate_handle_led_command)
 
 COMMAND_HANDLER(buspirate_handle_mode_command)
 {
-       if (CMD_ARGC < 1) {
+       if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
        if (CMD_ARGV[0][0] == 'n')
                buspirate_pinmode = MODE_JTAG;
@@ -352,9 +345,8 @@ COMMAND_HANDLER(buspirate_handle_mode_command)
 
 COMMAND_HANDLER(buspirate_handle_speed_command)
 {
-       if (CMD_ARGC < 1) {
+       if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
        if (CMD_ARGV[0][0] == 'n')
                buspirate_baudrate = SERIAL_NORMAL;
@@ -369,9 +361,8 @@ COMMAND_HANDLER(buspirate_handle_speed_command)
 
 COMMAND_HANDLER(buspirate_handle_port_command)
 {
-       if (CMD_ARGC < 1) {
+       if (CMD_ARGC < 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
        if (buspirate_port == NULL)
                buspirate_port = strdup(CMD_ARGV[0]);
@@ -987,8 +978,6 @@ static void buspirate_print_buffer(char *buf, int size)
                }
        }
 
-       if (line[0] != 0) {
+       if (line[0] != 0)
                LOG_DEBUG("%s", line);
-       }
 }
-
index 49f4024..87ed6ca 100644 (file)
@@ -27,6 +27,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -37,8 +38,7 @@
 #include <jtag/minidriver.h>
 #include <helper/command.h>
 
-struct jtag_callback_entry
-{
+struct jtag_callback_entry {
        struct jtag_callback_entry *next;
 
        jtag_callback_t callback;
@@ -48,8 +48,8 @@ struct jtag_callback_entry
        jtag_callback_data_t data3;
 };
 
-static struct jtag_callback_entry *jtag_callback_queue_head = NULL;
-static struct jtag_callback_entry *jtag_callback_queue_tail = NULL;
+static struct jtag_callback_entry *jtag_callback_queue_head;
+static struct jtag_callback_entry *jtag_callback_queue_tail;
 
 static void jtag_callback_queue_reset(void)
 {
@@ -62,60 +62,56 @@ static void jtag_callback_queue_reset(void)
  *
  * This allocates a new copy of out_value using cmd_queue_alloc.
  */
-static void cmd_queue_scan_field_clone(struct scan_field * dst, const struct scan_field * src)
+static void cmd_queue_scan_field_clone(struct scan_field *dst, const struct scan_field *src)
 {
        dst->num_bits   = src->num_bits;
        dst->out_value  = buf_cpy(src->out_value, cmd_queue_alloc(DIV_ROUND_UP(src->num_bits, 8)), src->num_bits);
        dst->in_value   = src->in_value;
 }
 
-
 /**
  * see jtag_add_ir_scan()
  *
  */
-int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field *in_fields, tap_state_t state)
+int interface_jtag_add_ir_scan(struct jtag_tap *active,
+               const struct scan_field *in_fields, tap_state_t state)
 {
        size_t num_taps = jtag_tap_count_enabled();
 
-       struct jtag_command * cmd               = cmd_queue_alloc(sizeof(struct jtag_command));
-       struct scan_command * scan              = cmd_queue_alloc(sizeof(struct scan_command));
-       struct scan_field * out_fields  = cmd_queue_alloc(num_taps  * sizeof(struct scan_field));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
+       struct scan_field *out_fields = cmd_queue_alloc(num_taps  * sizeof(struct scan_field));
 
        jtag_queue_command(cmd);
 
-       cmd->type                               = JTAG_SCAN;
-       cmd->cmd.scan                   = scan;
+       cmd->type = JTAG_SCAN;
+       cmd->cmd.scan = scan;
 
-       scan->ir_scan                   = true;
-       scan->num_fields                = num_taps;     /* one field per device */
-       scan->fields                    = out_fields;
-       scan->end_state                 = state;
+       scan->ir_scan = true;
+       scan->num_fields = num_taps;    /* one field per device */
+       scan->fields = out_fields;
+       scan->end_state = state;
 
-
-       struct scan_field * field = out_fields; /* keep track where we insert data */
+       struct scan_field *field = out_fields;  /* keep track where we insert data */
 
        /* loop over all enabled TAPs */
 
-       for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap))
-       {
+       for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
                /* search the input field list for fields for the current TAP */
 
-               if (tap == active)
-               {
+               if (tap == active) {
                        /* if TAP is listed in input fields, copy the value */
                        tap->bypass = 0;
 
                        cmd_queue_scan_field_clone(field, in_fields);
-               } else
-               {
+               } else {
                        /* if a TAP isn't listed in input fields, set it to BYPASS */
 
                        tap->bypass = 1;
 
-                       field->num_bits         = tap->ir_length;
-                       field->out_value        = buf_set_ones(cmd_queue_alloc(DIV_ROUND_UP(tap->ir_length, 8)), tap->ir_length);
-                       field->in_value         = NULL; /* do not collect input for tap's in bypass */
+                       field->num_bits = tap->ir_length;
+                       field->out_value = buf_set_ones(cmd_queue_alloc(DIV_ROUND_UP(tap->ir_length, 8)), tap->ir_length);
+                       field->in_value = NULL; /* do not collect input for tap's in bypass */
                }
 
                /* update device information */
@@ -123,8 +119,8 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
 
                field++;
        }
-
-       assert(field == out_fields + num_taps); /* paranoia: jtag_tap_count_enabled() and jtag_tap_next_enabled() not in sync */
+       /* paranoia: jtag_tap_count_enabled() and jtag_tap_next_enabled() not in sync */
+       assert(field == out_fields + num_taps);
 
        return ERROR_OK;
 }
@@ -133,51 +129,47 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
  * see jtag_add_dr_scan()
  *
  */
-int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
+int interface_jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields,
+               const struct scan_field *in_fields, tap_state_t state)
 {
        /* count devices in bypass */
 
        size_t bypass_devices = 0;
 
-       for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap))
-       {
+       for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
                if (tap->bypass)
                        bypass_devices++;
        }
 
-       struct jtag_command * cmd               = cmd_queue_alloc(sizeof(struct jtag_command));
-       struct scan_command * scan              = cmd_queue_alloc(sizeof(struct scan_command));
-       struct scan_field * out_fields  = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
+       struct scan_field *out_fields = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field));
 
        jtag_queue_command(cmd);
 
-       cmd->type                               = JTAG_SCAN;
-       cmd->cmd.scan                   = scan;
+       cmd->type = JTAG_SCAN;
+       cmd->cmd.scan = scan;
 
-       scan->ir_scan                   = false;
-       scan->num_fields                = in_num_fields + bypass_devices;
-       scan->fields                    = out_fields;
-       scan->end_state                 = state;
+       scan->ir_scan = false;
+       scan->num_fields = in_num_fields + bypass_devices;
+       scan->fields = out_fields;
+       scan->end_state = state;
 
-
-       struct scan_field * field = out_fields; /* keep track where we insert data */
+       struct scan_field *field = out_fields;  /* keep track where we insert data */
 
        /* loop over all enabled TAPs */
 
-       for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap))
-       {
+       for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
                /* if TAP is not bypassed insert matching input fields */
 
-               if (!tap->bypass)
-               {
+               if (!tap->bypass) {
                        assert(active == tap);
 #ifndef NDEBUG
                        /* remember initial position for assert() */
                        struct scan_field *start_field = field;
 #endif /* NDEBUG */
 
-                       for (int j = 0; j < in_num_fields; j++)
-                       {
+                       for (int j = 0; j < in_num_fields; j++) {
                                cmd_queue_scan_field_clone(field, in_fields + j);
 
                                field++;
@@ -187,11 +179,10 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
                }
 
                /* if a TAP is bypassed, generated a dummy bit*/
-               else
-               {
-                       field->num_bits         = 1;
-                       field->out_value        = NULL;
-                       field->in_value         = NULL;
+               else {
+                       field->num_bits = 1;
+                       field->out_value = NULL;
+                       field->in_value = NULL;
 
                        field++;
                }
@@ -202,8 +193,6 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
        return ERROR_OK;
 }
 
-
-
 /**
  * Generate a DR SCAN using the array of output values passed to the function
  *
@@ -228,65 +217,60 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
 
        size_t bypass_devices = 0;
 
-       for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap))
-       {
+       for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
                if (tap->bypass)
                        bypass_devices++;
        }
 
 
-       struct jtag_command * cmd               = cmd_queue_alloc(sizeof(struct jtag_command));
-       struct scan_command * scan              = cmd_queue_alloc(sizeof(struct scan_command));
-       struct scan_field * out_fields  = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
+       struct scan_field *out_fields = cmd_queue_alloc((in_num_fields + bypass_devices) * sizeof(struct scan_field));
 
        jtag_queue_command(cmd);
 
-       cmd->type                               = JTAG_SCAN;
-       cmd->cmd.scan                   = scan;
+       cmd->type = JTAG_SCAN;
+       cmd->cmd.scan = scan;
 
-       scan->ir_scan                   = false;
-       scan->num_fields                = in_num_fields + bypass_devices;
-       scan->fields                    = out_fields;
-       scan->end_state                 = end_state;
+       scan->ir_scan = false;
+       scan->num_fields = in_num_fields + bypass_devices;
+       scan->fields = out_fields;
+       scan->end_state = end_state;
 
 
        bool target_tap_match   = false;
 
-       struct scan_field * field = out_fields; /* keep track where we insert data */
+       struct scan_field *field = out_fields;  /* keep track where we insert data */
 
        /* loop over all enabled TAPs */
 
-       for (struct jtag_tap * tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap))
-       {
+       for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = jtag_tap_next_enabled(tap)) {
                /* if TAP is not bypassed insert matching input fields */
 
-               if (!tap->bypass)
-               {
+               if (!tap->bypass) {
                        assert(tap == target_tap); /* target_tap must match the one not bypassed TAP */
 
                        target_tap_match = true;
 
-                       for (int j = 0; j < in_num_fields; j++)
-                       {
+                       for (int j = 0; j < in_num_fields; j++) {
                                uint8_t out_value[4];
                                size_t scan_size = num_bits[j];
                                buf_set_u32(out_value, 0, scan_size, value[j]);
 
-                               field->num_bits         = scan_size;
-                               field->out_value        = buf_cpy(out_value, cmd_queue_alloc(DIV_ROUND_UP(scan_size, 8)), scan_size);
-                               field->in_value         = NULL;
+                               field->num_bits = scan_size;
+                               field->out_value = buf_cpy(out_value, cmd_queue_alloc(DIV_ROUND_UP(scan_size, 8)), scan_size);
+                               field->in_value = NULL;
 
                                field++;
                        }
                }
 
                /* if a TAP is bypassed, generated a dummy bit*/
-               else
-               {
+               else {
 
-                       field->num_bits                 = 1;
-                       field->out_value                = NULL;
-                       field->in_value                 = NULL;
+                       field->num_bits = 1;
+                       field->out_value = NULL;
+                       field->in_value = NULL;
 
                        field++;
                }
@@ -298,23 +282,23 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
 static int jtag_add_plain_scan(int num_bits, const uint8_t *out_bits,
                uint8_t *in_bits, tap_state_t state, bool ir_scan)
 {
-       struct jtag_command * cmd               = cmd_queue_alloc(sizeof(struct jtag_command));
-       struct scan_command * scan              = cmd_queue_alloc(sizeof(struct scan_command));
-       struct scan_field * out_fields  = cmd_queue_alloc(sizeof(struct scan_field));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct scan_command *scan = cmd_queue_alloc(sizeof(struct scan_command));
+       struct scan_field *out_fields = cmd_queue_alloc(sizeof(struct scan_field));
 
        jtag_queue_command(cmd);
 
-       cmd->type                               = JTAG_SCAN;
-       cmd->cmd.scan                   = scan;
+       cmd->type = JTAG_SCAN;
+       cmd->cmd.scan = scan;
 
-       scan->ir_scan                   = ir_scan;
-       scan->num_fields                = 1;
-       scan->fields                    = out_fields;
-       scan->end_state                 = state;
+       scan->ir_scan = ir_scan;
+       scan->num_fields = 1;
+       scan->fields = out_fields;
+       scan->end_state = state;
 
-       out_fields->num_bits    = num_bits;
-       out_fields->out_value   = buf_cpy(out_bits, cmd_queue_alloc(DIV_ROUND_UP(num_bits, 8)), num_bits);
-       out_fields->in_value    = in_bits;
+       out_fields->num_bits = num_bits;
+       out_fields->out_value = buf_cpy(out_bits, cmd_queue_alloc(DIV_ROUND_UP(num_bits, 8)), num_bits);
+       out_fields->in_value = in_bits;
 
        return ERROR_OK;
 }
@@ -334,7 +318,7 @@ int interface_jtag_add_tlr(void)
        tap_state_t state = TAP_RESET;
 
        /* allocate memory for a new list member */
-       struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
 
        jtag_queue_command(cmd);
 
@@ -374,7 +358,7 @@ int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state
 int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
 {
        /* allocate memory for a new list member */
-       struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
 
        jtag_queue_command(cmd);
 
@@ -393,7 +377,7 @@ int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
 int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
 {
        /* allocate memory for a new list member */
-       struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
 
        jtag_queue_command(cmd);
 
@@ -409,7 +393,7 @@ int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
 int interface_jtag_add_clocks(int num_cycles)
 {
        /* allocate memory for a new list member */
-       struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
 
        jtag_queue_command(cmd);
 
@@ -424,7 +408,7 @@ int interface_jtag_add_clocks(int num_cycles)
 int interface_jtag_add_reset(int req_trst, int req_srst)
 {
        /* allocate memory for a new list member */
-       struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
 
        jtag_queue_command(cmd);
 
@@ -440,7 +424,7 @@ int interface_jtag_add_reset(int req_trst, int req_srst)
 int interface_jtag_add_sleep(uint32_t us)
 {
        /* allocate memory for a new list member */
-       struct jtag_command * cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+       struct jtag_command *cmd = cmd_queue_alloc(sizeof(struct jtag_command));
 
        jtag_queue_command(cmd);
 
@@ -453,7 +437,9 @@ int interface_jtag_add_sleep(uint32_t us)
 }
 
 /* add callback to end of queue */
-void interface_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
+void interface_jtag_add_callback4(jtag_callback_t callback,
+               jtag_callback_data_t data0, jtag_callback_data_t data1,
+               jtag_callback_data_t data2, jtag_callback_data_t data3)
 {
        struct jtag_callback_entry *entry = cmd_queue_alloc(sizeof(struct jtag_callback_entry));
 
@@ -464,12 +450,10 @@ void interface_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t
        entry->data2 = data2;
        entry->data3 = data3;
 
-       if (jtag_callback_queue_head == NULL)
-       {
+       if (jtag_callback_queue_head == NULL) {
                jtag_callback_queue_head = entry;
                jtag_callback_queue_tail = entry;
-       } else
-       {
+       } else {
                jtag_callback_queue_tail->next = entry;
                jtag_callback_queue_tail = entry;
        }
@@ -477,17 +461,15 @@ void interface_jtag_add_callback4(jtag_callback_t callback, jtag_callback_data_t
 
 int interface_jtag_execute_queue(void)
 {
-       static int reentry = 0;
+       static int reentry;
 
-       assert(reentry==0);
+       assert(reentry == 0);
        reentry++;
 
        int retval = default_interface_jtag_execute_queue();
-       if (retval == ERROR_OK)
-       {
+       if (retval == ERROR_OK) {
                struct jtag_callback_entry *entry;
-               for (entry = jtag_callback_queue_head; entry != NULL; entry = entry->next)
-               {
+               for (entry = jtag_callback_queue_head; entry != NULL; entry = entry->next) {
                        retval = entry->callback(entry->data0, entry->data1, entry->data2, entry->data3);
                        if (retval != ERROR_OK)
                                break;
@@ -502,7 +484,8 @@ int interface_jtag_execute_queue(void)
        return retval;
 }
 
-static int jtag_convert_to_callback4(jtag_callback_data_t data0, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
+static int jtag_convert_to_callback4(jtag_callback_data_t data0,
+               jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
 {
        ((jtag_callback1_t)data1)(data0);
        return ERROR_OK;
@@ -513,10 +496,9 @@ void interface_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t
        jtag_add_callback4(jtag_convert_to_callback4, data0, (jtag_callback_data_t)callback, 0, 0);
 }
 
-
 /* A minidriver can use use an inline versions of this API level fn */
-void jtag_add_dr_out(struct jtag_taptap,
-               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);
index 8b1e5ec..be61b37 100644 (file)
@@ -17,6 +17,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 #include "bitbang.h"
 #include "hello.h"
 
-
 /* my private tap controller state, which tracks state for calling code */
 static tap_state_t dummy_state = TAP_RESET;
 
-static int dummy_clock;         /* edge detector */
+static int dummy_clock;                /* edge detector */
 
-static int clock_count;         /* count clocks in any stable state, only stable states */
+static int clock_count;                /* count clocks in any stable state, only stable states */
 
 static uint32_t dummy_data;
 
-
 static int dummy_read(void)
 {
        int data = 1 & dummy_data;
@@ -43,21 +42,16 @@ static int dummy_read(void)
        return data;
 }
 
-
 static void dummy_write(int tck, int tms, int tdi)
 {
        /* TAP standard: "state transitions occur on rising edge of clock" */
-       if (tck != dummy_clock)
-       {
-               if (tck)
-               {
+       if (tck != dummy_clock) {
+               if (tck) {
                        tap_state_t old_state = dummy_state;
                        dummy_state = tap_state_transition(old_state, tms);
 
-                       if (old_state != dummy_state)
-                       {
-                               if (clock_count)
-                               {
+                       if (old_state != dummy_state) {
+                               if (clock_count) {
                                        LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
                                        clock_count = 0;
                                }
@@ -68,9 +62,7 @@ static void dummy_write(int tck, int tms, int tdi)
                                if (dummy_state == TAP_DRCAPTURE)
                                        dummy_data = 0x01255043;
 #endif
-                       }
-                       else
-                       {
+                       } else {
                                /* this is a stable state clock edge, no change of state here,
                                 * simply increment clock_count for subsequent logging
                                 */
@@ -102,30 +94,21 @@ static struct bitbang_interface dummy_bitbang = {
                .blink = &dummy_led,
        };
 
-
 static int dummy_khz(int khz, int *jtag_speed)
 {
        if (khz == 0)
-       {
                *jtag_speed = 0;
-       }
        else
-       {
                *jtag_speed = 64000/khz;
-       }
        return ERROR_OK;
 }
 
 static int dummy_speed_div(int speed, int *khz)
 {
        if (speed == 0)
-       {
                *khz = 0;
-       }
        else
-       {
                *khz = 64000/speed;
-       }
 
        return ERROR_OK;
 }
index 7e3b456..9781130 100644 (file)
@@ -17,6 +17,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -34,7 +35,7 @@
 
 #include <sys/mman.h>
 
-static uint8_t output_value = 0x0;
+static uint8_t output_value;
 static int dev_mem_fd;
 static void *gpio_controller;
 static volatile uint8_t *gpio_data_register;
@@ -52,8 +53,7 @@ static int ep93xx_quit(void);
 
 struct timespec ep93xx_zzzz;
 
-struct jtag_interface ep93xx_interface =
-{
+struct jtag_interface ep93xx_interface = {
        .name = "ep93xx",
 
        .supported = DEBUG_CAP_TMS_SEQ,
@@ -64,8 +64,7 @@ struct jtag_interface ep93xx_interface =
        .quit = ep93xx_quit,
 };
 
-static struct bitbang_interface ep93xx_bitbang =
-{
+static struct bitbang_interface ep93xx_bitbang = {
        .read = ep93xx_read,
        .write = ep93xx_write,
        .reset = ep93xx_reset,
index 4b9bdef..3a156bf 100644 (file)
 #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
@@ -117,7 +116,7 @@ enum ftdi_interface
 /* 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
 
@@ -150,13 +149,13 @@ enum ftdi_interface
  *
  * @returns ERROR_OK on success, or ERROR_JTAG_QUEUE_FAILED on failure.
  */
-static int ft2232_stableclocks(int num_cycles, struct jtag_commandcmd);
+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 */
@@ -164,7 +163,7 @@ static uint16_t ft2232_vid[MAX_USB_IDS + 1] = { 0x0403, 0 };
 static uint16_t ft2232_pid[MAX_USB_IDS + 1] = { 0x6010, 0 };
 
 struct ft2232_layout {
-       charname;
+       char *name;
        int (*init)(void);
        void (*reset)(int trst, int srst);
        void (*blink)(void);
@@ -225,10 +224,9 @@ static void flossjtag_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,
@@ -321,8 +319,8 @@ static const struct ft2232_layout  ft2232_layouts[] =
        },
        { .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,
@@ -343,37 +341,37 @@ static const struct ft2232_layout  ft2232_layouts[] =
 };
 
 /* 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:
 
@@ -389,17 +387,17 @@ static int             require_send;
 */
 
 #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
@@ -443,17 +441,16 @@ static inline uint8_t buffer_read(void)
  */
 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)
@@ -463,17 +460,16 @@ static void clock_tms(uint8_t mpsse_cmd, int tms_bits, int tms_count, bool tdi_b
                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));
                }
@@ -500,11 +496,10 @@ static inline int get_tms_buffer_requirements(int bit_count)
  */
 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 */
@@ -516,44 +511,37 @@ static void move_to_state(tap_state_t goal_state)
        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;
@@ -561,11 +549,10 @@ static int ft2232_read(uint8_t* buf, uint32_t size, uint32_t* 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;
@@ -578,10 +565,9 @@ static int ft2232_read(uint8_t* buf, uint32_t size, uint32_t* bytes_read)
        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;
@@ -591,12 +577,11 @@ static int ft2232_read(uint8_t* buf, uint32_t size, uint32_t* bytes_read)
 
 #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;
        }
 
@@ -626,8 +611,8 @@ static int ft2232h_ft4232h_adaptive_clocking(bool enable)
        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;
@@ -646,8 +631,7 @@ static int ft2232h_ft4232h_clk_divide_by_5(bool enable)
        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;
@@ -668,8 +652,7 @@ static int ft2232_speed(int speed)
        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;
@@ -683,8 +666,8 @@ static int ft2232_speed(int speed)
        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;
        }
@@ -692,7 +675,7 @@ static int ft2232_speed(int speed)
        return ERROR_OK;
 }
 
-static int ft2232_speed_div(int speed, intkhz)
+static int ft2232_speed_div(int speed, int *khz)
 {
        /* Take a look in the FT2232 manual,
         * AN2232C-01 Command Processor for
@@ -703,17 +686,13 @@ static int ft2232_speed_div(int speed, int* khz)
        return ERROR_OK;
 }
 
-static int ft2232_khz(int khz, intjtag_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;
                }
@@ -726,8 +705,8 @@ static int ft2232_khz(int khz, int* jtag_speed)
         * 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 */
@@ -738,15 +717,11 @@ static int ft2232_khz(int khz, int* jtag_speed)
 
        /* 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;
 }
@@ -755,21 +730,19 @@ static void ft2232_end_state(tap_state_t state)
 {
        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_tbuffer, 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;
        }
@@ -778,10 +751,11 @@ static void ft2232_read_scan(enum scan_type type, uint8_t* buffer, int scan_size
 
        /* 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);
 }
 
@@ -789,13 +763,14 @@ static void ft2232_debug_dump_buffer(void)
 {
        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;
                }
@@ -805,19 +780,19 @@ static void ft2232_debug_dump_buffer(void)
                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_commandcmd;
-       uint8_tbuffer;
+       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_
@@ -829,8 +804,8 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command*
        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;
        }
@@ -839,8 +814,7 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command*
        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;
@@ -849,8 +823,8 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command*
                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;
                }
@@ -870,14 +844,13 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command*
 
                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);
@@ -885,8 +858,8 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command*
 
 #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
        }
@@ -900,25 +873,22 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command*
        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;
@@ -938,7 +908,7 @@ static int ft2232_send_and_recv(struct jtag_command* first, struct jtag_command*
  *   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_tpath, int num_states)
+static void ft2232_add_pathmove(tap_state_t *path, int num_states)
 {
        int state_count = 0;
 
@@ -947,11 +917,10 @@ static void ft2232_add_pathmove(tap_state_t* path, int num_states)
        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);
@@ -961,17 +930,15 @@ static void ft2232_add_pathmove(tap_state_t* path, int num_states)
 
                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);
@@ -987,70 +954,52 @@ static void ft2232_add_pathmove(tap_state_t* path, int num_states)
        tap_set_end_state(tap_get_state());
 }
 
-static void ft2232_add_scan(bool ir_scan, enum scan_type type, uint8_tbuffer, 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 */
@@ -1060,22 +1009,16 @@ static void ft2232_add_scan(bool ir_scan, enum scan_type type, uint8_t* buffer,
                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); */
@@ -1087,47 +1030,37 @@ static void ft2232_add_scan(bool ir_scan, enum scan_type type, uint8_t* buffer,
        }
 
        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) */
@@ -1139,63 +1072,55 @@ static void ft2232_add_scan(bool ir_scan, enum scan_type type, uint8_t* buffer,
        }
 
        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_treceive_buffer  = malloc(DIV_ROUND_UP(scan_size, 8));
-       uint8_treceive_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); */
@@ -1207,41 +1132,35 @@ static int ft2232_large_scan(struct scan_command* cmd, enum scan_type type, uint
                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;
                }
        }
@@ -1255,22 +1174,16 @@ static int ft2232_large_scan(struct scan_command* cmd, enum scan_type type, uint
                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); */
@@ -1283,44 +1196,33 @@ static int ft2232_large_scan(struct scan_command* cmd, enum scan_type type, uint
                        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)"); */
@@ -1333,26 +1235,25 @@ static int ft2232_large_scan(struct scan_command* cmd, enum scan_type type, uint
        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;
@@ -1364,19 +1265,17 @@ static int ft2232_predict_scan_out(int scan_size, enum scan_type type)
        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) */
@@ -1390,10 +1289,10 @@ static int ft2232_predict_scan_in(int scan_size, enum scan_type type)
 {
        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;
@@ -1411,30 +1310,25 @@ static int ft2232_predict_scan_in(int scan_size, enum scan_type type)
 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
@@ -1450,30 +1344,24 @@ static void ftx23_reset(int trst, int srst)
 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
@@ -1484,22 +1372,22 @@ static void jtagkey_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 olimex_jtag_reset(int trst, int srst)
 {
      &nbs