board.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-07-11 wangyq the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "drv_uart.h"
  14. #include "drv_gpio.h"
  15. #include <lib_scu.h>
  16. #include <lib_gpio.h>
  17. /**
  18. * @addtogroup es8p
  19. */
  20. /*@{*/
  21. /*******************************************************************************
  22. * Function Name : NVIC_Configuration
  23. * Description : Configures Vector Table base location.
  24. * Input : None
  25. * Output : None
  26. * Return : None
  27. *******************************************************************************/
  28. void NVIC_Configuration(void)
  29. {
  30. }
  31. /*******************************************************************************
  32. * Function Name : SystemClock_Configuration
  33. * Description : Configures the System Clock.
  34. * Input : None
  35. * Output : None
  36. * Return : None
  37. *******************************************************************************/
  38. void SystemClock_Config(void)
  39. {
  40. /* system clock 48MHz */
  41. PLLClock_Config(ENABLE, SCU_PLL_HRC, SCU_PLL_48M, ENABLE);
  42. }
  43. /*******************************************************************************
  44. * Function Name : SysTick_Configuration
  45. * Description : Configures the SysTick for OS tick.
  46. * Input : None
  47. * Output : None
  48. * Return : None
  49. *******************************************************************************/
  50. void SysTick_Configuration(void)
  51. {
  52. /* ticks = SYS_CLK / RT_TICK_PER_SECOND */
  53. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  54. }
  55. /**
  56. * This is the timer interrupt service routine.
  57. *
  58. */
  59. void systick_irq_cbk(void)
  60. {
  61. /* enter interrupt */
  62. rt_interrupt_enter();
  63. rt_tick_increase();
  64. /* leave interrupt */
  65. rt_interrupt_leave();
  66. }
  67. /*@}*/
  68. /**
  69. * This function will initial es8p board.
  70. */
  71. void rt_hw_board_init(void)
  72. {
  73. /* NVIC Configuration */
  74. NVIC_Configuration();
  75. /*System Clock Configuration */
  76. SystemClock_Config();
  77. /* Configure the SysTick */
  78. SysTick_Configuration();
  79. #ifdef RT_USING_HEAP
  80. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  81. #endif
  82. #ifdef RT_USING_COMPONENTS_INIT
  83. rt_components_board_init();
  84. #endif
  85. #ifdef RT_USING_CONSOLE
  86. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  87. #endif
  88. }
  89. /**
  90. * This function will delay for some us.
  91. *
  92. * @param us the delay time of us
  93. */
  94. void rt_hw_us_delay(rt_uint32_t us)
  95. {
  96. unsigned int start, now, delta, reload, us_tick;
  97. start = SysTick->VAL;
  98. reload = SysTick->LOAD;
  99. us_tick = SystemCoreClock / 1000000UL;
  100. do
  101. {
  102. now = SysTick->VAL;
  103. delta = start > now ? start - now : reload + start - now;
  104. }
  105. while (delta < us_tick * us);
  106. }