board.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /**
  19. * @addtogroup NUVOTON_M05X
  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. // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  32. }
  33. /**
  34. * @brief Inserts a delay time.
  35. * @param nCount: specifies the delay time length.
  36. * @retval None
  37. */
  38. static void delay(__IO uint32_t nCount)
  39. {
  40. /* Decrement nCount value */
  41. while (nCount != 0)
  42. {
  43. nCount--;
  44. }
  45. }
  46. static void rt_hw_system_init(void)
  47. {
  48. /*---------------------------------------------------------------------------------------------------------*/
  49. /* Init System Clock */
  50. /*---------------------------------------------------------------------------------------------------------*/
  51. SYS_UnlockReg();
  52. /* Enable Internal RC 22.1184MHz clock */
  53. CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
  54. /* Waiting for Internal RC clock ready */
  55. CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
  56. /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
  57. CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
  58. /* Set core clock as PLL_CLOCK from PLL */
  59. CLK_SetCoreClock(BOARD_PLL_CLOCK);
  60. /* Set SysTick clock source to HCLK source divide 2 */
  61. CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLK_S_HCLK_DIV2);
  62. SYS_LockReg();
  63. }
  64. /**
  65. * This is the timer interrupt service routine.
  66. *
  67. */
  68. void SysTick_Handler(void)
  69. {
  70. /* enter interrupt */
  71. rt_interrupt_enter();
  72. rt_tick_increase();
  73. /* leave interrupt */
  74. rt_interrupt_leave();
  75. }
  76. /**
  77. * This function will initial Nuvoton board.
  78. */
  79. void rt_hw_board_init()
  80. {
  81. /* NVIC Configuration */
  82. NVIC_Configuration();
  83. /* Configure the system clock */
  84. rt_hw_system_init();
  85. /* Configure the SysTick */
  86. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  87. /* Initial usart deriver, and set console device */
  88. rt_hw_usart_init();
  89. #ifdef RT_USING_CONSOLE
  90. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  91. #endif
  92. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  93. #ifdef RT_USING_COMPONENTS_INIT
  94. rt_components_board_init();
  95. #endif
  96. }
  97. /*@}*/