Skip to content

Commit d66dfcb

Browse files
authored
Merge pull request #7036 from maciejbocianski/hal_ticker_feature_merging
tests-mbed_hal-sleep fix
2 parents 245a9aa + 53548e2 commit d66dfcb

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

TESTS/mbed_hal/sleep/main.cpp

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

17-
#if 1 || !DEVICE_SLEEP
17+
#if !DEVICE_SLEEP
1818
#error [NOT_SUPPORTED] sleep not supported for this target
1919
#endif
2020

@@ -37,7 +37,12 @@ using namespace utest::v1;
3737

3838
/* Used for regular sleep mode, a target should be awake within 10 us. Define us delta value as follows:
3939
* delta = default 10 us + worst ticker resolution + extra time for code execution */
40+
#if defined(MBED_CPU_STATS_ENABLED)
41+
/* extra 25us for stats computation (for more details see MBED_CPU_STATS_ENABLED) */
42+
static const uint32_t sleep_mode_delta_us = (10 + 4 + 5 + 25);
43+
#else
4044
static const uint32_t sleep_mode_delta_us = (10 + 4 + 5);
45+
#endif
4146

4247
/* Used for deep-sleep mode, a target should be awake within 10 ms. Define us delta value as follows:
4348
* delta = default 10 ms + worst ticker resolution + extra time for code execution */
@@ -98,13 +103,23 @@ void lp_ticker_isr(const ticker_data_t *const ticker_data)
98103
* high frequency ticker interrupt can wake-up target from sleep. */
99104
void sleep_usticker_test()
100105
{
101-
#if 0
102106
const ticker_data_t * ticker = get_us_ticker_data();
103107
const unsigned int ticker_freq = ticker->interface->get_info()->frequency;
104108
const unsigned int ticker_width = ticker->interface->get_info()->bits;
105109

106110
const ticker_irq_handler_type us_ticker_irq_handler_org = set_us_ticker_irq_handler(us_ticker_isr);
107111

112+
// call ticker_read_us to initialize ticker upper layer
113+
// prevents subsequent scheduling of max_delta interrupt during ticker initialization while test execution
114+
// (e.g when ticker_read_us is called)
115+
ticker_read_us(ticker);
116+
#ifdef DEVICE_LPTICKER
117+
// call ticker_read_us to initialize lp_ticker
118+
// prevents scheduling interrupt during ticker initialization (in lp_ticker_init) while test execution
119+
// (e.g when ticker_read_us is called for lp_ticker, see MBED_CPU_STATS_ENABLED)
120+
ticker_read_us(get_lp_ticker_data());
121+
#endif
122+
108123
/* Test only sleep functionality. */
109124
sleep_manager_lock_deep_sleep();
110125
TEST_ASSERT_FALSE_MESSAGE(sleep_manager_can_deep_sleep(), "deep sleep should be locked");
@@ -130,7 +145,6 @@ void sleep_usticker_test()
130145

131146
sleep_manager_unlock_deep_sleep();
132147
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
133-
#endif
134148
}
135149

136150
#ifdef DEVICE_LPTICKER
@@ -143,6 +157,11 @@ void deepsleep_lpticker_test()
143157
const unsigned int ticker_freq = ticker->interface->get_info()->frequency;
144158
const unsigned int ticker_width = ticker->interface->get_info()->bits;
145159

160+
// call ticker_read_us to initialize ticker upper layer
161+
// prevents subsequent scheduling of max_delta interrupt during ticker initialization while test execution
162+
// (e.g when ticker_read_us is called)
163+
ticker_read_us(ticker);
164+
146165
const ticker_irq_handler_type lp_ticker_irq_handler_org = set_lp_ticker_irq_handler(lp_ticker_isr);
147166

148167
/* Give some time Green Tea to finish UART transmission before entering

0 commit comments

Comments
 (0)