/********************************************************************************************************* **函数名称: WriteFlash **函数功能: 向FLASH中写入数据 **入口参数: dst 目标地址,即FLASH起始地址,地址必须以256字节对齐,即地址的低8位必须为0 ** src 源地址,即RAM地址,地址必须字对齐,即地址的低两位必须为0 ** no 写入字节数,必须为256/512/1024/4096 **出口参数: Compare的返回值,操作成功正确返回0 ********************************************************************************************************/ INT8U WriteFlash(INT32U dst, INT32U src, INT32U no) { SelSector((dst/0x1000),(dst+no)/0x1000); // 选择扇区 EraseSector((dst/0x1000),(dst+no)/0x1000); // 擦除扇区 BlankCHK((dst/0x1000),(dst+no)/0x1000); // 查空扇区 SelSector((dst/0x1000),(dst+no)/0x1000); // 选择扇区 RamToFlash(dst,src,no); // 写数据到FLASH return(Compare(dst,src,no)); // 比较数据 }
/* ******************************************************************************************************* ** 函数名称:read_userinfo_flash() ** 函数功能:清除冷热启动信息 ** 入口参数:无 ** 出口参数:无 ** ******************************************************************************************************* */ void clean_userinfo_flash(void) { //User_Info_Flash *readflash; User_Info_Flash *writeflash = (User_Info_Flash *)flashdata; writeflash->poweron_cnt = 1; writeflash->powerup_cnt = 0; writeflash->is_fistpoweron = 0x12801280; writeflash->err_type = 0; /*将更新好的数据写入到flash*/ SelSector(14,14); // 选择扇区14 EraseSector(14,14); // 擦除扇区14 BlankCHK(14,14) ; // 查空扇区14 SelSector(14,14); // 选择扇区14 RamToFlash(USER_FLASH_ADDR,(uint32)flashdata, 512); }
/* ******************************************************************************************************* ** 函数名称:powerup_process() ** 函数功能:冷热启动处理 ** 入口参数:无 ** 出口参数:无 ** ******************************************************************************************************* */ void startup_process(void) { User_Info_Flash *readflash; User_Info_Flash *writeflash; readflash = (User_Info_Flash *)USER_FLASH_ADDR; //flash地址 writeflash = (User_Info_Flash *)flashdata; //暂存flash数据数组 /*更新User_Info_Flash 结构体的各个字段*/ if(readflash->is_fistpoweron != 0x12801280){ //判断是否为首次上电 IS_HOTSTART1 = 0x128A128A; IS_HOTSTART2 = 0x128B128B; RESET_TYPE = 0; writeflash->is_fistpoweron = 0x12801280; //初始化各个字段 writeflash->poweron_cnt = 1; writeflash->powerup_cnt = 0; writeflash->err_type = 0; }else{ if((IS_HOTSTART1 == 0x128A128A)&&(IS_HOTSTART2 == 0x128B128B)){ //复位启动 writeflash->is_fistpoweron = 0x12801280; writeflash->poweron_cnt = readflash->poweron_cnt; writeflash->powerup_cnt = (readflash->powerup_cnt+1); writeflash->err_type = RESET_TYPE; }else{ IS_HOTSTART1 = 0x128A128A; IS_HOTSTART2 = 0x128B128B; RESET_TYPE = 0; //上电启动 writeflash->is_fistpoweron = 0x12801280; writeflash->poweron_cnt = (readflash->poweron_cnt + 1); writeflash->powerup_cnt = readflash->powerup_cnt; writeflash->err_type = readflash->err_type; } } /*将更新好的数据写入到flash*/ SelSector(14,14); // 选择扇区14 EraseSector(14,14); // 擦除扇区14 BlankCHK(14,14) ; // 查空扇区14 SelSector(14,14); // 选择扇区14 RamToFlash(USER_FLASH_ADDR,(uint32)flashdata, 512); }
///////////////////////////////////////////////////////////////////// // 函数名称:void File_Table_Write(BYTE page,BYTE *buf) // 函数功能: 配置表文件写 // 入口参数: // // // 出口参数:无 //////////////////////////////////////////////////////////////////// void File_Table_Write(uint16 page, BYTE *buf, uint8 *des_ip) { uint8 str[128], err, *pw,i=0,n=1; uint32 resault, tmp, resault1; struct CLASS_INFO *pinfo; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; /* Prevent compiler warning */ #endif IP_printf("文件写:%d\n\n\n", page); //设备表擦除 if (page == 0) { // gDeviceTable.File.FileDebug=gDeviceTable.Debug; // gDeviceTable.Debug&=~DEV_DEBUG_MSG; OS_ENTER_CRITICAL(); InitIAP(); resault = SelSector(ARM_TABLE_SECTOR_START, ARM_TABLE_SECTOR_END); resault = EraseSector(ARM_TABLE_SECTOR_START, ARM_TABLE_SECTOR_END); resault = BlankCHK(ARM_TABLE_SECTOR_START, ARM_TABLE_SECTOR_END); OS_EXIT_CRITICAL(); IP_printf("配置表被擦除!"); if (resault != CMD_SUCCESS) { File_Req(0, 0xffff, des_ip); return; } } if (page < 256) { if ((page % 10) == 0) IP_printf("文件写:%d\n\n\n", page); InitIAP(); //p=(BYTE *)(buf+sizeof (struct BASE_MSG)+sizeof(struct SFILE_TRANSLATE_TYPE )); pw = (BYTE *)User_mem_allco(256); if (pw == NULL) { File_Req(0, page, des_ip); return; } memcpy(pw, buf, 256); if (page == 0) { pinfo = (struct CLASS_INFO *)pw; User_ID_Read(str, 1); memcpy((BYTE *)pinfo->class_ID, str, 8); //IP_printf_256(pw); } if (page == 0xfa) { err = 0; memset(str, 0, 128); while(AT24C16_Write(str, DEVICE_USE_STAT_TIME, 128) == FALSE) { if (err++ > 10 ) break; }; } if ((page > 2) && (page < 10)) //课程表 { err = 0; //while(AT24C16_Write(pw,CLASS_TABLE_ADDRESS+(page-3)*256,256)==FALSE) //{ if (err++>10) break; }; } else { tmp = ARM_TABLE_ADDRESS + page * 256; OS_ENTER_CRITICAL(); resault = SelSector(ARM_TABLE_SECTOR_START, ARM_TABLE_SECTOR_END); resault = RamToFlash(tmp, (uint32)pw, 256); OS_EXIT_CRITICAL(); } User_mem_free(pw); //申请下一包 if ((page + 1) < 256) { File_Req(0, page + 1, des_ip); } else { File_Req(0, 0xffff, des_ip); Device_Rec_Scan(); } } else { File_Req(0, 0xffff, des_ip); Device_Rec_Scan(); } }