Skip to content

Commit 956e6a1

Browse files
committed
ports/renesas: Replace MICROPY_EVENT_POLL_HOOK with mp_event_wait.
Signed-off-by: Andrew Leech <[email protected]>
1 parent 17d8234 commit 956e6a1

File tree

5 files changed

+11
-20
lines changed

5 files changed

+11
-20
lines changed

ports/renesas-ra/machine_uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint
501501
if (!uart_tx_busy(self)) {
502502
return 0;
503503
}
504-
MICROPY_EVENT_POLL_HOOK
504+
mp_event_wait_indefinite();
505505
} while (mp_hal_ticks_ms() < timeout);
506506
*errcode = MP_ETIMEDOUT;
507507
ret = MP_STREAM_ERROR;

ports/renesas-ra/mpconfigport.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,28 +251,17 @@ typedef unsigned int mp_uint_t; // must be pointer size
251251
typedef long mp_off_t;
252252

253253
#if MICROPY_PY_THREAD
254-
#define MICROPY_EVENT_POLL_HOOK \
254+
#define MICROPY_INTERNAL_EVENT_HOOK \
255255
do { \
256-
extern void mp_handle_pending(bool); \
257-
mp_handle_pending(true); \
258256
if (pyb_thread_enabled) { \
259257
MP_THREAD_GIL_EXIT(); \
260258
pyb_thread_yield(); \
261259
MP_THREAD_GIL_ENTER(); \
262-
} else { \
263-
__WFI(); \
264260
} \
265261
} while (0);
266262

267263
#define MICROPY_THREAD_YIELD() pyb_thread_yield()
268264
#else
269-
#define MICROPY_EVENT_POLL_HOOK \
270-
do { \
271-
extern void mp_handle_pending(bool); \
272-
mp_handle_pending(true); \
273-
__WFI(); \
274-
} while (0);
275-
276265
#define MICROPY_THREAD_YIELD()
277266
#endif
278267

ports/renesas-ra/mphalport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int mp_hal_stdin_rx_chr(void) {
104104
return dupterm_c;
105105
}
106106
#endif
107-
MICROPY_EVENT_POLL_HOOK
107+
mp_event_wait_indefinite();
108108
}
109109
}
110110

ports/renesas-ra/systick.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,24 @@ void HAL_Delay(uint32_t Delay) {
9797

9898
// Core delay function that does an efficient sleep and may switch thread context.
9999
// If IRQs are enabled then we must have the GIL.
100-
void mp_hal_delay_ms(mp_uint_t Delay) {
100+
void mp_hal_delay_ms(mp_uint_t ms) {
101101
if (query_irq() == IRQ_STATE_ENABLED) {
102102
// IRQs enabled, so can use systick counter to do the delay
103103
uint32_t start = uwTick;
104+
mp_uint_t elapsed = 0;
104105
// Wraparound of tick is taken care of by 2's complement arithmetic.
105106
do {
106107
// This macro will execute the necessary idle behaviour. It may
107108
// raise an exception, switch threads or enter sleep mode (waiting for
108109
// (at least) the SysTick interrupt).
109-
MICROPY_EVENT_POLL_HOOK
110-
} while (uwTick - start < Delay);
110+
mp_event_wait_ms(ms - elapsed);
111+
elapsed = uwTick - start;
112+
} while (elapsed < ms);
111113
} else {
112114
// IRQs disabled, so need to use a busy loop for the delay.
113115
// To prevent possible overflow of the counter we use a double loop.
114116
volatile uint32_t count_1ms;
115-
while (Delay-- > 0) {
117+
while (ms-- > 0) {
116118
count_1ms = (MICROPY_HW_MCU_PCLK / 1000 / 10);
117119
while (count_1ms-- > 0) {
118120
__asm__ __volatile__ ("nop");

ports/renesas-ra/uart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ bool uart_rx_wait(machine_uart_obj_t *self, uint32_t timeout) {
477477
if (HAL_GetTick() - start >= timeout) {
478478
return false; // timeout
479479
}
480-
MICROPY_EVENT_POLL_HOOK
480+
mp_event_wait_ms(1);
481481
}
482482
}
483483

@@ -498,7 +498,7 @@ bool uart_tx_wait(machine_uart_obj_t *self, uint32_t timeout) {
498498
if (HAL_GetTick() - start >= timeout) {
499499
return false; // timeout
500500
}
501-
MICROPY_EVENT_POLL_HOOK
501+
mp_event_wait_ms(1);
502502
}
503503
}
504504

0 commit comments

Comments
 (0)