From 3a32dff0895b7f85d29d5f58a21f17851f0a220e Mon Sep 17 00:00:00 2001 From: Spencer Oliver Date: Wed, 11 Sep 2013 21:31:50 +0100 Subject: [PATCH] hla: cleanup read/write api This is the first part in moving the adapter specific api back into the driver. The next task is to also move the hla read/write buffer size handling. Change-Id: I86a19144b50b6de18659bfcd05b3729b2cafc051 Signed-off-by: Spencer Oliver Reviewed-on: http://openocd.zylin.com/1621 Tested-by: jenkins Reviewed-by: Andreas Fritiofson --- src/jtag/drivers/stlink_usb.c | 26 +++++++++++++++----- src/jtag/drivers/ti_icdi_usb.c | 44 ++++++++++++++++------------------ src/jtag/hla/hla_layout.h | 14 ++++------- src/target/hla_target.c | 23 ++++-------------- 4 files changed, 49 insertions(+), 58 deletions(-) diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index cccb9ffa0..1dfe9401d 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -1429,6 +1429,24 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, return stlink_usb_get_rw_status(handle); } +static int stlink_usb_read_mem(void *handle, uint32_t addr, uint32_t size, + uint32_t count, uint8_t *buffer) +{ + if (size == 4) + return stlink_usb_read_mem32(handle, addr, count, buffer); + else + return stlink_usb_read_mem8(handle, addr, count, buffer); +} + +static int stlink_usb_write_mem(void *handle, uint32_t addr, uint32_t size, + uint32_t count, const uint8_t *buffer) +{ + if (size == 4) + return stlink_usb_write_mem32(handle, addr, count, buffer); + else + return stlink_usb_write_mem8(handle, addr, count, buffer); +} + /** */ static int stlink_usb_close(void *fd) { @@ -1632,13 +1650,9 @@ struct hl_layout_api_s stlink_usb_layout_api = { /** */ .write_reg = stlink_usb_write_reg, /** */ - .read_mem8 = stlink_usb_read_mem8, + .read_mem = stlink_usb_read_mem, /** */ - .write_mem8 = stlink_usb_write_mem8, - /** */ - .read_mem32 = stlink_usb_read_mem32, - /** */ - .write_mem32 = stlink_usb_write_mem32, + .write_mem = stlink_usb_write_mem, /** */ .write_debug_reg = stlink_usb_write_debug_reg }; diff --git a/src/jtag/drivers/ti_icdi_usb.c b/src/jtag/drivers/ti_icdi_usb.c index f10d12073..ae2f240fc 100644 --- a/src/jtag/drivers/ti_icdi_usb.c +++ b/src/jtag/drivers/ti_icdi_usb.c @@ -55,8 +55,10 @@ struct icdi_usb_handle_s { int read_count; }; -static int icdi_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, uint8_t *buffer); -static int icdi_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, const uint8_t *buffer); +static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t size, + uint32_t count, uint8_t *buffer); +static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t size, + uint32_t count, const uint8_t *buffer); static int remote_escape_output(const char *buffer, int len, char *out_buf, int *out_len, int out_maxlen) { @@ -286,7 +288,7 @@ static int icdi_usb_idcode(void *handle, uint32_t *idcode) static int icdi_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val) { - return icdi_usb_write_mem32(handle, addr, 1, (uint8_t *)&val); + return icdi_usb_write_mem(handle, addr, 4, 1, (uint8_t *)&val); } static enum target_state icdi_usb_state(void *handle) @@ -297,7 +299,7 @@ static enum target_state icdi_usb_state(void *handle) h = (struct icdi_usb_handle_s *)handle; - result = icdi_usb_read_mem32(h, DCB_DHCSR, 1, (uint8_t *)&dhcsr); + result = icdi_usb_read_mem(h, DCB_DHCSR, 4, 1, (uint8_t *)&dhcsr); if (result != ERROR_OK) return TARGET_UNKNOWN; @@ -524,7 +526,7 @@ static int icdi_usb_write_reg(void *handle, int num, uint32_t val) return result; } -static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t len, uint8_t *buffer) +static int icdi_usb_read_mem_int(void *handle, uint32_t addr, uint32_t len, uint8_t *buffer) { int result; struct icdi_usb_handle_s *h; @@ -554,7 +556,7 @@ static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t len, uint8_t return ERROR_OK; } -static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t len, const uint8_t *buffer) +static int icdi_usb_write_mem_int(void *handle, uint32_t addr, uint32_t len, const uint8_t *buffer) { int result; struct icdi_usb_handle_s *h; @@ -587,24 +589,20 @@ static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t len, const u return ERROR_OK; } -static int icdi_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, uint8_t *buffer) +static int icdi_usb_read_mem(void *handle, uint32_t addr, uint32_t size, + uint32_t count, uint8_t *buffer) { - return icdi_usb_read_mem(handle, addr, len, buffer); + if (size == 4) + count *= size; + return icdi_usb_read_mem_int(handle, addr, count, buffer); } -static int icdi_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, const uint8_t *buffer) +static int icdi_usb_write_mem(void *handle, uint32_t addr, uint32_t size, + uint32_t count, const uint8_t *buffer) { - return icdi_usb_write_mem(handle, addr, len, buffer); -} - -static int icdi_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, uint8_t *buffer) -{ - return icdi_usb_read_mem(handle, addr, len * 4, buffer); -} - -static int icdi_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, const uint8_t *buffer) -{ - return icdi_usb_write_mem(handle, addr, len * 4, buffer); + if (size == 4) + count *= size; + return icdi_usb_write_mem_int(handle, addr, count, buffer); } static int icdi_usb_close(void *handle) @@ -732,9 +730,7 @@ struct hl_layout_api_s icdi_usb_layout_api = { .read_regs = icdi_usb_read_regs, .read_reg = icdi_usb_read_reg, .write_reg = icdi_usb_write_reg, - .read_mem8 = icdi_usb_read_mem8, - .write_mem8 = icdi_usb_write_mem8, - .read_mem32 = icdi_usb_read_mem32, - .write_mem32 = icdi_usb_write_mem32, + .read_mem = icdi_usb_read_mem, + .write_mem = icdi_usb_write_mem, .write_debug_reg = icdi_usb_write_debug_reg }; diff --git a/src/jtag/hla/hla_layout.h b/src/jtag/hla/hla_layout.h index bd6a6b42a..d7b5d9353 100644 --- a/src/jtag/hla/hla_layout.h +++ b/src/jtag/hla/hla_layout.h @@ -55,17 +55,11 @@ struct hl_layout_api_s { /** */ int (*write_reg) (void *fd, int num, uint32_t val); /** */ - int (*read_mem8) (void *handle, uint32_t addr, uint16_t len, - uint8_t *buffer); + int (*read_mem) (void *handle, uint32_t addr, uint32_t size, + uint32_t count, uint8_t *buffer); /** */ - int (*write_mem8) (void *handle, uint32_t addr, uint16_t len, - const uint8_t *buffer); - /** */ - int (*read_mem32) (void *handle, uint32_t addr, uint16_t len, - uint8_t *buffer); - /** */ - int (*write_mem32) (void *handle, uint32_t addr, uint16_t len, - const uint8_t *buffer); + int (*write_mem) (void *handle, uint32_t addr, uint32_t size, + uint32_t count, const uint8_t *buffer); /** */ int (*write_debug_reg) (void *handle, uint32_t addr, uint32_t val); /** */ diff --git a/src/target/hla_target.c b/src/target/hla_target.c index 2db04f811..dc81ee89a 100644 --- a/src/target/hla_target.c +++ b/src/target/hla_target.c @@ -259,8 +259,8 @@ static int adapter_examine_debug_reason(struct target *target) static int hl_dcc_read(struct hl_interface_s *hl_if, uint8_t *value, uint8_t *ctrl) { uint16_t dcrdr; - int retval = hl_if->layout->api->read_mem8(hl_if->fd, - DCB_DCRDR, sizeof(dcrdr), (uint8_t *)&dcrdr); + int retval = hl_if->layout->api->read_mem(hl_if->fd, + DCB_DCRDR, 1, sizeof(dcrdr), (uint8_t *)&dcrdr); if (retval == ERROR_OK) { *ctrl = (uint8_t)dcrdr; *value = (uint8_t)(dcrdr >> 8); @@ -272,8 +272,7 @@ static int hl_dcc_read(struct hl_interface_s *hl_if, uint8_t *value, uint8_t *ct * to signify we have read data */ /* atomically clear just the byte containing the busy bit */ static const uint8_t zero; - retval = hl_if->layout->api->write_mem8( - hl_if->fd, DCB_DCRDR, 1, &zero); + retval = hl_if->layout->api->write_mem(hl_if->fd, DCB_DCRDR, 1, 1, &zero); } } return retval; @@ -784,13 +783,7 @@ static int adapter_read_memory(struct target *target, uint32_t address, else c = count; - if (size != 4) - res = adapter->layout->api->read_mem8(adapter->fd, - address, c, buffer); - else - res = adapter->layout->api->read_mem32(adapter->fd, - address, c, buffer); - + res = adapter->layout->api->read_mem(adapter->fd, address, size, c, buffer); if (res != ERROR_OK) return res; @@ -832,13 +825,7 @@ static int adapter_write_memory(struct target *target, uint32_t address, else c = count; - if (size != 4) - res = adapter->layout->api->write_mem8(adapter->fd, - address, c, buffer); - else - res = adapter->layout->api->write_mem32(adapter->fd, - address, c, buffer); - + res = adapter->layout->api->write_mem(adapter->fd, address, size, c, buffer); if (res != ERROR_OK) return res;