23 #define IAP_BOOTLOADER_APP_SWITCH_SIGNATURE 0xb001204d
24 #define IAP_BOOTLOADER_MODE_UART 0
26 #include PLATFORM_HEADER
30 extern unsigned long _etext;
31 extern unsigned long _sidata;
32 extern unsigned long _sdata;
33 extern unsigned long _edata;
35 extern unsigned long _sbss;
36 extern unsigned long _ebss;
38 extern unsigned long _estack;
41 VAR_AT_SEGMENT(
const HalFixedAddressTableType halFixedAddressTable, __FAT__);
48 extern
int main(
void);
59 void NMI_Handler()
__attribute__ ((weak, alias("Default_Handler")));
60 void HardFault_Handler()
__attribute__ ((weak, alias("Default_Handler")));
61 void MemManage_Handler()
__attribute__ ((weak, alias("Default_Handler")));
62 void BusFault_Handler()
__attribute__ ((weak, alias("Default_Handler")));
63 void UsageFault_Handler()
__attribute__ ((weak, alias("Default_Handler")));
64 void SVC_Handler()
__attribute__ ((weak, alias("Default_Handler")));
65 void DebugMonitor_Handler()
__attribute__ ((weak, alias("Default_Handler")));
66 void PendSV_Handler()
__attribute__ ((weak, alias("Default_Handler")));
67 void SysTick_Handler()
__attribute__ ((weak, alias("Default_Handler")));
68 void halTimer1Isr()
__attribute__ ((weak, alias("Default_Handler")));
69 void halTimer2Isr()
__attribute__ ((weak, alias("Default_Handler")));
70 void halManagementIsr()
__attribute__ ((weak, alias("Default_Handler")));
71 void halBaseBandIsr()
__attribute__ ((weak, alias("Default_Handler")));
72 void halSleepTimerIsr()
__attribute__ ((weak, alias("Default_Handler")));
73 void halSc1Isr()
__attribute__ ((weak, alias("Default_Handler")));
74 void halSc2Isr()
__attribute__ ((weak, alias("Default_Handler")));
75 void halSecurityIsr()
__attribute__ ((weak, alias("Default_Handler")));
76 void halStackMacTimerIsr()
__attribute__ ((weak, alias("Default_Handler")));
77 void stmRadioTransmitIsr()
__attribute__ ((weak, alias("Default_Handler")));
78 void stmRadioReceiveIsr()
__attribute__ ((weak, alias("Default_Handler")));
79 void halAdcIsr()
__attribute__ ((weak, alias("Default_Handler")));
80 void halIrqAIsr()
__attribute__ ((weak, alias("Default_Handler")));
81 void halIrqBIsr()
__attribute__ ((weak, alias("Default_Handler")));
82 void halIrqCIsr()
__attribute__ ((weak, alias("Default_Handler")));
83 void halIrqDIsr()
__attribute__ ((weak, alias("Default_Handler")));
84 void halDebugIsr()
__attribute__ ((weak, alias("Default_Handler")));
105 void (* const g_pfnVectors[])(
void) =
107 (void (*)(void))&_estack,
119 DebugMonitor_Handler,
142 static void setStackPointer(int32u address)
__attribute__((noinline));
143 static void setStackPointer(int32u address)
148 asm(
".short 0x4685");
151 static const int16u blOffset[] = {
152 0x0715 - 0x03ad - 0x68,
153 0x0719 - 0x03ad - 0x6C
165 void Reset_Handler(
void)
185 DEBUG_EMCR &= ~DEBUG_EMCR_VC_CORERESET;
189 FLASH_ACCESS = (FLASH_ACCESS_PREFETCH_EN |
190 (1<<FLASH_ACCESS_CODE_LATENCY_BIT));
199 SCS_AIRCR = (0x05FA0000 | (4 <<SCS_AIRCR_PRIGROUP_BIT));
211 #define CRITICAL (0 <<3)
215 #define NONE (31 <<3)
225 SCS_SHPR_7to4 = ((CRITICAL <<SCS_SHPR_7to4_PRI_4_BIT) |
226 (CRITICAL <<SCS_SHPR_7to4_PRI_5_BIT) |
227 (CRITICAL <<SCS_SHPR_7to4_PRI_6_BIT) |
228 (NONE <<SCS_SHPR_7to4_PRI_7_BIT));
229 SCS_SHPR_11to8 = ((NONE <<SCS_SHPR_11to8_PRI_8_BIT) |
230 (NONE <<SCS_SHPR_11to8_PRI_9_BIT) |
231 (NONE <<SCS_SHPR_11to8_PRI_10_BIT) |
232 (HIGH <<SCS_SHPR_11to8_PRI_11_BIT));
233 SCS_SHPR_15to12 = ((MED <<SCS_SHPR_15to12_PRI_12_BIT) |
234 (NONE <<SCS_SHPR_15to12_PRI_13_BIT) |
235 (HIGH <<SCS_SHPR_15to12_PRI_14_BIT) |
236 (MED <<SCS_SHPR_15to12_PRI_15_BIT));
237 NVIC_IPR_3to0 = ((MED <<NVIC_IPR_3to0_PRI_0_BIT) |
238 (MED <<NVIC_IPR_3to0_PRI_1_BIT) |
239 (HIGH <<NVIC_IPR_3to0_PRI_2_BIT) |
240 (MED <<NVIC_IPR_3to0_PRI_3_BIT));
241 NVIC_IPR_7to4 = ((MED <<NVIC_IPR_7to4_PRI_4_BIT) |
242 (MED <<NVIC_IPR_7to4_PRI_5_BIT) |
243 (MED <<NVIC_IPR_7to4_PRI_6_BIT) |
244 (MED <<NVIC_IPR_7to4_PRI_7_BIT));
245 NVIC_IPR_11to8 = ((MED <<NVIC_IPR_11to8_PRI_8_BIT) |
246 (MED <<NVIC_IPR_11to8_PRI_9_BIT) |
247 (MED <<NVIC_IPR_11to8_PRI_10_BIT) |
248 (MED <<NVIC_IPR_11to8_PRI_11_BIT));
249 NVIC_IPR_15to12 = ((MED <<NVIC_IPR_15to12_PRI_12_BIT) |
250 (MED <<NVIC_IPR_15to12_PRI_13_BIT) |
251 (MED <<NVIC_IPR_15to12_PRI_14_BIT) |
252 (MED <<NVIC_IPR_15to12_PRI_15_BIT));
253 NVIC_IPR_19to16 = ((LOW <<NVIC_IPR_19to16_PRI_16_BIT));
259 SCS_CCR = SCS_CCR_DIV_0_TRP_MASK;
260 SCS_SHCSR = ( SCS_SHCSR_USGFAULTENA_MASK
261 | SCS_SHCSR_BUSFAULTENA_MASK
262 | SCS_SHCSR_MEMFAULTENA_MASK );
265 if((RESET_EVENT&RESET_DSLEEP) == RESET_DSLEEP) {
270 void halTriggerContextRestore(
void);
271 extern volatile boolean halPendSvSaveContext;
272 halPendSvSaveContext = 0;
273 SCS_ICSR |= SCS_ICSR_PENDSVSET;
274 halTriggerContextRestore();
281 int8u cut = *(
volatile int8u *) 0x08040798;
283 typedef void (*EntryPoint)(void);
284 offset = (halFixedAddressTable.baseTable.version == 3) ? blOffset[cut - 2] : 0;
285 *((int32u *)RAM_BOTTOM) = 0;
289 EntryPoint entryPoint = (EntryPoint)(*(int32u *)(FIB_BOTTOM+4) - offset);
290 setStackPointer(*(int32u *)FIB_BOTTOM);
304 unsigned long *pulSrc, *pulDest;
310 for(pulDest = &_sdata; pulDest < &_edata; )
312 *(pulDest++) = *(pulSrc++);
318 for(pulDest = &_sbss; pulDest < &_ebss; )
329 static unsigned char __HEAP_START[1024*3-560+0x200];
330 caddr_t _sbrk (
int incr )
332 static unsigned char *heap =
NULL;
333 unsigned char *prev_heap;
337 heap = (
unsigned char *)__HEAP_START;
341 if ((heap + incr) > (__HEAP_START +
sizeof(__HEAP_START))) {
346 if (prev_heap ==
NULL) {
347 printf (
"_sbrk %d return %p\n\r", incr, prev_heap);
349 return (caddr_t) prev_heap;
352 caddr_t _sbrk (
int incr )
357 int _lseek (
int file,
363 int _close (
int file)
376 int _kill (
int n,
int m)
380 int _fstat(
int file,
struct stat *st)
382 st->st_mode = S_IFCHR;
394 int _open (
const char * path,
400 int _fflush_r(
struct _reent *r, FILE *f)