board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2014 RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2014-11-23 Bright first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. #include "usart.h"
  18. /* RT_USING_COMPONENTS_INIT */
  19. #ifdef RT_USING_COMPONENTS_INIT
  20. #include <components.h>
  21. #endif
  22. /**
  23. * @addtogroup NUVOTON_M05X
  24. */
  25. /*@{*/
  26. /*******************************************************************************
  27. * Function Name : NVIC_Configuration
  28. * Description : Configures Vector Table base location.
  29. * Input : None
  30. * Output : None
  31. * Return : None
  32. *******************************************************************************/
  33. void NVIC_Configuration(void)
  34. {
  35. // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  36. }
  37. /**
  38. * @brief Inserts a delay time.
  39. * @param nCount: specifies the delay time length.
  40. * @retval None
  41. */
  42. static void delay(__IO uint32_t nCount)
  43. {
  44. /* Decrement nCount value */
  45. while (nCount != 0)
  46. {
  47. nCount--;
  48. }
  49. }
  50. static void rt_hw_system_init(void)
  51. {
  52. /*---------------------------------------------------------------------------------------------------------*/
  53. /* Init System Clock */
  54. /*---------------------------------------------------------------------------------------------------------*/
  55. SYS_UnlockReg();
  56. /* Enable Internal RC 22.1184MHz clock */
  57. CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
  58. /* Waiting for Internal RC clock ready */
  59. CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
  60. /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
  61. CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
  62. /* Set core clock as PLL_CLOCK from PLL */
  63. CLK_SetCoreClock(BOARD_PLL_CLOCK);
  64. /* Set SysTick clock source to HCLK source divide 2 */
  65. CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLK_S_HCLK_DIV2);
  66. SYS_LockReg();
  67. }
  68. /**
  69. * This is the timer interrupt service routine.
  70. *
  71. */
  72. void SysTick_Handler(void)
  73. {
  74. /* enter interrupt */
  75. rt_interrupt_enter();
  76. rt_tick_increase();
  77. /* leave interrupt */
  78. rt_interrupt_leave();
  79. }
  80. /**
  81. * This function will initial Nuvoton board.
  82. */
  83. void rt_hw_board_init()
  84. {
  85. /* NVIC Configuration */
  86. NVIC_Configuration();
  87. /* Configure the system clock */
  88. rt_hw_system_init();
  89. /* Configure the SysTick */
  90. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  91. /* Initial usart deriver, and set console device */
  92. rt_hw_usart_init();
  93. #ifdef RT_USING_CONSOLE
  94. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  95. #endif
  96. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  97. #ifdef RT_USING_COMPONENTS_INIT
  98. rt_components_board_init();
  99. #endif
  100. }
  101. /*@}*/