mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 09:00:23 +08:00
ad806df857
Also move MICROPY_PY_PENDSV_ENTER/REENTER/EXIT to mphalport.h, for ports where these are not already there. This helps separate the hardware implementation of these macros from the MicroPython configuration (eg for renesas-ra and stm32, the IRQ static inline helper functions can now be moved to irq.h). Signed-off-by: Damien George <damien@micropython.org>
39 lines
1.0 KiB
C
39 lines
1.0 KiB
C
#include <zephyr/zephyr.h>
|
|
#include "shared/runtime/interrupt_char.h"
|
|
|
|
#define MICROPY_BEGIN_ATOMIC_SECTION irq_lock
|
|
#define MICROPY_END_ATOMIC_SECTION irq_unlock
|
|
|
|
void mp_hal_init(void);
|
|
void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms);
|
|
|
|
static inline mp_uint_t mp_hal_ticks_us(void) {
|
|
return k_cyc_to_ns_floor64(k_cycle_get_32()) / 1000;
|
|
}
|
|
|
|
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
|
return k_uptime_get();
|
|
}
|
|
|
|
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
|
// ticks_cpu() is defined as using the highest-resolution timing source
|
|
// in the system. This is usually a CPU clock, but doesn't have to be,
|
|
// here we just use Zephyr hi-res timer.
|
|
return k_cycle_get_32();
|
|
}
|
|
|
|
static inline void mp_hal_delay_us(mp_uint_t delay) {
|
|
k_busy_wait(delay);
|
|
}
|
|
|
|
static inline void mp_hal_delay_ms(mp_uint_t delay) {
|
|
mp_hal_wait_sem(NULL, delay);
|
|
}
|
|
|
|
static inline uint64_t mp_hal_time_ns(void) {
|
|
// Not currently implemented.
|
|
return 0;
|
|
}
|
|
|
|
#define mp_hal_delay_us_fast(us) (mp_hal_delay_us(us))
|