下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

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

xTimerChangePeriodFromISR
[定时器 API ]

timers.h
 BaseType_t xTimerChangePeriodFromISR
           (
              TimerHandle_t xTimer,
              TickType_t xNewPeriod,
              BaseType_t *pxHigherPriorityTaskWoken
           );

可从中断服务例程调用的 xTimerChangePeriod() 的版本。

参数:
xTimer   其周期将改变的定时器的句柄。
xNewPeriod   xTimer 的新周期。定时器周期 在 tick 周期中指定,因此常量 portTICK_PERIOD_MS 可用于转换 已指定的时间(以毫秒为单位)。 例如,如果定时器必须 在100个 tick 后过期,则 xNewPeriod 应设置为100。 或者, 如果定时器必须在500 毫秒后过期,则 xNewPeriod 可以设置为 (500/portTICK_PERIOD_MS) ,前提是 configTICK_RATE_HZ 小于 或等于 1000。定时器周期必须大于 0。
pxHigherPriorityTaskWoken    定时器服务/守护进程任务大部分时间 都处于阻塞状态,等待消息到达定时器 命令队列。 调用 xTimerChangePeriodFromISR() 会将消息写入 定时器命令队列,因此有可能将定时器服务/ 守护进程任务转换为非阻塞状态。 如果调用 xTimerChangePeriodFromISR() 导致定时器服务/守护进程任务退出阻塞状态,并且 定时器服务/守护进程任务的优先级等于或大于 当前正在执行任务(被中断的任务) ,则 *pxHigherPriorityTaskWoken 将获得在 xTimerChangePeriodFromISR() 函数内部 设置为 pdTRUE 。 如果 xTimerChangePeriodFromISR() 将此值设置为 pdTRUE ,则应在中断退出前执行上下文切换 。
返回:
如果更改定时器周期的命令无法发送到定时器命令队列, 则返回 pdFAIL 。 如果命令已成功发送到定时器命令队列, 则返回 pdPASS 。 实际处理命令的时间 将取决于定时服务/守护进程任务相对于系统中的其他任务的 优先级。 定时服务/守护进程任务 优先级由 configTIMER_TASK_PRIORITY 配置常量设置。
用法示例:

/* This scenario assumes xTimer has already been created and started.  When
an interrupt occurs, the period of xTimer should be changed to 500ms. */

/* The interrupt service routine that changes the period of xTimer. */
void vAnExampleInterruptServiceRoutine( void )
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    /* The interrupt has occurred - change the period of xTimer to 500ms.
    xHigherPriorityTaskWoken was set to pdFALSE where it was defined
    (within this function).  As this is an interrupt service routine, only
    FreeRTOS API functions that end in "FromISR" can be used. */
    if( xTimerChangePeriodFromISR( xTimer,
                                   pdMS_TO_TICKS( 500 ),
                                   &xHigherPriorityTaskWoken ) != pdPASS )
    {
        /* The command to change the timers period was not executed
        successfully.  Take appropriate action here. */
    }

    /* If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
    should be performed.  The syntax required to perform a context switch
    from inside an ISR varies from port to port, and from compiler to
    compiler.  Inspect the demos for the port you are using to find the
    actual syntax required. */
    if( xHigherPriorityTaskWoken != pdFALSE )
    {
        /* Call the interrupt safe yield function here (actual function
        depends on the FreeRTOS port being used). */
    }
}





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