move nand drivers to src/flash/nand/
[openocd.git] / src / jtag / usbprog.c
index 7e4b9986ebcb37a1308dcef9a770c024687bfbe2..204d0e2e9f5430e1fe69c7fdb12f79bc120f9db6 100644 (file)
@@ -34,9 +34,9 @@
 #include "config.h"
 #endif
 
-#include "jtag.h"
-
-#include <usb.h>
+#include "interface.h"
+#include "commands.h"
+#include "usb_common.h"
 
 
 #define VID 0x1781
 #define TCK_BIT                        2
 #define TMS_BIT                        1
 
-static int usbprog_execute_queue(void);
-static int usbprog_speed(int speed);
-static int usbprog_register_commands(struct command_context_s *cmd_ctx);
-static int usbprog_init(void);
-static int usbprog_quit(void);
-
 static void usbprog_end_state(tap_state_t state);
 static void usbprog_state_move(void);
-static void usbprog_path_move(pathmove_command_t *cmd);
+static void usbprog_path_move(struct pathmove_command *cmd);
 static void usbprog_runtest(int num_cycles);
-static void usbprog_scan(bool ir_scan, enum scan_type type, u8 *buffer, int scan_size);
-
-jtag_interface_t usbprog_interface =
-{
-       .name = "usbprog",
-       .execute_queue = usbprog_execute_queue,
-       .speed = usbprog_speed,
-       .register_commands = usbprog_register_commands,
-       .init = usbprog_init,
-       .quit = usbprog_quit
-};
+static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size);
 
 #define UNKOWN_COMMAND 0x00
 #define PORT_DIRECTION 0x01
@@ -119,29 +103,17 @@ static int usbprog_speed(int speed)
        return ERROR_OK;
 }
 
-static int usbprog_register_commands(struct command_context_s *cmd_ctx)
-{
-       return ERROR_OK;
-}
-
 static int usbprog_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;
-       u8 *buffer;
+       uint8_t *buffer;
 
        while (cmd)
        {
                switch (cmd->type)
                {
-                       case JTAG_END_STATE:
-#ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("end_state: %i", cmd->cmd.end_state->end_state);
-#endif
-                               if (cmd->cmd.end_state->end_state != TAP_INVALID)
-                                       usbprog_end_state(cmd->cmd.end_state->end_state);
-                               break;
                        case JTAG_RESET:
 #ifdef _DEBUG_JTAG_IO_
                                LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
@@ -156,16 +128,14 @@ static int usbprog_execute_queue(void)
 #ifdef _DEBUG_JTAG_IO_
                                LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
 #endif
-                               if (cmd->cmd.runtest->end_state != TAP_INVALID)
-                                       usbprog_end_state(cmd->cmd.runtest->end_state);
+                               usbprog_end_state(cmd->cmd.runtest->end_state);
                                usbprog_runtest(cmd->cmd.runtest->num_cycles);
                                break;
                        case JTAG_STATEMOVE:
 #ifdef _DEBUG_JTAG_IO_
                                LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state);
 #endif
-                               if (cmd->cmd.statemove->end_state != TAP_INVALID)
-                                       usbprog_end_state(cmd->cmd.statemove->end_state);
+                               usbprog_end_state(cmd->cmd.statemove->end_state);
                                usbprog_state_move();
                                break;
                        case JTAG_PATHMOVE:
@@ -179,8 +149,7 @@ static int usbprog_execute_queue(void)
 #ifdef _DEBUG_JTAG_IO_
                                LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state);
 #endif
-                               if (cmd->cmd.scan->end_state != TAP_INVALID)
-                                       usbprog_end_state(cmd->cmd.scan->end_state);
+                               usbprog_end_state(cmd->cmd.scan->end_state);
                                scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
                                type = jtag_scan_type(cmd->cmd.scan);
                                usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
@@ -246,10 +215,11 @@ static void usbprog_end_state(tap_state_t state)
 static void usbprog_state_move(void)
 {
        int i = 0, tms = 0;
-       u8 tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+       uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+       int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
 
        usbprog_jtag_write_tms(usbprog_jtag_handle, (char)tms_scan);
-       for (i = 0; i < 7; i++)
+       for (i = 0; i < tms_count; i++)
        {
                tms = (tms_scan >> i) & 1;
        }
@@ -257,7 +227,7 @@ static void usbprog_state_move(void)
        tap_set_state(tap_get_end_state());
 }
 
-static void usbprog_path_move(pathmove_command_t *cmd)
+static void usbprog_path_move(struct pathmove_command *cmd)
 {
        int num_states = cmd->num_states;
        int state_count;
@@ -336,7 +306,7 @@ static void usbprog_runtest(int num_cycles)
        */
 }
 
-static void usbprog_scan(bool ir_scan, enum scan_type type, u8 *buffer, int scan_size)
+static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
 {
        tap_state_t saved_end_state = tap_get_end_state();
 
@@ -378,14 +348,14 @@ static void usbprog_scan(bool ir_scan, enum scan_type type, u8 *buffer, int scan
 
 static void usbprog_write(int tck, int tms, int tdi)
 {
-       unsigned char output_value=0x00;
+       unsigned char output_value = 0x00;
 
        if (tms)
-               output_value |= (1<<TMS_BIT);
+               output_value |= (1 << TMS_BIT);
        if (tdi)
-               output_value |= (1<<TDI_BIT);
+               output_value |= (1 << TDI_BIT);
        if (tck)
-               output_value |= (1<<TCK_BIT);
+               output_value |= (1 << TCK_BIT);
 
        usbprog_jtag_write_slice(usbprog_jtag_handle,output_value);
 }
@@ -412,38 +382,23 @@ struct usb_bus *busses;
 
 struct usbprog_jtag* usbprog_jtag_open(void)
 {
-       struct usb_bus *bus;
-       struct usb_device *dev;
-
-       struct usbprog_jtag *tmp;
-
-       tmp = (struct usbprog_jtag*)malloc(sizeof(struct usbprog_jtag));
-
        usb_set_debug(10);
        usb_init();
-       usb_find_busses();
-       usb_find_devices();
 
-       busses = usb_get_busses();
+       const uint16_t vids[] = { VID, 0 };
+       const uint16_t pids[] = { PID, 0 };
+       struct usb_dev_handle *dev;
+       if (jtag_usb_open(vids, pids, &dev) != ERROR_OK)
+               return NULL;
 
-       /* find usbprog_jtag device in usb bus */
+       struct usbprog_jtag *tmp = malloc(sizeof(struct usbprog_jtag));
+       tmp->usb_handle = dev;
 
-       for (bus = busses; bus; bus = bus->next)
-       {
-               for (dev = bus->devices; dev; dev = dev->next)
-               {
-                       /* condition for sucessfully hit (too bad, I only check the vendor id)*/
-                       if (dev->descriptor.idVendor == VID && dev->descriptor.idProduct == PID)
-                       {
-                               tmp->usb_handle = usb_open(dev);
-                               usb_set_configuration(tmp->usb_handle, 1);
-                               usb_claim_interface(tmp->usb_handle, 0);
-                               usb_set_altinterface(tmp->usb_handle, 0);
-                               return tmp;
-                       }
-               }
-       }
-       return 0;
+       usb_set_configuration(dev, 1);
+       usb_claim_interface(dev, 0);
+       usb_set_altinterface(dev, 0);
+
+       return tmp;
 }
 
 #if 0
@@ -599,7 +554,7 @@ static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char * buf
                {
                        send_bits = size;
                        loops = size/8;
-                       /* if(loops==0) */
+                       /* if (loops == 0) */
                        loops++;
                        size = 0;
                }
@@ -695,3 +650,11 @@ static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag)
                tms_chain_index = 0;
        }
 }
+
+struct jtag_interface usbprog_interface = {
+               .name = "usbprog",
+               .execute_queue = &usbprog_execute_queue,
+               .speed = &usbprog_speed,
+               .init = &usbprog_init,
+               .quit = &usbprog_quit
+       };

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)