Skip to content

Commit 9ddb092

Browse files
authored
Merge pull request #6230 from bulislaw/system_reset
Add system_reset call
2 parents 8f5b857 + 2b83b69 commit 9ddb092

File tree

30 files changed

+349
-225
lines changed

30 files changed

+349
-225
lines changed

TESTS/host_tests/system_reset.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Copyright (c) 2018 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+
import time
17+
from mbed_host_tests import BaseHostTest
18+
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
19+
20+
DEFAULT_CYCLE_PERIOD = 1.0
21+
22+
MSG_VALUE_DUMMY = '0'
23+
24+
MSG_KEY_DEVICE_READY = 'ready'
25+
MSG_KEY_DEVICE_RESET = 'reset'
26+
MSG_KEY_SYNC = '__sync'
27+
28+
class SystemResetTest(BaseHostTest):
29+
"""Test for the system_reset API.
30+
31+
Given a device running code
32+
When the device is restarted using @a system_reset()
33+
Then the device is restarted
34+
"""
35+
36+
def __init__(self):
37+
super(SystemResetTest, self).__init__()
38+
self.reset = False
39+
cycle_s = self.get_config_item('program_cycle_s')
40+
self.program_cycle_s = cycle_s if cycle_s is not None else DEFAULT_CYCLE_PERIOD
41+
42+
self.test_steps_sequence = self.test_steps()
43+
# Advance the coroutine to it's first yield statement.
44+
self.test_steps_sequence.send(None)
45+
46+
def setup(self):
47+
self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready)
48+
49+
def cb_device_ready(self, key, value, timestamp):
50+
"""Acknowledge device rebooted correctly and feed the test execution
51+
"""
52+
self.reset = True
53+
54+
try:
55+
if self.test_steps_sequence.send(value):
56+
self.notify_complete(True)
57+
except (StopIteration, RuntimeError) as exc:
58+
self.notify_complete(False)
59+
60+
def test_steps(self):
61+
"""Reset the device and check the status
62+
"""
63+
system_reset = yield
64+
65+
self.reset = False
66+
self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY)
67+
time.sleep(self.program_cycle_s)
68+
self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
69+
70+
system_reset = yield
71+
72+
if self.reset == False:
73+
raise RuntimeError('Platform did not reset as expected.')
74+
75+
# The sequence is correct -- test passed.
76+
yield True
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 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+
#include "mbed.h"
17+
#include "greentea-client/test_env.h"
18+
#include "unity/unity.h"
19+
20+
#define MSG_VALUE_DUMMY "0"
21+
#define MSG_VALUE_LEN 16
22+
#define MSG_KEY_LEN 16
23+
24+
#define MSG_KEY_DEVICE_READY "ready"
25+
#define MSG_KEY_DEVICE_RESET "reset"
26+
27+
void test_system_reset()
28+
{
29+
// Report readiness
30+
greentea_send_kv(MSG_KEY_DEVICE_READY, MSG_VALUE_DUMMY);
31+
32+
static char _key[MSG_KEY_LEN + 1] = { };
33+
static char _value[MSG_VALUE_LEN + 1] = { };
34+
35+
greentea_parse_kv(_key, _value, MSG_KEY_LEN, MSG_VALUE_LEN);
36+
if (strcmp(_key, MSG_KEY_DEVICE_RESET) == 0) {
37+
system_reset();
38+
TEST_ASSERT_MESSAGE(0, "system_reset() did not reset the device as expected.");
39+
}
40+
41+
TEST_ASSERT_MESSAGE(0, "Unexpected message key.");
42+
}
43+
44+
int main(void)
45+
{
46+
GREENTEA_SETUP(2, "system_reset");
47+
test_system_reset();
48+
GREENTEA_TESTSUITE_RESULT(0); // Fail on any error.
49+
50+
return 0;
51+
}

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
@@ -83,7 +83,7 @@
8383
#include "drivers/InterruptIn.h"
8484
#include "platform/mbed_wait_api.h"
8585
#include "hal/sleep_api.h"
86-
#include "platform/mbed_sleep.h"
86+
#include "platform/mbed_power_mgmt.h"
8787
#include "platform/mbed_rtc_time.h"
8888
#include "platform/mbed_poll.h"
8989
#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
}

0 commit comments

Comments
 (0)