Skip to content

Commit b032eb1

Browse files
committed
Use a wall clock timeout to complete reset.
1 parent f0f1df1 commit b032eb1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/target/riscv/riscv-013.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ typedef enum slot {
121121

122122
/*** Info about the core being debugged. ***/
123123

124-
#define WALL_CLOCK_TIMEOUT 2
124+
#define WALL_CLOCK_TIMEOUT 2
125+
#define WALL_CLOCK_RESET_TIMEOUT 30
125126

126127
struct trigger {
127128
uint64_t address;
@@ -1882,14 +1883,17 @@ void riscv013_reset_current_hart(struct target *target)
18821883
control = set_field(control, DMI_DMCONTROL_NDMRESET, 0);
18831884
dmi_write(target, DMI_DMCONTROL, control);
18841885

1885-
for (unsigned i = 0; i < 256; i++) {
1886+
time_t start = time(NULL);
1887+
1888+
while (1) {
18861889
uint32_t dmstatus = dmi_read(target, DMI_DMSTATUS);
18871890
if (get_field(dmstatus, DMI_DMSTATUS_ALLHALTED)) {
18881891
break;
18891892
}
1890-
if (i == 255) {
1891-
LOG_ERROR("Hart didn't halt coming out of reset; dmstatus=0x%x",
1892-
dmstatus);
1893+
if (time(NULL) - start > WALL_CLOCK_RESET_TIMEOUT) {
1894+
LOG_ERROR("Hart didn't halt coming out of reset in %ds; "
1895+
"dmstatus=0x%x", WALL_CLOCK_RESET_TIMEOUT, dmstatus);
1896+
return;
18931897
}
18941898
}
18951899

0 commit comments

Comments
 (0)