renesas-ra: Replace MICROPY_EVENT_POLL_HOOK with mp_event_wait.

Basic update to the renesas-ra port to replace the traditional
`MICROPY_EVENT_POLL_HOOK` with the newer mp_event_wait API as appropriate.

Signed-off-by: Andrew Leech <andrew@alelec.net>
This commit is contained in:
Andrew Leech
2024-09-29 21:23:29 +10:00
committed by Damien George
parent d9467b07cb
commit 573180f788
6 changed files with 19 additions and 20 deletions

View File

@@ -501,7 +501,7 @@ static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint
if (!uart_tx_busy(self)) { if (!uart_tx_busy(self)) {
return 0; return 0;
} }
MICROPY_EVENT_POLL_HOOK mp_event_wait_indefinite();
} while (mp_hal_ticks_ms() < timeout); } while (mp_hal_ticks_ms() < timeout);
*errcode = MP_ETIMEDOUT; *errcode = MP_ETIMEDOUT;
ret = MP_STREAM_ERROR; ret = MP_STREAM_ERROR;

View File

@@ -243,28 +243,17 @@ typedef unsigned int mp_uint_t; // must be pointer size
typedef long mp_off_t; typedef long mp_off_t;
#if MICROPY_PY_THREAD #if MICROPY_PY_THREAD
#define MICROPY_EVENT_POLL_HOOK \ #define MICROPY_INTERNAL_EVENT_HOOK \
do { \ do { \
extern void mp_handle_pending(bool); \
mp_handle_pending(true); \
if (pyb_thread_enabled) { \ if (pyb_thread_enabled) { \
MP_THREAD_GIL_EXIT(); \ MP_THREAD_GIL_EXIT(); \
pyb_thread_yield(); \ pyb_thread_yield(); \
MP_THREAD_GIL_ENTER(); \ MP_THREAD_GIL_ENTER(); \
} else { \
__WFI(); \
} \ } \
} while (0); } while (0);
#define MICROPY_THREAD_YIELD() pyb_thread_yield() #define MICROPY_THREAD_YIELD() pyb_thread_yield()
#else #else
#define MICROPY_EVENT_POLL_HOOK \
do { \
extern void mp_handle_pending(bool); \
mp_handle_pending(true); \
__WFI(); \
} while (0);
#define MICROPY_THREAD_YIELD() #define MICROPY_THREAD_YIELD()
#endif #endif

View File

@@ -104,7 +104,7 @@ int mp_hal_stdin_rx_chr(void) {
return dupterm_c; return dupterm_c;
} }
#endif #endif
MICROPY_EVENT_POLL_HOOK mp_event_wait_indefinite();
} }
} }

View File

@@ -35,6 +35,14 @@
#define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV) #define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV)
#define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state) #define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state)
// 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).
// Uses WFI which will wake up from regular systick interrupt if not
// before from any other source.
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) __WFI()
#define MICROPY_PY_LWIP_ENTER #define MICROPY_PY_LWIP_ENTER
#define MICROPY_PY_LWIP_REENTER #define MICROPY_PY_LWIP_REENTER
#define MICROPY_PY_LWIP_EXIT #define MICROPY_PY_LWIP_EXIT

View File

@@ -97,22 +97,24 @@ void HAL_Delay(uint32_t Delay) {
// Core delay function that does an efficient sleep and may switch thread context. // Core delay function that does an efficient sleep and may switch thread context.
// If IRQs are enabled then we must have the GIL. // If IRQs are enabled then we must have the GIL.
void mp_hal_delay_ms(mp_uint_t Delay) { void mp_hal_delay_ms(mp_uint_t ms) {
if (query_irq() == IRQ_STATE_ENABLED) { if (query_irq() == IRQ_STATE_ENABLED) {
// IRQs enabled, so can use systick counter to do the delay // IRQs enabled, so can use systick counter to do the delay
uint32_t start = uwTick; uint32_t start = uwTick;
mp_uint_t elapsed = 0;
// Wraparound of tick is taken care of by 2's complement arithmetic. // Wraparound of tick is taken care of by 2's complement arithmetic.
do { do {
// This macro will execute the necessary idle behaviour. It may // This macro will execute the necessary idle behaviour. It may
// raise an exception, switch threads or enter sleep mode (waiting for // raise an exception, switch threads or enter sleep mode (waiting for
// (at least) the SysTick interrupt). // (at least) the SysTick interrupt).
MICROPY_EVENT_POLL_HOOK mp_event_wait_ms(ms - elapsed);
} while (uwTick - start < Delay); elapsed = uwTick - start;
} while (elapsed < ms);
} else { } else {
// IRQs disabled, so need to use a busy loop for the delay. // IRQs disabled, so need to use a busy loop for the delay.
// To prevent possible overflow of the counter we use a double loop. // To prevent possible overflow of the counter we use a double loop.
volatile uint32_t count_1ms; volatile uint32_t count_1ms;
while (Delay-- > 0) { while (ms-- > 0) {
count_1ms = (MICROPY_HW_MCU_PCLK / 1000 / 10); count_1ms = (MICROPY_HW_MCU_PCLK / 1000 / 10);
while (count_1ms-- > 0) { while (count_1ms-- > 0) {
__asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");

View File

@@ -477,7 +477,7 @@ bool uart_rx_wait(machine_uart_obj_t *self, uint32_t timeout) {
if (HAL_GetTick() - start >= timeout) { if (HAL_GetTick() - start >= timeout) {
return false; // timeout return false; // timeout
} }
MICROPY_EVENT_POLL_HOOK mp_event_wait_ms(1);
} }
} }
@@ -498,7 +498,7 @@ bool uart_tx_wait(machine_uart_obj_t *self, uint32_t timeout) {
if (HAL_GetTick() - start >= timeout) { if (HAL_GetTick() - start >= timeout) {
return false; // timeout return false; // timeout
} }
MICROPY_EVENT_POLL_HOOK mp_event_wait_ms(1);
} }
} }