board.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-01-23 wangyq the first version
  9. * 2019-11-01 wangyq update libraries
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include "board.h"
  14. #include "drv_uart.h"
  15. #include "drv_gpio.h"
  16. #include <ald_cmu.h>
  17. #include <ald_gpio.h>
  18. /**
  19. * @addtogroup es32f0
  20. */
  21. /*@{*/
  22. /*******************************************************************************
  23. * Function Name : NVIC_Configuration
  24. * Description : Configures Vector Table base location.
  25. * Input : None
  26. * Output : None
  27. * Return : None
  28. *******************************************************************************/
  29. void NVIC_Configuration(void)
  30. {
  31. }
  32. /*******************************************************************************
  33. * Function Name : SystemClock_Configuration
  34. * Description : Configures the System Clock.
  35. * Input : None
  36. * Output : None
  37. * Return : None
  38. *******************************************************************************/
  39. void SystemClock_Config(void)
  40. {
  41. /* hosc 12MHz, from hosc/3 pll to 48MHz */
  42. ald_cmu_pll1_config(CMU_PLL1_INPUT_HOSC_3, CMU_PLL1_OUTPUT_48M);
  43. /* MCLK 48MHz*/
  44. ald_cmu_clock_config(CMU_CLOCK_PLL1, 48000000);
  45. }
  46. /*******************************************************************************
  47. * Function Name : SysTick_Configuration
  48. * Description : Configures the SysTick for OS tick.
  49. * Input : None
  50. * Output : None
  51. * Return : None
  52. *******************************************************************************/
  53. void SysTick_Configuration(void)
  54. {
  55. /* ticks = sysclk / RT_TICK_PER_SECOND */
  56. SysTick_Config(ald_cmu_get_sys_clock() / RT_TICK_PER_SECOND);
  57. }
  58. /**
  59. * This is the timer interrupt service routine.
  60. *
  61. */
  62. void SysTick_Handler(void)
  63. {
  64. /* enter interrupt */
  65. rt_interrupt_enter();
  66. rt_tick_increase();
  67. /* leave interrupt */
  68. rt_interrupt_leave();
  69. }
  70. /*@}*/
  71. /**
  72. * This function will initial ES32F0 board.
  73. */
  74. void rt_hw_board_init(void)
  75. {
  76. /* NVIC Configuration */
  77. NVIC_Configuration();
  78. /*System Clock Configuration */
  79. SystemClock_Config();
  80. /* Configure the SysTick */
  81. SysTick_Configuration();
  82. #ifdef RT_USING_HEAP
  83. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  84. #endif
  85. #ifdef RT_USING_COMPONENTS_INIT
  86. rt_components_board_init();
  87. #endif
  88. #ifdef RT_USING_CONSOLE
  89. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  90. #endif
  91. }
  92. /**
  93. * This function will delay for some us.
  94. *
  95. * @param us the delay time of us
  96. */
  97. void rt_hw_us_delay(rt_uint32_t us)
  98. {
  99. unsigned int start, now, delta, reload, us_tick;
  100. start = SysTick->VAL;
  101. reload = SysTick->LOAD;
  102. us_tick = ald_cmu_get_sys_clock() / 1000000UL;
  103. do
  104. {
  105. now = SysTick->VAL;
  106. delta = start > now ? start - now : reload + start - now;
  107. }
  108. while (delta < us_tick * us);
  109. }