1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2009-01-05     Bernard      first implementation
9  * 2010-02-04     Magicoe      ported to LPC17xx
10  * 2010-05-02     Aozima       update CMSIS to 130
11  * 2017-08-02     XiaoYang     porting to LPC54608 bsp
12  */
13 
14 #include <rthw.h>
15 #include <rtthread.h>
16 
17 #include "board.h"
18 #include "clock_config.h"
19 #include "drv_uart.h"
20 #include "drv_sdram.h"
21 
22 /**
23  * This is the timer interrupt service routine.
24  *
25  */
SysTick_Handler(void)26 void SysTick_Handler(void)
27 {
28     /* enter interrupt */
29     rt_interrupt_enter();
30 
31     rt_tick_increase();
32 
33     /* leave interrupt */
34     rt_interrupt_leave();
35 }
36 
37 /**
38  * This function will initial LPC54xx board.
39  */
rt_hw_board_init()40 void rt_hw_board_init()
41 {
42     /* Hardware Initialization */
43     CLOCK_EnableClock(kCLOCK_InputMux);
44     CLOCK_EnableClock(kCLOCK_Iocon);
45 
46     /* NVIC Configuration */
47 #define NVIC_VTOR_MASK              0x3FFFFF80
48 #ifdef  VECT_TAB_RAM
49     /* Set the Vector Table base location at 0x10000000 */
50     SCB->VTOR  = (0x10000000 & NVIC_VTOR_MASK);
51 #else  /* VECT_TAB_FLASH  */
52     /* Set the Vector Table base location at 0x00000000 */
53     SCB->VTOR  = (0x00000000 & NVIC_VTOR_MASK);
54 #endif
55 
56     BOARD_BootClockFROHF48M();
57     /* init systick  1 systick = 1/(100M / 100) 100 systicks = 1s*/
58     SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
59     /* set pend exception priority */
60     NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
61 
62     /* Heap initialization */
63 #ifdef RT_USING_HEAP
64 #ifdef BSP_DRV_SDRAM
65     rt_kprintf("      heap: [0x%08x - 0x%08x]\n", LPC_EXT_SDRAM_BEGIN, LPC_EXT_SDRAM_END);
66     rt_system_heap_init((void *)LPC_EXT_SDRAM_BEGIN, (void *)LPC_EXT_SDRAM_END);
67     sram_init();
68 #else
69     rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
70 #endif
71 #endif
72 
73     /*init uart device*/
74     rt_hw_uart_init();
75 
76 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
77     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
78 #endif
79 
80 #ifdef BSP_DRV_SDRAM
81     lpc_sdram_hw_init();
82 #endif
83 
84 #ifdef RT_USING_COMPONENTS_INIT
85     /* initialization board with RT-Thread Components */
86     rt_components_board_init();
87 #endif
88 }
89 
90 #ifdef PKG_USING_GUIENGINE
91 #include <rtgui/driver.h>
92 #include "drv_lcd.h"
93 
94 /* initialize for gui driver */
rtgui_lcd_init(void)95 int rtgui_lcd_init(void)
96 {
97     rt_device_t device;
98 
99     rt_hw_lcd_init();
100 
101     device = rt_device_find("lcd");
102     /* set graphic device */
103     rtgui_graphic_set_device(device);
104 
105     return 0;
106 }
107 INIT_DEVICE_EXPORT(rtgui_lcd_init);
108 #endif
109 
MemManage_Handler(void)110 void MemManage_Handler(void)
111 {
112     extern void HardFault_Handler(void);
113 
114     rt_kprintf("Memory Fault!\n");
115     HardFault_Handler();
116 }
117