//------------------------------------------------------------------------------ // Copy flash function to RAM. //------------------------------------------------------------------------------ void Upgrade(void) { unsigned char *flash_start_ptr; // Initialize pointers unsigned char *flash_end_ptr; unsigned char *RAM_start_ptr; if (CheckUpgrade() != 0xff) return; //Initialize flash and ram start and end address flash_start_ptr = (unsigned char *)__segment_begin("FLASHCODE"); flash_end_ptr = (unsigned char *)__segment_end("FLASHCODE"); RAM_start_ptr = (unsigned char *)__segment_begin("RAMCODE"); //calculate function size unsigned long function_size = (unsigned long)(flash_end_ptr) - (unsigned long)(flash_start_ptr); // Copy flash function to RAM printf("Copy From %p to %p size=%ld\n", flash_start_ptr, RAM_start_ptr, function_size); memcpy(RAM_start_ptr,flash_start_ptr,function_size); motor_on(0, 0); printf("Jump to %p\n", FlashFirmware); // remove the flag of firmware struct _header h; SPI_FLASH_BufferRead((void*)&h, FIRMWARE_BASE, sizeof(h)); SPI_FLASH_BufferWrite((void*)&h, FIRMWARE_BASE + h.length + 2 * sizeof(h), sizeof(h)); FlashFirmware(); }
/*! \brief Initializes the heap. */ static void init_heap(void) { #ifdef _DEBUG #if __GNUC__ && __AVR32__ // Import the location of the heap. extern void __heap_start__; extern void __heap_end__; U32 *p_heap_word; // Initialize the heap. for (p_heap_word = &__heap_start__; (void *)p_heap_word < &__heap_end__; p_heap_word++) *p_heap_word = DEFAULT_HEAP_INIT_WORD; #elif __ICCAVR32__ // Import the location of the heap. #pragma segment = "HEAP" U32 *p_heap_word; // Initialize the heap. for (p_heap_word = __segment_begin("HEAP"); (void *)p_heap_word < __segment_end("HEAP"); p_heap_word++) *p_heap_word = DEFAULT_HEAP_INIT_WORD; #endif #endif }
struct page_s* find_uri(char* href) { char uri[32]; int i; for(i=0; i<sizeof uri - 1 && href[i] && href[i]!='?'; ++i) uri[i] = href[i]; // 3.11.2010 by LBS (introduced in wtimer project) uri[i] = 0; struct page_s *page; for(page = __segment_begin("HTML_HEADERS"); (void*)page < __segment_end("HTML_HEADERS"); ++page) { if(strcmp(page->name, uri) == 0) { if((page->flags & HTML_FLG_CGI) == 0) { #if defined( HTML_RES_IS_IN_CPU_FLASH ) // unsigned char *page_sig = (void*)(HTML_RES_START + (unsigned)page->addr - 2); unsigned char *page_sig = (unsigned char*)(page->addr) - 2; // 30.10.2011 if(page_sig[0] != 0x59 || page_sig[1] != 0x95) return 0; #elif defined( HTML_RES_IS_IN_EEPROM ) #error "Data in ext. memory is not supported in this http2 version!" /* unsigned char page_sig[2]; EEPROM_READ(html_base + (unsigned)page->addr - 2, page_sig, sizeof page_sig); if(page_sig[0] != 0x59 || page_sig[1] != 0x95) return 0; */ #else #error "Define HTML_RES_IS_IN_xxxxx macro in http2_def.h!" #endif } return page; } } return 0; }
int LoadConfigData(const wchar_t *path,const wchar_t *fname) { int f; char *buf; int result=-1; void *cfg; FSTAT _fstat; unsigned int rlen; cfg=(char *)__segment_begin("CONFIG_C"); unsigned int len=(char *)__segment_end("CONFIG_C")-(char *)__segment_begin("CONFIG_C"); if ((buf=new char[len])) { if (fstat(path,fname,&_fstat)!=-1) { if ((f=_fopen(path,fname,0x001,0x180,0))>=0) { rlen=fread(f,buf,len); fclose(f); if (rlen!=_fstat.fsize || rlen!=len) goto L_SAVENEWCFG; memcpy(cfg,buf,len); result=0; } } else { L_SAVENEWCFG: if ((f=_fopen(path,fname,0x204,0x180,0))>=0) { if (fwrite(f,cfg,len)==len) result=0; fclose(f); } } delete buf; } if (result>=0) { successed_config_path=path; successed_config_name=fname; } return(result); }
static void AppTaskCreate (void) { OS_ERR error = OS_ERR_NONE; struct OSTaskCreate_Arg* task_find; struct OSTaskCreate_Arg* task_end; task_find = __segment_begin("APP_TASK_DEFINE"); task_end = __segment_end("APP_TASK_DEFINE"); for(; task_find < task_end; task_find ++) { OSTaskCreate((OS_TCB *)task_find->p_tcb, (CPU_CHAR *)task_find->p_name, (OS_TASK_PTR )task_find->p_task, (void *)task_find->p_arg, (OS_PRIO )task_find->prio, (CPU_STK *)task_find->p_stk_base, (CPU_STK_SIZE)task_find->stk_limit, (CPU_STK_SIZE)task_find->stk_size, (OS_MSG_QTY )task_find->q_size, (OS_TICK )task_find->time_quanta, (void *)task_find->p_ext, (OS_OPT )task_find->opt, (OS_ERR *)&error ); if(error != OS_ERR_NONE) { goto ERROR_HANDLE; } } return; ERROR_HANDLE: switch(error) { case OS_ERR_NONE: break; default: while(1); break; } }
/** * This function will startup RT-Thread RTOS. */ void rtthread_startup(void) { /* init board */ rt_hw_board_init(); /* show version */ rt_show_version(); /* init tick */ rt_system_tick_init(); /* init kernel object */ rt_system_object_init(); /* init timer system */ rt_system_timer_init(); #ifdef RT_USING_HEAP #ifdef __ICCM16C__ rt_system_heap_init(__segment_begin("DATA16_HEAP"),__segment_end("DATA16_HEAP")); #endif #endif /* init scheduler system */ rt_system_scheduler_init(); #ifdef RT_USING_DEVICE /* init all device */ rt_device_init_all(); #endif /* init application */ rt_application_init(); #ifdef RT_USING_FINSH /* init finsh */ finsh_system_init(); finsh_set_device("uart0"); #endif /* init timer thread */ rt_system_timer_thread_init(); /* init idle thread */ rt_thread_idle_init(); /* start scheduler */ rt_system_scheduler_start(); /* never reach here */ return ; }
void _DLIB_TLS_MEMORY *__iar_dlib_perthread_access (void _DLIB_TLS_MEMORY *symbp) { void _DLIB_TLS_MEMORY *p_tls; uintptr_t tls_start; uintptr_t tls_offset; if (OSRunning != OS_STATE_OS_RUNNING) { /* If the kernel is not running yet? */ p_tls = (OS_TLS)__segment_begin("__DLIB_PERTHREAD"); /* ... return the pointer to the main TLS segment. */ } else { p_tls = (void *)OSTCBCurPtr->TLS_Tbl[OS_TLS_LibID]; /* Get the pointer to the TLS for the task */ } tls_start = (uintptr_t)(p_tls); tls_offset = (uintptr_t)(__IAR_DLIB_PERTHREAD_SYMBOL_OFFSET(symbp)); p_tls = (void _DLIB_TLS_MEMORY *)(tls_start + tls_offset); return (p_tls); }
static void AppSemCreate (void) { OS_ERR error = OS_ERR_NONE; struct OSSemCreate_Arg* sem_find; struct OSSemCreate_Arg* sem_end; sem_find = __segment_begin("APP_SEM_DEFINE"); sem_end = __segment_end("APP_SEM_DEFINE"); for(; sem_find < sem_end; sem_find ++) { OSSemCreate ((OS_SEM *)sem_find->p_sem, (CPU_CHAR *)sem_find->p_name, (OS_SEM_CTR )sem_find->cnt, (OS_ERR *)&error); if(error != OS_ERR_NONE) { goto ERROR_HANDLE; } } return; ERROR_HANDLE: switch(error) { case OS_ERR_NONE: break; default: while(1); break; } }
/* * Low-level initialization routine called during startup, before the main * function. */ int __low_level_init(void) { #if configHEAP_INIT #pragma segment = "HEAP" portBASE_TYPE *pxMem; #endif /* Enable exceptions. */ ENABLE_ALL_EXCEPTIONS(); /* Initialize interrupt handling. */ INTC_init_interrupts(); #if configHEAP_INIT { /* Initialize the heap used by malloc. */ for( pxMem = __segment_begin( "HEAP" ); pxMem < ( portBASE_TYPE * ) __segment_end( "HEAP" ); ) { *pxMem++ = 0xA5A5A5A5; } } #endif /* Code section present if and only if the debug trace is activated. */ #if configDBG { static const gpio_map_t DBG_USART_GPIO_MAP = { { configDBG_USART_RX_PIN, configDBG_USART_RX_FUNCTION }, { configDBG_USART_TX_PIN, configDBG_USART_TX_FUNCTION } }; static const usart_options_t DBG_USART_OPTIONS = { .baudrate = configDBG_USART_BAUDRATE, .charlength = 8, .paritytype = USART_NO_PARITY, .stopbits = USART_1_STOPBIT, .channelmode = USART_NORMAL_CHMODE }; /* Initialize the USART used for the debug trace with the configured parameters. */ extern volatile avr32_usart_t *volatile stdio_usart_base; stdio_usart_base = configDBG_USART; gpio_enable_module( DBG_USART_GPIO_MAP, sizeof( DBG_USART_GPIO_MAP ) / sizeof( DBG_USART_GPIO_MAP[0] ) ); usart_init_rs232(configDBG_USART, &DBG_USART_OPTIONS, configCPU_CLOCK_HZ); } #endif /* Request initialization of data segments. */ return 1; } /*-----------------------------------------------------------*/ /* Added as there is no such function in FreeRTOS. */ void *pvPortRealloc( void *pv, size_t xWantedSize ) { void *pvReturn; vTaskSuspendAll(); { pvReturn = realloc( pv, xWantedSize ); } xTaskResumeAll(); return pvReturn; }