Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 dhylands 1
//*****************************************************************************
2
//
3
// startup.c - Boot code for Stellaris.
4
//
5
// Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.
6
//
7
// Software License Agreement
8
//
9
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10
// exclusively on LMI's Stellaris Family of microcontroller products.
11
//
12
// The software is owned by LMI and/or its suppliers, and is protected under
13
// applicable copyright laws.  All rights are reserved.  Any use in violation
14
// of the foregoing restrictions may subject the user to criminal sanctions
15
// under applicable laws, as well as to civil liability for the breach of the
16
// terms and conditions of this license.
17
//
18
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23
//
24
// This is part of revision 852 of the Stellaris Driver Library.
25
//
26
//*****************************************************************************
27
 
28
// modified by Martin Thomas - don't blame Luminary if it does
29
// not work for you.
30
 
31
//*****************************************************************************
32
//
33
// Forward declaration of the default fault handlers.
34
//
35
//*****************************************************************************
36
// mthomas: attribute for stack-aligment (see README_mthomas.txt)
37
#ifdef __GNUC__
38
void ResetISR(void) __attribute__((__interrupt__));
39
static void NmiSR(void) __attribute__((__interrupt__));
40
static void FaultISR(void) __attribute__((__interrupt__));
41
static void IntDefaultHandler(void) __attribute__((__interrupt__));
42
#else
43
void ResetISR(void);
44
static void NmiSR(void);
45
static void FaultISR(void);
46
static void IntDefaultHandler(void);
47
#endif
48
 
49
//*****************************************************************************
50
//
51
// The entry point for the application.
52
//
53
//*****************************************************************************
54
extern int main(void);
55
 
56
//*****************************************************************************
57
//
58
// External declaration for the interrupt handler used by the application.
59
//
60
//*****************************************************************************
61
extern void ADC_isr( void );
62
 
63
//*****************************************************************************
64
//
65
// Reserve space for the system stack.
66
//
67
//*****************************************************************************
68
#ifndef STACK_SIZE
69
#define STACK_SIZE                              64
70
#endif
71
 
72
// mthomas: added section -> alignment thru linker-script
73
__attribute__ ((section(".stackarea")))
74
static unsigned long pulStack[STACK_SIZE];
75
 
76
//*****************************************************************************
77
//
78
// The minimal vector table for a Cortex M3.  Note that the proper constructs
79
// must be placed on this to ensure that it ends up at physical address
80
// 0x0000.0000.
81
//
82
//*****************************************************************************
83
__attribute__ ((section(".isr_vector")))
84
void (* const g_pfnVectors[])(void) =
85
{
86
    (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)),
87
                                            // The initial stack pointer
88
    ResetISR,                               // The reset handler
89
    NmiSR,                                  // The NMI handler
90
    FaultISR,                               // The hard fault handler
91
    IntDefaultHandler,                      // The MPU fault handler
92
    IntDefaultHandler,                      // The bus fault handler
93
    IntDefaultHandler,                      // The usage fault handler
94
    0,                                      // Reserved
95
    0,                                      // Reserved
96
    0,                                      // Reserved
97
    0,                                      // Reserved
98
    IntDefaultHandler,                      // SVCall handler
99
    IntDefaultHandler,                      // Debug monitor handler
100
    0,                                      // Reserved
101
    IntDefaultHandler,                      // The PendSV handler
102
    IntDefaultHandler,                      // The SysTick handler
103
    IntDefaultHandler,                      // GPIO Port A
104
    IntDefaultHandler,                      // GPIO Port B
105
    IntDefaultHandler,                      // GPIO Port C
106
    IntDefaultHandler,                      // GPIO Port D
107
    IntDefaultHandler,                      // GPIO Port E
108
    IntDefaultHandler,                      // UART0 Rx and Tx
109
    IntDefaultHandler,                      // UART1 Rx and Tx
110
    IntDefaultHandler,                      // SSI Rx and Tx
111
    IntDefaultHandler,                      // I2C Master and Slave
112
    IntDefaultHandler,                      // PWM Fault
113
    IntDefaultHandler,                      // PWM Generator 0
114
    IntDefaultHandler,                      // PWM Generator 1
115
    IntDefaultHandler,                      // PWM Generator 2
116
    IntDefaultHandler,                      // Quadrature Encoder
117
    ADC_isr,                                // ADC Sequence 0
118
    IntDefaultHandler,                      // ADC Sequence 1
119
    IntDefaultHandler,                      // ADC Sequence 2
120
    IntDefaultHandler,                      // ADC Sequence 3
121
    IntDefaultHandler,                      // Watchdog timer
122
    IntDefaultHandler,                      // Timer 0 subtimer A
123
    IntDefaultHandler,                      // Timer 0 subtimer B
124
    IntDefaultHandler,                      // Timer 1 subtimer A
125
    IntDefaultHandler,                      // Timer 1 subtimer B
126
    IntDefaultHandler,                      // Timer 2 subtimer A
127
    IntDefaultHandler,                      // Timer 2 subtimer B
128
    IntDefaultHandler,                      // Analog Comparator 0
129
    IntDefaultHandler,                      // Analog Comparator 1
130
    IntDefaultHandler,                      // Analog Comparator 2
131
    IntDefaultHandler,                      // System Control (PLL, OSC, BO)
132
    IntDefaultHandler                       // FLASH Control
133
};
134
 
135
//*****************************************************************************
136
//
137
// The following are constructs created by the linker, indicating where the
138
// the "data" and "bss" segments reside in memory.  The initializers for the
139
// for the "data" segment resides immediately following the "text" segment.
140
//
141
//*****************************************************************************
142
extern unsigned long _etext;
143
extern unsigned long _data;
144
extern unsigned long _edata;
145
extern unsigned long _bss;
146
extern unsigned long _ebss;
147
 
148
//*****************************************************************************
149
//
150
// This is the code that gets called when the processor first starts execution
151
// following a reset event.  Only the absolutely necessary set is performed,
152
// after which the application supplied main() routine is called.  Any fancy
153
// actions (such as making decisions based on the reset cause register, and
154
// resetting the bits in that register) are left solely in the hands of the
155
// application.
156
//
157
//*****************************************************************************
158
void
159
ResetISR(void)
160
{
161
    unsigned long *pulSrc, *pulDest;
162
 
163
    //
164
    // Copy the data segment initializers from flash to SRAM.
165
    //
166
    pulSrc = &_etext;
167
    for(pulDest = &_data; pulDest < &_edata; )
168
    {
169
        *pulDest++ = *pulSrc++;
170
    }
171
 
172
    //
173
    // Zero fill the bss segment.
174
    //
175
    for(pulDest = &_bss; pulDest < &_ebss; )
176
    {
177
        *pulDest++ = 0;
178
    }
179
 
180
    //
181
    // Call the application's entry point.
182
    //
183
    main();
184
}
185
 
186
//*****************************************************************************
187
//
188
// This is the code that gets called when the processor receives a NMI.  This
189
// simply enters an infinite loop, preserving the system state for examination
190
// by a debugger.
191
//
192
//*****************************************************************************
193
static void
194
NmiSR(void)
195
{
196
    //
197
    // Enter an infinite loop.
198
    //
199
    while(1)
200
    {
201
    }
202
}
203
 
204
//*****************************************************************************
205
//
206
// This is the code that gets called when the processor receives a fault
207
// interrupt.  This simply enters an infinite loop, preserving the system state
208
// for examination by a debugger.
209
//
210
//*****************************************************************************
211
static void
212
FaultISR(void)
213
{
214
    //
215
    // Enter an infinite loop.
216
    //
217
    while(1)
218
    {
219
    }
220
}
221
 
222
//*****************************************************************************
223
//
224
// This is the code that gets called when the processor receives an unexpected
225
// interrupt.  This simply enters an infinite loop, preserving the system state
226
// for examination by a debugger.
227
//
228
//*****************************************************************************
229
static void
230
IntDefaultHandler(void)
231
{
232
    //
233
    // Go into an infinite loop.
234
    //
235
    while(1)
236
    {
237
    }
238
}