mphalport.h 685 B

12345678910111213141516171819202122232425
  1. #include <zephyr.h>
  2. #include "lib/utils/interrupt_char.h"
  3. static inline mp_uint_t mp_hal_ticks_us(void) {
  4. return SYS_CLOCK_HW_CYCLES_TO_NS(k_cycle_get_32()) / 1000;
  5. }
  6. static inline mp_uint_t mp_hal_ticks_ms(void) {
  7. return k_uptime_get();
  8. }
  9. static inline mp_uint_t mp_hal_ticks_cpu(void) {
  10. // ticks_cpu() is defined as using the highest-resolution timing source
  11. // in the system. This is usually a CPU clock, but doesn't have to be,
  12. // here we just use Zephyr hi-res timer.
  13. return k_cycle_get_32();
  14. }
  15. static inline void mp_hal_delay_us(mp_uint_t delay) {
  16. k_busy_wait(delay);
  17. }
  18. static inline void mp_hal_delay_ms(mp_uint_t delay) {
  19. k_sleep(delay);
  20. }