sleep.h 719 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020-2021, WangHuachen
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-11-30 WangHuachen the first version
  9. */
  10. #ifndef XLI_SLEEP_H
  11. #define XLI_SLEEP_H
  12. #include <rtthread.h>
  13. #include <rthw.h>
  14. #include "xil_types.h"
  15. #include "xil_io.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. static inline void usleep(unsigned long useconds)
  20. {
  21. rt_uint32_t milliseconds = useconds/1000;
  22. useconds = useconds%1000;
  23. if (milliseconds) rt_thread_mdelay(milliseconds);
  24. if (useconds) rt_hw_us_delay(useconds);
  25. }
  26. static inline void sleep(unsigned int seconds)
  27. {
  28. rt_thread_delay(seconds*RT_TICK_PER_SECOND);
  29. }
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33. #endif