FreeRTOS queue usage

来源:互联网 发布:sql查询多表相同列名 编辑:程序博客网 时间:2024/06/05 20:38

#include "freertos/queue.h"

typedef struct fg_data {

        unsigned short v;
        unsigned short i;
        unsigned short p;
        unsigned short kwh;
} fg_data_t;
static xQueueHandle UartMsgQueue;

Initialization:
UartMsgQueue = xQueueCreate( 5 /*depth*/, 8/*element size*/);

TX:
fg_data_t fgdata_tx;
fgdata_tx.v = 1;

xQueueSend( UartMsgQueue, ( void* )&fgdata, 1000/portTICK_RATE_MS);
ARG3: if queue has no room, the function will wait for maximum time, when timeout happens and still has no room, the function returns failure, otherwise returns success.

RX:
fg_data_t fgdata_rx;
xQueueReceive( UartMsgQueue, &fgdata_rx, 1000/portTICK_RATE_MS )
ARG3: if queue has been empty, the function will wait for maximum time, when timeout happens and no data available, the function returns failure, otherwise returns the data.