diff options
author | Alexander Osipenko <sipych@gmail.com> | 2012-05-28 17:22:35 +0400 |
---|---|---|
committer | Spencer Oliver <spen@spen-soft.co.uk> | 2012-06-26 10:10:06 +0000 |
commit | 17ea1b31a1f70d89ff8592382edad2f5fc0ac1a9 (patch) | |
tree | 2bb13a03d888e57a7e80bf03dffa9e0be1eabbc0 | |
parent | b79f9ad1726778bdad2f89b9297a4acc6adb5b77 (diff) |
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 <sipych@gmail.com>
Reviewed-on: http://openocd.zylin.com/679
Tested-by: jenkins
Reviewed-by: Xiaofan <xiaofanc@gmail.com>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
-rw-r--r-- | src/jtag/drivers/jlink.c | 56 |
1 files changed, 46 insertions, 10 deletions
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 |