Skip to content

Commit 975f84f

Browse files
committed
alif/mphalport: Enable efficient events and implement quiet timing.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 40ff0c2 commit 975f84f

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

ports/alif/mphalport.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ void mp_hal_delay_us(mp_uint_t us) {
133133

134134
void mp_hal_delay_ms(mp_uint_t ms) {
135135
uint32_t t0 = mp_hal_ticks_ms();
136-
do {
137-
// TODO: power saving wait
138-
mp_event_handle_nowait();
139-
} while (mp_hal_ticks_ms() - t0 < ms);
136+
mp_event_handle_nowait();
137+
for (;;) {
138+
uint32_t t1 = mp_hal_ticks_ms();
139+
if (t1 - t0 >= ms) {
140+
break;
141+
}
142+
mp_event_wait_ms(ms - (t1 - t0));
143+
}
140144
}
141145

142146
uint64_t mp_hal_time_ns(void) {

ports/alif/mphalport.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "py/ringbuf.h"
2828
#include "shared/runtime/interrupt_char.h"
2929
#include "irq.h"
30+
#include "system_tick.h"
3031
#include ALIF_CMSIS_H
3132

3233
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
@@ -47,8 +48,7 @@
4748
if ((TIMEOUT_MS) < 0) { \
4849
__WFE(); \
4950
} else { \
50-
/* TODO */ \
51-
__WFE(); \
51+
system_tick_wfe_with_timeout_us(TIMEOUT_MS * 1000); \
5252
} \
5353
} while (0)
5454

@@ -57,13 +57,12 @@
5757
(SCB_CleanDCache_by_Addr((uint32_t *)((uint32_t)addr & ~0x1f), \
5858
((uint32_t)((uint8_t *)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
5959

60-
extern ringbuf_t stdin_ringbuf;
61-
62-
// TODO
63-
#define mp_hal_quiet_timing_enter() 0
64-
#define mp_hal_quiet_timing_exit(x) (void)x
60+
#define mp_hal_quiet_timing_enter() raise_irq_pri(IRQ_PRI_QUIET_TIMING)
61+
#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
6562
#define mp_hal_delay_us_fast mp_hal_delay_us
6663

64+
extern ringbuf_t stdin_ringbuf;
65+
6766
/******************************************************************************/
6867
// C-level pin HAL
6968

0 commit comments

Comments
 (0)