Skip to content

Commit 1f601e8

Browse files
committed
samd: Convert port to use new event waiting functions.
Convert the samd 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()` is 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 941cc31 commit 1f601e8

8 files changed

Lines changed: 15 additions & 18 deletions

File tree

ports/samd/machine_i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
224224
self->buf = buf;
225225
// Wait a while if the bus is busy
226226
while (IS_BUS_BUSY && self->timer) {
227-
MICROPY_EVENT_POLL_HOOK
227+
mp_event_wait_ms(1);
228228
if (--self->timer == 0) {
229229
return -MP_ETIMEDOUT;
230230
}
@@ -240,7 +240,7 @@ static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
240240
self->timer = self->timeout;
241241
while (self->state == state_busy && self->timer) {
242242
self->timer--;
243-
MICROPY_EVENT_POLL_HOOK
243+
mp_event_wait_ms(1);
244244
}
245245
i2c->I2CM.INTENCLR.reg = SERCOM_I2CM_INTENSET_MB | SERCOM_I2CM_INTENSET_SB | SERCOM_I2CM_INTENSET_ERROR;
246246

ports/samd/machine_pwm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static void wait_for_register_update(Tcc *tcc) {
287287
if (tcc->INTFLAG.reg & TCC_INTFLAG_OVF) {
288288
break;
289289
}
290-
MICROPY_EVENT_POLL_HOOK
290+
mp_event_wait_ms(1);
291291
}
292292
// Clear the flag, telling that a cycle has been handled.
293293
tcc->INTFLAG.reg = TCC_INTFLAG_OVF;

ports/samd/machine_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8
328328
int32_t timeout = 1000;
329329
while (self->rxlen > 0 && timeout) {
330330
timeout--;
331-
MICROPY_EVENT_POLL_HOOK
331+
mp_event_wait_ms(1);
332332
}
333333
spi->SPI.INTENCLR.reg = SERCOM_SPI_INTENCLR_RXC;
334334
} else {

ports/samd/machine_uart.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) {
581581
// Wait for the tx buffer to drain.
582582
#if MICROPY_HW_UART_TXBUF
583583
while (ringbuf_avail(&self->write_buffer) > 0) {
584-
MICROPY_EVENT_POLL_HOOK
584+
mp_event_wait_ms(1);
585585
}
586586
#endif
587587
// Wait for the TX queue & register to clear
@@ -699,7 +699,7 @@ static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t
699699
return i;
700700
}
701701
}
702-
MICROPY_EVENT_POLL_HOOK
702+
mp_event_wait_ms(1);
703703
}
704704
*dest++ = ringbuf_get(&(self->read_buffer));
705705
i++;
@@ -751,7 +751,7 @@ static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_
751751
return i;
752752
}
753753
}
754-
MICROPY_EVENT_POLL_HOOK
754+
mp_event_wait_ms(1);
755755
}
756756
if (bits >= 9) {
757757
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION();
@@ -778,7 +778,7 @@ static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_
778778
return i;
779779
}
780780
}
781-
MICROPY_EVENT_POLL_HOOK
781+
mp_event_wait_ms(1);
782782
}
783783
if (self->bits > 8 && i < (size - 1)) {
784784
uart->USART.DATA.bit.DATA = *(uint16_t *)src;
@@ -822,7 +822,7 @@ static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint
822822
if (mp_machine_uart_txdone(self)) {
823823
return 0;
824824
}
825-
MICROPY_EVENT_POLL_HOOK
825+
mp_event_wait_ms(1);
826826
} while (mp_hal_ticks_ms_64() < timeout);
827827
*errcode = MP_ETIMEDOUT;
828828
ret = MP_STREAM_ERROR;

ports/samd/modmachine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static mp_obj_t mp_machine_unique_id(void) {
9999
}
100100

101101
static void mp_machine_idle(void) {
102-
MICROPY_EVENT_POLL_HOOK;
102+
mp_event_wait_ms(1);
103103
}
104104

105105
static mp_int_t mp_machine_reset_cause(void) {

ports/samd/mpconfigport.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@
168168

169169
// Miscellaneous settings
170170

171-
#define MICROPY_EVENT_POLL_HOOK \
172-
do { \
173-
mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); \
174-
__WFE(); \
175-
} while (0);
176-
177171
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
178172

179173
#define MP_SSIZE_MAX (0x7fffffff)

ports/samd/mphalport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0,
4848
// interrupt handler) and there is in/out data pending on the USB CDC interface.
4949
#define MICROPY_EVENT_POLL_HOOK_WITH_USB \
5050
do { \
51-
MICROPY_EVENT_POLL_HOOK; \
51+
mp_event_wait_ms(1); \
5252
mp_usbd_task(); \
5353
} while (0)
5454

@@ -71,7 +71,7 @@ void mp_hal_clr_pin_mux(mp_hal_pin_obj_t pin) {
7171
void mp_hal_delay_ms(mp_uint_t ms) {
7272
uint32_t t0 = systick_ms;
7373
while (systick_ms - t0 < ms) {
74-
MICROPY_EVENT_POLL_HOOK
74+
mp_event_wait_ms(1);
7575
}
7676
}
7777

ports/samd/mphalport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV)
4242
#define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state)
4343

44+
// Port level Wait-for-Event macro.
45+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) __WFE()
46+
4447
#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500)
4548

4649
extern int mp_interrupt_char;

0 commit comments

Comments
 (0)