1 //*****************************************************************************
2 // MK64F12 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 DMA4_IRQHandler(void);
92 WEAK void DMA5_IRQHandler(void);
93 WEAK void DMA6_IRQHandler(void);
94 WEAK void DMA7_IRQHandler(void);
95 WEAK void DMA8_IRQHandler(void);
96 WEAK void DMA9_IRQHandler(void);
97 WEAK void DMA10_IRQHandler(void);
98 WEAK void DMA11_IRQHandler(void);
99 WEAK void DMA12_IRQHandler(void);
100 WEAK void DMA13_IRQHandler(void);
101 WEAK void DMA14_IRQHandler(void);
102 WEAK void DMA15_IRQHandler(void);
103 WEAK void DMA_Error_IRQHandler(void);
104 WEAK void MCM_IRQHandler(void);
105 WEAK void FTFE_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 RNG_IRQHandler(void);
111 WEAK void I2C0_IRQHandler(void);
112 WEAK void I2C1_IRQHandler(void);
113 WEAK void SPI0_IRQHandler(void);
114 WEAK void SPI1_IRQHandler(void);
115 WEAK void I2S0_Tx_IRQHandler(void);
116 WEAK void I2S0_Rx_IRQHandler(void);
117 WEAK void UART0_LON_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 UART2_RX_TX_IRQHandler(void);
123 WEAK void UART2_ERR_IRQHandler(void);
124 WEAK void UART3_RX_TX_IRQHandler(void);
125 WEAK void UART3_ERR_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 CMT_IRQHandler(void);
133 WEAK void RTC_IRQHandler(void);
134 WEAK void RTC_Seconds_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 USB0_IRQHandler(void);
141 WEAK void USBDCD_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 WEAK void SPI2_IRQHandler(void);
153 WEAK void UART4_RX_TX_IRQHandler(void);
154 WEAK void UART4_ERR_IRQHandler(void);
155 WEAK void UART5_RX_TX_IRQHandler(void);
156 WEAK void UART5_ERR_IRQHandler(void);
157 WEAK void CMP2_IRQHandler(void);
158 WEAK void FTM3_IRQHandler(void);
159 WEAK void DAC1_IRQHandler(void);
160 WEAK void ADC1_IRQHandler(void);
161 WEAK void I2C2_IRQHandler(void);
162 WEAK void CAN0_ORed_Message_buffer_IRQHandler(void);
163 WEAK void CAN0_Bus_Off_IRQHandler(void);
164 WEAK void CAN0_Error_IRQHandler(void);
165 WEAK void CAN0_Tx_Warning_IRQHandler(void);
166 WEAK void CAN0_Rx_Warning_IRQHandler(void);
167 WEAK void CAN0_Wake_Up_IRQHandler(void);
168 WEAK void SDHC_IRQHandler(void);
169 WEAK void ENET_1588_Timer_IRQHandler(void);
170 WEAK void ENET_Transmit_IRQHandler(void);
171 WEAK void ENET_Receive_IRQHandler(void);
172 WEAK void ENET_Error_IRQHandler(void);
173 
174 //*****************************************************************************
175 // Forward declaration of the driver IRQ handlers. These are aliased
176 // to the IntDefaultHandler, which is a 'forever' loop. When the driver
177 // defines a handler (with the same name), this will automatically take
178 // precedence over these weak definitions
179 //*****************************************************************************
180 void DMA0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
181 void DMA1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
182 void DMA2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
183 void DMA3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
184 void DMA4_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
185 void DMA5_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
186 void DMA6_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
187 void DMA7_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
188 void DMA8_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
189 void DMA9_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
190 void DMA10_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
191 void DMA11_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
192 void DMA12_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
193 void DMA13_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
194 void DMA14_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
195 void DMA15_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
196 void DMA_Error_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
197 void MCM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
198 void FTFE_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
199 void Read_Collision_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
200 void LVD_LVW_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
201 void LLWU_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
202 void WDOG_EWM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
203 void RNG_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
204 void I2C0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
205 void I2C1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
206 void SPI0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
207 void SPI1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
208 void I2S0_Tx_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
209 void I2S0_Rx_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
210 void UART0_LON_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
211 void UART0_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
212 void UART0_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
213 void UART1_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
214 void UART1_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
215 void UART2_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
216 void UART2_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
217 void UART3_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
218 void UART3_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
219 void ADC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
220 void CMP0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
221 void CMP1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
222 void FTM0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
223 void FTM1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
224 void FTM2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
225 void CMT_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
226 void RTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
227 void RTC_Seconds_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
228 void PIT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
229 void PIT1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
230 void PIT2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
231 void PIT3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
232 void PDB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
233 void USB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
234 void USBDCD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
235 void Reserved71_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
236 void DAC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
237 void MCG_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
238 void LPTMR0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
239 void PORTA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
240 void PORTB_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
241 void PORTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
242 void PORTD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
243 void PORTE_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
244 void SWI_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
245 void SPI2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
246 void UART4_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
247 void UART4_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
248 void UART5_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
249 void UART5_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
250 void CMP2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
251 void FTM3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
252 void DAC1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
253 void ADC1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
254 void I2C2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
255 void CAN0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
256 void SDHC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
257 void ENET_1588_Timer_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
258 void ENET_Transmit_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
259 void ENET_Receive_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
260 void ENET_Error_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
261 
262 //*****************************************************************************
263 // The entry point for the application.
264 // __main() is the entry point for Redlib based applications
265 // main() is the entry point for Newlib based applications
266 //*****************************************************************************
267 #if defined (__REDLIB__)
268 extern void __main(void);
269 #endif
270 extern int main(void);
271 
272 //*****************************************************************************
273 // External declaration for the pointer to the stack top from the Linker Script
274 //*****************************************************************************
275 extern void _vStackTop(void);
276 //*****************************************************************************
277 #if defined (__cplusplus)
278 } // extern "C"
279 #endif
280 //*****************************************************************************
281 // The vector table.
282 // This relies on the linker script to place at correct location in memory.
283 //*****************************************************************************
284 
285 
286 
287 extern void (* const g_pfnVectors[])(void);
288 extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
289 
290 __attribute__ ((used, section(".isr_vector")))
291 void (* const g_pfnVectors[])(void) = {
292     // Core Level - CM4
293     &_vStackTop,                       // The initial stack pointer
294     ResetISR,                          // The reset handler
295     NMI_Handler,                       // The NMI handler
296     HardFault_Handler,                 // The hard fault handler
297     MemManage_Handler,                 // The MPU fault handler
298     BusFault_Handler,                  // The bus fault handler
299     UsageFault_Handler,                // The usage fault handler
300     0,                                 // Reserved
301     0,                                 // Reserved
302     0,                                 // Reserved
303     0,                                 // Reserved
304     SVC_Handler,                       // SVCall handler
305     DebugMon_Handler,                  // Debug monitor handler
306     0,                                 // Reserved
307     PendSV_Handler,                    // The PendSV handler
308     SysTick_Handler,                   // The SysTick handler
309 
310     // Chip Level - MK64F12
311     DMA0_IRQHandler,                      // 16 : DMA Channel 0 Transfer Complete
312     DMA1_IRQHandler,                      // 17 : DMA Channel 1 Transfer Complete
313     DMA2_IRQHandler,                      // 18 : DMA Channel 2 Transfer Complete
314     DMA3_IRQHandler,                      // 19 : DMA Channel 3 Transfer Complete
315     DMA4_IRQHandler,                      // 20 : DMA Channel 4 Transfer Complete
316     DMA5_IRQHandler,                      // 21 : DMA Channel 5 Transfer Complete
317     DMA6_IRQHandler,                      // 22 : DMA Channel 6 Transfer Complete
318     DMA7_IRQHandler,                      // 23 : DMA Channel 7 Transfer Complete
319     DMA8_IRQHandler,                      // 24 : DMA Channel 8 Transfer Complete
320     DMA9_IRQHandler,                      // 25 : DMA Channel 9 Transfer Complete
321     DMA10_IRQHandler,                     // 26 : DMA Channel 10 Transfer Complete
322     DMA11_IRQHandler,                     // 27 : DMA Channel 11 Transfer Complete
323     DMA12_IRQHandler,                     // 28 : DMA Channel 12 Transfer Complete
324     DMA13_IRQHandler,                     // 29 : DMA Channel 13 Transfer Complete
325     DMA14_IRQHandler,                     // 30 : DMA Channel 14 Transfer Complete
326     DMA15_IRQHandler,                     // 31 : DMA Channel 15 Transfer Complete
327     DMA_Error_IRQHandler,                 // 32 : DMA Error Interrupt
328     MCM_IRQHandler,                       // 33 : Normal Interrupt
329     FTFE_IRQHandler,                      // 34 : FTFE Command complete interrupt
330     Read_Collision_IRQHandler,            // 35 : Read Collision Interrupt
331     LVD_LVW_IRQHandler,                   // 36 : Low Voltage Detect, Low Voltage Warning
332     LLWU_IRQHandler,                      // 37 : Low Leakage Wakeup Unit
333     WDOG_EWM_IRQHandler,                  // 38 : WDOG Interrupt
334     RNG_IRQHandler,                       // 39 : RNG Interrupt
335     I2C0_IRQHandler,                      // 40 : I2C0 interrupt
336     I2C1_IRQHandler,                      // 41 : I2C1 interrupt
337     SPI0_IRQHandler,                      // 42 : SPI0 Interrupt
338     SPI1_IRQHandler,                      // 43 : SPI1 Interrupt
339     I2S0_Tx_IRQHandler,                   // 44 : I2S0 transmit interrupt
340     I2S0_Rx_IRQHandler,                   // 45 : I2S0 receive interrupt
341     UART0_LON_IRQHandler,                 // 46 : UART0 LON interrupt
342     UART0_RX_TX_IRQHandler,               // 47 : UART0 Receive/Transmit interrupt
343     UART0_ERR_IRQHandler,                 // 48 : UART0 Error interrupt
344     UART1_RX_TX_IRQHandler,               // 49 : UART1 Receive/Transmit interrupt
345     UART1_ERR_IRQHandler,                 // 50 : UART1 Error interrupt
346     UART2_RX_TX_IRQHandler,               // 51 : UART2 Receive/Transmit interrupt
347     UART2_ERR_IRQHandler,                 // 52 : UART2 Error interrupt
348     UART3_RX_TX_IRQHandler,               // 53 : UART3 Receive/Transmit interrupt
349     UART3_ERR_IRQHandler,                 // 54 : UART3 Error interrupt
350     ADC0_IRQHandler,                      // 55 : ADC0 interrupt
351     CMP0_IRQHandler,                      // 56 : CMP0 interrupt
352     CMP1_IRQHandler,                      // 57 : CMP1 interrupt
353     FTM0_IRQHandler,                      // 58 : FTM0 fault, overflow and channels interrupt
354     FTM1_IRQHandler,                      // 59 : FTM1 fault, overflow and channels interrupt
355     FTM2_IRQHandler,                      // 60 : FTM2 fault, overflow and channels interrupt
356     CMT_IRQHandler,                       // 61 : CMT interrupt
357     RTC_IRQHandler,                       // 62 : RTC interrupt
358     RTC_Seconds_IRQHandler,               // 63 : RTC seconds interrupt
359     PIT0_IRQHandler,                      // 64 : PIT timer channel 0 interrupt
360     PIT1_IRQHandler,                      // 65 : PIT timer channel 1 interrupt
361     PIT2_IRQHandler,                      // 66 : PIT timer channel 2 interrupt
362     PIT3_IRQHandler,                      // 67 : PIT timer channel 3 interrupt
363     PDB0_IRQHandler,                      // 68 : PDB0 Interrupt
364     USB0_IRQHandler,                      // 69 : USB0 interrupt
365     USBDCD_IRQHandler,                    // 70 : USBDCD Interrupt
366     Reserved71_IRQHandler,                // 71 : Reserved interrupt
367     DAC0_IRQHandler,                      // 72 : DAC0 interrupt
368     MCG_IRQHandler,                       // 73 : MCG Interrupt
369     LPTMR0_IRQHandler,                    // 74 : LPTimer interrupt
370     PORTA_IRQHandler,                     // 75 : Port A interrupt
371     PORTB_IRQHandler,                     // 76 : Port B interrupt
372     PORTC_IRQHandler,                     // 77 : Port C interrupt
373     PORTD_IRQHandler,                     // 78 : Port D interrupt
374     PORTE_IRQHandler,                     // 79 : Port E interrupt
375     SWI_IRQHandler,                       // 80 : Software interrupt
376     SPI2_IRQHandler,                      // 81 : SPI2 Interrupt
377     UART4_RX_TX_IRQHandler,               // 82 : UART4 Receive/Transmit interrupt
378     UART4_ERR_IRQHandler,                 // 83 : UART4 Error interrupt
379     UART5_RX_TX_IRQHandler,               // 84 : UART5 Receive/Transmit interrupt
380     UART5_ERR_IRQHandler,                 // 85 : UART5 Error interrupt
381     CMP2_IRQHandler,                      // 86 : CMP2 interrupt
382     FTM3_IRQHandler,                      // 87 : FTM3 fault, overflow and channels interrupt
383     DAC1_IRQHandler,                      // 88 : DAC1 interrupt
384     ADC1_IRQHandler,                      // 89 : ADC1 interrupt
385     I2C2_IRQHandler,                      // 90 : I2C2 interrupt
386     CAN0_ORed_Message_buffer_IRQHandler,  // 91 : CAN0 OR'd message buffers interrupt
387     CAN0_Bus_Off_IRQHandler,              // 92 : CAN0 bus off interrupt
388     CAN0_Error_IRQHandler,                // 93 : CAN0 error interrupt
389     CAN0_Tx_Warning_IRQHandler,           // 94 : CAN0 Tx warning interrupt
390     CAN0_Rx_Warning_IRQHandler,           // 95 : CAN0 Rx warning interrupt
391     CAN0_Wake_Up_IRQHandler,              // 96 : CAN0 wake up interrupt
392     SDHC_IRQHandler,                      // 97 : SDHC interrupt
393     ENET_1588_Timer_IRQHandler,           // 98 : Ethernet MAC IEEE 1588 Timer Interrupt
394     ENET_Transmit_IRQHandler,             // 99 : Ethernet MAC Transmit Interrupt
395     ENET_Receive_IRQHandler,              // 100: Ethernet MAC Receive Interrupt
396     ENET_Error_IRQHandler,                // 101: Ethernet MAC Error and miscelaneous Interrupt
397 
398 
399 }; /* End of g_pfnVectors */
400 
401 //*****************************************************************************
402 // Functions to carry out the initialization of RW and BSS data sections. These
403 // are written as separate functions rather than being inlined within the
404 // ResetISR() function in order to cope with MCUs with multiple banks of
405 // memory.
406 //*****************************************************************************
407 __attribute__ ((section(".after_vectors.init_data")))
data_init(unsigned int romstart,unsigned int start,unsigned int len)408 void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
409     unsigned int *pulDest = (unsigned int*) start;
410     unsigned int *pulSrc = (unsigned int*) romstart;
411     unsigned int loop;
412     for (loop = 0; loop < len; loop = loop + 4)
413         *pulDest++ = *pulSrc++;
414 }
415 
416 __attribute__ ((section(".after_vectors.init_bss")))
bss_init(unsigned int start,unsigned int len)417 void bss_init(unsigned int start, unsigned int len) {
418     unsigned int *pulDest = (unsigned int*) start;
419     unsigned int loop;
420     for (loop = 0; loop < len; loop = loop + 4)
421         *pulDest++ = 0;
422 }
423 
424 //*****************************************************************************
425 // The following symbols are constructs generated by the linker, indicating
426 // the location of various points in the "Global Section Table". This table is
427 // created by the linker via the Code Red managed linker script mechanism. It
428 // contains the load address, execution address and length of each RW data
429 // section and the execution and length of each BSS (zero initialized) section.
430 //*****************************************************************************
431 extern unsigned int __data_section_table;
432 extern unsigned int __data_section_table_end;
433 extern unsigned int __bss_section_table;
434 extern unsigned int __bss_section_table_end;
435 
436 //*****************************************************************************
437 // Reset entry point for your code.
438 // Sets up a simple runtime environment and initializes the C/C++
439 // library.
440 //*****************************************************************************
441 __attribute__ ((naked, section(".after_vectors.reset")))
ResetISR(void)442 void ResetISR(void) {
443 
444     // Disable interrupts
445     __asm volatile ("cpsid i");
446 
447 
448 #if defined (__USE_CMSIS)
449 // If __USE_CMSIS defined, then call CMSIS SystemInit code
450     SystemInit();
451 
452 #else
453     // Disable Watchdog
454     //  Write 0xC520 to watchdog unlock register
455     *((volatile unsigned short *)0x4005200E) = 0xC520;
456     //  Followed by 0xD928 to complete the unlock
457     *((volatile unsigned short *)0x4005200E) = 0xD928;
458     // Now disable watchdog via STCTRLH register
459     *((volatile unsigned short *)0x40052000) = 0x01D2u;
460 #endif // (__USE_CMSIS)
461 
462     //
463     // Copy the data sections from flash to SRAM.
464     //
465     unsigned int LoadAddr, ExeAddr, SectionLen;
466     unsigned int *SectionTableAddr;
467 
468     // Load base address of Global Section Table
469     SectionTableAddr = &__data_section_table;
470 
471     // Copy the data sections from flash to SRAM.
472     while (SectionTableAddr < &__data_section_table_end) {
473         LoadAddr = *SectionTableAddr++;
474         ExeAddr = *SectionTableAddr++;
475         SectionLen = *SectionTableAddr++;
476         data_init(LoadAddr, ExeAddr, SectionLen);
477     }
478 
479     // At this point, SectionTableAddr = &__bss_section_table;
480     // Zero fill the bss segment
481     while (SectionTableAddr < &__bss_section_table_end) {
482         ExeAddr = *SectionTableAddr++;
483         SectionLen = *SectionTableAddr++;
484         bss_init(ExeAddr, SectionLen);
485     }
486 
487 #if !defined (__USE_CMSIS)
488 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
489 // will enable the FPU
490 #if defined (__VFP_FP__) && !defined (__SOFTFP__)
491     //
492     // Code to enable the Cortex-M4 FPU only included
493     // if appropriate build options have been selected.
494     // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)
495     //
496     // Read CPACR (located at address 0xE000ED88)
497     // Set bits 20-23 to enable CP10 and CP11 coprocessors
498     // Write back the modified value to the CPACR
499     asm volatile ("LDR.W R0, =0xE000ED88\n\t"
500                   "LDR R1, [R0]\n\t"
501                   "ORR R1, R1, #(0xF << 20)\n\t"
502                   "STR R1, [R0]");
503 #endif // (__VFP_FP__) && !(__SOFTFP__)
504 #endif // (__USE_CMSIS)
505 
506 
507 #if !defined (__USE_CMSIS)
508 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
509 // will setup the VTOR register
510 
511     // Check to see if we are running the code from a non-zero
512     // address (eg RAM, external flash), in which case we need
513     // to modify the VTOR register to tell the CPU that the
514     // vector table is located at a non-0x0 address.
515     unsigned int * pSCB_VTOR = (unsigned int *) 0xE000ED08;
516     if ((unsigned int *)g_pfnVectors!=(unsigned int *) 0x00000000) {
517         *pSCB_VTOR = (unsigned int)g_pfnVectors;
518     }
519 #endif // (__USE_CMSIS)
520 #if defined (__cplusplus)
521     //
522     // Call C++ library initialisation
523     //
524     __libc_init_array();
525 #endif
526 
527     // Reenable interrupts
528     __asm volatile ("cpsie i");
529 
530 #if defined (__REDLIB__)
531     // Call the Redlib library, which in turn calls main()
532     __main();
533 #else
534     main();
535 #endif
536 
537     //
538     // main() shouldn't return, but if it does, we'll just enter an infinite loop
539     //
540     while (1) {
541         ;
542     }
543 }
544 
545 //*****************************************************************************
546 // Default core exception handlers. Override the ones here by defining your own
547 // handler routines in your application code.
548 //*****************************************************************************
NMI_Handler(void)549 WEAK_AV void NMI_Handler(void)
550 { while(1) {}
551 }
552 
HardFault_Handler(void)553 WEAK_AV void HardFault_Handler(void)
554 { while(1) {}
555 }
556 
MemManage_Handler(void)557 WEAK_AV void MemManage_Handler(void)
558 { while(1) {}
559 }
560 
BusFault_Handler(void)561 WEAK_AV void BusFault_Handler(void)
562 { while(1) {}
563 }
564 
UsageFault_Handler(void)565 WEAK_AV void UsageFault_Handler(void)
566 { while(1) {}
567 }
568 
SVC_Handler(void)569 WEAK_AV void SVC_Handler(void)
570 { while(1) {}
571 }
572 
DebugMon_Handler(void)573 WEAK_AV void DebugMon_Handler(void)
574 { while(1) {}
575 }
576 
PendSV_Handler(void)577 WEAK_AV void PendSV_Handler(void)
578 { while(1) {}
579 }
580 
SysTick_Handler(void)581 WEAK_AV void SysTick_Handler(void)
582 { while(1) {}
583 }
584 
585 //*****************************************************************************
586 // Processor ends up here if an unexpected interrupt occurs or a specific
587 // handler is not present in the application code.
588 //*****************************************************************************
IntDefaultHandler(void)589 WEAK_AV void IntDefaultHandler(void)
590 { while(1) {}
591 }
592 
593 //*****************************************************************************
594 // Default application exception handlers. Override the ones here by defining
595 // your own handler routines in your application code. These routines call
596 // driver exception handlers or IntDefaultHandler() if no driver exception
597 // handler is included.
598 //*****************************************************************************
DMA0_IRQHandler(void)599 WEAK void DMA0_IRQHandler(void)
600 {   DMA0_DriverIRQHandler();
601 }
602 
DMA1_IRQHandler(void)603 WEAK void DMA1_IRQHandler(void)
604 {   DMA1_DriverIRQHandler();
605 }
606 
DMA2_IRQHandler(void)607 WEAK void DMA2_IRQHandler(void)
608 {   DMA2_DriverIRQHandler();
609 }
610 
DMA3_IRQHandler(void)611 WEAK void DMA3_IRQHandler(void)
612 {   DMA3_DriverIRQHandler();
613 }
614 
DMA4_IRQHandler(void)615 WEAK void DMA4_IRQHandler(void)
616 {   DMA4_DriverIRQHandler();
617 }
618 
DMA5_IRQHandler(void)619 WEAK void DMA5_IRQHandler(void)
620 {   DMA5_DriverIRQHandler();
621 }
622 
DMA6_IRQHandler(void)623 WEAK void DMA6_IRQHandler(void)
624 {   DMA6_DriverIRQHandler();
625 }
626 
DMA7_IRQHandler(void)627 WEAK void DMA7_IRQHandler(void)
628 {   DMA7_DriverIRQHandler();
629 }
630 
DMA8_IRQHandler(void)631 WEAK void DMA8_IRQHandler(void)
632 {   DMA8_DriverIRQHandler();
633 }
634 
DMA9_IRQHandler(void)635 WEAK void DMA9_IRQHandler(void)
636 {   DMA9_DriverIRQHandler();
637 }
638 
DMA10_IRQHandler(void)639 WEAK void DMA10_IRQHandler(void)
640 {   DMA10_DriverIRQHandler();
641 }
642 
DMA11_IRQHandler(void)643 WEAK void DMA11_IRQHandler(void)
644 {   DMA11_DriverIRQHandler();
645 }
646 
DMA12_IRQHandler(void)647 WEAK void DMA12_IRQHandler(void)
648 {   DMA12_DriverIRQHandler();
649 }
650 
DMA13_IRQHandler(void)651 WEAK void DMA13_IRQHandler(void)
652 {   DMA13_DriverIRQHandler();
653 }
654 
DMA14_IRQHandler(void)655 WEAK void DMA14_IRQHandler(void)
656 {   DMA14_DriverIRQHandler();
657 }
658 
DMA15_IRQHandler(void)659 WEAK void DMA15_IRQHandler(void)
660 {   DMA15_DriverIRQHandler();
661 }
662 
DMA_Error_IRQHandler(void)663 WEAK void DMA_Error_IRQHandler(void)
664 {   DMA_Error_DriverIRQHandler();
665 }
666 
MCM_IRQHandler(void)667 WEAK void MCM_IRQHandler(void)
668 {   MCM_DriverIRQHandler();
669 }
670 
FTFE_IRQHandler(void)671 WEAK void FTFE_IRQHandler(void)
672 {   FTFE_DriverIRQHandler();
673 }
674 
Read_Collision_IRQHandler(void)675 WEAK void Read_Collision_IRQHandler(void)
676 {   Read_Collision_DriverIRQHandler();
677 }
678 
LVD_LVW_IRQHandler(void)679 WEAK void LVD_LVW_IRQHandler(void)
680 {   LVD_LVW_DriverIRQHandler();
681 }
682 
LLWU_IRQHandler(void)683 WEAK void LLWU_IRQHandler(void)
684 {   LLWU_DriverIRQHandler();
685 }
686 
WDOG_EWM_IRQHandler(void)687 WEAK void WDOG_EWM_IRQHandler(void)
688 {   WDOG_EWM_DriverIRQHandler();
689 }
690 
RNG_IRQHandler(void)691 WEAK void RNG_IRQHandler(void)
692 {   RNG_DriverIRQHandler();
693 }
694 
I2C0_IRQHandler(void)695 WEAK void I2C0_IRQHandler(void)
696 {   I2C0_DriverIRQHandler();
697 }
698 
I2C1_IRQHandler(void)699 WEAK void I2C1_IRQHandler(void)
700 {   I2C1_DriverIRQHandler();
701 }
702 
SPI0_IRQHandler(void)703 WEAK void SPI0_IRQHandler(void)
704 {   SPI0_DriverIRQHandler();
705 }
706 
SPI1_IRQHandler(void)707 WEAK void SPI1_IRQHandler(void)
708 {   SPI1_DriverIRQHandler();
709 }
710 
I2S0_Tx_IRQHandler(void)711 WEAK void I2S0_Tx_IRQHandler(void)
712 {   I2S0_Tx_DriverIRQHandler();
713 }
714 
I2S0_Rx_IRQHandler(void)715 WEAK void I2S0_Rx_IRQHandler(void)
716 {   I2S0_Rx_DriverIRQHandler();
717 }
718 
UART0_LON_IRQHandler(void)719 WEAK void UART0_LON_IRQHandler(void)
720 {   UART0_LON_DriverIRQHandler();
721 }
722 
UART0_RX_TX_IRQHandler(void)723 WEAK void UART0_RX_TX_IRQHandler(void)
724 {   UART0_RX_TX_DriverIRQHandler();
725 }
726 
UART0_ERR_IRQHandler(void)727 WEAK void UART0_ERR_IRQHandler(void)
728 {   UART0_ERR_DriverIRQHandler();
729 }
730 
UART1_RX_TX_IRQHandler(void)731 WEAK void UART1_RX_TX_IRQHandler(void)
732 {   UART1_RX_TX_DriverIRQHandler();
733 }
734 
UART1_ERR_IRQHandler(void)735 WEAK void UART1_ERR_IRQHandler(void)
736 {   UART1_ERR_DriverIRQHandler();
737 }
738 
UART2_RX_TX_IRQHandler(void)739 WEAK void UART2_RX_TX_IRQHandler(void)
740 {   UART2_RX_TX_DriverIRQHandler();
741 }
742 
UART2_ERR_IRQHandler(void)743 WEAK void UART2_ERR_IRQHandler(void)
744 {   UART2_ERR_DriverIRQHandler();
745 }
746 
UART3_RX_TX_IRQHandler(void)747 WEAK void UART3_RX_TX_IRQHandler(void)
748 {   UART3_RX_TX_DriverIRQHandler();
749 }
750 
UART3_ERR_IRQHandler(void)751 WEAK void UART3_ERR_IRQHandler(void)
752 {   UART3_ERR_DriverIRQHandler();
753 }
754 
ADC0_IRQHandler(void)755 WEAK void ADC0_IRQHandler(void)
756 {   ADC0_DriverIRQHandler();
757 }
758 
CMP0_IRQHandler(void)759 WEAK void CMP0_IRQHandler(void)
760 {   CMP0_DriverIRQHandler();
761 }
762 
CMP1_IRQHandler(void)763 WEAK void CMP1_IRQHandler(void)
764 {   CMP1_DriverIRQHandler();
765 }
766 
FTM0_IRQHandler(void)767 WEAK void FTM0_IRQHandler(void)
768 {   FTM0_DriverIRQHandler();
769 }
770 
FTM1_IRQHandler(void)771 WEAK void FTM1_IRQHandler(void)
772 {   FTM1_DriverIRQHandler();
773 }
774 
FTM2_IRQHandler(void)775 WEAK void FTM2_IRQHandler(void)
776 {   FTM2_DriverIRQHandler();
777 }
778 
CMT_IRQHandler(void)779 WEAK void CMT_IRQHandler(void)
780 {   CMT_DriverIRQHandler();
781 }
782 
RTC_IRQHandler(void)783 WEAK void RTC_IRQHandler(void)
784 {   RTC_DriverIRQHandler();
785 }
786 
RTC_Seconds_IRQHandler(void)787 WEAK void RTC_Seconds_IRQHandler(void)
788 {   RTC_Seconds_DriverIRQHandler();
789 }
790 
PIT0_IRQHandler(void)791 WEAK void PIT0_IRQHandler(void)
792 {   PIT0_DriverIRQHandler();
793 }
794 
PIT1_IRQHandler(void)795 WEAK void PIT1_IRQHandler(void)
796 {   PIT1_DriverIRQHandler();
797 }
798 
PIT2_IRQHandler(void)799 WEAK void PIT2_IRQHandler(void)
800 {   PIT2_DriverIRQHandler();
801 }
802 
PIT3_IRQHandler(void)803 WEAK void PIT3_IRQHandler(void)
804 {   PIT3_DriverIRQHandler();
805 }
806 
PDB0_IRQHandler(void)807 WEAK void PDB0_IRQHandler(void)
808 {   PDB0_DriverIRQHandler();
809 }
810 
USB0_IRQHandler(void)811 WEAK void USB0_IRQHandler(void)
812 {   USB0_DriverIRQHandler();
813 }
814 
USBDCD_IRQHandler(void)815 WEAK void USBDCD_IRQHandler(void)
816 {   USBDCD_DriverIRQHandler();
817 }
818 
Reserved71_IRQHandler(void)819 WEAK void Reserved71_IRQHandler(void)
820 {   Reserved71_DriverIRQHandler();
821 }
822 
DAC0_IRQHandler(void)823 WEAK void DAC0_IRQHandler(void)
824 {   DAC0_DriverIRQHandler();
825 }
826 
MCG_IRQHandler(void)827 WEAK void MCG_IRQHandler(void)
828 {   MCG_DriverIRQHandler();
829 }
830 
LPTMR0_IRQHandler(void)831 WEAK void LPTMR0_IRQHandler(void)
832 {   LPTMR0_DriverIRQHandler();
833 }
834 
PORTA_IRQHandler(void)835 WEAK void PORTA_IRQHandler(void)
836 {   PORTA_DriverIRQHandler();
837 }
838 
PORTB_IRQHandler(void)839 WEAK void PORTB_IRQHandler(void)
840 {   PORTB_DriverIRQHandler();
841 }
842 
PORTC_IRQHandler(void)843 WEAK void PORTC_IRQHandler(void)
844 {   PORTC_DriverIRQHandler();
845 }
846 
PORTD_IRQHandler(void)847 WEAK void PORTD_IRQHandler(void)
848 {   PORTD_DriverIRQHandler();
849 }
850 
PORTE_IRQHandler(void)851 WEAK void PORTE_IRQHandler(void)
852 {   PORTE_DriverIRQHandler();
853 }
854 
SWI_IRQHandler(void)855 WEAK void SWI_IRQHandler(void)
856 {   SWI_DriverIRQHandler();
857 }
858 
SPI2_IRQHandler(void)859 WEAK void SPI2_IRQHandler(void)
860 {   SPI2_DriverIRQHandler();
861 }
862 
UART4_RX_TX_IRQHandler(void)863 WEAK void UART4_RX_TX_IRQHandler(void)
864 {   UART4_RX_TX_DriverIRQHandler();
865 }
866 
UART4_ERR_IRQHandler(void)867 WEAK void UART4_ERR_IRQHandler(void)
868 {   UART4_ERR_DriverIRQHandler();
869 }
870 
UART5_RX_TX_IRQHandler(void)871 WEAK void UART5_RX_TX_IRQHandler(void)
872 {   UART5_RX_TX_DriverIRQHandler();
873 }
874 
UART5_ERR_IRQHandler(void)875 WEAK void UART5_ERR_IRQHandler(void)
876 {   UART5_ERR_DriverIRQHandler();
877 }
878 
CMP2_IRQHandler(void)879 WEAK void CMP2_IRQHandler(void)
880 {   CMP2_DriverIRQHandler();
881 }
882 
FTM3_IRQHandler(void)883 WEAK void FTM3_IRQHandler(void)
884 {   FTM3_DriverIRQHandler();
885 }
886 
DAC1_IRQHandler(void)887 WEAK void DAC1_IRQHandler(void)
888 {   DAC1_DriverIRQHandler();
889 }
890 
ADC1_IRQHandler(void)891 WEAK void ADC1_IRQHandler(void)
892 {   ADC1_DriverIRQHandler();
893 }
894 
I2C2_IRQHandler(void)895 WEAK void I2C2_IRQHandler(void)
896 {   I2C2_DriverIRQHandler();
897 }
898 
CAN0_ORed_Message_buffer_IRQHandler(void)899 WEAK void CAN0_ORed_Message_buffer_IRQHandler(void)
900 {   CAN0_DriverIRQHandler();
901 }
902 
CAN0_Bus_Off_IRQHandler(void)903 WEAK void CAN0_Bus_Off_IRQHandler(void)
904 {   CAN0_DriverIRQHandler();
905 }
906 
CAN0_Error_IRQHandler(void)907 WEAK void CAN0_Error_IRQHandler(void)
908 {   CAN0_DriverIRQHandler();
909 }
910 
CAN0_Tx_Warning_IRQHandler(void)911 WEAK void CAN0_Tx_Warning_IRQHandler(void)
912 {   CAN0_DriverIRQHandler();
913 }
914 
CAN0_Rx_Warning_IRQHandler(void)915 WEAK void CAN0_Rx_Warning_IRQHandler(void)
916 {   CAN0_DriverIRQHandler();
917 }
918 
CAN0_Wake_Up_IRQHandler(void)919 WEAK void CAN0_Wake_Up_IRQHandler(void)
920 {   CAN0_DriverIRQHandler();
921 }
922 
SDHC_IRQHandler(void)923 WEAK void SDHC_IRQHandler(void)
924 {   SDHC_DriverIRQHandler();
925 }
926 
ENET_1588_Timer_IRQHandler(void)927 WEAK void ENET_1588_Timer_IRQHandler(void)
928 {   ENET_1588_Timer_DriverIRQHandler();
929 }
930 
ENET_Transmit_IRQHandler(void)931 WEAK void ENET_Transmit_IRQHandler(void)
932 {   ENET_Transmit_DriverIRQHandler();
933 }
934 
ENET_Receive_IRQHandler(void)935 WEAK void ENET_Receive_IRQHandler(void)
936 {   ENET_Receive_DriverIRQHandler();
937 }
938 
ENET_Error_IRQHandler(void)939 WEAK void ENET_Error_IRQHandler(void)
940 {   ENET_Error_DriverIRQHandler();
941 }
942 
943 //*****************************************************************************
944 
945 #if defined (DEBUG)
946 #pragma GCC pop_options
947 #endif // (DEBUG)
948