修改了掉电下不处理其他逻辑,以及RTC更新问题

This commit is contained in:
小马_666 2025-01-09 14:30:40 +08:00
parent 1ef1ac80e7
commit 513ab2dcff
11 changed files with 145 additions and 31 deletions

View File

@ -0,0 +1,26 @@
{
"folders": [
{
"path": "."
},
{
"name": "ble_bjq_ch303rct6_ml307",
"path": "../"
}
],
"settings": {
"mrs.workspace.type": "project",
"files.associations": {
"*.c": "c",
"*.h": "cpp",
"*.hxx": "cpp",
"*.hpp": "cpp",
"*.c++": "cpp",
"*.cpp": "cpp",
"*.cxx": "cpp",
"*.cc": "cpp",
"*.hh": "cpp",
"*.h++": "cpp"
}
}
}

65
.mrs/launch.json Normal file
View File

@ -0,0 +1,65 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "mrs-debugger",
"request": "launch",
"name": "ble_bjq_ch303rct6_ml307",
"cwd": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307",
"openOCDCfg": {
"useLocalOpenOCD": true,
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
"configOptions": [
"-f \"c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/wch-riscv.cfg\" -c \"chip_id CH32V30x\""
],
"gdbport": 3333,
"telnetport": 4444,
"tclport": 6666,
"host": "localhost",
"port": 3333,
"skipDownloadBeforeDebug": false,
"enablePageEraser": false,
"enableNoZeroWaitingAreaFlash": false
},
"gdbCfg": {
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/Toolchain/RISC-V Embedded GCC12/bin/riscv-wch-elf-gdb.exe",
"commands": [
"set mem inaccessible-by-default off",
"set architecture riscv:rv32",
"set remotetimeout unlimited",
"set disassembler-options xw"
],
"options": []
},
"startup": {
"initCommands": {
"initReset": true,
"initResetType": "init",
"armSemihosting": false,
"additionalCommands": []
},
"loadedFiles": {
"executableFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf",
"symbolFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf",
"executableFileOffset": 0,
"symbolFileOffset": 0
},
"runCommands": {
"runReset": true,
"runResetType": "halt",
"additionalCommands": [],
"setBreakAt": "handle_reset",
"continue": true,
"setProgramCounterAt": 0
},
"debugInRAM": false
},
"svdpath": "c:\\MounRiver\\MounRiver_Studio2\\resources\\app\\resources\\win32\\components\\WCH\\SDK\\default/RISC-V/CH32V307/NoneOS/CH32V307xx.svd",
"output": {
"showDebugGDBTrace": true,
"saveDebugOutputToFile": false,
"showDebugOutputTimestamps": true
}
}
]
}

View File

@ -18,6 +18,8 @@
} }
], ],
"files.associations": { "files.associations": {
"*.ndjson": "jsonl",
"*.dbclient-js": "javascript",
"rtthread.h": "c", "rtthread.h": "c",
"user_sys.h": "c", "user_sys.h": "c",
"bsp_led.h": "c", "bsp_led.h": "c",
@ -57,6 +59,7 @@
"string.h": "c", "string.h": "c",
"completion.h": "c", "completion.h": "c",
"bsp_bt.h": "c", "bsp_bt.h": "c",
"bsp_ml307.h": "c" "bsp_ml307.h": "c",
"bsp_vin_detection.h": "c"
} }
} }

View File

@ -92,8 +92,15 @@ void Send_Laser_Alarm_Event(AlarmEvent event_type)
if (is_event_initialized == RT_TRUE) if (is_event_initialized == RT_TRUE)
{ {
rt_event_send(&alarm_event, Get_Sys_Event_Flag(event_type)); if (SysControl.status == kPowerDownEvent)
LOG_D("Send_Laser_Alarm_Event = %d", SysControl.status); {
LOG_D("掉电模式下不处理其他事件");
}
else
{
LOG_I("Send_Laser_Alarm_Event = %d", event_type);
rt_event_send(&alarm_event, Get_Sys_Event_Flag(event_type));
}
} }
else else
{ {
@ -102,6 +109,7 @@ void Send_Laser_Alarm_Event(AlarmEvent event_type)
} }
} }
int _Self_Check_Mode(void) int _Self_Check_Mode(void)
{ {
LED_STOP(r); LED_STOP(r);
@ -150,7 +158,6 @@ int main(void)
{ {
// 定义超时时间,单位为毫秒 // 定义超时时间,单位为毫秒
#define TIMEOUT_MS 3 * 60 * 1000 #define TIMEOUT_MS 3 * 60 * 1000
// #define TIMEOUT_MS 8 * 1000
#define WORK_TIMER_CNT (1000 * 60 * 60) #define WORK_TIMER_CNT (1000 * 60 * 60)
rt_err_t result = RT_EINVAL; rt_err_t result = RT_EINVAL;
rt_uint32_t received_event; rt_uint32_t received_event;
@ -345,7 +352,6 @@ int main(void)
Flash_Write_Record(kRecordAlarm); // 写入flash报警信息 Flash_Write_Record(kRecordAlarm); // 写入flash报警信息
if (Flash_Get_Valve_Num()) if (Flash_Get_Valve_Num())
{ {
// Bt_Valve_Handler(kValveCmdCtr, 0, RT_NULL);
rt_uint8_t mac_addr[6]; rt_uint8_t mac_addr[6];
Flash_Get_Mac_Addr(mac_addr, 1); Flash_Get_Mac_Addr(mac_addr, 1);
Bt_Valve_Handler(kValveCmdCtr, 1, mac_addr); Bt_Valve_Handler(kValveCmdCtr, 1, mac_addr);

View File

@ -30,9 +30,7 @@
#include "bsp_rng.h" #include "bsp_rng.h"
volatile rt_uint16_t work_duration = 0; // 工作时长,单位:小时
volatile rt_uint16_t work_duration = 1; // 工作时长
volatile rt_uint8_t device_life_check = 0; volatile rt_uint8_t device_life_check = 0;
volatile rt_uint8_t device_state_flag = 0; // 设备失效标志 volatile rt_uint8_t device_state_flag = 0; // 设备失效标志

View File

@ -116,9 +116,9 @@
#define FLASH_IOT_ICCID_ADDR (FLASH_IOT_IMSI_ADDR + FLASH_IOT_IMSI_LEN) #define FLASH_IOT_ICCID_ADDR (FLASH_IOT_IMSI_ADDR + FLASH_IOT_IMSI_LEN)
#define FLASH_IOT_ICCID_LEN (20) #define FLASH_IOT_ICCID_LEN (20)
/*工作时长记录*/ /*工作时长记录 5* 365 * 24 = 43800 < 65535*/
#define FLASH_WORK_TIME_ADDR (FLASH_IOT_ICCID_ADDR + FLASH_IOT_ICCID_LEN) #define FLASH_WORK_TIME_ADDR (FLASH_IOT_ICCID_ADDR + FLASH_IOT_ICCID_LEN)
#define FLASH_WORK_TIME_LEN (2)//单位: #define FLASH_WORK_TIME_LEN (2)//单位:hours
/*正式平台服务器地址*/ /*正式平台服务器地址*/
#define FLASH_SERVER_ADDR_ADDR (FLASH_WORK_TIME_ADDR + FLASH_WORK_TIME_LEN) #define FLASH_SERVER_ADDR_ADDR (FLASH_WORK_TIME_ADDR + FLASH_WORK_TIME_LEN)

View File

@ -20,7 +20,7 @@ typedef struct __attribute__((packed))
{ {
uint16_t year; // 年份设置,取值范围为 uint16_t year; // 年份设置,取值范围为
uint8_t month; // 日期设置取值范围为1~31 uint8_t month; // 日期设置取值范围为1~31
uint8_t day; // 月份设置取值范围为1~12 uint16_t day; // 月份设置取值范围为1~12
uint8_t hour; /* 小时设置 */ uint8_t hour; /* 小时设置 */
uint8_t minute; /* 分钟设置 */ uint8_t minute; /* 分钟设置 */

View File

@ -1,12 +1,12 @@
/* /*
* @Author : stark1898y 1658608470@qq.com * @Author: mbw
* @Date : 2024-09-04 13:33:49 * @Date: 2024-11-30 15:46:21
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-05 13:03:00 * @LastEditTime: 2025-01-09 14:18:04
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\at_device_ml307.c * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\at_device_ml307.c
* @Description : * @Description:
* *
* Copyright (c) 2024 by yzy, All Rights Reserved. * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved.
*/ */
/* /*
* Copyright (c) 2006-2023, RT-Thread Development Team * Copyright (c) 2006-2023, RT-Thread Development Team
@ -1094,7 +1094,28 @@ static void ml307_init_thread_entry(void *parameter)
goto __exit; goto __exit;
} }
#endif #endif
if (at_obj_exec_cmd(device->client, resp, "AT+CCLK?") == RT_EOK)
{
TsRtcDateTime rtc_dt;
int year, mounth, days, hous, min, sec;
/*+CCLK:24/11/12,06:08:19+32*/
if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0)
{
rtc_dt.year = (2000 + year);
rtc_dt.month = mounth;
rtc_dt.day = days;
rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区
rtc_dt.minute = min;
rtc_dt.second = sec;
Time_Zone_Conversion(&rtc_dt); // 时区设置
rtc_dt.week = RTC_GetWeek(rtc_dt.year, rtc_dt.month, rtc_dt.day);
RTC_SetTime(rtc_dt.year, rtc_dt.month, rtc_dt.day,
rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间
LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n",
rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second);
result = RT_EOK;
}
}
/* initialize successfully */ /* initialize successfully */
result = RT_EOK; result = RT_EOK;
break; break;

View File

@ -50,7 +50,7 @@ static uint8_t _CommonBtnRead(void *arg)
static void _CommonBtnEvtCb(void *arg) static void _CommonBtnEvtCb(void *arg)
{ {
static rt_uint8_t button_cnt = 0; // static rt_uint8_t button_cnt = 0;
if (flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK) if (flex_button_event_read(&user_button[USER_BUTTON_1]) == FLEX_BTN_PRESS_CLICK)
{ {

View File

@ -275,8 +275,7 @@ int Flash_Set_WorkDuration(rt_uint16_t value)
rt_uint8_t in_page_offset = (FLASH_WORK_TIME_ADDR - FLASH_CONFIG_INFO_START_ADDR); rt_uint8_t in_page_offset = (FLASH_WORK_TIME_ADDR - FLASH_CONFIG_INFO_START_ADDR);
Flash_ErasePage_ReadConfigInfo(page_buf); Flash_ErasePage_ReadConfigInfo(page_buf);
rt_memcpy(page_buf + in_page_offset, &value, FLASH_WORK_TIME_LEN);
*(rt_uint16_t *)(page_buf + in_page_offset) = value;
return Flash_Write_ConfigInfo(page_buf); return Flash_Write_ConfigInfo(page_buf);
} }
@ -284,12 +283,6 @@ int Flash_Get_Sever_Addr_Info(flash_sever_info *sever_info)
{ {
rt_uint8_t data[FLASH_SERVER_LEN]; rt_uint8_t data[FLASH_SERVER_LEN];
rt_memcpy(data, (rt_uint8_t *)FLASH_SERVER_ADDR_ADDR, FLASH_SERVER_LEN); rt_memcpy(data, (rt_uint8_t *)FLASH_SERVER_ADDR_ADDR, FLASH_SERVER_LEN);
if (data == RT_NULL)
{
LOG_E("Flash_Get_Sever_Addr_Info failed");
return -RT_ERROR;
}
LOG_D("FLASH_SERVER_ADDR_ADDR = %X", FLASH_SERVER_ADDR_ADDR); LOG_D("FLASH_SERVER_ADDR_ADDR = %X", FLASH_SERVER_ADDR_ADDR);
LOG_D("data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x", 0, data[0], 1, data[1], 2, data[2], 3, data[3], 4, data[4], 5, data[5]); LOG_D("data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x", 0, data[0], 1, data[1], 2, data[2], 3, data[3], 4, data[4], 5, data[5]);
rt_snprintf(sever_info->server_url, sizeof(sever_info->server_url), "%d.%d.%d.%d", rt_snprintf(sever_info->server_url, sizeof(sever_info->server_url), "%d.%d.%d.%d",
@ -655,8 +648,9 @@ void Flash_ErasePage_ConfigInfo(void)
void Flash_ErasePage_ReadConfigInfo(rt_uint8_t *page_buf) void Flash_ErasePage_ReadConfigInfo(rt_uint8_t *page_buf)
{ {
Flash_Read(FLASH_CONFIG_INFO_START_ADDR, page_buf, FLASH_PAGE_SIZE); Flash_Read(FLASH_CONFIG_INFO_START_ADDR, page_buf, FLASH_PAGE_SIZE);
rt_thread_mdelay(10);
Flash_ErasePage_ConfigInfo(); Flash_ErasePage_ConfigInfo();
rt_thread_mdelay(10);
} }
int Flash_Write_ConfigInfo(rt_uint8_t *page_buf) int Flash_Write_ConfigInfo(rt_uint8_t *page_buf)
@ -908,7 +902,7 @@ int BSP_Flash_Init(void)
sci.emagnetic_switch = sys_emagnetic_switch; sci.emagnetic_switch = sys_emagnetic_switch;
sci.relay_switch = sys_relay_switch; sci.relay_switch = sys_relay_switch;
Flash_Set_WorkDuration(work_duration); Flash_Set_WorkDuration(0);//第一次下载工作时长为0
LOG_D("work_duration:%d", Flash_Get_WorkDuration()); LOG_D("work_duration:%d", Flash_Get_WorkDuration());
Convert_To_Hex(&sever_info, sever_data); Convert_To_Hex(&sever_info, sever_data);
@ -921,7 +915,7 @@ int BSP_Flash_Init(void)
{ {
LOG_D("Flash_Set_Sever_Addr_Info error!"); LOG_D("Flash_Set_Sever_Addr_Info error!");
} }
Flash_Set_Calibration_State(kSysGasCalibStatus); // 标定状态 Flash_Set_Calibration_State(kSysGasCalibStatus); // 标定状态
Flash_Set_Valve_Num(0); Flash_Set_Valve_Num(0);
Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci, Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci,
(sizeof(sys_config_info) - 50)); (sizeof(sys_config_info) - 50));

View File

@ -2,7 +2,7 @@
* @Author: mbw * @Author: mbw
* @Date: 2024-11-30 15:46:21 * @Date: 2024-11-30 15:46:21
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-05 13:29:29 * @LastEditTime: 2025-01-08 16:36:27
* @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c
* @Description: * @Description:
* *
@ -1685,6 +1685,7 @@ static void Ml307_Life_Thread_Entry(void *parameter)
device->class->device_ops->control(device, AT_DEVICE_CTRL_RESET, RT_NULL); // 先关闭,再处理 device->class->device_ops->control(device, AT_DEVICE_CTRL_RESET, RT_NULL); // 先关闭,再处理
if(ml307_disconnect_pdp_flag) if(ml307_disconnect_pdp_flag)
{ {
ml307_disconnect_pdp_flag = 0;
at_response_t resp = at_create_resp(32, 0, 5000); at_response_t resp = at_create_resp(32, 0, 5000);
if (resp == RT_NULL) if (resp == RT_NULL)
{ {