Skip to content

Commit 501a7b6

Browse files
authored
Merge pull request #7009 from bulislaw/merge_feature_branches_for_5.9
Bring in improved HAL APIs to master
2 parents 9c62ea3 + 4ae6491 commit 501a7b6

File tree

155 files changed

+6083
-3646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+6083
-3646
lines changed

TESTS/events/queue/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@
2020
#include "unity.h"
2121
#include "utest.h"
2222

23+
#if !DEVICE_USTICKER
24+
#error [NOT_SUPPORTED] test not supported
25+
#endif
26+
2327
using namespace utest::v1;
2428

29+
// Assume that tolerance is 5% of measured time.
30+
#define DELTA(ms) (ms / 20)
31+
2532
// TEST_EQUEUE_SIZE was reduced below 1024B to fit this test to devices with small RAM (RAM <= 16kB)
2633
// additionally TEST_EQUEUE_SIZE was expressed in EVENTS_EVENT_SIZE to increase readability
2734
// (for more details about EVENTS_EVENT_SIZE see EventQueue constructor)
@@ -89,7 +96,7 @@ SIMPLE_POSTS_TEST(0)
8996

9097

9198
void time_func(Timer *t, int ms) {
92-
TEST_ASSERT_INT_WITHIN(5, ms, t->read_ms());
99+
TEST_ASSERT_INT_WITHIN(DELTA(ms), ms, t->read_ms());
93100
t->reset();
94101
}
95102

TESTS/events/timing/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
using namespace utest::v1;
2626

27+
#if !DEVICE_USTICKER
28+
#error [NOT_SUPPORTED] test not supported
29+
#endif
2730

2831
// Test delay
2932
#ifndef TEST_EVENTS_TIMING_TIME

