|
@@ -414,7 +414,6 @@ void appLoadConfig(void)
|
|
|
UINT32 readCount = 0;
|
|
|
//AppConfigHeader AppConfigHr; //4 bytes
|
|
|
UINT8 crcCheck = 0;
|
|
|
- BOOL needAdjust = FALSE;
|
|
|
void *pReadAppConfig = (void *)&AppNVMData;
|
|
|
/*
|
|
|
* open the NVM file
|
|
@@ -434,23 +433,25 @@ void appLoadConfig(void)
|
|
|
* read the file header
|
|
|
*/
|
|
|
readCount = OsaFread(&AppConfigHr, sizeof(AppConfigHeader), 1, fp);
|
|
|
-
|
|
|
- if (readCount != 1)
|
|
|
+ UINT8 readtimes=0;
|
|
|
+ while (readCount != 1 && readtimes<=5 )
|
|
|
{
|
|
|
//ECOMM_TRACE(UNILOG_PLA_MIDWARE, AppLoadNvmConfig_header_e_1, P_ERROR, 1,
|
|
|
// "NVM: 'qxappconfig.nvm', can't read header, return: %d, use the defult value", readCount);
|
|
|
-
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("NVM: 'qxappconfig.nvm', can't read header, return: %d, use the defult value \n");
|
|
|
- #endif
|
|
|
-
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("NVM: 'qxappconfig.nvm', can't read header, return: %d, use the defult value \n");
|
|
|
+ #endif
|
|
|
+ readtimes++;
|
|
|
+ readCount = OsaFread(&AppConfigHr, sizeof(AppConfigHeader), 1, fp);
|
|
|
+ osDelay(10);
|
|
|
+ }
|
|
|
+ if(readtimes>5)
|
|
|
+ {
|
|
|
OsaFclose(fp);
|
|
|
setDefaultAppDataValue();
|
|
|
appSaveConfig();
|
|
|
-
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
if (AppConfigHr.version != APP_CONFIG_FILE_LATEST_VERSION)
|
|
|
{
|
|
|
//ECOMM_TRACE(UNILOG_PLA_MIDWARE, AppLoadNvmConfig_ver_w_1, P_ERROR, 2,
|
|
@@ -473,7 +474,6 @@ void appLoadConfig(void)
|
|
|
OsaFclose(fp);
|
|
|
setDefaultAppDataValue();
|
|
|
appSaveConfig();
|
|
|
-
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -497,7 +497,7 @@ void appLoadConfig(void)
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
- needAdjust = TRUE;
|
|
|
+ //needAdjust = TRUE;
|
|
|
}
|
|
|
else if (AppConfigHr.fileBodySize != sizeof(AppNVMData)) //file version is the same, but NVM file size not right
|
|
|
{
|
|
@@ -522,10 +522,16 @@ void appLoadConfig(void)
|
|
|
*/
|
|
|
|
|
|
readCount = OsaFread(pReadAppConfig, AppConfigHr.fileBodySize, 1, fp);
|
|
|
- crcCheck = OsaCalcCrcValue((UINT8 *)pReadAppConfig, AppConfigHr.fileBodySize);
|
|
|
-
|
|
|
- if (readCount != 1 ||
|
|
|
- crcCheck != AppConfigHr.checkSum)
|
|
|
+ crcCheck = OsaCalcCrcValue((UINT8 *)pReadAppConfig, sizeof(AppNVMData));
|
|
|
+ readtimes = 0;
|
|
|
+ //while (readtimes<=5 && crcCheck != AppConfigHr.checkSum)
|
|
|
+ while (readtimes<=5 && crcCheck != AppConfigHr.checkSum)
|
|
|
+ {
|
|
|
+ readtimes++;
|
|
|
+ readCount = OsaFread(pReadAppConfig, AppConfigHr.fileBodySize, 1, fp);
|
|
|
+ crcCheck = OsaCalcCrcValue((UINT8 *)pReadAppConfig, sizeof(AppNVMData));
|
|
|
+ }
|
|
|
+ if (readtimes>5)
|
|
|
{
|
|
|
//ECOMM_TRACE(UNILOG_PLA_MIDWARE, AppLoadNvmConfig_3, P_ERROR, 2,
|
|
|
// "NVM: 'qxappconfig.nvm', can't read body, or body not right, (%u/%u), use the defult value",
|
|
@@ -537,35 +543,36 @@ void appLoadConfig(void)
|
|
|
OsaFclose(fp);
|
|
|
setDefaultAppDataValue();
|
|
|
appSaveConfig();
|
|
|
-
|
|
|
+ /*
|
|
|
if (needAdjust)
|
|
|
{
|
|
|
OsaFreeMemory(&pReadAppConfig);
|
|
|
}
|
|
|
+ */
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-#if 1
|
|
|
- if (needAdjust)
|
|
|
- {
|
|
|
- OsaFclose(fp);
|
|
|
- setDefaultAppDataValue();
|
|
|
- appSaveConfig();
|
|
|
-
|
|
|
- /* free memory */
|
|
|
- OsaFreeMemory(&pReadAppConfig);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
-#if 0
|
|
|
- int i=0;
|
|
|
+ #if 0
|
|
|
+ if (needAdjust)
|
|
|
+ {
|
|
|
+ OsaFclose(fp);
|
|
|
+ setDefaultAppDataValue();
|
|
|
+ appSaveConfig();
|
|
|
|
|
|
- printf("AppConfigHeader:\n");
|
|
|
- printf("%d,%d,%d\n",AppConfigHr.fileBodySize,AppConfigHr.version,AppConfigHr.checkSum);
|
|
|
- printf("AppConfigFileBody:\n");
|
|
|
- printf("%d,%d,%d\n",AppNVMData.chargEndWorkTime,AppNVMData.wakeupWorkTime,AppNVMData.sleepTime);
|
|
|
- printf("\n");
|
|
|
-#endif
|
|
|
+ /* free memory */
|
|
|
+ OsaFreeMemory(&pReadAppConfig);
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ #if 0
|
|
|
+ int i=0;
|
|
|
+
|
|
|
+ printf("AppConfigHeader:\n");
|
|
|
+ printf("%d,%d,%d\n",AppConfigHr.fileBodySize,AppConfigHr.version,AppConfigHr.checkSum);
|
|
|
+ printf("AppConfigFileBody:\n");
|
|
|
+ printf("%d,%d,%d\n",AppNVMData.chargEndWorkTime,AppNVMData.wakeupWorkTime,AppNVMData.sleepTime);
|
|
|
+ printf("\n");
|
|
|
+ #endif
|
|
|
+ OsaFclose(fp);
|
|
|
return;
|
|
|
}
|
|
|
|