下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

内核
最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

xQueueOverwriteFromISR
[队列管理]

queue.h
BaseType_t xQueueOverwrite ( QueueHandle_t xQueue, const void * pvItemToQueue BaseType_t *pxHigherPriorityTaskWoken );

这是用于调用 xQueueGenericSendFromISR() 函数的宏。

可以用于 ISR 的 xQueueOverwrite() 版本 。 xQueueOverwriteFromISR() 与 xQueueSendToBackFromISR() 相似, 但即使队列已满,前者也会写入队列,覆盖队列中已经 存在的数据。

xQueueOverwriteFromISR() 旨在用于长度为 1 的队列, 这意味着队列要么为空,要么为满。

参数:
xQueue   接收发送数据的队列的句柄。
pvItemToQueue   指向待入队数据项的指针。队列 队列可容纳的项数在 创建队列时定义,这些项 将从 pvItemToQueue 复制到队列存储区域。
pxHigherPriorityTaskWoken   如果发送通知到队列导致某个任务解除阻塞, 且被解除阻塞的任务的优先级高于当前运行的任务, 则 xQueueOverwriteFromISR() 将把 *pxHigherPriorityTaskWoken 设置 为 pdTRUE。 如果 xQueueOverwriteFromISR() 将此值设置为 pdTRUE, 则应在中断退出之前请求上下文切换 。 请参阅所使用移植的文档的中断服务例程章节, 了解如何完成该操作。
返回:
xQueueOverwriteFromISR() 是调用 xQueueGenericSendFromISR() 的宏, 因此与 xQueueSendToFrontFromISR() 具有 相同的返回值。 不过,由于 xQueueOverwriteFromISR() 将写入队列(即使队列已满), pdPASS 是唯一可以返回的值。
用法示例:
QueueHandle_t xQueue;

void vFunction( void *pvParameters )
{
    /* Create a queue to hold one unsigned long value.  It is strongly
    recommended not to use xQueueOverwriteFromISR() on queues that can
    contain more than one value, and doing so will trigger an assertion
    if configASSERT() is defined. */
    xQueue = xQueueCreate( 1, sizeof( unsigned long ) );
}

void vAnInterruptHandler( void )
{
/* xHigherPriorityTaskWoken must be set to pdFALSE before it is used. */
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
unsigned long ulVarToSend, ulValReceived;

    /* Write the value 10 to the queue using xQueueOverwriteFromISR(). */
    ulVarToSend = 10;
    xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );

    /* The queue is full, but calling xQueueOverwriteFromISR() again will still
    pass because the value held in the queue will be overwritten with the
    new value. */
    ulVarToSend = 100;
    xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );

    /* Reading from the queue will now return 100. */

    /* ... */

    if( xHigherPrioritytaskWoken == pdTRUE )
    {
        /* Writing to the queue caused a task to unblock and the unblocked task
        has a priority higher than or equal to the priority of the currently
        executing task (the task this interrupt interrupted).  Perform a
        context switch so this interrupt returns directly to the unblocked
        task. */
        portYIELD_FROM_ISR(); /* or portEND_SWITCHING_ISR() depending on the
        port.*/
    }
}




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.