From 9635c1ec8bab034040f3ada3e5e368a6fb9e5e7a Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期日, 21 一月 2024 18:56:53 +0800 Subject: [PATCH] V1.42 随机时间片 --- Src/application/global_param.c | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Src/application/global_param.c b/Src/application/global_param.c index f366224..eefa142 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) @@ -17,13 +47,8 @@ __enable_irq(); return result; } - -void parameter_init(void) +void ReturnFactorySettings(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; g_com_map[DEV_ID] =0x04;//DEFAULT_DEV_ID; //默认设备ID @@ -48,12 +73,22 @@ 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; g_com_map[CNT_UPDATE]=0; g_com_map[MODBUS_MODE]=0; save_com_map_to_flash(); +} +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) + { + ReturnFactorySettings(); } } -- Gitblit v1.9.3