board.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (C) 2022 Shanghai Eastsoft Microelectronics Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Change Logs:
  19. * Date Author Notes
  20. * 2022-02-10 Lisq the first version
  21. */
  22. #include "board.h"
  23. /**
  24. * @addtogroup es32
  25. */
  26. /*@{*/
  27. /*******************************************************************************
  28. * Function Name : SystemClock_Configuration
  29. * Description : Configures the System Clock.
  30. * Input : None
  31. * Output : None
  32. * Return : None
  33. *******************************************************************************/
  34. void SystemClock_Config(void)
  35. {
  36. /* Configure system clock */
  37. ald_cmu_pll_config(ALD_CMU_PLL_INPUT_HOSC8M, ALD_CMU_PLL_OUTPUT_72M);
  38. ald_cmu_clock_config(ALD_CMU_CLOCK_PLL, 72000000);
  39. /* Enable all peripherals */
  40. ald_cmu_perh_clock_config(ALD_CMU_PERH_ALL, ENABLE);
  41. __enable_irq();
  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. ald_cmu_init();
  53. }
  54. /**
  55. * This is the timer interrupt service routine.
  56. *
  57. */
  58. void __attribute__((interrupt)) CLINT_Handler(void)
  59. {
  60. /* enter interrupt */
  61. rt_interrupt_enter();
  62. csi_coret_clr(ald_cmu_get_clock() / RT_TICK_PER_SECOND, CLINT_IRQn);
  63. ald_inc_tick();
  64. rt_tick_increase();
  65. /* leave interrupt */
  66. rt_interrupt_leave();
  67. }
  68. void __attribute__((interrupt)) DMA_Handler(void)
  69. {
  70. /* enter interrupt */
  71. rt_interrupt_enter();
  72. ald_dma_irq_handler();
  73. /* leave interrupt */
  74. rt_interrupt_leave();
  75. }
  76. /*@}*/
  77. /**
  78. * This function will initial ES32F0 board.
  79. */
  80. void rt_hw_board_init(void)
  81. {
  82. csi_vic_set_prio(MACHINE_MODE_SOFT_IRQn, 0);
  83. csi_vic_enable_sirq(MACHINE_MODE_SOFT_IRQn);
  84. CLIC->CLICINT[MACHINE_MODE_SOFT_IRQn].ATTR |= (3);
  85. csi_vic_set_prio(DMA_IRQn, 4);
  86. csi_vic_enable_sirq(DMA_IRQn);
  87. csi_cpu_sleep_wfi(MEXSTATUS_SLEEP_DEEP);
  88. /*System Clock Configuration */
  89. SystemClock_Config();
  90. /* Configure the SysTick */
  91. SysTick_Configuration();
  92. #ifdef RT_USING_HEAP
  93. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  94. #endif
  95. #ifdef RT_USING_COMPONENTS_INIT
  96. rt_components_board_init();
  97. #endif
  98. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  99. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  100. #endif
  101. }
  102. /**
  103. * This function will delay for some us.
  104. *
  105. * @param us the delay time of us
  106. */
  107. void rt_hw_us_delay(rt_uint32_t us)
  108. {
  109. unsigned int start, now, delta, reload, us_tick;
  110. start = CORET->MTIME;
  111. reload = CORET->MTIMECMP;
  112. us_tick = ald_cmu_get_clock() / 1000000UL;
  113. do
  114. {
  115. now = CORET->MTIME;
  116. delta = start > now ? start - now : reload + start - now;
  117. }
  118. while (delta < us_tick * us);
  119. }
  120. void rt_trigger_software_interrupt(void)
  121. {
  122. *((uint8_t*)0xE080100C) = 0x1;
  123. }
  124. void rt_hw_do_after_save_above(void)
  125. {
  126. }