File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 128
128
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
129
129
#define MICROPY_WARNINGS (1)
130
130
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
131
+ #ifndef MICROPY_ENABLE_SCHEDULER
132
+ #define MICROPY_ENABLE_SCHEDULER (1)
133
+ #endif
131
134
132
135
// VFS stat functions should return time values relative to 1970/1/1
133
136
#define MICROPY_EPOCH_IS_1970 (1)
@@ -201,6 +204,15 @@ extern const struct _mp_obj_module_t mp_module_time;
201
204
202
205
#define MICROPY_MPHALPORT_H "windows_mphal.h"
203
206
207
+ #if MICROPY_ENABLE_SCHEDULER
208
+ #define MICROPY_EVENT_POLL_HOOK \
209
+ do { \
210
+ extern void mp_handle_pending(bool); \
211
+ mp_handle_pending(true); \
212
+ mp_hal_delay_us(500); \
213
+ } while (0);
214
+ #endif
215
+
204
216
// We need to provide a declaration/definition of alloca()
205
217
#include <malloc.h>
206
218
Original file line number Diff line number Diff line change @@ -262,8 +262,14 @@ uint64_t mp_hal_time_ns(void) {
262
262
return (uint64_t )tv .tv_sec * 1000000000ULL + (uint64_t )tv .tv_usec * 1000ULL ;
263
263
}
264
264
265
- // TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
266
- // "The useconds argument shall be less than one million."
267
265
void mp_hal_delay_ms (mp_uint_t ms ) {
266
+ #ifdef MICROPY_EVENT_POLL_HOOK
267
+ mp_uint_t start = mp_hal_ticks_ms ();
268
+ while (mp_hal_ticks_ms () - start < ms ) {
269
+ // MICROPY_EVENT_POLL_HOOK does mp_hal_delay_us(500) (i.e. usleep(500)).
270
+ MICROPY_EVENT_POLL_HOOK
271
+ }
272
+ #else
268
273
usleep ((ms ) * 1000 );
274
+ #endif
269
275
}
You can’t perform that action at this time.
0 commit comments