target: create and use target_name()
[fw/openocd] / src / target / target.c
index 4a9095a6764d8565bdbbcccf6b3ff83ee1894234..3de9f2c6a3adbea8492b6d837eb62a3b9661490f 100644 (file)
@@ -65,6 +65,7 @@ extern struct target_type cortexa8_target;
 extern struct target_type arm11_target;
 extern struct target_type mips_m4k_target;
 extern struct target_type avr_target;
+extern struct target_type testee_target;
 
 struct target_type *target_types[] =
 {
@@ -83,6 +84,7 @@ struct target_type *target_types[] =
        &arm11_target,
        &mips_m4k_target,
        &avr_target,
+       &testee_target,
        NULL,
 };
 
@@ -520,7 +522,7 @@ int target_examine(void)
        }
        return retval;
 }
-const char *target_get_name(struct target *target)
+const char *target_type_name(struct target *target)
 {
        return target->type->name;
 }
@@ -554,7 +556,7 @@ static int target_soft_reset_halt_imp(struct target *target)
        }
        if (!target->type->soft_reset_halt_imp) {
                LOG_ERROR("Target %s does not support soft_reset_halt",
-                               target->cmd_name);
+                               target_name(target));
                return ERROR_FAIL;
        }
        return target->type->soft_reset_halt_imp(target);
@@ -764,7 +766,7 @@ int target_init(struct command_context *cmd_ctx)
 
                if ((retval = target->type->init_target(cmd_ctx, target)) != ERROR_OK)
                {
-                       LOG_ERROR("target '%s' init failed", target_get_name(target));
+                       LOG_ERROR("target '%s' init failed", target_name(target));
                        return retval;
                }
 
@@ -1695,8 +1697,8 @@ DumpTargets:
                command_print(CMD_CTX, "%2d%c %-18s %-10s %-6s %-18s %s",
                                          target->target_number,
                                          marker,
-                                         target->cmd_name,
-                                         target_get_name(target),
+                                         target_name(target),
+                                         target_type_name(target),
                                          Jim_Nvp_value2name_simple(nvp_target_endian,
                                                                target->endianness)->name,
                                          target->tap->dotted_name,
@@ -3508,8 +3510,8 @@ void target_handle_event(struct target *target, enum target_event e)
                if (teap->event == e) {
                        LOG_DEBUG("target: (%d) %s (%s) event: %d (%s) action: %s",
                                           target->target_number,
-                                          target->cmd_name,
-                                          target_get_name(target),
+                                          target_name(target),
+                                          target_type_name(target),
                                           e,
                                           Jim_Nvp_value2name_simple(nvp_target_event, e)->name,
                                           Jim_GetString(teap->body, NULL));
@@ -3583,16 +3585,20 @@ static int target_configure(Jim_GetOptInfo *goi, struct target *target)
                case TCFG_TYPE:
                        /* not setable */
                        if (goi->isconfigure) {
-                               Jim_SetResult_sprintf(goi->interp, "not setable: %s", n->name);
+                               Jim_SetResult_sprintf(goi->interp,
+                                               "not settable: %s", n->name);
                                return JIM_ERR;
                        } else {
                        no_params:
                                if (goi->argc != 0) {
-                                       Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "NO PARAMS");
+                                       Jim_WrongNumArgs(goi->interp,
+                                                       goi->argc, goi->argv,
+                                                       "NO PARAMS");
                                        return JIM_ERR;
                                }
                        }
-                       Jim_SetResultString(goi->interp, target_get_name(target), -1);
+                       Jim_SetResultString(goi->interp,
+                                       target_type_name(target), -1);
                        /* loop for more */
                        break;
                case TCFG_EVENT:
@@ -4133,7 +4139,7 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                                || !target->type->deassert_reset) {
                        Jim_SetResult_sprintf(interp,
                                        "No target-specific reset for %s",
-                                       target->cmd_name);
+                                       target_name(target));
                        return JIM_ERR;
                }
                /* determine if we should halt or not. */
@@ -4177,10 +4183,9 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                e = target_wait_state(target, n->value, a);
                if (e != ERROR_OK) {
                        Jim_SetResult_sprintf(goi.interp,
-                                                                  "target: %s wait %s fails (%d) %s",
-                                                                  target->cmd_name,
-                                                                  n->name,
-                                                                  e, target_strerror_safe(e));
+                                       "target: %s wait %s fails (%d) %s",
+                                       target_name(target), n->name,
+                                       e, target_strerror_safe(e));
                        return JIM_ERR;
                } else {
                        return JIM_OK;
@@ -4192,9 +4197,10 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                {
                        struct target_event_action *teap;
                        teap = target->event_action;
-                       command_print(cmd_ctx, "Event actions for target (%d) %s\n",
-                                                  target->target_number,
-                                                  target->cmd_name);
+                       command_print(cmd_ctx,
+                                       "Event actions for target (%d) %s\n",
+                                       target->target_number,
+                                       target_name(target));
                        command_print(cmd_ctx, "%-25s | Body", "Event");
                        command_print(cmd_ctx, "------------------------- | ----------------------------------------");
                        while (teap) {
@@ -4444,7 +4450,9 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                        Jim_WrongNumArgs(goi.interp, 1, goi.argv, "Too many parameters");
                        return JIM_ERR;
                }
-               Jim_SetResultString(goi.interp, get_current_target(cmd_ctx)->cmd_name, -1);
+               Jim_SetResultString(goi.interp,
+                               target_name(get_current_target(cmd_ctx)),
+                               -1);
                return JIM_OK;
        case TG_CMD_TYPES:
                if (goi.argc != 0) {
@@ -4467,8 +4475,9 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                target = all_targets;
                while (target) {
                        Jim_ListAppendElement(goi.interp,
-                                                                  Jim_GetResult(goi.interp),
-                                                                  Jim_NewStringObj(goi.interp, target->cmd_name, -1));
+                                       Jim_GetResult(goi.interp),
+                                       Jim_NewStringObj(goi.interp,
+                                               target_name(target), -1));
                        target = target->next;
                }
                return JIM_OK;
@@ -4499,7 +4508,7 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                                        "Target: number %d does not exist", (int)(w));
                        return JIM_ERR;
                }
-               Jim_SetResultString(goi.interp, target->cmd_name, -1);
+               Jim_SetResultString(goi.interp, target_name(target), -1);
                return JIM_OK;
        case TG_CMD_COUNT:
                if (goi.argc != 0) {