windows: Add micropython.schedule support.
This commit is contained in:
parent
c153bfd311
commit
30b6ce86be
|
@ -69,6 +69,9 @@
|
|||
#define MICROPY_MODULE_WEAK_LINKS (1)
|
||||
#define MICROPY_MODULE_OVERRIDE_MAIN_IMPORT (1)
|
||||
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
|
||||
#ifndef MICROPY_ENABLE_SCHEDULER
|
||||
#define MICROPY_ENABLE_SCHEDULER (1)
|
||||
#endif
|
||||
#define MICROPY_VFS_POSIX_FILE (1)
|
||||
#define MICROPY_PY_FUNCTION_ATTRS (1)
|
||||
#define MICROPY_PY_DESCRIPTORS (1)
|
||||
|
@ -216,6 +219,15 @@ extern const struct _mp_obj_module_t mp_module_time;
|
|||
|
||||
#define MICROPY_MPHALPORT_H "windows_mphal.h"
|
||||
|
||||
#if MICROPY_ENABLE_SCHEDULER
|
||||
#define MICROPY_EVENT_POLL_HOOK \
|
||||
do { \
|
||||
extern void mp_handle_pending(bool); \
|
||||
mp_handle_pending(true); \
|
||||
mp_hal_delay_us(500); \
|
||||
} while (0);
|
||||
#endif
|
||||
|
||||
// We need to provide a declaration/definition of alloca()
|
||||
#include <malloc.h>
|
||||
|
||||
|
|
|
@ -262,8 +262,14 @@ uint64_t mp_hal_time_ns(void) {
|
|||
return (uint64_t)tv.tv_sec * 1000000000ULL + (uint64_t)tv.tv_usec * 1000ULL;
|
||||
}
|
||||
|
||||
// TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
|
||||
// "The useconds argument shall be less than one million."
|
||||
void mp_hal_delay_ms(mp_uint_t ms) {
|
||||
usleep((ms) * 1000);
|
||||
#ifdef MICROPY_EVENT_POLL_HOOK
|
||||
mp_uint_t start = mp_hal_ticks_ms();
|
||||
while (mp_hal_ticks_ms() - start < ms) {
|
||||
// MICROPY_EVENT_POLL_HOOK does mp_hal_delay_us(500) (i.e. usleep(500)).
|
||||
MICROPY_EVENT_POLL_HOOK
|
||||
}
|
||||
#else
|
||||
SleepEx(ms, TRUE);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue