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 <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/1621
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
This commit is contained in:
Spencer Oliver 2013-09-11 21:31:50 +01:00
parent 06fb3bf8cd
commit 3a32dff089
4 changed files with 49 additions and 58 deletions

View File

@ -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); 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) 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, .write_reg = stlink_usb_write_reg,
/** */ /** */
.read_mem8 = stlink_usb_read_mem8, .read_mem = stlink_usb_read_mem,
/** */ /** */
.write_mem8 = stlink_usb_write_mem8, .write_mem = stlink_usb_write_mem,
/** */
.read_mem32 = stlink_usb_read_mem32,
/** */
.write_mem32 = stlink_usb_write_mem32,
/** */ /** */
.write_debug_reg = stlink_usb_write_debug_reg .write_debug_reg = stlink_usb_write_debug_reg
}; };

View File

@ -55,8 +55,10 @@ struct icdi_usb_handle_s {
int read_count; int read_count;
}; };
static int icdi_usb_read_mem32(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,
static int icdi_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, const uint8_t *buffer); 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) 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) 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) 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; 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) if (result != ERROR_OK)
return TARGET_UNKNOWN; return TARGET_UNKNOWN;
@ -524,7 +526,7 @@ static int icdi_usb_write_reg(void *handle, int num, uint32_t val)
return result; 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; int result;
struct icdi_usb_handle_s *h; 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; 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; int result;
struct icdi_usb_handle_s *h; 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; 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); if (size == 4)
} count *= size;
return icdi_usb_write_mem_int(handle, addr, count, 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);
} }
static int icdi_usb_close(void *handle) 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_regs = icdi_usb_read_regs,
.read_reg = icdi_usb_read_reg, .read_reg = icdi_usb_read_reg,
.write_reg = icdi_usb_write_reg, .write_reg = icdi_usb_write_reg,
.read_mem8 = icdi_usb_read_mem8, .read_mem = icdi_usb_read_mem,
.write_mem8 = icdi_usb_write_mem8, .write_mem = icdi_usb_write_mem,
.read_mem32 = icdi_usb_read_mem32,
.write_mem32 = icdi_usb_write_mem32,
.write_debug_reg = icdi_usb_write_debug_reg .write_debug_reg = icdi_usb_write_debug_reg
}; };

View File

@ -55,17 +55,11 @@ struct hl_layout_api_s {
/** */ /** */
int (*write_reg) (void *fd, int num, uint32_t val); int (*write_reg) (void *fd, int num, uint32_t val);
/** */ /** */
int (*read_mem8) (void *handle, uint32_t addr, uint16_t len, int (*read_mem) (void *handle, uint32_t addr, uint32_t size,
uint8_t *buffer); uint32_t count, uint8_t *buffer);
/** */ /** */
int (*write_mem8) (void *handle, uint32_t addr, uint16_t len, int (*write_mem) (void *handle, uint32_t addr, uint32_t size,
const uint8_t *buffer); uint32_t count, 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_debug_reg) (void *handle, uint32_t addr, uint32_t val); int (*write_debug_reg) (void *handle, uint32_t addr, uint32_t val);
/** */ /** */

View File

@ -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) static int hl_dcc_read(struct hl_interface_s *hl_if, uint8_t *value, uint8_t *ctrl)
{ {
uint16_t dcrdr; uint16_t dcrdr;
int retval = hl_if->layout->api->read_mem8(hl_if->fd, int retval = hl_if->layout->api->read_mem(hl_if->fd,
DCB_DCRDR, sizeof(dcrdr), (uint8_t *)&dcrdr); DCB_DCRDR, 1, sizeof(dcrdr), (uint8_t *)&dcrdr);
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
*ctrl = (uint8_t)dcrdr; *ctrl = (uint8_t)dcrdr;
*value = (uint8_t)(dcrdr >> 8); *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 */ * to signify we have read data */
/* atomically clear just the byte containing the busy bit */ /* atomically clear just the byte containing the busy bit */
static const uint8_t zero; static const uint8_t zero;
retval = hl_if->layout->api->write_mem8( retval = hl_if->layout->api->write_mem(hl_if->fd, DCB_DCRDR, 1, 1, &zero);
hl_if->fd, DCB_DCRDR, 1, &zero);
} }
} }
return retval; return retval;
@ -784,13 +783,7 @@ static int adapter_read_memory(struct target *target, uint32_t address,
else else
c = count; c = count;
if (size != 4) res = adapter->layout->api->read_mem(adapter->fd, address, size, c, buffer);
res = adapter->layout->api->read_mem8(adapter->fd,
address, c, buffer);
else
res = adapter->layout->api->read_mem32(adapter->fd,
address, c, buffer);
if (res != ERROR_OK) if (res != ERROR_OK)
return res; return res;
@ -832,13 +825,7 @@ static int adapter_write_memory(struct target *target, uint32_t address,
else else
c = count; c = count;
if (size != 4) res = adapter->layout->api->write_mem(adapter->fd, address, size, c, buffer);
res = adapter->layout->api->write_mem8(adapter->fd,
address, c, buffer);
else
res = adapter->layout->api->write_mem32(adapter->fd,
address, c, buffer);
if (res != ERROR_OK) if (res != ERROR_OK)
return res; return res;