Background tasks: when to suspend, when to loop infinitely?

Hello,

I have a question about background tasks. It occured to meby comparing two different tasks among two different examples. All are created with task.createBackground(my_task)

In the user interface task (which receives characters from the serial monitor), such as loop_communication_task() in the OWNVERTER/BLDC_hall_sensor example, I see no call to task.suspendBackgroundMs(); as opposed to the loop_application_task() which displays board measurements.

So to be sure I understand correctly: the goal is to have loop_communication_task() run as much as possible (to be responsive to user input), while for loop_application_task() the goal is to have it pseudo periodic so as to display measurement at a reasonable rate (avoid flooding the terminal). Correct?

Second question about tasks: the code of the OWNVERTER/BLDC_hall_sensor loop_communication_task() is enclosed in a while (1) {...} infinite loop statement. However, in another example it is not (loop_background_task() in OWNVERTER/FOC_hall_sensor example). So my question: is it needed to add the infinite loop or is already done by Zephyr background task manager?

Correct :slight_smile:

Correct, when creating a task, the task is indeed scheduled by the Zephyr background task manager. No need of the while(1){...}

1 Like