Skip to content

Commit 6952704

Browse files
andrewleechpi-anl
authored andcommitted
windows/schedule: Add micropython.schedule to windows port.
1 parent e5f9e2f commit 6952704

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ports/windows/mpconfigport.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
129129
#define MICROPY_WARNINGS (1)
130130
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
131+
#ifndef MICROPY_ENABLE_SCHEDULER
132+
#define MICROPY_ENABLE_SCHEDULER (1)
133+
#endif
131134

132135
// VFS stat functions should return time values relative to 1970/1/1
133136
#define MICROPY_EPOCH_IS_1970 (1)
@@ -201,6 +204,15 @@ extern const struct _mp_obj_module_t mp_module_time;
201204

202205
#define MICROPY_MPHALPORT_H "windows_mphal.h"
203206

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+
204216
// We need to provide a declaration/definition of alloca()
205217
#include <malloc.h>
206218

ports/windows/windows_mphal.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,14 @@ uint64_t mp_hal_time_ns(void) {
262262
return (uint64_t)tv.tv_sec * 1000000000ULL + (uint64_t)tv.tv_usec * 1000ULL;
263263
}
264264

265-
// TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
266-
// "The useconds argument shall be less than one million."
267265
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
268273
usleep((ms) * 1000);
274+
#endif
269275
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy