8000 renesas-ra: Replace MICROPY_EVENT_POLL_HOOK with mp_event_wait. · sparkfun/micropython@573180f · GitHub
[go: up one dir, main page]

Skip to content

Commit 573180f

Browse files
pi-anldpgeorge
authored andcommitted
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>
1 parent d9467b0 commit 573180f

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-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
@@ -243,28 +243,17 @@ typedef unsigned int mp_uint_t; // must be pointer size
243243
typedef long mp_off_t;
244244

245245
#if MICROPY_PY_THREAD
246-
#define MICROPY_EVENT_POLL_HOOK \
246+
#define MICROPY_INTERNAL_EVENT_HOOK \
247247
do { \
248-
extern void mp_handle_pending(bool); \
249-
mp_handle_pending(true); \
250248
if (pyb_thread_enabled) { \
251249
MP_THREAD_GIL_EXIT(); \
252250
pyb_thread_yield(); \
253251
MP_THREAD_GIL_ENTER(); \
254-
} else { \
255-
__WFI(); \
256252
} \
257253
} while (0);
258254

259255
#define MICROPY_THREAD_YIELD() pyb_thread_yield()
260256
#else
261-
#define MICROPY_EVENT_POLL_HOOK \
262-
do { \
263-
extern void mp_handle_pending(bool); \
264-
mp_handle_pending(true); \
265-
__WFI(); \
266-
} while (0);
267-
268257
#define MICROPY_THREAD_YIELD()
269258
#endif
270259

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/mphalport.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
#define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV)
3636
#define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state)
3737

38+
// Port level Wait-for-Event macro
39+
//
40+
// Do not use this macro directly, include py/runtime.h and
41+
// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout).
42+
// Uses WFI which will wake up from regular systick interrupt if not
43+
// before from any other source.
44+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) __WFI()
45+
3846
#define MICROPY_PY_LWIP_ENTER
3947
#define MICROPY_PY_LWIP_REENTER
4048
#define MICROPY_PY_LWIP_EXIT

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)
0