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  */
12 
13 #include <rthw.h>
14 #include <rtthread.h>
15 
16 #include "uart.h"
17 #include "board.h"
18 #include "LPC177x_8x.h"
19 #include "system_LPC177x_8x.h"
20 #include "sdram.h"
21 
22 /**
23  * @addtogroup LPC17xx
24  */
25 
26 /*@{*/
27 
28 /**
29  * This is the timer interrupt service routine.
30  *
31  */
32 
SysTick_Handler(void)33 void SysTick_Handler(void)
34 {
35     /* enter interrupt */
36     rt_interrupt_enter();
37 
38     rt_tick_increase();
39 
40     /* leave interrupt */
41     rt_interrupt_leave();
42 }
43 
44 /**
45  * This function will initial LPC17xx board.
46  */
rt_hw_board_init()47 void rt_hw_board_init()
48 {
49     /* NVIC Configuration */
50 #define NVIC_VTOR_MASK              0x3FFFFF80
51 #ifdef  VECT_TAB_RAM
52     /* Set the Vector Table base location at 0x10000000 */
53     SCB->VTOR  = (0x10000000 & NVIC_VTOR_MASK);
54 #else  /* VECT_TAB_FLASH  */
55     /* Set the Vector Table base location at 0x00000000 */
56     SCB->VTOR  = (0x00000000 & NVIC_VTOR_MASK);
57 #endif
58 
59     /* init systick */
60     SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND);
61     /* set pend exception priority */
62     NVIC_SetPriority(PendSV_IRQn, (1<<__NVIC_PRIO_BITS) - 1);
63 
64 #ifdef RT_USING_HEAP
65     /* initialize memory system */
66     #ifdef __CC_ARM
67         rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)(0x10000000 + 1024*64));
68     #elif __ICCARM__
69         rt_system_heap_init(__segment_end("HEAP"), (void*)(0x10000000 + 1024*64));
70     #else
71         rt_system_heap_init((void*)&__bss_end, (void*)(0x10000000 + 1024*64));
72     #endif
73 #endif
74 
75     /* USART driver initialization is open by default */
76 #ifdef RT_USING_SERIAL
77     rt_hw_usart_init();
78 #endif
79 
80     /* Set the shell console output device */
81 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
82     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
83 #endif
84 
85     /* Board underlying hardware initialization */
86 #ifdef RT_USING_COMPONENTS_INIT
87     rt_components_board_init();
88 #endif
89 
90 #if LPC_EXT_SDRAM == 1
91     {
92         SDRAM_Init();
93     }
94 #endif
95 }
96 
97 /*@}*/
98