]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC82X/TARGET_LPC824/TOOLCHAIN_GCC_CR/startup_LPC824_CR.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / 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
3 //
4 // Version : 140901
5 //*****************************************************************************
6 //
7 // Copyright(C) NXP Semiconductors, 2014
8 // All rights reserved.
9 //
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.
23 //
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
29 // this code.
30 //*****************************************************************************
31
32 #if defined (__cplusplus)
33 #ifdef __REDLIB__
34 #error Redlib does not support C++
35 #else
36 //*****************************************************************************
37 //
38 // The entry point for the C++ library startup
39 //
40 //*****************************************************************************
41 extern "C" {
42 extern void __libc_init_array(void);
43 }
44 #endif
45 #endif
46
47 #define WEAK __attribute__ ((weak))
48 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
49
50 //*****************************************************************************
51 #if defined (__cplusplus)
52 extern "C" {
53 #endif
54
55 //*****************************************************************************
56 #if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
57 // Declaration of external SystemInit function
58 extern void SystemInit(void);
59 #endif
60
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;
68 #endif
69
70 //*****************************************************************************
71 //
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
75 //
76 //*****************************************************************************
77 void ResetISR(void);
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);
84
85 //*****************************************************************************
86 //
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
91 //
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 //*****************************************************************************
123 //
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
127 //
128 //*****************************************************************************
129 #if defined (__REDLIB__)
130 extern void __main(void);
131 #else
132 extern int main(void);
133 #endif
134 //*****************************************************************************
135 //
136 // External declaration for the pointer to the stack top from the Linker Script
137 //
138 //*****************************************************************************
139 extern void _vStackTop(void);
140
141 //*****************************************************************************
142 #if defined (__cplusplus)
143 } // extern "C"
144 #endif
145 //*****************************************************************************
146 //
147 // The vector table.
148 // This relies on the linker script to place at correct location in memory.
149 //
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
159 0, // Reserved
160 0, // Reserved
161 0, // Reserved
162 0, // Reserved
163 0, // Reserved
164 0, // Reserved
165 0, // Reserved
166 SVC_Handler, // SVCall handler
167 0, // Reserved
168 0, // Reserved
169 PendSV_Handler, // The PendSV handler
170 SysTick_Handler, // The SysTick handler
171
172 // Chip Level - LPC82x
173 SPI0_IRQHandler, // SPI0 controller
174 SPI1_IRQHandler, // SPI1 controller
175 0, // Reserved
176 UART0_IRQHandler, // UART0
177 UART1_IRQHandler, // UART1
178 UART2_IRQHandler, // UART2
179 0, // Reserved
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
196 0, // Reserved
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 */
206
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
211 // memory.
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;
217 unsigned int loop;
218 for (loop = 0; loop < len; loop = loop + 4)
219 *pulDest++ = *pulSrc++;
220 }
221
222 __attribute__ ((section(".after_vectors")))
223 void bss_init(unsigned int start, unsigned int len) {
224 unsigned int *pulDest = (unsigned int*) start;
225 unsigned int loop;
226 for (loop = 0; loop < len; loop = loop + 4)
227 *pulDest++ = 0;
228 }
229
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;
241
242
243 //*****************************************************************************
244 // Reset entry point for your code.
245 // Sets up a simple runtime environment and initializes the C/C++
246 // library.
247 //*****************************************************************************
248 __attribute__ ((section(".after_vectors")))
249 void
250 ResetISR(void) {
251
252 //
253 // Copy the data sections from flash to SRAM.
254 //
255 unsigned int LoadAddr, ExeAddr, SectionLen;
256 unsigned int *SectionTableAddr;
257
258 // Load base address of Global Section Table
259 SectionTableAddr = &__data_section_table;
260
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);
267 }
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);
274 }
275
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];
284 #endif
285
286 #if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
287 SystemInit();
288 #endif
289
290 #if defined (__cplusplus)
291 //
292 // Call C++ library initialisation
293 //
294 __libc_init_array();
295 #endif
296
297 #if defined (__REDLIB__)
298 // Call the Redlib library, which in turn calls main()
299 __main() ;
300 #else
301 main();
302 #endif
303
304 //
305 // main() shouldn't return, but if it does, we'll just enter an infinite loop
306 //
307 while (1) {
308 ;
309 }
310 }
311
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)
318 { while(1) {}
319 }
320
321 __attribute__ ((section(".after_vectors")))
322 void HardFault_Handler(void)
323 { while(1) {}
324 }
325
326 __attribute__ ((section(".after_vectors")))
327 void SVC_Handler(void)
328 { while(1) {}
329 }
330
331 __attribute__ ((section(".after_vectors")))
332 void PendSV_Handler(void)
333 { while(1) {}
334 }
335
336 __attribute__ ((section(".after_vectors")))
337 void SysTick_Handler(void)
338 { while(1) {}
339 }
340
341 //*****************************************************************************
342 //
343 // Processor ends up here if an unexpected interrupt occurs or a specific
344 // handler is not present in the application code.
345 //
346 //*****************************************************************************
347 __attribute__ ((section(".after_vectors")))
348 void IntDefaultHandler(void)
349 { while(1) {}
350 }
351
Imprint / Impressum