From 7f03a5fa045dffcde383531118be00c2ead93ff6 Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期四, 15 九月 2022 17:33:52 +0800 Subject: [PATCH] V1.32 保存参数前会检验一次,如果有问题,则不保存 --- Src/application/global_param.c | 38 +++++++++++++++++++++++++++++++++++--- 1 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Src/application/global_param.c b/Src/application/global_param.c index f366224..68a299b 100644 --- a/Src/application/global_param.c +++ b/Src/application/global_param.c @@ -4,12 +4,42 @@ #include <string.h> uint16_t g_com_map[COM_MAP_SIZE]; - +u8 parameter_check(void) +{ + if(g_com_map[0] != 0x55AA) + { + return 1; + } + if(g_com_map[COM_INTERVAL]<50||COM_INTERVAL>1000) + { + return 1; + } + if(g_com_map[POWER]>67) + { + return 1; + } + if(g_com_map[MOTOR_ENABLE]>1) + { + return 1; + } + if(g_com_map[IMU_ENABLE]>1) + { + return 1; + } + if(g_com_map[ACTIVE_INDEX]>1) + { + return 1; + } + return 0; +} uint32_t save_com_map_to_flash(void) { uint32_t result = 0; - + if(parameter_check()) //参数错误,不保存 + { + return 1; + } __disable_irq(); result = FLASH_Prepare(FLASH_IAP_CTRL_MAP, (COM_MAP_SIZE<<1)); if(result) @@ -21,7 +51,7 @@ void parameter_init(void) { FLASH_Read(FLASH_IAP_CTRL_MAP, (uint8_t*)&g_com_map, (COM_MAP_SIZE<<1)); - + if(g_com_map[0] != 0x55AA) { g_com_map[0] = 0x55AA; @@ -48,6 +78,8 @@ g_com_map[MOTOR_ENABLE]=1; g_com_map[IMU_ENABLE]=1; + g_com_map[ANT_LENGTH] = 0; + g_com_map[ACTIVE_INDEX]=0; g_com_map[CNT_RESTART]=0; g_com_map[CNT_REBOOT]=0; -- Gitblit v1.9.3