From 17ea1b31a1f70d89ff8592382edad2f5fc0ac1a9 Mon Sep 17 00:00:00 2001 From: Alexander Osipenko Date: Mon, 28 May 2012 17:22:35 +0400 Subject: JLink: added jlink_usb_io() function jlink_usb_io() function added for basic communication, since jlink_usb_message() is more specific to JTAG transactions. To verify the patch issue "jlink config" command. Change-Id: Id7d10bd5e8985d4c77f2e0ca47fb6033db2877bf Signed-off-by: Alexander Osipenko Reviewed-on: http://openocd.zylin.com/679 Tested-by: jenkins Reviewed-by: Xiaofan Reviewed-by: Spencer Oliver --- src/jtag/drivers/jlink.c | 56 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'src/jtag/drivers') diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 08df63bc..5dd09bc1 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -205,6 +205,7 @@ struct jlink { static struct jlink *jlink_usb_open(void); static void jlink_usb_close(struct jlink *jlink); static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length); +static int jlink_usb_io(struct jlink *jlink, int out_length, int in_length); static int jlink_usb_write(struct jlink *jlink, int out_length); static int jlink_usb_read(struct jlink *jlink, int expected_size); static int jlink_usb_read_emu_result(struct jlink *jlink); @@ -701,22 +702,15 @@ static int jlink_get_config(struct jlink_config *cfg) int result; int size = sizeof(struct jlink_config); - jlink_simple_command(EMU_CMD_READ_CONFIG); + usb_out_buffer[0] = EMU_CMD_READ_CONFIG; + result = jlink_usb_io(jlink_handle, 1, size); - result = jlink_usb_read(jlink_handle, size); - if (size != result) { + if (result != ERROR_OK) { LOG_ERROR("jlink_usb_read failed (requested=%d, result=%d)", size, result); return ERROR_FAIL; } memcpy(cfg, usb_in_buffer, size); - - /* - * Section 4.2.4 IN-transaction - * read dummy 0-byte packet - */ - jlink_usb_read(jlink_handle, 1); - return ERROR_OK; } @@ -1581,6 +1575,48 @@ static int jlink_usb_read_emu_result(struct jlink *jlink) return result; } +/* + * Send a message and receive the reply - simple messages. + * + * @param jlink pointer to driver data + * @param out_length data length in @c usb_out_buffer + * @param in_length data length to be read to @c usb_in_buffer + */ +static int jlink_usb_io(struct jlink *jlink, int out_length, int in_length) +{ + int result; + + result = jlink_usb_write(jlink, 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) { + LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", + in_length, result); + return ERROR_JTAG_DEVICE_ERROR; + } + + /* + * Section 4.2.4 IN-transaction: + * read dummy 0-byte packet if transaction size is + * multiple of 64 bytes but not max. size of 0x8000 + */ + if ((in_length % 64) == 0 && in_length != 0x8000) { + char dummy_buffer; + result = usb_bulk_read_ex(jlink->usb_handle, jlink_read_ep, + &dummy_buffer, 1, JLINK_USB_TIMEOUT); + if (result != 0) { + LOG_ERROR("dummy byte read failed"); + return ERROR_JTAG_DEVICE_ERROR; + } + } + return ERROR_OK; +} + #ifdef _DEBUG_USB_COMMS_ #define BYTES_PER_LINE 16 -- cgit v1.2.3-18-g5258