]> begriffs open source - freertos/blob - Demo/CORTEX_LM3S102_GCC/init/startup.c
Update to V4.3.0 as described in http://www.FreeRTOS.org/History.txt
[freertos] / Demo / CORTEX_LM3S102_GCC / init / startup.c
1 //*****************************************************************************\r
2 //\r
3 // startup.c - Boot code for Stellaris.\r
4 //\r
5 // Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.\r
6 //\r
7 // Software License Agreement\r
8 //\r
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and\r
10 // exclusively on LMI's Stellaris Family of microcontroller products.\r
11 //\r
12 // The software is owned by LMI and/or its suppliers, and is protected under\r
13 // applicable copyright laws.  All rights are reserved.  Any use in violation\r
14 // of the foregoing restrictions may subject the user to criminal sanctions\r
15 // under applicable laws, as well as to civil liability for the breach of the\r
16 // terms and conditions of this license.\r
17 //\r
18 // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
23 //\r
24 //*****************************************************************************\r
25 \r
26 //*****************************************************************************\r
27 //\r
28 // Forward declaration of the default fault handlers.\r
29 //\r
30 //*****************************************************************************\r
31 void ResetISR(void);\r
32 static void NmiSR(void);\r
33 void FaultISR(void);\r
34 extern void xPortPendSVHandler(void);\r
35 extern void xPortSysTickHandler(void);\r
36 extern void vUART_ISR( void );\r
37 \r
38 //*****************************************************************************\r
39 //\r
40 // The entry point for the application.\r
41 //\r
42 //*****************************************************************************\r
43 extern void entry(void);\r
44 \r
45 //*****************************************************************************\r
46 //\r
47 // Reserve space for the system stack.\r
48 //\r
49 //*****************************************************************************\r
50 #ifndef STACK_SIZE\r
51 #define STACK_SIZE                              51\r
52 #endif\r
53 static unsigned long pulMainStack[STACK_SIZE];\r
54 \r
55 //*****************************************************************************\r
56 //\r
57 // The minimal vector table for a Cortex M3.  Note that the proper constructs\r
58 // must be placed on this to ensure that it ends up at physical address\r
59 // 0x0000.0000.\r
60 //\r
61 //*****************************************************************************\r
62 __attribute__ ((section("vectors")))\r
63 void (* const g_pfnVectors[])(void) =\r
64 {\r
65     (void (*)(void))((unsigned long)pulMainStack + sizeof(pulMainStack)),\r
66     ResetISR,\r
67     NmiSR,\r
68     FaultISR,                                                           //FAULT\r
69     0,                                      // The MPU fault handler\r
70     0,                                      // The bus fault handler\r
71     0,                                      // The usage fault handler\r
72     0,                                      // Reserved\r
73     0,                                      // Reserved\r
74     0,                                      // Reserved\r
75     0,                                      // Reserved\r
76     0,                                                          // SVCall handler\r
77     0,                                      // Debug monitor handler\r
78     0,                                      // Reserved\r
79     xPortPendSVHandler,                     // The PendSV handler\r
80     xPortSysTickHandler,                    // The SysTick handler\r
81     0,                      // GPIO Port A\r
82     0,                      // GPIO Port B\r
83     0,                      // GPIO Port C\r
84     0,                      // GPIO Port D\r
85     0,                      // GPIO Port E\r
86     vUART_ISR                      // UART0 Rx and Tx\r
87 };\r
88 \r
89 //*****************************************************************************\r
90 //\r
91 // The following are constructs created by the linker, indicating where the\r
92 // the "data" and "bss" segments reside in memory.  The initializers for the\r
93 // for the "data" segment resides immediately following the "text" segment.\r
94 //\r
95 //*****************************************************************************\r
96 extern unsigned long _etext;\r
97 extern unsigned long _data;\r
98 extern unsigned long _edata;\r
99 extern unsigned long _bss;\r
100 extern unsigned long _ebss;\r
101 \r
102 //*****************************************************************************\r
103 //\r
104 // This is the code that gets called when the processor first starts execution\r
105 // following a reset event.  Only the absolutely necessary set is performed,\r
106 // after which the application supplied entry() routine is called.  Any fancy\r
107 // actions (such as making decisions based on the reset cause register, and\r
108 // resetting the bits in that register) are left solely in the hands of the\r
109 // application.\r
110 //\r
111 //*****************************************************************************\r
112 void\r
113 ResetISR(void)\r
114 {\r
115     unsigned long *pulSrc, *pulDest;\r
116 \r
117     //\r
118     // Copy the data segment initializers from flash to SRAM.\r
119     //\r
120     pulSrc = &_etext;\r
121     for(pulDest = &_data; pulDest < &_edata; )\r
122     {\r
123         *pulDest++ = *pulSrc++;\r
124     }\r
125 \r
126     //\r
127     // Zero fill the bss segment.\r
128     //\r
129     for(pulDest = &_bss; pulDest < &_ebss; )\r
130     {\r
131         *pulDest++ = 0;\r
132     }\r
133 \r
134     //\r
135     // Call the application's entry point.\r
136     //\r
137     Main();\r
138 }\r
139 \r
140 //*****************************************************************************\r
141 //\r
142 // This is the code that gets called when the processor receives a NMI.  This\r
143 // simply enters an infinite loop, preserving the system state for examination\r
144 // by a debugger.\r
145 //\r
146 //*****************************************************************************\r
147 static void\r
148 NmiSR(void)\r
149 {\r
150     //\r
151     // Enter an infinite loop.\r
152     //\r
153     while(1)\r
154     {\r
155     }\r
156 }\r
157 \r
158 //*****************************************************************************\r
159 //\r
160 // This is the code that gets called when the processor receives a fault\r
161 // interrupt.  This simply enters an infinite loop, preserving the system state\r
162 // for examination by a debugger.\r
163 //\r
164 //*****************************************************************************\r
165 void\r
166 FaultISR(void)\r
167 {\r
168     //\r
169     // Enter an infinite loop.\r
170     //\r
171     while(1)\r
172     {\r
173     }\r
174 }\r