X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=7e3975695404dfc5cb5e3b7587fb29010abe5639;hp=41fab1e623962eeab5dc44cb2c0328db44c4604f;hb=80b80ef9b43acd56358587724218131456049c59;hpb=6c467da586a42c8b1332670f2d5f27ae360a153f diff --git a/src/target/target.c b/src/target/target.c index 41fab1e623..7e39756954 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -379,9 +379,9 @@ struct target *get_target(const char *id) /* try as tcltarget name */ for (target = all_targets; target; target = target->next) { - if (target->cmd_name == NULL) + if (target_name(target) == NULL) continue; - if (strcmp(id, target->cmd_name) == 0) + if (strcmp(id, target_name(target)) == 0) return target; } @@ -395,7 +395,7 @@ struct target *get_target(const char *id) for (target = all_targets; target; target = target->next) { if (target->target_number == (int)num) { LOG_WARNING("use '%s' as target identifier, not '%u'", - target->cmd_name, num); + target_name(target), num); return target; } } @@ -677,18 +677,18 @@ static int target_read_memory_imp(struct target *target, uint32_t address, return target->type->read_memory_imp(target, address, size, count, buffer); } -static int target_soft_reset_halt_imp(struct target *target) +static int target_soft_reset_halt(struct target *target) { if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); return ERROR_FAIL; } - if (!target->type->soft_reset_halt_imp) { + if (!target->type->soft_reset_halt) { LOG_ERROR("Target %s does not support soft_reset_halt", target_name(target)); return ERROR_FAIL; } - return target->type->soft_reset_halt_imp(target); + return target->type->soft_reset_halt(target); } /** @@ -982,7 +982,7 @@ int target_add_breakpoint(struct target *target, struct breakpoint *breakpoint) { if ((target->state != TARGET_HALTED) && (breakpoint->type != BKPT_HARD)) { - LOG_WARNING("target %s is not halted", target->cmd_name); + LOG_WARNING("target %s is not halted", target_name(target)); return ERROR_TARGET_NOT_HALTED; } return target->type->add_breakpoint(target, breakpoint); @@ -992,7 +992,7 @@ int target_add_context_breakpoint(struct target *target, struct breakpoint *breakpoint) { if (target->state != TARGET_HALTED) { - LOG_WARNING("target %s is not halted", target->cmd_name); + LOG_WARNING("target %s is not halted", target_name(target)); return ERROR_TARGET_NOT_HALTED; } return target->type->add_context_breakpoint(target, breakpoint); @@ -1002,7 +1002,7 @@ int target_add_hybrid_breakpoint(struct target *target, struct breakpoint *breakpoint) { if (target->state != TARGET_HALTED) { - LOG_WARNING("target %s is not halted", target->cmd_name); + LOG_WARNING("target %s is not halted", target_name(target)); return ERROR_TARGET_NOT_HALTED; } return target->type->add_hybrid_breakpoint(target, breakpoint); @@ -1018,7 +1018,7 @@ int target_add_watchpoint(struct target *target, struct watchpoint *watchpoint) { if (target->state != TARGET_HALTED) { - LOG_WARNING("target %s is not halted", target->cmd_name); + LOG_WARNING("target %s is not halted", target_name(target)); return ERROR_TARGET_NOT_HALTED; } return target->type->add_watchpoint(target, watchpoint); @@ -1099,9 +1099,6 @@ static int target_init_one(struct command_context *cmd_ctx, type->read_memory_imp = target->type->read_memory; type->read_memory = target_read_memory_imp; - type->soft_reset_halt_imp = target->type->soft_reset_halt; - type->soft_reset_halt = target_soft_reset_halt_imp; - /* Sanity-check MMU support ... stub in what we must, to help * implement it in stages, but warn if we need to do so. */ @@ -2164,9 +2161,6 @@ static int sense_handler(void) return ERROR_OK; } -static int backoff_times; -static int backoff_count; - /* process target state changes */ static int handle_target(void *priv) { @@ -2222,13 +2216,6 @@ static int handle_target(void *priv) recursive = 0; } - if (backoff_times > backoff_count) { - /* do not poll this time as we failed previously */ - backoff_count++; - return ERROR_OK; - } - backoff_count = 0; - /* Poll targets for state changes unless that's globally disabled. * Skip targets that are currently disabled. */ @@ -2238,18 +2225,26 @@ static int handle_target(void *priv) if (!target->tap->enabled) continue; + if (target->backoff.times > target->backoff.count) { + /* do not poll this time as we failed previously */ + target->backoff.count++; + continue; + } + target->backoff.count = 0; + /* only poll target if we've got power and srst isn't asserted */ if (!powerDropout && !srstAsserted) { /* polling may fail silently until the target has been examined */ retval = target_poll(target); if (retval != ERROR_OK) { /* 100ms polling interval. Increase interval between polling up to 5000ms */ - if (backoff_times * polling_interval < 5000) { - backoff_times *= 2; - backoff_times++; + if (target->backoff.times * polling_interval < 5000) { + target->backoff.times *= 2; + target->backoff.times++; } - LOG_USER("Polling target failed, GDB will be halted. Polling again in %dms", - backoff_times * polling_interval); + LOG_USER("Polling target %s failed, GDB will be halted. Polling again in %dms", + target_name(target), + target->backoff.times * polling_interval); /* Tell GDB to halt the debugger. This allows the user to * run monitor commands to handle the situation. @@ -2258,9 +2253,9 @@ static int handle_target(void *priv) return retval; } /* Since we succeeded, we reset backoff count */ - if (backoff_times > 0) - LOG_USER("Polling succeeded again"); - backoff_times = 0; + if (target->backoff.times > 0) + LOG_USER("Polling target %s succeeded again", target_name(target)); + target->backoff.times = 0; } } @@ -2500,7 +2495,7 @@ COMMAND_HANDLER(handle_soft_reset_halt_command) LOG_USER("requesting target halt and executing a soft reset"); - target->type->soft_reset_halt(target); + target_soft_reset_halt(target); return ERROR_OK; } @@ -5073,7 +5068,7 @@ static int jim_target_current(Jim_Interp *interp, int argc, Jim_Obj *const *argv struct command_context *cmd_ctx = current_command_context(interp); assert(cmd_ctx != NULL); - Jim_SetResultString(interp, get_current_target(cmd_ctx)->cmd_name, -1); + Jim_SetResultString(interp, target_name(get_current_target(cmd_ctx)), -1); return JIM_OK; }