lp_us_tickers test - fix count_ticks() function to give the same results on all compilers

count_ticks() function counts ticker ticks elapsed during execution of N cycles of empty while loop.
In current version N value (cycles) is given as volatile paramater in order to disable possible compiler optimalisation.
There was a problem with measured time on different compilers and additionally results on ARM compiler were unexpected (the difference beetween measured elapsed ticks for the same number of cycles was to large). This might be caused by the memory access in order to store updated variable in memory. To fix this issue given numer of cycles has been stored into register and register is decremented (no memory access).

With this fix count_ticks(NUM_OF_CYCLES, 1) call returns 2500 +/-1 for us ticker ticks using each compiler (K64F).
pull/7009/head
Przemyslaw Stekiel 2018-02-13 14:17:47 +00:00 committed by Bartek Szatkowski
parent c4cf1f1eae
commit 6d7aef6bf1
1 changed files with 3 additions and 1 deletions

View File

@ -49,8 +49,10 @@ 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(volatile uint32_t cycles, uint32_t step)
uint32_t count_ticks(uint32_t cycles, uint32_t step)
{
register uint32_t reg_cycles = cycles;
core_util_critical_section_enter();
const uint32_t start = intf->read();