/[avr-libc]/avr-libc/include/avr/sleep.h
ViewVC logotype

Contents of /avr-libc/include/avr/sleep.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Tue Jan 21 06:16:56 2003 UTC (21 years, 3 months ago) by troth
Branch: MAIN
Changes since 1.4: +41 -5 lines
File MIME type: text/plain
* configure.in (AM_INIT_AUTOMAKE): Bump version.
* doc/TODO: Remove note about sleep.h.
* include/avr/sleep.h: Make it work with any device (mostly).

1 /* Copyright (c) 2002, Theodore A. Roth
2 All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 POSSIBILITY OF SUCH DAMAGE. */
25
26 /* $Id: sleep.h,v 1.4 2003/01/13 18:24:47 troth Exp $ */
27
28 #ifndef _AVR_SLEEP_H_
29 #define _AVR_SLEEP_H_ 1
30
31 #include <avr/io.h>
32
33 /* Figure out which type of sleep mode the selected device uses (1, 2 or 3
34 bits) */
35
36 #if defined(SM) && ! defined(SM0) && ! defined(SM1) && ! defined(SM2)
37 # define _SLEEP_TYPE 1
38 #elif ! defined(SM) && defined(SM0) && defined(SM1) && ! defined(SM2)
39 # define _SLEEP_TYPE 2
40 #elif ! defined(SM) && defined(SM0) && defined(SM1) && defined(SM2)
41 # define _SLEEP_TYPE 3
42 #endif
43
44 /** \defgroup avr_sleep Power Management and Sleep Modes
45
46 \code #include <avr/sleep.h>\endcode
47
48 Use of the \c SLEEP instruction can allow your application to reduce it's
49 power comsumption considerably. AVR devices can be put into different
50 sleep modes by changing the \c SMn bits of the \c MCU Control Register (
51 \c MCUCR ). Refer to the datasheet for the details relating to the device
52 you are using. */
53
54 /* Mask of all the sleep mode bits. */
55
56 #if _SLEEP_TYPE == 1
57 # define _SLEEP_MODE_MASK _BV(SM)
58 #elif _SLEEP_TYPE == 2
59 # define _SLEEP_MODE_MASK (_BV(SM0) | _BV(SM1))
60 #elif _SLEEP_TYPE == 3
61 # define _SLEEP_MODE_MASK (_BV(SM0) | _BV(SM1) | _BV(SM2))
62 #else
63 # error "No SLEEP mode defined for device."
64 #endif
65
66 /** \name Sleep Modes
67
68 \note Some of these modes are not available on all devices. See the
69 datasheet for target device for the available sleep modes. */
70
71 /* @{ */
72
73 /** \ingroup avr_sleep
74 \def SLEEP_MODE_IDLE
75 Idle mode. */
76 #define SLEEP_MODE_IDLE 0
77
78 #if _SLEEP_TYPE == 1
79
80 # define SLEEP_MODE_PWR_DOWN _BV(SM)
81
82 #elif _SLEEP_TYPE == 2
83
84 # define SLEEP_MODE_PWR_DOWN _BV(SM1)
85 # define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
86
87 #else /* _SLEEP_TYPE == 3 */
88
89 /** \ingroup avr_sleep
90 \def SLEEP_MODE_ADC
91 ADC Noise Reduction Mode. */
92 #define SLEEP_MODE_ADC _BV(SM0)
93
94 /** \ingroup avr_sleep
95 \def SLEEP_MODE_PWR_DOWN
96 Power Down Mode. */
97 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
98
99 /** \ingroup avr_sleep
100 \def SLEEP_MODE_PWR_SAVE
101 Power Save Mode. */
102 #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
103
104 /** \ingroup avr_sleep
105 \def SLEEP_MODE_STANDBY
106 Standby Mode. */
107 #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
108
109 /** \ingroup avr_sleep
110 \def SLEEP_MODE_EXT_STANDBY
111 Extended Standby Mode. */
112 #define SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2))
113
114 #endif /* _SLEEP_TYPE == 3 */
115
116 /* @} */
117
118 /** \name Sleep Functions */
119
120 /* @{ */
121
122 /** \ingroup avr_sleep
123
124 Set the bits in the \c MCUCR to select a sleep mode. */
125
126 #if defined(DOXYGEN)
127 extern void set_sleep_mode (uint8_t mode);
128 #else
129 # if defined (SMCR)
130 # define set_sleep_mode(mode) (SMCR = ((SMCR & ~_SLEEP_MODE_MASK) | (mode)))
131 # else
132 # define set_sleep_mode(mode) (MCUCR = ((MCUCR & ~_SLEEP_MODE_MASK) | (mode)))
133 # endif
134 #endif
135
136 /** \ingroup avr_sleep
137
138 Put the device in sleep mode. How the device is brought out of sleep mode
139 depends on the specific mode selected with the set_sleep_mode() function.
140 See the data sheet for your device for more details. */
141
142 #if defined(DOXYGEN)
143 extern void sleep_mode (void);
144 #else
145 #define sleep_mode() \
146 { \
147 MCUCR |= _BV(SE); \
148 __asm__ __volatile__ ("sleep" "\n\t" :: ); \
149 MCUCR &= ~_BV(SE); \
150 }
151 #endif
152
153 /*@}*/
154
155 #endif /* _AVR_SLEEP_H_ */

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26