File tree Expand file tree Collapse file tree 3 files changed +11
-20
lines changed Expand file tree Collapse file tree 3 files changed +11
-20
lines changed Original file line number Diff line number Diff line change 5
5
#include "py/obj.h"
6
6
#include "py/objfun.h"
7
7
#include "py/objstr.h"
8
+ #include "py/event.h"
8
9
#include "py/runtime.h"
9
10
#include "py/gc.h"
10
11
#include "py/repl.h"
@@ -578,10 +579,10 @@ STATIC mp_obj_t extra_coverage(void) {
578
579
mp_sched_unlock ();
579
580
mp_printf (& mp_plat_print , "unlocked\n" );
580
581
581
- // drain pending callbacks
582
- while ( mp_sched_num_pending ()) {
583
- mp_handle_pending (true );
584
- }
582
+ // drain pending callbacks (and test mp_event_wait_ms())
583
+ do {
584
+ mp_event_wait_ms ( 1 );
585
+ } while ( mp_sched_num_pending ());
585
586
586
587
// setting the keyboard interrupt and raising it during mp_handle_pending
587
588
mp_sched_keyboard_interrupt ();
Original file line number Diff line number Diff line change @@ -222,14 +222,10 @@ static inline unsigned long mp_random_seed_init(void) {
222
222
#endif
223
223
224
224
// In lieu of a WFI(), slow down polling from being a tight loop.
225
- #ifndef MICROPY_EVENT_POLL_HOOK
226
- #define MICROPY_EVENT_POLL_HOOK \
227
- do { \
228
- extern void mp_handle_pending(bool); \
229
- mp_handle_pending(true); \
230
- usleep(500); /* equivalent to mp_hal_delay_us(500) */ \
231
- } while (0 );
232
- #endif
225
+ //
226
+ // Note that we don't delay for the full TIMEOUT_MS, as execution
227
+ // can't be woken from the delay.
228
+ #define MICROPY_INTERNAL_WFE (TIMEOUT_MS ) mp_hal_delay_us(500)
233
229
234
230
// Configure the implementation of machine.idle().
235
231
#include <sched.h>
Original file line number Diff line number Diff line change 33
33
34
34
#include "py/mphal.h"
35
35
#include "py/mpthread.h"
36
+ #include "py/event.h"
36
37
#include "py/runtime.h"
37
38
#include "extmod/misc.h"
38
39
@@ -237,17 +238,10 @@ uint64_t mp_hal_time_ns(void) {
237
238
238
239
#ifndef mp_hal_delay_ms
239
240
void mp_hal_delay_ms (mp_uint_t ms ) {
240
- #ifdef MICROPY_EVENT_POLL_HOOK
241
241
mp_uint_t start = mp_hal_ticks_ms ();
242
242
while (mp_hal_ticks_ms () - start < ms ) {
243
- // MICROPY_EVENT_POLL_HOOK does usleep(500).
244
- MICROPY_EVENT_POLL_HOOK
243
+ mp_event_wait_ms (1 );
245
244
}
246
- #else
247
- // TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
248
- // "The useconds argument shall be less than one million."
249
- usleep (ms * 1000 );
250
- #endif
251
245
}
252
246
#endif
253
247
You can’t perform that action at this time.
0 commit comments