00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <stdint.h>
00038
00039
00040
00041
00042 extern uint32_t __etext;
00043 extern uint32_t __data_start__;
00044 extern uint32_t __data_end__;
00045 extern uint32_t __copy_table_start__;
00046 extern uint32_t __copy_table_end__;
00047 extern uint32_t __zero_table_start__;
00048 extern uint32_t __zero_table_end__;
00049 extern uint32_t __bss_start__;
00050 extern uint32_t __bss_end__;
00051 extern uint32_t __StackTop;
00052
00053
00054
00055
00056 typedef void( *pFunc )( void );
00057
00058
00059
00060
00061
00062 #ifndef __START
00063 extern void _start(void) __attribute__((noreturn));
00064 #else
00065 extern int __START(void) __attribute__((noreturn));
00066 #endif
00067
00068 #ifndef __NO_SYSTEM_INIT
00069 extern void SystemInit (void);
00070 #endif
00071
00072
00073
00074
00075
00076 void Default_Handler(void);
00077 void Reset_Handler(void);
00078
00079
00080
00081
00082
00083 #ifndef __STACK_SIZE
00084 #define __STACK_SIZE 0x00000400
00085 #endif
00086 static uint8_t stack[__STACK_SIZE] __attribute__ ((aligned(8), used, section(".stack")));
00087
00088 #ifndef __HEAP_SIZE
00089 #define __HEAP_SIZE 0x00000C00
00090 #endif
00091 #if __HEAP_SIZE > 0
00092 static uint8_t heap[__HEAP_SIZE] __attribute__ ((aligned(8), used, section(".heap")));
00093 #endif
00094
00095
00096
00097
00098
00099
00100 void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
00101 void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
00102 void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
00103 void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
00104 void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
00105
00106
00107 void DMA_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00108 void GPIO_EVEN_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00109 void TIMER0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00110 void ACMP0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00111 void ADC0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00112 void I2C0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00113 void GPIO_ODD_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00114 void TIMER1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00115 void USART1_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00116 void USART1_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00117 void LEUART0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00118 void PCNT0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00119 void RTC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00120 void CMU_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00121 void VCMP_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00122 void MSC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00123 void AES_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00124 void USART0_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00125 void USART0_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00126 void USB_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00127 void TIMER2_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
00128
00129
00130
00131
00132
00133
00134 const pFunc __Vectors[] __attribute__ ((section(".vectors"))) = {
00135
00136 (pFunc)&__StackTop,
00137 Reset_Handler,
00138 NMI_Handler,
00139 HardFault_Handler,
00140 Default_Handler,
00141 Default_Handler,
00142 Default_Handler,
00143 Default_Handler,
00144 Default_Handler,
00145 Default_Handler,
00146 Default_Handler,
00147 SVC_Handler,
00148 Default_Handler,
00149 Default_Handler,
00150 PendSV_Handler,
00151 SysTick_Handler,
00152
00153
00154 DMA_IRQHandler,
00155 GPIO_EVEN_IRQHandler,
00156 TIMER0_IRQHandler,
00157 ACMP0_IRQHandler,
00158 ADC0_IRQHandler,
00159 I2C0_IRQHandler,
00160 GPIO_ODD_IRQHandler,
00161 TIMER1_IRQHandler,
00162 USART1_RX_IRQHandler,
00163 USART1_TX_IRQHandler,
00164 LEUART0_IRQHandler,
00165 PCNT0_IRQHandler,
00166 RTC_IRQHandler,
00167 CMU_IRQHandler,
00168 VCMP_IRQHandler,
00169 MSC_IRQHandler,
00170 AES_IRQHandler,
00171 USART0_RX_IRQHandler,
00172 USART0_TX_IRQHandler,
00173 USB_IRQHandler,
00174 TIMER2_IRQHandler,
00175
00176 };
00177
00178
00179
00180
00181
00182 void Reset_Handler(void) {
00183 uint32_t *pSrc, *pDest;
00184 uint32_t *pTable __attribute__((unused));
00185
00186 #ifndef __NO_SYSTEM_INIT
00187 SystemInit();
00188 #endif
00189
00190
00191
00192
00193
00194
00195
00196 #ifdef __STARTUP_COPY_MULTIPLE
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 pTable = &__copy_table_start__;
00208
00209 for (; pTable < &__copy_table_end__; pTable = pTable + 3)
00210 {
00211 pSrc = (uint32_t*)*(pTable + 0);
00212 pDest = (uint32_t*)*(pTable + 1);
00213 for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; )
00214 {
00215 *pDest++ = *pSrc++;
00216 }
00217 }
00218 #else
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 pSrc = &__etext;
00229 pDest = &__data_start__;
00230
00231 for ( ; pDest < &__data_end__ ; )
00232 {
00233 *pDest++ = *pSrc++;
00234 }
00235 #endif
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
00248
00249
00250
00251
00252
00253
00254
00255 pTable = &__zero_table_start__;
00256
00257 for (; pTable < &__zero_table_end__; pTable = pTable + 2)
00258 {
00259 pDest = (uint32_t*)*(pTable + 0);
00260 for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; )
00261 {
00262 *pDest++ = 0;
00263 }
00264 }
00265 #elif defined (__STARTUP_CLEAR_BSS)
00266
00267
00268
00269
00270
00271
00272
00273
00274 pDest = &__bss_start__;
00275
00276 for ( ; pDest < &__bss_end__ ; )
00277 {
00278 *pDest++ = 0ul;
00279 }
00280 #endif
00281
00282 #ifndef __START
00283 #define __START _start
00284 #endif
00285 __START();
00286 }
00287
00288
00289
00290
00291
00292 void Default_Handler(void)
00293 {
00294 while(1);
00295 }
00296