This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can app_timer_cnt_get be interrupted by SD?

As the title says, can the call app_timer_cnt_get() be interrupted by the SoftDevice and return an outdated value?

Parents
  • Anything which takes longer than one instruction can get interrupted by anything with a higher interrupt priority, so not only could app_timer_cnt_get() be interrupted after it reads the count and before it returns it, the code it returns to could get interrupted before it processes the value (which is much more likely as when optimised reading the counter is one single instruction).

    You should basically assume that between any two instructions anywhere in your code there could be an indeterminate gap caused by an interrupt, softdevice or other.

  • You haven't really said what your problem is. In the end the code reads a register and then processes the data, it might read the register and then get interrupted before it processes, it might read it and process immediately, then get interrupted. It doesn't matter whether you use an inline expression (which is what optimised code does anyway), the time you read in one line of code may not be the time the next line of code is executed. If you rely on it being so, you are going to get broken.

    What is your actual issue?

Reply
  • You haven't really said what your problem is. In the end the code reads a register and then processes the data, it might read the register and then get interrupted before it processes, it might read it and process immediately, then get interrupted. It doesn't matter whether you use an inline expression (which is what optimised code does anyway), the time you read in one line of code may not be the time the next line of code is executed. If you rely on it being so, you are going to get broken.

    What is your actual issue?

Children
No Data
Related