Hello: I have detected a problem with a timer on my program. I can solve it, but I would like to understand what is happening exactly.
My program starts to scan BLE signal, and, if it find a known advertising signal, it starts a timer inside the ble_event_handler function. If the nrf detects again the signal, it stops the timer, and starts it again (reset the timer to initial value). If the nrf doesn't detect a new known advertising signal, the timer expires, and go to interruption.
I have init the timer:
uint32_t err_code;
// Initialize timer module
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
//Create a general timer
err_code = app_timer_create(&general_timer_id, APP_TIMER_MODE_SINGLE_SHOT, general_timer_handler);
APP_ERROR_CHECK(err_code);
And inside the ble_event_handler function I have the following code:
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
....
err_code = app_timer_stop(general_timer_id);
APP_ERROR_CHECK (err_code);
err_code = app_timer_start(general_timer_id, APP_TIMER_SCAN ,NULL);
APP_ERROR_CHECK (err_code);
....
}
My problem is that sometimes, it gives me an error of full queue (error 04), and it is because Im acumulating more instructions than APP_TIMER_OP_QUEUE_SIZE (2, on my code).
If I make APP_TIMER_OP_QUEUE_SIZE great than 2, it solves the problem, but I have some questions:
- Can I restart the timer, or have I to stop and start it?
If the APP_TIMER_OP_QUEUE_SIZE is 1, when I stop timer (first instruction), it goes ok, but when I start timer (second instruction), I get the error 04. If I stop the timer, the queue must be 0 when the instruction has been done, why get I the error 04 on the next instruction? Is it because it is executing inside the ble_event_handler? Is a problem of priorities?
I don't know if you have enough information to answer this question, but... why, despite config APP_TIMER_OP_QUEUE_SIZE to 2, I get the error 04 sometimes?
How can I know how many tasks are on the queue of the timer?
Thank you.