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
13 #include "board.h"
14 #include "drv_uart.h"
15
system_clock_init(void)16 static void system_clock_init(void)
17 {
18 GLB_Set_System_CLK(GLB_PLL_XTAL_40M, GLB_SYS_CLK_PLL192M);
19 GLB_Set_MTimer_CLK(1, GLB_MTIMER_CLK_BCLK, 95);
20 }
21
peripheral_clock_init(void)22 static void peripheral_clock_init(void)
23 {
24 PERIPHERAL_CLOCK_ADC_DAC_ENABLE();
25 PERIPHERAL_CLOCK_SEC_ENABLE();
26 PERIPHERAL_CLOCK_DMA0_ENABLE();
27 PERIPHERAL_CLOCK_UART0_ENABLE();
28 PERIPHERAL_CLOCK_UART1_ENABLE();
29 PERIPHERAL_CLOCK_SPI0_ENABLE();
30 PERIPHERAL_CLOCK_I2C0_ENABLE();
31 PERIPHERAL_CLOCK_PWM0_ENABLE();
32 PERIPHERAL_CLOCK_TIMER0_1_WDG_ENABLE();
33
34 GLB_Set_UART_CLK(ENABLE, HBN_UART_CLK_160M, 0);
35 GLB_Set_SPI_CLK(ENABLE, 0);
36 GLB_Set_I2C_CLK(ENABLE, 0);
37
38 GLB_Set_ADC_CLK(ENABLE, GLB_ADC_CLK_XCLK, 1);
39 GLB_Set_DAC_CLK(ENABLE, GLB_DAC_CLK_XCLK, 0x3E);
40 }
41
42 /* This is the timer interrupt service routine. */
systick_isr(void)43 static void systick_isr(void)
44 {
45 rt_tick_increase();
46 }
47
rt_hw_board_init(void)48 void rt_hw_board_init(void)
49 {
50 bflb_flash_init();
51
52 system_clock_init();
53 peripheral_clock_init();
54 bflb_irq_initialize();
55
56 bflb_mtimer_config(HW_MTIMER_CLOCK / RT_TICK_PER_SECOND, systick_isr);
57
58 #ifdef RT_USING_HEAP
59 /* initialize memory system */
60 rt_kprintf("RT_HW_HEAP_BEGIN:%x RT_HW_HEAP_END:%x\r\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
61 rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
62 #endif
63
64 /* UART driver initialization is open by default */
65 #ifdef RT_USING_SERIAL
66 rt_hw_uart_init();
67 #endif
68
69 /* Set the shell console output device */
70 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
71 rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
72 #endif
73
74 #ifdef RT_USING_COMPONENTS_INIT
75 rt_components_board_init();
76 #endif
77 }
78
rt_hw_cpu_reset(void)79 void rt_hw_cpu_reset(void)
80 {
81 GLB_SW_POR_Reset();
82 }
83
84 MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);
85