use COMMAND_HANDLER macro to define all commands
[fw/openocd] / src / jtag / amt_jtagaccel.c
index c059d920628cdb81d60425dfecc545fb4e5b5cdd..a34387f8b43df0db78ea98dfc676cbe3e6da010e 100644 (file)
@@ -72,15 +72,6 @@ static int data_mode = IEEE1284_MODE_EPP | IEEE1284_DATA ;
 
 #endif // PARPORT_USE_PPDEV
 
-static int amt_jtagaccel_execute_queue(void);
-static int amt_jtagaccel_register_commands(struct command_context_s *cmd_ctx);
-static int amt_jtagaccel_speed(int speed);
-static int amt_jtagaccel_init(void);
-static int amt_jtagaccel_quit(void);
-
-static int amt_jtagaccel_handle_parport_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-static int amt_jtagaccel_handle_rtck_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-
 /* tap_move[i][j]: tap movement command to go from state i to state j
  * 0: Test-Logic-Reset
  * 1: Run-Test/Idle
@@ -92,8 +83,8 @@ static int amt_jtagaccel_handle_rtck_command(struct command_context_s *cmd_ctx,
 static uint8_t amt_jtagaccel_tap_move[6][6][2] =
 {
        /*         RESET         IDLE        DRSHIFT       DRPAUSE       IRSHIFT       IRPAUSE             */
-       {{0x1f, 0x00}, {0x0f, 0x00}, {0x8a, 0x04}, {0x0a, 0x00}, {0x06, 0x00}, {0x96, 0x00}},   /* RESET */
-       {{0x1f, 0x00}, {0x00, 0x00}, {0x85, 0x08}, {0x05, 0x00}, {0x8b, 0x08}, {0x0b, 0x00}},   /* IDLE */
+       {{0x1f, 0x00}, {0x0f, 0x00}, {0x05, 0x00}, {0x0a, 0x00}, {0x06, 0x00}, {0x96, 0x00}},   /* RESET */
+       {{0x1f, 0x00}, {0x00, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x0b, 0x00}},   /* IDLE */
        {{0x1f, 0x00}, {0x0d, 0x00}, {0x00, 0x00}, {0x01, 0x00}, {0x8f, 0x09}, {0x8f, 0x01}},   /* DRSHIFT  */
        {{0x1f, 0x00}, {0x0c, 0x00}, {0x08, 0x00}, {0x00, 0x00}, {0x8f, 0x09}, {0x8f, 0x01}},   /* DRPAUSE  */
        {{0x1f, 0x00}, {0x0d, 0x00}, {0x07, 0x00}, {0x97, 0x00}, {0x00, 0x00}, {0x01, 0x00}},   /* IRSHIFT  */
@@ -101,28 +92,6 @@ static uint8_t amt_jtagaccel_tap_move[6][6][2] =
 };
 
 
-jtag_interface_t amt_jtagaccel_interface =
-{
-       .name = "amt_jtagaccel",
-
-       .execute_queue = amt_jtagaccel_execute_queue,
-
-       .speed = amt_jtagaccel_speed,
-       .register_commands = amt_jtagaccel_register_commands,
-       .init = amt_jtagaccel_init,
-       .quit = amt_jtagaccel_quit,
-};
-
-static int amt_jtagaccel_register_commands(struct command_context_s *cmd_ctx)
-{
-       register_command(cmd_ctx, NULL, "parport_port", amt_jtagaccel_handle_parport_port_command,
-                                        COMMAND_CONFIG, NULL);
-       register_command(cmd_ctx, NULL, "rtck", amt_jtagaccel_handle_rtck_command,
-                                        COMMAND_CONFIG, NULL);
-
-       return ERROR_OK;
-}
-
 static void amt_jtagaccel_reset(int trst, int srst)
 {
        if (trst == 1)
@@ -374,7 +343,7 @@ static int amt_jtagaccel_execute_queue(void)
                                break;
                        case JTAG_SLEEP:
 #ifdef _DEBUG_JTAG_IO_
-                               LOG_DEBUG("sleep %i", cmd->cmd.sleep->us);
+                               LOG_DEBUG("sleep %" PRIi32, cmd->cmd.sleep->us);
 #endif
                                jtag_sleep(cmd->cmd.sleep->us);
                                break;
@@ -395,20 +364,20 @@ int amt_jtagaccel_get_giveio_access(void)
        OSVERSIONINFO version;
 
        version.dwOSVersionInfoSize = sizeof version;
-       if (!GetVersionEx( &version )) {
+       if (!GetVersionEx(&version)) {
        errno = EINVAL;
        return -1;
        }
        if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
        return 0;
 
-       h = CreateFile( "\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
+       h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (h == INVALID_HANDLE_VALUE) {
        errno = ENODEV;
        return -1;
        }
 
-       CloseHandle( h );
+       CloseHandle(h);
 
        return 0;
 }
@@ -526,17 +495,16 @@ static int amt_jtagaccel_quit(void)
        return ERROR_OK;
 }
 
-static int amt_jtagaccel_handle_parport_port_command(
-               struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command)
 {
        if (argc == 1)
        {
                /* only if the port wasn't overwritten by cmdline */
                if (amt_jtagaccel_port == 0)
                {
-                       int retval = parse_u16(args[0], &amt_jtagaccel_port);
-                       if (ERROR_OK != retval)
-                               return retval;
+                       uint16_t port;
+                       COMMAND_PARSE_NUMBER(u16, args[0], port);
+                       amt_jtagaccel_port = port;
                }
                else
                {
@@ -550,7 +518,7 @@ static int amt_jtagaccel_handle_parport_port_command(
        return ERROR_OK;
 }
 
-static int amt_jtagaccel_handle_rtck_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command)
 {
        if (argc == 0)
        {
@@ -571,3 +539,24 @@ static int amt_jtagaccel_handle_rtck_command(struct command_context_s *cmd_ctx,
 
        return ERROR_OK;
 }
+
+static int amt_jtagaccel_register_commands(struct command_context_s *cmd_ctx)
+{
+       register_command(cmd_ctx, NULL, "parport_port",
+                       amt_jtagaccel_handle_parport_port_command, COMMAND_CONFIG,
+                       NULL);
+       register_command(cmd_ctx, NULL, "rtck",
+                       amt_jtagaccel_handle_rtck_command, COMMAND_CONFIG,
+                       NULL);
+
+       return ERROR_OK;
+}
+
+jtag_interface_t amt_jtagaccel_interface = {
+               .name = "amt_jtagaccel",
+               .register_commands = &amt_jtagaccel_register_commands,
+               .init = &amt_jtagaccel_init,
+               .quit = &amt_jtagaccel_quit,
+               .speed = &amt_jtagaccel_speed,
+               .execute_queue = &amt_jtagaccel_execute_queue,
+       };