]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_LM3S316_IAR/hw_include/startup.c
Prepare for V4.7.1 release.
[freertos] / Demo / CORTEX_LM3S316_IAR / hw_include / 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 // This is part of revision 635 of the Stellaris Driver Library.\r
25 //\r
26 //*****************************************************************************\r
27 \r
28 //*****************************************************************************\r
29 //\r
30 // Enable the IAR extensions for this source file.\r
31 //\r
32 //*****************************************************************************\r
33 #pragma language=extended\r
34 \r
35 //*****************************************************************************\r
36 //\r
37 // Forward declaration of the default fault handlers.\r
38 //\r
39 //*****************************************************************************\r
40 void ResetISR(void);\r
41 static void NmiSR(void);\r
42 static void FaultISR(void);\r
43 static void IntDefaultHandler(void);\r
44 \r
45 //*****************************************************************************\r
46 //\r
47 // External declaration for the interrupt handler used by the application.\r
48 //\r
49 //*****************************************************************************\r
50 extern void xPortPendSVHandler(void);\r
51 extern void xPortSysTickHandler(void);\r
52 extern void vUART_ISR( void );\r
53 \r
54 //*****************************************************************************\r
55 //\r
56 // The entry point for the application.\r
57 //\r
58 //*****************************************************************************\r
59 extern void main(void);\r
60 \r
61 //*****************************************************************************\r
62 //\r
63 // Reserve space for the system stack.\r
64 //\r
65 //*****************************************************************************\r
66 #ifndef STACK_SIZE\r
67 #define STACK_SIZE                              50\r
68 #endif\r
69 static unsigned long pulStack[STACK_SIZE] = { \r
70 0xbbbbbbbb, \r
71 0xbbbbbbbb,\r
72 0xbbbbbbbb,\r
73 0xbbbbbbbb,\r
74 0xbbbbbbbb,\r
75 0xbbbbbbbb,\r
76 0xbbbbbbbb,\r
77 0xbbbbbbbb,\r
78 0xbbbbbbbb,\r
79 0xbbbbbbbb,\r
80 0xbbbbbbbb, \r
81 0xbbbbbbbb,\r
82 0xbbbbbbbb,\r
83 0xbbbbbbbb,\r
84 0xbbbbbbbb,\r
85 0xbbbbbbbb,\r
86 0xbbbbbbbb,\r
87 0xbbbbbbbb,\r
88 0xbbbbbbbb,\r
89 0xbbbbbbbb,\r
90 0xbbbbbbbb, \r
91 0xbbbbbbbb,\r
92 0xbbbbbbbb,\r
93 0xbbbbbbbb,\r
94 0xbbbbbbbb,\r
95 0xbbbbbbbb,\r
96 0xbbbbbbbb,\r
97 0xbbbbbbbb,\r
98 0xbbbbbbbb,\r
99 0xbbbbbbbb,\r
100 0xbbbbbbbb, \r
101 0xbbbbbbbb,\r
102 0xbbbbbbbb,\r
103 0xbbbbbbbb,\r
104 0xbbbbbbbb,\r
105 0xbbbbbbbb,\r
106 0xbbbbbbbb,\r
107 0xbbbbbbbb,\r
108 0xbbbbbbbb,\r
109 0xbbbbbbbb,\r
110 0xbbbbbbbb, \r
111 0xbbbbbbbb,\r
112 0xbbbbbbbb,\r
113 0xbbbbbbbb,\r
114 0xbbbbbbbb,\r
115 0xbbbbbbbb,\r
116 0xbbbbbbbb,\r
117 0xbbbbbbbb,\r
118 0xbbbbbbbb,\r
119 0xbbbbbbbb };\r
120 //*****************************************************************************\r
121 //\r
122 // A union that describes the entries of the vector table.  The union is needed\r
123 // since the first entry is the stack pointer and the remainder are function\r
124 // pointers.\r
125 //\r
126 //*****************************************************************************\r
127 typedef union\r
128 {\r
129     void (*pfnHandler)(void);\r
130     unsigned long ulPtr;\r
131 }\r
132 uVectorEntry;\r
133 \r
134 //*****************************************************************************\r
135 //\r
136 // The minimal vector table for a Cortex M3.  Note that the proper constructs\r
137 // must be placed on this to ensure that it ends up at physical address\r
138 // 0x0000.0000.\r
139 //\r
140 //*****************************************************************************\r
141 __root const uVectorEntry g_pfnVectors[] @ "INTVEC" =\r
142 {\r
143     { .ulPtr = (unsigned long)pulStack + sizeof(pulStack) },\r
144                                             // The initial stack pointer\r
145     ResetISR,                               // The reset handler\r
146     NmiSR,                                  // The NMI handler\r
147     FaultISR,                               // The hard fault handler\r
148     IntDefaultHandler,                      // The MPU fault handler\r
149     IntDefaultHandler,                      // The bus fault handler\r
150     IntDefaultHandler,                      // The usage fault handler\r
151     0,                                      // Reserved\r
152     0,                                      // Reserved\r
153     0,                                      // Reserved\r
154     0,                                      // Reserved\r
155     IntDefaultHandler,                      // SVCall handler\r
156     IntDefaultHandler,                      // Debug monitor handler\r
157     0,                                      // Reserved\r
158     xPortPendSVHandler,                     // The PendSV handler\r
159     xPortSysTickHandler,                    // The SysTick handler\r
160     IntDefaultHandler,                      // GPIO Port A\r
161     IntDefaultHandler,                      // GPIO Port B\r
162     IntDefaultHandler,                      // GPIO Port C\r
163     IntDefaultHandler,                      // GPIO Port D\r
164     IntDefaultHandler,                      // GPIO Port E\r
165     vUART_ISR,                                  // UART0 Rx and Tx\r
166     IntDefaultHandler,                      // UART1 Rx and Tx\r
167     IntDefaultHandler,                      // SSI Rx and Tx\r
168     IntDefaultHandler,                      // I2C Master and Slave\r
169     IntDefaultHandler,                      // PWM Fault\r
170     IntDefaultHandler,                      // PWM Generator 0\r
171     IntDefaultHandler,                      // PWM Generator 1\r
172     IntDefaultHandler,                      // PWM Generator 2\r
173     0,                                      // Reserved\r
174     IntDefaultHandler,                      // ADC Sequence 0\r
175     IntDefaultHandler,                      // ADC Sequence 1\r
176     IntDefaultHandler,                      // ADC Sequence 2\r
177     IntDefaultHandler,                      // ADC Sequence 3\r
178     IntDefaultHandler,                      // Watchdog timer\r
179     IntDefaultHandler,                      // Timer 0 subtimer A\r
180     IntDefaultHandler,                      // Timer 0 subtimer B\r
181     IntDefaultHandler,                      // Timer 1 subtimer A\r
182     IntDefaultHandler,                      // Timer 1 subtimer B\r
183     IntDefaultHandler,                      // Timer 2 subtimer A\r
184     IntDefaultHandler,                      // Timer 2 subtimer B\r
185     IntDefaultHandler,                      // Analog Comparator 0\r
186     IntDefaultHandler,                      // Analog Comparator 1\r
187     IntDefaultHandler,                      // Analog Comparator 2\r
188     IntDefaultHandler,                      // System Control (PLL, OSC, BO)\r
189     IntDefaultHandler                       // FLASH Control\r
190 };\r
191 \r
192 //*****************************************************************************\r
193 //\r
194 // The following are constructs created by the linker, indicating where the\r
195 // the "data" and "bss" segments reside in memory.  The initializers for the\r
196 // for the "data" segment resides immediately following the "text" segment.\r
197 //\r
198 //*****************************************************************************\r
199 #pragma segment="DATA_ID"\r
200 #pragma segment="DATA_I"\r
201 #pragma segment="DATA_Z"\r
202 \r
203 //*****************************************************************************\r
204 //\r
205 // This is the code that gets called when the processor first starts execution\r
206 // following a reset event.  Only the absolutely necessary set is performed,\r
207 // after which the application supplied entry() routine is called.  Any fancy\r
208 // actions (such as making decisions based on the reset cause register, and\r
209 // resetting the bits in that register) are left solely in the hands of the\r
210 // application.\r
211 //\r
212 //*****************************************************************************\r
213 void\r
214 ResetISR(void)\r
215 {\r
216     unsigned long *pulSrc, *pulDest, *pulEnd;\r
217 \r
218     //\r
219     // Copy the data segment initializers from flash to SRAM.\r
220     //\r
221     pulSrc = __segment_begin("DATA_ID");\r
222     pulDest = __segment_begin("DATA_I");\r
223     pulEnd = __segment_end("DATA_I");\r
224     while(pulDest < pulEnd)\r
225     {\r
226         *pulDest++ = *pulSrc++;\r
227     }\r
228 \r
229     //\r
230     // Zero fill the bss segment.\r
231     //\r
232     pulDest = __segment_begin("DATA_Z");\r
233     pulEnd = __segment_end("DATA_Z");\r
234     while(pulDest < pulEnd)\r
235     {\r
236         *pulDest++ = 0;\r
237     }\r
238 \r
239     //\r
240     // Call the application's entry point.\r
241     //\r
242     main();\r
243 }\r
244 \r
245 //*****************************************************************************\r
246 //\r
247 // This is the code that gets called when the processor receives a NMI.  This\r
248 // simply enters an infinite loop, preserving the system state for examination\r
249 // by a debugger.\r
250 //\r
251 //*****************************************************************************\r
252 static void\r
253 NmiSR(void)\r
254 {\r
255     //\r
256     // Enter an infinite loop.\r
257     //\r
258     while(1)\r
259     {\r
260     }\r
261 }\r
262 \r
263 //*****************************************************************************\r
264 //\r
265 // This is the code that gets called when the processor receives a fault\r
266 // interrupt.  This simply enters an infinite loop, preserving the system state\r
267 // for examination by a debugger.\r
268 //\r
269 //*****************************************************************************\r
270 static void\r
271 FaultISR(void)\r
272 {\r
273     //\r
274     // Enter an infinite loop.\r
275     //\r
276     while(1)\r
277     {\r
278     }\r
279 }\r
280 \r
281 //*****************************************************************************\r
282 //\r
283 // This is the code that gets called when the processor receives an unexpected\r
284 // interrupt.  This simply enters an infinite loop, preserving the system state\r
285 // for examination by a debugger.\r
286 //\r
287 //*****************************************************************************\r
288 static void\r
289 IntDefaultHandler(void)\r
290 {\r
291     //\r
292     // Go into an infinite loop.\r
293     //\r
294     while(1)\r
295     {\r
296     }\r
297 }\r