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"
44 #include <kern/proc.h>
52 * Let the CPU rest in tight busy loops
54 * User code that sits in a busy loop should call cpu_relax() every
55 * once in a while to perform system-dependent idle processing.
57 * Depending on the system configuration, this might perform different
60 * - yield the CPU to other processes
61 * - reset the watchdog timer to avoid it from triggering
62 * - scale the CPU speed down to save power (unimplemented)
63 * - let the event loop of the emulator process a few events
65 * \see proc_yield() cpu_pause()
67 INLINE void cpu_relax(void)
79 * Stop the processor until the next interrupt occurs.
81 * Pausing the CPU effectively reduces power usage, and should be used
82 * whenever the program is idle waiting for the next event to occur.
84 * To avoid deadlocking, the caller should normally check for the
85 * desired condition with interrupts disabled, and enter this function
86 * while interrupts are still disabled:
90 * while (!event_occurred)
95 * \note Some implementations of cpu_pause() may return before any interrupt
96 * has occurred. Calling code should take this possibility into account.
98 * \note This function is currently unimplemented
100 * \see cpu_relax() cpu_yield()
102 INLINE void cpu_pause(void)
104 //ASSERT_IRQ_DISABLED();
111 * Safely call cpu_pause() until the COND predicate becomes true.
113 #define CPU_PAUSE_ON(COND) ATOMIC(while (!(COND)) { cpu_pause(); })
115 #endif /* CPU_POWER_H */