DockerFluxDC/components/user_common/user_common.c

52 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}
}
}
}