freertos - configUSE_TICKLESS_IDLE-低功耗-idel状态下不产生sys tick

 

from :  https://www.freertos.org/vTaskStepTick.html

1 系统idle 状态

the Idle task is the only task able to execute

 idle 任务是 唯一任务时,系统进入idle 状态。

 

2 configUSE_TICKLESS_IDLE

设置为 1 时,系统进入idle 状态后,关闭系统定时器(即不再产生 sys tick 中断)

 

相关实现使用如下函数

2.1 portSUPPRESS_TICKS_AND_SLEEP( xIdleTime )

当系统进入idle 状态下,调用此函数。

移植者自己实现这个函数。

这个函数需要做的事情就是

1、关闭系统定时器 ;

2、【假设 systick  timer 中断间隔是T 】 设置 另外一个低功耗定时器,在 T * xIdleTime 时间后发出中断

3、启用低功耗定时器;关闭系统定时器。

 

2.2 vTaskStepTick

void vTaskStepTick( TickType_t xTicksToJump );

 

在低功耗定时器的中断  唤醒系统后,调用这个函数。设置  系统停用 sys tick 中断后,过去的tick 数目。

 

3 示例:

 1 /* First define the portSUPPRESS_TICKS_AND_SLEEP().  The parameter is the time,
 2 in ticks, until the kernel next needs to execute. */
 3 #define portSUPPRESS_TICKS_AND_SLEEP( xIdleTime ) vApplicationSleep( xIdleTime )
 4 
 5 /* Define the function that is called by portSUPPRESS_TICKS_AND_SLEEP(). */
 6 void vApplicationSleep( TickType_t xExpectedIdleTime )
 7 {
 8 unsigned long ulLowPowerTimeBeforeSleep, ulLowPowerTimeAfterSleep;
 9 
10     /* Read the current time from a time source that will remain operational
11     while the microcontroller is in a low power state. */
12     ulLowPowerTimeBeforeSleep = ulGetExternalTime();
13 
14     /* Stop the timer that is generating the tick interrupt. */
15     prvStopTickInterruptTimer();
16 
17     /* Configure an interrupt to bring the microcontroller out of its low power
18     state at the time the kernel next needs to execute.  The interrupt must be
19     generated from a source that is remains operational when the microcontroller
20     is in a low power state. */
21     vSetWakeTimeInterrupt( xExpectedIdleTime );
22 
23     /* Enter the low power state. */
24     prvSleep();
25 
26     /* Determine how long the microcontroller was actually in a low power state
27     for, which will be less than xExpectedIdleTime if the microcontroller was
28     brought out of low power mode by an interrupt other than that configured by
29     the vSetWakeTimeInterrupt() call.  Note that the scheduler is suspended
30     before portSUPPRESS_TICKS_AND_SLEEP() is called, and resumed when
31     portSUPPRESS_TICKS_AND_SLEEP() returns.  Therefore no other tasks will
32     execute until this function completes. */
33     ulLowPowerTimeAfterSleep = ulGetExternalTime();
34 
35     /* Correct the kernels tick count to account for the time the microcontroller
36     spent in its low power state. */
37     vTaskStepTick( ulLowPowerTimeAfterSleep - ulLowPowerTimeBeforeSleep );
38 
39     /* Restart the timer that is generating the tick interrupt. */
40     prvStartTickInterruptTimer();
41 }

 

posted @ 2022-02-13 14:43  张志伟122  阅读(1019)  评论(0编辑  收藏  举报