diff options
author | Spencer Oliver <spen@spen-soft.co.uk> | 2013-09-18 20:06:26 +0100 |
---|---|---|
committer | Spencer Oliver <spen@spen-soft.co.uk> | 2013-09-25 13:53:34 +0000 |
commit | cfe9ca039f4f6c058dff64effea50a857ff80f96 (patch) | |
tree | e5a30faaba2005b3f538ba83708c33680a0558c6 /src/jtag/drivers/ti_icdi_usb.c | |
parent | 0c58b81b08455439a5ef7c06a839664d1460748b (diff) |
hla: move memory read/write functionality to driver
Due to issues reported when using the jtag mode of the stlink (see Trac #61),
the functionality/checking has been moved to the driver.
This change also fixes unaligned 32bit memory read/write for the stlink.
From testing this change also brings a 3KiB/s speed increase, this is due
to the larger read/write packets.
Change-Id: I8234110e7e49a683f4dadd54c442ecdc3c47b320
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/1632
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Diffstat (limited to 'src/jtag/drivers/ti_icdi_usb.c')
-rw-r--r-- | src/jtag/drivers/ti_icdi_usb.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/src/jtag/drivers/ti_icdi_usb.c b/src/jtag/drivers/ti_icdi_usb.c index ae2f240f..0d7d943b 100644 --- a/src/jtag/drivers/ti_icdi_usb.c +++ b/src/jtag/drivers/ti_icdi_usb.c @@ -53,6 +53,7 @@ struct icdi_usb_handle_s { char *write_buffer; int max_packet; int read_count; + uint32_t max_rw_packet; /* max X packet (read/write memory) transfers */ }; static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t size, @@ -592,17 +593,57 @@ static int icdi_usb_write_mem_int(void *handle, uint32_t addr, uint32_t len, con static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t size, uint32_t count, uint8_t *buffer) { - if (size == 4) - count *= size; - return icdi_usb_read_mem_int(handle, addr, count, buffer); + int retval = ERROR_OK; + struct icdi_usb_handle_s *h = (struct icdi_usb_handle_s *)handle; + uint32_t bytes_remaining; + + /* calculate byte count */ + count *= size; + + while (count) { + + bytes_remaining = h->max_rw_packet; + if (count < bytes_remaining) + bytes_remaining = count; + + retval = icdi_usb_read_mem_int(handle, addr, bytes_remaining, buffer); + if (retval != ERROR_OK) + return retval; + + buffer += bytes_remaining; + addr += bytes_remaining; + count -= bytes_remaining; + } + + return retval; } static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t size, uint32_t count, const uint8_t *buffer) { - if (size == 4) - count *= size; - return icdi_usb_write_mem_int(handle, addr, count, buffer); + int retval = ERROR_OK; + struct icdi_usb_handle_s *h = (struct icdi_usb_handle_s *)handle; + uint32_t bytes_remaining; + + /* calculate byte count */ + count *= size; + + while (count) { + + bytes_remaining = h->max_rw_packet; + if (count < bytes_remaining) + bytes_remaining = count; + + retval = icdi_usb_write_mem_int(handle, addr, bytes_remaining, buffer); + if (retval != ERROR_OK) + return retval; + + buffer += bytes_remaining; + addr += bytes_remaining; + count -= bytes_remaining; + } + + return retval; } static int icdi_usb_close(void *handle) @@ -707,7 +748,7 @@ static int icdi_usb_open(struct hl_interface_param_s *param, void **fd) * as we are using gdb binary packets to transfer memory we have to * reserve half the buffer for any possible escape chars plus * at least 64 bytes for the gdb packet header */ - param->max_buffer = (((h->max_packet - 64) / 4) * 4) / 2; + h->max_rw_packet = (((h->max_packet - 64) / 4) * 4) / 2; return ERROR_OK; |