TESTS/host_tests/rtc_reset.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
"""
2+
mbed SDK
3+
Copyright (c) 2017-2017 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
from __future__ import print_function
18+
19+
from mbed_host_tests import BaseHostTest
20+
from time import sleep
21+
22+
23+
class RtcResetTest(BaseHostTest):
24+
"""This test checks that a device's RTC keeps count through a reset
25+
26+
It does this by setting the RTC's time, triggering a reset,
27+
delaying and then reading the RTC's time again to ensure
28+
that the RTC is still counting.
29+
"""
30+
31+
"""Start of the RTC"""
32+
START_TIME = 50000
33+
START_TIME_TOLERANCE = 10
34+
"""Time to delay after sending reset"""
35+
DELAY_TIME = 5.0
36+
DELAY_TOLERANCE = 1.0
37+
VALUE_PLACEHOLDER = "0"
38+
39+
def setup(self):
40+
"""Register callbacks required for the test"""
41+
self._error = False
42+
generator = self.rtc_reset_test()
43+
generator.next()
44+
45+
def run_gen(key, value, time):
46+
"""Run the generator, and fail testing if the iterator stops"""
47+
if self._error:
48+
return
49+
try:
50+
generator.send((key, value, time))
51+
except StopIteration:
52+
self._error = True
53+
54+
for resp in ("start", "read", "ack"):
55+
self.register_callback(resp, run_gen)
56+
57+
def teardown(self):
58+
"""No work to do here"""
59+
pass
60+
61+
def rtc_reset_test(self):
62+
"""Generator for running the reset test
63+
64+
This function calls yield to wait for the next event from
65+
the device. If the device gives the wrong response, then the
66+
generator terminates by returing which raises a StopIteration
67+
exception and fails the test.
68+
"""
69+
70+
# Wait for start token
71+
key, value, time = yield
72+
if key != "start":
73+
return
74+
75+
# Initialize, and set the time
76+
self.send_kv("init", self.VALUE_PLACEHOLDER)
77+
78+
# Wait for ack from the device
79+
key, value, time = yield
80+
if key != "ack":
81+
return
82+
83+
self.send_kv("write", str(self.START_TIME))
84+
85+
# Wait for ack from the device
86+
key, value, time = yield
87+
if key != "ack":
88+
return
89+
90+
self.send_kv("read", self.VALUE_PLACEHOLDER)
91+
key, value, time = yield
92+
if key != "read":
93+
return
94+
dev_time_start = int(value)
95+
96+
# Unitialize, and reset
97+
self.send_kv("free", self.VALUE_PLACEHOLDER)
98+
99+
# Wait for ack from the device
100+
key, value, time = yield
101+
if key != "ack":
102+
return
103+
104+
self.send_kv("reset", self.VALUE_PLACEHOLDER)
105+
106+
# No ack after reset
107+
sleep(self.DELAY_TIME)
108+
109+
# Restart the test, and send the sync token
110+
self.send_kv("__sync", "00000000-0000-000000000-000000000000")
111+
key, value, time = yield
112+
if key != "start":
113+
return
114+
115+
# Initialize, and read the time
116+
self.send_kv("init", self.VALUE_PLACEHOLDER)
117+
118+
# Wait for ack from the device
119+
key, value, time = yield
120+
if key != "ack":
121+
return
122+
123+
self.send_kv("read", self.VALUE_PLACEHOLDER)
124+
key, value, time = yield
125+
if key != "read":
126+
return
127+
dev_time_end = int(value)
128+
129+
# Check result
130+
elapsed = dev_time_end - dev_time_start
131+
start_time_valid = (self.START_TIME <= dev_time_start <
132+
self.START_TIME + self.START_TIME_TOLERANCE)
133+
elapsed_time_valid = elapsed >= self.DELAY_TIME - self.DELAY_TOLERANCE
134+
passed = start_time_valid and elapsed_time_valid
135+
if not start_time_valid:
136+
self.log("FAIL: Expected start time of %i got %i" %
137+
(self.START_TIME, dev_time_start))
138+
elif not passed:
139+
self.log("FAIL: Delayed for %fs but device "
140+
"reported elapsed time of %fs" %
141+
(self.DELAY_TIME, elapsed))
142+
self.send_kv("exit", "pass" if passed else "fail")
143+
yield # No more events expected
144+

TESTS/mbed_drivers/lp_ticker/main.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "unity/unity.h"
2020

2121

22-
#if !DEVICE_LOWPOWERTIMER
22+
#if !DEVICE_LPTICKER
2323
#error [NOT_SUPPORTED] Low power ticker not supported for this target
2424
#endif
2525

@@ -33,8 +33,9 @@ static const int test_timeout = 10;
3333
/* Due to poor accuracy of LowPowerTicker on many platforms
3434
there is no sense to tune tolerance value as it was in Ticker tests.
3535
36-
Tolerance value is set to 2000us to cover this diversity */
37-
#define TOLERANCE_US 2000
36+
Tolerance value is set to 600us for measurement inaccuracy + 5% tolerance
37+
for LowPowerTicker. */
38+
#define TOLERANCE_US(DELAY) (600 + DELAY / 20)
3839

3940

4041
volatile uint32_t ticker_callback_flag;
@@ -117,7 +118,7 @@ void test_multi_call_time(void)
117118
while(!ticker_callback_flag);
118119
time_diff = gtimer.read_us();
119120

120-
TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US, MULTI_TICKER_TIME_MS * 1000, time_diff);
121+
TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US(MULTI_TICKER_TIME_MS * 1000), MULTI_TICKER_TIME_MS * 1000, time_diff);
121122
}
122123
}
123124

@@ -167,7 +168,7 @@ void test_attach_time(void)
167168
ticker.detach();
168169
const int time_diff = gtimer.read_us();
169170

170-
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US, DELAY_US, time_diff);
171+
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US(DELAY_US), DELAY_US, time_diff);
171172
}
172173

173174
/** Test single callback time via attach_us
@@ -189,7 +190,7 @@ void test_attach_us_time(void)
189190
ticker.detach();
190191
const int time_diff = gtimer.read_us();
191192

192-
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US, DELAY_US, time_diff);
193+
TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US(DELAY_US), DELAY_US, time_diff);
193194
}
194195

195196
// Test cases

TESTS/mbed_drivers/lp_timeout/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#if !DEVICE_LOWPOWERTIMER
18-
#error [NOT_SUPPORTED] Low power timer not supported for this target
17+
#if !DEVICE_LPTICKER
18+
#error [NOT_SUPPORTED] Low power timer not supported for this target
1919
#endif
2020

2121
#include "mbed.h"

0 commit comments

Comments
 (0)