xQueueSendFromISR
[队列管理]
queue.h
BaseType_t xQueueSendFromISR
(
QueueHandle_t xQueue,
const void *pvItemToQueue,
BaseType_t *pxHigherPriorityTaskWoken
);
这是用于调用 xQueueGenericSendFromISR() 的宏。 加入此宏可
向后兼容不包括 xQueueSendToBackFromISR() 和 xQueueSendToFrontFromISR() 宏的 FreeRTOS
版本
。
将项目发布到队列尾部。在中断服务程序中使用此函数是安全的。
数据项通过复制而非引用入队,因此最好只将较小的项放入队列,
特别是从 ISR 调用时。在大多数情况下,最好存储一个指向正在排队的数据项的指针。
- 参数:
-
xQueue | 队列的句柄,数据项将发布到此队列。 |
pvItemToQueue | 指向待入队数据项的指针。创建队列时定义了队列将保留的项的大小,因此固定数量的字节将从 pvItemToQueue 复制到队列存储区域。 |
pxHigherPriorityTaskWoken | 如果发送到队列导致任务解除阻塞,且解除阻塞的任务的优先级高于当前运行的任务,则xQueueSendFromISR() 会将 *pxHigherPriorityTaskWoken 设置为 pdTRUE。 如果 xQueueSendFromISR() 将此值设置为 pdTRUE,则应在中断退出前请求上下文切换。 从 FreeRTOSV7.3.0 开始,pxHigherPriorityTaskWoken 是一个可选参数,可设置为 NULL。 |
- 返回:
- 如果将数据成功发送至队列,则返回 pdTRUE,否则返回 errQUEUE_FULL。
缓冲 IO(每次调用 ISR 可以获取多个值)的用法示例:
void vBufferISR( void )
{
char cIn;
BaseType_t xHigherPriorityTaskWoken;
/* We have not woken a task at the start of the ISR. */
xHigherPriorityTaskWoken = pdFALSE;
/* Loop until the buffer is empty. */
do
{
/* Obtain a byte from the buffer. */
cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
/* Post the byte. */
xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
} while( portINPUT_BYTE( BUFFER_COUNT ) );
/* Now the buffer is empty we can switch context if necessary. */
if( xHigherPriorityTaskWoken )
{
/* Actual macro used here is port specific. */
taskYIELD_FROM_ISR ();
}
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|