Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Is nrf_rtc_counter_get interrupt safe?

Hi!

I'm not good at C and microcontrollers programming. Could somebody clarify, if nrf_rtc_counter_get interrupt safe? It just reads value from rtc register->COUNTER (24bit), how many ticks it takes?

Thanks.

Parents
  • Hi,

     

    Could somebody clarify, if nrf_rtc_counter_get interrupt safe? It just reads value from rtc register->COUNTER (24bit), how many ticks it takes?

     As you mention, it reads the ->COUNTER register. It does not guard (disable / enable) against any interrupt that might occur while reading the register.

    You can call this from any priority.

    One tick is one cycle on the RTC (32.768k), and the register is read via the CPU, so it'll take alot less time than one tick to read. See 's excellent answer on this.

     

    If you have a function that should not be interrupted, you can use the macros "CRITICAL_REGION_ENTER()" and "CRITICAL_REGION_EXIT()" to guard that function.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Could somebody clarify, if nrf_rtc_counter_get interrupt safe? It just reads value from rtc register->COUNTER (24bit), how many ticks it takes?

     As you mention, it reads the ->COUNTER register. It does not guard (disable / enable) against any interrupt that might occur while reading the register.

    You can call this from any priority.

    One tick is one cycle on the RTC (32.768k), and the register is read via the CPU, so it'll take alot less time than one tick to read. See 's excellent answer on this.

     

    If you have a function that should not be interrupted, you can use the macros "CRITICAL_REGION_ENTER()" and "CRITICAL_REGION_EXIT()" to guard that function.

     

    Kind regards,

    Håkon

Children
Related