Skip to content

Commit 57c0667

Browse files
committed
target: introduce active_polled flag in struct target
The spliting of examined status to two partialy independent flags resolves the dirty hack of setting examined after failed examine call in handle_target() and ambiguity in the examined flag usage. Change-Id: I16567248f81d6b096d864ef11480e6c611398494 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: https://review.openocd.org/c/openocd/+/9180 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
1 parent 8395453 commit 57c0667

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

src/target/target.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,17 @@ static int no_mmu(struct target *target, bool *enabled)
658658

659659
/**
660660
* Reset the @c examined flag for the given target.
661-
* Pure paranoia -- targets are zeroed on allocation.
662661
*/
663662
static inline void target_reset_examined(struct target *target)
664663
{
665664
target->examined = false;
666665
}
667666

667+
static inline void target_reset_active_polled(struct target *target)
668+
{
669+
target->active_polled = false;
670+
}
671+
668672
static int default_examine(struct target *target)
669673
{
670674
target_set_examined(target);
@@ -1495,6 +1499,7 @@ static int target_init_one(struct command_context *cmd_ctx,
14951499
struct target *target)
14961500
{
14971501
target_reset_examined(target);
1502+
target_reset_active_polled(target);
14981503

14991504
struct target_type *type = target->type;
15001505
if (!type->examine)
@@ -2922,7 +2927,7 @@ static int handle_target(void *priv)
29222927
is_jtag_poll_safe() && target;
29232928
target = target->next) {
29242929

2925-
if (!target_was_examined(target))
2930+
if (!target_active_polled(target))
29262931
continue;
29272932

29282933
if (!target->tap->enabled)
@@ -2955,10 +2960,7 @@ static int handle_target(void *priv)
29552960
LOG_TARGET_ERROR(target, "Polling failed, trying to reexamine");
29562961
target_reset_examined(target);
29572962
retval = target_examine_one(target);
2958-
/* Target examination could have failed due to unstable connection,
2959-
* but we set the examined flag anyway to repoll it later */
29602963
if (retval != ERROR_OK) {
2961-
target_set_examined(target);
29622964
LOG_TARGET_ERROR(target, "Examination failed, GDB will be halted. Polling again in %dms",
29632965
target->backoff.times * polling_interval);
29642966
return retval;
@@ -5349,8 +5351,10 @@ COMMAND_HANDLER(handle_target_reset)
53495351
/* do the assert */
53505352
if (n->value == NVP_ASSERT) {
53515353
int retval = target->type->assert_reset(target);
5352-
if (target->defer_examine)
5354+
if (target->defer_examine) {
53535355
target_reset_examined(target);
5356+
target_reset_active_polled(target);
5357+
}
53545358
return retval;
53555359
}
53565360

src/target/target.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,19 @@ struct target {
126126
bool defer_examine;
127127

128128
/**
129-
* Indicates whether this target has been examined.
129+
* Indicates whether this target has been examined,
130+
* remembers the last result of examine call.
130131
*
131132
* Do @b not access this field directly, use target_was_examined()
132133
* or target_set_examined().
133134
*/
134135
bool examined;
136+
/**
137+
* The flag is set after a successful examine call.
138+
* It remains set forever or in the case of defer examine
139+
* gets reset by reset command.
140+
*/
141+
bool active_polled;
135142

136143
/**
137144
* true if the target is currently running a downloaded
@@ -428,16 +435,26 @@ const char *target_type_name(const struct target *target);
428435
*/
429436
int target_examine_one(struct target *target);
430437

431-
/** @returns @c true if target_set_examined() has been called. */
438+
/** @returns @c true if target_set_examined() has been called.
439+
* The returned value reflects the last examination result. */
432440
static inline bool target_was_examined(const struct target *target)
433441
{
434442
return target->examined;
435443
}
436444

437-
/** Sets the @c examined flag for the given target. */
445+
/** @returns @c true if target_set_examined() has been called.
446+
* The flag remains set forever or in the case of defer examine
447+
* gets reset by reset command */
448+
static inline bool target_active_polled(const struct target *target)
449+
{
450+
return target->active_polled;
451+
}
452+
453+
/** Sets the @c examined and @c active_polled flags for the given target. */
438454
/** Use in target->type->examine() after one-time setup is done. */
439455
static inline void target_set_examined(struct target *target)
440456
{
457+
target->active_polled = true;
441458
target->examined = true;
442459
}
443460

0 commit comments

Comments
 (0)