Add stderr support and remove 1us timeout for timeouts of 0us (#858)
This commit is contained in:
parent
7858601a58
commit
b3c56e7169
@ -29,6 +29,10 @@
|
|||||||
#include "pico/stdio_semihosting.h"
|
#include "pico/stdio_semihosting.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define STDIO_HANDLE_STDIN 0
|
||||||
|
#define STDIO_HANDLE_STDOUT 1
|
||||||
|
#define STDIO_HANDLE_STDERR 2
|
||||||
|
|
||||||
static stdio_driver_t *drivers;
|
static stdio_driver_t *drivers;
|
||||||
static stdio_driver_t *filter;
|
static stdio_driver_t *filter;
|
||||||
|
|
||||||
@ -131,11 +135,13 @@ static int stdio_get_until(char *buf, int len, absolute_time_t until) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (time_reached(until)) {
|
||||||
|
return PICO_ERROR_TIMEOUT;
|
||||||
|
}
|
||||||
// we sleep here in case the in_chars methods acquire mutexes or disable IRQs and
|
// 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)
|
// potentially starve out what they are waiting on (have seen this with USB)
|
||||||
busy_wait_us(1);
|
busy_wait_us(1);
|
||||||
} while (!time_reached(until));
|
} while (true);
|
||||||
return PICO_ERROR_TIMEOUT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int WRAPPER_FUNC(putchar)(int c) {
|
int WRAPPER_FUNC(putchar)(int c) {
|
||||||
@ -165,14 +171,14 @@ int puts_raw(const char *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int _read(int handle, char *buffer, int length) {
|
int _read(int handle, char *buffer, int length) {
|
||||||
if (handle == 0) {
|
if (handle == STDIO_HANDLE_STDIN) {
|
||||||
return stdio_get_until(buffer, length, at_the_end_of_time);
|
return stdio_get_until(buffer, length, at_the_end_of_time);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _write(int handle, char *buffer, int length) {
|
int _write(int handle, char *buffer, int length) {
|
||||||
if (handle == 1) {
|
if (handle == STDIO_HANDLE_STDOUT || handle == STDIO_HANDLE_STDERR) {
|
||||||
stdio_put_string(buffer, length, false, false);
|
stdio_put_string(buffer, length, false, false);
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user