diff --git a/TESTS/mbed_hal/lp_ticker/lp_ticker_api_tests.h b/TESTS/mbed_hal/lp_ticker/lp_ticker_api_tests.h index b4cac3e866..2e9293cb53 100644 --- a/TESTS/mbed_hal/lp_ticker/lp_ticker_api_tests.h +++ b/TESTS/mbed_hal/lp_ticker/lp_ticker_api_tests.h @@ -44,7 +44,13 @@ void lp_ticker_info_test(void); */ void lp_ticker_deepsleep_test(void); - +/** Test that the ticker does not glitch backwards due to an incorrectly implemented ripple counter driver. + * + * Given ticker is available. + * When ticker is enabled and counts. + * Then ticker does not glitch backwards due to an incorrectly implemented ripple counter driver. + */ +void lp_ticker_glitch_test(void); /**@}*/ #ifdef __cplusplus diff --git a/TESTS/mbed_hal/lp_ticker/main.cpp b/TESTS/mbed_hal/lp_ticker/main.cpp index 4be9c11e3d..14794f957b 100644 --- a/TESTS/mbed_hal/lp_ticker/main.cpp +++ b/TESTS/mbed_hal/lp_ticker/main.cpp @@ -86,6 +86,24 @@ void lp_ticker_deepsleep_test() TEST_ASSERT_EQUAL(1, intFlag); } +/* Test that the ticker does not glitch backwards due to an incorrectly implemented ripple counter driver. */ +void lp_ticker_glitch_test() +{ + lp_ticker_init(); + + const ticker_info_t* p_ticker_info = lp_ticker_get_info(); + + uint32_t last = lp_ticker_read(); + const uint32_t start = last; + + /* Set test time to 2 sec. */ + while (last < (start + p_ticker_info->frequency * 2)) { + const uint32_t cur = lp_ticker_read(); + TEST_ASSERT(cur >= last); + last = cur; + } +} + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(20, "default_auto"); @@ -95,6 +113,7 @@ utest::v1::status_t test_setup(const size_t number_of_cases) Case cases[] = { Case("lp ticker info test", lp_ticker_info_test), Case("lp ticker sleep test", lp_ticker_deepsleep_test), + Case("lp ticker glitch test", lp_ticker_glitch_test) }; Specification specification(test_setup, cases); diff --git a/hal/lp_ticker_api.h b/hal/lp_ticker_api.h index c6156a9f28..51eb64f433 100644 --- a/hal/lp_ticker_api.h +++ b/hal/lp_ticker_api.h @@ -43,6 +43,9 @@ extern "C" { * * See the @ref hal_ticker_shared "ticker specification" * * Calling any function other than lp_ticker_init after calling lp_ticker_free * + * # Potential bugs + * * Glitches due to ripple counter - Verified by ::lp_ticker_glitch_test + * * @see hal_lp_ticker_tests * * @{