123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #include <kernel.h>
- #include <toolchain.h>
- #include <linker/sections.h>
- #include <drivers/timer/system_timer.h>
- #include <wait_q.h>
- #include <pm/pm.h>
- #include <stdbool.h>
- #include <logging/log.h>
- #include <ksched.h>
- #include <kswap.h>
- LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
- static void pm_save_idle(void)
- {
- #ifdef CONFIG_PM
- int32_t ticks = z_get_next_timeout_expiry();
- _kernel.idle = ticks;
-
- if (pm_system_suspend(ticks) == PM_STATE_ACTIVE) {
- k_cpu_idle();
- }
- #endif
- }
- void z_pm_save_idle_exit(int32_t ticks)
- {
- #ifdef CONFIG_PM
-
- pm_system_resume();
- #endif
- sys_clock_idle_exit();
- }
- void idle(void *unused1, void *unused2, void *unused3)
- {
- ARG_UNUSED(unused1);
- ARG_UNUSED(unused2);
- ARG_UNUSED(unused3);
- __ASSERT_NO_MSG(_current->base.prio >= 0);
- while (true) {
-
- if (IS_ENABLED(CONFIG_SMP) &&
- !IS_ENABLED(CONFIG_SCHED_IPI_SUPPORTED)) {
- k_busy_wait(100);
- k_yield();
- continue;
- }
-
- (void) arch_irq_lock();
- if (IS_ENABLED(CONFIG_PM)) {
- pm_save_idle();
- } else {
- k_cpu_idle();
- }
- #if !defined(CONFIG_PREEMPT_ENABLED)
- # if !defined(CONFIG_USE_SWITCH) || defined(CONFIG_SPARC)
-
- if (_kernel.ready_q.cache != _current) {
- z_swap_unlocked();
- }
- # endif
- #endif
- }
- }
|