]> git.sur5r.net Git - openocd/commitdiff
hla: cleanup read/write api
authorSpencer Oliver <spen@spen-soft.co.uk>
Wed, 11 Sep 2013 20:31:50 +0000 (21:31 +0100)
committerSpencer Oliver <spen@spen-soft.co.uk>
Wed, 25 Sep 2013 13:53:19 +0000 (13:53 +0000)
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>
src/jtag/drivers/stlink_usb.c
src/jtag/drivers/ti_icdi_usb.c
src/jtag/hla/hla_layout.h
src/target/hla_target.c

index cccb9ffa0b2fbccd3d83d7aef9240171084aeaf5..1dfe9401de99693ef288cfeaa7508c75f097c7d7 100644 (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);
 }
 
+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,
-       /** */
-       .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
 };
index f10d12073668aaa18af54f3ff274a838785e5db8..ae2f240fc58e9053d687c7efbae839b841439dc8 100644 (file)
@@ -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
 };
index bd6a6b42ae70915661704c359fa8111967b444cf..d7b5d9353f5d77c24f962e4fa24df3a604af496a 100644 (file)
@@ -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);
        /** */
index 2db04f8111aa6e9d5ea296550ed1eaafd501d9c7..dc81ee89a6d39955808867fd3318188fe853e93d 100644 (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)
 {
        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;