1 //*****************************************************************************
2 //
3 // Startup code for use with GNU tools.
4 //
5 //*****************************************************************************
6
7
8 //*****************************************************************************
9 //
10 // Forward declaration of the default fault handlers.
11 //
12 //*****************************************************************************
13 static void Reset_Handler(void);
14 static void Default_Handler(void);
15
16 //*****************************************************************************
17 //
18 // External declaration for the interrupt handler used by the application.
19 //
20 //*****************************************************************************
21 void NMI_Handler(void) __attribute__((weak, alias("Default_Handler")));
22 void HardFault_Handler(void) __attribute__((weak, alias("Default_Handler")));
23 void MemManage_Handler(void) __attribute__((weak, alias("Default_Handler")));
24 void BusFault_Handler(void) __attribute__((weak, alias("Default_Handler")));
25 void UsageFault_Handler(void) __attribute__((weak, alias("Default_Handler")));
26 void SVC_Handler(void) __attribute__((weak, alias("Default_Handler")));
27 void DebugMon_Handler(void) __attribute__((weak, alias("Default_Handler")));
28 void PendSV_Handler(void) __attribute__((weak, alias("Default_Handler")));
29 void SysTick_Handler(void) __attribute__((weak, alias("Default_Handler")));
30
31 void ETH_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
32 void USB_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
33 void DMAC_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
34 void CAN0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
35 void CAN1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
36
37 void FP0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
38 void FP1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
39 void FP2_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
40 void FP3_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
41 void FP4_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
42 void FP5_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
43 void FP6_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
44 void FP7_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
45 void FP8_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
46 void FP9_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
47 void FP10_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
48 void FP11_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
49 void FP12_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
50 void FP13_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
51 void FP14_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
52 void FP15_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
53 void UART0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
54 void UART1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
55 void ADC_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
56 void GPIO_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
57 void SPI1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
58 void I2C1_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
59 void SPI0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
60 void I2C0_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
61 void RTC_1S_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
62 void RTC_1MS_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
63 void WDG_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
64 void TIMER_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
65 void DDRC_SW_PROC_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
66 void ETH_PMT_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
67 void PAD_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
68 void DDRC_LANE_SYNC_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
69 void UART2_IRQHandler(void) __attribute__((weak, alias("Default_Handler")));
70
71 //*****************************************************************************
72 //
73 // The entry point for the application.
74 //
75 //*****************************************************************************
76 extern int main(void);
77
78 //*****************************************************************************
79 //
80 // Reserve space for the system stack.
81 //
82 //*****************************************************************************
83 static unsigned long pulStack[512];
84
85 //*****************************************************************************
86 //
87 // The vector table. Note that the proper constructs must be placed on this to
88 // ensure that it ends up at physical address 0x0000.0000.
89 //
90 //*****************************************************************************
91 __attribute__ ((section(".isr_vector")))
92 void (* const g_pfnVectors[])(void) =
93 {
94 (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)),
95 // The initial stack pointer
96 Reset_Handler, // Reset Handler
97 NMI_Handler, // NMI Handler
98 HardFault_Handler, // Hard Fault Handler
99 MemManage_Handler, // MPU Fault Handler
100 BusFault_Handler, // Bus Fault Handler
101 UsageFault_Handler, // Usage Fault Handler
102 0, // Reserved
103 0, // Reserved
104 0, // Reserved
105 0, // Reserved
106 SVC_Handler, // SVCall Handler
107 DebugMon_Handler, // Debug Monitor Handler
108 0, // Reserved
109 PendSV_Handler, // PendSV Handler
110 SysTick_Handler, // SysTick Handler
111
112 // External Interrupts
113 ETH_IRQHandler,
114 USB_IRQHandler,
115 DMAC_IRQHandler,
116 CAN0_IRQHandler,
117 CAN1_IRQHandler,
118 FP0_IRQHandler,
119 FP1_IRQHandler,
120 FP2_IRQHandler,
121 FP3_IRQHandler,
122 FP4_IRQHandler,
123 FP5_IRQHandler,
124 FP6_IRQHandler,
125 FP7_IRQHandler,
126 FP8_IRQHandler,
127 FP9_IRQHandler,
128 FP10_IRQHandler,
129 FP11_IRQHandler,
130 FP12_IRQHandler,
131 FP13_IRQHandler,
132 FP14_IRQHandler,
133 FP15_IRQHandler,
134 UART0_IRQHandler,
135 UART1_IRQHandler,
136 ADC_IRQHandler,
137 GPIO_IRQHandler,
138 SPI1_IRQHandler,
139 I2C1_IRQHandler,
140 SPI0_IRQHandler,
141 I2C0_IRQHandler,
142 RTC_1S_IRQHandler,
143 RTC_1MS_IRQHandler,
144 WDG_IRQHandler,
145 TIMER_IRQHandler,
146 DDRC_SW_PROC_IRQHandler,
147 ETH_PMT_IRQHandler,
148 PAD_IRQHandler,
149 DDRC_LANE_SYNC_IRQHandler,
150 UART2_IRQHandler,
151 };
152
153 //*****************************************************************************
154 //
155 // The following are constructs created by the linker, indicating where the
156 // the "data" and "bss" segments reside in memory. The initializers for the
157 // for the "data" segment resides immediately following the "text" segment.
158 //
159 //*****************************************************************************
160 extern unsigned long _etext;
161 extern unsigned long _data;
162 extern unsigned long _edata;
163 extern unsigned long _bss;
164 extern unsigned long _ebss;
165
166 //*****************************************************************************
167 //
168 // This is the code that gets called when the processor first starts execution
169 // following a reset event. Only the absolutely necessary set is performed,
170 // after which the application supplied entry() routine is called. Any fancy
171 // actions (such as making decisions based on the reset cause register, and
172 // resetting the bits in that register) are left solely in the hands of the
173 // application.
174 //
175 //*****************************************************************************
Reset_Handler(void)176 static void Reset_Handler(void)
177 {
178 unsigned long *pulSrc, *pulDest;
179
180 //
181 // Copy the data segment initializers from flash to SRAM.
182 //
183 pulSrc = &_etext;
184 for(pulDest = &_data; pulDest < &_edata; )
185 {
186 *pulDest++ = *pulSrc++;
187 }
188
189 //
190 // Zero fill the bss segment.
191 //
192 __asm(" ldr r0, =_bss\n"
193 " ldr r1, =_ebss\n"
194 " mov r2, #0\n"
195 " .thumb_func\n"
196 "zero_loop:\n"
197 " cmp r0, r1\n"
198 " it lt\n"
199 " strlt r2, [r0], #4\n"
200 " blt zero_loop");
201
202 // call system init.
203 SystemInit();
204
205 //
206 // Call the application's entry point.
207 //
208 main();
209 }
210
211 //*****************************************************************************
212 //
213 // This is the code that gets called when the processor receives an unexpected
214 // interrupt. This simply enters an infinite loop, preserving the system state
215 // for examination by a debugger.
216 //
217 //*****************************************************************************
Default_Handler(void)218 static void Default_Handler(void)
219 {
220 //
221 // Go into an infinite loop.
222 //
223 while(1)
224 {
225 }
226 }
227