4 * \brief Startup file for SAM4S.
\r
6 * Copyright (c) 2011 Atmel Corporation. All rights reserved.
\r
10 * Redistribution and use in source and binary forms, with or without
\r
11 * modification, are permitted provided that the following conditions are met:
\r
13 * 1. Redistributions of source code must retain the above copyright notice,
\r
14 * this list of conditions and the following disclaimer.
\r
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
17 * this list of conditions and the following disclaimer in the documentation
\r
18 * and/or other materials provided with the distribution.
\r
20 * 3. The name of Atmel may not be used to endorse or promote products derived
\r
21 * from this software without specific prior written permission.
\r
23 * 4. This software may only be redistributed and used in connection with an
\r
24 * Atmel microcontroller product.
\r
26 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
29 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
36 * POSSIBILITY OF SUCH DAMAGE.
\r
42 #include "exceptions.h"
\r
44 #include "system_sam4s.h"
\r
46 /* Initialize segments */
\r
47 extern uint32_t _sfixed;
\r
48 extern uint32_t _efixed;
\r
49 extern uint32_t _etext;
\r
50 extern uint32_t _srelocate;
\r
51 extern uint32_t _erelocate;
\r
52 extern uint32_t _szero;
\r
53 extern uint32_t _ezero;
\r
54 extern uint32_t _sstack;
\r
55 extern uint32_t _estack;
\r
57 /** \cond DOXYGEN_SHOULD_SKIP_THIS */
\r
61 void __libc_init_array(void);
\r
63 /* Exception Table */
\r
64 __attribute__ ((section(".vectors")))
\r
65 IntFunc exception_table[] = {
\r
67 /* Configure Initial Stack Pointer, using linker-generated symbols */
\r
68 (IntFunc) (&_estack),
\r
76 0, 0, 0, 0, /* Reserved */
\r
83 /* Configurable interrupts */
\r
84 SUPC_Handler, /* 0 Supply Controller */
\r
85 RSTC_Handler, /* 1 Reset Controller */
\r
86 RTC_Handler, /* 2 Real Time Clock */
\r
87 RTT_Handler, /* 3 Real Time Timer */
\r
88 WDT_Handler, /* 4 Watchdog Timer */
\r
89 PMC_Handler, /* 5 PMC */
\r
90 EFC_Handler, /* 6 EFC */
\r
91 Dummy_Handler, /* 7 Reserved */
\r
92 UART0_Handler, /* 8 UART0 */
\r
93 UART1_Handler, /* 9 UART1 */
\r
94 SMC_Handler, /* 10 SMC */
\r
95 PIOA_Handler, /* 11 Parallel IO Controller A */
\r
96 PIOB_Handler, /* 12 Parallel IO Controller B */
\r
97 PIOC_Handler, /* 13 Parallel IO Controller C */
\r
98 USART0_Handler, /* 14 USART 0 */
\r
99 USART1_Handler, /* 15 USART 1 */
\r
100 Dummy_Handler, /* 16 Reserved */
\r
101 Dummy_Handler, /* 17 Reserved */
\r
102 HSMCI_Handler, /* 18 HSMCI */
\r
103 TWI0_Handler, /* 19 TWI 0 */
\r
104 TWI1_Handler, /* 20 TWI 1 */
\r
105 SPI_Handler, /* 21 SPI */
\r
106 SSC_Handler, /* 22 SSC */
\r
107 TC0_Handler, /* 23 Timer Counter 0 */
\r
108 TC1_Handler, /* 24 Timer Counter 1 */
\r
109 TC2_Handler, /* 25 Timer Counter 2 */
\r
110 TC3_Handler, /* 26 Timer Counter 3 */
\r
111 TC4_Handler, /* 27 Timer Counter 4 */
\r
112 TC5_Handler, /* 28 Timer Counter 5 */
\r
113 ADC_Handler, /* 29 ADC controller */
\r
114 DACC_Handler, /* 30 DACC controller */
\r
115 PWM_Handler, /* 31 PWM */
\r
116 CRCCU_Handler, /* 32 CRC Calculation Unit */
\r
117 ACC_Handler, /* 33 Analog Comparator */
\r
118 UDP_Handler, /* 34 USB Device Port */
\r
119 Dummy_Handler /* 35 not used */
\r
122 /* TEMPORARY PATCH FOR SCB */
\r
123 #define SCB_VTOR_TBLBASE_Pos 29 /*!< SCB VTOR: TBLBASE Position */
\r
124 #define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */
\r
127 * \brief This is the code that gets called on processor reset.
\r
128 * To initialize the device, and call the main() routine.
\r
130 void Reset_Handler(void)
\r
132 uint32_t *pSrc, *pDest;
\r
134 /* Initialize the relocate segment */
\r
136 pDest = &_srelocate;
\r
138 if (pSrc != pDest) {
\r
139 for (; pDest < &_erelocate;) {
\r
140 *pDest++ = *pSrc++;
\r
144 /* Clear the zero segment */
\r
145 for (pDest = &_szero; pDest < &_ezero;) {
\r
149 /* Set the vector table base address */
\r
150 pSrc = (uint32_t *) & _sfixed;
\r
151 SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);
\r
153 if (((uint32_t) pSrc >= IRAM_ADDR) && ((uint32_t) pSrc < IRAM_ADDR + IRAM_SIZE)) {
\r
154 SCB->VTOR |= 1 << SCB_VTOR_TBLBASE_Pos;
\r
157 /* Initialize the C library */
\r
158 __libc_init_array();
\r
160 /* Branch to main function */
\r
163 /* Infinite loop */
\r