479b961d39
This provides time and sleep together with the usual ticks_us/_ms/_diff and sleep_us/ms family. We also provide access to Zephyr's high precision timer as ticks_cpu(). Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
27 lines
725 B
C
27 lines
725 B
C
#include <zephyr.h>
|
|
|
|
static inline mp_uint_t mp_hal_ticks_us(void) {
|
|
return sys_tick_get() * sys_clock_us_per_tick;
|
|
}
|
|
|
|
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
|
int64_t us = sys_tick_get() * sys_clock_us_per_tick;
|
|
mp_int_t ms = us / 1000;
|
|
return ms;
|
|
}
|
|
|
|
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 sys_cycle_get_32();
|
|
}
|
|
|
|
static inline void mp_hal_delay_us(mp_uint_t delay) {
|
|
task_sleep(USEC(delay));
|
|
}
|
|
|
|
static inline void mp_hal_delay_ms(mp_uint_t delay) {
|
|
task_sleep(MSEC(delay));
|
|
}
|