下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

内核
最新资讯
FreeRTOS-Plus-TCP 现具有统一的 IPv4 和 IPv6 功能,支持多接口。
为基于 FreeRTOS 的固件实现防砖化 MCU FOTA:
宣布停止支持 FreeRTOS 202012 LTS。
FreeRTOS 网站现已提供简体中文版本
新的 FreeRTOS Long Term Support 版本现已发布。

vTaskNotifyGiveFromISR / vTaskNotifyGiveIndexedFromISR
[RTOS 任务通知 API]


task.h

 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
                              BaseType_t *pxHigherPriorityTaskWoken );

void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );

可在中断服务程序 (ISR) 中使用的 xTaskNotifyGive() 和 xTaskNotifyGiveIndexed() 的版本。 请参阅文档页面,以获取关于 API 函数 xTaskNotifyGive() 的 操作描述和必要的配置参数, 以及向后兼容性信息。

参数:
xTaskToNotify   正被通知的 RTOS 任务的句柄,且该任务的通知值 正在递增。

要获取任务句柄,请使用 xTaskCreate() 创建任务并使用 pxCreatedTask 参数,或使用返回值创建任务 xTaskCreateStatic() 并存储该值,或在 调用 xTaskGetHandle() 中使用任务的名称。

当前执行的 RTOS 任务的句柄通过以下方式 由 xTaskGetCurrentTaskHandle() API 函数返回。

uxIndexToNotify   目标任务通知值数组中的索引, 通知值将发送给该索引。

uxIndexToNotify 必须小于 configTASK_NOTIFICATION_ARRAY_ENTRIES。

xTaskNotifyGiveFromISR() 不具有此参数,并且始终 将通知发送到索引 0。

pxHigherPriorityTaskWoken   *pxHigherPriorityTaskWoken 必须初始化为 0。

如果发送通知导致任务解除阻塞,并且被阻塞任务的优先级高于 当前运行的任务,vTaskNotifyGiveFromISR() 会将 *pxHigherPriorityTaskWoken 设 xTaskNotifyFromISR() 会将 *pxHigherPriorityTaskWoken 。

如果 vTaskNotifyGiveFromISR() 将此值设置为 pdTRUE , 则应在中断退出之前请求上下文切换 。 请参阅以下示例。

pxHigherPriorityTaskWoken 为可选参数,且可 设置为 NULL。


用法示例:

[更多示例来自主 RTOS 任务通知页面]


/* This is an example of a transmit function in a generic peripheral driver. An
RTOS task calls the transmit function, then waits in the Blocked state (so not
using an CPU time) until it is notified that the transmission is complete. The
transmission is performed by a DMA, and the DMA end interrupt is used to notify
the task. */


static TaskHandle_t xTaskToNotify = NULL;

/* The peripheral driver's transmit function. */
void StartTransmission( uint8_t *pcData, size_t xDataLength )
{
/* At this point xTaskToNotify should be NULL as no transmission is in
progress. A mutex can be used to guard access to the peripheral if
necessary. */

configASSERT( xTaskToNotify == NULL );

/* Store the handle of the calling task. */
xTaskToNotify = xTaskGetCurrentTaskHandle();

/* Start the transmission - an interrupt is generated when the transmission
is complete. */

vStartTransmit( pcData, xDatalength );
}
/*-----------------------------------------------------------*/

/* The transmit end interrupt. */
void vTransmitEndISR( void )
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

/* At this point xTaskToNotify should not be NULL as a transmission was
in progress. */

configASSERT( xTaskToNotify != NULL );

/* Notify the task that the transmission is complete. */
vTaskNotifyGiveIndexedFromISR( xTaskToNotify, 0, &xHigherPriorityTaskWoken );

/* There are no transmissions in progress, so no tasks to notify. */
xTaskToNotify = NULL;

/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
should be performed to ensure the interrupt returns directly to the highest
priority task. The macro used for this purpose is dependent on the port in
use and may be called portEND_SWITCHING_ISR(). */

portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
/*-----------------------------------------------------------*/

/* The task that initiates the transmission, then enters the Blocked state (so
not consuming any CPU time) to wait for it to complete. */

void vAFunctionCalledFromATask( uint8_t ucDataToTransmit, size_t xDataLength )
{
uint32_t ulNotificationValue;
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );

/* Start the transmission by calling the function shown above. */
StartTransmission( ucDataToTransmit, xDataLength );

/* Wait for the transmission to complete. */
ulNotificationValue = ulTaskNotifyTakeIndexed( 0, pdFALSE, xMaxBlockTime );

if( ulNotificationValue == 1 )
{
/* The transmission ended as expected. */
}
else
{
/* The call to ulTaskNotifyTake() timed out. */
}
}





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