|
29 | 29 | #include "pico/stdio_semihosting.h"
|
30 | 30 | #endif
|
31 | 31 |
|
| 32 | +#define STDIO_HANDLE_STDIN 0 |
| 33 | +#define STDIO_HANDLE_STDOUT 1 |
| 34 | +#define STDIO_HANDLE_STDERR 2 |
| 35 | + |
32 | 36 | static stdio_driver_t *drivers;
|
33 | 37 | static stdio_driver_t *filter;
|
34 | 38 |
|
@@ -131,11 +135,13 @@ static int stdio_get_until(char *buf, int len, absolute_time_t until) {
|
131 | 135 | }
|
132 | 136 | }
|
133 | 137 | }
|
| 138 | + if (time_reached(until)) { |
| 139 | + return PICO_ERROR_TIMEOUT; |
| 140 | + } |
134 | 141 | // we sleep here in case the in_chars methods acquire mutexes or disable IRQs and
|
135 | 142 | // potentially starve out what they are waiting on (have seen this with USB)
|
136 | 143 | busy_wait_us(1);
|
137 |
| - } while (!time_reached(until)); |
138 |
| - return PICO_ERROR_TIMEOUT; |
| 144 | + } while (true); |
139 | 145 | }
|
140 | 146 |
|
141 | 147 | int WRAPPER_FUNC(putchar)(int c) {
|
@@ -165,14 +171,14 @@ int puts_raw(const char *s) {
|
165 | 171 | }
|
166 | 172 |
|
167 | 173 | int _read(int handle, char *buffer, int length) {
|
168 |
| - if (handle == 0) { |
| 174 | + if (handle == STDIO_HANDLE_STDIN) { |
169 | 175 | return stdio_get_until(buffer, length, at_the_end_of_time);
|
170 | 176 | }
|
171 | 177 | return -1;
|
172 | 178 | }
|
173 | 179 |
|
174 | 180 | int _write(int handle, char *buffer, int length) {
|
175 |
| - if (handle == 1) { |
| 181 | + if (handle == STDIO_HANDLE_STDOUT || handle == STDIO_HANDLE_STDERR) { |
176 | 182 | stdio_put_string(buffer, length, false, false);
|
177 | 183 | return length;
|
178 | 184 | }
|
|
0 commit comments