void SaveTripDataToEeprom() { int TripDataPoint,TripBaseAddr; char str[30]; UNION32 u32data; I2CA_ReadData(ADDR_24LC32,EPROM_ADDR_TRIP_POINT,&TripDataPoint); if( TripDataPoint == 0x00FF) TripDataPoint = 1; else TripDataPoint ++; if( TripDataPoint > 10 ) TripDataPoint = 1; I2CA_WriteData(ADDR_24LC32, EPROM_ADDR_TRIP_POINT, TripDataPoint); TripBaseAddr = TRIP_BACKUP_ADDR + TripDataPoint * 100; EepromSaveFlag = 1; // Code u32data.dword = TripInfoNow.CODE; write_code_2_eeprom( TripBaseAddr+ 0, u32data); // Data u32data.dword = TripInfoNow.DATA; write_code_2_eeprom( TripBaseAddr+ 4, u32data); // Current u32data.dword = TripInfoNow.CURRENT; write_code_2_eeprom( TripBaseAddr+ 8, u32data); // HZ u32data.dword = TripInfoNow.HZ; write_code_2_eeprom( TripBaseAddr+ 12, u32data); // VDC u32data.dword = TripInfoNow.VDC; write_code_2_eeprom( TripBaseAddr+16, u32data); // Time strncpy(str,TripInfoNow.TIME,20); WriteTripString( TripBaseAddr+20,str); // Msg strncpy(str,TripInfoNow.MSG,20); WriteTripString( TripBaseAddr+40,str); EepromSaveFlag = 0; }
void ReadTripString(int StartAddr, char * str) { int i; int Addr; int iTemp; char StrBuf[30]; Addr = StartAddr; for(i=0;i<20;i++){ I2CA_ReadData(ADDR_24LC32,Addr+i,&iTemp); StrBuf[i] = (char)(iTemp); } StrBuf[20] =0; strncpy(str,StrBuf,20); }
void ClearTripDataToEeprom() { int TripBaseAddr = 0; int TripDataPoint; int TripPointCount; char str[30]; UNION32 u32data; EepromSaveFlag = 1; u32data.dword = 0.0; load_sci_tx_mail_box("WAIT FOR CLEAR DATA!"); for(TripPointCount = 1; TripPointCount <= 10; TripPointCount++) { I2CA_ReadData(ADDR_24LC32,EPROM_ADDR_TRIP_POINT,&TripDataPoint); if( TripDataPoint == 0x00FF) TripDataPoint = 1; else TripDataPoint ++; if( TripDataPoint > 10 ) TripDataPoint = 1; I2CA_WriteData(ADDR_24LC32, EPROM_ADDR_TRIP_POINT, TripDataPoint); TripBaseAddr = TRIP_BACKUP_ADDR + TripDataPoint * 100; write_code_2_eeprom( TripBaseAddr+ 0, u32data); write_code_2_eeprom( TripBaseAddr+ 4, u32data); write_code_2_eeprom( TripBaseAddr+ 8, u32data); write_code_2_eeprom( TripBaseAddr+ 12, u32data); write_code_2_eeprom( TripBaseAddr+16, u32data); strncpy(str,"2010:01:01 00:00:00",20); WriteTripString( TripBaseAddr+20,str); strncpy(str," NO TRIP DATA ",20); WriteTripString( TripBaseAddr+40,str); } EepromSaveFlag = 0; load_sci_tx_mail_box("CLEAR COMPLETE !! "); }
void GetTripInfo(int Point,TRIP_INFO * TripData ) { int TripDataPoint; int TripBaseAddr; int iTemp; char str[30]={0}; UNION32 u32data; strncpy(TripData->MSG ,NULL,41); strncpy(TripData->TIME ,NULL,31); if( Point == 0){ // * TripData = &TripInfoNow; TripData->CURRENT = TripInfoNow.CURRENT; TripData->DATA = TripInfoNow.DATA; TripData->HZ = TripInfoNow.HZ; TripData->CODE = TripInfoNow.CODE; TripData->VDC = TripInfoNow.VDC; strncpy(TripData->MSG ,TripInfoNow.MSG,20); strncpy(TripData->TIME ,TripInfoNow.TIME,20); return ; } I2CA_ReadData(ADDR_24LC32,EPROM_ADDR_TRIP_POINT,&TripDataPoint); // erased if( ( 1 > Point ) || ( Point > 10) || (TripDataPoint == 0x00ff)) { TripData->CURRENT = 0.0; TripData->DATA = 0.0; TripData->HZ = 0.0; TripData->CODE = 0.0; TripData->VDC = 0.0; if( TripDataPoint == 0x00ff){ strncpy(TripData->MSG ," NO TRIP DATA ",20); strncpy(TripData->TIME ,"2008:07:24 00:57:00",20); } else { strncpy(TripData->MSG ," Invalid Trip Code ",20); strncpy(TripData->TIME ,"2008:07:24 00:57:00",20); } return ; } if( (TripDataPoint<1)||(TripDataPoint>10)){ I2CA_WriteData(ADDR_24LC32, EPROM_ADDR_TRIP_POINT,1); TripDataPoint = 1; } EepromSaveFlag = 1; // 저장된 립 데이터를 구한다. iTemp = TripDataPoint - Point + 1; // iPoint = 1~10; if( iTemp <= 0 ) iTemp += 10; TripBaseAddr = TRIP_BACKUP_ADDR + iTemp * 100; // Code read_eprom_data( TripBaseAddr+ 0, & u32data); TripData->CODE = u32data.dword; // Data read_eprom_data( TripBaseAddr+ 4, & u32data); TripData->CURRENT = u32data.dword; // Current read_eprom_data( TripBaseAddr+ 8, & u32data); TripData->CURRENT = u32data.dword; // HZ read_eprom_data( TripBaseAddr+ 12, & u32data); TripData->HZ = u32data.dword; // VDC read_eprom_data( TripBaseAddr+16, & u32data); TripData->VDC = u32data.dword; // Time ReadTripString( TripBaseAddr+20,str); strncpy(TripData->TIME,str,20); ReadTripString( TripBaseAddr+40,str); strncpy(TripData->MSG,str,20); EepromSaveFlag = 0; }
// // Main // void main(void) { Uint16 Error; Uint16 i; CurrentMsgPtr = &I2cMsgOut1; // // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the F2837xS_SysCtrl.c file. // InitSysCtrl(); // // Step 2. Initialize GPIO: // This example function is found in the F2837xS_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // // For this example, only init the pins for the SCI-A port. // These functions are found in the F2837xS_Gpio.c file. // GPIO_SetupPinMux(32, GPIO_MUX_CPU1, 1); GPIO_SetupPinMux(33, GPIO_MUX_CPU1, 1); // // Step 3. Clear all __interrupts and initialize PIE vector table: // Disable CPU __interrupts // DINT; // // Initialize PIE control registers to their default state. // The default state is all PIE __interrupts disabled and flags // are cleared. // This function is found in the F2837xS_PieCtrl.c file. // InitPieCtrl(); // // Disable CPU __interrupts and clear all CPU __interrupt flags: // IER = 0x0000; IFR = 0x0000; // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the __interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in F2837xS_DefaultIsr.c. // This function is found in F2837xS_PieVect.c. // InitPieVectTable(); // // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. // EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.I2CA_INT = &i2c_int1a_isr; EDIS; // This is needed to disable write to EALLOW protected registers // // Step 4. Initialize the Device Peripherals: // I2CA_Init(); // // Step 5. User specific code // // // Clear Counters // PassCount = 0; FailCount = 0; // // Clear incoming message buffer // for (i = 0; i < I2C_MAX_BUFFER_SIZE; i++) { I2cMsgIn1.MsgBuffer[i] = 0x0000; } // // Enable __interrupts required for this example // // // Enable I2C __interrupt 1 in the PIE: Group 8 __interrupt 1 // PieCtrlRegs.PIEIER8.bit.INTx1 = 1; // // Enable CPU INT8 which is connected to PIE group 8 // IER |= M_INT8; EINT; for(;;) { // // Write data to EEPROM section // // // Check the outgoing message to see if it should be sent. // In this example it is initialized to send with a stop bit. // if(I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP) { Error = I2CA_WriteData(&I2cMsgOut1); // // If communication is correctly initiated, set msg status to busy // and update CurrentMsgPtr for the __interrupt service routine. // Otherwise, do nothing and try again next loop. Once message is // initiated, the I2C __interrupts will handle the rest. Search for // ICINTR1A_ISR in the i2c_eeprom_isr.c file. // if (Error == I2C_SUCCESS) { CurrentMsgPtr = &I2cMsgOut1; I2cMsgOut1.MsgStatus = I2C_MSGSTAT_WRITE_BUSY; } } // // Read data from EEPROM section // // // Check outgoing message status. Bypass read section if status is // not inactive. // if (I2cMsgOut1.MsgStatus == I2C_MSGSTAT_INACTIVE) { // // Check incoming message status. // if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_SEND_NOSTOP) { // // EEPROM address setup portion // while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS) { // // Maybe setup an attempt counter to break an infinite while // loop. The EEPROM will send back a NACK while it is performing // a write operation. Even though the write communique is // complete at this point, the EEPROM could still be busy // programming the data. Therefore, multiple attempts are // necessary. // } // // Update current message pointer and message status // CurrentMsgPtr = &I2cMsgIn1; I2cMsgIn1.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY; } // // Once message has progressed past setting up the internal address // of the EEPROM, send a restart to read the data bytes from the // EEPROM. Complete the communique with a stop bit. MsgStatus is // updated in the __interrupt service routine. // else if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_RESTART) { // // Read data portion // while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS) { // // Maybe setup an attempt counter to break an infinite while // loop. // } // // Update current message pointer and message status // CurrentMsgPtr = &I2cMsgIn1; I2cMsgIn1.MsgStatus = I2C_MSGSTAT_READ_BUSY; } } } }