代码暂存 优化ML307R在睡眠模式下的功耗,目前70uA左右
This commit is contained in:
parent
3778c3652c
commit
7a5f675ac2
|
@ -5,7 +5,7 @@
|
|||
"type": "mrs-debugger",
|
||||
"request": "launch",
|
||||
"name": "IoT_SCV_CH584M1",
|
||||
"cwd": "c:\\Users\\123\\Desktop\\物联网自闭阀",
|
||||
"cwd": "c:\\Users\\123\\Desktop\\物联网自闭阀\\iot_-scv_-ch584-m",
|
||||
"openOCDCfg": {
|
||||
"useLocalOpenOCD": true,
|
||||
"executable": "d:/MounRiverV2/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
|
||||
|
@ -39,8 +39,8 @@
|
|||
"additionalCommands": []
|
||||
},
|
||||
"loadedFiles": {
|
||||
"executableFile": "c:\\Users\\123\\Desktop\\物联网自闭阀\\obj\\IoT_SCV_CH584M1.elf",
|
||||
"symbolFile": "c:\\Users\\123\\Desktop\\物联网自闭阀\\obj\\IoT_SCV_CH584M1.elf",
|
||||
"executableFile": "c:\\Users\\123\\Desktop\\物联网自闭阀\\iot_-scv_-ch584-m\\obj\\IoT_SCV_CH584M1.elf",
|
||||
"symbolFile": "c:\\Users\\123\\Desktop\\物联网自闭阀\\iot_-scv_-ch584-m\\obj\\IoT_SCV_CH584M1.elf",
|
||||
"executableFileOffset": 0,
|
||||
"symbolFileOffset": 0
|
||||
},
|
||||
|
|
|
@ -78,7 +78,7 @@ int main(void)
|
|||
SysTick_Config( GetSysClock() / 1000 * SYSTICK_INTERVAL); //设定嘀嗒时间1ms
|
||||
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
|
||||
// GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD); // 临时屏蔽
|
||||
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -20,13 +20,11 @@ static volatile bool block_sleep_flag = false;
|
|||
|
||||
void BSP_RequestSleep(void)
|
||||
{
|
||||
printf("block_sleep_flag1 = %d\r\n",block_sleep_flag);
|
||||
block_sleep_flag = false;
|
||||
}
|
||||
|
||||
void BSP_BlockSleep(void)
|
||||
{
|
||||
printf("block_sleep_flag3 = %d\r\n",block_sleep_flag);
|
||||
block_sleep_flag = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
系统进入睡眠模式后,需要长按键盘按键来激活letter shell
|
||||
激活后可正常使用letter shell
|
||||
30秒无操作后自动进入睡眠
|
||||
1.4G模组偶先连接失败问题
|
||||
2.需添加如果短时间内多次改变阀门状态时4G可以都上报的功能
|
||||
|
|
|
@ -18,6 +18,7 @@ void PRESS_LowPower(void);
|
|||
|
||||
void BSP_PRESS_Init(void);
|
||||
void Function_Check(void);
|
||||
extern uint8_t volatile fault_state;
|
||||
|
||||
#include "bmp3.h"
|
||||
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
#include "CONFIG.h"
|
||||
#include "log.h"
|
||||
#include "bsp_ml307r.h"
|
||||
#include "SLEEP.h"
|
||||
|
||||
uint8_t flag, fault_state;
|
||||
uint8_t flag;
|
||||
uint8_t volatile fault_state = 0;
|
||||
extern uint8_t motor_flag;
|
||||
extern Shell shell;
|
||||
|
||||
|
@ -380,14 +382,14 @@ void Lower_IO_Deinit(void)
|
|||
|
||||
//4G
|
||||
// 关闭3.8V供电
|
||||
// GPIOB_ResetBits(ENABLE_3_8_V);
|
||||
// GPIOB_ModeCfg(ENABLE_3_8_V, GPIO_ModeIN_PD);
|
||||
// // 将控制引脚设为下拉,减少漏电流
|
||||
// GPIOB_ModeCfg(ML307_PWR_PIN | ML307_RST_PIN, GPIO_ModeIN_PD);
|
||||
// // UART引脚设为下拉
|
||||
// GPIOB_ModeCfg(ML307_UART_TX_PIN | ML307_UART_RX_PIN, GPIO_ModeIN_PU);
|
||||
// // SIM卡检测引脚配置为下拉输入
|
||||
// GPIOB_ModeCfg(USIM_DECT_PIN, GPIO_ModeIN_PD);
|
||||
GPIOB_ResetBits(ENABLE_3_8_V);
|
||||
GPIOB_ModeCfg(ENABLE_3_8_V, GPIO_ModeIN_PD);
|
||||
// 将控制引脚设为下拉,减少漏电流
|
||||
GPIOB_ModeCfg(ML307_PWR_PIN | ML307_RST_PIN, GPIO_ModeIN_PD);
|
||||
// UART引脚设为下拉
|
||||
GPIOB_ModeCfg(ML307_UART_TX_PIN | ML307_UART_RX_PIN, GPIO_ModeIN_PU);
|
||||
// SIM卡检测引脚配置为下拉输入
|
||||
GPIOB_ModeCfg(USIM_DECT_PIN, GPIO_ModeIN_PD);
|
||||
|
||||
//motor
|
||||
GPIOB_ResetBits(NSLEEP_PIN);
|
||||
|
|
|
@ -39,7 +39,7 @@ void app_task_handler(TeAppEvtType app_evt_type)
|
|||
BSP_KEY_EnterLowpower();
|
||||
// DelayMs(10);
|
||||
// BSP_RequestSleep();
|
||||
// logDebug("gpio relase;BSP_RequestSleep ");
|
||||
logDebug("gpio relase;BSP_RequestSleep ");
|
||||
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "CONFIG.h"
|
||||
#include "SLEEP.h"
|
||||
#include "bsp_iwdg.h"
|
||||
#include "bsp_bmp390.h"
|
||||
|
||||
#undef LOG_ENABLE
|
||||
#define LOG_ENABLE 1
|
||||
|
@ -118,13 +119,12 @@ static uint16_t Ml307_Power_Handle(uint8_t task_id, uint16_t events)
|
|||
// 完成上电过程
|
||||
logDebug("ML307 power on complete\n");
|
||||
GPIOB_ResetBits(ML307_PWR_PIN);
|
||||
ml307_power_state = POWER_STATE_INIT;
|
||||
ml307_power_state = POWER_STATE_ON_COMPLETE;
|
||||
// 继续初始化过程
|
||||
if (ml307r_obj != NULL) {
|
||||
BSP_ML307_SetActive();
|
||||
// 触发模块初始化流程
|
||||
tmos_set_event(ml307_task_id, ML307_PERIODIC_EVT);
|
||||
|
||||
// 执行后续初始化步骤
|
||||
logDebug("BSP_Read_Module\n");
|
||||
BSP_Read_Module();
|
||||
|
@ -135,7 +135,7 @@ static uint16_t Ml307_Power_Handle(uint8_t task_id, uint16_t events)
|
|||
BSP_Module_Connect_CtWing();
|
||||
logDebug("BSP_ML307_SendMessage\n");
|
||||
BSP_ML307_SetActive();
|
||||
BSP_ML307_SendMessage();
|
||||
// BSP_ML307_SendMessage();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -173,7 +173,7 @@ static uint16_t Ml307_Power_Handle(uint8_t task_id, uint16_t events)
|
|||
logDebug("ML307 power off complete\n");
|
||||
ml307_power_state = POWER_STATE_INIT;
|
||||
// 请求系统进入睡眠状态
|
||||
// BSP_RequestSleep();
|
||||
BSP_RequestSleep();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -226,17 +226,6 @@ int Ml307r_Gpio_Init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// 停止4G通信,停止轮询任务
|
||||
void BSP_Stop_ML307_Task(void)
|
||||
{
|
||||
if (ml307_task_id != INVALID_TASK_ID) {
|
||||
tmos_stop_task(ml307_task_id, ML307_PERIODIC_EVT);
|
||||
// Ml307_Power_Off();
|
||||
// BSP_RequestSleep();
|
||||
Ml307_Power_Off_NonBlocking();
|
||||
logDebug("4G module polling stopped\n");
|
||||
}
|
||||
}
|
||||
|
||||
static int Module_Read_State(at_env_t *e)
|
||||
{
|
||||
|
@ -310,7 +299,7 @@ static void simcom_init(void)
|
|||
attr.cb = simcom_init_callback; //设置命令回调
|
||||
// 设置命令间延迟,给模块更多响应时间
|
||||
attr.timeout = 2000; // 增加超时时间到2秒
|
||||
attr.retry = 2; // 设置重试次数
|
||||
attr.retry = 3; // 设置重试次数
|
||||
at_send_multiline(ml307r_obj, &attr, cmds);
|
||||
}
|
||||
|
||||
|
@ -324,7 +313,7 @@ static int BSP_Module_Connect_CtWing_Handle(at_env_t *e)
|
|||
{
|
||||
case 0:
|
||||
logDebug("create device...\r\n");
|
||||
e->println(e, "AT+MIPOPEN=0,\"TCP\",\"112.125.89.8\",43192,,1"); // 8.135.10.183,32994
|
||||
e->println(e, "AT+MIPOPEN=0,\"TCP\",\"112.125.89.8\",46763,,1"); // 8.135.10.183,32994
|
||||
e->reset_timer(e);
|
||||
e->state++;
|
||||
break;
|
||||
|
@ -333,6 +322,10 @@ static int BSP_Module_Connect_CtWing_Handle(at_env_t *e)
|
|||
{
|
||||
logDebug("create device complete\r\n");
|
||||
e->finish(e, AT_RESP_OK);
|
||||
BSP_ML307_SetActive();
|
||||
BSP_ML307_SendMessage();
|
||||
// BSP_ML307_SetActive();
|
||||
// BSP_ML307_SendMessage();
|
||||
}
|
||||
else if (e->is_timeout(e, 5000))
|
||||
{
|
||||
|
@ -426,7 +419,7 @@ uint16_t Ml307r_Handle(uint8_t task_id, uint16_t events)
|
|||
{
|
||||
FEED_IWDG();
|
||||
Ml307r_Loop();
|
||||
tmos_start_task(ml307_task_id, ML307_PERIODIC_EVT, MS1_TO_SYSTEM_TIME(200)); //5
|
||||
tmos_start_task(ml307_task_id, ML307_PERIODIC_EVT, MS1_TO_SYSTEM_TIME(5)); //5
|
||||
return (events ^ ML307_PERIODIC_EVT);
|
||||
}
|
||||
return 0;
|
||||
|
@ -441,6 +434,40 @@ void BSP_Module_Send_Data(uint8_t* data, uint8_t len)
|
|||
at_send_data(ml307r_obj, &attr, data, len);
|
||||
}
|
||||
|
||||
void BSP_ML307_SendMessage(void)
|
||||
{
|
||||
if(fault_state){
|
||||
char json_buffer[300];
|
||||
snprintf(json_buffer, sizeof(json_buffer),
|
||||
"{"
|
||||
"\"device\":{"
|
||||
"\"id\":\"SCV001\","
|
||||
"\"time\":\"2025\""
|
||||
"},"
|
||||
"\"status\":\"closed\","
|
||||
"\"fault\":{"
|
||||
"\"lowBattery\":true,"
|
||||
"\"code\":1"
|
||||
"},"
|
||||
"\"monitor\":{"
|
||||
"\"pressure\":0.8,"
|
||||
"\"lowVoltage\":true"
|
||||
"},"
|
||||
"\"network\":{"
|
||||
"\"sinr\":15.2,"
|
||||
"\"signal\":4"
|
||||
"},"
|
||||
"\"standards\":{"
|
||||
"\"iotId\":\"IoT-SCV-12345\""
|
||||
"}"
|
||||
"}");
|
||||
|
||||
BSP_Module_Send_Data((uint8_t*)json_buffer, strlen(json_buffer));
|
||||
// logDebug("fault_state: %d\n", fault_state);
|
||||
logDebug("BSP_ML307_SendMessage: %s\n", json_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// 断电保护数据上报
|
||||
void BSP_Module_Emergency_Send(uint8_t* data, uint8_t len)
|
||||
{
|
||||
|
@ -465,7 +492,8 @@ void BSP_Module_Emergency_Send(uint8_t* data, uint8_t len)
|
|||
|
||||
void BSP_Ml307r_Init(void)
|
||||
{
|
||||
|
||||
if(ml307_power_state == POWER_STATE_INIT)
|
||||
{
|
||||
Ml307r_Gpio_Init();
|
||||
|
||||
// Ml307_Power_On();
|
||||
|
@ -473,7 +501,7 @@ void BSP_Ml307r_Init(void)
|
|||
BSP_UART1_Init();
|
||||
|
||||
ml307r_obj = at_obj_create(&at_adapter);//Create AT communication object
|
||||
at_obj_set_urc(ml307r_obj, urc_table, sizeof(urc_table) / sizeof(urc_table[0]));
|
||||
// at_obj_set_urc(ml307r_obj, urc_table, sizeof(urc_table) / sizeof(urc_table[0]));
|
||||
ml307_task_id = TMOS_ProcessEventRegister(Ml307r_Handle);
|
||||
// tmos_set_event(ml307_task_id, ML307_PERIODIC_EVT);
|
||||
|
||||
|
@ -483,6 +511,9 @@ void BSP_Ml307r_Init(void)
|
|||
// 启动非阻塞式电源开启,后续初始化会在电源开启完成后自动进行
|
||||
Ml307_Power_On_NonBlocking();
|
||||
|
||||
|
||||
|
||||
|
||||
// logDebug("BSP_Read_Module\n");
|
||||
// BSP_Read_Module();
|
||||
// logDebug("simcom_init\n");
|
||||
|
@ -492,8 +523,21 @@ void BSP_Ml307r_Init(void)
|
|||
// logDebug("BSP_Module_Send_Data\n");
|
||||
// // BSP_Module_Send_Data(databuf, 5);
|
||||
// BSP_ML307_SendMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 停止4G通信,停止轮询任务
|
||||
void BSP_Stop_ML307_Task(void)
|
||||
{
|
||||
if (ml307_task_id != INVALID_TASK_ID) {
|
||||
tmos_stop_task(ml307_task_id, ML307_PERIODIC_EVT);
|
||||
// Ml307_Power_Off();
|
||||
Ml307_Power_Off_NonBlocking();
|
||||
logDebug("4G module polling stopped\n");
|
||||
// BSP_RequestSleep();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ML307超时任务处理函数
|
||||
|
@ -532,32 +576,3 @@ void BSP_ML307_SetActive(void)
|
|||
}
|
||||
|
||||
|
||||
void BSP_ML307_SendMessage(void)
|
||||
{
|
||||
char json_buffer[300];
|
||||
snprintf(json_buffer, sizeof(json_buffer),
|
||||
"{"
|
||||
"\"device\":{"
|
||||
"\"id\":\"SCV001\","
|
||||
"\"time\":\"2025\""
|
||||
"},"
|
||||
"\"status\":\"closed\","
|
||||
"\"fault\":{"
|
||||
"\"lowBattery\":true,"
|
||||
"\"code\":1001"
|
||||
"},"
|
||||
"\"monitor\":{"
|
||||
"\"pressure\":0.8,"
|
||||
"\"lowVoltage\":true"
|
||||
"},"
|
||||
"\"network\":{"
|
||||
"\"sinr\":15.2,"
|
||||
"\"signal\":4"
|
||||
"},"
|
||||
"\"standards\":{"
|
||||
"\"iotId\":\"IoT-SCV-12345\""
|
||||
"}"
|
||||
"}");
|
||||
BSP_Module_Send_Data((uint8_t*)json_buffer, strlen(json_buffer));
|
||||
logDebug("BSP_ML307_SendMessage: %s\n", json_buffer);
|
||||
}
|
Loading…
Reference in New Issue