hla: move memory read/write functionality to driver
[openocd.git] / src / jtag / drivers / ti_icdi_usb.c
index ae2f240fc58e9053d687c7efbae839b841439dc8..0d7d943bede0ed04734930860b4c3bb152d34b68 100644 (file)
@@ -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;
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)