drv_common.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-08-20 breo.com first version
  9. */
  10. #include "drv_common.h"
  11. #include "board.h"
  12. #ifdef RT_USING_SERIAL
  13. #ifdef RT_USING_SERIAL_V2
  14. #include "drv_usart_v2.h"
  15. #else
  16. #include "drv_usart.h"
  17. #endif
  18. #endif
  19. #ifdef RT_USING_FINSH
  20. #include <finsh.h>
  21. static void reboot(uint8_t argc, char **argv)
  22. {
  23. rt_hw_cpu_reset();
  24. }
  25. MSH_CMD_EXPORT(reboot, Reboot System);
  26. #endif /* RT_USING_FINSH */
  27. /**
  28. * This function will delay for some us.
  29. *
  30. * @param us the delay time of us
  31. */
  32. void rt_hw_us_delay(rt_uint32_t us)
  33. {
  34. rt_uint32_t ticks;
  35. rt_uint32_t told, tnow, tcnt = 0;
  36. rt_uint32_t reload = SysTick->LOAD;
  37. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  38. told = SysTick->VAL;
  39. while (1)
  40. {
  41. tnow = SysTick->VAL;
  42. if (tnow != told)
  43. {
  44. if (tnow < told)
  45. {
  46. tcnt += told - tnow;
  47. }
  48. else
  49. {
  50. tcnt += reload - tnow + told;
  51. }
  52. told = tnow;
  53. if (tcnt >= ticks)
  54. {
  55. break;
  56. }
  57. }
  58. }
  59. }