board.c 2.9 KB

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