xQueueSend
[队列管理]
queue.h
BaseType_t xQueueSend(
QueueHandle_t xQueue,
const void * pvItemToQueue,
TickType_t xTicksToWait
);
这是一个调用 xQueueGenericSend() 的宏。 它用于
向后兼容 FreeRTOS 的一些版本,
这些版本不包含 xQueueSendToFront() 和 xQueueSendToBack() 宏。 它
等同于 xQueueSendToBack()。
在队列中发布项目。该项目按副本排队,而不是按引用排队。不得从中断服务程序调用此函数。请参阅 xQueueSendFromISR() 以获取
可用于 ISR 的替代方案。
参数:
xQueue | 队列的句柄,数据项将发布到此队列。 |
pvItemToQueue | 指向待入队数据项的指针。创建队列时定义了队列将保留的项的大小,因此固定数量的字节将从 pvItemToQueue 复制到队列存储区域。 |
xTicksToWait | 如果队列已满,则任务应进入阻塞态等待队列上出现可用空间的最大时间。如果队列已满,并且 xTicksToWait 设置为0 ,调用将立即返回。时间在 tick 周期中定义,因此如果需要,应使用常量 portTICK_PERIOD_MS 转换为实时。
如果 INCLUDE_vTaskSuspend 设置为 “1” ,则将阻塞时间指定为 portMAX_DELAY 会导致任务无限期地阻塞(没有超时)。 |
返回:如果成功发布项目,则返回 pdTRUE,否则返回 errQUEUE_FULL。
用法示例:
struct AMessage
{
char ucMessageID;
char ucData[ 20 ];
} xMessage;
unsigned long ulVar = 10UL;
void vATask( void *pvParameters )
{
QueueHandle_t xQueue1, xQueue2;
struct AMessage *pxMessage;
/* Create a queue capable of containing 10 unsigned long values. */
xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
/* Create a queue capable of containing 10 pointers to AMessage structures.
These should be passed by pointer as they contain a lot of data. */
xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
/* ... */
if( xQueue1 != 0 )
{
/* Send an unsigned long. Wait for 10 ticks for space to become
available if necessary. */
if( xQueueSend( xQueue1,
( void * ) &ulVar,
( TickType_t ) 10 ) != pdPASS )
{
/* Failed to post the message, even after 10 ticks. */
}
}
if( xQueue2 != 0 )
{
/* Send a pointer to a struct AMessage object. Don't block if the
queue is already full. */
pxMessage = & xMessage;
xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
}
/* ... Rest of task code. */
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|