2016-10-22 13:15:26 -04:00
|
|
|
#include <zephyr.h>
|
2016-10-26 10:53:28 -04:00
|
|
|
#include "lib/utils/interrupt_char.h"
|
2016-10-22 13:15:26 -04:00
|
|
|
|
|
|
|
static inline mp_uint_t mp_hal_ticks_us(void) {
|
2016-12-03 16:47:20 -05:00
|
|
|
return SYS_CLOCK_HW_CYCLES_TO_NS(k_cycle_get_32()) / 1000;
|
2016-10-22 13:15:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline mp_uint_t mp_hal_ticks_ms(void) {
|
2016-12-03 16:47:20 -05:00
|
|
|
return k_uptime_get();
|
2016-10-22 13:15:26 -04: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 16:47:20 -05:00
|
|
|
return k_cycle_get_32();
|
2016-10-22 13:15:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mp_hal_delay_us(mp_uint_t delay) {
|
2016-11-08 16:11:30 -05:00
|
|
|
k_busy_wait(delay);
|
2016-10-22 13:15:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mp_hal_delay_ms(mp_uint_t delay) {
|
2016-11-08 16:11:30 -05:00
|
|
|
k_sleep(delay);
|
2016-10-22 13:15:26 -04:00
|
|
|
}
|