| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cr_ucos_iii_startup_lpc18xx43xx.c
Go to the documentation of this file.
1 // *****************************************************************************
2 // +--+
3 // | ++----+
4 // +-++ |
5 // | |
6 // +-+--+ |
7 // | +--+--+
8 // +----+ Copyright (c) 2011-12 Code Red Technologies Ltd.
9 //
10 // LPC43xx Microcontroller Startup code for use with Red Suite
11 //
12 // Version : 120430
13 //
14 // Software License Agreement
15 //
16 // The software is owned by Code Red Technologies and/or its suppliers, and is
17 // protected under applicable copyright laws. All rights are reserved. Any
18 // use in violation of the foregoing restrictions may subject the user to criminal
19 // sanctions under applicable laws, as well as to civil liability for the breach
20 // of the terms and conditions of this license.
21 //
22 // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
23 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
24 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
25 // USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT
26 // TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH
27 // CODE RED TECHNOLOGIES LTD.
28 //
29 // *****************************************************************************
30 #if defined(__cplusplus)
31 #ifdef __REDLIB__
32 #error Redlib does not support C++
33 #else
34 // *****************************************************************************
35 //
36 // The entry point for the C++ library startup
37 //
38 // *****************************************************************************
39 extern "C" {
40 extern void __libc_init_array(void);
41
42 }
43 #endif
44 #endif
45
46 #define WEAK __attribute__ ((weak))
47 #define ALIAS(f) __attribute__ ((weak, alias(# f)))
48
49 // Code Red - if CMSIS is being used, then SystemInit() routine
50 // will be called by startup code rather than in application's main()
51 extern void SystemInit(void);
52 extern void OS_CPU_PendSVHandler(void);
53 extern void OS_CPU_SysTickHandler (void);
54
55 // *****************************************************************************
56 #if defined(__cplusplus)
57 extern "C" {
58 #endif
59
60 // *****************************************************************************
61 //
62 // Forward declaration of the default handlers. These are aliased.
63 // When the application defines a handler (with the same name), this will
64 // automatically take precedence over these weak definitions
65 //
66 // *****************************************************************************
67 void ResetISR(void);
68 WEAK void NMI_Handler(void);
69 WEAK void HardFault_Handler(void);
70 WEAK void MemManage_Handler(void);
71 WEAK void BusFault_Handler(void);
72 WEAK void UsageFault_Handler(void);
73 WEAK void SVC_Handler(void);
74 WEAK void DebugMon_Handler(void);
75 WEAK void PendSV_Handler(void);
76 WEAK void SysTick_Handler(void);
77 WEAK void IntDefaultHandler(void);
78
79 // *****************************************************************************
80 //
81 // Forward declaration of the specific IRQ handlers. These are aliased
82 // to the IntDefaultHandler, which is a 'forever' loop. When the application
83 // defines a handler (with the same name), this will automatically take
84 // precedence over these weak definitions
85 //
86 // *****************************************************************************
87 void DAC_IRQHandler(void) ALIAS(IntDefaultHandler);
88 void MX_CORE_IRQHandler(void) ALIAS(IntDefaultHandler);
89 void DMA_IRQHandler(void) ALIAS(IntDefaultHandler);
90 void FLASHEEPROM_IRQHandler(void) ALIAS(IntDefaultHandler);
91 void ETH_IRQHandler(void) ALIAS(IntDefaultHandler);
92 void SDIO_IRQHandler(void) ALIAS(IntDefaultHandler);
93 void LCD_IRQHandler(void) ALIAS(IntDefaultHandler);
94 void USB0_IRQHandler(void) ALIAS(IntDefaultHandler);
95 void USB1_IRQHandler(void) ALIAS(IntDefaultHandler);
96 void SCT_IRQHandler(void) ALIAS(IntDefaultHandler);
97 void RIT_IRQHandler(void) ALIAS(IntDefaultHandler);
98 void TIMER0_IRQHandler(void) ALIAS(IntDefaultHandler);
99 void TIMER1_IRQHandler(void) ALIAS(IntDefaultHandler);
100 void TIMER2_IRQHandler(void) ALIAS(IntDefaultHandler);
101 void TIMER3_IRQHandler(void) ALIAS(IntDefaultHandler);
102 void MCPWM_IRQHandler(void) ALIAS(IntDefaultHandler);
103 void ADC0_IRQHandler(void) ALIAS(IntDefaultHandler);
104 void I2C0_IRQHandler(void) ALIAS(IntDefaultHandler);
105 void I2C1_IRQHandler(void) ALIAS(IntDefaultHandler);
106 void SPI_IRQHandler (void) ALIAS(IntDefaultHandler);
107 void ADC1_IRQHandler(void) ALIAS(IntDefaultHandler);
108 void SSP0_IRQHandler(void) ALIAS(IntDefaultHandler);
109 void SSP1_IRQHandler(void) ALIAS(IntDefaultHandler);
110 void UART0_IRQHandler(void) ALIAS(IntDefaultHandler);
111 void UART1_IRQHandler(void) ALIAS(IntDefaultHandler);
112 void UART2_IRQHandler(void) ALIAS(IntDefaultHandler);
113 void UART3_IRQHandler(void) ALIAS(IntDefaultHandler);
114 void I2S0_IRQHandler(void) ALIAS(IntDefaultHandler);
115 void I2S1_IRQHandler(void) ALIAS(IntDefaultHandler);
116 void SPIFI_IRQHandler(void) ALIAS(IntDefaultHandler);
117 void SGPIO_IRQHandler(void) ALIAS(IntDefaultHandler);
118 void GPIO0_IRQHandler(void) ALIAS(IntDefaultHandler);
119 void GPIO1_IRQHandler(void) ALIAS(IntDefaultHandler);
120 void GPIO2_IRQHandler(void) ALIAS(IntDefaultHandler);
121 void GPIO3_IRQHandler(void) ALIAS(IntDefaultHandler);
122 void GPIO4_IRQHandler(void) ALIAS(IntDefaultHandler);
123 void GPIO5_IRQHandler(void) ALIAS(IntDefaultHandler);
124 void GPIO6_IRQHandler(void) ALIAS(IntDefaultHandler);
125 void GPIO7_IRQHandler(void) ALIAS(IntDefaultHandler);
126 void GINT0_IRQHandler(void) ALIAS(IntDefaultHandler);
127 void GINT1_IRQHandler(void) ALIAS(IntDefaultHandler);
128 void EVRT_IRQHandler(void) ALIAS(IntDefaultHandler);
129 void CAN1_IRQHandler(void) ALIAS(IntDefaultHandler);
130 void ATIMER_IRQHandler(void) ALIAS(IntDefaultHandler);
131 void RTC_IRQHandler(void) ALIAS(IntDefaultHandler);
132 void WDT_IRQHandler(void) ALIAS(IntDefaultHandler);
133 void CAN0_IRQHandler(void) ALIAS(IntDefaultHandler);
134 void QEI_IRQHandler(void) ALIAS(IntDefaultHandler);
135
136 // *****************************************************************************
137 //
138 // The entry point for the application.
139 // __main() is the entry point for Redlib based applications
140 // main() is the entry point for Newlib based applications
141 //
142 // *****************************************************************************
143 #if defined(__REDLIB__)
144 extern void __main(void);
145
146 #endif
147 extern int main(void);
148
149 // *****************************************************************************
150 //
151 // External declaration for the pointer to the stack top from the Linker Script
152 //
153 // *****************************************************************************
154 extern void _vStackTop(void);
155
156 // *****************************************************************************
157 #if defined(__cplusplus)
158 } // extern "C"
159 #endif
160 // *****************************************************************************
161 //
162 // The vector table.
163 // This relies on the linker script to place at correct location in memory.
164 //
165 // *****************************************************************************
166 extern void(*const g_pfnVectors[]) (void);
167 __attribute__ ((section(".isr_vector")))
168 void(*const g_pfnVectors[]) (void) = {
169 // Core Level - CM4/CM3
170 &_vStackTop, // The initial stack pointer
171 ResetISR, // The reset handler
172 NMI_Handler, // The NMI handler
173 HardFault_Handler, // The hard fault handler
174 MemManage_Handler, // The MPU fault handler
175 BusFault_Handler, // The bus fault handler
176 UsageFault_Handler, // The usage fault handler
177 0, // Reserved
178 0, // Reserved
179 0, // Reserved
180 0, // Reserved
181 SVC_Handler, // SVCall handler
182 DebugMon_Handler, // Debug monitor handler
183 0, // Reserved
184 OS_CPU_PendSVHandler, // The PendSV handler
185 OS_CPU_SysTickHandler, // The SysTick handler
186
187 // Chip Level - LPC18xx/43xx
188 DAC_IRQHandler, // 16 D/A Converter
189 MX_CORE_IRQHandler, // 17 CortexM4/M0 (LPC43XX ONLY)
190 DMA_IRQHandler, // 18 General Purpose DMA
191 0, // 19 Reserved
192 FLASHEEPROM_IRQHandler, // 20 ORed flash Bank A, flash Bank B, EEPROM interrupts
193 ETH_IRQHandler, // 21 Ethernet
194 SDIO_IRQHandler, // 22 SD/MMC
195 LCD_IRQHandler, // 23 LCD
196 USB0_IRQHandler, // 24 USB0
197 USB1_IRQHandler, // 25 USB1
198 SCT_IRQHandler, // 26 State Configurable Timer
199 RIT_IRQHandler, // 27 Repetitive Interrupt Timer
200 TIMER0_IRQHandler, // 28 Timer0
201 TIMER1_IRQHandler, // 29 Timer 1
202 TIMER2_IRQHandler, // 30 Timer 2
203 TIMER3_IRQHandler, // 31 Timer 3
204 MCPWM_IRQHandler, // 32 Motor Control PWM
205 ADC0_IRQHandler, // 33 A/D Converter 0
206 I2C0_IRQHandler, // 34 I2C0
207 I2C1_IRQHandler, // 35 I2C1
208 SPI_IRQHandler, // 36 SPI (LPC43XX ONLY)
209 ADC1_IRQHandler, // 37 A/D Converter 1
210 SSP0_IRQHandler, // 38 SSP0
211 SSP1_IRQHandler, // 39 SSP1
212 UART0_IRQHandler, // 40 UART0
213 UART1_IRQHandler, // 41 UART1
214 UART2_IRQHandler, // 42 UART2
215 UART3_IRQHandler, // 43 USRT3
216 I2S0_IRQHandler, // 44 I2S0
217 I2S1_IRQHandler, // 45 I2S1
218 SPIFI_IRQHandler, // 46 SPI Flash Interface
219 SGPIO_IRQHandler, // 47 SGPIO (LPC43XX ONLY)
220 GPIO0_IRQHandler, // 48 GPIO0
221 GPIO1_IRQHandler, // 49 GPIO1
222 GPIO2_IRQHandler, // 50 GPIO2
223 GPIO3_IRQHandler, // 51 GPIO3
224 GPIO4_IRQHandler, // 52 GPIO4
225 GPIO5_IRQHandler, // 53 GPIO5
226 GPIO6_IRQHandler, // 54 GPIO6
227 GPIO7_IRQHandler, // 55 GPIO7
228 GINT0_IRQHandler, // 56 GINT0
229 GINT1_IRQHandler, // 57 GINT1
230 EVRT_IRQHandler, // 58 Event Router
231 CAN1_IRQHandler, // 59 C_CAN1
232 0, // 60 Reserved
233 0, // 61 Reserved
234 ATIMER_IRQHandler, // 62 ATIMER
235 RTC_IRQHandler, // 63 RTC
236 0, // 64 Reserved
237 WDT_IRQHandler, // 65 WDT
238 0, // 66 Reserved
239 CAN0_IRQHandler, // 67 C_CAN0
240 QEI_IRQHandler, // 68 QEI
241 };
242
243 // *****************************************************************************
244 // Functions to carry out the initialization of RW and BSS data sections. These
245 // are written as separate functions rather than being inlined within the
246 // ResetISR() function in order to cope with MCUs with multiple banks of
247 // memory.
248 // *****************************************************************************
249 __attribute__ ((section(".after_vectors")))
250 void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
251 unsigned int *pulDest = (unsigned int *) start;
252 unsigned int *pulSrc = (unsigned int *) romstart;
253 unsigned int loop;
254 for (loop = 0; loop < len; loop = loop + 4)
255 *pulDest++ = *pulSrc++;
256 }
257
258 __attribute__ ((section(".after_vectors")))
259 void bss_init(unsigned int start, unsigned int len) {
260 unsigned int *pulDest = (unsigned int *) start;
261 unsigned int loop;
262 for (loop = 0; loop < len; loop = loop + 4)
263 *pulDest++ = 0;
264 }
265
266 // *****************************************************************************
267 // The following symbols are constructs generated by the linker, indicating
268 // the location of various points in the "Global Section Table". This table is
269 // created by the linker via the Code Red managed linker script mechanism. It
270 // contains the load address, execution address and length of each RW data
271 // section and the execution and length of each BSS (zero initialized) section.
272 // *****************************************************************************
273 extern unsigned int __data_section_table;
274 extern unsigned int __data_section_table_end;
275 extern unsigned int __bss_section_table;
276 extern unsigned int __bss_section_table_end;
277
278 // *****************************************************************************
279 // Reset entry point for your code.
280 // Sets up a simple runtime environment and initializes the C/C++
281 // library.
282 //
283 // *****************************************************************************
284 void
285 ResetISR(void) {
286
287 //
288 // Copy the data sections from flash to SRAM.
289 //
290 unsigned int LoadAddr, ExeAddr, SectionLen;
291 unsigned int *SectionTableAddr;
292
293 /* Call SystemInit() for clocking/memory setup prior to scatter load */
294 SystemInit();
295
296 // Load base address of Global Section Table
297 SectionTableAddr = &__data_section_table;
298
299 // Copy the data sections from flash to SRAM.
300 while (SectionTableAddr < &__data_section_table_end) {
301 LoadAddr = *SectionTableAddr++;
302 ExeAddr = *SectionTableAddr++;
303 SectionLen = *SectionTableAddr++;
304 data_init(LoadAddr, ExeAddr, SectionLen);
305 }
306 // At this point, SectionTableAddr = &__bss_section_table;
307 // Zero fill the bss segment
308 while (SectionTableAddr < &__bss_section_table_end) {
309 ExeAddr = *SectionTableAddr++;
310 SectionLen = *SectionTableAddr++;
311 bss_init(ExeAddr, SectionLen);
312 }
313
314 #if defined(__cplusplus)
315 //
316 // Call C++ library initialisation
317 //
318 __libc_init_array();
319 #endif
320
321 #if defined(__REDLIB__)
322 // Call the Redlib library, which in turn calls main()
323 __main();
324 #else
325 main();
326 #endif
327
328 //
329 // main() shouldn't return, but if it does, we'll just enter an infinite loop
330 //
331 while (1) {}
332 }
333
334 // *****************************************************************************
335 // Default exception handlers. Override the ones here by defining your own
336 // handler routines in your application code.
337 // *****************************************************************************
338 __attribute__ ((section(".after_vectors")))
339 void NMI_Handler(void)
340 {
341 while (1) {}
342 }
343
344 __attribute__ ((section(".after_vectors")))
345 void HardFault_Handler(void)
346 {
347 while (1) {}
348 }
349
350 __attribute__ ((section(".after_vectors")))
351 void MemManage_Handler(void)
352 {
353 while (1) {}
354 }
355
356 __attribute__ ((section(".after_vectors")))
357 void BusFault_Handler(void)
358 {
359 while (1) {}
360 }
361
362 __attribute__ ((section(".after_vectors")))
363 void UsageFault_Handler(void)
364 {
365 while (1) {}
366 }
367
368 __attribute__ ((section(".after_vectors")))
369 void SVC_Handler(void)
370 {
371 while (1) {}
372 }
373
374 __attribute__ ((section(".after_vectors")))
375 void DebugMon_Handler(void)
376 {
377 while (1) {}
378 }
379
380 __attribute__ ((section(".after_vectors")))
381 void PendSV_Handler(void)
382 {
383 while (1) {}
384 }
385
386 __attribute__ ((section(".after_vectors")))
387 void SysTick_Handler(void)
388 {
389 while (1) {}
390 }
391
392 // *****************************************************************************
393 //
394 // Processor ends up here if an unexpected interrupt occurs or a specific
395 // handler is not present in the application code.
396 //
397 // *****************************************************************************
398 __attribute__ ((section(".after_vectors")))
399 void IntDefaultHandler(void)
400 {
401 while (1) {}
402 }
403
404
405