/** * @brief UpiWriteSuspendResumeData * * Write suspend / resume data to file * * @para data address of BackupDataType * @return NULL */ void UpiWriteSuspendResumeData(BackupDataType *data) { _backup_bool_ rtn; _backup_u8_ *buf; _backup_u32_ size; _backup_u32_ cmpResult; size = sizeof(BackupSuspendDataType)*BACKUP_MAX_LOG_SUSPEND_DATA; #ifndef UG31XX_SHELL_ALGORITHM buf = (_backup_u8_ *)&UpiWriteSuspendResumeData_buf[0]; #else ///< else of UG31XX_SHELL_ALGORITHM buf = (_backup_u8_ *)upi_malloc(size); #endif ///< end of UG31XX_SHELL_ALGORITHM #if defined (uG31xx_OS_WINDOWS) rtn = read_backup_file(data->suspendFileName, (_upi_u8_ *)buf, size); #else ///< else of defined (uG31xx_OS_WINDOWS) rtn = read_backup_file(ptrSuspendFileName, (_upi_u8_ *)buf, size); #endif ///< end of defined (uG31xx_OS_WINDOWS) UG31_LOGN("[%s]: Read suspend / resume data from file -> %d\n", __func__, rtn); if(rtn != _UPI_TRUE_) { #if defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(data->suspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #else ///< else of defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(ptrSuspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #endif ///< end of defined (uG31xx_OS_WINDOWS) UG31_LOGN("[%s]: Write suspend / resume data to file -> %d\n", __func__, rtn); #ifdef UG31XX_SHELL_ALGORITHM upi_free(buf); #endif ///< end of UG31XX_SHELL_ALGORITHM return; } cmpResult = upi_memcmp(buf, (_backup_u8_ *)(&data->backupSuspendData[0]), size); UG31_LOGN("[%s]: Compare suspend / resume data with file -> %d\n", __func__, (int)cmpResult); if(cmpResult != 0) { #if defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(data->suspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #else ///< else of defined (uG31xx_OS_WINDOWS) rtn = write_backup_file(ptrSuspendFileName, (_upi_u8_ *)(&data->backupSuspendData[0]), size); #endif ///< end of defined (uG31xx_OS_WINDOWS) UG31_LOGN("[%s]: Write suspend / resume data to file -> %d\n", __func__, rtn); } #ifdef UG31XX_SHELL_ALGORITHM upi_free(buf); #endif ///< end of UG31XX_SHELL_ALGORITHM }
/** * @brief CheckBackupFile * * Check backup file is consisted with IC or not * * @para data address of BackupDataType * @return CHECK_BACKUP_FILE_STS */ _backup_u8_ CheckBackupFile(BackupDataType *data) { CapacityDataType *orgCapData; SystemDataType *orgSysData; _upi_bool_ rtn; _backup_u32_ driverVer; _backup_u8_ rtnU8; _backup_u16_ volt1; _backup_u16_ volt2; /// [AT-PM] : Create buffer ; 02/21/2013 #ifndef UG31XX_SHELL_ALGORITHM orgCapData = &CheckBackupFile_orgCapData; orgSysData = &CheckBackupFile_orgSysData; #else ///< else of UG31XX_SHELL_ALGORITHM orgCapData = (CapacityDataType *)upi_malloc(sizeof(CapacityDataType)); orgSysData = (SystemDataType *)upi_malloc(sizeof(SystemDataType)); #endif ///< end of UG31XX_SHELL_ALGORITHM upi_memcpy(orgCapData, data->capData, sizeof(CapacityDataType)); upi_memcpy(orgSysData, data->sysData, sizeof(SystemDataType)); volt1 = data->backupVolt1; volt2 = data->backupVolt2; /// [AT-PM] : Get data from file ; 02/21/2013 rtn = read_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize); if(rtn == _UPI_FALSE_) { UG31_LOGD("[%s]: Read data from backup file fail.\n", __func__); #ifdef UG31XX_SHELL_ALGORITHM upi_free(orgCapData); upi_free(orgSysData); #endif ///< end of UG31XX_SHELL_ALGORITHM return (CHECK_BACKUP_FILE_STS_READ_FAIL); } driverVer = ConvertData(data); /// [AT-PM] : Following information is not checked ; 02/21/2013 data->sysData->rmFromIC = orgSysData->rmFromIC; data->sysData->timeTagFromIC = orgSysData->timeTagFromIC; data->sysData->deltaCapFromIC = orgSysData->deltaCapFromIC; data->sysData->adc1ConvTime = orgSysData->adc1ConvTime; data->capData->preDsgCharge = orgCapData->preDsgCharge; /// [AT-PM] : Check data ; 02/21/2013 if(driverVer != UG31XX_DRIVER_VERSION) { UG31_LOGN("[%s]: Backup file version mismatched.\n", __func__); rtnU8 = CHECK_BACKUP_FILE_STS_VERSION_MISMATCH; } else if((upi_memcmp(data->backupCustomerSelfDef, data->sysData->ggbParameter->customerSelfDef, CELL_PARAMETER_STRING_LENGTH) != 0) || (upi_memcmp(data->backupProjectSelfDef, data->sysData->ggbParameter->projectSelfDef, CELL_PARAMETER_STRING_LENGTH) != 0)) { UG31_LOGN("[%s]: Backup file cell information mismatched.\n", __func__); rtnU8 = CHECK_BACKUP_FILE_STS_VERSION_MISMATCH; } else if((upi_memcmp(orgCapData, data->capData, sizeof(CapacityDataType)) != 0) || (upi_memcmp(orgSysData, data->sysData, sizeof(SystemDataType)) != 0) || (volt1 != data->backupVolt1) || (volt2 != data->backupVolt2)) { UG31_LOGN("[%s]: Backup file needs to be updated\n", __func__); rtnU8 = CHECK_BACKUP_FILE_STS_NEED_UPDATE; } else { rtnU8 = CHECK_BACKUP_FILE_STS_PASS; } #ifdef UG31XX_SHELL_ALGORITHM upi_free(orgCapData); upi_free(orgSysData); #endif ///< end of UG31XX_SHELL_ALGORITHM return (rtnU8); }