创建两个发送队列数据任务和一个接收队列数据任务。
1、头文件声明和任务定义
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "supporting_functions.h"
static void vSenderTask( void *pvParameters );
static void vReceiverTask( void *pvParameters );
// 创建队列变量
QueueHandle_t xQueue;
typedef enum
{
eSender1,
eSender2
} DataSource_t;
// 数据结构
typedef struct
{
uint8_t ucValue;
DataSource_t eDataSource;
} Data_t;
// 要发送的队列数据
static const Data_t xStructsToSend[ 2 ] =
{
{ 100, eSender1 },
{ 200, eSender2 }
};
2、创建任务
int main( void )
{
xQueue = xQueueCreate( 3, sizeof( Data_t ) );
if( xQueue != NULL )
{
xTaskCreate( vSenderTask, "Sender1", 1000, ( void * ) &( xStructsToSend[ 0 ] ), 2, NULL );
xTaskCreate( vSenderTask, "Sender2", 1000, ( void * ) &( xStructsToSend[ 1 ] ), 2, NULL );
// 任务优先级较低,队列满时才会接收数据