build: cleanup src/jtag/drivers directory

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

View File

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

View 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,22 +65,22 @@ 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);
@ -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
@ -175,7 +175,7 @@ SFR(IP, 0xB8);
SBIT(PS0, 0xB8, 4);
SBIT(PT2, 0xB8, 5);
SBIT(PS1, 0xB8, 6);
// Bit 7 read-only, always reads '1'
/* Bit 7 read-only, always reads '1' */
SFR(SCON1, 0xC0);
SBIT(RI_1, 0xC0, 0);
@ -215,13 +215,13 @@ SFR(PSW, 0xD0);
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'
/* 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'
/* Bit 6 read-only, always reads '1' */
SBIT(SMOD1, 0xD8, 7);
SFR(ACC, 0xE0);
@ -232,9 +232,9 @@ SFR(EIE, 0xE8);
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'
/* Bit 5 read-only, always reads '1' */
/* Bit 6 read-only, always reads '1' */
/* Bit 7 read-only, always reads '1' */
SFR(B, 0xF0);
@ -244,13 +244,13 @@ SFR(EIP, 0xF8);
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'
/* Bit 5 read-only, always reads '1' */
/* Bit 6 read-only, always reads '1' */
/* Bit 7 read-only, always reads '1' */
/***************************************************************************/
/***************************** XDATA Registers *****************************/
/***************************************************************************/
/**************************************************************************
***************************** XDATA Registers ****************************
***************************************************************************/
/************************ Endpoint 0-7 Data Buffers ************************/
SFRX(OUT7BUF[64], 0x7B40);
@ -269,7 +269,7 @@ SFRX(OUT1BUF[64], 0x7E40);
SFRX(IN1BUF[64], 0x7E80);
SFRX(OUT0BUF[64], 0x7EC0);
SFRX(IN0BUF[64], 0x7F00);
// 0x7F40 - 0x7F5F reserved
/* 0x7F40 - 0x7F5F reserved */
/**************************** Isochronous Data *****************************/
SFRX(OUT8DATA, 0x7F60);
@ -312,9 +312,9 @@ SFRX(OUT16BCL, 0x7F7F);
SFRX(CPUCS, 0x7F92);
#define RES8051 bmBit0
#define CLK24OE bmBit1
// Bit 2 read-only, always reads '0'
// Bit 3 read-only, always reads '0'
// Bits 4...7: Chip Revision
/* Bit 2 read-only, always reads '0' */
/* Bit 3 read-only, always reads '0' */
/* Bits 4...7: Chip Revision */
SFRX(PORTACFG, 0x7F93);
#define T0OUT bmBit0
@ -437,7 +437,7 @@ SFRX(OEC, 0x7F9E);
#define OEC6 bmBit6
#define OEC7 bmBit7
// 0x7F9F reserved
/* 0x7F9F reserved */
/****************** Isochronous Control/Status Registers *******************/
SFRX(ISOERR, 0x7FA0);
@ -455,10 +455,10 @@ SFRX(ISOCTL, 0x7FA1);
#define MBZ0 bmBit1
#define MBZ1 bmBit2
#define PPSTAT bmBit3
// Bit 4 unused
// Bit 5 unused
// Bit 6 unused
// Bit 7 unused
/* Bit 4 unused */
/* Bit 5 unused */
/* Bit 6 unused */
/* Bit 7 unused */
SFRX(ZBCOUT, 0x7FA2);
#define EP8 bmBit0
@ -470,8 +470,8 @@ SFRX(ZBCOUT, 0x7FA2);
#define EP14 bmBit6
#define EP15 bmBit7
// 0x7FA3 reserved
// 0x7FA4 reserved
/* 0x7FA3 reserved */
/* 0x7FA4 reserved */
/****************************** I2C Registers ******************************/
SFRX(I2CS, 0x7FA5);
@ -485,18 +485,18 @@ SFRX(I2CS, 0x7FA5);
#define I2C_START bmBit7
SFRX(I2DAT, 0x7FA6);
// 0x7FA7 reserved
/* 0x7FA7 reserved */
/******************************* Interrupts ********************************/
SFRX(IVEC, 0x7FA8);
// Bit 0 read-only, always reads '0'
// Bit 1 read-only, always reads '0'
/* Bit 0 read-only, always reads '0' */
/* Bit 1 read-only, always reads '0' */
#define IV0 bmBit2
#define IV1 bmBit3
#define IV2 bmBit4
#define IV3 bmBit5
#define IV4 bmBit6
// Bit 7 read-only, always reads '0'
/* Bit 7 read-only, always reads '0' */
SFRX(IN07IRQ, 0x7FA9);
#define IN0IR bmBit0
@ -524,9 +524,9 @@ SFRX(USBIRQ, 0x7FAB);
#define SUTOKIR bmBit2
#define SUSPIR bmBit3
#define URESIR bmBit4
// Bit 5 unused
// Bit 6 unused
// Bit 7 unused
/* Bit 5 unused */
/* Bit 6 unused */
/* Bit 7 unused */
SFRX(IN07IEN, 0x7FAC);
#define IN0IEN bmBit0
@ -554,22 +554,22 @@ SFRX(USBIEN, 0x7FAE);
#define SUTOKIE bmBit2
#define SUSPIE bmBit3
#define URESIE bmBit4
// Bit 5 unused
// Bit 6 unused
// Bit 7 unused
/* Bit 5 unused */
/* Bit 6 unused */
/* Bit 7 unused */
SFRX(USBBAV, 0x7FAF);
#define AVEN bmBit0
#define BPEN bmBit1
#define BPPULSE bmBit2
#define BREAK bmBit3
// Bit 4 unused
// Bit 5 unused
// Bit 6 unused
// Bit 7 unused
/* Bit 4 unused */
/* Bit 5 unused */
/* Bit 6 unused */
/* Bit 7 unused */
// 0x7FB0 reserved
// 0x7FB1 reserved
/* 0x7FB0 reserved */
/* 0x7FB1 reserved */
SFRX(BPADDRH, 0x7FB2);
SFRX(BPADDRL, 0x7FB3);
@ -579,10 +579,10 @@ SFRX(EP0CS, 0x7FB4);
#define HSNAK bmBit1
#define IN0BSY bmBit2
#define OUT0BSY bmBit3
// Bit 4 unused
// Bit 5 unused
// Bit 6 unused
// Bit 7 unused
/* Bit 4 unused */
/* Bit 5 unused */
/* Bit 6 unused */
/* Bit 7 unused */
SFRX(IN0BC, 0x7FB5);
SFRX(IN1CS, 0x7FB6);
@ -599,7 +599,7 @@ SFRX(IN6CS, 0x7FC0);
SFRX(IN6BC, 0x7FC1);
SFRX(IN7CS, 0x7FC2);
SFRX(IN7BC, 0x7FC3);
// 0x7FC4 reserved
/* 0x7FC4 reserved */
SFRX(OUT0BC, 0x7FC5);
SFRX(OUT1CS, 0x7FC6);
SFRX(OUT1BC, 0x7FC7);
@ -630,16 +630,16 @@ SFRX(USBCS, 0x7FD6);
#define RENUM bmBit1
#define DISCOE bmBit2
#define DISCON bmBit3
// Bit 4 unused
// Bit 5 unused
// Bit 6 unused
/* Bit 4 unused */
/* Bit 5 unused */
/* Bit 6 unused */
#define WAKESRC bmBit7
SFRX(TOGCTL, 0x7FD7);
#define TOG_EP0 bmBit0
#define TOG_EP1 bmBit1
#define TOG_EP2 bmBit2
// Bit 3 is read-only, always reads '0'
/* Bit 3 is read-only, always reads '0' */
#define TOG_IO bmBit4
#define TOG_R bmBit5
#define TOG_S bmBit6
@ -647,9 +647,9 @@ SFRX(TOGCTL, 0x7FD7);
SFRX(USBFRAMEL, 0x7FD8);
SFRX(USBFRAMEH, 0x7FD9);
// 0x7FDA reserved
/* 0x7FDA reserved */
SFRX(FNADDR, 0x7FDB);
// 0x7FDC reserved
/* 0x7FDC reserved */
SFRX(USBPAIR, 0x7FDD);
#define PR2IN bmBit0
@ -658,11 +658,11 @@ SFRX(USBPAIR, 0x7FDD);
#define PR2OUT bmBit3
#define PR4OUT bmBit4
#define PR6OUT bmBit5
// Bit 6 unused
/* Bit 6 unused */
#define ISOSEND0 bmBit7
SFRX(IN07VAL, 0x7FDE);
// Bit 0 is read-only, always reads '1'
/* Bit 0 is read-only, always reads '1' */
#define IN1VAL bmBit1
#define IN2VAL bmBit2
#define IN3VAL bmBit3
@ -672,7 +672,7 @@ SFRX(IN07VAL, 0x7FDE);
#define IN7VAL bmBit7
SFRX(OUT07VAL, 0x7FDF);
// Bit 0 is read-only, always reads '1'
/* Bit 0 is read-only, always reads '1' */
#define OUT1VAL bmBit1
#define OUT2VAL bmBit2
#define OUT3VAL bmBit3
@ -714,8 +714,8 @@ SFRX(FASTXFR, 0x7FE2);
SFRX(AUTOPTRH, 0x7FE3);
SFRX(AUTOPTRL, 0x7FE4);
SFRX(AUTODATA, 0x7FE5);
// 0x7FE6 reserved
// 0x7FE7 reserved
/* 0x7FE6 reserved */
/* 0x7FE7 reserved */
/******************************* Setup Data ********************************/
SFRX(SETUPDAT[8], 0x7FE8);

