helper/jim-nvp: comply with coding style [2/2]
[fw/openocd] / src / target / arm_dap.c
index 3adb4ed267babe0ff5b5fc03274cfb1114deb5a3..747733dc948bb75cd34403aa0a9da326413d085f 100644 (file)
@@ -34,7 +34,7 @@ static LIST_HEAD(all_dap);
 
 extern const struct dap_ops swd_dap_ops;
 extern const struct dap_ops jtag_dp_ops;
-extern struct jtag_interface *jtag_interface;
+extern struct adapter_driver *adapter_driver;
 
 /* DAP command support */
 struct arm_dap_object {
@@ -56,9 +56,10 @@ static void dap_instance_init(struct adiv5_dap *dap)
                /* Number of bits for tar autoincrement, impl. dep. at least 10 */
                dap->ap[i].tar_autoincr_block = (1<<10);
                /* default CSW value */
-               dap->ap[i].csw_default = CSW_DEFAULT;
+               dap->ap[i].csw_default = CSW_AHB_DEFAULT;
        }
        INIT_LIST_HEAD(&dap->cmd_journal);
+       INIT_LIST_HEAD(&dap->cmd_pool);
 }
 
 const char *adiv5_dap_name(struct adiv5_dap *self)
@@ -117,7 +118,11 @@ static int dap_init_all(void)
 
                if (transport_is_swd()) {
                        dap->ops = &swd_dap_ops;
-                       obj->swd = jtag_interface->swd;
+                       obj->swd = adapter_driver->swd_ops;
+               } else if (transport_is_dapdirect_swd()) {
+                       dap->ops = adapter_driver->dap_swd_ops;
+               } else if (transport_is_dapdirect_jtag()) {
+                       dap->ops = adapter_driver->dap_jtag_ops;
                } else
                        dap->ops = &jtag_dp_ops;
 
@@ -151,31 +156,31 @@ enum dap_cfg_param {
        CFG_IGNORE_SYSPWRUPACK,
 };
 
-static const Jim_Nvp nvp_config_opts[] = {
+static const struct jim_nvp nvp_config_opts[] = {
        { .name = "-chain-position",   .value = CFG_CHAIN_POSITION },
        { .name = "-ignore-syspwrupack", .value = CFG_IGNORE_SYSPWRUPACK },
        { .name = NULL, .value = -1 }
 };
 
-static int dap_configure(Jim_GetOptInfo *goi, struct arm_dap_object *dap)
+static int dap_configure(struct jim_getopt_info *goi, struct arm_dap_object *dap)
 {
        struct jtag_tap *tap = NULL;
-       Jim_Nvp *n;
+       struct jim_nvp *n;
        int e;
 
        /* parse config or cget options ... */
        while (goi->argc > 0) {
                Jim_SetEmptyResult(goi->interp);
 
-               e = Jim_GetOpt_Nvp(goi, nvp_config_opts, &n);
+               e = jim_getopt_nvp(goi, nvp_config_opts, &n);
                if (e != JIM_OK) {
-                       Jim_GetOpt_NvpUnknown(goi, nvp_config_opts, 0);
+                       jim_getopt_nvp_unknown(goi, nvp_config_opts, 0);
                        return e;
                }
                switch (n->value) {
                case CFG_CHAIN_POSITION: {
                        Jim_Obj *o_t;
-                       e = Jim_GetOpt_Obj(goi, &o_t);
+                       e = jim_getopt_obj(goi, &o_t);
                        if (e != JIM_OK)
                                return e;
                        tap = jtag_tap_by_jim_obj(goi->interp, o_t);
@@ -205,7 +210,7 @@ static int dap_configure(Jim_GetOptInfo *goi, struct arm_dap_object *dap)
        return JIM_OK;
 }
 
-static int dap_create(Jim_GetOptInfo *goi)
+static int dap_create(struct jim_getopt_info *goi)
 {
        struct command_context *cmd_ctx;
        static struct arm_dap_object *dap;
@@ -222,7 +227,7 @@ static int dap_create(Jim_GetOptInfo *goi)
                return JIM_ERR;
        }
        /* COMMAND */
-       Jim_GetOpt_Obj(goi, &new_cmd);
+       jim_getopt_obj(goi, &new_cmd);
        /* does this command exist? */
        cmd = Jim_GetCommand(goi->interp, new_cmd, JIM_ERRMSG);
        if (cmd) {
@@ -260,23 +265,19 @@ static int dap_create(Jim_GetOptInfo *goi)
        if (transport_is_hla())
                dap_commands[0].chain = NULL;
 
-       e = register_commands(cmd_ctx, NULL, dap_commands);
+       e = register_commands_with_data(cmd_ctx, NULL, dap_commands, dap);
        if (ERROR_OK != e)
                return JIM_ERR;
 
-       struct command *c = command_find_in_context(cmd_ctx, cp);
-       assert(c);
-       command_set_handler_data(c, dap);
-
        list_add_tail(&dap->lh, &all_dap);
 
-       return (ERROR_OK == e) ? JIM_OK : JIM_ERR;
+       return JIM_OK;
 }
 
 static int jim_dap_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
-       Jim_GetOptInfo goi;
-       Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+       struct jim_getopt_info goi;
+       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
        if (goi.argc < 2) {
                Jim_WrongNumArgs(goi.interp, goi.argc, goi.argv,
                        "<name> [<dap_options> ...]");
@@ -313,6 +314,11 @@ COMMAND_HANDLER(handle_dap_info_command)
        struct adiv5_dap *dap = arm->dap;
        uint32_t apsel;
 
+       if (dap == NULL) {
+               LOG_ERROR("DAP instance not available. Probably a HLA target...");
+               return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
+       }
+
        switch (CMD_ARGC) {
                case 0:
                        apsel = dap->apsel;
@@ -326,7 +332,7 @@ COMMAND_HANDLER(handle_dap_info_command)
                        return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       return dap_info_command(CMD_CTX, &dap->ap[apsel]);
+       return dap_info_command(CMD, &dap->ap[apsel]);
 }
 
 static const struct command_registration dap_subcommand_handlers[] = {
@@ -368,6 +374,7 @@ static const struct command_registration dap_commands[] = {
                .mode = COMMAND_CONFIG,
                .help = "DAP commands",
                .chain = dap_subcommand_handlers,
+               .usage = "",
        },
        COMMAND_REGISTRATION_DONE
 };