Contiki-NG
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 cc2538 chip, to be used when building with gcc
38  */
39 #include "contiki.h"
40 #include "reg.h"
41 #include "flash.h"
42 #include "sys-ctrl.h"
43 #include "rom-util.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 void crypto_isr(void);
66 void pka_isr(void);
67 
68 /* Link in the USB ISR only if USB is enabled */
69 #if USB_SERIAL_CONF_ENABLE
70 void usb_isr(void);
71 #else
72 #define usb_isr default_handler
73 #endif
74 
75 /* Likewise for the UART[01] ISRs */
76 #if UART_CONF_ENABLE
77 void uart0_isr(void);
78 void uart1_isr(void);
79 #else /* UART_CONF_ENABLE */
80 #define uart0_isr default_handler
81 #define uart1_isr default_handler
82 #endif /* UART_CONF_ENABLE */
83 
84 /* Boot Loader Backdoor selection */
85 #if FLASH_CCA_CONF_BOOTLDR_BACKDOOR
86 /* Backdoor enabled */
87 
88 #if FLASH_CCA_CONF_BOOTLDR_BACKDOOR_ACTIVE_HIGH
89 #define FLASH_CCA_BOOTLDR_CFG_ACTIVE_LEVEL FLASH_CCA_BOOTLDR_CFG_ACTIVE_HIGH
90 #else
91 #define FLASH_CCA_BOOTLDR_CFG_ACTIVE_LEVEL 0
92 #endif
93 
94 #if ((FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN < 0) || (FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN > 7))
95 #error Invalid boot loader backdoor pin. Please set FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN between 0 and 7 (indicating PA0 - PA7).
96 #endif
97 
98 #define FLASH_CCA_BOOTLDR_CFG (FLASH_CCA_BOOTLDR_CFG_ENABLE \
99  | FLASH_CCA_BOOTLDR_CFG_ACTIVE_LEVEL \
100  | (FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN << FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_S))
101 #else
102 #define FLASH_CCA_BOOTLDR_CFG FLASH_CCA_BOOTLDR_CFG_DISABLE
103 #endif
104 /*---------------------------------------------------------------------------*/
105 /* Allocate stack space */
106 static uint64_t stack[256] __attribute__ ((section(".stack")));
107 /*---------------------------------------------------------------------------*/
108 __attribute__((__section__(".vectors")))
109 void(*const vectors[])(void) =
110 {
111  (void (*)(void))((unsigned long)stack + sizeof(stack)), /* Stack pointer */
112  reset_handler, /* Reset handler */
113  nmi_handler, /* The NMI handler */
114  default_handler, /* The hard fault handler */
115  default_handler, /* 4 The MPU fault handler */
116  default_handler, /* 5 The bus fault handler */
117  default_handler, /* 6 The usage fault handler */
118  0, /* 7 Reserved */
119  0, /* 8 Reserved */
120  0, /* 9 Reserved */
121  0, /* 10 Reserved */
122  default_handler, /* 11 SVCall handler */
123  default_handler, /* 12 Debug monitor handler */
124  0, /* 13 Reserved */
125  default_handler, /* 14 The PendSV handler */
126  clock_isr, /* 15 The SysTick handler */
127  gpio_port_a_isr, /* 16 GPIO Port A */
128  gpio_port_b_isr, /* 17 GPIO Port B */
129  gpio_port_c_isr, /* 18 GPIO Port C */
130  gpio_port_d_isr, /* 19 GPIO Port D */
131  0, /* 20 none */
132  uart0_isr, /* 21 UART0 Rx and Tx */
133  uart1_isr, /* 22 UART1 Rx and Tx */
134  default_handler, /* 23 SSI0 Rx and Tx */
135  default_handler, /* 24 I2C Master and Slave */
136  0, /* 25 Reserved */
137  0, /* 26 Reserved */
138  0, /* 27 Reserved */
139  0, /* 28 Reserved */
140  0, /* 29 Reserved */
141  default_handler, /* 30 ADC Sequence 0 */
142  0, /* 31 Reserved */
143  0, /* 32 Reserved */
144  0, /* 33 Reserved */
145  default_handler, /* 34 Watchdog timer, timer 0 */
146  default_handler, /* 35 Timer 0 subtimer A */
147  default_handler, /* 36 Timer 0 subtimer B */
148  default_handler, /* 37 Timer 1 subtimer A */
149  default_handler, /* 38 Timer 1 subtimer B */
150  default_handler, /* 39 Timer 2 subtimer A */
151  default_handler, /* 40 Timer 2 subtimer B */
152  default_handler, /* 41 Analog Comparator 0 */
153  default_handler, /* 42 RFCore Rx/Tx (Alternate) */
154  default_handler, /* 43 RFCore Error (Alternate) */
155  default_handler, /* 44 System Control */
156  default_handler, /* 45 FLASH Control */
157  default_handler, /* 46 AES (Alternate) */
158  default_handler, /* 47 PKA (Alternate) */
159  default_handler, /* 48 SM Timer (Alternate) */
160  default_handler, /* 49 MacTimer (Alternate) */
161  default_handler, /* 50 SSI1 Rx and Tx */
162  default_handler, /* 51 Timer 3 subtimer A */
163  default_handler, /* 52 Timer 3 subtimer B */
164  0, /* 53 Reserved */
165  0, /* 54 Reserved */
166  0, /* 55 Reserved */
167  0, /* 56 Reserved */
168  0, /* 57 Reserved */
169  0, /* 58 Reserved */
170  0, /* 59 Reserved */
171  0, /* 60 Reserved */
172  0, /* 61 Reserved */
173  udma_isr, /* 62 uDMA */
174  udma_err_isr, /* 63 uDMA Error */
175  0, /* 64 64-155 are not in use */
176  0, /* 65 */
177  0, /* 66 */
178  0, /* 67 */
179  0, /* 68 */
180  0, /* 69 */
181  0, /* 70 */
182  0, /* 71 */
183  0, /* 72 */
184  0, /* 73 */
185  0, /* 74 */
186  0, /* 75 */
187  0, /* 76 */
188  0, /* 77 */
189  0, /* 78 */
190  0, /* 79 */
191  0, /* 80 */
192  0, /* 81 */
193  0, /* 82 */
194  0, /* 83 */
195  0, /* 84 */
196  0, /* 85 */
197  0, /* 86 */
198  0, /* 87 */
199  0, /* 88 */
200  0, /* 89 */
201  0, /* 90 */
202  0, /* 91 */
203  0, /* 92 */
204  0, /* 93 */
205  0, /* 94 */
206  0, /* 95 */
207  0, /* 96 */
208  0, /* 97 */
209  0, /* 98 */
210  0, /* 99 */
211  0, /* 100 */
212  0, /* 101 */
213  0, /* 102 */
214  0, /* 103 */
215  0, /* 104 */
216  0, /* 105 */
217  0, /* 106 */
218  0, /* 107 */
219  0, /* 108 */
220  0, /* 109 */
221  0, /* 110 */
222  0, /* 111 */
223  0, /* 112 */
224  0, /* 113 */
225  0, /* 114 */
226  0, /* 115 */
227  0, /* 116 */
228  0, /* 117 */
229  0, /* 118 */
230  0, /* 119 */
231  0, /* 120 */
232  0, /* 121 */
233  0, /* 122 */
234  0, /* 123 */
235  0, /* 124 */
236  0, /* 125 */
237  0, /* 126 */
238  0, /* 127 */
239  0, /* 128 */
240  0, /* 129 */
241  0, /* 130 */
242  0, /* 131 */
243  0, /* 132 */
244  0, /* 133 */
245  0, /* 134 */
246  0, /* 135 */
247  0, /* 136 */
248  0, /* 137 */
249  0, /* 138 */
250  0, /* 139 */
251  0, /* 140 */
252  0, /* 141 */
253  0, /* 142 */
254  0, /* 143 */
255  0, /* 144 */
256  0, /* 145 */
257  0, /* 146 */
258  0, /* 147 */
259  0, /* 148 */
260  0, /* 149 */
261  0, /* 150 */
262  0, /* 151 */
263  0, /* 152 */
264  0, /* 153 */
265  0, /* 154 */
266  0, /* 155 */
267  usb_isr, /* 156 USB */
268  cc2538_rf_rx_tx_isr, /* 157 RFCORE RX/TX */
269  cc2538_rf_err_isr, /* 158 RFCORE Error */
270  crypto_isr, /* 159 AES */
271  pka_isr, /* 160 PKA */
272  rtimer_isr, /* 161 SM Timer */
273  default_handler, /* 162 MACTimer */
274 };
275 /*---------------------------------------------------------------------------*/
276 __attribute__((__section__(".flashcca")))
277 const flash_cca_lock_page_t flash_cca_lock_page = {
278  FLASH_CCA_BOOTLDR_CFG, /* Boot loader backdoor configuration */
279  FLASH_CCA_IMAGE_VALID, /* Image valid */
280  &vectors, /* Vector table */
281  /* Unlock all pages and debug */
282  { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
283  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
284  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
285  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
286 };
287 /*---------------------------------------------------------------------------*/
288 /* Linker constructs indicating .data and .bss segment locations */
289 extern uint8_t _ldata;
290 extern uint8_t _data;
291 extern uint8_t _edata;
292 extern uint8_t _bss;
293 extern uint8_t _ebss;
294 /*---------------------------------------------------------------------------*/
295 /* Weak interrupt handlers. */
296 void
297 nmi_handler(void)
298 {
299  reset_handler();
300  while(1);
301 }
302 /*---------------------------------------------------------------------------*/
303 void
304 default_handler(void)
305 {
306  while(1);
307 }
308 /*---------------------------------------------------------------------------*/
309 void
310 reset_handler(void)
311 {
312  REG(SYS_CTRL_EMUOVR) = 0xFF;
313 
314  /* Copy the data segment initializers from flash to SRAM. */
315  rom_util_memcpy(&_data, &_ldata, &_edata - &_data);
316 
317  /* Zero-fill the bss segment. */
318  rom_util_memset(&_bss, 0, &_ebss - &_bss);
319 
320  /* call the application's entry point. */
321  main();
322 
323  /* End here if main () returns */
324  while(1);
325 }
326 /*---------------------------------------------------------------------------*/
327 
328 /** @} */
void clock_isr(void)
The clock Interrupt Service Routine.
Definition: clock.c:242
Header file for the cc2538 System Control driver.
void cc2538_rf_err_isr(void)
The cc2538 RF Error ISR.
Definition: cc2538-rf.c:1175
void rtimer_isr(void)
The rtimer ISR.
Definition: rtimer-arch.c:136
void pka_isr(void)
The PKA engine ISR.
Definition: pka.c:62
Header file with register manipulation macro definitions.
#define SYS_CTRL_EMUOVR
Emulator override.
Definition: sys-ctrl.h:96
void cc2538_rf_rx_tx_isr(void)
The cc2538 RF RX/TX ISR.
Definition: cc2538-rf.c:1148
void crypto_isr(void)
The AES/SHA cryptoprocessor ISR.
Definition: crypto.c:59
Header file for the cc2538 ROM utility function library driver.
#define FLASH_CCA_IMAGE_VALID
Indicates valid image in flash.
Definition: flash.h:83