drv_common.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2021, 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. FINSH_FUNCTION_EXPORT_ALIAS(reboot, __cmd_reboot, Reboot System);
  26. MSH_CMD_EXPORT(reboot, Reboot System);
  27. #endif /* RT_USING_FINSH */
  28. /**
  29. * This function will delay for some us.
  30. *
  31. * @param us the delay time of us
  32. */
  33. void rt_hw_us_delay(rt_uint32_t us)
  34. {
  35. rt_uint32_t ticks;
  36. rt_uint32_t told, tnow, tcnt = 0;
  37. rt_uint32_t reload = SysTick->LOAD;
  38. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  39. told = SysTick->VAL;
  40. while (1)
  41. {
  42. tnow = SysTick->VAL;
  43. if (tnow != told)
  44. {
  45. if (tnow < told)
  46. {
  47. tcnt += told - tnow;
  48. }
  49. else
  50. {
  51. tcnt += reload - tnow + told;
  52. }
  53. told = tnow;
  54. if (tcnt >= ticks)
  55. {
  56. break;
  57. }
  58. }
  59. }
  60. }