-
Notifications
You must be signed in to change notification settings - Fork 3k
us/lp ticker - port K64F platform to new HAL api #6052
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
us/lp ticker - port K64F platform to new HAL api #6052
Conversation
b57f60e
to
f2e7043
Compare
6c6605f
to
ea62ab7
Compare
Waiting for the following patches: |
@cmonr All reqired patches are now on master. Could you rebase destination branch on master? |
f2e7043
to
2f14057
Compare
@mprse I've rebased the target branch. You should be good to go once you rebase this PR! |
ea62ab7
to
98d54f7
Compare
- provide ticker configuration: 1MHz/32 bit counter. - us_ticker_init() routine disables interrupts. - adapt comments.
98d54f7
to
fbdfa51
Compare
/morph build |
Build : FAILUREBuild number : 1196 |
It looks like the conflicts for the following commit have been incorrectly resolved while rebasing on master: Support for lp/us ticker should be disabled for all CI boards by above commit: Line 3667 in 7f88de9
NRF51_DK - disabled NRF52_DK - "LOWPOWERTIMER" should be removed: Line 3482 in 7f88de9
NUCLEO_F401RE - disabled NUCLEO_F429ZI - "LOWPOWERTIMER" should be removed: Line 1198 in 7f88de9
NUCLEO_F746ZG - disabled UBLOX_EVK_ODIN_W2 - disabled @cmonr @0xc0170 What can we do with this issue? |
both should be fine. I expect that feature branch will be rebased later for integration so this will be cleaned up. |
So I will add additional commit with the fix and explanation in this PR. |
57423d9
to
9ba82bb
Compare
/morph build |
Build : SUCCESSBuild number : 1201 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 873 |
Test : FAILUREBuild number : 1003 |
All ok for K64F! |
/morph build |
Build : SUCCESSBuild number : 1214 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 885 |
/morph test |
Test : SUCCESSBuild number : 1030 |
* count[0 - 14] - ticks (RTC->TPR) | ||
* count[15 - 31] - seconds (RTC->TSR) | ||
*/ | ||
const uint32_t count = ((RTC->TSR << SEC_SHIFT) | (RTC->TPR & TICKS_MASK)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Kinetis RTC is based on a ripple counter so if it is read at the right time it can glich. To guarantee a glitch free value, the same count needs to be read twice in a row. A psuedo code example of this is here:
Lines 143 to 149 in 2f14057
* // Loop until the same tick is read twice since this | |
* // is ripple counter on a different clock domain. | |
* count = LPTMR_COUNT; | |
* do { | |
* last_count = count; | |
* count = LPTMR_COUNT; | |
* } while (last_count != count); |
This would be a good case to add a test for if we don't have one already. Repeatedly call lp_ticker_read
in a tight loop and if the value every glitches into the past then fail the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed lp_ticker_read
as suggested and added glitch test cases for lp ticker.
delta_ticks = 1; | ||
} | ||
|
||
if (delta_ticks > MAX_LPTMR_SLEEP) { | ||
/* Using RTC if wait time is over 16b (2s @32kHz) */ | ||
uint32_t delta_sec; | ||
/* Using RTC if wait time is over 16b (2s @32kHz). */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the RTC alarm interrupt need to be used here? It seems like this code could be made simpler and thus more robust by only using the LPTMR. You would just need to adjust the supported number of bits to 15 so delta_ticks will never be greater than MAX_LPTMR_SLEEP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this can be implemented using only RTC->TPR as 15 bit time counter and only LPTMR to generate interrupts, but on the other hand combining 32 bit time counter from RTC->TSR and RTC->TPR is also ok and we got wider counter range.
I suggest to leave 32-bit counter in this PR and consider change to 15-bit counter in another PR (I will create it) since we need to have some example implementations before meting with silicon partners and it looks like this version is stable.
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).
This has been done already here: ARMmbed@7f88de9 Unfortunately targets.json file is changed quite often and it is hard to maintain conflicts while rebasing feature branch on master. This will have to be cleaned up later for integration with master. Note: lp ticker is required to have flash support on NRF52_DK. Disable flash support for this board.
…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.
cdfb9ec
to
c74c6c7
Compare
/morph build |
Build : SUCCESSBuild number : 1255 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 919 |
Test : SUCCESSBuild number : 1052 |
uint32_t last = lp_ticker_read(); | ||
const uint32_t start = last; | ||
|
||
/* Set test time to 2 sec. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi
This test is not protected for overflow.
Regards,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to provide fix tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix can be found here: PR #6584.
Description
This PR ports us/lp ticker K64F drivers to the new HAL API, enables support for ticker on K64F and also provides little modifications to the HAL ticker tests (resolve issues found while porting ticker driver).
Here only cosmetic changes were required since US ticker is already driven by 1MHz clock, so us <-> ticks conversion is not required.
Init routine needed to be modified since according to the requirements init should disable us ticker interrupt.
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 (in case when sleep time does not exceed 2 sec otherwise interrupt is scheduled in two steps - first full seconds are scheduled using RTC Alarm interrupt and then remaining time using LPTMR).
In previous version RTC time was converted to us before was passed to the upper layer and vice versa. In the new version upper layer is informed that lp ticker is driven by 32KHz clock, ticker driver operates on ticks and ticks <-> us conversion is handled by the upper ticker layer.
Init routine needed to be modified since according to the requirements init should disable lp ticker interrupt.
Since counter overflow is handled by the upper layer new drivers does not check if counter has overflown. Added protection against counter overflow during test case execution.
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.
Status
HOLD
Migrations
YES
Low power ticker K64F drivers operates now on ticks and ticks <--> us conversion is done in the upper layer.