View File

@ -33,8 +33,8 @@
#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 **********/
@ -49,80 +49,80 @@
/** 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

View File

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

View File

@ -27,19 +27,19 @@
#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.
@ -68,9 +68,8 @@ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) {
if (tms_count_start > 0)
jtag_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
@ -83,10 +82,9 @@ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset)
tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
if (GET_TDO()) {
if (GET_TDO())
tdo_data |= 0x80;
}
}
/* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data;
@ -107,20 +105,18 @@ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset)
tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
if (GET_TDO()) {
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) {
if (tms_count_end > 0)
jtag_clock_tms(tms_count_end, tms_sequence_end);
}
}
/**
* Perform JTAG SCAN-IN operation at variable TCK frequency.
@ -149,9 +145,8 @@ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) {
if (tms_count_start > 0)
jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TDI | PIN_TCK | PIN_TMS);
@ -161,16 +156,17 @@ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
for (j = 0; j < 8; j++) {
OUTB = outb_buffer; /* TCK changes here */
for (k = 0; k < delay_scan_in; k++);
for (k = 0; k < delay_scan_in; k++)
;
tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_in; k++);
for (k = 0; k < delay_scan_in; k++)
;
if (GET_TDO()) {
if (GET_TDO())
tdo_data |= 0x80;
}
}
/* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data;
@ -188,26 +184,26 @@ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset)
}
OUTB = outb_buffer; /* TCK change here */
for (k = 0; k < delay_scan_in; k++);
for (k = 0; k < delay_scan_in; k++)
;
tdo_data = tdo_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_in; k++);
for (k = 0; k < delay_scan_in; k++)
;
if (GET_TDO()) {
if (GET_TDO())
tdo_data |= 0x80;
}
}
tdo_data = 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) {
if (tms_count_end > 0)
jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
}
/**
* Perform JTAG SCAN-OUT operation at maximum TCK frequency.
@ -237,9 +233,8 @@ void jtag_scan_out(uint8_t out_offset)
tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) {
if (tms_count_start > 0)
jtag_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -248,12 +243,10 @@ void jtag_scan_out(uint8_t out_offset)
tdi_data = OUT2BUF[i + out_offset + 5];
for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
else
outb_buffer &= ~PIN_TDI;
}
OUTB = outb_buffer; /* TDI and TCK change here */
tdi_data = tdi_data >> 1;
@ -265,12 +258,10 @@ void jtag_scan_out(uint8_t out_offset)
/* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
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)) {
@ -285,10 +276,9 @@ void jtag_scan_out(uint8_t out_offset)
}
/* Move to correct end state */
if (tms_count_end > 0) {
if (tms_count_end > 0)
jtag_clock_tms(tms_count_end, tms_sequence_end);
}
}
/**
* Perform JTAG SCAN-OUT operation at maximum TCK frequency.
@ -318,9 +308,8 @@ void jtag_slow_scan_out(uint8_t out_offset)
tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) {
if (tms_count_start > 0)
jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -329,19 +318,19 @@ void jtag_slow_scan_out(uint8_t out_offset)
tdi_data = OUT2BUF[i + out_offset + 5];
for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
else
outb_buffer &= ~PIN_TDI;
}
OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_out; k++);
for (k = 0; k < delay_scan_out; k++)
;
tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_out; k++);
for (k = 0; k < delay_scan_out; k++)
;
}
}
@ -349,12 +338,10 @@ void jtag_slow_scan_out(uint8_t out_offset)
/* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
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)) {
@ -364,18 +351,19 @@ void jtag_slow_scan_out(uint8_t out_offset)
}
OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_out; k++);
for (k = 0; k < delay_scan_out; k++)
;
tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_out; k++);
for (k = 0; k < delay_scan_out; k++)
;
}
/* Move to correct end state */
if (tms_count_end > 0) {
if (tms_count_end > 0)
jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
}
/**
* Perform bidirectional JTAG SCAN operation at maximum TCK frequency.
@ -405,9 +393,8 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) {
if (tms_count_start > 0)
jtag_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -417,22 +404,19 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
tdo_data = 0;
for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
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()) {
if (GET_TDO())
tdo_data |= 0x80;
}
}
/* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data;
@ -443,12 +427,10 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
/* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
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)) {
@ -462,20 +444,18 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset)
OUTB = (outb_buffer | PIN_TCK);
tdo_data = tdo_data >> 1;
if (GET_TDO()) {
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) {
if (tms_count_end > 0)
jtag_clock_tms(tms_count_end, tms_sequence_end);
}
}
/**
* Perform bidirectional JTAG SCAN operation at maximum TCK frequency.
@ -505,9 +485,8 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
tms_sequence_start = OUT2BUF[out_offset + 3];
tms_sequence_end = OUT2BUF[out_offset + 4];
if (tms_count_start > 0) {
if (tms_count_start > 0)
jtag_slow_clock_tms(tms_count_start, tms_sequence_start);
}
outb_buffer = OUTB & ~(PIN_TCK | PIN_TMS);
@ -517,25 +496,24 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
tdo_data = 0;
for (j = 0; j < 8; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
else
outb_buffer &= ~PIN_TDI;
}
OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_io; k++);
for (k = 0; k < delay_scan_io; k++)
;
tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_io; k++);
for (k = 0; k < delay_scan_io; k++)
;
tdo_data = tdo_data >> 1;
if (GET_TDO()) {
if (GET_TDO())
tdo_data |= 0x80;
}
}
/* Copy TDO data to IN2BUF */
IN2BUF[i + in_offset] = tdo_data;
@ -546,12 +524,10 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
/* Shift the last byte */
for (j = 0; j < bits_last_byte; j++) {
if (tdi_data & 0x01) {
if (tdi_data & 0x01)
outb_buffer |= PIN_TDI;
}
else {
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)) {
@ -561,27 +537,27 @@ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset)
}
OUTB = outb_buffer; /* TDI and TCK change here */
for (k = 0; k < delay_scan_io; k++);
for (k = 0; k < delay_scan_io; k++)
;
tdi_data = tdi_data >> 1;
OUTB = (outb_buffer | PIN_TCK);
for (k = 0; k < delay_scan_io; k++);
for (k = 0; k < delay_scan_io; k++)
;
tdo_data = tdo_data >> 1;
if (GET_TDO()) {
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) {
if (tms_count_end > 0)
jtag_slow_clock_tms(tms_count_end, tms_sequence_end);
}
}
/**
* Generate TCK clock cycles.
@ -616,9 +592,11 @@ void jtag_slow_clock_tck(uint16_t count)
for (i = 0; i < count; i++) {
OUTB = outb_buffer;
for (j = 0; j < delay_tck; j++);
for (j = 0; j < delay_tck; j++)
;
OUTB = outb_buffer | PIN_TCK;
for (j = 0; j < delay_tck; j++);
for (j = 0; j < delay_tck; j++)
;
}
}
@ -638,12 +616,10 @@ void jtag_clock_tms(uint8_t count, uint8_t sequence)
for (i = 0; i < count; i++) {
/* Set TMS pin according to sequence parameter */
if ( sequence & 0x1 ) {
if (sequence & 0x1)
outb_buffer |= PIN_TMS;
}
else {
else
outb_buffer &= ~PIN_TMS;
}
OUTB = outb_buffer;
sequence = sequence >> 1;
@ -667,18 +643,18 @@ void jtag_slow_clock_tms(uint8_t count, uint8_t sequence)
for (i = 0; i < count; i++) {
/* Set TMS pin according to sequence parameter */
if ( sequence & 0x1 ) {
if (sequence & 0x1)
outb_buffer |= PIN_TMS;
}
else {
else
outb_buffer &= ~PIN_TMS;
}
OUTB = outb_buffer;
for (j = 0; j < delay_tms; j++);
for (j = 0; j < delay_tms; j++)
;
sequence = sequence >> 1;
OUTB = outb_buffer | PIN_TCK;
for (j = 0; j < delay_tms; j++);
for (j = 0; j < delay_tms; j++)
;
}
}
@ -697,15 +673,12 @@ uint16_t jtag_get_signals(void)
output_signal_state = 0;
/* Get states of input pins */
if (GET_TDO()) {
if (GET_TDO())
input_signal_state |= SIGNAL_TDO;
}
if (GET_BRKOUT()) {
if (GET_BRKOUT())
input_signal_state |= SIGNAL_BRKOUT;
}
if (GET_TRAP()) {
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 */

View File

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

View File

@ -33,8 +33,8 @@
/* 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;
@ -155,47 +155,87 @@ void sudav_isr(void) __interrupt SUDAV_ISR
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 {
void ep2in_isr(void) __interrupt EP2IN_ISR
{
EP2_in = 1;
CLEAR_IRQ();
IN07IRQ = IN2IR; // Clear OUT2 IRQ
IN07IRQ = IN2IR;/* Clear OUT2 IRQ */
}
/**
* EP2 OUT: called after the transfer from Host->uC has finished: we got data
*/
void ep2out_isr(void) __interrupt EP2OUT_ISR {
void ep2out_isr(void) __interrupt EP2OUT_ISR
{
EP2_out = 1;
CLEAR_IRQ();
OUT07IRQ = OUT2IR; // Clear OUT2 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
@ -293,12 +333,10 @@ bool usb_handle_get_status(void)
/* 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) {
if (*ep_cs & EPSTALL)
IN0BUF[0] = 0x01;
}
else {
else
IN0BUF[0] = 0x00;
}
/* Second byte sent has to be always zero */
IN0BUF[1] = 0;
@ -333,12 +371,10 @@ bool usb_handle_clear_feature(void)
if (setup_data.wValue == 0) {
/* Unstall the endpoint specified in wIndex */
ep_cs = usb_get_endpoint_cs_reg(setup_data.wIndex);
if (!ep_cs) {
if (!ep_cs)
return false;
}
*ep_cs &= ~EPSTALL;
}
else {
} else {
/* Unsupported feature, stall EP0 */
STALL_EP0();
}
@ -362,20 +398,17 @@ bool usb_handle_set_feature(void)
switch (setup_data.bmRequestType) {
case SF_DEVICE:
if (setup_data.wValue == 2) {
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) {
if (!ep_cs)
return false;
}
*ep_cs |= EPSTALL;
}
else {
} else {
/* Unsupported endpoint feature */
return false;
}
@ -416,15 +449,12 @@ bool usb_handle_get_descriptor(void)
/* Supply language descriptor */
SUDPTRH = HI8(&language_descriptor);
SUDPTRL = LO8(&language_descriptor);
}
else if (setup_data.wIndex == 0x0409 /* US English */) {
} else if (setup_data.wIndex == 0x0409 /* US English */) {
/* Supply string descriptor */
SUDPTRH = HI8(en_string_descriptors[descriptor_index - 1]);
SUDPTRL = LO8(en_string_descriptors[descriptor_index - 1]);
}
else {
} else
return false;
}
break;
default:
/* Unsupported descriptor type */
@ -459,23 +489,20 @@ void usb_handle_setup_data(void)
{
switch (setup_data.bRequest) {
case GET_STATUS:
if (!usb_handle_get_status()) {
if (!usb_handle_get_status())
STALL_EP0();
}
break;
case CLEAR_FEATURE:
if (!usb_handle_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()) {
if (!usb_handle_set_feature())
STALL_EP0();
}
break;
case SET_ADDRESS:
/* Handled by USB core */
@ -485,9 +512,8 @@ void usb_handle_setup_data(void)
STALL_EP0();
break;
case GET_DESCRIPTOR:
if (!usb_handle_get_descriptor()) {
if (!usb_handle_get_descriptor())
STALL_EP0();
}
break;
case GET_CONFIGURATION:
/* OpenULINK has only one configuration, return its index */
@ -518,7 +544,8 @@ void usb_handle_setup_data(void)
* USB initialization. Configures USB interrupts, endpoints and performs
* ReNumeration.
*/
void usb_init(void) {
void usb_init(void)
{
/* Mark endpoint 2 IN & OUT as valid */
IN07VAL = IN2VAL;
OUT07VAL = OUT2VAL;

View 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
@ -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;
@ -113,7 +114,7 @@ static const int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA;
#define AMT_DW(val) do { outb(val, amt_jtagaccel_port + 4); } while (0)
#define AMT_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,8 +124,7 @@ 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 */
@ -134,7 +134,6 @@ static uint8_t amt_jtagaccel_tap_move[6][6][2] =
{ {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);
}
}
@ -205,8 +205,7 @@ static void amt_jtagaccel_state_move(void)
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)
@ -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);
@ -418,7 +410,13 @@ int amt_jtagaccel_get_giveio_access(void)
if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
return 0;
h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
h = CreateFile("\\\\.\\giveio",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (h == INVALID_HANDLE_VALUE) {
errno = ENODEV;
return -1;
@ -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)
{
if (i < 0) {
LOG_ERROR(" cannot set compatible mode to device");
return ERROR_JTAG_INIT_FAILED;
}
@ -479,8 +474,7 @@ 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)");
}
@ -494,8 +488,8 @@ static int amt_jtagaccel_init(void)
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,22 +554,17 @@ 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;
}

