Skip to content

Commit 7dc6199

Browse files
committed
ports/renesas: Replace MICROPY_EVENT_POLL_HOOK with mp_event_wait.
Signed-off-by: Andrew Leech <andrew@alelec.net>
1 parent 0b72962 commit 7dc6199

File tree

6 files changed

+27
-20
lines changed

6 files changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@
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+
39+
// Port level Wait-for-Event macro
40+
//
41+
// Do not use this macro directly, include py/runtime.h and
42+
// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout)
43+
// Uses WFI when timeout is given so it wakes up from systick
44+
// otherwise it may not wake up within given timeout.
45+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
46+
do { \
47+
if ((TIMEOUT_MS) < 0) { \
48+
__WFE(); \
49+
} else { \
50+
__WFI(); \
51+
} \
52+
} while (0)
53+
3854
#define MICROPY_PY_LWIP_ENTER
3955
#define MICROPY_PY_LWIP_REENTER
4056
#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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy