下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

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

xTimerPendFunctionCallFromISR()
[定时器 API]



timers.h

 BaseType_t xTimerPendFunctionCallFromISR(
                       PendedFunction_t xFunctionToPend,
                       void *pvParameter1,
                       uint32_t ulParameter2,
                       BaseType_t *pxHigherPriorityTaskWoken );

在应用程序中断服务程序中使用此函数, 用于将函数的执行推迟到 RTOS 守护进程任务(即定时器服务任务,因此该函数 在 timers.c 中实现,并以“Timer”为前缀)。

理想情况下,中断服务程序 (ISR) 需尽可能短, 但有时 ISR 要么需要处理很多任务, 要么需要执行非确定性任务。 在这些情况下,可使用 xTimerPendFunctionCallFromISR() 将 函数的处理推迟到 RTOS 守护进程任务。

这里提供了一种允许中断直接返回到 随后将执行挂起函数任务的机制。 使用该机制, 回调函数可在中断时间内连续执行, 就像回调在中断本身中执行一样。

可延迟到 RTOS 守护进程任务的函数必须具有以下 原型:

void vPendableFunction( void * pvParameter1, uint32_t ulParameter2 );

pvParameter1ulParameter2 供 应用程序代码使用。

INCLUDE_xTimerPendFunctionCall() 和 configUSE_TIMERS 必须同时 设置为 1,xTimerPendFunctionCallFromISR() 才可用。

参数:
xFunctionToPend   要从定时器服务/ 守护进程任务执行的函数。 函数必须符合上面所示的 PendedFunction_t 如上所示的 PendedFunction_t 原型。
pvParameter1   回调函数的第一个参数的值。 该参数为 void * 类型,可用于传递任何类型。 例如,整数类型可转换为 void *, 或者可使用 void * 指向结构体。
ulParameter2   回调函数的第二个参数的值。
pxHigherPriorityTaskWoken   如上所述,调用 xTimerPendFunctionCallFromSR() 将意味着向 RTOS 定时器守护进程任务发送一条消息。 如果 守护进程任务的优先级(该任务 使用 configTIMER_TASK_PRIORITY 设置, 位于 FreeRTOSConfig.h 中)高于 当前正在运行的任务(中断中断的任务), 则需在 xTimerPendFunctionCallFromISR() 中 将 *pxHigherPriorityTaskWoken 设置为 pdTRUE, 表示应在中断退出之前请求上下文切换。 因此 必须将 *pxHigherPriorityTaskWoken 初始化为 pdFALSE。 请参阅 下面的代码示例。
返回:
如果消息成功发送到 RTOS 定时器守护进程任务, 则返回 pdPASS,否则返回 pdFALSE。
用法示例:
/* The callback function that will execute in the context of the daemon task.
Note callback functions must all use this same prototype. */
void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
{
BaseType_t xInterfaceToService;

    /* The interface that requires servicing is passed in the second
    parameter.  The first parameter is not used in this case. */
    xInterfaceToService = ( BaseType_t ) ulParameter2;

    /* ...Perform the processing here... */
}

/* An ISR that receives data packets from multiple interfaces */
void vAnISR( void )
{
BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;

    /* Query the hardware to determine which interface needs processing. */
    xInterfaceToService = prvCheckInterfaces();

    /* The actual processing is to be deferred to a task.  Request the
    vProcessInterface() callback function is executed, passing in the
    number of the interface that needs processing.  The interface to
    service is passed in the second parameter.  The first parameter is
    not used in this case. */
    xHigherPriorityTaskWoken = pdFALSE;
    xTimerPendFunctionCallFromISR( vProcessInterface,
                               NULL,
                               ( uint32_t ) xInterfaceToService,
                               &xHigherPriorityTaskWoken );

    /* If xHigherPriorityTaskWoken is now set to pdTRUE then a context
    switch should be requested.  The macro used is port specific and will
    be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
    the documentation page for the port being used. */
    portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}





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