board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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-01-04 iysheng first version
  9. * 2021-09-07 idk500 suit for Vango V85xx
  10. * 2021-09-08 ZhuXW add delay function
  11. */
  12. #include <stdint.h>
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include <target.h>
  16. #include <board.h>
  17. #include <drv_usart.h>
  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. }
  38. /*
  39. * This is the timer interrupt service routine.
  40. */
  41. void SysTick_Handler(void)
  42. {
  43. /* enter interrupt */
  44. rt_interrupt_enter();
  45. rt_tick_increase();
  46. /* leave interrupt */
  47. rt_interrupt_leave();
  48. }
  49. /**
  50. * This function will initial V85xx board.
  51. */
  52. void rt_hw_board_init()
  53. {
  54. SystemClock_Config();
  55. #ifdef RT_USING_COMPONENTS_INIT
  56. rt_components_board_init();
  57. #endif
  58. #ifdef RT_USING_CONSOLE
  59. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  60. #endif
  61. #ifdef BSP_USING_SDRAM
  62. rt_system_heap_init((void *)EXT_SDRAM_BEGIN, (void *)EXT_SDRAM_END);
  63. #else
  64. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  65. #endif
  66. }
  67. void rt_hw_us_delay(rt_uint32_t us)
  68. {
  69. rt_uint32_t ticks;
  70. rt_uint32_t told, tnow, tcnt = 0;
  71. rt_uint32_t reload = SysTick->LOAD;
  72. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  73. told = SysTick->VAL;
  74. while (1)
  75. {
  76. tnow = SysTick->VAL;
  77. if (tnow != told)
  78. {
  79. if (tnow < told)
  80. {
  81. tcnt += told - tnow;
  82. }
  83. else
  84. {
  85. tcnt += reload - tnow + told;
  86. }
  87. told = tnow;
  88. if (tcnt >= ticks)
  89. {
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. /*@}*/