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:
parent
b6f812f647
commit
929ede7482
@ -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)
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user