summaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-08-30 17:30:14 +0000
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-08-30 17:30:14 +0000
commitd879faa3cb8200c1c31e1a52c42e9bbacb9fac40 (patch)
treef4615c0c22e50f94c61a292ce3d582132ca2d789 /src/target
parent4b9bdd664a79d5713b22a178086b071abc049d01 (diff)
downloadopenocd+libswd-d879faa3cb8200c1c31e1a52c42e9bbacb9fac40.tar.gz
openocd+libswd-d879faa3cb8200c1c31e1a52c42e9bbacb9fac40.tar.bz2
openocd+libswd-d879faa3cb8200c1c31e1a52c42e9bbacb9fac40.tar.xz
openocd+libswd-d879faa3cb8200c1c31e1a52c42e9bbacb9fac40.zip
David Brownell <david-b@pacbell.net> start phasing out integers as target IDs
git-svn-id: svn://svn.berlios.de/openocd/trunk@2650 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/target')
-rw-r--r--src/target/target.c54
-rw-r--r--src/target/target.h3
2 files changed, 22 insertions, 35 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 381e774e..b6ea6555 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -249,22 +249,6 @@ target_state_name( target_t *t )
return cp;
}
-static int max_target_number(void)
-{
- target_t *t;
- int x;
-
- x = -1;
- t = all_targets;
- while (t) {
- if (x < t->target_number) {
- x = (t->target_number) + 1;
- }
- t = t->next;
- }
- return x;
-}
-
/* determine the number of the new target */
static int new_target_number(void)
{
@@ -346,14 +330,19 @@ target_t *get_target(const char *id)
return target;
}
+ /* It's OK to remove this fallback sometime after August 2010 or so */
+
/* no match, try as number */
unsigned num;
if (parse_uint(id, &num) != ERROR_OK)
return NULL;
for (target = all_targets; target; target = target->next) {
- if (target->target_number == (int)num)
+ if (target->target_number == (int)num) {
+ LOG_WARNING("use '%s' as target identifier, not '%u'",
+ target->cmd_name, num);
return target;
+ }
}
return NULL;
@@ -374,11 +363,6 @@ static target_t *get_target_by_num(int num)
return NULL;
}
-int get_num_by_target(target_t *query_target)
-{
- return query_target->target_number;
-}
-
target_t* get_current_target(command_context_t *cmd_ctx)
{
target_t *target = get_target_by_num(cmd_ctx->current_target);
@@ -4387,6 +4371,8 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return target_create(&goi);
break;
case TG_CMD_NUMBER:
+ /* It's OK to remove this mechanism sometime after August 2010 or so */
+ LOG_WARNING("don't use numbers as target identifiers; use names");
if (goi.argc != 1) {
Jim_SetResult_sprintf(goi.interp, "expected: target number ?NUMBER?");
return JIM_ERR;
@@ -4395,23 +4381,25 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (e != JIM_OK) {
return JIM_ERR;
}
- {
- target_t *t;
- t = get_target_by_num(w);
- if (t == NULL) {
- Jim_SetResult_sprintf(goi.interp,"Target: number %d does not exist", (int)(w));
- return JIM_ERR;
- }
- Jim_SetResultString(goi.interp, t->cmd_name, -1);
- return JIM_OK;
+ for (x = 0, target = all_targets; target; target = target->next, x++) {
+ if (target->target_number == w)
+ break;
}
+ if (target == NULL) {
+ Jim_SetResult_sprintf(goi.interp,
+ "Target: number %d does not exist", (int)(w));
+ return JIM_ERR;
+ }
+ Jim_SetResultString(goi.interp, target->cmd_name, -1);
+ return JIM_OK;
case TG_CMD_COUNT:
if (goi.argc != 0) {
Jim_WrongNumArgs(goi.interp, 0, goi.argv, "<no parameters>");
return JIM_ERR;
}
- Jim_SetResult(goi.interp,
- Jim_NewIntObj(goi.interp, max_target_number()));
+ for (x = 0, target = all_targets; target; target = target->next, x++)
+ continue;
+ Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, x));
return JIM_OK;
}
diff --git a/src/target/target.h b/src/target/target.h
index 9894aca9..509bfd2a 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -120,7 +120,7 @@ typedef struct target_s
{
target_type_t *type; /* target type definition (name, access functions) */
const char *cmd_name; /* tcl Name of target */
- int target_number; /* generaly, target index but may not be in order */
+ int target_number; /* DO NOT USE! field to be removed in 2010 */
jtag_tap_t *tap; /* where on the jtag chain is this */
const char *variant; /* what varient of this chip is it? */
target_event_action_t *event_action;
@@ -250,7 +250,6 @@ extern int target_call_timer_callbacks(void);
extern int target_call_timer_callbacks_now(void);
extern target_t* get_current_target(struct command_context_s *cmd_ctx);
-extern int get_num_by_target(target_t *query_target);
extern target_t *get_target(const char *id);
/**