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