The xQueueOverwrite() API Function. FreeRTOS Real Time Kernel
광고
광고
161204 Pre-release for FreeRTOS V8.x.x. See http://www.FreeRTOS.org/FreeRTOS-V9.html
for information about FreeRTOS
V9.x.x. Use http://www.FreeRTOS.org/contact to provide feedback, corrections, and check for updates.
Listing 67 shows a queue being created for use as a mailbox.
/* A mailbox can hold a fixed size data item. The size of the data item is set when the mailbox (queue) is created. In this example the mailbox is created to hold an Example_t structure. Example_t includes a time stamp to allow the data held in the mailbox to note the time at which the mailbox was last updated. The time stamp used in this example is for demonstration purposes only - a mailbox can hold any data the application writer wants, and the data does not need to include a time stamp. */ typedef struct xExampleStructure
{
TickType_t xTimeStamp;
uint32_t ulValue;
} Example_t;
/* A mailbox is a queue, so its handle is stored in a variable of type
QueueHandle_t. */
QueueHandle_t xMailbox; void vAFunction( void )
{
/* Create the queue that is going to be used as a mailbox. The queue has a
length of 1 to allow it to be used with the xQueueOverwrite() API function, which
is described below. */
xMailbox = xQueueCreate( 1, sizeof( Example_t ) );
}
Listing 67. A queue being created for use as a mailbox
The xQueueOverwrite() API Function
Like the xQueueSendToBack() API function, the xQueueOverwrite() API function sends data to a queue. Unlike xQueueSendToBack(), if the queue is already full, then xQueueOverwrite() will overwrite data that is already in the queue. xQueueOverwrite() should only be used with queues that have a length of one. That restriction avoids the need for the function’s implementation to make an arbitrary decision as to which item in the queue to overwrite, if the queue is full.
Note: Never call xQueueOverwrite() from an interrupt service routine. The interrupt-safe
version xQueueOverwriteFromISR() should be used in its place.
BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void * pvItemToQueue );
Listing 68. The xQueueOverwrite() API function prototype
144
다운로드
광고