pld_driver_t -> struct pld_driver
[fw/openocd] / src / pld / pld.c
index 2bfb4016880a2aa5032c0faad6fe62cc6e5897ae..119d75d49234b19de7b9f7a016311e7f454edf30 100644 (file)
@@ -28,9 +28,9 @@
 
 /* pld drivers
  */
-extern pld_driver_t virtex2_pld;
+extern struct pld_driver virtex2_pld;
 
-static pld_driver_t *pld_drivers[] =
+static struct pld_driver *pld_drivers[] =
 {
        &virtex2_pld,
        NULL,
@@ -39,26 +39,6 @@ static pld_driver_t *pld_drivers[] =
 static pld_device_t *pld_devices;
 static command_t *pld_cmd;
 
-static int handle_pld_devices_command(struct command_context_s *cmd_ctx,
-               char *cmd, char **args, int argc);
-static int handle_pld_device_command(struct command_context_s *cmd_ctx,
-               char *cmd, char **args, int argc);
-static int handle_pld_load_command(struct command_context_s *cmd_ctx,
-               char *cmd, char **args, int argc);
-
-int pld_init(struct command_context_s *cmd_ctx)
-{
-       if (pld_devices)
-       {
-               register_command(cmd_ctx, pld_cmd, "devices", handle_pld_devices_command, COMMAND_EXEC,
-                                               "list configured pld devices");
-               register_command(cmd_ctx, pld_cmd, "load", handle_pld_load_command, COMMAND_EXEC,
-                                               "load configuration <file> into programmable logic device");
-       }
-
-       return ERROR_OK;
-}
-
 pld_device_t *get_pld_device_by_num(int num)
 {
        pld_device_t *p;
@@ -77,8 +57,7 @@ pld_device_t *get_pld_device_by_num(int num)
 
 /* pld device <driver> [driver_options ...]
  */
-static int handle_pld_device_command(struct command_context_s *cmd_ctx,
-               char *cmd, char **args, int argc)
+COMMAND_HANDLER(handle_pld_device_command)
 {
        int i;
        int found = 0;
@@ -106,7 +85,8 @@ static int handle_pld_device_command(struct command_context_s *cmd_ctx,
                        c->driver = pld_drivers[i];
                        c->next = NULL;
 
-                       if (pld_drivers[i]->pld_device_command(cmd_ctx, cmd, args, argc, c) != ERROR_OK)
+                       int retval = CALL_COMMAND_HANDLER(pld_drivers[i]->pld_device_command, c);
+                       if (ERROR_OK != retval)
                        {
                                LOG_ERROR("'%s' driver rejected pld device", args[0]);
                                free(c);
@@ -140,8 +120,7 @@ static int handle_pld_device_command(struct command_context_s *cmd_ctx,
        return ERROR_OK;
 }
 
-static int handle_pld_devices_command(struct command_context_s *cmd_ctx,
-               char *cmd, char **args, int argc)
+COMMAND_HANDLER(handle_pld_devices_command)
 {
        pld_device_t *p;
        int i = 0;
@@ -160,8 +139,7 @@ static int handle_pld_devices_command(struct command_context_s *cmd_ctx,
        return ERROR_OK;
 }
 
-static int handle_pld_load_command(struct command_context_s *cmd_ctx,
-               char *cmd, char **args, int argc)
+COMMAND_HANDLER(handle_pld_load_command)
 {
        int retval;
        struct timeval start, end, duration;
@@ -206,6 +184,21 @@ static int handle_pld_load_command(struct command_context_s *cmd_ctx,
        return ERROR_OK;
 }
 
+int pld_init(struct command_context_s *cmd_ctx)
+{
+       if (!pld_devices)
+               return ERROR_OK;
+
+       register_command(cmd_ctx, pld_cmd, "devices",
+                       handle_pld_devices_command, COMMAND_EXEC,
+                       "list configured pld devices");
+       register_command(cmd_ctx, pld_cmd, "load",
+                       handle_pld_load_command, COMMAND_EXEC,
+                       "load configuration <file> into programmable logic device");
+
+       return ERROR_OK;
+}
+
 int pld_register_commands(struct command_context_s *cmd_ctx)
 {
        pld_cmd = register_command(cmd_ctx, NULL, "pld", NULL, COMMAND_ANY, "programmable logic device commands");