LOS_QueueWrite
发送出去LssAppConfig.h
中添加
lssConfigvMsgQueueTaskPRIO (5)
lssConfigvMsgQueueTaskSIZE 512u
evMsgQueueTaskNum = 0x0D,
extern UINT32 MsgQueueTask_Handle;
main.c
中添加
#include "MsgQueueAppTask.h"
UINT32 MsgQueueTask_Handle = NULL;
UINT32 TestAQue_Handle = NULL;
uwRet = Creat_vMsgQueue_Task();
,以表示创建该任务uwRet = LOS_QueueCreate("Msg Queue", 20, &TestAQue_Handle, 0, 10);
, 以表示创建消息MsgQueueTask.c
和 MsgQueueTask.h
void vMsgQueueTask( void )
IPCApp.c
文件中添加两个测试函数(框架需要)
IPCCoreTask.c
文件中 void msgDecode(msgIpc_t * msg)
函数中添加两条处理命令(框架需要)
$QA#
$QB#
/**
* @brief 创建vMsgQueueTask任务
* @param
* @retval
* @author lzm
*/
static UINT32 Creat_vMsgQueue_Task()
{
//定义一个创建任务的返回类型,初始化为创建成功的返回值
UINT32 uwRet = LOS_OK;
TSK_INIT_PARAM_S task_init_param;
task_init_param.usTaskPrio = lssConfigvMsgQueueTaskPRIO;
task_init_param.pcName = "MsgQueue Task";
task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)vMsgQueueTask;
task_init_param.uwStackSize = lssConfigvMsgQueueTaskSIZE;
uwRet = LOS_TaskCreate(&MsgQueueTask_Handle, &task_init_param);
return uwRet;
}
/**
******************************************************************************
* @file MsgQueueTask.c
* @author lzm
* @version V1.0
* @date 2020-10-28
* @brief
* @attention
*
* 实验平台:LZM
*
*
*
******************************************************************************
*/
#include "MsgQueueTask.h"
#include "bsp_usart.h"
/*
*********************************************************************************************************
* FUNCTION
*********************************************************************************************************
*/
/**
* @brief 该任务的软硬件配置初始化
* @param
* @retval
* @author lzm
*/
static void msgQueueInit(void)
{
;
}
/**
* @brief 任务函数
* @param
* @retval
* @author lzm
*/
void vMsgQueueTask( void )
{
UINT32 uwRet = LOS_OK;
UINT32 msgLen = 30;
// 接收消息
UINT32 uwReadbuf;
msgQueueInit();
WaitAllTaskInitOk(evMsgQueueTaskNum); // 系统就绪检测及等待
while(1)
{
/* 等待消息 */
uwRet = LOS_QueueRead(TestAQue_Handle, // 消息队列 ID
&uwReadbuf, // 保存消息的位置
msgLen, // 接收消息的长度
LOS_WAIT_FOREVER); // 等待 - 一直等
if(uwRet != LOS_OK)
{
dbgPrintf("read message failure,error:%x\n",uwRet);
}
else
{
dbgPrintf("\r\nLOS_QueueRead is [%s]!",(char *)uwReadbuf);
}
}
}
/**
******************************************************************************
* @file MsgQueueTask.h
* @author lzm
* @version V1.0
* @date 2020-10-28
* @brief
* @attention
*
* 实验平台:LZM
*
******************************************************************************
*/
#ifndef __MSG_QUEUE_TASK_H_
#define __MSG_QUEUE_TASK_H_
#include "LssAppConfig.h"
#include "ipcConfig.h"
/*
*********************************************************************************************************
* API
*********************************************************************************************************
*/
/* function */
void vMsgQueueTask( void );
#endif
/**
* @brief
* 命令 [$QA#] 的回调函数。
* 消息队列测试 A
* @param
* @retval
* @author lzm
*/
void IPCAppMsgQueueA(msgIpc_t *msg)
{
static UINT32 i = 0;
static CHAR ABuf[] = "Test is message x";
UINT32 msgLen = sizeof(ABuf);
LOS_QueueWrite( TestAQue_Handle, /* 消息队列的句柄 */
ABuf, /* 发送的消息内容 发送字符串的地址*/
msgLen,
0); /* 消息大小 */
}
/**
* @brief
* 命令 [$QB#] 的回调函数。
* 消息队列测试 B
* @param
* @retval
* @author lzm
*/
void IPCAppMsgQueueB(msgIpc_t *msg)
{
static UINT32 i = 0;
static CHAR BBuf[] = "Test is message n";
UINT32 msgLen = sizeof(BBuf);
LOS_QueueWrite( TestAQue_Handle, /* 消息队列的句柄 */
BBuf, /* 发送的消息内容 发送字符串的地址*/
msgLen,
0); /* 消息大小 */
}
...
else if(msg->data[msg->index + 1] == ‘Q‘)
{
if(msg->data[msg->index + 2] == ‘A‘)
{
MALLOC_REGISTER_INSTEREND_CBFUN_LIST(cmd, cmdItem, 2, msg, callbackFunctionList, xCBFunListSem_Handle, IPCAppMsgQueueA);
// ???a?′DDè???
uwRet = LOS_SemPost(ListApp_Handle);
if (uwRet != LOS_OK){;}
}
else if(msg->data[msg->index + 2] == ‘B‘)
{
MALLOC_REGISTER_INSTEREND_CBFUN_LIST(cmd, cmdItem, 3, msg, callbackFunctionList, xCBFunListSem_Handle, IPCAppMsgQueueB);
// ???a?′DDè???
uwRet = LOS_SemPost(ListApp_Handle);
if (uwRet != LOS_OK){;}
}
}
...
原文:https://www.cnblogs.com/lizhuming/p/13944550.html