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

How big should APP_TIMER_OP_QUEUE_SIZE be?

On top of almost all the BLE examples in the SDK, there is an APP_TIMER_OP_QUEUE_SIZE define. How can I know how big this should be for a specific application?

  • If all your interrupts run on the same priority level, there shouldn't be any need for a queue at all, i.e. you should be able to set its size to 1. There are however some complications to this.

    If you look at the app_timer module, you can see that to do manipulations on its internal data structures, it uses a queue. All operations are posted to this queue, and at the end of the method a software interrupt is triggered, to actually do the data structure manipulation. This software interrupt runs with the same priority as the RTC interrupt itself, meaning that the structure manipulation can not be interrupted once started. Please note that the actual adding of operations to the queue runs in the context of the caller.

    However, if you have a higher priority interrupt (possibly more than one), which calls app_timer functions, this will interrupt the software interrupt that's actually doing the data manipulation. Since the adding of operations runs in the caller's context, this will be allowed to run, but not necessarily the actual handling of the operation (since that agains runs on a lower priority). Depending on how your application flow is (i.e. how many interrupts have high priority, do they use app_timer, will they happen at the same time and so on), you then might need room for more than one operation in the queue.

    It should be noted that if you don't use the scheduler, all the methods called from ble_evt_dispatch are examples of such higher priority interrupts, so if you do a stop/start sequence for a timer in these functions, you will need a queue after all.

  • After reading your answer,I still want to know if APP_TIMER_MAX_TIMERS equals to APP_TIMER_OP_QUEUE_SIZE,what will be happening?Upon our project,I creat a one minute app_timer,but after severval days,it stops working.I do not stop the one minute app_timer since the device is supplied.

Related