AVR-LibC  2.3.0git
Standard C library for AVR-GCC
 

AVR-LibC Documen­tation

AVR-LibC Development Pages

Main Page

User Manual

Library Refe­rence

FAQ

Example Projects

File List

Index

Loading...
Searching...
No Matches
power.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2007, 2008 Eric B. Weddington
2 Copyright (c) 2011 Frédéric Nadeau
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in
12 the documentation and/or other materials provided with the
13 distribution.
14 * Neither the name of the copyright holders nor the names of
15 contributors may be used to endorse or promote products derived
16 from this software without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 POSSIBILITY OF SUCH DAMAGE. */
29
30#ifndef _AVR_POWER_H_
31#define _AVR_POWER_H_ 1
32
33#include <avr/io.h>
34#include <stdint.h>
35#include <bits/attribs.h>
36
37/** \file */
38/** \defgroup avr_power <avr/power.h>: Power Reduction Management
39
40\code #include <avr/power.h>\endcode
41
42Many AVRs contain a Power Reduction Register (PRR) or Registers (PRRx) that
43allow you to reduce power consumption by disabling or enabling various on-board
44peripherals as needed. Some devices have the XTAL Divide Control Register
45(XDIV) which offer similar functionality as System Clock Prescale
46Register (CLKPR).
47
48There are many macros in this header file that provide an easy interface
49to enable or disable on-board peripherals to reduce power. See the table below.
50
51\note Not all AVR devices have a Power Reduction Register (for example
52the ATmega8). On those devices without a Power Reduction Register, the
53power reduction macros are not available..
54
55\note Not all AVR devices contain the same peripherals (for example, the LCD
56interface), or they will be named differently (for example, USART and
57USART0). Please consult your device's datasheet, or the header file, to
58find out which macros are applicable to your device.
59
60\note For device using the XTAL Divide Control Register (XDIV), when prescaler
61is used, Timer/Counter0 can only be used in asynchronous mode. Keep in mind
62that Timer/Counter0 source shall be less than ¼th of peripheral clock.
63Therefore, when using a typical 32.768 kHz crystal, one shall not scale
64the clock below 131.072 kHz.
65
66\anchor avr_powermacros
67<small>
68<table>
69 <caption>Power Macros</caption>
70 <tr>
71 <th>Power Macro
72 <th>Description
73 </tr>
74 <tr>
75 <td>\c power_aca_disable()</td>
76 <td>Disable the Analog Comparator on PortA</td>
77 </tr>
78 <tr>
79 <td>\c power_aca_enable()</td>
80 <td>Enable the Analog Comparator on PortA</td>
81 </tr>
82 <tr>
83 <td>\c power_adc_enable()</td>
84 <td>Enable the Analog to Digital Converter module</td>
85 </tr>
86 <tr>
87 <td>\c power_adc_disable()</td>
88 <td>Disable the Analog to Digital Converter module</td>
89 </tr>
90 <tr>
91 <td>\c power_adca_disable()</td>
92 <td>Disable the Analog to Digital Converter module on PortA</td>
93 </tr>
94 <tr>
95 <td>\c power_adca_enable()</td>
96 <td>Enable the Analog to Digital Converter module on PortA</td>
97 </tr>
98 <tr>
99 <td>\c power_evsys_disable()</td>
100 <td>Disable the EVSYS module</td>
101 </tr>
102 <tr>
103 <td>\c power_evsys_enable()</td>
104 <td>Enable the EVSYS module</td>
105 </tr>
106 <tr>
107 <td>\c power_hiresc_disable()</td>
108 <td>Disable the HIRES module on PortC</td>
109 </tr>
110 <tr>
111 <td>\c power_hiresc_enable()</td>
112 <td>Enable the HIRES module on PortC</td>
113 </tr>
114 <tr>
115 <td>\c power_lcd_enable()</td>
116 <td>Enable the LCD module</td>
117 </tr>
118 <tr>
119 <td>\c power_lcd_disable()</td>
120 <td>Disable the LCD module</td>
121 </tr>
122 <tr>
123 <td>\c power_pga_enable()</td>
124 <td>Enable the Programmable Gain Amplifier module</td>
125 </tr>
126 <tr>
127 <td>\c power_pga_disable()</td>
128 <td>Disable the Programmable Gain Amplifier module</td>
129 </tr>
130 <tr>
131 <td>\c power_pscr_enable()</td>
132 <td>Enable the Reduced Power Stage Controller module</td>
133 </tr>
134 <tr>
135 <td>\c power_pscr_disable()</td>
136 <td>Disable the Reduced Power Stage Controller module</td>
137 </tr>
138 <tr>
139 <td>\c power_psc0_enable()</td>
140 <td>Enable the Power Stage Controller 0 module</td>
141 </tr>
142 <tr>
143 <td>\c power_psc0_disable()</td>
144 <td>Disable the Power Stage Controller 0 module</td>
145 </tr>
146 <tr>
147 <td>\c power_psc1_enable()</td>
148 <td>Enable the Power Stage Controller 1 module</td>
149 </tr>
150 <tr>
151 <td>\c power_psc1_disable()</td>
152 <td>Disable the Power Stage Controller 1 module</td>
153 </tr>
154 <tr>
155 <td>\c power_psc2_enable()</td>
156 <td>Enable the Power Stage Controller 2 module</td>
157 </tr>
158 <tr>
159 <td>\c power_psc2_disable()</td>
160 <td>Disable the Power Stage Controller 2 module</td>
161 </tr>
162 <tr>
163 <td>\c power_ram0_enable()</td>
164 <td>Enable the SRAM block 0</td>
165 </tr>
166 <tr>
167 <td>\c power_ram0_disable()</td>
168 <td>Disable the SRAM block 0</td>
169 </tr>
170 <tr>
171 <td>\c power_ram1_enable()</td>
172 <td>Enable the SRAM block 1</td>
173 </tr>
174 <tr>
175 <td>\c power_ram1_disable()</td>
176 <td>Disable the SRAM block 1</td>
177 </tr>
178 <tr>
179 <td>\c power_ram2_enable()</td>
180 <td>Enable the SRAM block 2</td>
181 </tr>
182 <tr>
183 <td>\c power_ram2_disable()</td>
184 <td>Disable the SRAM block 2</td>
185 </tr>
186 <tr>
187 <td>\c power_ram3_enable()</td>
188 <td>Enable the SRAM block 3</td>
189 </tr>
190 <tr>
191 <td>\c power_ram3_disable()</td>
192 <td>Disable the SRAM block 3</td>
193 </tr>
194 <tr>
195 <td>\c power_rtc_disable()</td>
196 <td>Disable the RTC module</td>
197 </tr>
198 <tr>
199 <td>\c power_rtc_enable()</td>
200 <td>Enable the RTC module</td>
201 </tr>
202 <tr>
203 <td>\c power_spi_enable()</td>
204 <td>Enable the Serial Peripheral Interface module</td>
205 </tr>
206 <tr>
207 <td>\c power_spi_disable()</td>
208 <td>Disable the Serial Peripheral Interface module</td>
209 </tr>
210 <tr>
211 <td>\c power_spic_disable()</td>
212 <td>Disable the SPI module on PortC</td>
213 </tr>
214 <tr>
215 <td>\c power_spic_enable()</td>
216 <td>Enable the SPI module on PortC</td>
217 </tr>
218 <tr>
219 <td>\c power_spid_disable()</td>
220 <td>Disable the SPI module on PortD</td>
221 </tr>
222 <tr>
223 <td>\c power_spid_enable()</td>
224 <td>Enable the SPI module on PortD</td>
225 </tr>
226 <tr>
227 <td>\c power_tc0c_disable()</td>
228 <td>Disable the TC0 module on PortC</td>
229 </tr>
230 <tr>
231 <td>\c power_tc0c_enable()</td>
232 <td>Enable the TC0 module on PortC</td>
233 </tr>
234 <tr>
235 <td>\c power_tc0d_disable()</td>
236 <td>Disable the TC0 module on PortD</td>
237 </tr>
238 <tr>
239 <td>\c power_tc0d_enable()</td>
240 <td>Enable the TC0 module on PortD</td>
241 </tr>
242 <tr>
243 <td>\c power_tc0e_disable()</td>
244 <td>Disable the TC0 module on PortE</td>
245 </tr>
246 <tr>
247 <td>\c power_tc0e_enable()</td>
248 <td>Enable the TC0 module on PortE</td>
249 </tr>
250 <tr>
251 <td>\c power_tc0f_disable()</td>
252 <td>Disable the TC0 module on PortF</td>
253 </tr>
254 <tr>
255 <td>\c power_tc0f_enable()</td>
256 <td>Enable the TC0 module on PortF</td>
257 </tr>
258 <tr>
259 <td>\c power_tc1c_disable()</td>
260 <td>Disable the TC1 module on PortC</td>
261 </tr>
262 <tr>
263 <td>\c power_tc1c_enable()</td>
264 <td>Enable the TC1 module on PortC</td>
265 </tr>
266 <tr>
267 <td>\c power_twic_disable()</td>
268 <td>Disable the Two Wire Interface module on PortC</td>
269 </tr>
270 <tr>
271 <td>\c power_twic_enable()</td>
272 <td>Enable the Two Wire Interface module on PortC</td>
273 </tr>
274 <tr>
275 <td>\c power_twie_disable()</td>
276 <td>Disable the Two Wire Interface module on PortE</td>
277 </tr>
278 <tr>
279 <td>\c power_twie_enable()</td>
280 <td>Enable the Two Wire Interface module on PortE</td>
281 </tr>
282 <tr>
283 <td>\c power_timer0_enable()</td>
284 <td>Enable the Timer 0 module</td>
285 </tr>
286 <tr>
287 <td>\c power_timer0_disable()</td>
288 <td>Disable the Timer 0 module</td>
289 </tr>
290 <tr>
291 <td>\c power_timer1_enable()</td>
292 <td>Enable the Timer 1 module</td>
293 </tr>
294 <tr>
295 <td>\c power_timer1_disable()</td>
296 <td>Disable the Timer 1 module</td>
297 </tr>
298 <tr>
299 <td>\c power_timer2_enable()</td>
300 <td>Enable the Timer 2 module</td>
301 </tr>
302 <tr>
303 <td>\c power_timer2_disable()</td>
304 <td>Disable the Timer 2 module</td>
305 </tr>
306 <tr>
307 <td>\c power_timer3_enable()</td>
308 <td>Enable the Timer 3 module</td>
309 </tr>
310 <tr>
311 <td>\c power_timer3_disable()</td>
312 <td>Disable the Timer 3 module</td>
313 </tr>
314 <tr>
315 <td>\c power_timer4_enable()</td>
316 <td>Enable the Timer 4 module</td>
317 </tr>
318 <tr>
319 <td>\c power_timer4_disable()</td>
320 <td>Disable the Timer 4 module</td>
321 </tr>
322 <tr>
323 <td>\c power_timer5_enable()</td>
324 <td>Enable the Timer 5 module</td>
325 </tr>
326 <tr>
327 <td>\c power_timer5_disable()</td>
328 <td>Disable the Timer 5 module</td>
329 </tr>
330 <tr>
331 <td>\c power_twi_enable()</td>
332 <td>Enable the Two Wire Interface module</td>
333 </tr>
334 <tr>
335 <td>\c power_twi_disable()</td>
336 <td>Disable the Two Wire Interface module</td>
337 </tr>
338 <tr>
339 <td>\c power_usart_enable()</td>
340 <td>Enable the USART module</td>
341 </tr>
342 <tr>
343 <td>\c power_usart_disable()</td>
344 <td>Disable the USART module</td>
345 </tr>
346 <tr>
347 <td>\c power_usart0_enable()</td>
348 <td>Enable the USART 0 module</td>
349 </tr>
350 <tr>
351 <td>\c power_usart0_disable()</td>
352 <td>Disable the USART 0 module</td>
353 </tr>
354 <tr>
355 <td>\c power_usart1_enable()</td>
356 <td>Enable the USART 1 module</td>
357 </tr>
358 <tr>
359 <td>\c power_usart1_disable()</td>
360 <td>Disable the USART 1 module</td>
361 </tr>
362 <tr>
363 <td>\c power_usart2_enable()</td>
364 <td>Enable the USART 2 module</td>
365 </tr>
366 <tr>
367 <td>\c power_usart2_disable()</td>
368 <td>Disable the USART 2 module</td>
369 </tr>
370 <tr>
371 <td>\c power_usart3_enable()</td>
372 <td>Enable the USART 3 module</td>
373 </tr>
374 <tr>
375 <td>\c power_usart3_disable()</td>
376 <td>Disable the USART 3 module</td>
377 </tr>
378 <tr>
379 <td>\c power_usartc0_disable()</td>
380 <td> Disable the USART0 module on PortC</td>
381 </tr>
382 <tr>
383 <td>\c power_usartc0_enable()</td>
384 <td> Enable the USART0 module on PortC</td>
385 </tr>
386 <tr>
387 <td>\c power_usartd0_disable()</td>
388 <td> Disable the USART0 module on PortD</td>
389 </tr>
390 <tr>
391 <td>\c power_usartd0_enable()</td>
392 <td> Enable the USART0 module on PortD</td>
393 </tr>
394 <tr>
395 <td>\c power_usarte0_disable()</td>
396 <td> Disable the USART0 module on PortE</td>
397 </tr>
398 <tr>
399 <td>\c power_usarte0_enable()</td>
400 <td> Enable the USART0 module on PortE</td>
401 </tr>
402 <tr>
403 <td>\c power_usartf0_disable()</td>
404 <td> Disable the USART0 module on PortF</td>
405 </tr>
406 <tr>
407 <td>\c power_usartf0_enable()</td>
408 <td> Enable the USART0 module on PortF</td>
409 </tr>
410 <tr>
411 <td>\c power_usb_enable()</td>
412 <td>Enable the USB module</td>
413 </tr>
414 <tr>
415 <td>\c power_usb_disable()</td>
416 <td>Disable the USB module</td>
417 </tr>
418 <tr>
419 <td>\c power_usi_enable()</td>
420 <td>Enable the Universal Serial Interface module</td>
421 </tr>
422 <tr>
423 <td>\c power_usi_disable()</td>
424 <td>Disable the Universal Serial Interface module</td>
425 </tr>
426 <tr>
427 <td>\c power_vadc_enable()</td>
428 <td>Enable the Voltage ADC module</td>
429 </tr>
430 <tr>
431 <td>\c power_vadc_disable()</td>
432 <td>Disable the Voltage ADC module</td>
433 </tr>
434 <tr>
435 <td>\c power_all_enable()</td>
436 <td>Enable all modules</td>
437 </tr>
438 <tr>
439 <td>\c power_all_disable()</td>
440 <td>Disable all modules</td>
441 </tr>
442</table>
443</small>
444*/
445
446#if defined(__AVR_HAVE_PRR_PRADC)
447#define power_adc_enable() (PRR &= (uint8_t)~(1 << PRADC))
448#define power_adc_disable() (PRR |= (uint8_t)(1 << PRADC))
449#endif
450
451#if defined(__AVR_HAVE_PRR_PRCAN)
452#define power_can_enable() (PRR &= (uint8_t)~(1 << PRCAN))
453#define power_can_disable() (PRR |= (uint8_t)(1 << PRCAN))
454#endif
455
456#if defined(__AVR_HAVE_PRR_PRLCD)
457#define power_lcd_enable() (PRR &= (uint8_t)~(1 << PRLCD))
458#define power_lcd_disable() (PRR |= (uint8_t)(1 << PRLCD))
459#endif
460
461#if defined(__AVR_HAVE_PRR_PRLIN)
462#define power_lin_enable() (PRR &= (uint8_t)~(1 << PRLIN))
463#define power_lin_disable() (PRR |= (uint8_t)(1 << PRLIN))
464#endif
465
466#if defined(__AVR_HAVE_PRR_PRPSC)
467#define power_psc_enable() (PRR &= (uint8_t)~(1 << PRPSC))
468#define power_psc_disable() (PRR |= (uint8_t)(1 << PRPSC))
469#endif
470
471#if defined(__AVR_HAVE_PRR_PRPSC0)
472#define power_psc0_enable() (PRR &= (uint8_t)~(1 << PRPSC0))
473#define power_psc0_disable() (PRR |= (uint8_t)(1 << PRPSC0))
474#endif
475
476#if defined(__AVR_HAVE_PRR_PRPSC1)
477#define power_psc1_enable() (PRR &= (uint8_t)~(1 << PRPSC1))
478#define power_psc1_disable() (PRR |= (uint8_t)(1 << PRPSC1))
479#endif
480
481#if defined(__AVR_HAVE_PRR_PRPSC2)
482#define power_psc2_enable() (PRR &= (uint8_t)~(1 << PRPSC2))
483#define power_psc2_disable() (PRR |= (uint8_t)(1 << PRPSC2))
484#endif
485
486#if defined(__AVR_HAVE_PRR_PRPSCR)
487#define power_pscr_enable() (PRR &= (uint8_t)~(1 << PRPSCR))
488#define power_pscr_disable() (PRR |= (uint8_t)(1 << PRPSCR))
489#endif
490
491#if defined(__AVR_HAVE_PRR_PRSPI)
492#define power_spi_enable() (PRR &= (uint8_t)~(1 << PRSPI))
493#define power_spi_disable() (PRR |= (uint8_t)(1 << PRSPI))
494#endif
495
496#if defined(__AVR_HAVE_PRR_PRTIM0)
497#define power_timer0_enable() (PRR &= (uint8_t)~(1 << PRTIM0))
498#define power_timer0_disable() (PRR |= (uint8_t)(1 << PRTIM0))
499#endif
500
501#if defined(__AVR_HAVE_PRR_PRTIM1)
502#define power_timer1_enable() (PRR &= (uint8_t)~(1 << PRTIM1))
503#define power_timer1_disable() (PRR |= (uint8_t)(1 << PRTIM1))
504#endif
505
506#if defined(__AVR_HAVE_PRR_PRTIM2)
507#define power_timer2_enable() (PRR &= (uint8_t)~(1 << PRTIM2))
508#define power_timer2_disable() (PRR |= (uint8_t)(1 << PRTIM2))
509#endif
510
511#if defined(__AVR_HAVE_PRR_PRTWI)
512#define power_twi_enable() (PRR &= (uint8_t)~(1 << PRTWI))
513#define power_twi_disable() (PRR |= (uint8_t)(1 << PRTWI))
514#endif
515
516#if defined(__AVR_HAVE_PRR_PRUSART)
517#define power_usart_enable() (PRR &= (uint8_t)~(1 << PRUSART))
518#define power_usart_disable() (PRR |= (uint8_t)(1 << PRUSART))
519#endif
520
521#if defined(__AVR_HAVE_PRR_PRUSART0)
522#define power_usart0_enable() (PRR &= (uint8_t)~(1 << PRUSART0))
523#define power_usart0_disable() (PRR |= (uint8_t)(1 << PRUSART0))
524#endif
525
526#if defined(__AVR_HAVE_PRR_PRUSART1)
527#define power_usart1_enable() (PRR &= (uint8_t)~(1 << PRUSART1))
528#define power_usart1_disable() (PRR |= (uint8_t)(1 << PRUSART1))
529#endif
530
531#if defined(__AVR_HAVE_PRR_PRUSI)
532#define power_usi_enable() (PRR &= (uint8_t)~(1 << PRUSI))
533#define power_usi_disable() (PRR |= (uint8_t)(1 << PRUSI))
534#endif
535
536#if defined(__AVR_HAVE_PRR0_PRADC)
537#define power_adc_enable() (PRR0 &= (uint8_t)~(1 << PRADC))
538#define power_adc_disable() (PRR0 |= (uint8_t)(1 << PRADC))
539#endif
540
541#if defined(__AVR_HAVE_PRR0_PRC0)
542#define power_clock_output_enable() (PRR0 &= (uint8_t)~(1 << PRCO))
543#define power_clock_output_disable() (PRR0 |= (uint8_t)(1 << PRCO))
544#endif
545
546#if defined(__AVR_HAVE_PRR0_PRCRC)
547#define power_crc_enable() (PRR0 &= (uint8_t)~(1 << PRCRC))
548#define power_crc_disable() (PRR0 |= (uint8_t)(1 << PRCRC))
549#endif
550
551#if defined(__AVR_HAVE_PRR0_PRCU)
552#define power_crypto_enable() (PRR0 &= (uint8_t)~(1 << PRCU))
553#define power_crypto_disable() (PRR0 |= (uint8_t)(1 << PRCU))
554#endif
555
556#if defined(__AVR_HAVE_PRR0_PRDS)
557#define power_irdriver_enable() (PRR0 &= (uint8_t)~(1 << PRDS))
558#define power_irdriver_disable() (PRR0 |= (uint8_t)(1 << PRDS))
559#endif
560
561#if defined(__AVR_HAVE_PRR0_PRLFR)
562#define power_lfreceiver_enable() (PRR0 &= (uint8_t)~(1 << PRLFR))
563#define power_lfreceiver_disable() (PRR0 |= (uint8_t)(1 << PRLFR))
564#endif
565
566#if defined(__AVR_HAVE_PRR0_PRLFRS)
567#define power_lfrs_enable() (PRR0 &= (uint8_t)~(1 << PRLFRS))
568#define power_lfrs_disable() (PRR0 |= (uint8_t)(1 << PRLFRS))
569#endif
570
571#if defined(__AVR_HAVE_PRR0_PRLIN)
572#define power_lin_enable() (PRR0 &= (uint8_t)~(1 << PRLIN))
573#define power_lin_disable() (PRR0 |= (uint8_t)(1 << PRLIN))
574#endif
575
576#if defined(__AVR_HAVE_PRR0_PRPGA)
577#define power_pga_enable() (PRR0 &= (uint8_t)~(1 << PRPGA))
578#define power_pga_disable() (PRR0 |= (uint8_t)(1 << PRPGA))
579#endif
580
581#if defined(__AVR_HAVE_PRR0_PRRXDC)
582#define power_receive_dsp_control_enable() (PRR0 &= (uint8_t)~(1 << PRRXDC))
583#define power_receive_dsp_control_disable() (PRR0 |= (uint8_t)(1 << PRRXDC))
584#endif
585
586#if defined(__AVR_HAVE_PRR0_PRSPI)
587#define power_spi_enable() (PRR0 &= (uint8_t)~(1 << PRSPI))
588#define power_spi_disable() (PRR0 |= (uint8_t)(1 << PRSPI))
589#endif
590
591#if defined(__AVR_HAVE_PRR0_PRT0)
592#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRT0))
593#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRT0))
594#endif
595
596#if defined(__AVR_HAVE_PRR0_PRTIM0)
597#define power_timer0_enable() (PRR0 &= (uint8_t)~(1 << PRTIM0))
598#define power_timer0_disable() (PRR0 |= (uint8_t)(1 << PRTIM0))
599#endif
600
601#if defined(__AVR_HAVE_PRR0_PRT1)
602#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRT1))
603#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRT1))
604#endif
605
606#if defined(__AVR_HAVE_PRR0_PRTIM1)
607#define power_timer1_enable() (PRR0 &= (uint8_t)~(1 << PRTIM1))
608#define power_timer1_disable() (PRR0 |= (uint8_t)(1 << PRTIM1))
609#endif
610
611#if defined(__AVR_HAVE_PRR0_PRT2)
612#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRT2))
613#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRT2))
614#endif
615
616#if defined(__AVR_HAVE_PRR0_PRTIM2)
617#define power_timer2_enable() (PRR0 &= (uint8_t)~(1 << PRTIM2))
618#define power_timer2_disable() (PRR0 |= (uint8_t)(1 << PRTIM2))
619#endif
620
621#if defined(__AVR_HAVE_PRR0_PRT3)
622#define power_timer3_enable() (PRR0 &= (uint8_t)~(1 << PRT3))
623#define power_timer3_disable() (PRR0 |= (uint8_t)(1 << PRT3))
624#endif
625
626#if defined(__AVR_HAVE_PRR0_PRTM)
627#define power_timermodulator_enable() (PRR0 &= (uint8_t)~(1 << PRTM))
628#define power_timermodulator_disable() (PRR0 |= (uint8_t)(1 << PRTM))
629#endif
630
631#if defined(__AVR_HAVE_PRR0_PRTWI)
632#define power_twi_enable() (PRR0 &= (uint8_t)~(1 << PRTWI))
633#define power_twi_disable() (PRR0 |= (uint8_t)(1 << PRTWI))
634#endif
635
636#if defined(__AVR_HAVE_PRR0_PRTWI1)
637#define power_twi1_enable() (PRR0 &= (uint8_t)~(1 << PRTWI1))
638#define power_twi1_disable() (PRR0 |= (uint8_t)(1 << PRTWI1))
639#endif
640
641#if defined(__AVR_HAVE_PRR0_PRTXDC)
642#define power_transmit_dsp_control_enable() (PRR0 &= (uint8_t)~(1 << PRTXDC))
643#define power_transmit_dsp_control_disable() (PRR0 |= (uint8_t)(1 << PRTXDC))
644#endif
645
646#if defined(__AVR_HAVE_PRR0_PRUSART0)
647#define power_usart0_enable() (PRR0 &= (uint8_t)~(1 << PRUSART0))
648#define power_usart0_disable() (PRR0 |= (uint8_t)(1 << PRUSART0))
649#endif
650
651#if defined(__AVR_HAVE_PRR0_PRUSART1)
652#define power_usart1_enable() (PRR0 &= (uint8_t)~(1 << PRUSART1))
653#define power_usart1_disable() (PRR0 |= (uint8_t)(1 << PRUSART1))
654#endif
655
656#if defined(__AVR_HAVE_PRR0_PRVADC)
657#define power_vadc_enable() (PRR0 &= (uint8_t)~(1 << PRVADC))
658#define power_vadc_disable() (PRR0 |= (uint8_t)(1 << PRVADC))
659#endif
660
661#if defined(__AVR_HAVE_PRR0_PRVM)
662#define power_voltage_monitor_enable() (PRR0 &= (uint8_t)~(1 << PRVM))
663#define power_voltage_monitor_disable() (PRR0 |= (uint8_t)(1 << PRVM))
664#endif
665
666#if defined(__AVR_HAVE_PRR0_PRVRM)
667#define power_vrm_enable() (PRR0 &= (uint8_t)~(1 << PRVRM))
668#define power_vrm_disable() (PRR0 |= (uint8_t)(1 << PRVRM))
669#endif
670
671#if defined(__AVR_HAVE_PRR1_PRAES)
672#define power_aes_enable() (PRR1 &= (uint8_t)~(1 << PRAES))
673#define power_aes_disable() (PRR1 |= (uint8_t)(1 << PRAES))
674#endif
675
676#if defined(__AVR_HAVE_PRR1_PRCI)
677#define power_cinterface_enable() (PRR1 &= (uint8_t)~(1 << PRCI))
678#define power_cinterface_disable() (PRR1 |= (uint8_t)(1 << PRCI))
679#endif
680
681#if defined(__AVR_HAVE_PRR1_PRHSSPI)
682#define power_hsspi_enable() (PRR1 &= (uint8_t)~(1 << PRHSSPI))
683#define power_hsspi_disable() (PRR1 |= (uint8_t)(1 << PRHSSPI))
684#endif
685
686#if defined(__AVR_HAVE_PRR1_PRKB)
687#define power_kb_enable() (PRR1 &= (uint8_t)~(1 << PRKB))
688#define power_kb_disable() (PRR1 |= (uint8_t)(1 << PRKB))
689#endif
690
691#if defined(__AVR_HAVE_PRR1_PRLFPH)
692#define power_lfph_enable() (PRR1 &= (uint8_t)~(1 << PRLFPH))
693#define power_lfph_disable() (PRR1 |= (uint8_t)(1 << PRLFPH))
694#endif
695
696#if defined(__AVR_HAVE_PRR1_PRLFR)
697#define power_lfreceiver_enable() (PRR1 &= (uint8_t)~(1 << PRLFR))
698#define power_lfreceiver_disable() (PRR1 |= (uint8_t)(1 << PRLFR))
699#endif
700
701#if defined(__AVR_HAVE_PRR1_PRLFTP)
702#define power_lftp_enable() (PRR1 &= (uint8_t)~(1 << PRLFTP))
703#define power_lftp_disable() (PRR1 |= (uint8_t)(1 << PRLFTP))
704#endif
705
706#if defined(__AVR_HAVE_PRR1_PRSCI)
707#define power_sci_enable() (PRR1 &= (uint8_t)~(1 << PRSCI))
708#define power_sci_disable() (PRR1 |= (uint8_t)(1 << PRSCI))
709#endif
710
711#if defined(__AVR_HAVE_PRR1_PRSPI)
712#define power_spi_enable() (PRR1 &= (uint8_t)~(1 << PRSPI))
713#define power_spi_disable() (PRR1 |= (uint8_t)(1 << PRSPI))
714#endif
715
716#if defined(__AVR_HAVE_PRR1_PRT1)
717#define power_timer1_enable() (PRR1 &= (uint8_t)~(1 << PRT1))
718#define power_timer1_disable() (PRR1 |= (uint8_t)(1 << PRT1))
719#endif
720
721#if defined(__AVR_HAVE_PRR1_PRT2)
722#define power_timer2_enable() (PRR1 &= (uint8_t)~(1 << PRT2))
723#define power_timer2_disable() (PRR1 |= (uint8_t)(1 << PRT2))
724#endif
725
726#if defined(__AVR_HAVE_PRR1_PRT3)
727#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRT3))
728#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRT3))
729#endif
730
731#if defined(__AVR_HAVE_PRR1_PRT4)
732#define power_timer4_enable() (PRR1 &= (uint8_t)~(1 << PRT4))
733#define power_timer4_disable() (PRR1 |= (uint8_t)(1 << PRT4))
734#endif
735
736#if defined(__AVR_HAVE_PRR1_PRT5)
737#define power_timer5_enable() (PRR1 &= (uint8_t)~(1 << PRT5))
738#define power_timer5_disable() (PRR1 |= (uint8_t)(1 << PRT5))
739#endif
740
741#if defined(__AVR_HAVE_PRR1_PRTIM3)
742#define power_timer3_enable() (PRR1 &= (uint8_t)~(1 << PRTIM3))
743#define power_timer3_disable() (PRR1 |= (uint8_t)(1 << PRTIM3))
744#endif
745
746#if defined(__AVR_HAVE_PRR1_PRTIM4)
747#define power_timer4_enable() (PRR1 &= (uint8_t)~(1 << PRTIM4))
748#define power_timer4_disable() (PRR1 |= (uint8_t)(1 << PRTIM4))
749#endif
750
751#if defined(__AVR_HAVE_PRR1_PRTIM5)
752#define power_timer5_enable() (PRR1 &= (uint8_t)~(1 << PRTIM5))
753#define power_timer5_disable() (PRR1 |= (uint8_t)(1 << PRTIM5))
754#endif
755
756#if defined(__AVR_HAVE_PRR1_PRTRX24)
757#define power_transceiver_enable() (PRR1 &= (uint8_t)~(1 << PRTRX24))
758#define power_transceiver_disable() (PRR1 |= (uint8_t)(1 << PRTRX24))
759#endif
760
761#if defined(__AVR_HAVE_PRR1_PRUSART1)
762#define power_usart1_enable() (PRR1 &= (uint8_t)~(1 << PRUSART1))
763#define power_usart1_disable() (PRR1 |= (uint8_t)(1 << PRUSART1))
764#endif
765
766#if defined(__AVR_HAVE_PRR1_PRUSART2)
767#define power_usart2_enable() (PRR1 &= (uint8_t)~(1 << PRUSART2))
768#define power_usart2_disable() (PRR1 |= (uint8_t)(1 << PRUSART2))
769#endif
770
771#if defined(__AVR_HAVE_PRR1_PRUSART3)
772#define power_usart3_enable() (PRR1 &= (uint8_t)~(1 << PRUSART3))
773#define power_usart3_disable() (PRR1 |= (uint8_t)(1 << PRUSART3))
774#endif
775
776#if defined(__AVR_HAVE_PRR1_PRUSB)
777#define power_usb_enable() (PRR1 &= (uint8_t)~(1 << PRUSB))
778#define power_usb_disable() (PRR1 |= (uint8_t)(1 << PRUSB))
779#endif
780
781#if defined(__AVR_HAVE_PRR1_PRUSBH)
782#define power_usbh_enable() (PRR1 &= (uint8_t)~(1 << PRUSBH))
783#define power_usbh_disable() (PRR1 |= (uint8_t)(1 << PRUSBH))
784#endif
785
786#if defined(__AVR_HAVE_PRR2_PRDF)
787#define power_data_fifo_enable() (PRR2 &= (uint8_t)~(1 << PRDF))
788#define power_data_fifo_disable() (PRR2 |= (uint8_t)(1 << PRDF))
789#endif
790
791#if defined(__AVR_HAVE_PRR2_PRIDS)
792#define power_id_scan_enable() (PRR2 &= (uint8_t)~(1 << PRIDS))
793#define power_id_scan_disable() (PRR2 |= (uint8_t)(1 << PRIDS))
794#endif
795
796#if defined(__AVR_HAVE_PRR2_PRRAM0)
797#define power_ram0_enable() (PRR2 &= (uint8_t)~(1 << PRRAM0))
798#define power_ram0_disable() (PRR2 |= (uint8_t)(1 << PRRAM0))
799#endif
800
801#if defined(__AVR_HAVE_PRR2_PRRAM1)
802#define power_ram1_enable() (PRR2 &= (uint8_t)~(1 << PRRAM1))
803#define power_ram1_disable() (PRR2 |= (uint8_t)(1 << PRRAM1))
804#endif
805
806#if defined(__AVR_HAVE_PRR2_PRRAM2)
807#define power_ram2_enable() (PRR2 &= (uint8_t)~(1 << PRRAM2))
808#define power_ram2_disable() (PRR2 |= (uint8_t)(1 << PRRAM2))
809#endif
810
811#if defined(__AVR_HAVE_PRR2_PRRAM3)
812#define power_ram3_enable() (PRR2 &= (uint8_t)~(1 << PRRAM3))
813#define power_ram3_disable() (PRR2 |= (uint8_t)(1 << PRRAM3))
814#endif
815
816#if defined(__AVR_HAVE_PRR2_PRRS)
817#define power_rssi_buffer_enable() (PRR2 &= (uint8_t)~(1 << PRRS))
818#define power_rssi_buffer_disable() (PRR2 |= (uint8_t)(1 << PRRS))
819#endif
820
821#if defined(__AVR_HAVE_PRR2_PRSF)
822#define power_preamble_rssi_fifo_enable() (PRR2 &= (uint8_t)~(1 << PRSF))
823#define power_preamble_rssi_fifo_disable() (PRR2 |= (uint8_t)(1 << PRSF))
824#endif
825
826#if defined(__AVR_HAVE_PRR2_PRSPI2)
827#define power_spi2_enable() (PRR2 &= (uint8_t)~(1 << PRSPI2))
828#define power_spi2_disable() (PRR2 |= (uint8_t)(1 << PRSPI2))
829#endif
830
831#if defined(__AVR_HAVE_PRR2_PRSSM)
832#define power_sequencer_state_machine_enable() (PRR2 &= (uint8_t)~(1 << PRSSM))
833#define power_sequencer_state_machine_disable() (PRR2 |= (uint8_t)(1 << PRSSM))
834#endif
835
836#if defined(__AVR_HAVE_PRR2_PRTM)
837#define power_tx_modulator_enable() (PRR2 &= (uint8_t)~(1 << PRTM))
838#define power_tx_modulator_disable() (PRR2 |= (uint8_t)(1 << PRTM))
839#endif
840
841#if defined(__AVR_HAVE_PRR2_PRTWI2)
842#define power_twi2_enable() (PRR2 &= (uint8_t)~(1 << PRTWI2))
843#define power_twi2_disable() (PRR2 |= (uint8_t)(1 << PRTWI2))
844#endif
845
846#if defined(__AVR_HAVE_PRR2_PRXA)
847#define power_rx_buffer_A_enable() (PRR2 &= (uint8_t)~(1 << PRXA))
848#define power_rx_buffer_A_disable() (PRR2 |= (uint8_t)(1 << PRXA))
849#endif
850
851#if defined(__AVR_HAVE_PRR2_PRXB)
852#define power_rx_buffer_B_enable() (PRR2 &= (uint8_t)~(1 << PRXB))
853#define power_rx_buffer_B_disable() (PRR2 |= (uint8_t)(1 << PRXB))
854#endif
855
856#if defined(__AVR_HAVE_PRGEN_AES)
857#define power_aes_enable() (PR_PRGEN &= (uint8_t)~(PR_AES_bm))
858#define power_aes_disable() (PR_PRGEN |= (uint8_t)PR_AES_bm)
859#endif
860
861#if defined(__AVR_HAVE_PRGEN_DMA)
862#define power_dma_enable() (PR_PRGEN &= (uint8_t)~(PR_DMA_bm))
863#define power_dma_disable() (PR_PRGEN |= (uint8_t)PR_DMA_bm)
864#endif
865
866#if defined(__AVR_HAVE_PRGEN_EBI)
867#define power_ebi_enable() (PR_PRGEN &= (uint8_t)~(PR_EBI_bm))
868#define power_ebi_disable() (PR_PRGEN |= (uint8_t)PR_EBI_bm)
869#endif
870
871#if defined(__AVR_HAVE_PRGEN_EDMA)
872#define power_edma_enable() (PR_PRGEN &= (uint8_t)~(PR_EDMA_bm))
873#define power_edma_disable() (PR_PRGEN |= (uint8_t)PR_EDMA_bm)
874#endif
875
876#if defined(__AVR_HAVE_PRGEN_EVSYS)
877#define power_evsys_enable() (PR_PRGEN &= (uint8_t)~(PR_EVSYS_bm))
878#define power_evsys_disable() (PR_PRGEN |= (uint8_t)PR_EVSYS_bm)
879#endif
880
881#if defined(__AVR_HAVE_PRGEN_LCD)
882#define power_lcd_enable() (PR_PRGEN &= (uint8_t)~(PR_LCD_bm))
883#define power_lcd_disable() (PR_PRGEN |= (uint8_t)PR_LCD_bm)
884#endif
885
886#if defined(__AVR_HAVE_PRGEN_RTC)
887#define power_rtc_enable() (PR_PRGEN &= (uint8_t)~(PR_RTC_bm))
888#define power_rtc_disable() (PR_PRGEN |= (uint8_t)PR_RTC_bm)
889#endif
890
891#if defined(__AVR_HAVE_PRGEN_USB)
892#define power_usb_enable() (PR_PRGEN &= (uint8_t)~(PR_USB_bm))
893#define power_usb_disable() (PR_PRGEN &= (uint8_t)(PR_USB_bm))
894#endif
895
896#if defined(__AVR_HAVE_PRGEN_XCL)
897#define power_xcl_enable() (PR_PRGEN &= (uint8_t)~(PR_XCL_bm))
898#define power_xcl_disable() (PR_PRGEN |= (uint8_t)PR_XCL_bm)
899#endif
900
901#if defined(__AVR_HAVE_PRPA_AC)
902#define power_aca_enable() (PR_PRPA &= (uint8_t)~(PR_AC_bm))
903#define power_aca_disable() (PR_PRPA |= (uint8_t)PR_AC_bm)
904#endif
905
906#if defined(__AVR_HAVE_PRPA_ADC)
907#define power_adca_enable() (PR_PRPA &= (uint8_t)~(PR_ADC_bm))
908#define power_adca_disable() (PR_PRPA |= (uint8_t)PR_ADC_bm)
909#endif
910
911#if defined(__AVR_HAVE_PRPA_DAC)
912#define power_daca_enable() (PR_PRPA &= (uint8_t)~(PR_DAC_bm))
913#define power_daca_disable() (PR_PRPA |= (uint8_t)PR_DAC_bm)
914#endif
915
916#if defined(__AVR_HAVE_PRPB_AC)
917#define power_acb_enable() (PR_PRPB &= (uint8_t)~(PR_AC_bm))
918#define power_acb_disable() (PR_PRPB |= (uint8_t)PR_AC_bm)
919#endif
920
921#if defined(__AVR_HAVE_PRPB_ADC)
922#define power_adcb_enable() (PR_PRPB &= (uint8_t)~(PR_ADC_bm))
923#define power_adcb_disable() (PR_PRPB |= (uint8_t)PR_ADC_bm)
924#endif
925
926#if defined(__AVR_HAVE_PRPB_DAC)
927#define power_dacb_enable() (PR_PRPB &= (uint8_t)~(PR_DAC_bm))
928#define power_dacb_disable() (PR_PRPB |= (uint8_t)PR_DAC_bm)
929#endif
930
931#if defined(__AVR_HAVE_PRPC_HIRES)
932#define power_hiresc_enable() (PR_PRPC &= (uint8_t)~(PR_HIRES_bm))
933#define power_hiresc_disable() (PR_PRPC |= (uint8_t)PR_HIRES_bm)
934#endif
935
936#if defined(__AVR_HAVE_PRPC_SPI)
937#define power_spic_enable() (PR_PRPC &= (uint8_t)~(PR_SPI_bm))
938#define power_spic_disable() (PR_PRPC |= (uint8_t)PR_SPI_bm)
939#endif
940
941#if defined(__AVR_HAVE_PRPC_TC0)
942#define power_tc0c_enable() (PR_PRPC &= (uint8_t)~(PR_TC0_bm))
943#define power_tc0c_disable() (PR_PRPC |= (uint8_t)PR_TC0_bm)
944#endif
945
946#if defined(__AVR_HAVE_PRPC_TC1)
947#define power_tc1c_enable() (PR_PRPC &= (uint8_t)~(PR_TC1_bm))
948#define power_tc1c_disable() (PR_PRPC |= (uint8_t)PR_TC1_bm)
949#endif
950
951#if defined(__AVR_HAVE_PRPC_TC4)
952#define power_tc4c_enable() (PR_PRPC &= (uint8_t)~(PR_TC4_bm))
953#define power_tc4c_disable() (PR_PRPC |= (uint8_t)PR_TC4_bm)
954#endif
955
956#if defined(__AVR_HAVE_PRPC_TC5)
957#define power_tc5c_enable() (PR_PRPC &= (uint8_t)~(PR_TC5_bm))
958#define power_tc5c_disable() (PR_PRPC |= (uint8_t)PR_TC5_bm)
959#endif
960
961#if defined(__AVR_HAVE_PRPC_TWI)
962#define power_twic_enable() (PR_PRPC &= (uint8_t)~(PR_TWI_bm))
963#define power_twic_disable() (PR_PRPC |= (uint8_t)PR_TWI_bm)
964#endif
965
966#if defined(__AVR_HAVE_PRPC_USART0)
967#define power_usartc0_enable() (PR_PRPC &= (uint8_t)~(PR_USART0_bm))
968#define power_usartc0_disable() (PR_PRPC |= (uint8_t)PR_USART0_bm)
969#endif
970
971#if defined(__AVR_HAVE_PRPC_USART1)
972#define power_usartc1_enable() (PR_PRPC &= (uint8_t)~(PR_USART1_bm))
973#define power_usartc1_disable() (PR_PRPC |= (uint8_t)PR_USART1_bm)
974#endif
975
976#if defined(__AVR_HAVE_PRPD_HIRES)
977#define power_hiresd_enable() (PR_PRPD &= (uint8_t)~(PR_HIRES_bm))
978#define power_hiresd_disable() (PR_PRPD |= (uint8_t)PR_HIRES_bm)
979#endif
980
981#if defined(__AVR_HAVE_PRPD_SPI)
982#define power_spid_enable() (PR_PRPD &= (uint8_t)~(PR_SPI_bm))
983#define power_spid_disable() (PR_PRPD |= (uint8_t)PR_SPI_bm)
984#endif
985
986#if defined(__AVR_HAVE_PRPD_TC0)
987#define power_tc0d_enable() (PR_PRPD &= (uint8_t)~(PR_TC0_bm))
988#define power_tc0d_disable() (PR_PRPD |= (uint8_t)PR_TC0_bm)
989#endif
990
991#if defined(__AVR_HAVE_PRPD_TC1)
992#define power_tc1d_enable() (PR_PRPD &= (uint8_t)~(PR_TC1_bm))
993#define power_tc1d_disable() (PR_PRPD |= (uint8_t)PR_TC1_bm)
994#endif
995
996#if defined(__AVR_HAVE_PRPD_TC5)
997#define power_tc5d_enable() (PR_PRPD &= (uint8_t)~(PR_TC5_bm))
998#define power_tc5d_disable() (PR_PRPD |= (uint8_t)PR_TC5_bm)
999#endif
1000
1001#if defined(__AVR_HAVE_PRPD_TWI)
1002#define power_twid_enable() (PR_PRPD &= (uint8_t)~(PR_TWI_bm))
1003#define power_twid_disable() (PR_PRPD |= (uint8_t)PR_TWI_bm)
1004#endif
1005
1006#if defined(__AVR_HAVE_PRPD_USART0)
1007#define power_usartd0_enable() (PR_PRPD &= (uint8_t)~(PR_USART0_bm))
1008#define power_usartd0_disable() (PR_PRPD |= (uint8_t)PR_USART0_bm)
1009#endif
1010
1011#if defined(__AVR_HAVE_PRPD_USART1)
1012#define power_usartd1_enable() (PR_PRPD &= (uint8_t)~(PR_USART1_bm))
1013#define power_usartd1_disable() (PR_PRPD |= (uint8_t)PR_USART1_bm)
1014#endif
1015
1016#if defined(__AVR_HAVE_PRPE_HIRES)
1017#define power_hirese_enable() (PR_PRPE &= (uint8_t)~(PR_HIRES_bm))
1018#define power_hirese_disable() (PR_PRPE |= (uint8_t)PR_HIRES_bm)
1019#endif
1020
1021#if defined(__AVR_HAVE_PRPE_SPI)
1022#define power_spie_enable() (PR_PRPE &= (uint8_t)~(PR_SPI_bm))
1023#define power_spie_disable() (PR_PRPE |= (uint8_t)PR_SPI_bm)
1024#endif
1025
1026#if defined(__AVR_HAVE_PRPE_TC0)
1027#define power_tc0e_enable() (PR_PRPE &= (uint8_t)~(PR_TC0_bm))
1028#define power_tc0e_disable() (PR_PRPE |= (uint8_t)PR_TC0_bm)
1029#endif
1030
1031#if defined(__AVR_HAVE_PRPE_TC1)
1032#define power_tc1e_enable() (PR_PRPE &= (uint8_t)~(PR_TC1_bm))
1033#define power_tc1e_disable() (PR_PRPE |= (uint8_t)PR_TC1_bm)
1034#endif
1035
1036#if defined(__AVR_HAVE_PRPE_TWI)
1037#define power_twie_enable() (PR_PRPE &= (uint8_t)~(PR_TWI_bm))
1038#define power_twie_disable() (PR_PRPE |= (uint8_t)PR_TWI_bm)
1039#endif
1040
1041#if defined(__AVR_HAVE_PRPE_USART0)
1042#define power_usarte0_enable() (PR_PRPE &= (uint8_t)~(PR_USART0_bm))
1043#define power_usarte0_disable() (PR_PRPE |= (uint8_t)PR_USART0_bm)
1044#endif
1045
1046#if defined(__AVR_HAVE_PRPE_USART1)
1047#define power_usarte1_enable() (PR_PRPE &= (uint8_t)~(PR_USART1_bm))
1048#define power_usarte1_disable() (PR_PRPE |= (uint8_t)PR_USART1_bm)
1049#endif
1050
1051#if defined(__AVR_HAVE_PRPF_HIRES)
1052#define power_hiresf_enable() (PR_PRPF &= (uint8_t)~(PR_HIRES_bm))
1053#define power_hiresf_disable() (PR_PRPF |= (uint8_t)PR_HIRES_bm)
1054#endif
1055
1056#if defined(__AVR_HAVE_PRPF_SPI)
1057#define power_spif_enable() (PR_PRPF &= (uint8_t)~(PR_SPI_bm))
1058#define power_spif_disable() (PR_PRPF |= (uint8_t)PR_SPI_bm)
1059#endif
1060
1061#if defined(__AVR_HAVE_PRPF_TC0)
1062#define power_tc0f_enable() (PR_PRPF &= (uint8_t)~(PR_TC0_bm))
1063#define power_tc0f_disable() (PR_PRPF |= (uint8_t)PR_TC0_bm)
1064#endif
1065
1066#if defined(__AVR_HAVE_PRPF_TC1)
1067#define power_tc1f_enable() (PR_PRPF &= (uint8_t)~(PR_TC1_bm))
1068#define power_tc1f_disable() (PR_PRPF |= (uint8_t)PR_TC1_bm)
1069#endif
1070
1071#if defined(__AVR_HAVE_PRPF_TWI)
1072#define power_twif_enable() (PR_PRPF &= (uint8_t)~(PR_TWI_bm))
1073#define power_twif_disable() (PR_PRPF |= (uint8_t)PR_TWI_bm)
1074#endif
1075
1076#if defined(__AVR_HAVE_PRPF_USART0)
1077#define power_usartf0_enable() (PR_PRPF &= (uint8_t)~(PR_USART0_bm))
1078#define power_usartf0_disable() (PR_PRPF |= (uint8_t)PR_USART0_bm)
1079#endif
1080
1081#if defined(__AVR_HAVE_PRPF_USART1)
1082#define power_usartf1_enable() (PR_PRPF &= (uint8_t)~(PR_USART1_bm))
1083#define power_usartf1_disable() (PR_PRPF |= (uint8_t)PR_USART1_bm)
1084#endif
1085
1086#ifdef __DOXYGEN__
1087/**
1088 \ingroup avr_power
1089 \fn void power_all_enable()
1090 Enable all modules.
1091 */
1092static __ATTR_ALWAYS_INLINE__ void power_all_enable();
1093#else
1094static __ATTR_ALWAYS_INLINE__ void __power_all_enable()
1095{
1096#ifdef __AVR_HAVE_PRR
1097 PRR &= (uint8_t)~(__AVR_HAVE_PRR);
1098#endif
1099
1100#ifdef __AVR_HAVE_PRR0
1101 PRR0 &= (uint8_t)~(__AVR_HAVE_PRR0);
1102#endif
1103
1104#ifdef __AVR_HAVE_PRR1
1105 PRR1 &= (uint8_t)~(__AVR_HAVE_PRR1);
1106#endif
1107
1108#ifdef __AVR_HAVE_PRR2
1109 PRR2 &= (uint8_t)~(__AVR_HAVE_PRR2);
1110#endif
1111
1112#ifdef __AVR_HAVE_PRGEN
1113 PR_PRGEN &= (uint8_t)~(__AVR_HAVE_PRGEN);
1114#endif
1115
1116#ifdef __AVR_HAVE_PRPA
1117 PR_PRPA &= (uint8_t)~(__AVR_HAVE_PRPA);
1118#endif
1119
1120#ifdef __AVR_HAVE_PRPB
1121 PR_PRPB &= (uint8_t)~(__AVR_HAVE_PRPB);
1122#endif
1123
1124#ifdef __AVR_HAVE_PRPC
1125 PR_PRPC &= (uint8_t)~(__AVR_HAVE_PRPC);
1126#endif
1127
1128#ifdef __AVR_HAVE_PRPD
1129 PR_PRPD &= (uint8_t)~(__AVR_HAVE_PRPD);
1130#endif
1131
1132#ifdef __AVR_HAVE_PRPE
1133 PR_PRPE &= (uint8_t)~(__AVR_HAVE_PRPE);
1134#endif
1135
1136#ifdef __AVR_HAVE_PRPF
1137 PR_PRPF &= (uint8_t)~(__AVR_HAVE_PRPF);
1138#endif
1139}
1140#endif /* __DOXYGEN__ */
1141
1142#ifdef __DOXYGEN__
1143/**
1144 \ingroup avr_power
1145 \fn void power_all_disable()
1146 Disable all modules.
1147 */
1148static __ATTR_ALWAYS_INLINE__ void power_all_disable();
1149#else
1150static __ATTR_ALWAYS_INLINE__ void __power_all_disable()
1151{
1152#ifdef __AVR_HAVE_PRR
1153 PRR |= (uint8_t)(__AVR_HAVE_PRR);
1154#endif
1155
1156#ifdef __AVR_HAVE_PRR0
1157 PRR0 |= (uint8_t)(__AVR_HAVE_PRR0);
1158#endif
1159
1160#ifdef __AVR_HAVE_PRR1
1161 PRR1 |= (uint8_t)(__AVR_HAVE_PRR1);
1162#endif
1163
1164#ifdef __AVR_HAVE_PRR2
1165 PRR2 |= (uint8_t)(__AVR_HAVE_PRR2);
1166#endif
1167
1168#ifdef __AVR_HAVE_PRGEN
1169 PR_PRGEN |= (uint8_t)(__AVR_HAVE_PRGEN);
1170#endif
1171
1172#ifdef __AVR_HAVE_PRPA
1173 PR_PRPA |= (uint8_t)(__AVR_HAVE_PRPA);
1174#endif
1175
1176#ifdef __AVR_HAVE_PRPB
1177 PR_PRPB |= (uint8_t)(__AVR_HAVE_PRPB);
1178#endif
1179
1180#ifdef __AVR_HAVE_PRPC
1181 PR_PRPC |= (uint8_t)(__AVR_HAVE_PRPC);
1182#endif
1183
1184#ifdef __AVR_HAVE_PRPD
1185 PR_PRPD |= (uint8_t)(__AVR_HAVE_PRPD);
1186#endif
1187
1188#ifdef __AVR_HAVE_PRPE
1189 PR_PRPE |= (uint8_t)(__AVR_HAVE_PRPE);
1190#endif
1191
1192#ifdef __AVR_HAVE_PRPF
1193 PR_PRPF |= (uint8_t)(__AVR_HAVE_PRPF);
1194#endif
1195}
1196#endif /* __DOXYGEN__ */
1197
1198#ifndef __DOXYGEN__
1199#ifndef power_all_enable
1200#define power_all_enable() __power_all_enable()
1201#endif
1202
1203#ifndef power_all_disable
1204#define power_all_disable() __power_all_disable()
1205#endif
1206#endif /* !__DOXYGEN__ */
1207
1208
1209#if defined(__DOXYGEN__) \
1210|| defined(__AVR_AT90CAN32__) \
1211|| defined(__AVR_AT90CAN64__) \
1212|| defined(__AVR_AT90CAN128__) \
1213|| defined(__AVR_AT90PWM1__) \
1214|| defined(__AVR_AT90PWM2__) \
1215|| defined(__AVR_AT90PWM2B__) \
1216|| defined(__AVR_AT90PWM3__) \
1217|| defined(__AVR_AT90PWM3B__) \
1218|| defined(__AVR_AT90PWM81__) \
1219|| defined(__AVR_AT90PWM161__) \
1220|| defined(__AVR_AT90PWM216__) \
1221|| defined(__AVR_AT90PWM316__) \
1222|| defined(__AVR_AT90SCR100__) \
1223|| defined(__AVR_AT90USB646__) \
1224|| defined(__AVR_AT90USB647__) \
1225|| defined(__AVR_AT90USB82__) \
1226|| defined(__AVR_AT90USB1286__) \
1227|| defined(__AVR_AT90USB1287__) \
1228|| defined(__AVR_AT90USB162__) \
1229|| defined(__AVR_ATA5505__) \
1230|| defined(__AVR_ATA5272__) \
1231|| defined(__AVR_ATmega1280__) \
1232|| defined(__AVR_ATmega1281__) \
1233|| defined(__AVR_ATmega1284__) \
1234|| defined(__AVR_ATmega128RFA1__) \
1235|| defined(__AVR_ATmega1284RFR2__) \
1236|| defined(__AVR_ATmega128RFR2__) \
1237|| defined(__AVR_ATmega1284P__) \
1238|| defined(__AVR_ATmega162__) \
1239|| defined(__AVR_ATmega164A__) \
1240|| defined(__AVR_ATmega164P__) \
1241|| defined(__AVR_ATmega164PA__) \
1242|| defined(__AVR_ATmega165__) \
1243|| defined(__AVR_ATmega165A__) \
1244|| defined(__AVR_ATmega165P__) \
1245|| defined(__AVR_ATmega165PA__) \
1246|| defined(__AVR_ATmega168__) \
1247|| defined(__AVR_ATmega168P__) \
1248|| defined(__AVR_ATmega168A__) \
1249|| defined(__AVR_ATmega168PA__) \
1250|| defined(__AVR_ATmega168PB__) \
1251|| defined(__AVR_ATmega169__) \
1252|| defined(__AVR_ATmega169A__) \
1253|| defined(__AVR_ATmega169P__) \
1254|| defined(__AVR_ATmega169PA__) \
1255|| defined(__AVR_ATmega16M1__) \
1256|| defined(__AVR_ATmega16U2__) \
1257|| defined(__AVR_ATmega16U4__) \
1258|| defined(__AVR_ATmega2560__) \
1259|| defined(__AVR_ATmega2561__) \
1260|| defined(__AVR_ATmega2564RFR2__) \
1261|| defined(__AVR_ATmega256RFR2__) \
1262|| defined(__AVR_ATmega324A__) \
1263|| defined(__AVR_ATmega324P__) \
1264|| defined(__AVR_ATmega324PA__) \
1265|| defined(__AVR_ATmega324PB__) \
1266|| defined(__AVR_ATmega325__) \
1267|| defined(__AVR_ATmega325A__) \
1268|| defined(__AVR_ATmega325PA__) \
1269|| defined(__AVR_ATmega3250__) \
1270|| defined(__AVR_ATmega3250A__) \
1271|| defined(__AVR_ATmega3250PA__) \
1272|| defined(__AVR_ATmega328__) \
1273|| defined(__AVR_ATmega328P__) \
1274|| defined(__AVR_ATmega328PB__) \
1275|| defined(__AVR_ATmega329__) \
1276|| defined(__AVR_ATmega329A__) \
1277|| defined(__AVR_ATmega329P__) \
1278|| defined(__AVR_ATmega329PA__) \
1279|| defined(__AVR_ATmega3290__) \
1280|| defined(__AVR_ATmega3290A__) \
1281|| defined(__AVR_ATmega3290P__) \
1282|| defined(__AVR_ATmega3290PA__) \
1283|| defined(__AVR_ATmega32C1__) \
1284|| defined(__AVR_ATmega32M1__) \
1285|| defined(__AVR_ATmega32U2__) \
1286|| defined(__AVR_ATmega32U4__) \
1287|| defined(__AVR_ATmega32U6__) \
1288|| defined(__AVR_ATmega48__) \
1289|| defined(__AVR_ATmega48A__) \
1290|| defined(__AVR_ATmega48PA__) \
1291|| defined(__AVR_ATmega48P__) \
1292|| defined(__AVR_ATmega640__) \
1293|| defined(__AVR_ATmega649P__) \
1294|| defined(__AVR_ATmega644__) \
1295|| defined(__AVR_ATmega644A__) \
1296|| defined(__AVR_ATmega644P__) \
1297|| defined(__AVR_ATmega644PA__) \
1298|| defined(__AVR_ATmega645__) \
1299|| defined(__AVR_ATmega645A__) \
1300|| defined(__AVR_ATmega645P__) \
1301|| defined(__AVR_ATmega6450__) \
1302|| defined(__AVR_ATmega6450A__) \
1303|| defined(__AVR_ATmega6450P__) \
1304|| defined(__AVR_ATmega649__) \
1305|| defined(__AVR_ATmega649A__) \
1306|| defined(__AVR_ATmega64M1__) \
1307|| defined(__AVR_ATmega64C1__) \
1308|| defined(__AVR_ATmega6490__) \
1309|| defined(__AVR_ATmega6490A__) \
1310|| defined(__AVR_ATmega6490P__) \
1311|| defined(__AVR_ATmega644RFR2__) \
1312|| defined(__AVR_ATmega64RFR2__) \
1313|| defined(__AVR_ATmega88__) \
1314|| defined(__AVR_ATmega88A__) \
1315|| defined(__AVR_ATmega88P__) \
1316|| defined(__AVR_ATmega88PA__) \
1317|| defined(__AVR_ATmega8U2__) \
1318|| defined(__AVR_ATmega16U2__) \
1319|| defined(__AVR_ATmega32U2__) \
1320|| defined(__AVR_ATtiny48__) \
1321|| defined(__AVR_ATtiny88__) \
1322|| defined(__AVR_ATtiny87__) \
1323|| defined(__AVR_ATtiny167__)
1324
1325
1326/** \addtogroup avr_power
1327
1328Some of the newer AVRs contain a System Clock Prescale Register (CLKPR) that
1329allows you to decrease the system clock frequency and the power consumption
1330when the need for processing power is low.
1331On some earlier AVRs (ATmega103, ATmega64, ATmega128), similar
1332functionality can be achieved through the XTAL Divide Control Register.
1333Below are two macros and an enumerated type that can be used to
1334interface to the Clock Prescale Register or
1335XTAL Divide Control Register.
1336
1337\note Not all AVR devices have a clock prescaler. On those devices
1338without a Clock Prescale Register or XTAL Divide Control Register, these
1339macros are not available.
1340
1341\code
1342typedef enum
1343{
1344 clock_div_1 = 0,
1345 clock_div_2 = 1,
1346 clock_div_4 = 2,
1347 clock_div_8 = 3,
1348 clock_div_16 = 4,
1349 clock_div_32 = 5,
1350 clock_div_64 = 6,
1351 clock_div_128 = 7,
1352 clock_div_256 = 8,
1353 clock_div_1_rc = 15, // ATmega128RFA1 only
1354} clock_div_t;
1355\endcode
1356Clock prescaler setting enumerations for device using
1357System Clock Prescale Register.
1358
1359\code
1360typedef enum
1361{
1362 clock_div_1 = 1,
1363 clock_div_2 = 2,
1364 clock_div_4 = 4,
1365 clock_div_8 = 8,
1366 clock_div_16 = 16,
1367 clock_div_32 = 32,
1368 clock_div_64 = 64,
1369 clock_div_128 = 128
1370} clock_div_t;
1371\endcode
1372Clock prescaler setting enumerations for device using
1373XTAL Divide Control Register.
1374
1375*/
1376#ifndef __DOXYGEN__
1377typedef enum
1378{
1379 clock_div_1 = 0,
1380 clock_div_2 = 1,
1381 clock_div_4 = 2,
1382 clock_div_8 = 3,
1383 clock_div_16 = 4,
1384 clock_div_32 = 5,
1385 clock_div_64 = 6,
1386 clock_div_128 = 7,
1387 clock_div_256 = 8
1388#if defined(__AVR_ATmega128RFA1__) \
1389|| defined(__AVR_ATmega2564RFR2__) \
1390|| defined(__AVR_ATmega1284RFR2__) \
1391|| defined(__AVR_ATmega644RFR2__) \
1392|| defined(__AVR_ATmega256RFR2__) \
1393|| defined(__AVR_ATmega128RFR2__) \
1394|| defined(__AVR_ATmega64RFR2__)
1395 , clock_div_1_rc = 15
1396#endif
1397} clock_div_t;
1398
1399static __ATTR_ALWAYS_INLINE__ void clock_prescale_set(clock_div_t);
1400#endif /* !__DOXYGEN__ */
1401
1402/**
1403 \ingroup avr_power
1404 \fn clock_prescale_set(clock_div_t x)
1405
1406Set the clock prescaler register select bits, selecting a system clock
1407division setting. This function is inlined, even if compiler
1408optimizations are disabled.
1409
1410The type of \c x is \c clock_div_t.
1411
1412\note For device with XTAL Divide Control Register (XDIV), \c x can actually range
1413from 1 to 129. Thus, one does not need to use \c clock_div_t type as argument.
1414*/
1415void clock_prescale_set(clock_div_t __x)
1416{
1417 uint8_t __tmp = _BV(CLKPCE);
1418 __asm__ __volatile__ (
1419 "in __tmp_reg__,__SREG__" "\n\t"
1420 "cli" "\n\t"
1421 "sts %1, %0" "\n\t"
1422 "sts %1, %2" "\n\t"
1423 "out __SREG__, __tmp_reg__"
1424 : /* no outputs */
1425 : "d" (__tmp),
1426 "M" (_SFR_MEM_ADDR(CLKPR)),
1427 "d" ((uint8_t) __x)
1428 : "r0", "memory");
1429}
1430
1431/** \ingroup avr_power
1432\def clock_prescale_get()
1433Gets and returns the clock prescaler register setting. The return type is \c clock_div_t.
1434
1435\note For device with XTAL Divide Control Register (XDIV), return can actually
1436range from 1 to 129. Care should be taken has the return value could differ from the
1437typedef enum clock_div_t. This should only happen if clock_prescale_set was previously
1438called with a value other than those defined by \c clock_div_t.
1439*/
1440#define clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))
1441
1442#elif defined(__AVR_ATmega16HVB__) \
1443|| defined(__AVR_ATmega16HVBREVB__) \
1444|| defined(__AVR_ATmega32HVB__) \
1445|| defined(__AVR_ATmega32HVBREVB__)
1446
1447typedef enum
1448{
1449 clock_div_1 = 0,
1450 clock_div_2 = 1,
1451 clock_div_4 = 2,
1452 clock_div_8 = 3
1453} clock_div_t;
1454
1455static __ATTR_ALWAYS_INLINE__ void clock_prescale_set(clock_div_t);
1456
1457void clock_prescale_set(clock_div_t __x)
1458{
1459 uint8_t __tmp = _BV(CLKPCE);
1460 __asm__ __volatile__ (
1461 "in __tmp_reg__,__SREG__" "\n\t"
1462 "cli" "\n\t"
1463 "sts %1, %0" "\n\t"
1464 "sts %1, %2" "\n\t"
1465 "out __SREG__, __tmp_reg__"
1466 : /* no outputs */
1467 : "d" (__tmp),
1468 "M" (_SFR_MEM_ADDR(CLKPR)),
1469 "d" ((uint8_t) __x)
1470 : "r0", "memory");
1471}
1472
1473#define clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)))
1474
1475#elif defined(__AVR_ATA5790__) \
1476|| defined (__AVR_ATA5795__)
1477
1478typedef enum
1479{
1480 clock_div_1 = 0,
1481 clock_div_2 = 1,
1482 clock_div_4 = 2,
1483 clock_div_8 = 3,
1484 clock_div_16 = 4,
1485 clock_div_32 = 5,
1486 clock_div_64 = 6,
1487 clock_div_128 = 7,
1488} clock_div_t;
1489
1490static __ATTR_ALWAYS_INLINE__ void system_clock_prescale_set(clock_div_t);
1491
1492void system_clock_prescale_set(clock_div_t __x)
1493{
1494 uint8_t __tmp = _BV(CLKPCE);
1495 __asm__ __volatile__ (
1496 "in __tmp_reg__,__SREG__" "\n\t"
1497 "cli" "\n\t"
1498 "out %1, %0" "\n\t"
1499 "out %1, %2" "\n\t"
1500 "out __SREG__, __tmp_reg__"
1501 : /* no outputs */
1502 : "d" (__tmp),
1503 "I" (_SFR_IO_ADDR(CLKPR)),
1504 "d" ((uint8_t) __x)
1505 : "r0", "memory");
1506}
1507
1508#define system_clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)))
1509
1510typedef enum
1511{
1512 timer_clock_div_reset = 0,
1513 timer_clock_div_1 = 1,
1514 timer_clock_div_2 = 2,
1515 timer_clock_div_4 = 3,
1516 timer_clock_div_8 = 4,
1517 timer_clock_div_16 = 5,
1518 timer_clock_div_32 = 6,
1519 timer_clock_div_64 = 7
1520} timer_clock_div_t;
1521
1522static __ATTR_ALWAYS_INLINE__ void timer_clock_prescale_set(timer_clock_div_t);
1523
1524void timer_clock_prescale_set(timer_clock_div_t __x)
1525{
1526 uint8_t __t;
1527 __asm__ __volatile__ (
1528 "in __tmp_reg__,__SREG__" "\n\t"
1529 "cli" "\n\t"
1530 "in %[temp],%[clkpr]" "\n\t"
1531 "out %[clkpr],%[enable]" "\n\t"
1532 "cbr %[temp],%[not_CLTPS]" "\n\t"
1533 "or %[temp], %[set_value]" "\n\t"
1534 "out %[clkpr],%[temp]" "\n\t"
1535 "out __SREG__,__tmp_reg__"
1536 : [temp] "=d" (__t)
1537 : [clkpr] "I" (_SFR_IO_ADDR(CLKPR)),
1538 [enable] "r" ((uint8_t) _BV(CLKPCE)),
1539 [not_CLTPS] "M" ((1 << CLTPS2) | (1 << CLTPS1) | (1 << CLTPS0)),
1540 [set_value] "r" ((uint8_t) ((__x & 7) << 3))
1541 : "r0", "memory");
1542}
1543
1544#define timer_clock_prescale_get() (timer_clock_div_t)(CLKPR & (uint8_t)((1<<CLTPS0)|(1<<CLTPS1)|(1<<CLTPS2)))
1545
1546#elif defined(__AVR_ATA6285__) \
1547|| defined(__AVR_ATA6286__)
1548
1549typedef enum
1550{
1551 clock_div_1 = 0,
1552 clock_div_2 = 1,
1553 clock_div_4 = 2,
1554 clock_div_8 = 3,
1555 clock_div_16 = 4,
1556 clock_div_32 = 5,
1557 clock_div_64 = 6,
1558 clock_div_128 = 7
1559} clock_div_t;
1560
1561static __ATTR_ALWAYS_INLINE__ void system_clock_prescale_set(clock_div_t);
1562
1563void system_clock_prescale_set(clock_div_t __x)
1564{
1565 uint8_t __t;
1566 __asm__ __volatile__ (
1567 "in __tmp_reg__,__SREG__" "\n\t"
1568 "cli" "\n\t"
1569 "in %[temp],%[clpr]" "\n\t"
1570 "out %[clpr],%[enable]" "\n\t"
1571 "cbr %[temp],%[not_CLKPS]" "\n\t"
1572 "or %[temp], %[set_value]" "\n\t"
1573 "out %[clpr],%[temp]" "\n\t"
1574 "out __SREG__,__tmp_reg__"
1575 : [temp] "=d" (__t)
1576 : [clpr] "I" (_SFR_IO_ADDR(CLKPR)),
1577 [enable] "r" ((uint8_t) (1 << CLPCE)),
1578 [not_CLKPS] "M" ((1 << CLKPS2) | (1 << CLKPS1) | (1 << CLKPS0)),
1579 [set_value] "r" ((uint8_t) (__x & 7))
1580 : "r0", "memory");
1581}
1582
1583#define system_clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)))
1584
1585typedef enum
1586{
1587 timer_clock_div_reset = 0,
1588 timer_clock_div_1 = 1,
1589 timer_clock_div_2 = 2,
1590 timer_clock_div_4 = 3,
1591 timer_clock_div_8 = 4,
1592 timer_clock_div_16 = 5,
1593 timer_clock_div_32 = 6,
1594 timer_clock_div_64 = 7
1595} timer_clock_div_t;
1596
1597static __ATTR_ALWAYS_INLINE__ void timer_clock_prescale_set(timer_clock_div_t);
1598
1599void timer_clock_prescale_set(timer_clock_div_t __x)
1600{
1601 uint8_t __t;
1602 __asm__ __volatile__ (
1603 "in __tmp_reg__,__SREG__" "\n\t"
1604 "cli" "\n\t"
1605 "in %[temp],%[clpr]" "\n\t"
1606 "out %[clpr],%[enable]" "\n\t"
1607 "cbr %[temp],%[not_CLTPS]" "\n\t"
1608 "or %[temp], %[set_value]" "\n\t"
1609 "out %[clpr],%[temp]" "\n\t"
1610 "out __SREG__,__tmp_reg__"
1611 : [temp] "=d" (__t)
1612 : [clpr] "I" (_SFR_IO_ADDR(CLKPR)),
1613 [enable] "r" ((uint8_t) (1 << CLPCE)),
1614 [not_CLTPS] "M" ((1 << CLTPS2) | (1 << CLTPS1) | (1 << CLTPS0)),
1615 [set_value] "r" ((uint8_t) ((__x & 7) << 3))
1616 : "r0", "memory");
1617}
1618
1619#define timer_clock_prescale_get() (timer_clock_div_t)(CLKPR & (uint8_t)((1<<CLTPS0)|(1<<CLTPS1)|(1<<CLTPS2)))
1620
1621#elif defined(__AVR_ATtiny24__) \
1622|| defined(__AVR_ATtiny24A__) \
1623|| defined(__AVR_ATtiny44__) \
1624|| defined(__AVR_ATtiny44A__) \
1625|| defined(__AVR_ATtiny84__) \
1626|| defined(__AVR_ATtiny84A__) \
1627|| defined(__AVR_ATtiny25__) \
1628|| defined(__AVR_ATtiny45__) \
1629|| defined(__AVR_ATtiny85__) \
1630|| defined(__AVR_ATtiny261A__) \
1631|| defined(__AVR_ATtiny261__) \
1632|| defined(__AVR_ATtiny461__) \
1633|| defined(__AVR_ATtiny461A__) \
1634|| defined(__AVR_ATtiny861__) \
1635|| defined(__AVR_ATtiny861A__) \
1636|| defined(__AVR_ATtiny2313__) \
1637|| defined(__AVR_ATtiny2313A__) \
1638|| defined(__AVR_ATtiny4313__) \
1639|| defined(__AVR_ATtiny13__) \
1640|| defined(__AVR_ATtiny13A__) \
1641|| defined(__AVR_ATtiny43U__) \
1642
1643typedef enum
1644{
1645 clock_div_1 = 0,
1646 clock_div_2 = 1,
1647 clock_div_4 = 2,
1648 clock_div_8 = 3,
1649 clock_div_16 = 4,
1650 clock_div_32 = 5,
1651 clock_div_64 = 6,
1652 clock_div_128 = 7,
1653 clock_div_256 = 8
1654} clock_div_t;
1655
1656static __ATTR_ALWAYS_INLINE__ void clock_prescale_set(clock_div_t);
1657
1658void clock_prescale_set(clock_div_t __x)
1659{
1660 __asm__ __volatile__ (
1661 "in __tmp_reg__,__SREG__" "\n\t"
1662 "cli" "\n\t"
1663 "out %1, %0" "\n\t"
1664 "out %1, %2" "\n\t"
1665 "out __SREG__, __tmp_reg__"
1666 : /* no outputs */
1667 : "d" ((uint8_t) (1 << CLKPCE)),
1668 "I" (_SFR_IO_ADDR(CLKPR)),
1669 "d" ((uint8_t) __x)
1670 : "r0", "memory");
1671}
1672
1673
1674#define clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))
1675
1676#elif defined(__AVR_ATtiny441__) \
1677|| defined(__AVR_ATtiny841__)
1678
1679typedef enum
1680{
1681 clock_div_1 = 0,
1682 clock_div_2 = 1,
1683 clock_div_4 = 2,
1684 clock_div_8 = 3,
1685 clock_div_16 = 4,
1686 clock_div_32 = 5,
1687 clock_div_64 = 6,
1688 clock_div_128 = 7,
1689 clock_div_256 = 8
1690} clock_div_t;
1691
1692static __ATTR_ALWAYS_INLINE__ void clock_prescale_set (clock_div_t);
1693
1694void clock_prescale_set (clock_div_t __x)
1695{
1696 __asm__ __volatile__ (
1697 "in __tmp_reg__,__SREG__" "\n\t"
1698 "cli" "\n\t"
1699 "sts %2, %3" "\n\t"
1700 "sts %1, %0" "\n\t"
1701 "out __SREG__, __tmp_reg__"
1702 : /* no outputs */
1703 : "r" ((uint8_t) __x),
1704 "n" (_SFR_MEM_ADDR(CLKPR)),
1705 "n" (_SFR_MEM_ADDR(CCP)),
1706 "r" ((uint8_t) 0xD8)
1707 : "r0", "memory");
1708}
1709
1710#define clock_prescale_get() (clock_div_t) (CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))
1711
1712#elif defined(__AVR_ATmega64__) \
1713|| defined(__AVR_ATmega103__) \
1714|| defined(__AVR_ATmega128__)
1715
1716//Enum is declared for code compatibility
1717typedef enum
1718{
1719 clock_div_1 = 1,
1720 clock_div_2 = 2,
1721 clock_div_4 = 4,
1722 clock_div_8 = 8,
1723 clock_div_16 = 16,
1724 clock_div_32 = 32,
1725 clock_div_64 = 64,
1726 clock_div_128 = 128
1727} clock_div_t;
1728
1729static __ATTR_ALWAYS_INLINE__ void clock_prescale_set(clock_div_t);
1730
1731void clock_prescale_set(clock_div_t __x)
1732{
1733 if ((uint8_t) __x <= 0 || (uint8_t) __x > 129)
1734 {
1735 return;//Invalid value.
1736 }
1737 else
1738 {
1739 uint8_t __tmp = 0;
1740 //Algo explained:
1741 //1 - Clear XDIV in order for it to accept a new value (actually only
1742 // XDIVEN need to be cleared, but clearing XDIV is faster than
1743 // read-modify-write since we will rewrite XDIV later anyway)
1744 //2 - wait 8 clock cycle for stability, see datasheet errata
1745 //3 - Exit if requested prescaler is 1
1746 //4 - Calculate XDIV6..0 value = 129 - __x
1747 //5 - Set XDIVEN bit in calculated value
1748 //6 - write XDIV with calculated value
1749 //7 - wait 8 clock cycle for stability, see datasheet errata
1750 __asm__ __volatile__ (
1751 "in __tmp_reg__,__SREG__" "\n\t"
1752 "cli" "\n\t"
1753 "out %2, __zero_reg__" "\n\t"
1754 "nop" "\n\t"
1755 "nop" "\n\t"
1756 "nop" "\n\t"
1757 "nop" "\n\t"
1758 "nop" "\n\t"
1759 "nop" "\n\t"
1760 "nop" "\n\t"
1761 "nop" "\n\t"
1762 "cpi %1, 0x01" "\n\t"
1763 "breq L_%=" "\n\t"
1764 "ldi %0, 0x81" "\n\t" //129
1765 "sub %0, %1" "\n\t"
1766 "ori %0, 0x80" "\n\t" //128
1767 "out %2, %0" "\n\t"
1768 "nop" "\n\t"
1769 "nop" "\n\t"
1770 "nop" "\n\t"
1771 "nop" "\n\t"
1772 "nop" "\n\t"
1773 "nop" "\n\t"
1774 "nop" "\n\t"
1775 "nop" "\n\t"
1776 "L_%=: " "out __SREG__, __tmp_reg__"
1777 : "=d" (__tmp)
1778 : "d" ((uint8_t) __x),
1779 "I" (_SFR_IO_ADDR(XDIV))
1780 : "r0", "memory");
1781 }
1782}
1783
1784static __ATTR_ALWAYS_INLINE__ clock_div_t clock_prescale_get(void);
1785
1786clock_div_t clock_prescale_get(void)
1787{
1788 if (bit_is_clear(XDIV, XDIVEN))
1789 {
1790 return (clock_div_t) 1;
1791 }
1792 else
1793 {
1794 return (clock_div_t) (129 - (XDIV & 0x7F));
1795 }
1796}
1797
1798#elif defined(__AVR_ATtiny4__) \
1799|| defined(__AVR_ATtiny5__) \
1800|| defined(__AVR_ATtiny9__) \
1801|| defined(__AVR_ATtiny10__) \
1802|| defined(__AVR_ATtiny102__) \
1803|| defined(__AVR_ATtiny104__) \
1804|| defined(__AVR_ATtiny20__) \
1805|| defined(__AVR_ATtiny40__) \
1806
1807typedef enum
1808{
1809 clock_div_1 = 0,
1810 clock_div_2 = 1,
1811 clock_div_4 = 2,
1812 clock_div_8 = 3,
1813 clock_div_16 = 4,
1814 clock_div_32 = 5,
1815 clock_div_64 = 6,
1816 clock_div_128 = 7,
1817 clock_div_256 = 8
1818} clock_div_t;
1819
1820static __ATTR_ALWAYS_INLINE__ void clock_prescale_set(clock_div_t);
1821
1822void clock_prescale_set(clock_div_t __x)
1823{
1824 __asm__ __volatile__ (
1825 "in __tmp_reg__,__SREG__" "\n\t"
1826 "cli" "\n\t"
1827 "out %1, %0" "\n\t"
1828 "out %2, %3" "\n\t"
1829 "out __SREG__, __tmp_reg__"
1830 : /* no outputs */
1831 : "d" ((uint8_t) 0xD8),
1832 "I" (_SFR_IO_ADDR(CCP)),
1833 "I" (_SFR_IO_ADDR(CLKPSR)),
1834 "d" ((uint8_t) __x)
1835 : "r16", "memory");
1836}
1837
1838#define clock_prescale_get() (clock_div_t)(CLKPSR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))
1839
1840#endif
1841
1842#endif /* _AVR_POWER_H_ */
#define clock_prescale_get()
Definition: power.h:1440
static void power_all_enable()
static void power_all_disable()
void clock_prescale_set(clock_div_t __x)
Definition: power.h:1415
#define _BV(bit)
Definition: sfr_defs.h:206
#define bit_is_clear(sfr, bit)
Definition: sfr_defs.h:243
unsigned char uint8_t
Definition: stdint.h:81