add small delay to stdio_get_until to prevent starvation of USB IRQ handler due to in use mutex. build was non deterministic due to missing link wrapping of getchar (#364)

This commit is contained in:
Graham Sanderson 2021-05-04 08:01:34 -05:00 committed by GitHub
parent b6f812f647
commit 929ede7482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -11,6 +11,7 @@ if (NOT TARGET pico_stdio)
pico_wrap_function(pico_stdio vprintf)
pico_wrap_function(pico_stdio puts)
pico_wrap_function(pico_stdio putchar)
pico_wrap_function(pico_stdio getchar)
if (TARGET pico_printf)
target_link_libraries(pico_stdio INTERFACE pico_printf)

View File

@ -123,7 +123,9 @@ static int stdio_get_until(char *buf, int len, absolute_time_t until) {
}
}
}
// todo maybe a little sleep here?
// we sleep here in case the in_chars methods acquire mutexes or disable IRQs and
// potentially starve out what they are waiting on (have seen this with USB)
busy_wait_us(1);
} while (!time_reached(until));
return PICO_ERROR_TIMEOUT;
}
@ -257,9 +259,9 @@ void stdio_init_all() {
int WRAPPER_FUNC(getchar)(void) {
char buf[1];
if (0 == stdio_get_until(buf, sizeof(buf), at_the_end_of_time)) {
return PICO_ERROR_TIMEOUT;
}
int len = stdio_get_until(buf, 1, at_the_end_of_time);
if (len < 0) return len;
assert(len == 1);
return (uint8_t)buf[0];
}