View 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 */
@ -91,8 +95,8 @@ static void armjtagew_debug_buffer(uint8_t *buffer, int length);
static struct armjtagew *armjtagew_handle;
/***************************************************************************/
/* External interface implementation */
/**************************************************************************
* External interface implementation */
static int armjtagew_execute_queue(void)
{
@ -101,12 +105,11 @@ 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, \
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);
@ -125,7 +128,8 @@ static int armjtagew_execute_queue(void)
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;
}
@ -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,10 +367,8 @@ 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,10 +407,8 @@ 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,10 +417,10 @@ 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",
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)),
@ -453,14 +430,9 @@ static int armjtagew_get_status(void)
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], \
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);
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
@ -569,50 +542,37 @@ 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)
{
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);
}
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);
}
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);
}
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,8 +672,8 @@ static int armjtagew_tap_execute(void)
return ERROR_OK;
}
/*****************************************************************************/
/* JLink USB low-level functions */
/****************************************************************************
* JLink USB low-level functions */
static struct armjtagew *armjtagew_usb_open()
{
@ -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,9 +735,10 @@ 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;
}
@ -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();
}
}

View 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,8 +78,7 @@
#define P30 (1 << 30)
#define P31 (1 << 31)
struct device_t
{
struct device_t {
char *name;
int TDO_PIO; /* PIO holding TDO */
uint32_t TDO_MASK; /* TDO bitmask */
@ -95,8 +94,7 @@ 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 },
};
@ -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;
}

