-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleep.hpp
29 lines (22 loc) · 1.13 KB
/
sleep.hpp
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
#ifndef CAVE_SLEEPER_SLEEP_HPP
#define CAVE_SLEEPER_SLEEP_HPP
#include "print.hpp"
#include <avr/sleep.h>
namespace cvslpr {
[[nodiscard]] bool
init_sleep();
// Necessary order of instructions in order to avoid race conditions.
// See <avr/sleep.h> for more information.
#define go_sleep(condition) \
cli(); \
if (condition) { \
msg_println(F("Sleeping...")); \
sleep_enable(); \
sei(); \
sleep_cpu(); \
sleep_disable(); \
} \
sei(); \
msg_println(F("In awake mode."));
} // namespace cvslpr
#endif