版本 e7e9fa6a56e2ed1e6aa678dfa6bbf9e46948d725
Changes from beginning to e7e9fa6a56e2ed1e6aa678dfa6bbf9e46948d725
---
title: ChibiOS/RT idle thread
categories: embedded, arm, stm32, stm32f429
toc: yes
...
idle thread
==============
| idle thread 是一個 CPU 實現 power saving 的機制
| 在 ChibiOS/RT 中, idle thread 的優先度被設為最低,意即只要有其他的 Thread 在跑, idle thread 就不可能被執行到
|
|
| In ChibiOS-RT-Community / os / kernel / include / chsys.h
.. code-block:: c
#if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__)
/**
* @brief Idle thread working area.
*/
WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE);
/**
* @brief This function implements the idle thread infinite loop.
* @details The function puts the processor in the lowest power mode capable
* to serve interrupts.<br>
* The priority is internally set to the minimum system value so
* that this thread is executed only if there are no other ready
* threads in the system.
*
* @param[in] p the thread parameter, unused in this scenario
*/
void _idle_thread(void *p) {
(void)p;
chRegSetThreadName("idle");
while (TRUE) {
port_wait_for_interrupt(); //空函式
IDLE_LOOP_HOOK();
}
}
| 在chSysInit()函式的最後, 建立了 idle thread
|
.. code-block:: c
#if !CH_NO_IDLE_THREAD
/* This thread has the lowest priority in the system, its role is just to
serve interrupts in its context while keeping the lowest energy saving
mode compatible with the system status.*/
chThdCreateStatic(_idle_thread_wa, sizeof(_idle_thread_wa), IDLEPRIO,
(tfunc_t)_idle_thread, NULL);
#endif