Ejemplo n.º 1
0
void Flash_Store_Code(void)
{
	U8_T i;
	U16_T temp = 0;
	U32_T base_addr = 0;
	U16_T loop;

	for(i = 0;i < MAX_PRGS;i++)
	{	
		if(mGetPointWord2(programs[i].bytes) > 0 && mGetPointWord2(programs[i].bytes) < CODE_ELEMENT)	
		{
//			IntFlashWriteByte(BASE_CODE_INDEX + i * 2,mGetPointWord2(programs[i].bytes));
//			IntFlashWriteByte(BASE_CODE_INDEX + i * 2 + 1,(mGetPointWord2(programs[i].bytes) >> 8));
			IntFlashWriteInt(BASE_CODE_INDEX + i * 2,mGetPointWord2(programs[i].bytes));
			IntFlashReadInt(BASE_CODE_INDEX + i * 2, &temp);
			Test[40 + i] = mGetPointWord2(programs[i].bytes);
			Test[30 + i] = temp;
			for(loop = 0;loop < mGetPointWord2(programs[i].bytes) + USER_DATA_HEADER_LEN;loop++)
			{
				IntFlashWriteByte(BASE_CODE + base_addr + loop,prg_code[i][loop]);
			}
			base_addr += (mGetPointWord2(programs[i].bytes) + USER_DATA_HEADER_LEN);
		}
		else
		{
			temp = 0;
//			IntFlashWriteByte(BASE_CODE_INDEX + i * 2,0);
//			IntFlashWriteByte(BASE_CODE_INDEX + i * 2 + 1,0);
			IntFlashWriteInt(BASE_CODE_INDEX + i * 2,temp);	
		}
	}
	IntFlashWriteInt(BASE_CODE_LEN,Code_total_length);
}
Ejemplo n.º 2
0
void Flash_Write_Mass(void)
{									 
	STR_flag_flash ptr_flash;
	U16_T base_addr;
	U8_T loop;
	U16_T loop1,loop2;
//	U16_T i;
 /* only the first block, erase memory */
	IntFlashErase(ERA_RUN,0x70000);	
	IntFlashWriteByte(0x70000 + 0xfff0,0x55);
	// MassFlashWrite(0,Para,400); //LHN add

	ptr_flash.index = 0;

	for(loop = 0;loop < T_END ;loop++)
	{
		ptr_flash.table = loop;	
		
		ptr_flash.len = Flash_Position[loop].len;
		base_addr = Flash_Position[loop].addr;
		switch(loop)
		{			
			case T_WEEK_DES:
				for(loop1 = 0;loop1 < MAX_WR1;loop1++)
				{
					memcpy(&tempbuf[WR_DESCRIPTION_SIZE * loop1],WR_Roution[loop1].UN.all,WR_DESCRIPTION_SIZE);					
				}
				for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
				break;
			case T_WEEK_ONTIME:
				for(loop1 = 0;loop1 < MAX_WR1;loop1++)
				{
					memcpy(&tempbuf[WR_TIME_SIZE * loop1],WR_Roution[loop1].OnTime,WR_TIME_SIZE);					
				}
				for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);
				break;
			case T_WEEK_OFFTIME:
				for(loop1 = 0;loop1 < MAX_WR1;loop1++)
				{
					memcpy(&tempbuf[WR_TIME_SIZE * loop1],WR_Roution[loop1].OffTime,WR_TIME_SIZE);					
				}
				for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);		
				break;
			case T_ANNUAL_DES:
				for(loop1 = 0;loop1 < MAX_AR1;loop1++)
				{
					memcpy(&tempbuf[AR_DESCRIPTION_SIZE * loop1],AR_Roution[loop1].UN.all,AR_DESCRIPTION_SIZE);					
				}
				for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);		
				break;
			case T_ANNUAL_TIME:
				for(loop1 = 0;loop1 < MAX_AR1;loop1++)
				{
					memcpy(&tempbuf[AR_TIME_SIZE * loop1],AR_Roution[loop1].Time,AR_TIME_SIZE);					
				}
				for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);		
				break;

			case T_ID:
				for(loop1 = 0;loop1 < MAX_ID;loop1++)
				{
					memcpy(&tempbuf[ID_SIZE * loop1],ID_Config[loop1].all,ID_SIZE);					
				}
				for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);		
				break;
					 
			case T_NAME:
				for(loop1 = 0;loop1 < MAX_NAME;loop1++)
				{
					memcpy(&tempbuf[NAME_SIZE * loop1],menu_name[loop1],NAME_SIZE);					
				}
				for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);		
				break;
			default:	
				break;
		
		}
	}

}
Ejemplo n.º 3
0
void Flash_Write_Mass(void)
{
	STR_flag_flash ptr_flash;
	U16_T base_addr;
	U8_T loop;
	U16_T loop1,loop2;

 /* only the first block, erase memory */
	IntFlashErase(ERA_RUN,0x70000);	
//	IntFlashWriteByte(0x70000 + 0xfff0,0x55);
	// MassFlashWrite(0,Para,400); //LHN add
	ptr_flash.index = 0;

	for(loop = 0;loop < MAX_POINT_TYPE ;loop++)
	{
		ptr_flash.table = loop;	
		
		ptr_flash.len = Flash_Position[loop].len;
		base_addr = Flash_Position[loop].addr;

		switch(loop)
		{	
		case OUT: 
			for(loop1 = 0;loop1 < MAX_OUTS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_out_point) * loop1],&outputs[loop1],sizeof(Str_out_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);
			
			break;
		case IN:
			for(loop1 = 0;loop1 < MAX_INS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_in_point) * loop1],&inputs[loop1],sizeof(Str_in_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);

			break;
		case VAR:  
			for(loop1 = 0;loop1 < MAX_VARS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_variable_point) * loop1],&vars[loop1],sizeof(Str_variable_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);							
			break;
	/*	case CON:
			for(loop1 = 0;loop1 < MAX_CONS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_controller_point) * loop1],&controllers[loop1],sizeof(Str_controller_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break;*/
		case WRT:  				
			for(loop1 = 0;loop1 < MAX_WR;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_weekly_routine_point) * loop1],&weekly_routines[loop1],sizeof(Str_weekly_routine_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
						
			break;
		case AR: 
			for(loop1 = 0;loop1 < MAX_AR;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_annual_routine_point) * loop1],&annual_routines[loop1],sizeof(Str_annual_routine_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
					
			break;
		case PRG:  
			for(loop1 = 0;loop1 < MAX_PRGS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_program_point) * loop1],&programs[loop1],sizeof(Str_program_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	 Test[7]++;
			break;
	/*	case TBL:
			for(loop1 = 0;loop1 < MAX_TBLS;loop1++)
			{
				memcpy(&tempbuf[sizeof(custom_tab) * 16 * loop1],&custom_tab[loop1],sizeof(custom_tab) * 16);					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break;
		case TZ:
			for(loop1 = 0;loop1 < MAX_TOTALIZERS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_totalizer_point) * loop1],&totalizers[loop1],sizeof(Str_totalizer_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break;	
		case AMON:
			for(loop1 = 0;loop1 < MAX_MONITORS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_monitor_point) * loop1],&monitors[loop1],sizeof(Str_monitor_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break;
		case GRP: 
			for(loop1 = 0;loop1 < MAX_GRPS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Control_group_point) * loop1],&control_groups[loop1],sizeof(Control_group_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break;
		case ARRAY:
			for(loop1 = 0;loop1 < MAX_ARRAYS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Str_array_point) * loop1],&arrays[loop1],sizeof(Str_array_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break; */
		case ALARMM: 
			for(loop1 = 0;loop1 < MAX_ALARMS;loop1++)
			{
				memcpy(&tempbuf[sizeof(Alarm_point) * loop1],&alarms[loop1],sizeof(Alarm_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break; 			
		case ALARM_SET:  
			for(loop1 = 0;loop1 < MAX_ALARMS_SET;loop1++)
			{
				memcpy(&tempbuf[sizeof(Alarm_set_point) * loop1],&alarms_set[loop1],sizeof(Alarm_set_point));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break; 

	/*	case UNIT:
			for(loop1 = 0;loop1 < MAX_UNIT;loop1++)
			{
				memcpy(&tempbuf[sizeof(Units_element) * loop1],&units[loop1],sizeof(Units_element));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break; 
		case USER_NAME:
			memcpy(tempbuf,passwords,sizeof(Password_struct));					
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);						
			break;		*/
		case WR_TIME: 	
			for(loop1 = 0;loop1 < MAX_WR;loop1++)
			{
				memcpy(&tempbuf[sizeof(Wr_one_day) * 9 * loop1],&wr_times[loop1],sizeof(Wr_one_day) * 9);					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break;
		case AR_DATA:  
			for(loop1 = 0;loop1 < MAX_AR;loop1++)
			{
				memcpy(&tempbuf[46 * sizeof(S8_T) * loop1],&ar_dates[loop1],46 * sizeof(S8_T));					
			}
			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
			break; 			
//	   	case TSTAT:
//			for(loop1 = 0;loop1 < SUB_NO;loop1++)
//			{
//				memcpy(&tempbuf[sizeof(TST_INFO) * loop1],&tst_info[loop1],sizeof(TST_INFO));					
//			}
//			for(loop2 = 0;loop2 < ptr_flash.len;loop2++)
//				IntFlashWriteByte(0x70000 + base_addr + loop2,tempbuf[loop2]);	
		default:	
			break;
	
		} 			
	}
	Flash_Store_Code();

   	IntFlashWriteByte(0x7fff0,0x55); 
}
void Flash_Write_Schedule(void)
{
	STR_flag_flash ptr_flash;
	U16_T base_addr;
	U8_T loop;
	U16_T loop1, loop2;

 /* only the first block, erase memory */
	IntFlashErase(ERA_RUN, 0x70000);	
	IntFlashWriteByte(0x70000 + 0xfff0, 0x55);
	MassFlashWrite(0, Para, 400); //LHN add

	ptr_flash.index = 0;

	for(loop = 0; loop < T_TOTAL; loop++)
	{
		ptr_flash.table = loop;	
		
		ptr_flash.len = Flash_Position[loop].len;
		base_addr = Flash_Position[loop].addr;
		
		switch(loop)
		{			
			case T_WEEK_DES:
				for(loop1 = 0; loop1 < MAX_WR; loop1++)
				{
					memcpy(&tempbuf[WR_DESCRIPTION_SIZE * loop1], WR_Roution[loop1].UN.all, WR_DESCRIPTION_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);	
				break;
			case T_WEEK_ONTIME:
				for(loop1 = 0; loop1 < MAX_WR; loop1++)
				{
					memcpy(&tempbuf[WR_TIME_SIZE * loop1], WR_Roution[loop1].OnTime, WR_TIME_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);
				break;
			case T_WEEK_OFFTIME:
				for(loop1 = 0;loop1 < MAX_WR;loop1++)
				{
					memcpy(&tempbuf[WR_TIME_SIZE * loop1], WR_Roution[loop1].OffTime, WR_TIME_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);		
				break;
			case T_ANNUAL_DES:
				for(loop1 = 0; loop1 < MAX_AR; loop1++)
				{
					memcpy(&tempbuf[AR_DESCRIPTION_SIZE * loop1], AR_Roution[loop1].UN.all, AR_DESCRIPTION_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);		
				break;
			case T_ANNUAL_TIME:
				for(loop1 = 0; loop1 < MAX_AR; loop1++)
				{
					memcpy(&tempbuf[AR_TIME_SIZE * loop1], AR_Roution[loop1].Time, AR_TIME_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);		
				break;
			case T_ID:
				for(loop1 = 0; loop1 < MAX_ID; loop1++)
				{
					memcpy(&tempbuf[ID_SIZE * loop1], ID_Config[loop1].all, ID_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);		
				break;
			case T_SCAN:
				for(loop1 = 0; loop1 < MAX_ID; loop1++)
				{
					memcpy(&tempbuf[SCAN_DB_SIZE * loop1], (U8_T *)&scan_db[loop1], SCAN_DB_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);
				break;
		
/*******************************************************************************************/
			case T_BACNET:
				for(loop1 = 0; loop1 < MAX_BACNET; loop1++)
				{
					memcpy(&tempbuf[BACNET_SIZE * loop1], (U8_T *)&bacnet_id, BACNET_SIZE);					
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);
				break;
/*=========================================================================================*/
			case T_GSM:
				for(loop1 = 0; loop1 < PHONE_NUM_SIZE; loop1++)
				{
					memcpy(&tempbuf[loop1], &phoneNumber[loop1], 1);
				}
				for(loop2 = 0; loop2 < ptr_flash.len; loop2++)
					IntFlashWriteByte(0x70000 + base_addr + loop2, tempbuf[loop2]);
				break;


			default:	
				break;
		
		}
	}

}