View 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,7 +88,6 @@ 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.
@ -104,8 +100,7 @@ static int bitbang_execute_tms(struct jtag_command *cmd)
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.
@ -261,8 +243,7 @@ int bitbang_execute_queue(void)
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,
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);

View 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

View 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,7 +26,6 @@
#include "bitq.h"
#include <jtag/interface.h>
struct bitq_interface *bitq_interface; /* low level bit queue interface */
/* state of input queue */
@ -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,7 +159,6 @@ 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;
@ -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,7 +218,6 @@ static void bitq_scan(struct scan_command *cmd)
bitq_scan_field(&cmd->fields[i], 1);
}
int bitq_execute_queue(void)
{
struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
@ -253,18 +227,16 @@ int bitq_execute_queue(void)
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)
{
}

View File

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

View 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);
}
}

View 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)
{
@ -69,12 +69,12 @@ static void cmd_queue_scan_field_clone(struct scan_field * dst, const struct sca
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();
@ -92,23 +92,19 @@ int interface_jtag_add_ir_scan(struct jtag_tap* active, const struct scan_field
scan->fields = out_fields;
scan->end_state = state;
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;
@ -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,14 +129,14 @@ 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++;
}
@ -159,25 +155,21 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
scan->fields = out_fields;
scan->end_state = state;
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,8 +179,7 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
}
/* if a TAP is bypassed, generated a dummy bit*/
else
{
else {
field->num_bits = 1;
field->out_value = NULL;
field->in_value = NULL;
@ -202,8 +193,6 @@ int interface_jtag_add_dr_scan(struct jtag_tap* active, int in_num_fields, const
return ERROR_OK;
}
/**
* Generate a DR SCAN using the array of output values passed to the function
*
@ -228,8 +217,7 @@ 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++;
}
@ -256,18 +244,15 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
/* 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]);
@ -281,8 +266,7 @@ void interface_jtag_add_dr_out(struct jtag_tap *target_tap,
}
/* if a TAP is bypassed, generated a dummy bit*/
else
{
else {
field->num_bits = 1;
field->out_value = NULL;
@ -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);
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,7 +496,6 @@ void interface_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t
jtag_add_callback4(jtag_convert_to_callback4, data0, (jtag_callback_data_t)callback, 0, 0);
}
/* A minidriver can use use an inline versions of this API level fn */
void jtag_add_dr_out(struct jtag_tap *tap,
int num_fields, const int *num_bits, const uint32_t *value,

View 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,7 +26,6 @@
#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;
@ -35,7 +35,6 @@ static int clock_count; /* count clocks in any stable state, only stable
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;
}

View 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,

File diff suppressed because it is too large Load Diff

View File

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

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

View File

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

View File

@ -48,4 +48,4 @@ void jtag_add_callback4(jtag_callback_t f, jtag_callback_data_t data0,
jtag_callback_data_t data1, jtag_callback_data_t data2,
jtag_callback_data_t data3);
#endif // MINIDRIVER_IMP_H
#endif /* MINIDRIVER_IMP_H */

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

View File

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

View 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,27 +28,30 @@
#include <jtag/interface.h>
#include "bitbang.h"
// from unix man page and sys/un.h:
/* from unix man page and sys/un.h: */
#define UNIX_PATH_MAX 108
// arbitrary limit on host name length:
/* arbitrary limit on host name length: */
#define REMOTE_BITBANG_HOST_MAX 255
#define REMOTE_BITBANG_RAISE_ERROR(expr ...) \
LOG_ERROR(expr); LOG_ERROR("Terminating openocd."); exit(-1);
do { \
LOG_ERROR(expr); \
LOG_ERROR("Terminating openocd."); \
exit(-1); \
while (0)
static char remote_bitbang_host[REMOTE_BITBANG_HOST_MAX] = "openocd";
static uint16_t remote_bitbang_port = 0;
static uint16_t remote_bitbang_port;
FILE *remote_bitbang_in;
FILE *remote_bitbang_out;
static void remote_bitbang_putc(int c)
{
if (EOF == fputc(c, remote_bitbang_out)) {
if (EOF == fputc(c, remote_bitbang_out))
REMOTE_BITBANG_RAISE_ERROR("remote_bitbang_putc: %s", strerror(errno));
}
}
static int remote_bitbang_quit(void)
{
@ -61,8 +65,8 @@ static int remote_bitbang_quit(void)
return ERROR_FAIL;
}
// We only need to close one of the FILE*s, because they both use the same
// underlying file descriptor.
/* We only need to close one of the FILE*s, because they both use the same */
/* underlying file descriptor. */
if (EOF == fclose(remote_bitbang_out)) {
LOG_ERROR("fclose: %s", strerror(errno));
return ERROR_FAIL;
@ -72,7 +76,7 @@ static int remote_bitbang_quit(void)
return ERROR_OK;
}
// Get the next read response.
/* Get the next read response. */
static int remote_bitbang_rread(void)
{
if (EOF == fflush(remote_bitbang_out)) {
@ -82,8 +86,10 @@ static int remote_bitbang_rread(void)
int c = fgetc(remote_bitbang_in);
switch (c) {
case '0': return 0;
case '1': return 1;
case '0':
return 0;
case '1':
return 1;
default:
remote_bitbang_quit();
REMOTE_BITBANG_RAISE_ERROR(
@ -140,10 +146,18 @@ static int remote_bitbang_init_tcp(void)
if (hent == NULL) {
char *errorstr = "???";
switch (h_errno) {
case HOST_NOT_FOUND: errorstr = "host not found"; break;
case NO_ADDRESS: errorstr = "no address"; break;
case NO_RECOVERY: errorstr = "no recovery"; break;
case TRY_AGAIN: errorstr = "try again"; break;
case HOST_NOT_FOUND:
errorstr = "host not found";
break;
case NO_ADDRESS:
errorstr = "no address";
break;
case NO_RECOVERY:
errorstr = "no recovery";
break;
case TRY_AGAIN:
errorstr = "try again";
break;
}
LOG_ERROR("gethostbyname: %s", errorstr);
return ERROR_FAIL;
@ -214,9 +228,8 @@ static int remote_bitbang_init(void)
bitbang_interface = &remote_bitbang_bitbang;
LOG_INFO("Initializing remote_bitbang driver");
if (remote_bitbang_port == 0) {
if (remote_bitbang_port == 0)
return remote_bitbang_init_unix();
}
return remote_bitbang_init_tcp();
}
@ -228,7 +241,7 @@ static int remote_bitbang_khz(int khz, int* jtag_speed)
static int remote_bitbang_speed_div(int speed, int *khz)
{
// I don't think this really matters any.
/* I don't think this really matters any. */
*khz = 1;
return ERROR_OK;
}

File diff suppressed because it is too large Load Diff

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@ -38,7 +38,6 @@
#include <jtag/commands.h>
#include "usb_common.h"
#define VID 0x1781
#define PID 0x0c63
@ -66,15 +65,14 @@ static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
#define WRITE_TMS 0x09
#define WRITE_TMS_CHAIN 0x0A
struct usbprog_jtag
{
struct usbprog_jtag {
struct usb_dev_handle *usb_handle;
};
static struct usbprog_jtag *usbprog_jtag_handle;
static struct usbprog_jtag *usbprog_jtag_open(void);
//static void usbprog_jtag_close(struct usbprog_jtag *usbprog_jtag);
/* static void usbprog_jtag_close(struct usbprog_jtag *usbprog_jtag); */
static void usbprog_jtag_init(struct usbprog_jtag *usbprog_jtag);
static unsigned char usbprog_jtag_message(struct usbprog_jtag *usbprog_jtag, char *msg, int msglen);
@ -94,9 +92,9 @@ static void usbprog_reset(int trst, int srst);
static void usbprog_jtag_set_direction(struct usbprog_jtag *usbprog_jtag, unsigned char direction);
static void usbprog_jtag_write_slice(struct usbprog_jtag *usbprog_jtag, unsigned char value);
//static unsigned char usbprog_jtag_get_port(struct usbprog_jtag *usbprog_jtag);
/* static unsigned char usbprog_jtag_get_port(struct usbprog_jtag *usbprog_jtag); */
static void usbprog_jtag_set_bit(struct usbprog_jtag *usbprog_jtag, int bit, int value);
//static int usbprog_jtag_get_bit(struct usbprog_jtag *usbprog_jtag, int bit);
/* static int usbprog_jtag_get_bit(struct usbprog_jtag *usbprog_jtag, int bit); */
static int usbprog_speed(int speed)
{
@ -110,23 +108,23 @@ static int usbprog_execute_queue(void)
enum scan_type type;
uint8_t *buffer;
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);
}
usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
break;
case JTAG_RUNTEST:
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
LOG_DEBUG("runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles,
cmd->cmd.runtest->end_state);
#endif
usbprog_end_state(cmd->cmd.runtest->end_state);
usbprog_runtest(cmd->cmd.runtest->num_cycles);
@ -140,7 +138,8 @@ static int usbprog_execute_queue(void)
break;
case JTAG_PATHMOVE:
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states,
LOG_DEBUG("pathmove: %i states, end in %i",
cmd->cmd.pathmove->num_states,
cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
#endif
usbprog_path_move(cmd->cmd.pathmove);
@ -180,8 +179,7 @@ static int usbprog_init(void)
usbprog_jtag_handle = usbprog_jtag_open();
tms_chain_index = 0;
if (usbprog_jtag_handle == 0)
{
if (usbprog_jtag_handle == 0) {
LOG_ERROR("Can't find USB JTAG Interface! Please check connection and permissions.");
return ERROR_JTAG_INIT_FAILED;
}
@ -205,8 +203,7 @@ static void usbprog_end_state(tap_state_t state)
{
if (tap_is_state_stable(state))
tap_set_end_state(state);
else
{
else {
LOG_ERROR("BUG: %i is not a valid end state", state);
exit(-1);
}
@ -231,23 +228,20 @@ static void usbprog_path_move(struct pathmove_command *cmd)
usbprog_jtag_tms_send(usbprog_jtag_handle);
state_count = 0;
while (num_states)
{
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count])
{
while (num_states) {
if (tap_state_transition(tap_get_state(), false) == cmd->path[state_count]) {
/* LOG_INFO("1"); */
usbprog_write(0, 0, 0);
usbprog_write(1, 0, 0);
}
else if (tap_state_transition(tap_get_state(), true) == cmd->path[state_count])
{
} else if (tap_state_transition(tap_get_state(),
true) == cmd->path[state_count]) {
/* LOG_INFO("2"); */
usbprog_write(0, 1, 0);
usbprog_write(1, 1, 0);
}
else
{
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(tap_get_state()), tap_state_name(cmd->path[state_count]));
} else {
LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
tap_state_name(tap_get_state()),
tap_state_name(cmd->path[state_count]));
exit(-1);
}
@ -264,32 +258,28 @@ static void usbprog_runtest(int num_cycles)
int i;
/* only do a state_move when we're not already in IDLE */
if (tap_get_state() != TAP_IDLE)
{
if (tap_get_state() != TAP_IDLE) {
usbprog_end_state(TAP_IDLE);
usbprog_state_move();
}
/* execute num_cycles */
if (num_cycles > 0)
{
if (num_cycles > 0) {
usbprog_jtag_tms_send(usbprog_jtag_handle);
usbprog_write(0, 0, 0);
}
else
{
} else {
usbprog_jtag_tms_send(usbprog_jtag_handle);
/* LOG_INFO("NUM CYCLES %i",num_cycles); */
}
for (i = 0; i < num_cycles; i++)
{
for (i = 0; i < num_cycles; i++) {
usbprog_write(1, 0, 0);
usbprog_write(0, 0, 0);
}
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("runtest: cur_state %s end_state %s", tap_state_name(tap_get_state()), tap_state_name(tap_get_end_state()));
LOG_DEBUG("runtest: cur_state %s end_state %s", tap_state_name(
tap_get_state()), tap_state_name(tap_get_end_state()));
#endif
/* finish in end_state */
@ -319,9 +309,15 @@ static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int
void (*f)(struct usbprog_jtag *usbprog_jtag, char *buffer_local, int size);
switch (type) {
case SCAN_OUT: f = &usbprog_jtag_write_tdi; break;
case SCAN_IN: f = &usbprog_jtag_read_tdo; break;
case SCAN_IO: f = &usbprog_jtag_write_and_read; break;
case SCAN_OUT:
f = &usbprog_jtag_write_tdi;
break;
case SCAN_IN:
f = &usbprog_jtag_read_tdo;
break;
case SCAN_IO:
f = &usbprog_jtag_write_and_read;
break;
default:
LOG_ERROR("unknown scan type: %i", type);
exit(-1);
@ -409,16 +405,14 @@ static unsigned char usbprog_jtag_message(struct usbprog_jtag *usbprog_jtag, cha
if ((msg[0] == 2) || (msg[0] == 1) || (msg[0] == 4) || (msg[0] == 0) || \
(msg[0] == 6) || (msg[0] == 0x0A) || (msg[0] == 9))
return 1;
if (res == msglen)
{
if (res == msglen) {
/* LOG_INFO("HALLLLOOO %i",(int)msg[0]); */
res = usb_bulk_read(usbprog_jtag->usb_handle, 0x82, msg, 2, 100);
if (res > 0)
return (unsigned char)msg[1];
else
return -1;
}
else
} else
return -1;
return 0;
}
@ -436,16 +430,12 @@ static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char
char swap;
/* 61 byte can be transfered (488 bit) */
while (size > 0)
{
if (size > 488)
{
while (size > 0) {
if (size > 488) {
send_bits = 488;
size = size - 488;
loops = 61;
}
else
{
} else {
send_bits = size;
loops = size / 8;
loops++;
@ -455,26 +445,22 @@ static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char
tmp[1] = (char)(send_bits >> 8); /* high */
tmp[2] = (char)(send_bits); /* low */
for (i = 0; i < loops; i++)
{
for (i = 0; i < loops; i++) {
tmp[3 + i] = buffer[bufindex];
bufindex++;
}
if (usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000) == 64)
{
if (usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000) == 64) {
/* LOG_INFO("HALLLLOOO2 %i",(int)tmp[0]); */
usleep(1);
int timeout = 0;
while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 1000) < 1)
{
while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 1000) < 1) {
timeout++;
if (timeout > 10)
break;
}
for (i = 0; i < loops; i++)
{
for (i = 0; i < loops; i++) {
swap = tmp[3 + i];
buffer[fillindex++] = swap;
}
@ -490,16 +476,12 @@ static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char * buff
char swap;
/* 61 byte can be transfered (488 bit) */
while (size > 0)
{
if (size > 488)
{
while (size > 0) {
if (size > 488) {
send_bits = 488;
size = size - 488;
loops = 61;
}
else
{
} else {
send_bits = size;
loops = size / 8;
loops++;
@ -514,15 +496,13 @@ static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char * buff
/* LOG_INFO("HALLLLOOO3 %i",(int)tmp[0]); */
int timeout = 0;
usleep(1);
while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 10) < 1)
{
while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 10) < 1) {
timeout++;
if (timeout > 10)
break;
}
for (i = 0; i < loops; i++)
{
for (i = 0; i < loops; i++) {
swap = tmp[3 + i];
buffer[fillindex++] = swap;
}
@ -535,16 +515,12 @@ static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char * buf
int send_bits, bufindex = 0, i, loops;
/* 61 byte can be transfered (488 bit) */
while (size > 0)
{
if (size > 488)
{
while (size > 0) {
if (size > 488) {
send_bits = 488;
size = size - 488;
loops = 61;
}
else
{
} else {
send_bits = size;
loops = size/8;
/* if (loops == 0) */
@ -555,8 +531,7 @@ static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char * buf
tmp[1] = (char)(send_bits >> 8); /* high */
tmp[2] = (char)(send_bits); /* low */
for (i = 0; i < loops; i++)
{
for (i = 0; i < loops; i++) {
tmp[3 + i] = buffer[bufindex];
bufindex++;
}
@ -631,8 +606,7 @@ static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag)
{
int i;
/* LOG_INFO("TMS SEND"); */
if (tms_chain_index > 0)
{
if (tms_chain_index > 0) {
char tmp[tms_chain_index + 2];
tmp[0] = WRITE_TMS_CHAIN;
tmp[1] = (char)(tms_chain_index);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,11 +16,11 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef __VERSALOON_H_INCLUDED__
#define __VERSALOON_H_INCLUDED__
struct usart_status_t
{
struct usart_status_t {
uint32_t tx_buff_avail;
uint32_t tx_buff_size;
uint32_t rx_buff_avail;
@ -29,7 +29,7 @@ struct usart_status_t
#include "usbtoxxx/usbtoxxx.h"
// GPIO pins
/* GPIO pins */
#define GPIO_SRST (1 << 0)
#define GPIO_TRST (1 << 1)
#define GPIO_USR1 (1 << 2)
@ -39,8 +39,8 @@ struct usart_status_t
#define GPIO_TDI (1 << 6)
#define GPIO_RTCK (1 << 7)
#define GPIO_TMS (1 << 8)
struct interface_gpio_t
{
struct interface_gpio_t {
RESULT(*init)(uint8_t interface_index);
RESULT(*fini)(uint8_t interface_index);
RESULT(*config)(uint8_t interface_index, uint32_t pin_mask, uint32_t io,
@ -49,14 +49,12 @@ struct interface_gpio_t
RESULT(*in)(uint8_t interface_index, uint32_t pin_mask, uint32_t *value);
};
struct interface_delay_t
{
struct interface_delay_t {
RESULT(*delayms)(uint16_t ms);
RESULT(*delayus)(uint16_t us);
};
struct interface_swd_t
{
struct interface_swd_t {
RESULT(*init)(uint8_t interface_index);
RESULT(*fini)(uint8_t interface_index);
RESULT(*config)(uint8_t interface_index, uint8_t trn, uint16_t retry,
@ -67,8 +65,7 @@ struct interface_swd_t
uint32_t *data, uint8_t *ack);
};
struct interface_jtag_raw_t
{
struct interface_jtag_raw_t {
RESULT(*init)(uint8_t interface_index);
RESULT(*fini)(uint8_t interface_index);
RESULT(*config)(uint8_t interface_index, uint32_t kHz);
@ -76,14 +73,12 @@ struct interface_jtag_raw_t
uint8_t *tdo, uint32_t bitlen);
};
struct interface_target_voltage_t
{
struct interface_target_voltage_t {
RESULT(*get)(uint16_t *voltage);
RESULT(*set)(uint16_t voltage);
};
struct versaloon_adaptors_t
{
struct versaloon_adaptors_t {
struct interface_target_voltage_t target_voltage;
struct interface_gpio_t gpio;
struct interface_delay_t delay;
@ -92,8 +87,7 @@ struct versaloon_adaptors_t
RESULT(*peripheral_commit)(void);
};
struct versaloon_usb_setting_t
{
struct versaloon_usb_setting_t {
uint16_t vid;
uint16_t pid;
uint8_t ep_out;
@ -104,8 +98,7 @@ struct versaloon_usb_setting_t
uint16_t buf_size;
};
struct versaloon_interface_t
{
struct versaloon_interface_t {
RESULT(*init)(void);
RESULT(*fini)(void);
struct versaloon_adaptors_t adaptors;

View File

@ -16,8 +16,9 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
// This file is used to include different header and macros
// according to different platform
/* This file is used to include different header and macros */
/* according to different platform */
#include <jtag/interface.h>
#include <jtag/commands.h>
#include "usb_common.h"
@ -31,7 +32,7 @@
#define RESULT int
#define LOG_BUG LOG_ERROR
// Common error messages
/* Common error messages */
#define ERRMSG_NOT_ENOUGH_MEMORY "Lack of memory."
#define ERRCODE_NOT_ENOUGH_MEMORY ERROR_FAIL

View File

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

View File

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

View File

@ -18,6 +18,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MINIDRIVER_IMP_H
#define MINIDRIVER_IMP_H
@ -36,8 +37,7 @@ static inline void jtag_add_dr_out(struct jtag_tap* tap,
#define jtag_add_callback(callback, in) interface_jtag_add_callback(callback, in)
#define jtag_add_callback4(callback, in, data1, data2, data3) interface_jtag_add_callback4(callback, in, data1, data2, data3)
#define jtag_add_callback4(callback, in, data1, data2, data3) \
interface_jtag_add_callback4(callback, in, data1, data2, data3)
#endif // MINIDRIVER_IMP_H
#endif /* MINIDRIVER_IMP_H */

View File

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

View File

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

View 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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff