Contiki-Inga 3.x
startup-gcc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
3  *
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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /**
33  * \addtogroup cc2538
34  * @{
35  *
36  * \file
37  * Startup code for the cc2538dk platform, to be used when building with gcc
38  */
39 #include "contiki.h"
40 #include "reg.h"
41 #include "flash-cca.h"
42 #include "sys-ctrl.h"
43 #include "uart.h"
44 
45 #include <stdint.h>
46 /*---------------------------------------------------------------------------*/
47 extern int main(void);
48 /*---------------------------------------------------------------------------*/
49 /* System handlers provided here */
50 void reset_handler(void);
51 void nmi_handler(void);
52 void default_handler(void);
53 
54 /* System Handler and ISR prototypes implemented elsewhere */
55 void clock_isr(void); /* SysTick Handler */
56 void gpio_port_a_isr(void);
57 void gpio_port_b_isr(void);
58 void gpio_port_c_isr(void);
59 void gpio_port_d_isr(void);
60 void rtimer_isr(void);
61 void cc2538_rf_rx_tx_isr(void);
62 void cc2538_rf_err_isr(void);
63 void udma_isr(void);
64 void udma_err_isr(void);
65 
66 /* Boot Loader Backdoor selection */
67 #if FLASH_CCA_CONF_BOOTLDR_BACKDOOR
68 /* Backdoor enabled, on PA_3 (Select button) */
69 #define FLASH_CCA_BOOTLDR_CFG (FLASH_CCA_BOOTLDR_CFG_ENABLE \
70  | ((3 << FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_S) & FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_M))
71 #else
72 #define FLASH_CCA_BOOTLDR_CFG FLASH_CCA_BOOTLDR_CFG_DISABLE
73 #endif
74 
75 /* Link in the USB ISR only if USB is enabled */
76 #if USB_SERIAL_CONF_ENABLE
77 void usb_isr(void);
78 #else
79 #define usb_isr default_handler
80 #endif
81 
82 /* Likewise for the UART[01] ISRs */
83 #if UART_CONF_ENABLE
84 void uart_isr(void);
85 
86 #if UART_BASE==UART_1_BASE
87 #define uart0_isr default_handler
88 #define uart1_isr uart_isr
89 #else
90 #define uart0_isr uart_isr
91 #define uart1_isr default_handler
92 #endif
93 
94 #else /* UART_CONF_ENABLE */
95 #define uart0_isr default_handler
96 #define uart1_isr default_handler
97 #endif /* UART_CONF_ENABLE */
98 /*---------------------------------------------------------------------------*/
99 /* Allocate stack space */
100 static unsigned long stack[512];
101 /*---------------------------------------------------------------------------*/
102 /* Linker construct indicating .text section location */
103 extern uint8_t _text[0];
104 /*---------------------------------------------------------------------------*/
105 __attribute__ ((section(".flashcca"), used))
106 const flash_cca_lock_page_t __cca = {
107  FLASH_CCA_BOOTLDR_CFG, /* Boot loader backdoor configuration */
108  FLASH_CCA_IMAGE_VALID, /* Image valid */
109  &_text, /* Vector table located at the start of .text */
110  /* Unlock all pages and debug */
111  { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
112  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
113  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
114  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
115 };
116 /*---------------------------------------------------------------------------*/
117 __attribute__ ((section(".vectors"), used))
118 void(*const vectors[])(void) =
119 {
120  (void (*)(void))((unsigned long)stack + sizeof(stack)), /* Stack pointer */
121  reset_handler, /* Reset handler */
122  nmi_handler, /* The NMI handler */
123  default_handler, /* The hard fault handler */
124  default_handler, /* 4 The MPU fault handler */
125  default_handler, /* 5 The bus fault handler */
126  default_handler, /* 6 The usage fault handler */
127  0, /* 7 Reserved */
128  0, /* 8 Reserved */
129  0, /* 9 Reserved */
130  0, /* 10 Reserved */
131  default_handler, /* 11 SVCall handler */
132  default_handler, /* 12 Debug monitor handler */
133  0, /* 13 Reserved */
134  default_handler, /* 14 The PendSV handler */
135  clock_isr, /* 15 The SysTick handler */
136  gpio_port_a_isr, /* 16 GPIO Port A */
137  gpio_port_b_isr, /* 17 GPIO Port B */
138  gpio_port_c_isr, /* 18 GPIO Port C */
139  gpio_port_d_isr, /* 19 GPIO Port D */
140  0, /* 20 none */
141  uart0_isr, /* 21 UART0 Rx and Tx */
142  uart1_isr, /* 22 UART1 Rx and Tx */
143  default_handler, /* 23 SSI0 Rx and Tx */
144  default_handler, /* 24 I2C Master and Slave */
145  0, /* 25 Reserved */
146  0, /* 26 Reserved */
147  0, /* 27 Reserved */
148  0, /* 28 Reserved */
149  0, /* 29 Reserved */
150  default_handler, /* 30 ADC Sequence 0 */
151  0, /* 31 Reserved */
152  0, /* 32 Reserved */
153  0, /* 33 Reserved */
154  default_handler, /* 34 Watchdog timer, timer 0 */
155  default_handler, /* 35 Timer 0 subtimer A */
156  default_handler, /* 36 Timer 0 subtimer B */
157  default_handler, /* 37 Timer 1 subtimer A */
158  default_handler, /* 38 Timer 1 subtimer B */
159  default_handler, /* 39 Timer 2 subtimer A */
160  default_handler, /* 40 Timer 2 subtimer B */
161  default_handler, /* 41 Analog Comparator 0 */
162  default_handler, /* 42 RFCore Rx/Tx (Alternate) */
163  default_handler, /* 43 RFCore Error (Alternate) */
164  default_handler, /* 44 System Control */
165  default_handler, /* 45 FLASH Control */
166  default_handler, /* 46 AES (Alternate) */
167  default_handler, /* 47 PKA (Alternate) */
168  default_handler, /* 48 SM Timer (Alternate) */
169  default_handler, /* 49 MacTimer (Alternate) */
170  default_handler, /* 50 SSI1 Rx and Tx */
171  default_handler, /* 51 Timer 3 subtimer A */
172  default_handler, /* 52 Timer 3 subtimer B */
173  0, /* 53 Reserved */
174  0, /* 54 Reserved */
175  0, /* 55 Reserved */
176  0, /* 56 Reserved */
177  0, /* 57 Reserved */
178  0, /* 58 Reserved */
179  0, /* 59 Reserved */
180  0, /* 60 Reserved */
181  0, /* 61 Reserved */
182  udma_isr, /* 62 uDMA */
183  udma_err_isr, /* 63 uDMA Error */
184  0, /* 64 64-155 are not in use */
185  0, /* 65 */
186  0, /* 66 */
187  0, /* 67 */
188  0, /* 68 */
189  0, /* 69 */
190  0, /* 70 */
191  0, /* 71 */
192  0, /* 72 */
193  0, /* 73 */
194  0, /* 74 */
195  0, /* 75 */
196  0, /* 76 */
197  0, /* 77 */
198  0, /* 78 */
199  0, /* 79 */
200  0, /* 80 */
201  0, /* 81 */
202  0, /* 82 */
203  0, /* 83 */
204  0, /* 84 */
205  0, /* 85 */
206  0, /* 86 */
207  0, /* 87 */
208  0, /* 88 */
209  0, /* 89 */
210  0, /* 90 */
211  0, /* 91 */
212  0, /* 92 */
213  0, /* 93 */
214  0, /* 94 */
215  0, /* 95 */
216  0, /* 96 */
217  0, /* 97 */
218  0, /* 98 */
219  0, /* 99 */
220  0, /* 100 */
221  0, /* 101 */
222  0, /* 102 */
223  0, /* 103 */
224  0, /* 104 */
225  0, /* 105 */
226  0, /* 106 */
227  0, /* 107 */
228  0, /* 108 */
229  0, /* 109 */
230  0, /* 110 */
231  0, /* 111 */
232  0, /* 112 */
233  0, /* 113 */
234  0, /* 114 */
235  0, /* 115 */
236  0, /* 116 */
237  0, /* 117 */
238  0, /* 118 */
239  0, /* 119 */
240  0, /* 120 */
241  0, /* 121 */
242  0, /* 122 */
243  0, /* 123 */
244  0, /* 124 */
245  0, /* 125 */
246  0, /* 126 */
247  0, /* 127 */
248  0, /* 128 */
249  0, /* 129 */
250  0, /* 130 */
251  0, /* 131 */
252  0, /* 132 */
253  0, /* 133 */
254  0, /* 134 */
255  0, /* 135 */
256  0, /* 136 */
257  0, /* 137 */
258  0, /* 138 */
259  0, /* 139 */
260  0, /* 140 */
261  0, /* 141 */
262  0, /* 142 */
263  0, /* 143 */
264  0, /* 144 */
265  0, /* 145 */
266  0, /* 146 */
267  0, /* 147 */
268  0, /* 148 */
269  0, /* 149 */
270  0, /* 150 */
271  0, /* 151 */
272  0, /* 152 */
273  0, /* 153 */
274  0, /* 154 */
275  0, /* 155 */
276  usb_isr, /* 156 USB */
277  cc2538_rf_rx_tx_isr, /* 157 RFCORE RX/TX */
278  cc2538_rf_err_isr, /* 158 RFCORE Error */
279  default_handler, /* 159 AES */
280  default_handler, /* 160 PKA */
281  rtimer_isr, /* 161 SM Timer */
282  default_handler, /* 162 MACTimer */
283 };
284 /*---------------------------------------------------------------------------*/
285 /* Linker constructs indicating .data and .bss segment locations */
286 extern unsigned long _etext;
287 extern unsigned long _data;
288 extern unsigned long _edata;
289 extern unsigned long _bss;
290 extern unsigned long _ebss;
291 /*---------------------------------------------------------------------------*/
292 /* Weak interrupt handlers. */
293 void
294 nmi_handler(void)
295 {
296  reset_handler();
297  while(1);
298 }
299 /*---------------------------------------------------------------------------*/
300 void
301 default_handler(void)
302 {
303  while(1);
304 }
305 /*---------------------------------------------------------------------------*/
306 void
307 reset_handler(void)
308 {
309  unsigned long *pul_src, *pul_dst;
310 
311  REG(SYS_CTRL_EMUOVR) = 0xFF;
312 
313  /* Copy the data segment initializers from flash to SRAM. */
314  pul_src = &_etext;
315 
316  for(pul_dst = &_data; pul_dst < &_edata;) {
317  *pul_dst++ = *pul_src++;
318  }
319 
320  /* Zero-fill the bss segment. */
321  __asm(" ldr r0, =_bss\n"
322  " ldr r1, =_ebss\n"
323  " mov r2, #0\n"
324  " .thumb_func\n"
325  "zero_loop:\n"
326  " cmp r0, r1\n"
327  " it lt\n"
328  " strlt r2, [r0], #4\n" " blt zero_loop");
329 
330  /* call the application's entry point. */
331  main();
332 
333  /* End here if main () returns */
334  while(1);
335 }
336 /*---------------------------------------------------------------------------*/
337 
338 /** @} */