windows: Add micropython.schedule support.

pull/8205/head
Andrew Leech 2021-09-13 10:43:42 +10:00 zatwierdzone przez Damien George
rodzic c153bfd311
commit 30b6ce86be
2 zmienionych plików z 21 dodań i 3 usunięć

Wyświetl plik

@ -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>

Wyświetl plik

@ -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
}