board.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023/03/15 flyingcys first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "drv_uart.h"
  14. static void system_clock_init(void)
  15. {
  16. GLB_Set_System_CLK(GLB_PLL_XTAL_40M, GLB_SYS_CLK_PLL192M);
  17. GLB_Set_MTimer_CLK(1, GLB_MTIMER_CLK_BCLK, 95);
  18. }
  19. static void peripheral_clock_init(void)
  20. {
  21. PERIPHERAL_CLOCK_ADC_DAC_ENABLE();
  22. PERIPHERAL_CLOCK_SEC_ENABLE();
  23. PERIPHERAL_CLOCK_DMA0_ENABLE();
  24. PERIPHERAL_CLOCK_UART0_ENABLE();
  25. PERIPHERAL_CLOCK_UART1_ENABLE();
  26. PERIPHERAL_CLOCK_SPI0_ENABLE();
  27. PERIPHERAL_CLOCK_I2C0_ENABLE();
  28. PERIPHERAL_CLOCK_PWM0_ENABLE();
  29. PERIPHERAL_CLOCK_TIMER0_1_WDG_ENABLE();
  30. GLB_Set_UART_CLK(ENABLE, HBN_UART_CLK_160M, 0);
  31. GLB_Set_SPI_CLK(ENABLE, 0);
  32. GLB_Set_I2C_CLK(ENABLE, 0);
  33. GLB_Set_ADC_CLK(ENABLE, GLB_ADC_CLK_XCLK, 1);
  34. GLB_Set_DAC_CLK(ENABLE, GLB_DAC_CLK_XCLK, 0x3E);
  35. }
  36. /* This is the timer interrupt service routine. */
  37. static void systick_isr(void)
  38. {
  39. rt_tick_increase();
  40. }
  41. void rt_hw_board_init(void)
  42. {
  43. bflb_flash_init();
  44. system_clock_init();
  45. peripheral_clock_init();
  46. bflb_irq_initialize();
  47. bflb_mtimer_config(HW_MTIMER_CLOCK / RT_TICK_PER_SECOND, systick_isr);
  48. #ifdef RT_USING_HEAP
  49. /* initialize memory system */
  50. rt_kprintf("RT_HW_HEAP_BEGIN:%x RT_HW_HEAP_END:%x\r\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  51. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  52. #endif
  53. /* UART driver initialization is open by default */
  54. #ifdef RT_USING_SERIAL
  55. rt_hw_uart_init();
  56. #endif
  57. /* Set the shell console output device */
  58. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  59. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  60. #endif
  61. #ifdef RT_USING_COMPONENTS_INIT
  62. rt_components_board_init();
  63. #endif
  64. }
  65. void rt_hw_cpu_reset(void)
  66. {
  67. GLB_SW_POR_Reset();
  68. }
  69. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);