1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// RustDuino : A generic HAL implementation for Arduino Boards in Rust
// Copyright (C) 2021 Akshit Verma, Indian Institute of Technology Kanpur
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>
//! Power management for ATmega328p chip using sleep modes.
//! Section 9.11 of ATmega328p Datasheet is to be used.
use core;
/// Contains sleep modes.
/// # Modes Explanantion
/// * **Idle**: This mode makes the MCU enter idle mode, stopping the CPU but
/// allowing the SPI, USART, analog comparator, ADC, 2-wire serial
/// interface, Timer/Counters, watchdog, and the interrupt system
/// to continue operating. This sleep mode basically halts clkCPU
/// and clkFLASH, while allowing the other clocks to run.
/// * **ADCNR**: ADC Noise Reducion mode makes the MCU enter ADC noise reduction
/// mode, stopping the CPU but allowing the ADC, the external interrupts,
/// the 2-wire serial interface address watch, Timer/Counter2, and the
/// watchdog to continue operating (if enabled). This sleep mode
/// basically halts clkI/O, clkCPU, and clkFLASH, while allowing the
/// other clocks to run.
/// * **PowerDown**: Power Down mode makes the MCU enter power-down mode. In this mode, the
/// external oscillator is stopped, while the external interrupts, the
/// 2-wire serial interface address watch, and the watchdog continue
/// operating (if enabled). Only an external reset, a watchdog system
/// reset, a watchdog interrupt, a brown-out reset, a 2-wire serial
/// interface address match, an external level interrupt on INT0 or INT1,
/// or a pin change interrupt can wake up the MCU. This sleep mode basically
/// halts all generated clocks, allowing operation of asynchronous modules only.
/// * **PowerSave**: Power Save mode is identical to Power Down, with one exception:
///
/// If Timer/Counter2 is enabled, it will keep running during sleep. The
/// device can wake up from either timer overflow or output compare event
/// from Timer/Counter2 if the corresponding Timer/Counter2 interrupt enable
/// bits are set in TIMSK2, and the global interrupt enable bit in SREG is set.
/// * **Standby**: It is identical to Power Down, with one exception:
///
/// If Timer/Counter2 is enabled, it will keep running during sleep. The device
// can wake up from either timer overflow or output compare event from
/// Timer/Counter2 if the corresponding Timer/Counter2 interrupt enable bits
/// are set in TIMSK2, and the global interrupt enable bit in SREG is set.
/// * **ExtStandby**: Extendend Standby mode is identical to Power Save with the exception that
/// the oscillator is kept running. From extended standby mode, the device
/// wakes up in six clock cycles.
/// * **Disable**: Disables the sleep mode.
/// Contains registers controlling power management.
/// Enables the Chosen power mode.
/// # Arguments
/// * `mode` - a `SleepMode` object, to select the mode to be activated.