Skip to content

Commit 4cb47df

Browse files
committed
Add system_reset() function to Mbed OS
1 parent eaf6f81 commit 4cb47df

File tree

25 files changed

+222
-189
lines changed

25 files changed

+222
-189
lines changed

drivers/CAN.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#if DEVICE_CAN
1919

2020
#include "cmsis.h"
21-
#include "platform/mbed_sleep.h"
21+
#include "platform/mbed_power_mgmt.h"
2222

2323
namespace mbed {
2424

drivers/I2C.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#if DEVICE_I2C
1919

2020
#if DEVICE_I2C_ASYNCH
21-
#include "platform/mbed_sleep.h"
21+
#include "platform/mbed_power_mgmt.h"
2222
#endif
2323

2424
namespace mbed {

drivers/PwmOut.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#if defined (DEVICE_PWMOUT) || defined(DOXYGEN_ONLY)
2222
#include "hal/pwmout_api.h"
2323
#include "platform/mbed_critical.h"
24-
#include "platform/mbed_sleep.h"
24+
#include "platform/mbed_power_mgmt.h"
2525

2626
namespace mbed {
2727
/** \addtogroup drivers */

drivers/SPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "platform/mbed_critical.h"
1818

1919
#if DEVICE_SPI_ASYNCH
20-
#include "platform/mbed_sleep.h"
20+
#include "platform/mbed_power_mgmt.h"
2121
#endif
2222

2323
#if DEVICE_SPI

drivers/SerialBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "drivers/SerialBase.h"
1717
#include "platform/mbed_wait_api.h"
1818
#include "platform/mbed_critical.h"
19-
#include "platform/mbed_sleep.h"
19+
#include "platform/mbed_power_mgmt.h"
2020

2121
#if DEVICE_SERIAL
2222

drivers/Ticker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "platform/Callback.h"
2121
#include "platform/mbed_toolchain.h"
2222
#include "platform/NonCopyable.h"
23-
#include "platform/mbed_sleep.h"
23+
#include "platform/mbed_power_mgmt.h"
2424
#include "hal/lp_ticker_api.h"
2525
#include "platform/mbed_critical.h"
2626

drivers/Timeout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "drivers/Ticker.h"
2020
#include "platform/NonCopyable.h"
21-
#include "platform/mbed_sleep.h"
21+
#include "platform/mbed_power_mgmt.h"
2222

2323
namespace mbed {
2424
/** \addtogroup drivers */

drivers/Timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "platform/platform.h"
2020
#include "hal/ticker_api.h"
2121
#include "platform/NonCopyable.h"
22-
#include "platform/mbed_sleep.h"
22+
#include "platform/mbed_power_mgmt.h"
2323

2424
namespace mbed {
2525
/** \addtogroup drivers */

features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <string.h>
1919

2020
#include "mbed.h"
21-
#include "mbed_sleep.h"
21+
#include "mbed_power_mgmt.h"
2222
#include "ns_types.h"
2323
#include "platform/arm_hal_interrupt.h"
2424
#include "nanostack/platform/arm_hal_phy.h"

hal/mbed_sleep_manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "mbed_sleep.h"
17+
#include "mbed_power_mgmt.h"
1818
#include "mbed_critical.h"
1919
#include "sleep_api.h"
2020
#include "mbed_error.h"

mbed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
#include "drivers/InterruptIn.h"
8383
#include "platform/mbed_wait_api.h"
8484
#include "hal/sleep_api.h"
85-
#include "platform/mbed_sleep.h"
85+
#include "platform/mbed_power_mgmt.h"
8686
#include "platform/mbed_rtc_time.h"
8787
#include "platform/mbed_poll.h"
8888
#include "platform/ATCmdParser.h"

platform/DeepSleepLock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define MBED_DEEPSLEEPLOCK_H
1818

1919
#include <limits.h>
20-
#include "platform/mbed_sleep.h"
20+
#include "platform/mbed_power_mgmt.h"
2121
#include "platform/mbed_critical.h"
2222

2323
namespace mbed {

platform/mbed_interface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ int mbed_interface_powerdown(void) {
7171
}
7272
}
7373

74-
// for backward compatibility
74+
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code."
75+
"For system reset funcionality use system_reset()")
7576
void mbed_reset(void) {
7677
mbed_interface_reset();
7778
}

platform/mbed_power_mgmt.h

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/** \addtogroup platform */
2+
/** @{*/
3+
/**
4+
* \defgroup platform_power_mgmt Power management functions
5+
* @{
6+
*/
7+
8+
/* mbed Microcontroller Library
9+
* Copyright (c) 2006-2018 ARM Limited
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
#ifndef MBED_POWER_MGMT_H
24+
#define MBED_POWER_MGMT_H
25+
26+
#include "hal/sleep_api.h"
27+
#include "mbed_toolchain.h"
28+
#include <stdbool.h>
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
/** Sleep manager API
35+
* The sleep manager provides API to automatically select sleep mode.
36+
*
37+
* There are two sleep modes:
38+
* - sleep
39+
* - deepsleep
40+
*
41+
* Use locking/unlocking deepsleep for drivers that depend on features that
42+
* are not allowed (=disabled) during the deepsleep. For instance, high frequency
43+
* clocks.
44+
*
45+
* Example:
46+
* @code
47+
*
48+
* void driver::handler()
49+
* {
50+
* if (_sensor.get_event()) {
51+
* // any event - we are finished, unlock the deepsleep
52+
* sleep_manager_unlock_deep_sleep();
53+
* _callback();
54+
* }
55+
* }
56+
*
57+
* int driver::measure(event_t event, callback_t& callback)
58+
* {
59+
* _callback = callback;
60+
* sleep_manager_lock_deep_sleep();
61+
* // start async transaction, we are waiting for an event
62+
* return _sensor.start(event, callback);
63+
* }
64+
* @endcode
65+
*/
66+
67+
/** Lock the deep sleep mode
68+
*
69+
* This locks the automatic deep mode selection.
70+
* sleep_manager_sleep_auto() will ignore deepsleep mode if
71+
* this function is invoked at least once (the internal counter is non-zero)
72+
*
73+
* Use this locking mechanism for interrupt driven API that are
74+
* running in the background and deepsleep could affect their functionality
75+
*
76+
* The lock is a counter, can be locked up to USHRT_MAX
77+
* This function is IRQ and thread safe
78+
*/
79+
void sleep_manager_lock_deep_sleep(void);
80+
81+
/** Unlock the deep sleep mode
82+
*
83+
* Use unlocking in pair with sleep_manager_lock_deep_sleep().
84+
*
85+
* The lock is a counter, should be equally unlocked as locked
86+
* This function is IRQ and thread safe
87+
*/
88+
void sleep_manager_unlock_deep_sleep(void);
89+
90+
/** Get the status of deep sleep allowance for a target
91+
*
92+
* @return true if a target can go to deepsleep, false otherwise
93+
*/
94+
bool sleep_manager_can_deep_sleep(void);
95+
96+
/** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based
97+
* on the deepsleep locking counter
98+
*
99+
* This function is IRQ and thread safe
100+
*
101+
* @note
102+
* If MBED_DEBUG is defined, only hal_sleep is allowed. This ensures the debugger
103+
* to be active for debug modes.
104+
*
105+
*/
106+
void sleep_manager_sleep_auto(void);
107+
108+
/** Send the microcontroller to sleep
109+
*
110+
* @note This function can be a noop if not implemented by the platform.
111+
* @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined).
112+
* @note This function will be a noop while uVisor is in use.
113+
* @note This function will be a noop if the following conditions are met:
114+
* - The RTOS is present
115+
* - The processor turn off the Systick clock during sleep
116+
* - The target does not implement tickless mode
117+
*
118+
* The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
119+
* system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
120+
* dynamic power used by the processor, memory systems and buses. The processor, peripheral and
121+
* memory state are maintained, and the peripherals continue to work and can generate interrupts.
122+
*
123+
* The processor can be woken up by any internal peripheral interrupt or external pin interrupt.
124+
*
125+
* @note
126+
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
127+
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
128+
* able to access the LocalFileSystem
129+
*/
130+
static inline void sleep(void)
131+
{
132+
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
133+
#if DEVICE_SLEEP
134+
#if (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS)
135+
sleep_manager_sleep_auto();
136+
#endif /* (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS) */
137+
#endif /* DEVICE_SLEEP */
138+
#endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
139+
}
140+
141+
/** Send the microcontroller to deep sleep
142+
*
143+
* @note This function can be a noop if not implemented by the platform.
144+
* @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined)
145+
* @note This function will be a noop while uVisor is in use.
146+
*
147+
* This processor is setup ready for deep sleep, and sent to sleep. This mode
148+
* has the same sleep features as sleep plus it powers down peripherals and clocks. All state
149+
* is still maintained.
150+
*
151+
* The processor can only be woken up by an external interrupt on a pin or a watchdog timer.
152+
*
153+
* @note
154+
* The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.
155+
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
156+
* able to access the LocalFileSystem
157+
*/
158+
159+
MBED_DEPRECATED_SINCE("mbed-os-5.6", "One entry point for an application, use sleep()")
160+
static inline void deepsleep(void)
161+
{
162+
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
163+
#if DEVICE_SLEEP
164+
sleep_manager_sleep_auto();
165+
#endif /* DEVICE_SLEEP */
166+
#endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
167+
}
168+
169+
/** Resets the processor and most of the sub-system
170+
*
171+
* @note Does not affect the debug sub-system
172+
*/
173+
static inline void system_reset(void)
174+
{
175+
NVIC_SystemReset();
176+
}
177+
178+
#ifdef __cplusplus
179+
}
180+
#endif
181+
182+
#endif
183+
184+
/** @}*/
185+
/** @}*/

0 commit comments

Comments
 (0)