target: make register flags "bool"
[fw/openocd] / src / jtag / usbprog.c
index dfde29551f2f9548e79763947c47763d11ef4e80..e8c0eadf9f87e54f4d6bb4c49b4e6ee19cf3f8bd 100644 (file)
@@ -34,7 +34,8 @@
 #include "config.h"
 #endif
 
-#include "jtag.h"
+#include "interface.h"
+#include "commands.h"
 
 #include <usb.h>
 
 #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,17 +104,12 @@ 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)
        {
@@ -149,16 +129,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:
@@ -172,8 +150,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);
@@ -239,7 +216,7 @@ 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);
@@ -251,7 +228,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;
@@ -330,7 +307,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();
 
@@ -372,14 +349,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);
 }
@@ -437,6 +414,7 @@ struct usbprog_jtag* usbprog_jtag_open(void)
                        }
                }
        }
+       free(tmp);
        return 0;
 }
 
@@ -593,7 +571,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;
                }
@@ -689,3 +667,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
+       };