Preface
link
Reference resources
Draft notes
- I'm a little busy with my work recently , Far away? Reading delayed. Ha ha
- By sending address
- In fact, the application of these components is very simple , I don't care , I'll build it soon and see , Prepare to test and look at the source code ,
- however , It took two hours this afternoon , Just to test the non copy communication failure problem
- bug That is, I create a buffer in the function to store the message content locally , Using functions
LOS_QueueWrite
Send out
- There are all kinds of problems when receiving , It's obviously the wrong address , But I didn't even think of the notice that the content of the message was rewritten , alas
- When using address mode , It must be ensured that the content of the address has not been modified , Local variables are not recommended
- When using address mode , It must be ensured that the content of the address has not been modified , Local variables are not recommended
- When using address mode , It must be ensured that the content of the address has not been modified , Local variables are not recommended
Create a test task
- This task is for LiteOS Message queuing test
- step
- Create task related values and functions
- stay
LssAppConfig.h
Add
- Task priority macro
lssConfigvMsgQueueTaskPRIO (5)
- Task stack macro
lssConfigvMsgQueueTaskSIZE 512u
- Task initialization complete enumeration
evMsgQueueTaskNum = 0x0D,
- Message queue external handle
extern UINT32 MsgQueueTask_Handle;
- stay
main.c
Add
- Add task header file
#include "MsgQueueAppTask.h"
- Add handle
- Task to handle
UINT32 MsgQueueTask_Handle = NULL;
- Message queue test handle
UINT32 TestAQue_Handle = NULL;
- Create Message Queue task function
- In the startup task
- add to
uwRet = Creat_vMsgQueue_Task();
, To indicate that the task was created
- add to
uwRet = LOS_QueueCreate("Msg Queue", 20, &TestAQue_Handle, 0, 10);
, To indicate the creation message
- Create a task file
MsgQueueTask.c
and MsgQueueTask.h
- It is mainly used for business test of message queue
- Write task functions
void vMsgQueueTask( void )
- Message queue test task source file
- Message queue test task header file
- stay
IPCApp.c
Add two test functions to the file ( The framework needs )
void IPCAppMsgQueueA(msgIpc_t *msg)
function
- It's the sender of the message
- Queue test function A
void IPCAppMsgQueueB(msgIpc_t *msg)
function
- It's the sender of the message
- Queue test function B
- The header file
PCApp.h
Also need to do external function processing
- stay
IPCCoreTask.c
In file void msgDecode(msgIpc_t * msg)
Function to add two processing commands ( The framework needs )
$QA#
$QB#
- Command processing add part of the source code
Part of the source code
- Create Message Queue task function
/**
* @brief establish vMsgQueueTask Mission
* @param
* @retval
* @author lzm
*/
static UINT32 Creat_vMsgQueue_Task()
{
// Define the return type of a create task , Initialize to create a successful return value
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;
}
- Message queue test task source file
/**
******************************************************************************
* @file MsgQueueTask.c
* @author lzm
* @version V1.0
* @date 2020-10-28
* @brief
* @attention
*
* The experiment platform :LZM
*
*
*
******************************************************************************
*/
#include "MsgQueueTask.h"
#include "bsp_usart.h"
/*
*********************************************************************************************************
* FUNCTION
*********************************************************************************************************
*/
/**
* @brief The hardware and software configuration of this task is initialized
* @param
* @retval
* @author lzm
*/
static void msgQueueInit(void)
{
;
}
/**
* @brief Task function
* @param
* @retval
* @author lzm
*/
void vMsgQueueTask( void )
{
UINT32 uwRet = LOS_OK;
UINT32 msgLen = 30;
// receive messages
UINT32 uwReadbuf;
msgQueueInit();
WaitAllTaskInitOk(evMsgQueueTaskNum); // System ready detection and waiting
while(1)
{
/* Waiting for news */
uwRet = LOS_QueueRead(TestAQue_Handle, // Message queue ID
&uwReadbuf, // Where to save the message
msgLen, // The length of the received message
LOS_WAIT_FOREVER); // wait for - Keep waiting
if(uwRet != LOS_OK)
{
dbgPrintf("read message failure,error:%x\n",uwRet);
}
else
{
dbgPrintf("\r\nLOS_QueueRead is [%s]!",(char *)uwReadbuf);
}
}
}
- Message queue test task header file
/**
******************************************************************************
* @file MsgQueueTask.h
* @author lzm
* @version V1.0
* @date 2020-10-28
* @brief
* @attention
*
* The experiment platform :LZM
*
******************************************************************************
*/
#ifndef __MSG_QUEUE_TASK_H_
#define __MSG_QUEUE_TASK_H_
#include "LssAppConfig.h"
#include "ipcConfig.h"
/*
*********************************************************************************************************
* API
*********************************************************************************************************
*/
/* function */
void vMsgQueueTask( void );
#endif
/**
* @brief
* command [$QA#] Callback function for .
* Message queuing test 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, /* Handle to message queue */
ABuf, /* The content of the message sent The address to send the string */
msgLen,
0); /* Message size */
}
/**
* @brief
* command [$QB#] Callback function for .
* Message queuing test 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, /* Handle to message queue */
BBuf, /* The content of the message sent The address to send the string */
msgLen,
0); /* Message size */
}
- Command processing add part of the source code
...
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);
// ¸æÖªÖ´ÐÐÈÎÎñ
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);
// ¸æÖªÖ´ÐÐÈÎÎñ
uwRet = LOS_SemPost(ListApp_Handle);
if (uwRet != LOS_OK){;}
}
}
...