mirror of https://github.com/ARMmbed/mbed-os.git
lp_us_tickers test: fix `increment test` for slow boards
Increment test proves that ticker counter is incremented by one. This is done indirectly for high frequency counters where it is impossible to read 'value' and 'value + 1' in two successive ticker reads. This check is done indirectly by counting ticker ticks elapsed during execution of N cycles of empty while loop. Unfortunately on slow boards with fast tickers like NRF51_DK(16 MHz CPU/1MHz hf ticker) it is possible that for the same N cycles measured number of elapsed ticks in two successive calls is greater than 1. This patch provides fix for such case - measure operation is repeated with the same number of cycles.pull/7009/head
parent
a92ff94904
commit
0ecf58f51c
|
@ -46,13 +46,15 @@ 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. */
|
||||
uint32_t count_ticks(uint32_t cycles, uint32_t step)
|
||||
{
|
||||
register uint32_t reg_cycles = cycles;
|
||||
|
||||
const ticker_info_t* p_ticker_info = intf->get_info();
|
||||
const uint32_t max_count = ((1 << p_ticker_info->bits) - 1);
|
||||
|
||||
core_util_critical_section_enter();
|
||||
|
||||
const uint32_t start = intf->read();
|
||||
|
@ -65,7 +67,10 @@ uint32_t count_ticks(uint32_t cycles, uint32_t step)
|
|||
|
||||
core_util_critical_section_exit();
|
||||
|
||||
return (stop - start);
|
||||
/* Handle overflow - overflow protection may not work in this case. */
|
||||
uint32_t diff = (start <= stop) ? (stop - start) : (uint32_t)(max_count - start + stop);
|
||||
|
||||
return (diff);
|
||||
}
|
||||
|
||||
void ticker_event_handler_stub(const ticker_data_t * const ticker)
|
||||
|
@ -302,9 +307,23 @@ void ticker_increment_test(void)
|
|||
uint32_t next_tick_count = base_tick_count;
|
||||
uint32_t inc_val = 0;
|
||||
|
||||
while (next_tick_count == base_tick_count) {
|
||||
while (inc_val < 100) {
|
||||
next_tick_count = count_ticks(NUM_OF_CYCLES + inc_val, 1);
|
||||
|
||||
if (next_tick_count == base_tick_count) {
|
||||
/* Same tick count, so increase num of cycles. */
|
||||
inc_val++;
|
||||
} else {
|
||||
/* It is possible that the difference between base and next
|
||||
* tick count on some platforms is greater that 1, in this case we need
|
||||
* to repeat counting with the same number of cycles.
|
||||
* In cases if difference is exactly 1 we can exit the loop.
|
||||
*/
|
||||
if (next_tick_count - base_tick_count == 1 ||
|
||||
base_tick_count - next_tick_count == 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Since we are here we know that next_tick_count != base_tick_count.
|
||||
|
|
Loading…
Reference in New Issue