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 <damien@micropython.org>
This commit is contained in:
Damien George 2024-01-05 15:47:06 +11:00
parent d45176fc27
commit 0640ff3b97
6 changed files with 30 additions and 28 deletions

View File

@ -245,19 +245,6 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
#define MICROPY_HW_BOOTSEL_DELAY_US 8 #define MICROPY_HW_BOOTSEL_DELAY_US 8
#endif #endif
// Port level Wait-for-Event macro
//
// Do not use this macro directly, include py/runtime.h and
// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout)
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
do { \
if ((TIMEOUT_MS) < 0) { \
__wfe(); \
} else { \
best_effort_wfe_or_timeout(make_timeout_time_ms(TIMEOUT_MS)); \
} \
} while (0)
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1)) #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
#define MP_SSIZE_MAX (0x7fffffff) #define MP_SSIZE_MAX (0x7fffffff)

View File

@ -48,6 +48,19 @@
#define MICROPY_PY_LWIP_REENTER lwip_lock_acquire(); #define MICROPY_PY_LWIP_REENTER lwip_lock_acquire();
#define MICROPY_PY_LWIP_EXIT lwip_lock_release(); #define MICROPY_PY_LWIP_EXIT lwip_lock_release();
// Port level Wait-for-Event macro
//
// Do not use this macro directly, include py/runtime.h and
// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout)
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
do { \
if ((TIMEOUT_MS) < 0) { \
__wfe(); \
} else { \
best_effort_wfe_or_timeout(make_timeout_time_ms(TIMEOUT_MS)); \
} \
} while (0)
extern int mp_interrupt_char; extern int mp_interrupt_char;
extern ringbuf_t stdin_ringbuf; extern ringbuf_t stdin_ringbuf;

View File

@ -221,12 +221,6 @@ static inline unsigned long mp_random_seed_init(void) {
#include <stdio.h> #include <stdio.h>
#endif #endif
// In lieu of a WFI(), slow down polling from being a tight loop.
//
// Note that we don't delay for the full TIMEOUT_MS, as execution
// can't be woken from the delay.
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500)
// Configure the implementation of machine.idle(). // Configure the implementation of machine.idle().
#include <sched.h> #include <sched.h>
#define MICROPY_UNIX_MACHINE_IDLE sched_yield(); #define MICROPY_UNIX_MACHINE_IDLE sched_yield();

View File

@ -36,6 +36,12 @@
#define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section() #define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section()
#endif #endif
// In lieu of a WFI(), slow down polling from being a tight loop.
//
// Note that we don't delay for the full TIMEOUT_MS, as execution
// can't be woken from the delay.
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500)
void mp_hal_set_interrupt_char(char c); void mp_hal_set_interrupt_char(char c);
#define mp_hal_stdio_poll unused // this is not implemented, nor needed #define mp_hal_stdio_poll unused // this is not implemented, nor needed

View File

@ -224,15 +224,6 @@ typedef long mp_off_t;
#include "realpath.h" #include "realpath.h"
#include "init.h" #include "init.h"
#include "sleep.h"
#if MICROPY_ENABLE_SCHEDULER
// Use minimum 1mSec sleep to make sure there is effectively a wait period:
// something like usleep(500) truncates and ends up calling Sleep(0).
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) msec_sleep(MAX(1.0, (double)(TIMEOUT_MS)))
#else
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) /* No-op */
#endif
#ifdef __GNUC__ #ifdef __GNUC__
#define MP_NOINLINE __attribute__((noinline)) #define MP_NOINLINE __attribute__((noinline))

View File

@ -27,6 +27,17 @@
#include "sleep.h" #include "sleep.h"
#include "ports/unix/mphalport.h" #include "ports/unix/mphalport.h"
// Don't use the unix version of this macro.
#undef MICROPY_INTERNAL_WFE
#if MICROPY_ENABLE_SCHEDULER
// Use minimum 1mSec sleep to make sure there is effectively a wait period:
// something like usleep(500) truncates and ends up calling Sleep(0).
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) msec_sleep(MAX(1.0, (double)(TIMEOUT_MS)))
#else
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) /* No-op */
#endif
#define MICROPY_HAL_HAS_VT100 (0) #define MICROPY_HAL_HAS_VT100 (0)
void mp_hal_move_cursor_back(unsigned int pos); void mp_hal_move_cursor_back(unsigned int pos);