timer.c 510 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "timer.h"
  2. #include "io.h"
  3. static uint64_t __time_us;
  4. static uint64_t __delta_time_us;
  5. unsigned long time_micros()
  6. {
  7. #ifdef __linux__
  8. return 0;
  9. #else
  10. return millis()*1000;
  11. #endif
  12. }
  13. void micro_sleep(unsigned long x)
  14. {
  15. #ifdef __linux__
  16. usleep(x);
  17. #else
  18. delay(x/1000);
  19. #endif
  20. }
  21. void timer_init()
  22. {
  23. __time_us=0;
  24. }
  25. uint64_t get_time_us()
  26. {
  27. return millis()*1000;
  28. }
  29. void set_delta()
  30. {
  31. __delta_time_us=__time_us;
  32. }
  33. uint64_t get_delta()
  34. {
  35. return __time_us-__delta_time_us;
  36. }