1 //*****************************************************************************
2 // MK02F12810 startup code for use with MCUXpresso IDE
3 //
4 // Version : 160420
5 //*****************************************************************************
6 //
7 // Copyright 2016-2020 NXP
8 // All rights reserved.
9 //
10 // SPDX-License-Identifier: BSD-3-Clause
11 //*****************************************************************************
12 
13 #if defined (DEBUG)
14 #pragma GCC push_options
15 #pragma GCC optimize ("Og")
16 #endif // (DEBUG)
17 
18 #if defined (__cplusplus)
19 #ifdef __REDLIB__
20 #error Redlib does not support C++
21 #else
22 //*****************************************************************************
23 //
24 // The entry point for the C++ library startup
25 //
26 //*****************************************************************************
27 extern "C" {
28     extern void __libc_init_array(void);
29 }
30 #endif
31 #endif
32 
33 #define WEAK __attribute__ ((weak))
34 #define WEAK_AV __attribute__ ((weak, section(".after_vectors")))
35 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
36 
37 //*****************************************************************************
38 #if defined (__cplusplus)
39 extern "C" {
40 #endif
41 
42 //*****************************************************************************
43 // Flash Configuration block : 16-byte flash configuration field that stores
44 // default protection settings (loaded on reset) and security information that
45 // allows the MCU to restrict access to the Flash Memory module.
46 // Placed at address 0x400 by the linker script.
47 //*****************************************************************************
48 __attribute__ ((used,section(".FlashConfig"))) const struct {
49     unsigned int word1;
50     unsigned int word2;
51     unsigned int word3;
52     unsigned int word4;
53 } Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE};
54 //*****************************************************************************
55 // Declaration of external SystemInit function
56 //*****************************************************************************
57 #if defined (__USE_CMSIS)
58 extern void SystemInit(void);
59 #endif // (__USE_CMSIS)
60 
61 //*****************************************************************************
62 // Forward declaration of the core exception handlers.
63 // When the application defines a handler (with the same name), this will
64 // automatically take precedence over these weak definitions.
65 // If your application is a C++ one, then any interrupt handlers defined
66 // in C++ files within in your main application will need to have C linkage
67 // rather than C++ linkage. To do this, make sure that you are using extern "C"
68 // { .... } around the interrupt handler within your main application code.
69 //*****************************************************************************
70      void ResetISR(void);
71 WEAK void NMI_Handler(void);
72 WEAK void HardFault_Handler(void);
73 WEAK void MemManage_Handler(void);
74 WEAK void BusFault_Handler(void);
75 WEAK void UsageFault_Handler(void);
76 WEAK void SVC_Handler(void);
77 WEAK void DebugMon_Handler(void);
78 WEAK void PendSV_Handler(void);
79 WEAK void SysTick_Handler(void);
80 WEAK void IntDefaultHandler(void);
81 
82 //*****************************************************************************
83 // Forward declaration of the application IRQ handlers. When the application
84 // defines a handler (with the same name), this will automatically take
85 // precedence over weak definitions below
86 //*****************************************************************************
87 WEAK void DMA0_IRQHandler(void);
88 WEAK void DMA1_IRQHandler(void);
89 WEAK void DMA2_IRQHandler(void);
90 WEAK void DMA3_IRQHandler(void);
91 WEAK void Reserved20_IRQHandler(void);
92 WEAK void Reserved21_IRQHandler(void);
93 WEAK void Reserved22_IRQHandler(void);
94 WEAK void Reserved23_IRQHandler(void);
95 WEAK void Reserved24_IRQHandler(void);
96 WEAK void Reserved25_IRQHandler(void);
97 WEAK void Reserved26_IRQHandler(void);
98 WEAK void Reserved27_IRQHandler(void);
99 WEAK void Reserved28_IRQHandler(void);
100 WEAK void Reserved29_IRQHandler(void);
101 WEAK void Reserved30_IRQHandler(void);
102 WEAK void Reserved31_IRQHandler(void);
103 WEAK void DMA_Error_IRQHandler(void);
104 WEAK void MCM_IRQHandler(void);
105 WEAK void FTF_IRQHandler(void);
106 WEAK void Read_Collision_IRQHandler(void);
107 WEAK void LVD_LVW_IRQHandler(void);
108 WEAK void LLWU_IRQHandler(void);
109 WEAK void WDOG_EWM_IRQHandler(void);
110 WEAK void Reserved39_IRQHandler(void);
111 WEAK void I2C0_IRQHandler(void);
112 WEAK void Reserved41_IRQHandler(void);
113 WEAK void SPI0_IRQHandler(void);
114 WEAK void Reserved43_IRQHandler(void);
115 WEAK void Reserved44_IRQHandler(void);
116 WEAK void Reserved45_IRQHandler(void);
117 WEAK void Reserved46_IRQHandler(void);
118 WEAK void UART0_RX_TX_IRQHandler(void);
119 WEAK void UART0_ERR_IRQHandler(void);
120 WEAK void UART1_RX_TX_IRQHandler(void);
121 WEAK void UART1_ERR_IRQHandler(void);
122 WEAK void Reserved51_IRQHandler(void);
123 WEAK void Reserved52_IRQHandler(void);
124 WEAK void Reserved53_IRQHandler(void);
125 WEAK void Reserved54_IRQHandler(void);
126 WEAK void ADC0_IRQHandler(void);
127 WEAK void CMP0_IRQHandler(void);
128 WEAK void CMP1_IRQHandler(void);
129 WEAK void FTM0_IRQHandler(void);
130 WEAK void FTM1_IRQHandler(void);
131 WEAK void FTM2_IRQHandler(void);
132 WEAK void Reserved61_IRQHandler(void);
133 WEAK void Reserved62_IRQHandler(void);
134 WEAK void Reserved63_IRQHandler(void);
135 WEAK void PIT0_IRQHandler(void);
136 WEAK void PIT1_IRQHandler(void);
137 WEAK void PIT2_IRQHandler(void);
138 WEAK void PIT3_IRQHandler(void);
139 WEAK void PDB0_IRQHandler(void);
140 WEAK void Reserved69_IRQHandler(void);
141 WEAK void Reserved70_IRQHandler(void);
142 WEAK void Reserved71_IRQHandler(void);
143 WEAK void DAC0_IRQHandler(void);
144 WEAK void MCG_IRQHandler(void);
145 WEAK void LPTMR0_IRQHandler(void);
146 WEAK void PORTA_IRQHandler(void);
147 WEAK void PORTB_IRQHandler(void);
148 WEAK void PORTC_IRQHandler(void);
149 WEAK void PORTD_IRQHandler(void);
150 WEAK void PORTE_IRQHandler(void);
151 WEAK void SWI_IRQHandler(void);
152 
153 //*****************************************************************************
154 // Forward declaration of the driver IRQ handlers. These are aliased
155 // to the IntDefaultHandler, which is a 'forever' loop. When the driver
156 // defines a handler (with the same name), this will automatically take
157 // precedence over these weak definitions
158 //*****************************************************************************
159 void DMA0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
160 void DMA1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
161 void DMA2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
162 void DMA3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
163 void Reserved20_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
164 void Reserved21_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
165 void Reserved22_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
166 void Reserved23_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
167 void Reserved24_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
168 void Reserved25_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
169 void Reserved26_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
170 void Reserved27_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
171 void Reserved28_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
172 void Reserved29_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
173 void Reserved30_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
174 void Reserved31_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
175 void DMA_Error_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
176 void MCM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
177 void FTF_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
178 void Read_Collision_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
179 void LVD_LVW_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
180 void LLWU_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
181 void WDOG_EWM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
182 void Reserved39_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
183 void I2C0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
184 void Reserved41_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
185 void SPI0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
186 void Reserved43_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
187 void Reserved44_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
188 void Reserved45_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
189 void Reserved46_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
190 void UART0_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
191 void UART0_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
192 void UART1_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
193 void UART1_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
194 void Reserved51_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
195 void Reserved52_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
196 void Reserved53_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
197 void Reserved54_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
198 void ADC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
199 void CMP0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
200 void CMP1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
201 void FTM0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
202 void FTM1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
203 void FTM2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
204 void Reserved61_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
205 void Reserved62_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
206 void Reserved63_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
207 void PIT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
208 void PIT1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
209 void PIT2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
210 void PIT3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
211 void PDB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
212 void Reserved69_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
213 void Reserved70_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
214 void Reserved71_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
215 void DAC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
216 void MCG_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
217 void LPTMR0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
218 void PORTA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
219 void PORTB_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
220 void PORTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
221 void PORTD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
222 void PORTE_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
223 void SWI_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
224 
225 //*****************************************************************************
226 // The entry point for the application.
227 // __main() is the entry point for Redlib based applications
228 // main() is the entry point for Newlib based applications
229 //*****************************************************************************
230 #if defined (__REDLIB__)
231 extern void __main(void);
232 #endif
233 extern int main(void);
234 
235 //*****************************************************************************
236 // External declaration for the pointer to the stack top from the Linker Script
237 //*****************************************************************************
238 extern void _vStackTop(void);
239 //*****************************************************************************
240 #if defined (__cplusplus)
241 } // extern "C"
242 #endif
243 //*****************************************************************************
244 // The vector table.
245 // This relies on the linker script to place at correct location in memory.
246 //*****************************************************************************
247 
248 
249 
250 extern void (* const g_pfnVectors[])(void);
251 extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
252 
253 __attribute__ ((used, section(".isr_vector")))
254 void (* const g_pfnVectors[])(void) = {
255     // Core Level - CM4
256     &_vStackTop,                       // The initial stack pointer
257     ResetISR,                          // The reset handler
258     NMI_Handler,                       // The NMI handler
259     HardFault_Handler,                 // The hard fault handler
260     MemManage_Handler,                 // The MPU fault handler
261     BusFault_Handler,                  // The bus fault handler
262     UsageFault_Handler,                // The usage fault handler
263     0,                                 // Reserved
264     0,                                 // Reserved
265     0,                                 // Reserved
266     0,                                 // Reserved
267     SVC_Handler,                       // SVCall handler
268     DebugMon_Handler,                  // Debug monitor handler
269     0,                                 // Reserved
270     PendSV_Handler,                    // The PendSV handler
271     SysTick_Handler,                   // The SysTick handler
272 
273     // Chip Level - MK02F12810
274     DMA0_IRQHandler,            // 16: DMA Channel 0 Transfer Complete
275     DMA1_IRQHandler,            // 17: DMA Channel 1 Transfer Complete
276     DMA2_IRQHandler,            // 18: DMA Channel 2 Transfer Complete
277     DMA3_IRQHandler,            // 19: DMA Channel 3 Transfer Complete
278     Reserved20_IRQHandler,      // 20: Reserved interrupt
279     Reserved21_IRQHandler,      // 21: Reserved interrupt
280     Reserved22_IRQHandler,      // 22: Reserved interrupt
281     Reserved23_IRQHandler,      // 23: Reserved interrupt
282     Reserved24_IRQHandler,      // 24: Reserved interrupt
283     Reserved25_IRQHandler,      // 25: Reserved interrupt
284     Reserved26_IRQHandler,      // 26: Reserved interrupt
285     Reserved27_IRQHandler,      // 27: Reserved interrupt
286     Reserved28_IRQHandler,      // 28: Reserved interrupt
287     Reserved29_IRQHandler,      // 29: Reserved interrupt
288     Reserved30_IRQHandler,      // 30: Reserved interrupt
289     Reserved31_IRQHandler,      // 31: Reserved interrupt
290     DMA_Error_IRQHandler,       // 32: DMA Error Interrupt
291     MCM_IRQHandler,             // 33: Normal Interrupt
292     FTF_IRQHandler,             // 34: FTFA Command complete interrupt
293     Read_Collision_IRQHandler,  // 35: Read Collision Interrupt
294     LVD_LVW_IRQHandler,         // 36: Low Voltage Detect, Low Voltage Warning
295     LLWU_IRQHandler,            // 37: Low Leakage Wakeup Unit
296     WDOG_EWM_IRQHandler,        // 38: WDOG Interrupt
297     Reserved39_IRQHandler,      // 39: Reserved interrupt
298     I2C0_IRQHandler,            // 40: I2C0 interrupt
299     Reserved41_IRQHandler,      // 41: Reserved interrupt
300     SPI0_IRQHandler,            // 42: SPI0 Interrupt
301     Reserved43_IRQHandler,      // 43: Reserved interrupt
302     Reserved44_IRQHandler,      // 44: Reserved interrupt
303     Reserved45_IRQHandler,      // 45: Reserved interrupt
304     Reserved46_IRQHandler,      // 46: Reserved interrupt
305     UART0_RX_TX_IRQHandler,     // 47: UART0 Receive/Transmit interrupt
306     UART0_ERR_IRQHandler,       // 48: UART0 Error interrupt
307     UART1_RX_TX_IRQHandler,     // 49: UART1 Receive/Transmit interrupt
308     UART1_ERR_IRQHandler,       // 50: UART1 Error interrupt
309     Reserved51_IRQHandler,      // 51: Reserved interrupt
310     Reserved52_IRQHandler,      // 52: Reserved interrupt
311     Reserved53_IRQHandler,      // 53: Reserved interrupt
312     Reserved54_IRQHandler,      // 54: Reserved interrupt
313     ADC0_IRQHandler,            // 55: ADC0 interrupt
314     CMP0_IRQHandler,            // 56: CMP0 interrupt
315     CMP1_IRQHandler,            // 57: CMP1 interrupt
316     FTM0_IRQHandler,            // 58: FTM0 fault, overflow and channels interrupt
317     FTM1_IRQHandler,            // 59: FTM1 fault, overflow and channels interrupt
318     FTM2_IRQHandler,            // 60: FTM2 fault, overflow and channels interrupt
319     Reserved61_IRQHandler,      // 61: Reserved interrupt
320     Reserved62_IRQHandler,      // 62: Reserved interrupt
321     Reserved63_IRQHandler,      // 63: Reserved interrupt
322     PIT0_IRQHandler,            // 64: PIT timer channel 0 interrupt
323     PIT1_IRQHandler,            // 65: PIT timer channel 1 interrupt
324     PIT2_IRQHandler,            // 66: PIT timer channel 2 interrupt
325     PIT3_IRQHandler,            // 67: PIT timer channel 3 interrupt
326     PDB0_IRQHandler,            // 68: PDB0 Interrupt
327     Reserved69_IRQHandler,      // 69: Reserved interrupt
328     Reserved70_IRQHandler,      // 70: Reserved interrupt
329     Reserved71_IRQHandler,      // 71: Reserved interrupt
330     DAC0_IRQHandler,            // 72: DAC0 interrupt
331     MCG_IRQHandler,             // 73: MCG Interrupt
332     LPTMR0_IRQHandler,          // 74: LPTimer interrupt
333     PORTA_IRQHandler,           // 75: Port A interrupt
334     PORTB_IRQHandler,           // 76: Port B interrupt
335     PORTC_IRQHandler,           // 77: Port C interrupt
336     PORTD_IRQHandler,           // 78: Port D interrupt
337     PORTE_IRQHandler,           // 79: Port E interrupt
338     SWI_IRQHandler,             // 80: Software interrupt
339 
340 
341 }; /* End of g_pfnVectors */
342 
343 //*****************************************************************************
344 // Functions to carry out the initialization of RW and BSS data sections. These
345 // are written as separate functions rather than being inlined within the
346 // ResetISR() function in order to cope with MCUs with multiple banks of
347 // memory.
348 //*****************************************************************************
349 __attribute__ ((section(".after_vectors.init_data")))
data_init(unsigned int romstart,unsigned int start,unsigned int len)350 void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
351     unsigned int *pulDest = (unsigned int*) start;
352     unsigned int *pulSrc = (unsigned int*) romstart;
353     unsigned int loop;
354     for (loop = 0; loop < len; loop = loop + 4)
355         *pulDest++ = *pulSrc++;
356 }
357 
358 __attribute__ ((section(".after_vectors.init_bss")))
bss_init(unsigned int start,unsigned int len)359 void bss_init(unsigned int start, unsigned int len) {
360     unsigned int *pulDest = (unsigned int*) start;
361     unsigned int loop;
362     for (loop = 0; loop < len; loop = loop + 4)
363         *pulDest++ = 0;
364 }
365 
366 //*****************************************************************************
367 // The following symbols are constructs generated by the linker, indicating
368 // the location of various points in the "Global Section Table". This table is
369 // created by the linker via the Code Red managed linker script mechanism. It
370 // contains the load address, execution address and length of each RW data
371 // section and the execution and length of each BSS (zero initialized) section.
372 //*****************************************************************************
373 extern unsigned int __data_section_table;
374 extern unsigned int __data_section_table_end;
375 extern unsigned int __bss_section_table;
376 extern unsigned int __bss_section_table_end;
377 
378 //*****************************************************************************
379 // Reset entry point for your code.
380 // Sets up a simple runtime environment and initializes the C/C++
381 // library.
382 //*****************************************************************************
383 __attribute__ ((naked, section(".after_vectors.reset")))
ResetISR(void)384 void ResetISR(void) {
385 
386     // Disable interrupts
387     __asm volatile ("cpsid i");
388 
389 
390 #if defined (__USE_CMSIS)
391 // If __USE_CMSIS defined, then call CMSIS SystemInit code
392     SystemInit();
393 
394 #else
395     // Disable Watchdog
396     //  Write 0xC520 to watchdog unlock register
397     *((volatile unsigned short *)0x4005200E) = 0xC520;
398     //  Followed by 0xD928 to complete the unlock
399     *((volatile unsigned short *)0x4005200E) = 0xD928;
400     // Now disable watchdog via STCTRLH register
401     *((volatile unsigned short *)0x40052000) = 0x01D2u;
402 #endif // (__USE_CMSIS)
403 
404     //
405     // Copy the data sections from flash to SRAM.
406     //
407     unsigned int LoadAddr, ExeAddr, SectionLen;
408     unsigned int *SectionTableAddr;
409 
410     // Load base address of Global Section Table
411     SectionTableAddr = &__data_section_table;
412 
413     // Copy the data sections from flash to SRAM.
414     while (SectionTableAddr < &__data_section_table_end) {
415         LoadAddr = *SectionTableAddr++;
416         ExeAddr = *SectionTableAddr++;
417         SectionLen = *SectionTableAddr++;
418         data_init(LoadAddr, ExeAddr, SectionLen);
419     }
420 
421     // At this point, SectionTableAddr = &__bss_section_table;
422     // Zero fill the bss segment
423     while (SectionTableAddr < &__bss_section_table_end) {
424         ExeAddr = *SectionTableAddr++;
425         SectionLen = *SectionTableAddr++;
426         bss_init(ExeAddr, SectionLen);
427     }
428 
429 #if !defined (__USE_CMSIS)
430 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
431 // will enable the FPU
432 #if defined (__VFP_FP__) && !defined (__SOFTFP__)
433     //
434     // Code to enable the Cortex-M4 FPU only included
435     // if appropriate build options have been selected.
436     // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)
437     //
438     // Read CPACR (located at address 0xE000ED88)
439     // Set bits 20-23 to enable CP10 and CP11 coprocessors
440     // Write back the modified value to the CPACR
441     asm volatile ("LDR.W R0, =0xE000ED88\n\t"
442                   "LDR R1, [R0]\n\t"
443                   "ORR R1, R1, #(0xF << 20)\n\t"
444                   "STR R1, [R0]");
445 #endif // (__VFP_FP__) && !(__SOFTFP__)
446 #endif // (__USE_CMSIS)
447 
448 
449 #if !defined (__USE_CMSIS)
450 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
451 // will setup the VTOR register
452 
453     // Check to see if we are running the code from a non-zero
454     // address (eg RAM, external flash), in which case we need
455     // to modify the VTOR register to tell the CPU that the
456     // vector table is located at a non-0x0 address.
457     unsigned int * pSCB_VTOR = (unsigned int *) 0xE000ED08;
458     if ((unsigned int *)g_pfnVectors!=(unsigned int *) 0x00000000) {
459         *pSCB_VTOR = (unsigned int)g_pfnVectors;
460     }
461 #endif // (__USE_CMSIS)
462 #if defined (__cplusplus)
463     //
464     // Call C++ library initialisation
465     //
466     __libc_init_array();
467 #endif
468 
469     // Reenable interrupts
470     __asm volatile ("cpsie i");
471 
472 #if defined (__REDLIB__)
473     // Call the Redlib library, which in turn calls main()
474     __main();
475 #else
476     main();
477 #endif
478 
479     //
480     // main() shouldn't return, but if it does, we'll just enter an infinite loop
481     //
482     while (1) {
483         ;
484     }
485 }
486 
487 //*****************************************************************************
488 // Default core exception handlers. Override the ones here by defining your own
489 // handler routines in your application code.
490 //*****************************************************************************
NMI_Handler(void)491 WEAK_AV void NMI_Handler(void)
492 { while(1) {}
493 }
494 
HardFault_Handler(void)495 WEAK_AV void HardFault_Handler(void)
496 { while(1) {}
497 }
498 
MemManage_Handler(void)499 WEAK_AV void MemManage_Handler(void)
500 { while(1) {}
501 }
502 
BusFault_Handler(void)503 WEAK_AV void BusFault_Handler(void)
504 { while(1) {}
505 }
506 
UsageFault_Handler(void)507 WEAK_AV void UsageFault_Handler(void)
508 { while(1) {}
509 }
510 
SVC_Handler(void)511 WEAK_AV void SVC_Handler(void)
512 { while(1) {}
513 }
514 
DebugMon_Handler(void)515 WEAK_AV void DebugMon_Handler(void)
516 { while(1) {}
517 }
518 
PendSV_Handler(void)519 WEAK_AV void PendSV_Handler(void)
520 { while(1) {}
521 }
522 
SysTick_Handler(void)523 WEAK_AV void SysTick_Handler(void)
524 { while(1) {}
525 }
526 
527 //*****************************************************************************
528 // Processor ends up here if an unexpected interrupt occurs or a specific
529 // handler is not present in the application code.
530 //*****************************************************************************
IntDefaultHandler(void)531 WEAK_AV void IntDefaultHandler(void)
532 { while(1) {}
533 }
534 
535 //*****************************************************************************
536 // Default application exception handlers. Override the ones here by defining
537 // your own handler routines in your application code. These routines call
538 // driver exception handlers or IntDefaultHandler() if no driver exception
539 // handler is included.
540 //*****************************************************************************
DMA0_IRQHandler(void)541 WEAK void DMA0_IRQHandler(void)
542 {   DMA0_DriverIRQHandler();
543 }
544 
DMA1_IRQHandler(void)545 WEAK void DMA1_IRQHandler(void)
546 {   DMA1_DriverIRQHandler();
547 }
548 
DMA2_IRQHandler(void)549 WEAK void DMA2_IRQHandler(void)
550 {   DMA2_DriverIRQHandler();
551 }
552 
DMA3_IRQHandler(void)553 WEAK void DMA3_IRQHandler(void)
554 {   DMA3_DriverIRQHandler();
555 }
556 
Reserved20_IRQHandler(void)557 WEAK void Reserved20_IRQHandler(void)
558 {   Reserved20_DriverIRQHandler();
559 }
560 
Reserved21_IRQHandler(void)561 WEAK void Reserved21_IRQHandler(void)
562 {   Reserved21_DriverIRQHandler();
563 }
564 
Reserved22_IRQHandler(void)565 WEAK void Reserved22_IRQHandler(void)
566 {   Reserved22_DriverIRQHandler();
567 }
568 
Reserved23_IRQHandler(void)569 WEAK void Reserved23_IRQHandler(void)
570 {   Reserved23_DriverIRQHandler();
571 }
572 
Reserved24_IRQHandler(void)573 WEAK void Reserved24_IRQHandler(void)
574 {   Reserved24_DriverIRQHandler();
575 }
576 
Reserved25_IRQHandler(void)577 WEAK void Reserved25_IRQHandler(void)
578 {   Reserved25_DriverIRQHandler();
579 }
580 
Reserved26_IRQHandler(void)581 WEAK void Reserved26_IRQHandler(void)
582 {   Reserved26_DriverIRQHandler();
583 }
584 
Reserved27_IRQHandler(void)585 WEAK void Reserved27_IRQHandler(void)
586 {   Reserved27_DriverIRQHandler();
587 }
588 
Reserved28_IRQHandler(void)589 WEAK void Reserved28_IRQHandler(void)
590 {   Reserved28_DriverIRQHandler();
591 }
592 
Reserved29_IRQHandler(void)593 WEAK void Reserved29_IRQHandler(void)
594 {   Reserved29_DriverIRQHandler();
595 }
596 
Reserved30_IRQHandler(void)597 WEAK void Reserved30_IRQHandler(void)
598 {   Reserved30_DriverIRQHandler();
599 }
600 
Reserved31_IRQHandler(void)601 WEAK void Reserved31_IRQHandler(void)
602 {   Reserved31_DriverIRQHandler();
603 }
604 
DMA_Error_IRQHandler(void)605 WEAK void DMA_Error_IRQHandler(void)
606 {   DMA_Error_DriverIRQHandler();
607 }
608 
MCM_IRQHandler(void)609 WEAK void MCM_IRQHandler(void)
610 {   MCM_DriverIRQHandler();
611 }
612 
FTF_IRQHandler(void)613 WEAK void FTF_IRQHandler(void)
614 {   FTF_DriverIRQHandler();
615 }
616 
Read_Collision_IRQHandler(void)617 WEAK void Read_Collision_IRQHandler(void)
618 {   Read_Collision_DriverIRQHandler();
619 }
620 
LVD_LVW_IRQHandler(void)621 WEAK void LVD_LVW_IRQHandler(void)
622 {   LVD_LVW_DriverIRQHandler();
623 }
624 
LLWU_IRQHandler(void)625 WEAK void LLWU_IRQHandler(void)
626 {   LLWU_DriverIRQHandler();
627 }
628 
WDOG_EWM_IRQHandler(void)629 WEAK void WDOG_EWM_IRQHandler(void)
630 {   WDOG_EWM_DriverIRQHandler();
631 }
632 
Reserved39_IRQHandler(void)633 WEAK void Reserved39_IRQHandler(void)
634 {   Reserved39_DriverIRQHandler();
635 }
636 
I2C0_IRQHandler(void)637 WEAK void I2C0_IRQHandler(void)
638 {   I2C0_DriverIRQHandler();
639 }
640 
Reserved41_IRQHandler(void)641 WEAK void Reserved41_IRQHandler(void)
642 {   Reserved41_DriverIRQHandler();
643 }
644 
SPI0_IRQHandler(void)645 WEAK void SPI0_IRQHandler(void)
646 {   SPI0_DriverIRQHandler();
647 }
648 
Reserved43_IRQHandler(void)649 WEAK void Reserved43_IRQHandler(void)
650 {   Reserved43_DriverIRQHandler();
651 }
652 
Reserved44_IRQHandler(void)653 WEAK void Reserved44_IRQHandler(void)
654 {   Reserved44_DriverIRQHandler();
655 }
656 
Reserved45_IRQHandler(void)657 WEAK void Reserved45_IRQHandler(void)
658 {   Reserved45_DriverIRQHandler();
659 }
660 
Reserved46_IRQHandler(void)661 WEAK void Reserved46_IRQHandler(void)
662 {   Reserved46_DriverIRQHandler();
663 }
664 
UART0_RX_TX_IRQHandler(void)665 WEAK void UART0_RX_TX_IRQHandler(void)
666 {   UART0_RX_TX_DriverIRQHandler();
667 }
668 
UART0_ERR_IRQHandler(void)669 WEAK void UART0_ERR_IRQHandler(void)
670 {   UART0_ERR_DriverIRQHandler();
671 }
672 
UART1_RX_TX_IRQHandler(void)673 WEAK void UART1_RX_TX_IRQHandler(void)
674 {   UART1_RX_TX_DriverIRQHandler();
675 }
676 
UART1_ERR_IRQHandler(void)677 WEAK void UART1_ERR_IRQHandler(void)
678 {   UART1_ERR_DriverIRQHandler();
679 }
680 
Reserved51_IRQHandler(void)681 WEAK void Reserved51_IRQHandler(void)
682 {   Reserved51_DriverIRQHandler();
683 }
684 
Reserved52_IRQHandler(void)685 WEAK void Reserved52_IRQHandler(void)
686 {   Reserved52_DriverIRQHandler();
687 }
688 
Reserved53_IRQHandler(void)689 WEAK void Reserved53_IRQHandler(void)
690 {   Reserved53_DriverIRQHandler();
691 }
692 
Reserved54_IRQHandler(void)693 WEAK void Reserved54_IRQHandler(void)
694 {   Reserved54_DriverIRQHandler();
695 }
696 
ADC0_IRQHandler(void)697 WEAK void ADC0_IRQHandler(void)
698 {   ADC0_DriverIRQHandler();
699 }
700 
CMP0_IRQHandler(void)701 WEAK void CMP0_IRQHandler(void)
702 {   CMP0_DriverIRQHandler();
703 }
704 
CMP1_IRQHandler(void)705 WEAK void CMP1_IRQHandler(void)
706 {   CMP1_DriverIRQHandler();
707 }
708 
FTM0_IRQHandler(void)709 WEAK void FTM0_IRQHandler(void)
710 {   FTM0_DriverIRQHandler();
711 }
712 
FTM1_IRQHandler(void)713 WEAK void FTM1_IRQHandler(void)
714 {   FTM1_DriverIRQHandler();
715 }
716 
FTM2_IRQHandler(void)717 WEAK void FTM2_IRQHandler(void)
718 {   FTM2_DriverIRQHandler();
719 }
720 
Reserved61_IRQHandler(void)721 WEAK void Reserved61_IRQHandler(void)
722 {   Reserved61_DriverIRQHandler();
723 }
724 
Reserved62_IRQHandler(void)725 WEAK void Reserved62_IRQHandler(void)
726 {   Reserved62_DriverIRQHandler();
727 }
728 
Reserved63_IRQHandler(void)729 WEAK void Reserved63_IRQHandler(void)
730 {   Reserved63_DriverIRQHandler();
731 }
732 
PIT0_IRQHandler(void)733 WEAK void PIT0_IRQHandler(void)
734 {   PIT0_DriverIRQHandler();
735 }
736 
PIT1_IRQHandler(void)737 WEAK void PIT1_IRQHandler(void)
738 {   PIT1_DriverIRQHandler();
739 }
740 
PIT2_IRQHandler(void)741 WEAK void PIT2_IRQHandler(void)
742 {   PIT2_DriverIRQHandler();
743 }
744 
PIT3_IRQHandler(void)745 WEAK void PIT3_IRQHandler(void)
746 {   PIT3_DriverIRQHandler();
747 }
748 
PDB0_IRQHandler(void)749 WEAK void PDB0_IRQHandler(void)
750 {   PDB0_DriverIRQHandler();
751 }
752 
Reserved69_IRQHandler(void)753 WEAK void Reserved69_IRQHandler(void)
754 {   Reserved69_DriverIRQHandler();
755 }
756 
Reserved70_IRQHandler(void)757 WEAK void Reserved70_IRQHandler(void)
758 {   Reserved70_DriverIRQHandler();
759 }
760 
Reserved71_IRQHandler(void)761 WEAK void Reserved71_IRQHandler(void)
762 {   Reserved71_DriverIRQHandler();
763 }
764 
DAC0_IRQHandler(void)765 WEAK void DAC0_IRQHandler(void)
766 {   DAC0_DriverIRQHandler();
767 }
768 
MCG_IRQHandler(void)769 WEAK void MCG_IRQHandler(void)
770 {   MCG_DriverIRQHandler();
771 }
772 
LPTMR0_IRQHandler(void)773 WEAK void LPTMR0_IRQHandler(void)
774 {   LPTMR0_DriverIRQHandler();
775 }
776 
PORTA_IRQHandler(void)777 WEAK void PORTA_IRQHandler(void)
778 {   PORTA_DriverIRQHandler();
779 }
780 
PORTB_IRQHandler(void)781 WEAK void PORTB_IRQHandler(void)
782 {   PORTB_DriverIRQHandler();
783 }
784 
PORTC_IRQHandler(void)785 WEAK void PORTC_IRQHandler(void)
786 {   PORTC_DriverIRQHandler();
787 }
788 
PORTD_IRQHandler(void)789 WEAK void PORTD_IRQHandler(void)
790 {   PORTD_DriverIRQHandler();
791 }
792 
PORTE_IRQHandler(void)793 WEAK void PORTE_IRQHandler(void)
794 {   PORTE_DriverIRQHandler();
795 }
796 
SWI_IRQHandler(void)797 WEAK void SWI_IRQHandler(void)
798 {   SWI_DriverIRQHandler();
799 }
800 
801 //*****************************************************************************
802 
803 #if defined (DEBUG)
804 #pragma GCC pop_options
805 #endif // (DEBUG)
806