micropython/ports/zephyr/mphalport.h
Maureen Helm a7663b862e zephyr: Replace deprecated time conversion macro.
The SYS_CLOCK_HW_CYCLES_TO_NS macro was deprecated in zephyr commit
8892406c1de21bd5de5877f39099e3663a5f3af1.  This commit updates MicroPython
to use the new k_cyc_to_ns_floor64 api and fix build warnings in the zephyr
port.

This change is compatible with Zephyr v2.1 and later.
2020-02-04 17:09:59 +11:00

31 lines
1003 B
C

#include <zephyr.h>
#include "lib/utils/interrupt_char.h"
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) {
k_sleep(delay);
}
#define mp_hal_delay_us_fast(us) (mp_hal_delay_us(us))
#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"))