Skip to content

Ticker requirement and test update #5884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions TESTS/mbed_hal/lp_us_tickers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
#define TICKER_INT_VAL 2000
#define TICKER_DELTA 50

#if DEVICE_LOWPOWERTIMER
#define TICKER_OVERFLOW_DELTA 0 // this will allow to detect that ticker counter rollovers to 0
#else
#define TICKER_OVERFLOW_DELTA 50
#endif
#define LP_TICKER_OVERFLOW_DELTA 0 // this will allow to detect that ticker counter rollovers to 0
#define HF_TICKER_OVERFLOW_DELTA 50

#define TICKER_100_TICKS 100

Expand All @@ -47,6 +44,8 @@ using namespace utest::v1;

volatile int intFlag = 0;
const ticker_interface_t* intf;
unsigned int ticker_overflow_delta;


/* Auxiliary function to count ticker ticks elapsed during execution of N cycles of empty while loop.
* Parameter <step> is used to disable compiler optimisation. */
Expand Down Expand Up @@ -92,7 +91,7 @@ void wait_cycles(volatile unsigned int cycles)
}

/* Test that ticker_init can be called multiple times and
* ticker_init resets the internal count and disables the ticker interrupt.
* ticker_init allows the ticker to keep counting and disables the ticker interrupt.
*/
void ticker_init_test()
{
Expand All @@ -118,7 +117,7 @@ void ticker_init_test()
}

TEST_ASSERT(intf->read() >= (ticks_start + 2 * TICKER_INT_VAL));
TEST_ASSERT(ticks_start > ticks_after_reinit);
TEST_ASSERT(ticks_start <= ticks_after_reinit);
TEST_ASSERT_EQUAL(0, intFlag);
}

Expand Down Expand Up @@ -260,12 +259,12 @@ void ticker_overflow_test(void)
intf->init();

/* Wait for max count. */
while (intf->read() != (max_count - TICKER_OVERFLOW_DELTA)) {
while (intf->read() != (max_count - ticker_overflow_delta)) {
/* Just wait. */
}

/* Now we are near/at the overflow point. Detect rollover. */
while (intf->read() > TICKER_OVERFLOW_DELTA);
while (intf->read() > ticker_overflow_delta);

const uint32_t after_overflow = intf->read();

Expand All @@ -277,7 +276,7 @@ void ticker_overflow_test(void)
const uint32_t next_after_overflow = intf->read();

/* Check that after the overflow ticker continue count. */
TEST_ASSERT(after_overflow <= TICKER_OVERFLOW_DELTA);
TEST_ASSERT(after_overflow <= ticker_overflow_delta);
TEST_ASSERT(next_after_overflow >= TICKER_100_TICKS);
TEST_ASSERT_EQUAL(0, intFlag);

Expand Down Expand Up @@ -399,6 +398,8 @@ utest::v1::status_t hf_ticker_setup(const Case *const source, const size_t index

set_us_ticker_irq_handler(ticker_event_handler_stub);

ticker_overflow_delta = HF_TICKER_OVERFLOW_DELTA;

return greentea_case_setup_handler(source, index_of_case);
}

Expand All @@ -409,6 +410,8 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index

set_lp_ticker_irq_handler(ticker_event_handler_stub);

ticker_overflow_delta = LP_TICKER_OVERFLOW_DELTA;

return greentea_case_setup_handler(source, index_of_case);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion TESTS/mbed_hal/lp_us_tickers/ticker_api_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern "C" {
*
* Given ticker is initialised and interrupt is set.
* When ticker is re-initialised.
* Then ticker resets the internal count and disables the ticker interrupt.
* Then ticker keeps counting and disables the ticker interrupt.
*/
void ticker_init_test(void);

Expand Down
2 changes: 1 addition & 1 deletion hal/us_ticker_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern "C" {
*
* # Defined behavior
* * The function ticker_init is safe to call repeatedly - Verified by test ::ticker_init_test
* * The function ticker_init resets the internal count and disables the ticker interrupt - Verified by test ::ticker_init_test
* * The function ticker_init allows the ticker to keep counting and disables the ticker interrupt - Verified by test ::ticker_init_test
* * Ticker frequency is non-zero and counter is at least 8 bits - Verified by ::ticker_info_test
* * The ticker rolls over at (1 << bits) and continues counting starting from 0 - Verified by ::ticker_overflow_test
* * The ticker counts at the specified frequency +- 10% - Verified by ::ticker_frequency_test
Expand Down