JLink: added jlink_usb_io() function
authorAlexander Osipenko <sipych@gmail.com>
Mon, 28 May 2012 13:22:35 +0000 (17:22 +0400)
committerSpencer Oliver <spen@spen-soft.co.uk>
Tue, 26 Jun 2012 10:10:06 +0000 (10:10 +0000)
jlink_usb_io() function added for basic communication,
since jlink_usb_message() is more specific to JTAG transactions.

To verify the patch issue "jlink config" command.

Change-Id: Id7d10bd5e8985d4c77f2e0ca47fb6033db2877bf
Signed-off-by: Alexander Osipenko <sipych@gmail.com>
Reviewed-on: http://openocd.zylin.com/679
Tested-by: jenkins
Reviewed-by: Xiaofan <xiaofanc@gmail.com>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/jtag/drivers/jlink.c

index 08df63bca7d7db3cf9dfebd31af096bd007c793b..5dd09bc13c9feff342fabd7e982bf6f6b1918531 100644 (file)
@@ -205,6 +205,7 @@ struct jlink {
 static struct jlink *jlink_usb_open(void);
 static void jlink_usb_close(struct jlink *jlink);
 static int jlink_usb_message(struct jlink *jlink, int out_length, int in_length);
+static int jlink_usb_io(struct jlink *jlink, int out_length, int in_length);
 static int jlink_usb_write(struct jlink *jlink, int out_length);
 static int jlink_usb_read(struct jlink *jlink, int expected_size);
 static int jlink_usb_read_emu_result(struct jlink *jlink);
@@ -701,22 +702,15 @@ static int jlink_get_config(struct jlink_config *cfg)
        int result;
        int size = sizeof(struct jlink_config);
 
-       jlink_simple_command(EMU_CMD_READ_CONFIG);
+       usb_out_buffer[0] = EMU_CMD_READ_CONFIG;
+       result = jlink_usb_io(jlink_handle, 1, size);
 
-       result = jlink_usb_read(jlink_handle, size);
-       if (size != result) {
+       if (result != ERROR_OK) {
                LOG_ERROR("jlink_usb_read failed (requested=%d, result=%d)", size, result);
                return ERROR_FAIL;
        }
 
        memcpy(cfg, usb_in_buffer, size);
-
-       /*
-        * Section 4.2.4 IN-transaction
-        * read dummy 0-byte packet
-        */
-       jlink_usb_read(jlink_handle, 1);
-
        return ERROR_OK;
 }
 
@@ -1581,6 +1575,48 @@ static int jlink_usb_read_emu_result(struct jlink *jlink)
        return result;
 }
 
+/*
+ * Send a message and receive the reply - simple messages.
+ *
+ * @param jlink pointer to driver data
+ * @param out_length data length in @c usb_out_buffer
+ * @param in_length data length to be read to @c usb_in_buffer
+ */
+static int jlink_usb_io(struct jlink *jlink, int out_length, int in_length)
+{
+       int result;
+
+       result = jlink_usb_write(jlink, out_length);
+       if (result != out_length) {
+               LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)",
+                               out_length, result);
+               return ERROR_JTAG_DEVICE_ERROR;
+       }
+
+       result = jlink_usb_read(jlink, in_length);
+       if (result != in_length) {
+               LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)",
+                               in_length, result);
+               return ERROR_JTAG_DEVICE_ERROR;
+       }
+
+       /*
+        * Section 4.2.4 IN-transaction:
+        * read dummy 0-byte packet if transaction size is
+        * multiple of 64 bytes but not max. size of 0x8000
+        */
+       if ((in_length % 64) == 0 && in_length != 0x8000) {
+               char dummy_buffer;
+               result = usb_bulk_read_ex(jlink->usb_handle, jlink_read_ep,
+                       &dummy_buffer, 1, JLINK_USB_TIMEOUT);
+               if (result != 0) {
+                       LOG_ERROR("dummy byte read failed");
+                       return ERROR_JTAG_DEVICE_ERROR;
+               }
+       }
+       return ERROR_OK;
+}
+
 #ifdef _DEBUG_USB_COMMS_
 #define BYTES_PER_LINE  16
 

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)