presto: use register_commands()
[openocd.git] / src / jtag / rlink / rlink.c
index 8f2f26fe65d8d9d0edc752b332bab90a567332f1..6fb721d5e4f6d257b2982fd979ae6ba1ee624871 100644 (file)
@@ -34,9 +34,7 @@
 #include "st7.h"
 #include "ep1_cmd.h"
 #include "dtc_cmd.h"
-
-/* system includes */
-#include <usb.h>
+#include "usb_common.h"
 
 
 /* This feature is made useless by running the DTC all the time.  When automatic, the LED is on whenever the DTC is running.  Otherwise, USB messages are sent to turn it on and off. */
@@ -577,8 +575,8 @@ dtc_run_download(
  */
 
 struct dtc_reply_queue_entry {
-       struct dtc_reply_queue_entry_s  *next;
-       jtag_command_t  *cmd;   /* the command that resulted in this entry */
+       struct dtc_reply_queue_entry    *next;
+       struct jtag_command     *cmd;   /* the command that resulted in this entry */
 
        struct {
                uint8_t         *buffer;        /* the scan buffer */
@@ -637,7 +635,7 @@ dtc_queue_enqueue_reply(
        int                             size,
        int                             offset,
        int                             length,
-       jtag_command_t  *cmd
+       struct jtag_command     *cmd
 ) {
        struct dtc_reply_queue_entry    *rq_entry;
 
@@ -1090,7 +1088,7 @@ void rlink_reset(int trst, int srst)
 static
 int
 rlink_scan(
-       jtag_command_t  *cmd,
+       struct jtag_command     *cmd,
        enum scan_type  type,
        uint8_t                 *buffer,
        int                     scan_size
@@ -1378,7 +1376,7 @@ rlink_scan(
 static
 int rlink_execute_queue(void)
 {
-       jtag_command_t *cmd = jtag_command_queue; /* currently processed command */
+       struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
        int scan_size;
        enum scan_type type;
        uint8_t *buffer;
@@ -1616,104 +1614,72 @@ int rlink_register_commands(struct command_context *cmd_ctx)
 static
 int rlink_init(void)
 {
-       struct usb_bus *busses;
-       struct usb_bus *bus;
        int i, j, retries;
-       int found = 0;
-       int success = 0;
        uint8_t reply_buffer[USB_EP1IN_SIZE];
 
        usb_init();
-       usb_find_busses();
-       usb_find_devices();
-
-       busses = usb_get_busses();
+       const uint16_t vids[] = { USB_IDVENDOR, 0 };
+       const uint16_t pids[] = { USB_IDPRODUCT, 0 };
+       if (jtag_usb_open(vids, pids, &pHDev) != ERROR_OK)
+               return ERROR_FAIL;
 
-       for (bus = busses; bus; bus = bus->next)
+       struct usb_device *dev = usb_device(pHDev);
+       if (dev->descriptor.bNumConfigurations > 1)
+       {
+               LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n");
+               return ERROR_FAIL;
+       }
+       if (dev->config->bNumInterfaces > 1)
        {
-               struct usb_device *dev;
+               LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n");
+               return ERROR_FAIL;
+       }
 
-               for (dev = bus->devices; dev; dev = dev->next)
-               {
-                       if ((dev->descriptor.idVendor == USB_IDVENDOR) && (dev->descriptor.idProduct == USB_IDPRODUCT))
-                       {
-                               found = 1;
-                               LOG_DEBUG("Found device on bus.\n");
+       LOG_DEBUG("Opened device, pHDev = %p\n", pHDev);
 
-                               do
-                               {
-                                       if (dev->descriptor.bNumConfigurations > 1)
-                                       {
-                                               LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n");
-                                               break;
-                                       }
-                                       if (dev->config->bNumInterfaces > 1)
-                                       {
-                                               LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n");
-                                               break;
-                                       }
+       /* usb_set_configuration required under win32 */
+       usb_set_configuration(pHDev, dev->config[0].bConfigurationValue);
 
-                                       pHDev = usb_open(dev);
-                                       if (!pHDev)
-                                               LOG_ERROR ("Failed to open device.\n");
-                                       else
-                                       {
-                                               LOG_DEBUG("Opened device, pHDev = %p\n",pHDev);
-
-                                               /* usb_set_configuration required under win32 */
-                                               usb_set_configuration(pHDev, dev->config[0].bConfigurationValue);
-
-                                               retries = 3;
-                                               do
-                                               {
-                                                       i = usb_claim_interface(pHDev,0);
-                                                       if (i)
-                                                       {
-                                                               LOG_ERROR("usb_claim_interface: %s", usb_strerror());
+       retries = 3;
+       do
+       {
+               i = usb_claim_interface(pHDev,0);
+               if (i)
+               {
+                       LOG_ERROR("usb_claim_interface: %s", usb_strerror());
 #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
-                                                               j = usb_detach_kernel_driver_np(pHDev, 0);
-                                                               if (j)
-                                                                       LOG_ERROR("detach kernel driver: %s", usb_strerror());
+                       j = usb_detach_kernel_driver_np(pHDev, 0);
+                       if (j)
+                               LOG_ERROR("detach kernel driver: %s", usb_strerror());
 #endif
-                                                       }
-                                                       else
-                                                       {
-                                                               LOG_DEBUG("interface claimed!\n");
-                                                               break;
-                                                       }
-                                               } while (--retries);
-
-                                               if (!i)
-                                               {
-                                                       if (usb_set_altinterface(pHDev,0))
-                                                       {
-                                                               LOG_ERROR("Failed to set interface.\n");
-                                                               break;
-                                                       }
-                                                       else
-                                                               success = 1;
-                                               }
-                                       }
-                               } while (0);
-                       }
                }
-       }
+               else
+               {
+                       LOG_DEBUG("interface claimed!\n");
+                       break;
+               }
+       } while (--retries);
 
-       if (!found)
+       if (i)
        {
-               LOG_ERROR("No device found on bus.\n");
-               exit(1);
+               LOG_ERROR("Initialisation failed.");
+               return ERROR_FAIL;
        }
-
-       if (!success)
+       if (usb_set_altinterface(pHDev,0) != 0)
        {
-               LOG_ERROR("Initialisation failed.");
-               exit(1);
+               LOG_ERROR("Failed to set interface.\n");
+               return ERROR_FAIL;
        }
 
-
-       /* The device starts out in an unknown state on open.  As such, result reads time out, and it's not even known whether the command was accepted.  So, for this first command, we issue it repeatedly until its response doesn't time out.  Also, if sending a command is going to time out, we'll find that out here. */
-       /* It must be possible to open the device in such a way that this special magic isn't needed, but, so far, it escapes us. */
+       /* The device starts out in an unknown state on open.  As such,
+        * result reads time out, and it's not even known whether the
+        * command was accepted.  So, for this first command, we issue
+        * it repeatedly until its response doesn't time out.  Also, if
+        * sending a command is going to time out, we find that out here.
+        *
+        * It must be possible to open the device in such a way that
+        * this special magic isn't needed, but, so far, it escapes us.
+        */
        for (i = 0; i < 5; i++) {
                j = ep1_generic_commandl(
                        pHDev, 1,

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)