2016-10-22 18:15:26 +01:00
|
|
|
#include <zephyr.h>
|
2016-10-26 15:53:28 +01:00
|
|
|
#include "lib/utils/interrupt_char.h"
|
2016-10-22 18:15:26 +01:00
|
|
|
|
2021-04-25 13:28:55 +01:00
|
|
|
void mp_hal_init(void);
|
|
|
|
void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms);
|
|
|
|
|
2016-10-22 18:15:26 +01:00
|
|
|
static inline mp_uint_t mp_hal_ticks_us(void) {
|
2019-12-30 13:25:49 +00:00
|
|
|
return k_cyc_to_ns_floor64(k_cycle_get_32()) / 1000;
|
2016-10-22 18:15:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
2016-12-03 21:47:20 +00:00
|
|
|
return k_uptime_get();
|
2016-10-22 18:15:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2016-12-03 21:47:20 +00:00
|
|
|
return k_cycle_get_32();
|
2016-10-22 18:15:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mp_hal_delay_us(mp_uint_t delay) {
|
2016-11-08 21:11:30 +00:00
|
|
|
k_busy_wait(delay);
|
2016-10-22 18:15:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mp_hal_delay_ms(mp_uint_t delay) {
|
2021-04-25 13:28:55 +01:00
|
|
|
mp_hal_wait_sem(NULL, delay);
|
2016-10-22 18:15:26 +01:00
|
|
|
}
|
2019-03-18 13:54:08 +00:00
|
|
|
|
2020-08-01 14:50:23 +01:00
|
|
|
static inline uint64_t mp_hal_time_ns(void) {
|
|
|
|
// Not currently implemented.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-18 13:54:08 +00:00
|
|
|
#define mp_hal_delay_us_fast(us) (mp_hal_delay_us(us))
|
2020-09-16 05:09:49 +01:00
|
|
|
|
|
|
|
// C-level pin API is not currently implemented
|
|
|
|
#define MP_HAL_PIN_FMT "%d"
|
|
|
|
#define mp_hal_pin_name(p) (0)
|
2019-03-18 13:54:08 +00:00
|
|
|
#define mp_hal_pin_od_low(p) (mp_raise_NotImplementedError("mp_hal_pin_od_low"))
|
|
|
|
#define mp_hal_pin_od_high(p) (mp_raise_NotImplementedError("mp_hal_pin_od_high"))
|
|
|
|
#define mp_hal_pin_open_drain(p) (mp_raise_NotImplementedError("mp_hal_pin_open_drain"))
|