]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC82X/TARGET_LPC824/TOOLCHAIN_GCC_CR/startup_LPC824_CR.cpp
1 //*****************************************************************************
2 // LPC82x Microcontroller Startup code for use with LPCXpresso IDE
5 //*****************************************************************************
7 // Copyright(C) NXP Semiconductors, 2014
8 // All rights reserved.
10 // Software that is described herein is for illustrative purposes only
11 // which provides customers with programming information regarding the
12 // LPC products. This software is supplied "AS IS" without any warranties of
13 // any kind, and NXP Semiconductors and its licensor disclaim any and
14 // all warranties, express or implied, including all implied warranties of
15 // merchantability, fitness for a particular purpose and non-infringement of
16 // intellectual property rights. NXP Semiconductors assumes no responsibility
17 // or liability for the use of the software, conveys no license or rights under any
18 // patent, copyright, mask work right, or any other intellectual property rights in
19 // or to any products. NXP Semiconductors reserves the right to make changes
20 // in the software without notification. NXP Semiconductors also makes no
21 // representation or warranty that such application will be suitable for the
22 // specified use without further testing or modification.
24 // Permission to use, copy, modify, and distribute this software and its
25 // documentation is hereby granted, under NXP Semiconductors' and its
26 // licensor's relevant copyrights in the software, without fee, provided that it
27 // is used in conjunction with NXP Semiconductors microcontrollers. This
28 // copyright, permission, and disclaimer notice must appear in all copies of
30 //*****************************************************************************
32 #if defined (__cplusplus)
34 #error Redlib does not support C++
36 //*****************************************************************************
38 // The entry point for the C++ library startup
40 //*****************************************************************************
42 extern void __libc_init_array(void);
47 #define WEAK __attribute__ ((weak))
48 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
50 //*****************************************************************************
51 #if defined (__cplusplus)
55 //*****************************************************************************
56 #if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
57 // Declaration of external SystemInit function
58 extern void SystemInit(void);
61 // Patch the AEABI integer divide functions to use MCU's romdivide library
62 #ifdef __USE_ROMDIVIDE
63 // Location in memory that holds the address of the ROM Driver table
64 #define PTR_ROM_DRIVER_TABLE ((unsigned int *)(0x1FFF1FF8))
65 // Variables to store addresses of idiv and udiv functions within MCU ROM
66 unsigned int *pDivRom_idiv
;
67 unsigned int *pDivRom_uidiv
;
70 //*****************************************************************************
72 // Forward declaration of the default handlers. These are aliased.
73 // When the application defines a handler (with the same name), this will
74 // automatically take precedence over these weak definitions
76 //*****************************************************************************
78 WEAK
void NMI_Handler(void);
79 WEAK
void HardFault_Handler(void);
80 WEAK
void SVC_Handler(void);
81 WEAK
void PendSV_Handler(void);
82 WEAK
void SysTick_Handler(void);
83 WEAK
void IntDefaultHandler(void);
85 //*****************************************************************************
87 // Forward declaration of the specific IRQ handlers. These are aliased
88 // to the IntDefaultHandler, which is a 'forever' loop. When the application
89 // defines a handler (with the same name), this will automatically take
90 // precedence over these weak definitions
92 //*****************************************************************************
93 void SPI0_IRQHandler(void) ALIAS(IntDefaultHandler
);
94 void SPI1_IRQHandler(void) ALIAS(IntDefaultHandler
);
95 void UART0_IRQHandler(void) ALIAS(IntDefaultHandler
);
96 void UART1_IRQHandler(void) ALIAS(IntDefaultHandler
);
97 void UART2_IRQHandler(void) ALIAS(IntDefaultHandler
);
98 void I2C1_IRQHandler(void) ALIAS(IntDefaultHandler
);
99 void I2C0_IRQHandler(void) ALIAS(IntDefaultHandler
);
100 void SCT_IRQHandler(void) ALIAS(IntDefaultHandler
);
101 void MRT_IRQHandler(void) ALIAS(IntDefaultHandler
);
102 void CMP_IRQHandler(void) ALIAS(IntDefaultHandler
);
103 void WDT_IRQHandler(void) ALIAS(IntDefaultHandler
);
104 void BOD_IRQHandler(void) ALIAS(IntDefaultHandler
);
105 void FLASH_IRQHandler(void) ALIAS(IntDefaultHandler
);
106 void WKT_IRQHandler(void) ALIAS(IntDefaultHandler
);
107 void ADC_SEQA_IRQHandler(void) ALIAS(IntDefaultHandler
);
108 void ADC_SEQB_IRQHandler(void) ALIAS(IntDefaultHandler
);
109 void ADC_THCMP_IRQHandler(void) ALIAS(IntDefaultHandler
);
110 void ADC_OVR_IRQHandler(void) ALIAS(IntDefaultHandler
);
111 void DMA_IRQHandler(void) ALIAS(IntDefaultHandler
);
112 void I2C2_IRQHandler(void) ALIAS(IntDefaultHandler
);
113 void I2C3_IRQHandler(void) ALIAS(IntDefaultHandler
);
114 void PIN_INT0_IRQHandler(void) ALIAS(IntDefaultHandler
);
115 void PIN_INT1_IRQHandler(void) ALIAS(IntDefaultHandler
);
116 void PIN_INT2_IRQHandler(void) ALIAS(IntDefaultHandler
);
117 void PIN_INT3_IRQHandler(void) ALIAS(IntDefaultHandler
);
118 void PIN_INT4_IRQHandler(void) ALIAS(IntDefaultHandler
);
119 void PIN_INT5_IRQHandler(void) ALIAS(IntDefaultHandler
);
120 void PIN_INT6_IRQHandler(void) ALIAS(IntDefaultHandler
);
121 void PIN_INT7_IRQHandler(void) ALIAS(IntDefaultHandler
);
122 //*****************************************************************************
124 // The entry point for the application.
125 // __main() is the entry point for Redlib based applications
126 // main() is the entry point for Newlib based applications
128 //*****************************************************************************
129 #if defined (__REDLIB__)
130 extern void __main(void);
132 extern int main(void);
134 //*****************************************************************************
136 // External declaration for the pointer to the stack top from the Linker Script
138 //*****************************************************************************
139 extern void _vStackTop(void);
141 //*****************************************************************************
142 #if defined (__cplusplus)
145 //*****************************************************************************
148 // This relies on the linker script to place at correct location in memory.
150 //*****************************************************************************
151 extern void (* const g_pfnVectors
[])(void);
152 __attribute__ ((section(".isr_vector")))
153 void (* const g_pfnVectors
[])(void) = {
154 // Core Level - CM0plus
155 &_vStackTop
, // The initial stack pointer
156 ResetISR
, // The reset handler
157 NMI_Handler
, // The NMI handler
158 HardFault_Handler
, // The hard fault handler
166 SVC_Handler
, // SVCall handler
169 PendSV_Handler
, // The PendSV handler
170 SysTick_Handler
, // The SysTick handler
172 // Chip Level - LPC82x
173 SPI0_IRQHandler
, // SPI0 controller
174 SPI1_IRQHandler
, // SPI1 controller
176 UART0_IRQHandler
, // UART0
177 UART1_IRQHandler
, // UART1
178 UART2_IRQHandler
, // UART2
180 I2C1_IRQHandler
, // I2C1 controller
181 I2C0_IRQHandler
, // I2C0 controller
182 SCT_IRQHandler
, // Smart Counter Timer
183 MRT_IRQHandler
, // Multi-Rate Timer
184 CMP_IRQHandler
, // Comparator
185 WDT_IRQHandler
, // Watchdog
186 BOD_IRQHandler
, // Brown Out Detect
187 FLASH_IRQHandler
, // Flash Interrupt
188 WKT_IRQHandler
, // Wakeup timer
189 ADC_SEQA_IRQHandler
, // ADC sequence A completion
190 ADC_SEQB_IRQHandler
, // ADC sequence B completion
191 ADC_THCMP_IRQHandler
, // ADC threshold compare
192 ADC_OVR_IRQHandler
, // ADC overrun
193 DMA_IRQHandler
, // DMA
194 I2C2_IRQHandler
, // I2C2 controller
195 I2C3_IRQHandler
, // I2C3 controller
197 PIN_INT0_IRQHandler
, // PIO INT0
198 PIN_INT1_IRQHandler
, // PIO INT1
199 PIN_INT2_IRQHandler
, // PIO INT2
200 PIN_INT3_IRQHandler
, // PIO INT3
201 PIN_INT4_IRQHandler
, // PIO INT4
202 PIN_INT5_IRQHandler
, // PIO INT5
203 PIN_INT6_IRQHandler
, // PIO INT6
204 PIN_INT7_IRQHandler
, // PIO INT7
205 }; /* End of g_pfnVectors */
207 //*****************************************************************************
208 // Functions to carry out the initialization of RW and BSS data sections. These
209 // are written as separate functions rather than being inlined within the
210 // ResetISR() function in order to cope with MCUs with multiple banks of
212 //*****************************************************************************
213 __attribute__ ((section(".after_vectors")))
214 void data_init(unsigned int romstart
, unsigned int start
, unsigned int len
) {
215 unsigned int *pulDest
= (unsigned int*) start
;
216 unsigned int *pulSrc
= (unsigned int*) romstart
;
218 for (loop
= 0; loop
< len
; loop
= loop
+ 4)
219 *pulDest
++ = *pulSrc
++;
222 __attribute__ ((section(".after_vectors")))
223 void bss_init(unsigned int start
, unsigned int len
) {
224 unsigned int *pulDest
= (unsigned int*) start
;
226 for (loop
= 0; loop
< len
; loop
= loop
+ 4)
230 //*****************************************************************************
231 // The following symbols are constructs generated by the linker, indicating
232 // the location of various points in the "Global Section Table". This table is
233 // created by the linker via the Code Red managed linker script mechanism. It
234 // contains the load address, execution address and length of each RW data
235 // section and the execution and length of each BSS (zero initialized) section.
236 //*****************************************************************************
237 extern unsigned int __data_section_table
;
238 extern unsigned int __data_section_table_end
;
239 extern unsigned int __bss_section_table
;
240 extern unsigned int __bss_section_table_end
;
243 //*****************************************************************************
244 // Reset entry point for your code.
245 // Sets up a simple runtime environment and initializes the C/C++
247 //*****************************************************************************
248 __attribute__ ((section(".after_vectors")))
253 // Copy the data sections from flash to SRAM.
255 unsigned int LoadAddr
, ExeAddr
, SectionLen
;
256 unsigned int *SectionTableAddr
;
258 // Load base address of Global Section Table
259 SectionTableAddr
= &__data_section_table
;
261 // Copy the data sections from flash to SRAM.
262 while (SectionTableAddr
< &__data_section_table_end
) {
263 LoadAddr
= *SectionTableAddr
++;
264 ExeAddr
= *SectionTableAddr
++;
265 SectionLen
= *SectionTableAddr
++;
266 data_init(LoadAddr
, ExeAddr
, SectionLen
);
268 // At this point, SectionTableAddr = &__bss_section_table;
269 // Zero fill the bss segment
270 while (SectionTableAddr
< &__bss_section_table_end
) {
271 ExeAddr
= *SectionTableAddr
++;
272 SectionLen
= *SectionTableAddr
++;
273 bss_init(ExeAddr
, SectionLen
);
276 // Patch the AEABI integer divide functions to use MCU's romdivide library
277 #ifdef __USE_ROMDIVIDE
278 // Get address of Integer division routines function table in ROM
279 unsigned int *div_ptr
= (unsigned int *)((unsigned int *)*(PTR_ROM_DRIVER_TABLE
))[4];
280 // Get addresses of integer divide routines in ROM
281 // These address are then used by the code in aeabi_romdiv_patch.s
282 pDivRom_idiv
= (unsigned int *)div_ptr
[0];
283 pDivRom_uidiv
= (unsigned int *)div_ptr
[1];
286 #if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
290 #if defined (__cplusplus)
292 // Call C++ library initialisation
297 #if defined (__REDLIB__)
298 // Call the Redlib library, which in turn calls main()
305 // main() shouldn't return, but if it does, we'll just enter an infinite loop
312 //*****************************************************************************
313 // Default exception handlers. Override the ones here by defining your own
314 // handler routines in your application code.
315 //*****************************************************************************
316 __attribute__ ((section(".after_vectors")))
317 void NMI_Handler(void)
321 __attribute__ ((section(".after_vectors")))
322 void HardFault_Handler(void)
326 __attribute__ ((section(".after_vectors")))
327 void SVC_Handler(void)
331 __attribute__ ((section(".after_vectors")))
332 void PendSV_Handler(void)
336 __attribute__ ((section(".after_vectors")))
337 void SysTick_Handler(void)
341 //*****************************************************************************
343 // Processor ends up here if an unexpected interrupt occurs or a specific
344 // handler is not present in the application code.
346 //*****************************************************************************
347 __attribute__ ((section(".after_vectors")))
348 void IntDefaultHandler(void)