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