alif/mphalport: Enable efficient events and implement quiet timing.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-01-10 16:08:45 +11:00
parent 40ff0c2f27
commit 975f84f2ad
2 changed files with 14 additions and 11 deletions

View File

@@ -133,10 +133,14 @@ void mp_hal_delay_us(mp_uint_t us) {
void mp_hal_delay_ms(mp_uint_t ms) { void mp_hal_delay_ms(mp_uint_t ms) {
uint32_t t0 = mp_hal_ticks_ms(); uint32_t t0 = mp_hal_ticks_ms();
do { mp_event_handle_nowait();
// TODO: power saving wait for (;;) {
mp_event_handle_nowait(); uint32_t t1 = mp_hal_ticks_ms();
} while (mp_hal_ticks_ms() - t0 < ms); if (t1 - t0 >= ms) {
break;
}
mp_event_wait_ms(ms - (t1 - t0));
}
} }
uint64_t mp_hal_time_ns(void) { uint64_t mp_hal_time_ns(void) {

View File

@@ -27,6 +27,7 @@
#include "py/ringbuf.h" #include "py/ringbuf.h"
#include "shared/runtime/interrupt_char.h" #include "shared/runtime/interrupt_char.h"
#include "irq.h" #include "irq.h"
#include "system_tick.h"
#include ALIF_CMSIS_H #include ALIF_CMSIS_H
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
@@ -47,8 +48,7 @@
if ((TIMEOUT_MS) < 0) { \ if ((TIMEOUT_MS) < 0) { \
__WFE(); \ __WFE(); \
} else { \ } else { \
/* TODO */ \ system_tick_wfe_with_timeout_us(TIMEOUT_MS * 1000); \
__WFE(); \
} \ } \
} while (0) } while (0)
@@ -57,13 +57,12 @@
(SCB_CleanDCache_by_Addr((uint32_t *)((uint32_t)addr & ~0x1f), \ (SCB_CleanDCache_by_Addr((uint32_t *)((uint32_t)addr & ~0x1f), \
((uint32_t)((uint8_t *)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f))) ((uint32_t)((uint8_t *)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
extern ringbuf_t stdin_ringbuf; #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)
// TODO
#define mp_hal_quiet_timing_enter() 0
#define mp_hal_quiet_timing_exit(x) (void)x
#define mp_hal_delay_us_fast mp_hal_delay_us #define mp_hal_delay_us_fast mp_hal_delay_us
extern ringbuf_t stdin_ringbuf;
/******************************************************************************/ /******************************************************************************/
// C-level pin HAL // C-level pin HAL