int init_eprom_data() { UNION32 data,data2; int check; int address,cmd,loop_ctrl; int return_value; data.dword = 0.0; cmd = CMD_READ_DATA; address = return_value = 0; loop_ctrl = 1; while(loop_ctrl) { cmd = CMD_READ_DATA; check = get_code_information( address, cmd , & code_inform); if( check==0 ){ if( code_inform.type == TYPE_DOUBLE){ data.dword = code_inform.code_default.doubles; } else{ data.word.word0 = code_inform.code_default.ints; } read_eprom_data(address, & data2 ); if( data.dword != data2.dword) write_code_2_eeprom( address,data); read_eprom_data(address, & data2 ); if( data.dword != data2.dword) { loop_ctrl = 0; return_value = -1; load_sci_tx_mail_box("Trip : eeprom write" ); delay_msecs(100); break; } code_inform.code_value.doubles = data.dword; cmd = CMD_WRITE_RAM; check = get_code_information( address,cmd, & code_inform); address ++; } else if( check == -2) address = (address/100)*100 + 100; else address ++; if( address >= CODE_GROUP7_END ) { EepromSaveFlag = 0; return 0; } } EepromSaveFlag = 0; return return_value; }
void save_backup_data() { UNION32 data; int i,j,check; int address,cmd; data.dword = 0.0; address = 0; // start of address cmd = CMD_READ_DATA; address = 0; for( i = 0 ; i <= 7 ; i++){ // code group 이 6개 for( j = 0; j <= 29 ;j++) { address = i* 100 +j ; check = get_code_information( address, cmd , & code_inform); if( !check ){ read_eprom_data( address, & data); Flag_TripDataBackup = 1; write_code_2_eeprom( address,data); Flag_TripDataBackup = 0; } } } }
double CheckSum_bk() { UNION32 data; UNION32 data2; int i,j,check; int address,cmd; data.dword = 0.0; data2.dword = 0.0; address = 0; // start of address cmd = CMD_READ_DATA; for( i = 0 ; i <= 7 ; i++){ for( j = 0; j <= 29 ;j++) { address = i* 100 +j ; check = get_code_information( address, cmd , & code_inform); if( !check ){ read_eprom_data( address, & data); data2.dword = data2.dword + data.dword; } } } return data2.dword; }
void backup_data_load() { UNION32 data; int i,j,check; int loop_control,address,cmd; data.dword = 0.0; address = 0; // start of address cmd = CMD_READ_DATA; address = 0; loop_control = 1; while( loop_control ) { for( i = 0 ; i <= 7 ; i++){ // code group 이 6개 for( j = 0; j <= 29 ;j++) { address = i * 100 + j ; check = get_code_information( address, cmd , & code_inform); if( !check ){ Flag_TripDataBackup = 1; read_eprom_data( address, & data); Flag_TripDataBackup = 0; write_code_2_eeprom( address,data); if( code_inform.type == TYPE_DOUBLE) code_inform.code_value.doubles = data.dword; else code_inform.code_value.ints = data.word.word0; cmd = CMD_WRITE_RAM; check = get_code_information( address,cmd, & code_inform); } } } loop_control = 0; } }
// address 가 1000을 더한 영역에 저장한 데이터를 // 검사 하는 루틴 int check_backup_data() { UNION32 data; int i,j,check; int loop_control,address,cmd,return_value; data.dword = 0.0; address = return_value = 0; // start of address cmd = CMD_READ_DATA; address = 0; loop_control = 1; while( loop_control ) { for( i = 0 ; i <= 7 ; i++){ // code group 이 6개 for( j = 0; j <= 50 ;j++) { address = i * 100 + j ; check = get_code_information( address, cmd , & code_inform); if( !check ){ // debug address 의 뱅크를 설정하는 기능을 추가할 것 // 2009.08.30 Flag_TripDataBackup = 1; read_eprom_data( address, & data); Flag_TripDataBackup = 0; check = check_code_data(data, code_inform ); // check min and max boundary if(check){ loop_control = 0; return_value = -1; } } } } loop_control = 0; } return return_value; }
// read data format "X40001.234e-3" // write data format "X60001.234e-3" void scia_cmd_proc( int * sci_cmd, double * sci_ref) { double data; int addr,check; * sci_cmd = CMD_NULL; * sci_ref = 0.0; if( scia_rx_msg_flag == 0) return; scia_rx_msg_flag = 0; if ( scia_rx_msg_box[0] != 'X') return; addr = (scia_rx_msg_box[2]- '0')* 100 +(scia_rx_msg_box[2]- '0')*10 + (scia_rx_msg_box[2]- '0'); data = atof( & scia_rx_msg_box[4]); // regist write function decoding if( scia_rx_msg_box[1] == '6'){ if( addr == 900 ){ * sci_cmd = CMD_START; * sci_ref = data;} else if( addr == 901 ){ * sci_cmd = CMD_STOP; * sci_ref = 0.0;} else{ // registor_write_proc(addr,data); check = SaveDataProc(addr, data); } } else if(scia_rx_msg_box[1] == '4'){ check = get_code_information( addr, CMD_READ_DATA , & code_inform); if( check != 0 ){ if( code_inform.type == TYPE_DOUBLE ) data = code_inform.code_value.doubles; else data = (double)(code_inform.code_value.ints); snprintf( gStr1,20,"read data =10.3%e \n",data); load_scia_tx_mail_box(gStr1); } else{ load_scia_tx_mail_box("Error Invalid Address"); } } }
int EnterChangeDataState(int addr) { int temp,cmd; double temp_data; char str[20]; UNION32 u32data; cmd = CMD_READ_DATA; temp = get_code_information( addr,cmd, & code_inform); if(temp){ strncpy(MonitorMsg," !Invaild Funcion Code ",20); strncpy(str,"ER99",4); // MmiErrMsgBlinkStart(str); return -1; } digit_position = 0; if( addr < 800 ) read_eprom_data( addr, & u32data); else{ code_inform.type = TYPE_DOUBLE; u32data.dword = 0.0; } if(code_inform.type == TYPE_INTEGER) temp_data = (double)((int)(u32data.word.word0)); else temp_data = u32data.dword; snprintf(str,12,"%10.2e",temp_data); if( str[1] == '-') num_sign_flag = -1; else num_sign_flag = 1; if( str[7] == '-') exp_sign_flag = -1; else exp_sign_flag = 1; button_input_state = BUTTON_CHANGE_DATA; return 0; }
// read data format "9:4:123:x.xxxe-x" // write data format "9:6:123:1.234e-3" void scib_cmd_proc( int * sci_cmd, double * sci_ref) { double data,dbtemp; int addr,check,temp; char str[30]={0}; TRIP_INFO * TripData; * sci_cmd = CMD_NULL; * sci_ref = 0.0; if( scib_rx_msg_flag == 0) return; scib_rx_msg_flag = 0; if ( scib_rx_msg_box[0] != '9') return; addr = (scib_rx_msg_box[4]- '0')* 100 +(scib_rx_msg_box[5]- '0')*10 + (scib_rx_msg_box[6]- '0'); scib_rx_msg_box[16]=0; data = atof( & scib_rx_msg_box[8]); // regist write function decoding if( scib_rx_msg_box[2] == '6'){ if( addr == 900 ){ check = (int)data; if(check == 10){ * sci_cmd = CMD_START; * sci_ref = code_btn_start_ref; load_scib_tx_mail_box("UART CMD_START"); } else if( check == 20 ){ * sci_cmd = CMD_STOP; * sci_ref = 0.0; load_scib_tx_mail_box("UART CMD_STOP"); } else if( check == 30 ){ * sci_cmd = CMD_RESET; * sci_ref = 0.0; load_scib_tx_mail_box("UART CMD_RESET"); } else if( data == 40 ){ * sci_cmd = CMD_SAVE; * sci_ref = 0.0; load_scib_tx_mail_box("UART CMD_SAVE"); } else if( data == 80 ){ * sci_cmd = CMD_NULL; * sci_ref = 0.0; get_adc_offset(); } else if( data == 90 ){ * sci_cmd = CMD_NULL; * sci_ref = 0.0; load_scib_tx_mail_box("EEPROM init Start"); check = init_eprom_data(); // 0이 아니면 address value if( check != 0) load_scib_tx_mail_box("EEPROM init Fail"); else load_scib_tx_mail_box("EEPROM init Success"); } else{ load_scib_tx_mail_box("Illegal CMD data"); } } else{ // registor_write_proc(addr,data); check = SaveDataProc(addr, data); Nop(); } } //================== // read routine //==================== else if(scib_rx_msg_box[2] == '4'){ if(addr == 901){ // monitor state check = (int)data; if(check == 0){ switch(gMachineState){ case STATE_POWER_ON: load_scib_tx_mail_box("[POWE_ON] "); break; case STATE_READY: load_scib_tx_mail_box("[READY] "); break; case STATE_RUN: load_scib_tx_mail_box("[RUN ] "); break; case STATE_TRIP: load_scib_tx_mail_box("[TRIP] "); break; case STATE_INIT_RUN: load_scib_tx_mail_box("[INIT] "); break; case STATE_GO_STOP: load_scib_tx_mail_box("[GO_STOP] "); break; case STATE_WAIT_BREAK_OFF: load_scib_tx_mail_box("STATE_WAIT_BREAK_OFF"); break; default: load_scib_tx_mail_box("Unknown State"); break; } } return; } else if(addr == 902){ // 내부 변수 read check = (int)data; switch( check ){ case 0 : temp = (int)(floor(Freq_out +0.5)); snprintf( str,10,"Fq=%3d[hz]",temp); load_scib_tx_mail_box(str); break; case 1 : temp = (int)(floor(rpm +0.5)); snprintf( str,10,"RPM =%4d ",temp); load_scib_tx_mail_box(str); break; case 2 : temp = (int)(floor(Vdc +0.5)); snprintf( str,10," VDC =%4d",temp); load_scib_tx_mail_box(str); break; case 3 : temp = (int)(floor( RMS_Ia * 10 + 0.5 ) ); snprintf( str,10,"I1 =%2d.%d ",temp/10, temp%10); load_scib_tx_mail_box(str); break; case 4 : temp = (int)(floor( RMS_Ib * 10 + 0.5 ) ); snprintf( str,10,"I2 =%2d.%d ",temp/10, temp%10); load_scib_tx_mail_box(str); break; case 5 : // Reset; gMachineState = STATE_POWER_ON; Nop(); asm (" .ref _c_int00"); // ;Branch to start of boot.asm in RTS library asm (" LB _c_int00"); // ;Branch to start of boot.asm in RTS library break; default: break; } // check 에 따른 변수를 포인터로 두어서 처리 한다. // snprintf( str,30,"\n Vdc =%10.3e \n",Vdc); load_scib_tx_mail_box(str); return; } else if(addr == 903){ // 내부 변수 read // EEPROM TRIP DATA check = (int)data; if( data == 0 ){ snprintf( str,4,"%03d:",TripInfoNow.CODE); load_scib_tx_mail_box(str); delay_msecs(180); load_scib_tx_mail_box(TripInfoNow.MSG); delay_msecs(220); load_scib_tx_mail_box(TripInfoNow.TIME); delay_msecs(180); dbtemp = TripInfoNow.HZ; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10,"Fq=%3d[hz]",temp); load_scib_tx_mail_box(str); delay_msecs(180); dbtemp = TripInfoNow.VDC; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10," VDC =%4d",temp); load_scib_tx_mail_box(str); delay_msecs(180); dbtemp = TripInfoNow.CURRENT; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10,"I1 =%4d ",temp); load_scib_tx_mail_box(str); delay_msecs(180); dbtemp = TripInfoNow.DATA; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10," DATA=%4d",temp); load_scib_tx_mail_box(str); delay_msecs(180); } else{ TripData = (TRIP_INFO*)malloc(sizeof(TRIP_INFO)); GetTripInfo(check + 1,TripData); strncpy(gStr1,TripInfoNow.MSG,20); snprintf( str,4,"%03d:",TripData->CODE); load_scib_tx_mail_box(str); delay_msecs(180); load_scib_tx_mail_box(TripData->MSG); delay_msecs(220); load_scib_tx_mail_box(TripData->TIME); delay_msecs(180); dbtemp = TripData->HZ; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10,"Fq=%3d[hz]",temp); load_scib_tx_mail_box(str); delay_msecs(180); dbtemp = TripData->VDC; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10," VDC =%4d",temp); load_scib_tx_mail_box(str); delay_msecs(180); dbtemp = TripData->CURRENT; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10,"I1 =%4d ",temp); load_scib_tx_mail_box(str); delay_msecs(180); dbtemp = TripData->DATA; temp = (int)(floor(dbtemp +0.5)); snprintf( str,10," DATA=%4d",temp); load_scib_tx_mail_box(str); delay_msecs(180); free(TripData); } return; } else if(addr == 904){ // DATE & TIME SET check = (int)data; switch( check ){ case 0: TimeInput[0] = scib_rx_msg_box[10]; TimeInput[1] = scib_rx_msg_box[11]; TimeInput[2] = scib_rx_msg_box[12]; TimeInput[3] = scib_rx_msg_box[13]; TimeInput[4] = scib_rx_msg_box[14]; TimeInput[5] = scib_rx_msg_box[15]; break; case 1: TimeInput[6] = scib_rx_msg_box[10]; TimeInput[7] = scib_rx_msg_box[11]; TimeInput[8] = scib_rx_msg_box[12]; TimeInput[9] = scib_rx_msg_box[13]; TimeInput[10] = scib_rx_msg_box[14]; TimeInput[11] = scib_rx_msg_box[15]; delay_msecs(50); WriteTimeToDS1307(TimeInput); load_scib_tx_mail_box("Date & Time Saved"); break; case 2: // load_scib_tx_mail_box("WAIT FOR CLEAR DATA!"); // delay_msecs(180); ClearTripDataToEeprom(); break; } return; } else if(addr == 905){ // RUN & STOP check = (int)data; switch( check ){ case 0: * sci_cmd = CMD_START; * sci_ref = code_btn_start_ref; break; case 1: * sci_cmd = CMD_STOP; * sci_ref = 0.0; break; case 2: * sci_cmd = CMD_SPEED_UP; break; case 3: * sci_cmd = CMD_SPEED_DOWN; break; default: * sci_cmd = CMD_NULL; break; } return; } else if(addr == 906){ GetTimeAndDateStr(str); load_scib_tx_mail_box(str); return; } else if (( addr > 979) && ( addr < 996)){ check = addr - 980; snprintf( str,19,"adc =%4d",adc_result[check]); load_scib_tx_mail_box(str); delay_msecs(10); return; } check = get_code_information( addr, CMD_READ_DATA , & code_inform); if( check == 0 ){ check = (int)data; switch(check) { case 0: snprintf( str,19,"CODE=%4d",addr); load_scib_tx_mail_box(str); delay_msecs(10); break; case 1: load_scib_tx_mail_box(code_inform.disp);delay_msecs(10); break; case 2: if( code_inform.type == TYPE_DOUBLE ){ snprintf( str,20,"Data =%10.3e",code_inform.code_value.doubles); } else{ snprintf( str,20,"Data =%10d",code_inform.code_value.ints); } load_scib_tx_mail_box(str); delay_msecs(10); break; default: snprintf( str,19,"CODE=%4d",addr); load_scib_tx_mail_box(str);delay_msecs(10); load_scib_tx_mail_box(code_inform.disp);delay_msecs(10); if( code_inform.type == TYPE_DOUBLE ) snprintf( str,20,"Data =%10.3e",code_inform.code_value.doubles); else snprintf( str,20,"Data =%10d",code_inform.code_value.ints); load_scib_tx_mail_box(str); delay_msecs(10); break; } } else{ load_scib_tx_mail_box("Error Invalid Address");delay_msecs(10); } return; } }
int SaveDataProc(int addr, double data) { int cmd,i,return_value; char SciBuf[30]={0}; char str[30]; UNION32 u32data,u32data2; return_value = 0; cmd = CMD_READ_DATA; i = get_code_information( addr,cmd,&code_inform); if( i != 0 ) goto _SAVE_ERROR_INVALID_ADDR; if( addr >= 800 ){ if( data < 1.22 ) goto _SAVE_ERROR_INVALID_DATA; if( data > 1.24 ) goto _SAVE_ERROR_INVALID_DATA; switch(addr) { case CODE_Data_Check: return_value = check_backup_data(); break; case CODE_Data_Backup: strncpy(str,"Wait for Data Backup",20); load_sci_tx_mail_box(str); delay_msecs(20); save_backup_data(); strncpy(str,"Wait for Error Check",20); load_sci_tx_mail_box(str); delay_msecs(20); break; case CODE_Data_Load: strncpy(str,"Wait for Data Load !",20); load_sci_tx_mail_box(str); delay_msecs(20); backup_data_load(); break; case CODE_Data_Init: strncpy(str,"Wait For Data Init !",20); load_sci_tx_mail_box(str); delay_msecs(20); init_eprom_data(); strncpy(str,"Data Init OK ! ",20); load_sci_tx_mail_box(str); delay_msecs(20); break; case CODE_get_adc_offset: get_adc_offset(); break; default: goto _SAVE_ERROR_INVALID_ADDR; } return return_value; } if( code_inform.type == TYPE_INTEGER){ if( (code_inform.code_min.ints) > (int)data ){ goto _SAVE_ERROR_DATA_UNDER; } else if( (code_inform.code_max.ints) < (int)data){ goto _SAVE_ERROR_DATA_OVER; } else { // u32data.word.word1 = 0; u32data.word.word0 = (int)data; read_eprom_data( addr, & u32data2); if( u32data.word.word0 != u32data2.word.word0 ){ write_code_2_eeprom( addr, u32data); read_eprom_data( addr, & u32data2); if( u32data.word.word0 != u32data2.word.word0 ) goto _EEPROM_WRITE_ERROR; code_inform.code_value.ints = (int)data; cmd = CMD_WRITE_RAM; get_code_information( addr,cmd, & code_inform); load_sci_tx_mail_box("OK write success") ; } else{ load_sci_tx_mail_box("Equal Data write skipped"); } return 0; } } else { // code_inform->Type == TYPE_DOUBLE if( ( code_inform.code_min.doubles) > data ){ goto _SAVE_ERROR_DATA_UNDER; } else if( ( code_inform.code_max.doubles) < data ){ goto _SAVE_ERROR_DATA_OVER; } else { u32data.dword = data; read_eprom_data( addr, & u32data2); if( u32data.dword != u32data2.dword ){ write_code_2_eeprom( addr, u32data); read_eprom_data( addr, & u32data2); if( u32data.dword != u32data2.dword ) goto _EEPROM_WRITE_ERROR; code_inform.code_value.doubles = data; cmd = CMD_WRITE_RAM; get_code_information( addr,cmd, & code_inform); // CheckSum Save u32data.dword = CheckSum(); EepromSaveFlag = 1; write_code_2_eeprom(EPROM_ADDR_CHECKSUM, u32data); EepromSaveFlag = 0; load_sci_tx_mail_box("OK write success") ; } else{ load_sci_tx_mail_box("Equal Data write skipped"); } return 0; } } _SAVE_ERROR_INVALID_ADDR: // strcpy(SciBuf, "ADDR"); strcpy(SciBuf,"Invalid Address" ); load_sci_tx_mail_box(SciBuf) ; return -1; _SAVE_ERROR_DATA_UNDER: // strcpy(SciBuf, "UNDE"); strcpy(SciBuf,"Input data under" ); load_sci_tx_mail_box(SciBuf) ; return -1; _SAVE_ERROR_DATA_OVER: // strcpy(SciBuf, "OVER"); strcpy(SciBuf,"Input data over" ); load_sci_tx_mail_box(SciBuf) ; return -1; _SAVE_ERROR_INVALID_DATA: // strcpy(SciBuf, "DATA"); strcpy(SciBuf,"Invalid data " ); load_sci_tx_mail_box(SciBuf) ; return -1; _EEPROM_WRITE_ERROR: // strcpy(SciBuf, "DATA"); strcpy(SciBuf,"Eeprom write error" ); load_sci_tx_mail_box(SciBuf) ; return -1; }
// read data format "9:4:123:x.xxxe-x" // write data format "9:6:123:1.234e-3" void scia_cmd_proc( int * sci_cmd, double * sci_ref) { double data; int addr,check; char str[30]={0}; * sci_cmd = CMD_NULL; * sci_ref = 0.0; if( scia_rx_msg_flag == 0) return; scia_rx_msg_flag = 0; if ( scia_rx_msg_box[0] != '9') return; addr = (scia_rx_msg_box[4]- '0')* 100 +(scia_rx_msg_box[5]- '0')*10 + (scia_rx_msg_box[6]- '0'); scia_rx_msg_box[16]=0; data = atof( & scia_rx_msg_box[8]); // regist write function decoding if( scia_rx_msg_box[2] == '6'){ if( addr == 900 ){ check = (int)data; if(check == 10){ * sci_cmd = CMD_START; * sci_ref = data; load_scia_tx_mail_box("\n UART CMD_START"); } else if( check == 20 ){ * sci_cmd = CMD_STOP; * sci_ref = 0.0; load_scia_tx_mail_box("\n UART CMD_STOP"); } else if( check == 30 ){ * sci_cmd = CMD_RESET; * sci_ref = 0.0; load_scia_tx_mail_box("\n UART CMD_RESET"); } else if( data == 40 ){ * sci_cmd = CMD_SAVE; * sci_ref = 0.0; load_scia_tx_mail_box("\n UART CMD_SAVE"); } else if( data == 80 ){ * sci_cmd = CMD_NULL; * sci_ref = 0.0; get_adc_offset(); } else if( data == 90 ){ * sci_cmd = CMD_NULL; * sci_ref = 0.0; load_scia_tx_mail_box("\n EEPROM init Start"); check = init_eprom_data(); // 0이 아니면 address value if( check != 0) load_scia_tx_mail_box("\n EEPROM init Fail"); else load_scia_tx_mail_box("\n EEPROM init Success"); } else{ load_scia_tx_mail_box("\n Illegal CMD data"); } } else{ // registor_write_proc(addr,data); check = SaveDataProc(addr, data); Nop(); } } else if(scia_rx_msg_box[2] == '4'){ if(addr == 901){ // monitor state check = (int)data; if(check == 0){ switch(gMachineState){ case STATE_POWER_ON: load_scia_tx_mail_box("\n POWER_ON"); break; case STATE_READY: load_scia_tx_mail_box("\n STATE_READY"); break; case STATE_RUN: load_scia_tx_mail_box("\n STATE_RUN"); break; case STATE_TRIP: load_scia_tx_mail_box("\n STATE_TRIP"); break; case STATE_INIT_RUN: load_scia_tx_mail_box("\n STATE_INIT_RUN"); break; case STATE_GO_STOP: load_scia_tx_mail_box("\n STATE_GO_STOP"); break; case STATE_WAIT_BREAK_OFF: load_scia_tx_mail_box("\n STATE_WAIT_BREAK_OFF"); break; default: load_scia_tx_mail_box("\n Unknown State"); break; } } return; } else if(addr == 902){ // 내부 변수 read check = (int)data; // check 에 따른 변수를 포인터로 두어서 처리 한다. snprintf( str,30,"\n Vdc =%10.3e \n",Vdc); load_scia_tx_mail_box(str); return; } check = get_code_information( addr, CMD_READ_DATA , & code_inform); if( check == 0 ){ load_scia_tx_mail_box(code_inform.disp); if( code_inform.type == TYPE_DOUBLE ) snprintf( str,30," :: read data =%10.3e \n",code_inform.code_value.doubles); else snprintf( str,30," :: read data =%10d \n",code_inform.code_value.ints); load_scia_tx_mail_box(str); } else{ load_scia_tx_mail_box("Error Invalid Address"); } } }
int SaveDataProc(int addr, double data) { int cmd,i,return_value; char SciBuf[30]={0}; UNION32 u32data,u32data2; return_value = 0; cmd = CMD_READ_DATA; i = get_code_information( addr,cmd,&code_inform); if( i != 0 ) goto _SAVE_ERROR_INVALID_ADDR; if( addr >= 800 ){ if( data < 1.22 ) goto _SAVE_ERROR_INVALID_DATA; if( data > 1.24 ) goto _SAVE_ERROR_INVALID_DATA; switch(addr) { case CODE_Data_Check: return_value = check_backup_data(); break; case CODE_Data_Backup: save_backup_data(); break; case CODE_Data_Load: backup_data_load(); break; case CODE_Data_Init: init_eprom_data(); break; case CODE_get_adc_offset: get_adc_offset(); break; case CODE_get_adc_vdc_100: get_adc_vdc_100(); break; case CODE_get_adc_vdc_300: get_adc_vdc_300(); break; default: goto _SAVE_ERROR_INVALID_ADDR; } return return_value; } if( code_inform.type == TYPE_INTEGER){ if( (code_inform.code_min.ints) > (int)data ){ goto _SAVE_ERROR_DATA_UNDER; } else if( (code_inform.code_max.ints) < (int)data){ goto _SAVE_ERROR_DATA_OVER; } else { // u32data.word.word1 = 0; u32data.word.word0 = (int)data; read_eprom_data( addr, & u32data2); if( u32data.word.word0 != u32data2.word.word0 ){ write_code_2_eeprom( addr, u32data); read_eprom_data( addr, & u32data2); if( u32data.word.word0 != u32data2.word.word0 ) goto _EEPROM_WRITE_ERROR; code_inform.code_value.ints = (int)data; cmd = CMD_WRITE_RAM; get_code_information( addr,cmd, & code_inform); load_sci_tx_mail_box("\n OK write success") ; } else{ load_sci_tx_mail_box("\n Equal Data write skipped"); } return 0; } } else { // code_inform->Type == TYPE_DOUBLE if( ( code_inform.code_min.doubles) > data ){ goto _SAVE_ERROR_DATA_UNDER; } else if( ( code_inform.code_max.doubles) < data ){ goto _SAVE_ERROR_DATA_OVER; } else { u32data.dword = data; read_eprom_data( addr, & u32data2); if( u32data.dword != u32data2.dword ){ write_code_2_eeprom( addr, u32data); read_eprom_data( addr, & u32data2); if( u32data.dword != u32data2.dword ) goto _EEPROM_WRITE_ERROR; code_inform.code_value.doubles = data; cmd = CMD_WRITE_RAM; get_code_information( addr,cmd, & code_inform); load_sci_tx_mail_box("\n OK write success") ; } else{ load_sci_tx_mail_box("\n Equal Data write skipped"); } return 0; } } _SAVE_ERROR_INVALID_ADDR: // strcpy(SciBuf, "ADDR"); // MmiErrMsgBlinkStart(SciBuf); strcpy(SciBuf,"\n Invalid Address" ); load_sci_tx_mail_box(SciBuf) ; return -1; _SAVE_ERROR_DATA_UNDER: // strcpy(SciBuf, "UNDE"); // MmiErrMsgBlinkStart(SciBuf); strcpy(SciBuf,"\n Input data under" ); load_sci_tx_mail_box(SciBuf) ; return -1; _SAVE_ERROR_DATA_OVER: // strcpy(SciBuf, "OVER"); // MmiErrMsgBlinkStart(SciBuf); strcpy(SciBuf,"\n Input data over" ); load_sci_tx_mail_box(SciBuf) ; return -1; _SAVE_ERROR_INVALID_DATA: // strcpy(SciBuf, "DATA"); // MmiErrMsgBlinkStart(SciBuf); strcpy(SciBuf,"\n Invalid data " ); load_sci_tx_mail_box(SciBuf) ; return -1; _EEPROM_WRITE_ERROR: // strcpy(SciBuf, "DATA"); // MmiErrMsgBlinkStart(SciBuf); strcpy(SciBuf,"\n Eeprom write error" ); load_sci_tx_mail_box(SciBuf) ; return -1; }