Skip to content

Commit 941cc31

Browse files
committed
mimxrt: Convert port to use new event waiting functions.
Convert the mimxrt port from the old `MICROPY_EVENT_POLL_HOOK` macro to use the new `mp_event_wait_xxx()` functions in conjunction with `MICROPY_INTERNAL_WFE`. This change should be functionally equivalent to the existing behaivour because `mp_event_wait_ms()` and `mp_event_wait_indefinite()` are equal to `mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); __WFE()`, which is what `MICROPY_EVENT_POLL_HOOK` was. Signed-off-by: Damien George <damien@micropython.org>
1 parent 036bd81 commit 941cc31

10 files changed

Lines changed: 18 additions & 25 deletions

File tree

ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-1070evk"
55

6-
#define MICROPY_EVENT_POLL_HOOK \
7-
do { \
8-
mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); \
9-
} while (0);
6+
// Do not use WFE when waiting for an event.
7+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS)
108

119
// MIMXRT1170_EVK has 2 user LEDs
1210
#define MICROPY_HW_LED1_PIN (pin_GPIO_AD_04)

ports/mimxrt/boards/PHYBOARD_RT1170/mpconfigboard.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-phyboard"
55

6-
#define MICROPY_EVENT_POLL_HOOK \
7-
do { \
8-
mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); \
9-
} while (0);
6+
// Do not use WFE when waiting for an event.
7+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS)
108

119
// phyBOARD-RT1170 SoM onboard LEDs (red and green from phyCORE SoM)
1210
// Carrier board provides additional RGB LEDs via GPIO

ports/mimxrt/machine_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
170170
}
171171
// Wait for the transfer to complete
172172
while (self->transfer_busy) {
173-
MICROPY_EVENT_POLL_HOOK
173+
mp_event_wait_ms(1);
174174
}
175175

176176
// Transfer will not send a stop in case of errors like NAK. So it's done here.

ports/mimxrt/machine_uart.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t
527527
return received;
528528
}
529529
}
530-
MICROPY_EVENT_POLL_HOOK
530+
mp_event_wait_ms(1);
531531
}
532532
// Get as many bytes as possible to meet the need.
533533
nget = avail < (size - received) ? avail : size - received;
@@ -558,7 +558,7 @@ static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_
558558
*errcode = MP_ETIMEDOUT;
559559
return MP_STREAM_ERROR;
560560
}
561-
MICROPY_EVENT_POLL_HOOK
561+
mp_event_wait_ms(1);
562562
}
563563

564564
// Check if the first part has to be sent semi-blocking.
@@ -581,7 +581,7 @@ static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_
581581
return size - self->handle.txDataSize;
582582
}
583583
}
584-
MICROPY_EVENT_POLL_HOOK
584+
mp_event_wait_ms(1);
585585
}
586586
remaining = self->txbuf_len;
587587
} else {
@@ -627,7 +627,7 @@ static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint
627627
if (mp_machine_uart_txdone(self)) {
628628
return 0;
629629
}
630-
MICROPY_EVENT_POLL_HOOK
630+
mp_event_wait_ms(1);
631631
} while (ticks_us64() < timeout);
632632

633633
*errcode = MP_ETIMEDOUT;

ports/mimxrt/modmachine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
133133
}
134134

135135
static void mp_machine_idle(void) {
136-
MICROPY_EVENT_POLL_HOOK;
136+
mp_event_wait_ms(1);
137137
}
138138

139139
static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {

ports/mimxrt/mpconfigport.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,6 @@ extern const struct _mp_obj_type_t network_lan_type;
223223
#define MICROPY_HW_USB_PID (0x9802)
224224
#endif
225225

226-
#ifndef MICROPY_EVENT_POLL_HOOK
227-
#define MICROPY_EVENT_POLL_HOOK \
228-
do { \
229-
mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); \
230-
__WFE(); \
231-
} while (0);
232-
#endif
233-
234226
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
235227

236228
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) \

ports/mimxrt/mphalport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int mp_hal_stdin_rx_chr(void) {
7171
return dupterm_c;
7272
}
7373
#endif
74-
MICROPY_EVENT_POLL_HOOK
74+
mp_event_wait_indefinite();
7575
}
7676
}
7777

ports/mimxrt/mphalport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
#define MICROPY_PY_LWIP_REENTER MICROPY_PY_PENDSV_REENTER
5151
#define MICROPY_PY_LWIP_EXIT MICROPY_PY_PENDSV_EXIT
5252

53+
// Port level Wait-for-Event macro.
54+
#ifndef MICROPY_INTERNAL_WFE
55+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) __WFE()
56+
#endif
57+
5358
#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500)
5459

5560
#define MP_HAL_PIN_FMT "%q"

ports/mimxrt/sdio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static status_t sdio_transfer_dma(USDHC_Type *base,
259259
while ((sdmmc.xfer_flags != xfer_flags) &&
260260
!(sdmmc.xfer_flags & SDIO_TRANSFER_ERROR) &&
261261
(mp_hal_ticks_ms() - start) < timeout_ms) {
262-
MICROPY_EVENT_POLL_HOOK;
262+
mp_event_wait_ms(1);
263263
}
264264

265265
if (sdmmc.xfer_flags == 0) {

ports/mimxrt/ticks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void ticks_delay_us64(uint64_t us) {
136136
}
137137
ticks_wake_after_us32((uint32_t)dt);
138138
if (dt > 50) {
139-
MICROPY_EVENT_POLL_HOOK
139+
mp_event_wait_ms(1);
140140
}
141141
}
142142
}

0 commit comments

Comments
 (0)