SDK 14.2, SoftDevice 140, NRF52840.
My code is below. I am putting stuff on a queue (q1 in the code below) inside an interrupt. This stuff is then processed in the main loop via function2.
Normally, this works perfectly fine. But when I have a bunch of things queued up inside the app_scheduler, so that app_sched_execute() actually does something when called, function2 doesn't seem to run properly to dequeue the stuff that has built up in q1.
What I queue up using the app scheduler is function5. When function5 is done running, I check a condition to see if it needs to run again. If it does, then I add it again to the app_scheduler as you can see in the code.
I thought the app_scheduler just processes one queued function at a time, each time the main loop is run through (e.g., my intent is to run through function1, function2, function3, function4, then function5, and if there are more function5 to process, it will go again through the sequence 1, 2, 3, 4, 5. (I will call this "CASE 1")
However, it seems like maybe it processes all functions that might be in the queue all at once, and since function5 queues up another function5 (if needed) before it returns, what I really get is 1, 2, 3, 4, 5, 5, 5, 5, 5 ... etc (I will call this "CASE 2"). (I am not sure about this, because it hard to set a print statement in function2 since it runs so often when the main loop runs, so it fills up all the logs, and i don't want to set a breakpoint for the same reason) So I wanted to ask about how the app_scheduler works. Is it like CASE1 or CASE2?
If it is like CASE1, then it seems like queue_is_empty is not evaluating properly, since function2 never runs properly until there are no more function5 to process.
If it is like CASE2, this is a bit of a problem, because sometimes I need function5 to run for quite some time and don't want to block function2. How can I make it run more like CASE1?
Thanks!
// Enter main loop.
for (;;)
{
function1();
function2();
function3();
function4();
app_sched_execute(); //queues function5()
}
...
void function2()
{
if(!q1_queue_is_empty) {
NRF_LOG_INFO("in func2, queue not empty");
DATA_S dat;
ret = q1_queue_pop(&dat);
APP_ERROR_CHECK(ret);
// do stuff with dat
}
}
void function5(...)
{
// do stuff
// check exit condition
if(!time_to_exit){
uint32_t err_code = app_sched_event_put(&bdata, sizeof(bdata), function5);
APP_ERROR_CHECK(err_code);
}
}
