Skip to content

nrfx: drivers: nrfx_grtc: Improvements to speed up nrf_grtc_timer #288

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nordic-krch
Copy link
Contributor

Set of proposed improvements to reduce time spent in the GRTC functions. The main factor impacting performance is the number of register accesses. For example on nrf54h20 each register access to GRTC takes ~0.5 us which is 160 cycles at 320 MHz.

Following improvements are proposed:

  • Using INTPEND register in the interrupt handler - it reduces the need of reading INTEN and EVENTS registers. After INTPEND is read then only EVENTS clearing for events that actually triggered the interrupt are cleared
  • Removing event readback after clearing the register. Event readback was introduced in nrf52 series and it was recommended to avoid a risk of getting another interrupt triggered. It could happen in a case where event clearing happens just before exiting an interrupt since register writes are queued and write may not happen before interrupt routine finishes. That will never be the case for GRTC since there is always user handler and next CC value being set (which will ensure that write to EVENT register is done)
  • Adding functions dedicated for nrf_grtc_timer that will speed up CC configuration.

Newly added functons:
nrfx_grtc_channel_cb_alloc Allocated a channel, enables interrupt source and stores callback + p_context. Previously only channel was allocated and enabling interrupt and storing callback+p_context was done on every new CC value setting. Those operations were redundant.
nrfx_grtc_syscounter_cc_abs_set - Function for setting absolute CC value. One of the parameters is safe_setting bool. If true then it indicates that previous CC is earlier than new CC and it is not far in the future so longer and safer procedure must be applied. If false then CC can be just written with the new value.
nrfx_grtc_syscounter_cc_rel_set - Function for setting CCADD. It just writes CCADD. It is caller responsibility to use it only when it makes sense. For nrf_grtc_timer it is used when setting a new CC value from callback of previous Compare event. It is using relative to CC.

Modified function:
nrfx_grtc_syscounter_start - Added handler and p_context to function parameters. It not only allocates main channel but stores callback and enables interrupt handler.

Readback was added to ensure that interrupt is not triggered spuriously.
It may only happen if event clearing is done just before exiting the
interrupt. It is not the case in the GRTC driver. Each access to the
register interface is costly (~160 320MHz cycles) so it must be avoided
if possible.

Signed-off-by: Krzysztof Chruściński <[email protected]>
Use INTPEND in the interrupt handler to optimize handler execution.
Do not read CC value from GRTC registers before calling the user
handler. User can read that if it is needed. Reading GRTC registers
is costly and should be avoided if possible.

Signed-off-by: Krzysztof Chruściński <[email protected]>
Add functions that improves performance of nrf_grtc_timer:
- Channel allocation with callback. Previously callback is written on every CC val
setting which is redundant
- Function for setting CCADD register
- Function for setting CC register

Signed-off-by: Krzysztof Chruściński <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant