This code shows a basic logic to perform inter-task communication using multiple queues
- GPIO2 : output ( built-in led on Devkit-V1 )
- This code is developed for ESP32 on Embedded C Language using FreeRTOS.
- FreeRTOS task don't have the provision to return values.
- That said, one can either use global variables to track changes in values but is not the most appropriate way.
- This is where "Queue" comes into picture, enabling inter-task communications.
- As the name suggests, Queues acts like a stacked list and mostly preferred in FIFO ( First In First Out ).
- There are various Queue operations available, but in this program I will cover the basic functions.
- xQueueCreate( UBaseType_t uxQueueLength, UBaseType_t uxItemSize );
- uxQueueLength --> The maximum number of items the queue can hold at any one time.
- uxItemSize --> The size, in bytes, required to hold each item in the queue.
- Example --> xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
- If created successfully, returns the handle or "NULL" otherwise.
- vQueueDelete( QueueHandle_t xQueue );
- Deletes the queue with the provided handle "xQueue".
- xQueueSend( QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait );
- xQueue --> The handle to the queue on which the item is to be posted.
- pvItemToQueue --> A pointer to the item that is to be placed on the queue.
- xTicksToWait --> The maximum amount of time the task should block waiting for space to become available on the queue, should it already be full.
- Returns "pdTRUE" if the item was successfully posted, otherwise "errQUEUE_FULL".
- *xQueueReceive( QueueHandle_t xQueue, void pvBuffer, TickType_t xTicksToWait );
- xQueue --> The handle to the queue on which the item is to be received.
- pvBuffer --> Pointer to the buffer into which the received item will be copied.
- xTicksToWait --> The maximum amount of time the task should block waiting for an item to receive should the queue be empty at the time of the call.
- Returns "pdTRUE" if an item was successfully received from the queue, otherwise "pdFALSE".