]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4_SimpleLink_CC3220SF_CCS/ti/startup_cc32xx_ccs.c
Add SimpleLink CC3220SF demo.
[freertos] / FreeRTOS / Demo / CORTEX_M4_SimpleLink_CC3220SF_CCS / ti / startup_cc32xx_ccs.c
1 /*
2  * Copyright (c) 2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <stdint.h>
34 #include <string.h>
35
36 #include <ti/devices/cc32xx/inc/hw_types.h>
37 #include <ti/devices/cc32xx/inc/hw_ints.h>
38 #include <ti/devices/cc32xx/inc/hw_memmap.h>
39 #include <ti/devices/cc32xx/inc/hw_common_reg.h>
40
41 #include <ti/devices/cc32xx/driverlib/interrupt.h>
42 #include <ti/devices/cc32xx/inc/hw_apps_rcm.h>
43 #include <ti/devices/cc32xx/driverlib/rom_map.h>
44 #include <ti/devices/cc32xx/driverlib/prcm.h>
45
46 //*****************************************************************************
47 //
48 // Forward declaration of the default fault handlers.
49 //
50 //*****************************************************************************
51 void resetISR(void);
52 static void nmiISR(void);
53 static void faultISR(void);
54 static void defaultHandler(void);
55 static void busFaultHandler(void);
56
57 //*****************************************************************************
58 //
59 // External declaration for the reset handler that is to be called when the
60 // processor is started
61 //
62 //*****************************************************************************
63 extern void _c_int00(void);
64 extern void vPortSVCHandler(void);
65 extern void xPortPendSVHandler(void);
66 extern void xPortSysTickHandler(void);
67
68 //*****************************************************************************
69 //
70 // Linker variable that marks the top of the stack.
71 //
72 //*****************************************************************************
73 extern unsigned long __STACK_END;
74
75 //*****************************************************************************
76 // The vector table.  Note that the proper constructs must be placed on this to
77 // ensure that it ends up at physical address 0x0000.0000 or at the start of
78 // the program if located at a start address other than 0.
79 //
80 //*****************************************************************************
81 #pragma RETAIN(resetVectors)
82 #pragma DATA_SECTION(resetVectors, ".resetVecs")
83 void (* const resetVectors[16])(void) =
84 {
85     (void (*)(void))((unsigned long)&__STACK_END),
86                                          // The initial stack pointer
87     resetISR,                            // The reset handler
88     nmiISR,                              // The NMI handler
89     faultISR,                            // The hard fault handler
90     defaultHandler,                      // The MPU fault handler
91     busFaultHandler,                     // The bus fault handler
92     defaultHandler,                      // The usage fault handler
93     0,                                   // Reserved
94     0,                                   // Reserved
95     0,                                   // Reserved
96     0,                                   // Reserved
97     vPortSVCHandler,                     // SVCall handler
98     defaultHandler,                      // Debug monitor handler
99     0,                                   // Reserved
100     xPortPendSVHandler,                  // The PendSV handler
101     xPortSysTickHandler                  // The SysTick handler
102 };
103
104
105 #pragma DATA_SECTION(ramVectors, ".ramVecs")
106 static unsigned long ramVectors[256];
107
108 //*****************************************************************************
109 //
110 // Copy the first 16 vectors from the read-only/reset table to the runtime
111 // RAM table. Fill the remaining vectors with a stub. This vector table will
112 // be updated at runtime.
113 //
114 //*****************************************************************************
115 void initVectors(void)
116 {
117     int i;
118
119     /* Copy from reset vector table into RAM vector table */
120     memcpy(ramVectors, resetVectors, 16*4);
121
122     /* fill remaining vectors with default handler */
123     for (i=16; i < 256; i++) {
124         ramVectors[i] = (unsigned long)defaultHandler;
125     }
126
127     /* Set vector table base */
128     MAP_IntVTableBaseSet((unsigned long)&ramVectors[0]);
129
130     /* Enable Processor */
131     MAP_IntMasterEnable();
132     MAP_IntEnable(FAULT_SYSTICK);
133 }
134
135 //*****************************************************************************
136 //
137 // This is the code that gets called when the processor first starts execution
138 // following a reset event.  Only the absolutely necessary set is performed,
139 // after which the application supplied entry() routine is called.  Any fancy
140 // actions (such as making decisions based on the reset cause register, and
141 // resetting the bits in that register) are left solely in the hands of the
142 // application.
143 //
144 //*****************************************************************************
145 void resetISR(void)
146 {
147     /*
148      * Set stack pointer based on the stack value stored in the vector table.
149      * This is necessary to ensure that the application is using the correct
150      * stack when using a debugger since a reset within the debugger will
151      * load the stack pointer from the bootloader's vector table at address '0'.
152      */
153     __asm(" .global resetVectorAddr\n"
154           " ldr r0, resetVectorAddr\n"
155           " ldr r0, [r0]\n"
156           " mov sp, r0\n"
157           " bl initVectors");
158
159     /* Jump to the CCS C Initialization Routine. */
160     __asm(" .global _c_int00\n"
161           " b.w     _c_int00");
162
163     _Pragma("diag_suppress 1119");
164     __asm("resetVectorAddr: .word resetVectors");
165     _Pragma("diag_default 1119");
166 }
167
168 //*****************************************************************************
169 //
170 // This is the code that gets called when the processor receives a NMI.  This
171 // simply enters an infinite loop, preserving the system state for examination
172 // by a debugger.
173 //
174 //*****************************************************************************
175 static void
176 nmiISR(void)
177 {
178     /* Enter an infinite loop. */
179     while(1)
180     {
181     }
182 }
183
184 //*****************************************************************************
185 //
186 // This is the code that gets called when the processor receives a fault
187 // interrupt.  This simply enters an infinite loop, preserving the system state
188 // for examination by a debugger.
189 //
190 //*****************************************************************************
191 static void
192 faultISR(void)
193 {
194     /* Enter an infinite loop. */
195     while(1)
196     {
197     }
198 }
199
200 //*****************************************************************************
201 //
202 // This is the code that gets called when the processor receives an unexpected
203 // interrupt.  This simply enters an infinite loop, preserving the system state
204 // for examination by a debugger.
205 //
206 //*****************************************************************************
207
208 static void
209 busFaultHandler(void)
210 {
211     /* Enter an infinite loop. */
212     while(1)
213     {
214     }
215 }
216
217 //*****************************************************************************
218 //
219 // This is the code that gets called when the processor receives an unexpected
220 // interrupt.  This simply enters an infinite loop, preserving the system state
221 // for examination by a debugger.
222 //
223 //*****************************************************************************
224 static void
225 defaultHandler(void)
226 {
227     /* Enter an infinite loop. */
228     while(1)
229     {
230     }
231 }