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

Multiple App Timers

I have a general question that I haven't been able to clearly locate in documentation.  How does the processor handle "traffic" jams from within the different app timers?

I'm using an app timer to generate a sampling circuit that runs at 1 hz(RTC1 with nrf standard app timer library structure).  I also have a BLE stack running with three custom services.  I have an RGB led on the device that I would like ot have blink different colors based on various device states. Right now, I'm planning on having the LED essentially toggle on and off on a timer to create a blink.  The sampling circuit should always run continuously.  I haven't precisely figured out the timing for the sampling algorithm, but it reads 1 adc channel, a few I2C peripherals, and saves a data buffer, so its fairly light weight.  In working on setting flags in the ISR triggered by the app timer, which should help prevent traffic jams. 

So my question is, is there anything else I should be doing when setting up these LED states that will save me debugging time later? Does the MCU automatically prioritize these events based on FIFO since they all have the same priority, unless overridden? Should I set the sampling ISR at a higher priority to ensure it takes precedence over LEDS?

  • Hi,

    I would not expect any problems as long your app isn't spending too much time inside the timer callbacks like you said. That is, execution of code and and triggering of peripheral tasks is generally OK, but "wait" functions (e.g. waiting for a TWI transfer complete event) should be avoided.

    App timer callbacks are all being invoked in the same RTC1_IRQ interrupt context, unless you are using it with the app scheduler (see "Scheduler tutorial"), in that case they will be processed from your main loop. In either case, a timer callback cannot be preempted by another app timer callback so all instances will effectively have the same priority (FIFO).

    Also, as you might know, both the I2C and ADC driver support non-blocking operation: Using the SAADC driver, TWI master if you want to start a transfer/sampling directly from the timer handler.

    Best regards,

    Vidar

Related