/***************************************************************************
- * Copyright (C) 2011 by Martin Schmoelzer *
+ * Copyright (C) 2011-2013 by Martin Schmoelzer *
* <martin.schmoelzer@student.tuwien.ac.at> *
* *
* This program is free software; you can redistribute it and/or modify *
* 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. *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <jtag/interface.h>
#include <jtag/commands.h>
#include <target/image.h>
-#include <helper/types.h>
-#include "usb_common.h"
+#include <libusb.h>
#include "OpenULINK/include/msgtypes.h"
/** USB Vendor ID of ULINK device in unconfigured state (no firmware loaded
#define ULINK_RENUMERATION_DELAY 1500000
/** Default location of OpenULINK firmware image. */
-#define ULINK_FIRMWARE_FILE PKGLIBDIR "/OpenULINK/ulink_firmware.hex"
+#define ULINK_FIRMWARE_FILE PKGDATADIR "/OpenULINK/ulink_firmware.hex"
/** Maximum size of a single firmware section. Entire EZ-USB code space = 8kB */
#define SECTION_BUFFERSIZE 8192
* The last command sets #needs_postprocessing to true.
*/
struct ulink_cmd {
- uint8_t id; /* /< ULINK command ID */
+ uint8_t id; /**< ULINK command ID */
- uint8_t *payload_out; /* /< OUT direction payload data */
- uint8_t payload_out_size; /* /< OUT direction payload size for this command */
+ uint8_t *payload_out; /**< OUT direction payload data */
+ uint8_t payload_out_size; /**< OUT direction payload size for this command */
- uint8_t *payload_in_start; /* /< Pointer to first element of IN payload array */
- uint8_t *payload_in; /* /< Pointer where IN payload shall be stored */
- uint8_t payload_in_size;/* /< IN direction payload size for this command */
+ uint8_t *payload_in_start; /**< Pointer to first element of IN payload array */
+ uint8_t *payload_in; /**< Pointer where IN payload shall be stored */
+ uint8_t payload_in_size; /**< IN direction payload size for this command */
/** Indicates if this command needs post-processing */
bool needs_postprocessing;
/** Pointer to corresponding OpenOCD command for post-processing */
struct jtag_command *cmd_origin;
- struct ulink_cmd *next; /* /< Pointer to next command (linked list) */
+ struct ulink_cmd *next; /**< Pointer to next command (linked list) */
};
/** Describes one driver instance */
struct ulink {
- struct usb_dev_handle *usb_handle;
+ struct libusb_context *libusb_ctx;
+ struct libusb_device_handle *usb_device_handle;
enum ulink_type type;
- int delay_scan_in; /* /< Delay value for SCAN_IN commands */
- int delay_scan_out; /* /< Delay value for SCAN_OUT commands */
- int delay_scan_io; /* /< Delay value for SCAN_IO commands */
- int delay_clock_tck; /* /< Delay value for CLOCK_TMS commands */
- int delay_clock_tms; /* /< Delay value for CLOCK_TCK commands */
+ int delay_scan_in; /**< Delay value for SCAN_IN commands */
+ int delay_scan_out; /**< Delay value for SCAN_OUT commands */
+ int delay_scan_io; /**< Delay value for SCAN_IO commands */
+ int delay_clock_tck; /**< Delay value for CLOCK_TMS commands */
+ int delay_clock_tms; /**< Delay value for CLOCK_TCK commands */
- int commands_in_queue; /* /< Number of commands in queue */
- struct ulink_cmd *queue_start; /* /< Pointer to first command in queue */
- struct ulink_cmd *queue_end; /* /< Pointer to last command in queue */
+ int commands_in_queue; /**< Number of commands in queue */
+ struct ulink_cmd *queue_start; /**< Pointer to first command in queue */
+ struct ulink_cmd *queue_end; /**< Pointer to last command in queue */
};
/**************************** Function Prototypes *****************************/
int ulink_usb_close(struct ulink **device);
/* ULINK MCU (Cypress EZ-USB) specific functions */
-int ulink_cpu_reset(struct ulink *device, char reset_bit);
-int ulink_load_firmware_and_renumerate(struct ulink **device, char *filename,
+int ulink_cpu_reset(struct ulink *device, unsigned char reset_bit);
+int ulink_load_firmware_and_renumerate(struct ulink **device, const char *filename,
uint32_t delay);
-int ulink_load_firmware(struct ulink *device, char *filename);
+int ulink_load_firmware(struct ulink *device, const char *filename);
int ulink_write_firmware_section(struct ulink *device,
struct image *firmware_image, int section_index);
int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd);
int ulink_execute_queued_commands(struct ulink *device, int timeout);
-#ifdef _DEBUG_JTAG_IO_
-const char *ulink_cmd_id_string(uint8_t id);
-void ulink_print_command(struct ulink_cmd *ulink_cmd);
-void ulink_print_queue(struct ulink *device);
-#endif
+static void ulink_print_queue(struct ulink *device);
int ulink_append_scan_cmd(struct ulink *device,
enum scan_type scan_type,
/* OpenULINK TCK frequency helper functions */
int ulink_calculate_delay(enum ulink_delay_type type, long f, int *delay);
-int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long *f);
/* Interface between OpenULINK and OpenOCD */
static void ulink_set_end_state(tap_state_t endstate);
int ulink_post_process_scan(struct ulink_cmd *ulink_cmd);
int ulink_post_process_queue(struct ulink *device);
-/* JTAG driver functions (registered in struct jtag_interface) */
+/* adapter driver functions */
static int ulink_execute_queue(void);
static int ulink_khz(int khz, int *jtag_speed);
static int ulink_speed(int speed);
/**
* Opens the ULINK device and claims its USB interface.
*
+ * Currently, only the original ULINK is supported
+ *
* @param device pointer to struct ulink identifying ULINK driver instance.
* @return on success: ERROR_OK
* @return on failure: ERROR_FAIL
*/
int ulink_usb_open(struct ulink **device)
{
- int ret;
- struct usb_dev_handle *usb_handle;
+ ssize_t num_devices, i;
+ bool found;
+ libusb_device **usb_devices;
+ struct libusb_device_descriptor usb_desc;
+ struct libusb_device_handle *usb_device_handle;
- /* Currently, only original ULINK is supported */
- uint16_t vids[] = { ULINK_VID, 0 };
- uint16_t pids[] = { ULINK_PID, 0 };
+ num_devices = libusb_get_device_list((*device)->libusb_ctx, &usb_devices);
- ret = jtag_usb_open(vids, pids, &usb_handle);
+ if (num_devices <= 0)
+ return ERROR_FAIL;
- if (ret != ERROR_OK)
- return ret;
+ found = false;
+ for (i = 0; i < num_devices; i++) {
+ if (libusb_get_device_descriptor(usb_devices[i], &usb_desc) != 0)
+ continue;
+ else if (usb_desc.idVendor == ULINK_VID && usb_desc.idProduct == ULINK_PID) {
+ found = true;
+ break;
+ }
+ }
- ret = usb_claim_interface(usb_handle, 0);
+ if (!found)
+ return ERROR_FAIL;
- if (ret != 0)
- return ret;
+ if (libusb_open(usb_devices[i], &usb_device_handle) != 0)
+ return ERROR_FAIL;
+ libusb_free_device_list(usb_devices, 1);
+
+ if (libusb_claim_interface(usb_device_handle, 0) != 0)
+ return ERROR_FAIL;
- (*device)->usb_handle = usb_handle;
+ (*device)->usb_device_handle = usb_device_handle;
(*device)->type = ULINK_1;
return ERROR_OK;
*/
int ulink_usb_close(struct ulink **device)
{
- if (usb_release_interface((*device)->usb_handle, 0) != 0)
+ if (libusb_release_interface((*device)->usb_device_handle, 0) != 0)
return ERROR_FAIL;
- if (usb_close((*device)->usb_handle) != 0)
- return ERROR_FAIL;
+ libusb_close((*device)->usb_device_handle);
- (*device)->usb_handle = NULL;
+ (*device)->usb_device_handle = NULL;
return ERROR_OK;
}
* @return on success: ERROR_OK
* @return on failure: ERROR_FAIL
*/
-int ulink_cpu_reset(struct ulink *device, char reset_bit)
+int ulink_cpu_reset(struct ulink *device, unsigned char reset_bit)
{
int ret;
- ret = usb_control_msg(device->usb_handle,
- (USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE),
+ ret = libusb_control_transfer(device->usb_device_handle,
+ (LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE),
REQUEST_FIRMWARE_LOAD, CPUCS_REG, 0, &reset_bit, 1, USB_TIMEOUT);
/* usb_control_msg() returns the number of bytes transferred during the
* @return on failure: ERROR_FAIL
*/
int ulink_load_firmware_and_renumerate(struct ulink **device,
- char *filename, uint32_t delay)
+ const char *filename, uint32_t delay)
{
int ret;
* @return on success: ERROR_OK
* @return on failure: ERROR_FAIL
*/
-int ulink_load_firmware(struct ulink *device, char *filename)
+int ulink_load_firmware(struct ulink *device, const char *filename)
{
struct image ulink_firmware_image;
int ret, i;
LOG_DEBUG("section %02i at addr 0x%04x (size 0x%04x)", section_index, addr,
size);
- if (data == NULL)
- return ERROR_FAIL;
-
/* Copy section contents to local buffer */
ret = image_read_section(firmware_image, section_index, 0, size, data,
&size_read);
else
chunk_size = bytes_remaining;
- ret = usb_control_msg(device->usb_handle,
- (USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE),
- REQUEST_FIRMWARE_LOAD, addr, FIRMWARE_ADDR, (char *)data_ptr,
+ ret = libusb_control_transfer(device->usb_device_handle,
+ (LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE),
+ REQUEST_FIRMWARE_LOAD, addr, FIRMWARE_ADDR, (unsigned char *)data_ptr,
chunk_size, USB_TIMEOUT);
if (ret != (int)chunk_size) {
(input_signals & SIGNAL_TDO ? 1 : 0),
(output_signals & SIGNAL_TMS ? 1 : 0),
(output_signals & SIGNAL_TCK ? 1 : 0),
- (output_signals & SIGNAL_TRST ? 0 : 1),/* TRST and RESET are inverted */
- (output_signals & SIGNAL_RESET ? 0 : 1)); /* by hardware */
+ (output_signals & SIGNAL_TRST ? 0 : 1), /* Inverted by hardware */
+ (output_signals & SIGNAL_RESET ? 0 : 1)); /* Inverted by hardware */
}
/**************** OpenULINK command generation helper functions ***************/
case PAYLOAD_DIRECTION_OUT:
if (ulink_cmd->payload_out != NULL) {
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
+ free(payload);
return ERROR_FAIL;
} else {
ulink_cmd->payload_out = payload;
case PAYLOAD_DIRECTION_IN:
if (ulink_cmd->payload_in_start != NULL) {
LOG_ERROR("BUG: Duplicate payload allocation for OpenULINK command");
+ free(payload);
return ERROR_FAIL;
} else {
ulink_cmd->payload_in_start = payload;
int ulink_execute_queued_commands(struct ulink *device, int timeout)
{
struct ulink_cmd *current;
- int ret, i, index_out, index_in, count_out, count_in;
+ int ret, i, index_out, index_in, count_out, count_in, transferred;
uint8_t buffer[64];
-#ifdef _DEBUG_JTAG_IO_
- ulink_print_queue(device);
-#endif
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO))
+ ulink_print_queue(device);
index_out = 0;
count_out = 0;
}
/* Send packet to ULINK */
- ret = usb_bulk_write(device->usb_handle, (2 | USB_ENDPOINT_OUT),
- (char *)buffer, count_out, timeout);
- if (ret < 0)
+ ret = libusb_bulk_transfer(device->usb_device_handle, (2 | LIBUSB_ENDPOINT_OUT),
+ (unsigned char *)buffer, count_out, &transferred, timeout);
+ if (ret != 0)
return ERROR_FAIL;
- if (ret != count_out)
+ if (transferred != count_out)
return ERROR_FAIL;
/* Wait for response if commands contain IN payload data */
if (count_in > 0) {
- ret = usb_bulk_read(device->usb_handle, (2 | USB_ENDPOINT_IN),
- (char *)buffer, 64, timeout);
- if (ret < 0)
+ ret = libusb_bulk_transfer(device->usb_device_handle, (2 | LIBUSB_ENDPOINT_IN),
+ (unsigned char *)buffer, 64, &transferred, timeout);
+ if (ret != 0)
return ERROR_FAIL;
- if (ret != count_in)
+ if (transferred != count_in)
return ERROR_FAIL;
/* Write back IN payload data */
return ERROR_OK;
}
-#ifdef _DEBUG_JTAG_IO_
-
/**
* Convert an OpenULINK command ID (\a id) to a human-readable string.
*
* @param id the OpenULINK command ID.
* @return the corresponding human-readable string.
*/
-const char *ulink_cmd_id_string(uint8_t id)
+static const char *ulink_cmd_id_string(uint8_t id)
{
switch (id) {
- case CMD_SCAN_IN:
- return "CMD_SCAN_IN";
- break;
- case CMD_SLOW_SCAN_IN:
- return "CMD_SLOW_SCAN_IN";
- break;
- case CMD_SCAN_OUT:
- return "CMD_SCAN_OUT";
- break;
- case CMD_SLOW_SCAN_OUT:
- return "CMD_SLOW_SCAN_OUT";
- break;
- case CMD_SCAN_IO:
- return "CMD_SCAN_IO";
- break;
- case CMD_SLOW_SCAN_IO:
- return "CMD_SLOW_SCAN_IO";
- break;
- case CMD_CLOCK_TMS:
- return "CMD_CLOCK_TMS";
- break;
- case CMD_SLOW_CLOCK_TMS:
- return "CMD_SLOW_CLOCK_TMS";
- break;
- case CMD_CLOCK_TCK:
- return "CMD_CLOCK_TCK";
- break;
- case CMD_SLOW_CLOCK_TCK:
- return "CMD_SLOW_CLOCK_TCK";
- break;
- case CMD_SLEEP_US:
- return "CMD_SLEEP_US";
- break;
- case CMD_SLEEP_MS:
- return "CMD_SLEEP_MS";
- break;
- case CMD_GET_SIGNALS:
- return "CMD_GET_SIGNALS";
- break;
- case CMD_SET_SIGNALS:
- return "CMD_SET_SIGNALS";
- break;
- case CMD_CONFIGURE_TCK_FREQ:
- return "CMD_CONFIGURE_TCK_FREQ";
- break;
- case CMD_SET_LEDS:
- return "CMD_SET_LEDS";
- break;
- case CMD_TEST:
- return "CMD_TEST";
- break;
- default:
- return "CMD_UNKNOWN";
- break;
+ case CMD_SCAN_IN:
+ return "CMD_SCAN_IN";
+ break;
+ case CMD_SLOW_SCAN_IN:
+ return "CMD_SLOW_SCAN_IN";
+ break;
+ case CMD_SCAN_OUT:
+ return "CMD_SCAN_OUT";
+ break;
+ case CMD_SLOW_SCAN_OUT:
+ return "CMD_SLOW_SCAN_OUT";
+ break;
+ case CMD_SCAN_IO:
+ return "CMD_SCAN_IO";
+ break;
+ case CMD_SLOW_SCAN_IO:
+ return "CMD_SLOW_SCAN_IO";
+ break;
+ case CMD_CLOCK_TMS:
+ return "CMD_CLOCK_TMS";
+ break;
+ case CMD_SLOW_CLOCK_TMS:
+ return "CMD_SLOW_CLOCK_TMS";
+ break;
+ case CMD_CLOCK_TCK:
+ return "CMD_CLOCK_TCK";
+ break;
+ case CMD_SLOW_CLOCK_TCK:
+ return "CMD_SLOW_CLOCK_TCK";
+ break;
+ case CMD_SLEEP_US:
+ return "CMD_SLEEP_US";
+ break;
+ case CMD_SLEEP_MS:
+ return "CMD_SLEEP_MS";
+ break;
+ case CMD_GET_SIGNALS:
+ return "CMD_GET_SIGNALS";
+ break;
+ case CMD_SET_SIGNALS:
+ return "CMD_SET_SIGNALS";
+ break;
+ case CMD_CONFIGURE_TCK_FREQ:
+ return "CMD_CONFIGURE_TCK_FREQ";
+ break;
+ case CMD_SET_LEDS:
+ return "CMD_SET_LEDS";
+ break;
+ case CMD_TEST:
+ return "CMD_TEST";
+ break;
+ default:
+ return "CMD_UNKNOWN";
+ break;
}
}
*
* @param ulink_cmd pointer to OpenULINK command.
*/
-void ulink_print_command(struct ulink_cmd *ulink_cmd)
+static void ulink_print_command(struct ulink_cmd *ulink_cmd)
{
int i;
*
* @param device pointer to struct ulink identifying ULINK driver instance.
*/
-void ulink_print_queue(struct ulink *device)
+static void ulink_print_queue(struct ulink *device)
{
struct ulink_cmd *current;
ulink_print_command(current);
}
-#endif /* _DEBUG_JTAG_IO_ */
-
/**
* Perform JTAG scan
*
if (scan_size_bits > (58 * 8)) {
LOG_ERROR("BUG: Tried to create CMD_SCAN_IO OpenULINK command with too"
" large payload");
+ free(cmd);
return ERROR_FAIL;
}
break;
}
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
/* Build payload_out that is common to all scan types */
cmd->payload_out[0] = scan_size_bytes & 0xFF;
/* CMD_CLOCK_TMS has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = count;
cmd->payload_out[1] = sequence;
/* CMD_CLOCK_TCK has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = count & 0xff;
cmd->payload_out[1] = (count >> 8) & 0xff;
/* CMD_GET_SIGNALS has two IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_IN);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
return ulink_append_queue(device, cmd);
}
/* CMD_SET_SIGNALS has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = low;
cmd->payload_out[1] = high;
/* CMD_SLEEP_US has two OUT payload bytes and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = us & 0x00ff;
cmd->payload_out[1] = (us >> 8) & 0x00ff;
/* CMD_CONFIGURE_TCK_FREQ has five OUT payload bytes and zero
* IN payload bytes */
ret = ulink_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
if (delay_scan_in < 0)
cmd->payload_out[0] = 0;
/* CMD_SET_LEDS has one OUT payload byte and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = led_state;
/* CMD_TEST has one OUT payload byte and zero IN payload bytes */
ret = ulink_allocate_payload(cmd, 1, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK)
+ if (ret != ERROR_OK) {
+ free(cmd);
return ret;
+ }
cmd->payload_out[0] = 0xAA;
*
* @param type for which command to calculate the delay value.
* @param delay delay value for which to calculate the resulting TCK frequency.
- * @param f where to store the resulting TCK frequency.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @return the resulting TCK frequency
*/
-int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long *f)
+static long ulink_calculate_frequency(enum ulink_delay_type type, int delay)
{
- float t, f_float, f_rounded;
+ float t, f_float;
if (delay > 255)
- return ERROR_FAIL;
+ return 0;
switch (type) {
case DELAY_CLOCK_TCK:
t = (float)(4E-6) * (float)(delay) + (float)(1.3132E-5);
break;
default:
- return ERROR_FAIL;
- break;
+ return 0;
}
f_float = 1.0 / t;
- f_rounded = roundf(f_float);
- *f = (long)f_rounded;
-
- return ERROR_OK;
+ return roundf(f_float);
}
/******************* Interface between OpenULINK and OpenOCD ******************/
return ret;
}
-#ifdef _DEBUG_JTAG_IO_
- long f_tck, f_tms, f_scan_in, f_scan_out, f_scan_io;
-
- ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck,
- &f_tck);
- ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms,
- &f_tms);
- ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in,
- &f_scan_in);
- ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out,
- &f_scan_out);
- ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io,
- &f_scan_io);
-
- DEBUG_JTAG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),",
- ulink_handle->delay_clock_tck, f_tck);
- DEBUG_JTAG_IO(" delay_tms = %i (%li Hz),",
- ulink_handle->delay_clock_tms, f_tms);
- DEBUG_JTAG_IO(" delay_scan_in = %i (%li Hz),",
- ulink_handle->delay_scan_in, f_scan_in);
- DEBUG_JTAG_IO(" delay_scan_out = %i (%li Hz),",
- ulink_handle->delay_scan_out, f_scan_out);
- DEBUG_JTAG_IO(" delay_scan_io = %i (%li Hz),",
- ulink_handle->delay_scan_io, f_scan_io);
-#endif
+ LOG_DEBUG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),",
+ ulink_handle->delay_clock_tck,
+ ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck));
+ LOG_DEBUG_IO(" delay_tms = %i (%li Hz),",
+ ulink_handle->delay_clock_tms,
+ ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms));
+ LOG_DEBUG_IO(" delay_scan_in = %i (%li Hz),",
+ ulink_handle->delay_scan_in,
+ ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in));
+ LOG_DEBUG_IO(" delay_scan_out = %i (%li Hz),",
+ ulink_handle->delay_scan_out,
+ ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out));
+ LOG_DEBUG_IO(" delay_scan_io = %i (%li Hz),",
+ ulink_handle->delay_scan_io,
+ ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io));
/* Configure the ULINK device with the new delay values */
ret = ulink_append_configure_tck_cmd(ulink_handle,
*/
static int ulink_init(void)
{
- int ret;
+ int ret, transferred;
char str_manufacturer[20];
bool download_firmware = false;
- uint8_t *dummy;
+ unsigned char *dummy;
uint8_t input_signals, output_signals;
ulink_handle = calloc(1, sizeof(struct ulink));
if (ulink_handle == NULL)
return ERROR_FAIL;
- usb_init();
+ libusb_init(&ulink_handle->libusb_ctx);
ret = ulink_usb_open(&ulink_handle);
if (ret != ERROR_OK) {
LOG_ERROR("Could not open ULINK device");
+ free(ulink_handle);
+ ulink_handle = NULL;
return ret;
}
/* Get String Descriptor to determine if firmware needs to be loaded */
- ret = usb_get_string_simple(ulink_handle->usb_handle, 1, str_manufacturer, 20);
+ ret = libusb_get_string_descriptor_ascii(ulink_handle->usb_device_handle, 1, (unsigned char *)str_manufacturer, 20);
if (ret < 0) {
/* Could not get descriptor -> Unconfigured or original Keil firmware */
download_firmware = true;
ULINK_FIRMWARE_FILE, ULINK_RENUMERATION_DELAY);
if (ret != ERROR_OK) {
LOG_ERROR("Could not download firmware and re-numerate ULINK");
+ free(ulink_handle);
+ ulink_handle = NULL;
return ret;
}
} else
* shut down by the user via Ctrl-C. Try to retrieve this Bulk IN packet. */
dummy = calloc(64, sizeof(uint8_t));
- ret = usb_bulk_read(ulink_handle->usb_handle, (2 | USB_ENDPOINT_IN),
- (char *)dummy, 64, 200);
+ ret = libusb_bulk_transfer(ulink_handle->usb_device_handle, (2 | LIBUSB_ENDPOINT_IN),
+ dummy, 64, &transferred, 200);
free(dummy);
- if (ret < 0) {
+ if (ret != 0 || transferred == 0) {
/* Bulk IN transfer failed -> unrecoverable error condition */
LOG_ERROR("Cannot communicate with ULINK device. Disconnect ULINK from "
"the USB port and re-connect, then re-run OpenOCD");
+ free(ulink_handle);
+ ulink_handle = NULL;
return ERROR_FAIL;
}
#ifdef _DEBUG_USB_COMMS_
LOG_INFO("Downloading ULINK firmware image %s", CMD_ARGV[0]);
/* Download firmware image in CMD_ARGV[0] */
- ret = ulink_load_firmware_and_renumerate(&ulink_handle, (char *)CMD_ARGV[0],
+ ret = ulink_load_firmware_and_renumerate(&ulink_handle, CMD_ARGV[0],
ULINK_RENUMERATION_DELAY);
return ret;
COMMAND_REGISTRATION_DONE,
};
-struct jtag_interface ulink_interface = {
- .name = "ulink",
+static struct jtag_interface ulink_interface = {
+ .execute_queue = ulink_execute_queue,
+};
- .commands = ulink_command_handlers,
+struct adapter_driver ulink_adapter_driver = {
+ .name = "ulink",
.transports = jtag_only,
+ .commands = ulink_command_handlers,
- .execute_queue = ulink_execute_queue,
- .khz = ulink_khz,
+ .init = ulink_init,
+ .quit = ulink_quit,
.speed = ulink_speed,
+ .khz = ulink_khz,
.speed_div = ulink_speed_div,
- .init = ulink_init,
- .quit = ulink_quit
+ .jtag_ops = &ulink_interface,
};