修改了eeprom的app->count计数逻辑;增加eeprom的appcfg和appinfo的格式化操作
This commit is contained in:
parent
540f14ee53
commit
ab0d48d8b5
File diff suppressed because one or more lines are too long
@ -126,10 +126,6 @@
|
||||
<pMon>Segger\JL2CM3.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ARMRTXEVENTFLAGS</Key>
|
||||
|
||||
@ -216,12 +216,20 @@ int8_t DrvEepromWriteAppCfg(AppCfg *data) {
|
||||
|
||||
// 添加 APP
|
||||
int8_t DrvEepromAddApp(AppCfg *cfg, uint8_t app_id, const uint32_t *custom_params, size_t param_count) {
|
||||
uint8_t isExist;
|
||||
if (cfg->app_count >= 40) {
|
||||
return -1;
|
||||
DrvEepromFormatAppData();
|
||||
}
|
||||
|
||||
// 计算新 APP 的存储地址
|
||||
uint32_t app_info_addr = EEROM_ADDR_APP_INFO + cfg->app_count * sizeof(AppInfo);
|
||||
// uint32_t app_info_addr = EEROM_ADDR_APP_INFO + cfg->app_count * sizeof(AppInfo);
|
||||
uint32_t app_info_addr = EEROM_ADDR_APP_INFO + app_id * sizeof(AppInfo);
|
||||
|
||||
AppInfo temp_app = {0};
|
||||
int8_t read_status = EepromRead(app_info_addr, (uint32_t *)&temp_app, sizeof(AppInfo), NULL);
|
||||
if (read_status == 0 && temp_app.checkhead != 0xAABB) {
|
||||
isExist = 1;
|
||||
}
|
||||
|
||||
// 初始化 APP 信息并清零
|
||||
AppInfo new_app = {0};
|
||||
@ -241,7 +249,10 @@ int8_t DrvEepromAddApp(AppCfg *cfg, uint8_t app_id, const uint32_t *custom_param
|
||||
|
||||
// 临时保存原 app_count 值
|
||||
uint8_t original_count = cfg->app_count;
|
||||
if (isExist){
|
||||
cfg->app_count++;
|
||||
isExist = 0;
|
||||
}
|
||||
|
||||
// 更新 AppCfg 到 EEPROM
|
||||
status = EepromWrite(EEROM_ADDR_APP_CFG, (uint32_t *)cfg, sizeof(AppCfg));
|
||||
@ -315,6 +326,32 @@ int8_t DrvEepromRemoveApp(AppCfg *cfg, uint8_t app_id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int8_t DrvEepromFormatAppData(void) {
|
||||
|
||||
// 写入默认AppCfg(会自动计算校验和)
|
||||
int8_t status = DrvEepromWriteAppCfg(&defaultAppCfg);
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// 计算AppInfo总占用空间(最大40个AppInfo)
|
||||
uint32_t appInfoTotalSize = 40 * sizeof(AppInfo);
|
||||
uint32_t appInfoAddr = EEROM_ADDR_APP_INFO;
|
||||
|
||||
// 定义清空用的AppInfo结构(全0)
|
||||
AppInfo emptyApp = {0};
|
||||
|
||||
// 逐个清空所有AppInfo空间
|
||||
for (uint8_t i = 0; i < 40; i++) {
|
||||
status = EepromWrite(appInfoAddr, (uint32_t *)&emptyApp, sizeof(AppInfo));
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
appInfoAddr += sizeof(AppInfo);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* 内部辅助函数 */
|
||||
|
||||
@ -129,6 +129,7 @@ int8_t DrvEepromWriteAppCfg(AppCfg *data);
|
||||
int8_t DrvEepromAddApp(AppCfg *cfg, uint8_t app_id, const uint32_t *custom_params, size_t param_count);
|
||||
int8_t DrvEepromReadApp(AppCfg *cfg, uint32_t app_id, AppInfo *app_info);
|
||||
int8_t DrvEepromRemoveApp(AppCfg *cfg, uint8_t app_id);
|
||||
int8_t DrvEepromFormatAppData(void);
|
||||
|
||||
void LoadUpSysParam(void);
|
||||
unsigned char SaveUpSysParam(void);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user