summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-01-10 16:08:45 +1100
committerDamien George <damien@micropython.org>2025-04-09 00:22:32 +1000
commit975f84f2adc1f89b4c9349b6a6e83f6bc4ec2fd6 (patch)
tree5fcfe80d1f948cea395a89a1e406360d69b0fc7d
parent40ff0c2f276883ea325ce8977453bd16a2f2029a (diff)
alif/mphalport: Enable efficient events and implement quiet timing.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/alif/mphalport.c12
-rw-r--r--ports/alif/mphalport.h13
2 files changed, 14 insertions, 11 deletions
diff --git a/ports/alif/mphalport.c b/ports/alif/mphalport.c
index abb71aae6..8d0fa1b92 100644
--- a/ports/alif/mphalport.c
+++ b/ports/alif/mphalport.c
@@ -133,10 +133,14 @@ void mp_hal_delay_us(mp_uint_t us) {
void mp_hal_delay_ms(mp_uint_t ms) {
uint32_t t0 = mp_hal_ticks_ms();
- do {
- // TODO: power saving wait
- mp_event_handle_nowait();
- } while (mp_hal_ticks_ms() - t0 < ms);
+ mp_event_handle_nowait();
+ for (;;) {
+ uint32_t t1 = mp_hal_ticks_ms();
+ if (t1 - t0 >= ms) {
+ break;
+ }
+ mp_event_wait_ms(ms - (t1 - t0));
+ }
}
uint64_t mp_hal_time_ns(void) {
diff --git a/ports/alif/mphalport.h b/ports/alif/mphalport.h
index 1b8c854fd..8098c2650 100644
--- a/ports/alif/mphalport.h
+++ b/ports/alif/mphalport.h
@@ -27,6 +27,7 @@
#include "py/ringbuf.h"
#include "shared/runtime/interrupt_char.h"
#include "irq.h"
+#include "system_tick.h"
#include ALIF_CMSIS_H
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
@@ -47,8 +48,7 @@
if ((TIMEOUT_MS) < 0) { \
__WFE(); \
} else { \
- /* TODO */ \
- __WFE(); \
+ system_tick_wfe_with_timeout_us(TIMEOUT_MS * 1000); \
} \
} while (0)
@@ -57,13 +57,12 @@
(SCB_CleanDCache_by_Addr((uint32_t *)((uint32_t)addr & ~0x1f), \
((uint32_t)((uint8_t *)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
-extern ringbuf_t stdin_ringbuf;
-
-// TODO
-#define mp_hal_quiet_timing_enter() 0
-#define mp_hal_quiet_timing_exit(x) (void)x
+#define mp_hal_quiet_timing_enter() raise_irq_pri(IRQ_PRI_QUIET_TIMING)
+#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
#define mp_hal_delay_us_fast mp_hal_delay_us
+extern ringbuf_t stdin_ringbuf;
+
/******************************************************************************/
// C-level pin HAL