Skip to content

Commit bc70442

Browse files
committed
platform: add DeepSleepLock
RAII object for disabling, then restoring the deep sleep mode
1 parent 5b33d25 commit bc70442

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

mbed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#include "platform/FileHandle.h"
9191
#include "platform/DirHandle.h"
9292
#include "platform/CriticalSectionLock.h"
93+
#include "platform/DeepSleepLock.h"
9394

9495
// mbed Non-hardware components
9596
#include "platform/Callback.h"

platform/DeepSleepLock.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef MBED_DEEPSLEEPLOCK_H
17+
#define MBED_DEEPSLEEPLOCK_H
18+
19+
#include "platform/mbed_sleep.h"
20+
21+
namespace mbed {
22+
23+
24+
/** RAII object for disabling, then restoring the deep sleep mode
25+
* Usage:
26+
* @code
27+
*
28+
* void f() {
29+
* // some code here
30+
* {
31+
* DeepSleepLock lock;
32+
* // Code in this block will run with the deep sleep mode locked
33+
* }
34+
* // deep sleep mode will be restored to their previous state
35+
* }
36+
* @endcode
37+
*/
38+
class DeepSleepLock {
39+
public:
40+
DeepSleepLock()
41+
{
42+
sleep_manager_lock_deep_sleep();
43+
}
44+
45+
~DeepSleepLock()
46+
{
47+
sleep_manager_unlock_deep_sleep();
48+
}
49+
50+
/** Mark the start of a locked deep sleep section
51+
*/
52+
void lock()
53+
{
54+
sleep_manager_lock_deep_sleep();
55+
}
56+
57+
/** Mark the end of a locked deep sleep section
58+
*/
59+
void unlock()
60+
{
61+
sleep_manager_unlock_deep_sleep();
62+
}
63+
};
64+
65+
}
66+
67+
#endif

0 commit comments

Comments
 (0)