board.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2006-2018, Synwit Technology Co.,Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-31 ZYH first version
  9. * 2018-12-10 Zohar_Lee format file
  10. */
  11. #include "board.h"
  12. static void bsp_clock_config(void)
  13. {
  14. SystemInit();
  15. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  16. SysTick->CTRL |= 0x00000004UL;
  17. }
  18. void SysTick_Handler(void)
  19. {
  20. /* enter interrupt */
  21. rt_interrupt_enter();
  22. rt_tick_increase();
  23. /* leave interrupt */
  24. rt_interrupt_leave();
  25. }
  26. /**
  27. * This function will delay for some us.
  28. *
  29. * @param us the delay time of us
  30. */
  31. void rt_hw_us_delay(rt_uint32_t us)
  32. {
  33. rt_uint32_t ticks;
  34. rt_uint32_t told, tnow, tcnt = 0;
  35. rt_uint32_t reload = SysTick->LOAD;
  36. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  37. told = SysTick->VAL;
  38. while (1)
  39. {
  40. tnow = SysTick->VAL;
  41. if (tnow != told)
  42. {
  43. if (tnow < told)
  44. {
  45. tcnt += told - tnow;
  46. }
  47. else
  48. {
  49. tcnt += reload - tnow + told;
  50. }
  51. told = tnow;
  52. if (tcnt >= ticks)
  53. {
  54. break;
  55. }
  56. }
  57. }
  58. }
  59. void rt_hw_board_init()
  60. {
  61. bsp_clock_config();
  62. #ifdef RT_USING_HEAP
  63. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  64. #endif
  65. #ifdef RT_USING_COMPONENTS_INIT
  66. rt_components_board_init();
  67. #endif
  68. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  69. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  70. #endif
  71. }