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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM