当前位置:网站首页>Liteos message queuing actual combat

Liteos message queuing actual combat

2020-11-08 16:10:00 Li Zhuming


Preface

Reference resources

  • The link above

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
    1. Create task related values and functions
      1. stay LssAppConfig.h Add
        1. Task priority macro lssConfigvMsgQueueTaskPRIO (5)
        2. Task stack macro lssConfigvMsgQueueTaskSIZE 512u
        3. Task initialization complete enumeration evMsgQueueTaskNum = 0x0D,
        4. Message queue external handle extern UINT32 MsgQueueTask_Handle;
      2. stay main.c Add
        1. Add task header file #include "MsgQueueAppTask.h"
        2. Add handle
          1. Task to handle UINT32 MsgQueueTask_Handle = NULL;
          2. Message queue test handle UINT32 TestAQue_Handle = NULL;
          3. Create Message Queue task function
          4. In the startup task
            1. add to uwRet = Creat_vMsgQueue_Task();, To indicate that the task was created
            2. add to uwRet = LOS_QueueCreate("Msg Queue", 20, &TestAQue_Handle, 0, 10); , To indicate the creation message
    2. Create a task file MsgQueueTask.c and MsgQueueTask.h
      1. It is mainly used for business test of message queue
      2. Write task functions void vMsgQueueTask( void )
      3. Message queue test task source file
      4. Message queue test task header file
    3. stay IPCApp.c Add two test functions to the file ( The framework needs )
      1. void IPCAppMsgQueueA(msgIpc_t *msg) function
        1. It's the sender of the message
        2. Queue test function A
      2. void IPCAppMsgQueueB(msgIpc_t *msg) function
        1. It's the sender of the message
        2. Queue test function B
      3. The header file PCApp.h Also need to do external function processing
    4. stay IPCCoreTask.c In file void msgDecode(msgIpc_t * msg) Function to add two processing commands ( The framework needs )
      1. $QA#
      2. $QB#
      3. 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
  • Queue test function A
/**
  * @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  */
}
  • Queue test function B
/**
  * @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){;}		
		}
	}
...

版权声明
本文为[Li Zhuming]所创,转载请带上原文链接,感谢