Skip to content

Commit 0640ff3

Browse files
committed
ports: Move MICROPY_INTERNAL_WFE definition to mphalport.h.
It belongs here because the default value is defined in py/mphal.h. Signed-off-by: Damien George <[email protected]>
1 parent d45176f commit 0640ff3

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed

ports/rp2/mpconfigport.h

-13
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,6 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
245245
#define MICROPY_HW_BOOTSEL_DELAY_US 8
246246
#endif
247247

248-
// Port level Wait-for-Event macro
249-
//
250-
// Do not use this macro directly, include py/runtime.h and
251-
// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout)
252-
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
253-
do { \
254-
if ((TIMEOUT_MS) < 0) { \
255-
__wfe(); \
256-
} else { \
257-
best_effort_wfe_or_timeout(make_timeout_time_ms(TIMEOUT_MS)); \
258-
} \
259-
} while (0)
260-
261248
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
262249

263250
#define MP_SSIZE_MAX (0x7fffffff)

ports/rp2/mphalport.h

+13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
#define MICROPY_PY_LWIP_REENTER lwip_lock_acquire();
4949
#define MICROPY_PY_LWIP_EXIT lwip_lock_release();
5050

51+
// Port level Wait-for-Event macro
52+
//
53+
// Do not use this macro directly, include py/runtime.h and
54+
// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout)
55+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
56+
do { \
57+
if ((TIMEOUT_MS) < 0) { \
58+
__wfe(); \
59+
} else { \
60+
best_effort_wfe_or_timeout(make_timeout_time_ms(TIMEOUT_MS)); \
61+
} \
62+
} while (0)
63+
5164
extern int mp_interrupt_char;
5265
extern ringbuf_t stdin_ringbuf;
5366

ports/unix/mpconfigport.h

-6
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,6 @@ static inline unsigned long mp_random_seed_init(void) {
221221
#include <stdio.h>
222222
#endif
223223

224-
// In lieu of a WFI(), slow down polling from being a tight loop.
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)
229-
230224
// Configure the implementation of machine.idle().
231225
#include <sched.h>
232226
#define MICROPY_UNIX_MACHINE_IDLE sched_yield();

ports/unix/mphalport.h

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
#define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section()
3737
#endif
3838

39+
// In lieu of a WFI(), slow down polling from being a tight loop.
40+
//
41+
// Note that we don't delay for the full TIMEOUT_MS, as execution
42+
// can't be woken from the delay.
43+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500)
44+
3945
void mp_hal_set_interrupt_char(char c);
4046

4147
#define mp_hal_stdio_poll unused // this is not implemented, nor needed

ports/windows/mpconfigport.h

-9
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,6 @@ typedef long mp_off_t;
224224

225225
#include "realpath.h"
226226
#include "init.h"
227-
#include "sleep.h"
228-
229-
#if MICROPY_ENABLE_SCHEDULER
230-
// Use minimum 1mSec sleep to make sure there is effectively a wait period:
231-
// something like usleep(500) truncates and ends up calling Sleep(0).
232-
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) msec_sleep(MAX(1.0, (double)(TIMEOUT_MS)))
233-
#else
234-
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) /* No-op */
235-
#endif
236227

237228
#ifdef __GNUC__
238229
#define MP_NOINLINE __attribute__((noinline))

ports/windows/windows_mphal.h

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727
#include "sleep.h"
2828
#include "ports/unix/mphalport.h"
2929

30+
// Don't use the unix version of this macro.
31+
#undef MICROPY_INTERNAL_WFE
32+
33+
#if MICROPY_ENABLE_SCHEDULER
34+
// Use minimum 1mSec sleep to make sure there is effectively a wait period:
35+
// something like usleep(500) truncates and ends up calling Sleep(0).
36+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) msec_sleep(MAX(1.0, (double)(TIMEOUT_MS)))
37+
#else
38+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) /* No-op */
39+
#endif
40+
3041
#define MICROPY_HAL_HAS_VT100 (0)
3142

3243
void mp_hal_move_cursor_back(unsigned int pos);

0 commit comments

Comments
 (0)