4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2008 Bernie Innocenti <bernie@codewiz.org>
32 * \brief CPU power management functions
34 * \author Bernie Innocenti <bernie@codewiz.org>
40 #include "cfg/cfg_proc.h"
41 #include "cfg/cfg_wdt.h"
43 #include <cfg/compiler.h>
46 #include <kern/proc.h>
54 * Let the CPU rest in tight busy loops
56 * User code that sits in a busy loop should call cpu_relax() every
57 * once in a while to perform system-dependent idle processing.
59 * Depending on the system configuration, this might perform different
62 * - yield the CPU to other processes
63 * - reset the watchdog timer to avoid it from triggering
64 * - scale the CPU speed down to save power (unimplemented)
65 * - let the event loop of the emulator process a few events
67 * \see proc_yield() cpu_pause()
69 INLINE void cpu_relax(void)
73 if (proc_preemptAllowed())
83 * Stop the processor until the next interrupt occurs.
85 * Pausing the CPU effectively reduces power usage, and should be used
86 * whenever the program is idle waiting for the next event to occur.
88 * To avoid deadlocking, the caller should normally check for the
89 * desired condition with interrupts disabled, and enter this function
90 * while interrupts are still disabled:
94 * while (!event_occurred)
99 * \note Some implementations of cpu_pause() may return before any interrupt
100 * has occurred. Calling code should take this possibility into account.
102 * \note This function is currently unimplemented
104 * \see cpu_relax() cpu_yield()
106 INLINE void cpu_pause(void)
108 //ASSERT_IRQ_DISABLED();
115 * Safely call cpu_pause() until the COND predicate becomes true.
117 #define CPU_PAUSE_ON(COND) ATOMIC(while (!(COND)) { cpu_pause(); })
119 #endif /* CPU_POWER_H */