-
Notifications
You must be signed in to change notification settings - Fork 3k
TESTS: common_tickers handle wrap-around case #6462
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
TESTS: common_tickers handle wrap-around case #6462
Conversation
Add documentation and test header for the HAL Ticker API.
…header files. Add one potential bug to the test description. Fix test function names to be consistant with desctiption and test header. Fix typos.
…pecific drivers. Since target specific ticker drivers are not ready also features which uses ticker in upper layers may not work correctly and tests for these features. We need to disable also failing higher level ticker related tests (by adding check if DEVICE_USTICKER symbol is available and raise #error [NOT_SUPPORTED] if not).
Current version: The function ticker_init resets the internal count and disables the ticker interrupt. Proposed version: The function ticker_init allows the ticker to keep counting and disables the ticker interrupt. This is a result of the following discussion: ARMmbed#5233 (review)
The intention was to use ticker_overflow_delta equal to 0 for low power ticker tests and ticker_overflow_delta equal to 50 for high frequency ticker tests. Current implementation is invalid since for devices which provide LOW_POWER_TIMER feature delta is equal to 0 and for devices without this feature delta is equal 50.
- provide ticker configuration: 1MHz/32 bit counter. - us_ticker_init() routine disables interrupts. - adapt comments.
Low power ticker time counter is created based on RTC which is driven by 32KHz clock. Additional low power timer is used to generate interrupts. We need to adapt driver to operate on ticks instead of us. Perform the following updates: - provide lp ticker configuration: 32KHz/32 bit counter. - lp_ticker_init() routine disables lp ticker interrupts . - adapt the driver functions to operate on ticks instead us. - adapt comments. - add us_ticker_free() routine.
Since according to the ticker requirements min acceptable counter size is 12 bits (low power timer) for which max count is 4095, then all test cases must be executed in this time window. HAL ticker layer handles overflow and it is not handled in the target ticker drivers.
On some platforms (e.g. K64F) different counters are used for time measurement and interrupt generation. Because of that we should relax interrupt test case and give additional time before checking if interrupt handler has been executed.
…lts 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).
…pecific drivers. Since target specific ticker drivers are not ready also features which uses ticker in upper layers may not work correctly and tests for these features. We need to disable also failing higher level ticker related tests (by adding check if DEVICE_USTICKER symbol is available and raise #error [NOT_SUPPORTED] if not). Note: tests-mbed_drivers-rtc is new and uses us ticker to perform a delay.
Test that lp ticker does not glitch backwards due to an incorrectly implemented ripple counter driver.
That's to match DEVICE_USTICKER.
The current implementation of tickless requires LPTICKER to be present.
it seems that count_ticks function does not consider the case of a 16 its counter wrap-around - proposal added here.
@LMESTM Interesting that the counter is only 16 bits. Since this is a test, why not simplify things even further and instead increase the size of the counter type? |
Ah, never mind. Just went through your other PR, and now it makes sense why this was set to 16 bits. Something that bothers me. There's now an overflow check, but what happens if the counter overflows twice? Would this change catch multiple overflows? You might consider catching overflows inside of the while loop. |
I'm also curious to hear about how you tested the overflow edge case. |
I just tested on L073RZ target which happens to be a relatively slow CPU, with 16bits counter.
|
afd66ab
to
6daa7fc
Compare
It looks like you have conflicts with the base branch. This may require a rebase. Also, it looks like this PR includes many changes that @LMESTM did not make. These two observations are probably related. |
@cmonr this was a quick fix made during workshop to unblock situation. I'm fin if you fix it another way or use the same kind of protect overflow that have been proposed in other PRs. |
@0xc0170 - do you refer to another PR that would fix this issue ? Is there a missing link. I am not sure if #6492 covers the common_tickers tests, does it ? |
I'm saying this because previous comment from @cmonr makes definitely sense
|
@LMESTM Hi! I'm sure that I checked on slow board like 16 MHz NRF51_DK, that count_ticks(NUM_OF_CYCLES, 1) takes: mbed-os/TESTS/mbed_hal/common_tickers/main.cpp Lines 69 to 76 in 3821b54
Please update your local branch. |
@LMESTM I am closing this due inactivity. Please reopen if this is still needed (with an update - needs rebase) |
Description
it seems that count_ticks function does not consider the case of a
16 its counter wrap-around - proposal added here.
Pull request type
[x ] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change