| 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_freertos_startup_lpc13xx.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 // Microcontroller Startup code for use with Red Suite
11 //
12 // Version : 120126
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 #endif
43 #endif
44
45 #define WEAK __attribute__ ((weak))
46 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
47 /* Include sys_config.h to get the CHIP_11* device identifier */
48 #include "sys_config.h"
49
50 // Code Red - if CMSIS is being used, then SystemInit() routine
51 // will be called by startup code rather than in application's main()
52 extern void SystemInit(void);
53
54 //*****************************************************************************
55 #if defined (__cplusplus)
56 extern "C" {
57 #endif
58
59 //*****************************************************************************
60 //
61 // Forward declaration of the default handlers. These are aliased.
62 // When the application defines a handler (with the same name), this will
63 // automatically take precedence over these weak definitions
64 //
65 //*****************************************************************************
66 void ResetISR(void);
67 WEAK void NMI_Handler(void);
68 WEAK void HardFault_Handler(void);
69 WEAK void SVC_Handler(void);
70 WEAK void PendSV_Handler(void);
71 WEAK void SysTick_Handler(void);
72 WEAK void IntDefaultHandler(void);
73
74 void vPortSVCHandler(void);
75 void xPortPendSVHandler(void);
76 void xPortSysTickHandler(void);
77
78 //*****************************************************************************
79 //
80 // Forward declaration of the specific IRQ handlers. These are aliased
81 // to the IntDefaultHandler, which is a 'forever' loop. When the application
82 // defines a handler (with the same name), this will automatically take
83 // precedence over these weak definitions
84 //
85 //*****************************************************************************
86
87 #if defined(CHIP_LPC1343)
88 void WAKEUP_IRQHandler (void) ALIAS(IntDefaultHandler);
89 void I2C_IRQHandler (void) ALIAS(IntDefaultHandler);
90 void TIMER16_0_IRQHandler (void) ALIAS(IntDefaultHandler);
91 void TIMER16_1_IRQHandler (void) ALIAS(IntDefaultHandler);
92 void TIMER32_0_IRQHandler (void) ALIAS(IntDefaultHandler);
93 void TIMER32_1_IRQHandler (void) ALIAS(IntDefaultHandler);
94 void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);
95 void UART_IRQHandler (void) ALIAS(IntDefaultHandler);
96 void USB_IRQHandler (void) ALIAS(IntDefaultHandler);
97 void USB_FIQHandler (void) ALIAS(IntDefaultHandler);
98 void ADC_IRQHandler (void) ALIAS(IntDefaultHandler);
99 void WDT_IRQHandler (void) ALIAS(IntDefaultHandler);
100 void BOD_IRQHandler (void) ALIAS(IntDefaultHandler);
101 void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);
102 void PIOINT3_IRQHandler (void) ALIAS(IntDefaultHandler);
103 void PIOINT2_IRQHandler (void) ALIAS(IntDefaultHandler);
104 void PIOINT1_IRQHandler (void) ALIAS(IntDefaultHandler);
105 void PIOINT0_IRQHandler (void) ALIAS(IntDefaultHandler);
106
107 #elif defined(CHIP_LPC1347)
108 void PIN_INT0_IRQHandler (void) ALIAS(IntDefaultHandler);
109 void PIN_INT1_IRQHandler (void) ALIAS(IntDefaultHandler);
110 void PIN_INT2_IRQHandler (void) ALIAS(IntDefaultHandler);
111 void PIN_INT3_IRQHandler (void) ALIAS(IntDefaultHandler);
112 void PIN_INT4_IRQHandler (void) ALIAS(IntDefaultHandler);
113 void PIN_INT5_IRQHandler (void) ALIAS(IntDefaultHandler);
114 void PIN_INT6_IRQHandler (void) ALIAS(IntDefaultHandler);
115 void PIN_INT7_IRQHandler (void) ALIAS(IntDefaultHandler);
116 void GINT0_IRQHandler (void) ALIAS(IntDefaultHandler);
117 void GINT1_IRQHandler (void) ALIAS(IntDefaultHandler);
118 void RIT_IRQHandler (void) ALIAS(IntDefaultHandler);
119 void SSP1_IRQHandler (void) ALIAS(IntDefaultHandler);
120 void I2C_IRQHandler (void) ALIAS(IntDefaultHandler);
121 void TIMER16_0_IRQHandler (void) ALIAS(IntDefaultHandler);
122 void TIMER16_1_IRQHandler (void) ALIAS(IntDefaultHandler);
123 void TIMER32_0_IRQHandler (void) ALIAS(IntDefaultHandler);
124 void TIMER32_1_IRQHandler (void) ALIAS(IntDefaultHandler);
125 void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);
126 void UART_IRQHandler (void) ALIAS(IntDefaultHandler);
127 void USB_IRQHandler (void) ALIAS(IntDefaultHandler);
128 void USB_FIQHandler (void) ALIAS(IntDefaultHandler);
129 void ADC_IRQHandler (void) ALIAS(IntDefaultHandler);
130 void WDT_IRQHandler (void) ALIAS(IntDefaultHandler);
131 void BOD_IRQHandler (void) ALIAS(IntDefaultHandler);
132 void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);
133 void OSCFAIL_IRQHandler (void) ALIAS(IntDefaultHandler);
134 void PVTCIRCUIT_IRQHandler (void) ALIAS(IntDefaultHandler);
135 void USBWakeup_IRQHandler (void) ALIAS(IntDefaultHandler);
136
137 #else
138 #error No CHIP_134* device defined
139 #endif
140
141 //*****************************************************************************
142 //
143 // The entry point for the application.
144 // __main() is the entry point for redlib based applications
145 // main() is the entry point for newlib based applications
146 //
147 //*****************************************************************************
148 //
149 // The entry point for the application.
150 // __main() is the entry point for Redlib based applications
151 // main() is the entry point for Newlib based applications
152 //
153 //*****************************************************************************
154 #if defined (__REDLIB__)
155 extern void __main(void);
156 #endif
157 extern int main(void);
158 //*****************************************************************************
159 //
160 // External declaration for the pointer to the stack top from the Linker Script
161 //
162 //*****************************************************************************
163 extern void _vStackTop(void);
164
165 //*****************************************************************************
166 #if defined (__cplusplus)
167 } // extern "C"
168 #endif
169
170 //*****************************************************************************
171 //
172 // The vector table. Note that the proper constructs must be placed on this to
173 // ensure that it ends up at physical address 0x0000.0000.
174 //
175 //*****************************************************************************
176 extern void (* const g_pfnVectors[])(void);
177 __attribute__ ((section(".isr_vector")))
178 void (* const g_pfnVectors[])(void) = {
179 &_vStackTop, // The initial stack pointer
180 ResetISR, // The reset handler
181 NMI_Handler, // The NMI handler
182 HardFault_Handler, // The hard fault handler
183 0, // Reserved
184 0, // Reserved
185 0, // Reserved
186 0, // Reserved
187 0, // Reserved
188 0, // Reserved
189 0, // Reserved
190 vPortSVCHandler, // FreeRTOS SVCall Handler
191 0, // Reserved
192 0, // Reserved
193 xPortPendSVHandler, // FreeRTOS PendSV Handler
194 xPortSysTickHandler, // FreeRTOS SysTick Handler
195
196 #if defined(CHIP_LPC1343)
197 WAKEUP_IRQHandler, // Wakeup PIO0.0
198 WAKEUP_IRQHandler, // Wakeup PIO0.1
199 WAKEUP_IRQHandler, // Wakeup PIO0.2
200 WAKEUP_IRQHandler, // Wakeup PIO0.3
201 WAKEUP_IRQHandler, // Wakeup PIO0.4
202 WAKEUP_IRQHandler, // Wakeup PIO0.5
203 WAKEUP_IRQHandler, // Wakeup PIO0.6
204 WAKEUP_IRQHandler, // Wakeup PIO0.7
205 WAKEUP_IRQHandler, // Wakeup PIO0.8
206 WAKEUP_IRQHandler, // Wakeup PIO0.9
207 WAKEUP_IRQHandler, // Wakeup PIO0.10
208 WAKEUP_IRQHandler, // Wakeup PIO0.11
209 WAKEUP_IRQHandler, // Wakeup PIO1.0
210 WAKEUP_IRQHandler, // Wakeup PIO1.1
211 WAKEUP_IRQHandler, // Wakeup PIO1.2
212 WAKEUP_IRQHandler, // Wakeup PIO1.3
213 WAKEUP_IRQHandler, // Wakeup PIO1.4
214 WAKEUP_IRQHandler, // Wakeup PIO1.5
215 WAKEUP_IRQHandler, // Wakeup PIO1.6
216 WAKEUP_IRQHandler, // Wakeup PIO1.7
217 WAKEUP_IRQHandler, // Wakeup PIO1.8
218 WAKEUP_IRQHandler, // Wakeup PIO1.9
219 WAKEUP_IRQHandler, // Wakeup PIO1.10
220 WAKEUP_IRQHandler, // Wakeup PIO1.11
221 WAKEUP_IRQHandler, // Wakeup PIO2.0
222 WAKEUP_IRQHandler, // Wakeup PIO2.1
223 WAKEUP_IRQHandler, // Wakeup PIO2.2
224 WAKEUP_IRQHandler, // Wakeup PIO2.3
225 WAKEUP_IRQHandler, // Wakeup PIO2.4
226 WAKEUP_IRQHandler, // Wakeup PIO2.5
227 WAKEUP_IRQHandler, // Wakeup PIO2.6
228 WAKEUP_IRQHandler, // Wakeup PIO2.7
229 WAKEUP_IRQHandler, // Wakeup PIO2.8
230 WAKEUP_IRQHandler, // Wakeup PIO2.9
231 WAKEUP_IRQHandler, // Wakeup PIO2.10
232 WAKEUP_IRQHandler, // Wakeup PIO2.11
233 WAKEUP_IRQHandler, // Wakeup PIO3.0
234 WAKEUP_IRQHandler, // Wakeup PIO3.1
235 WAKEUP_IRQHandler, // Wakeup PIO3.2
236 WAKEUP_IRQHandler, // Wakeup PIO3.3
237 I2C_IRQHandler, // I2C
238 TIMER16_0_IRQHandler, // 16-bit Counter-Timer 0
239 TIMER16_1_IRQHandler, // 16-bit Counter-Timer 1
240 TIMER32_0_IRQHandler, // 32-bit Counter-Timer 0
241 TIMER32_1_IRQHandler, // 32-bit Counter-Timer 1
242 SSP0_IRQHandler, // SSP0
243 UART_IRQHandler, // UART
244 USB_IRQHandler, // USB IRQ
245 USB_FIQHandler, // USB FIQ
246 ADC_IRQHandler, // A/D Converter
247 WDT_IRQHandler, // Watchdog Timer
248 BOD_IRQHandler, // Brown Out Detect
249 FMC_IRQHandler, // IP2111 Flash Memory Controller
250 PIOINT3_IRQHandler, // PIO INT3
251 PIOINT2_IRQHandler, // PIO INT2
252 PIOINT1_IRQHandler, // PIO INT1
253 PIOINT0_IRQHandler, // PIO INT0
254
255 #elif defined(CHIP_LPC1347)
256 PIN_INT0_IRQHandler, // All GPIO pin can be routed to PIN_INTx
257 PIN_INT1_IRQHandler,
258 PIN_INT2_IRQHandler,
259 PIN_INT3_IRQHandler,
260 PIN_INT4_IRQHandler,
261 PIN_INT5_IRQHandler,
262 PIN_INT6_IRQHandler,
263 PIN_INT7_IRQHandler,
264 GINT0_IRQHandler,
265 GINT1_IRQHandler, // PIO0 (0:7)
266 0,
267 0,
268 RIT_IRQHandler,
269 0,
270 SSP1_IRQHandler, // SSP1
271 I2C_IRQHandler, // I2C
272 TIMER16_0_IRQHandler, // 16-bit Counter-Timer 0
273 TIMER16_1_IRQHandler, // 16-bit Counter-Timer 1
274 TIMER32_0_IRQHandler, // 32-bit Counter-Timer 0
275 TIMER32_1_IRQHandler, // 32-bit Counter-Timer 1
276 SSP0_IRQHandler, // SSP0
277 UART_IRQHandler, // UART
278 USB_IRQHandler, // USB IRQ
279 USB_FIQHandler, // USB FIQ
280 ADC_IRQHandler, // A/D Converter
281 WDT_IRQHandler, // Watchdog Timer
282 BOD_IRQHandler, // Brown Out Detect
283 FMC_IRQHandler, // IP2111 Flash Memory Controller
284 OSCFAIL_IRQHandler, // OSC FAIL
285 PVTCIRCUIT_IRQHandler, // PVT CIRCUIT
286 USBWakeup_IRQHandler, // USB wake up
287 0,
288
289 #else
290 #error No CHIP_13* device defined
291 #endif
292 };
293
294 //*****************************************************************************
295 // Functions to carry out the initialization of RW and BSS data sections. These
296 // are written as separate functions rather than being inlined within the
297 // ResetISR() function in order to cope with MCUs with multiple banks of
298 // memory.
299 //*****************************************************************************
300 __attribute__ ((section(".after_vectors")))
301 void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
302 unsigned int *pulDest = (unsigned int*) start;
303 unsigned int *pulSrc = (unsigned int*) romstart;
304 unsigned int loop;
305 for (loop = 0; loop < len; loop = loop + 4)
306 *pulDest++ = *pulSrc++;
307 }
308
309 __attribute__ ((section(".after_vectors")))
310 void bss_init(unsigned int start, unsigned int len) {
311 unsigned int *pulDest = (unsigned int*) start;
312 unsigned int loop;
313 for (loop = 0; loop < len; loop = loop + 4)
314 *pulDest++ = 0;
315 }
316
317 #ifndef USE_OLD_STYLE_DATA_BSS_INIT
318 //*****************************************************************************
319 // The following symbols are constructs generated by the linker, indicating
320 // the location of various points in the "Global Section Table". This table is
321 // created by the linker via the Code Red managed linker script mechanism. It
322 // contains the load address, execution address and length of each RW data
323 // section and the execution and length of each BSS (zero initialized) section.
324 //*****************************************************************************
325 extern unsigned int __data_section_table;
326 extern unsigned int __data_section_table_end;
327 extern unsigned int __bss_section_table;
328 extern unsigned int __bss_section_table_end;
329 #else
330 //*****************************************************************************
331 // The following symbols are constructs generated by the linker, indicating
332 // the load address, execution address and length of the RW data section and
333 // the execution and length of the BSS (zero initialized) section.
334 // Note that these symbols are not normally used by the managed linker script
335 // mechanism in Red Suite/LPCXpresso 3.6 (Windows) and LPCXpresso 3.8 (Linux).
336 // They are provide here simply so this startup code can be used with earlier
337 // versions of Red Suite which do not support the more advanced managed linker
338 // script mechanism introduced in the above version. To enable their use,
339 // define "USE_OLD_STYLE_DATA_BSS_INIT".
340 //*****************************************************************************
341 extern unsigned int _etext;
342 extern unsigned int _data;
343 extern unsigned int _edata;
344 extern unsigned int _bss;
345 extern unsigned int _ebss;
346 #endif
347
348
349 //*****************************************************************************
350 // Reset entry point for your code.
351 // Sets up a simple runtime environment and initializes the C/C++
352 // library.
353 //*****************************************************************************
354 __attribute__ ((section(".after_vectors")))
355 void
356 ResetISR(void) {
357
358 #ifndef USE_OLD_STYLE_DATA_BSS_INIT
359 //
360 // Copy the data sections from flash to SRAM.
361 //
362 unsigned int LoadAddr, ExeAddr, SectionLen;
363 unsigned int *SectionTableAddr;
364
365 // Load base address of Global Section Table
366 SectionTableAddr = &__data_section_table;
367
368 // Copy the data sections from flash to SRAM.
369 while (SectionTableAddr < &__data_section_table_end) {
370 LoadAddr = *SectionTableAddr++;
371 ExeAddr = *SectionTableAddr++;
372 SectionLen = *SectionTableAddr++;
373 data_init(LoadAddr, ExeAddr, SectionLen);
374 }
375 // At this point, SectionTableAddr = &__bss_section_table;
376 // Zero fill the bss segment
377 while (SectionTableAddr < &__bss_section_table_end) {
378 ExeAddr = *SectionTableAddr++;
379 SectionLen = *SectionTableAddr++;
380 bss_init(ExeAddr, SectionLen);
381 }
382 #else
383 // Use Old Style Data and BSS section initialization.
384 // This will only initialize a single RAM bank.
385 unsigned int * LoadAddr, *ExeAddr, *EndAddr, SectionLen;
386
387 // Copy the data segment from flash to SRAM.
388 LoadAddr = &_etext;
389 ExeAddr = &_data;
390 EndAddr = &_edata;
391 SectionLen = (void*)EndAddr - (void*)ExeAddr;
392 data_init((unsigned int)LoadAddr, (unsigned int)ExeAddr, SectionLen);
393 // Zero fill the bss segment
394 ExeAddr = &_bss;
395 EndAddr = &_ebss;
396 SectionLen = (void*)EndAddr - (void*)ExeAddr;
397 bss_init ((unsigned int)ExeAddr, SectionLen);
398 #endif
399
400 extern void SystemInit(void);
401 SystemInit();
402
403 #if defined (__cplusplus)
404 //
405 // Call C++ library initialisation
406 //
407 __libc_init_array();
408 #endif
409
410 #if defined (__REDLIB__)
411 // Call the Redlib library, which in turn calls main()
412 __main() ;
413 #else
414 main();
415 #endif
416 //
417 // main() shouldn't return, but if it does, we'll just enter an infinite loop
418 //
419 while (1) {
420 ;
421 }
422 }
423
424 //*****************************************************************************
425 // Default exception handlers. Override the ones here by defining your own
426 // handler routines in your application code.
427 //*****************************************************************************
428 __attribute__ ((section(".after_vectors")))
429 void NMI_Handler(void)
430 {
431 while(1)
432 {
433 }
434 }
435 __attribute__ ((section(".after_vectors")))
436 void HardFault_Handler(void)
437 {
438 while(1)
439 {
440 }
441 }
442 __attribute__ ((section(".after_vectors")))
443 void SVC_Handler(void)
444 {
445 while(1)
446 {
447 }
448 }
449 __attribute__ ((section(".after_vectors")))
450 void PendSV_Handler(void)
451 {
452 while(1)
453 {
454 }
455 }
456 __attribute__ ((section(".after_vectors")))
457 void SysTick_Handler(void)
458 {
459 while(1)
460 {
461 }
462 }
463
464 //*****************************************************************************
465 //
466 // Processor ends up here if an unexpected interrupt occurs or a specific
467 // handler is not present in the application code.
468 //
469 //*****************************************************************************
470 __attribute__ ((section(".after_vectors")))
471 void IntDefaultHandler(void)
472 {
473 while(1)
474 {
475 }
476 }
477