board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-01-04 iysheng first version
  9. * 2021-09-07 FuC Suit for V85xx
  10. */
  11. #include <stdint.h>
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include <target.h>
  15. #include <board.h>
  16. #include <drv_usart.h>
  17. uint32_t SystemCoreClock;
  18. /*
  19. * System Clock Configuration
  20. */
  21. void SystemClock_Config(void)
  22. {
  23. // SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  24. NVIC_SetPriority(SysTick_IRQn, 0);
  25. CLK_InitTypeDef CLK_Struct;
  26. CLK_Struct.ClockType = CLK_TYPE_AHBSRC \
  27. |CLK_TYPE_PLLL \
  28. |CLK_TYPE_HCLK \
  29. |CLK_TYPE_PCLK;
  30. CLK_Struct.AHBSource = CLK_AHBSEL_LSPLL;
  31. CLK_Struct.PLLL.Frequency = CLK_PLLL_26_2144MHz;
  32. CLK_Struct.PLLL.Source = CLK_PLLLSRC_XTALL;
  33. CLK_Struct.PLLL.State = CLK_PLLL_ON;
  34. CLK_Struct.HCLK.Divider = 1;
  35. CLK_Struct.PCLK.Divider = 2;
  36. CLK_ClockConfig(&CLK_Struct);
  37. SystemCoreClock = 26214400UL;
  38. }
  39. /*
  40. * This is the timer interrupt service routine.
  41. */
  42. void SysTick_Handler(void)
  43. {
  44. /* enter interrupt */
  45. rt_interrupt_enter();
  46. rt_tick_increase();
  47. /* leave interrupt */
  48. rt_interrupt_leave();
  49. }
  50. /**
  51. * This function will initial V85xx board.
  52. */
  53. void rt_hw_board_init()
  54. {
  55. SystemClock_Config();
  56. #ifdef RT_USING_COMPONENTS_INIT
  57. rt_components_board_init();
  58. #endif
  59. #ifdef RT_USING_CONSOLE
  60. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  61. #endif
  62. #ifdef BSP_USING_SDRAM
  63. rt_system_heap_init((void *)EXT_SDRAM_BEGIN, (void *)EXT_SDRAM_END);
  64. #else
  65. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  66. #endif
  67. }
  68. void rt_hw_us_delay(rt_uint32_t us)
  69. {
  70. rt_uint32_t ticks;
  71. rt_uint32_t told, tnow, tcnt = 0;
  72. rt_uint32_t reload = SysTick->LOAD;
  73. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  74. told = SysTick->VAL;
  75. while (1)
  76. {
  77. tnow = SysTick->VAL;
  78. if (tnow != told)
  79. {
  80. if (tnow < told)
  81. {
  82. tcnt += told - tnow;
  83. }
  84. else
  85. {
  86. tcnt += reload - tnow + told;
  87. }
  88. told = tnow;
  89. if (tcnt >= ticks)
  90. {
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. /*@}*/