2025-11-28 19:41:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "user_common.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 全局通用队列(所有任务共用)
|
|
|
|
|
|
QueueHandle_t xGlobalMsgQueue;
|
|
|
|
|
|
|
|
|
|
|
|
// 电源相关队列
|
|
|
|
|
|
QueueHandle_t xPowerTaskQueue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 消息分发函数用于进行消息分发
|
|
|
|
|
|
void msg_dispatch_task(void* arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
GeneralMsg_t received_msg;
|
|
|
|
|
|
|
|
|
|
|
|
// 创建用于任务间通讯的消息队列
|
|
|
|
|
|
xGlobalMsgQueue = xQueueCreate(
|
|
|
|
|
|
32, // 队列长度(可存储32条消息)
|
|
|
|
|
|
sizeof(GeneralMsg_t) // 每条消息大小
|
|
|
|
|
|
);
|
|
|
|
|
|
configASSERT(xGlobalMsgQueue != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
xPowerTaskQueue = xQueueCreate(
|
|
|
|
|
|
32, // 队列长度(可存储32条消息)
|
|
|
|
|
|
sizeof(GeneralMsg_t) // 每条消息大小
|
|
|
|
|
|
);
|
|
|
|
|
|
configASSERT(xPowerTaskQueue != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(xQueueReceive(xGlobalMsgQueue, &received_msg, portMAX_DELAY)) //若没有消息接收则将任务设置为阻塞态
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (received_msg.type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case MSG_TYPE_POWER_OFF:
|
|
|
|
|
|
// 将消息下发到电源处理任务中
|
|
|
|
|
|
xQueueSend(xPowerTaskQueue, &received_msg, 0);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-28 14:35:07 +08:00
|
|
|
|
}
|