When to use idle hook and when to create a seperate task?

Hello,
I wonder if I can turn my lowest priority task into an idle hook.

  • Which would be the benefits of that?
  • Can I still use xQueueReceive and ulTaskNotifyTake?
    My lowest priority task runs in an endless loop and never gets blocked. How to merge that into the idle task?

Thanks for any hint

Martin

You cannot block in the IDLE hook which means that you must use a block time of zero.

This page provides a comparison of the two approaches - RTOS idle task and the FreeRTOS idle task hook function

Thanks for these clarifying answers.
Another option would be use the same priority (0) as the idle task also for my lowest priority task and set configIDLE_SHOULD_YIELD to 1. Is that right? Then the lowest priority task could use xQueueReceive and ulTaskNotifyTake with a blocking time > 0 ?
Are there any drawbacks from this?
In case the lowest priority tasks has prriority 1 (greater than idle task) and never blocks, will idle task ever run ? What does that mean to FreeRTOS kernel? (It seems to work for me. While thinking about other options I came across this question)
Thanks for any help.

Yes, that is right.

The only drawback is the more RAM but if you want to use blocking time > 0, that is the only option.

No, the Idle task will starve.

The idle task does some housekeeping stuff and that won’t happen. For example, when a task deletes itself, its memory is freed in the Idle task. If the Idle task never runs, that memory will never be freed.

Ok, thanks. I have everything static, no dynamic task or other things creation and no delete. So I don’t need the idle task ?

You mean to ask that you can starve Idle task? Likely you can but I’d recommend to give it a chance to run once in a while.

CURRENTLY the only functions the idle task does is clean up deleted tasks and provide hooks for low power idle, so if you don’t need them, letting it starve is ok.

Putting your task that would be currently using up all the spare time at task priority 0, and enabling time slicing will say that the system will run the idle task alternating with your task, so it will not actually starve, but it also will not be using up much time as it will quickly see that there is nothing for it to do. This is the normal recommendation.

Hey @Mr_M_from_K, I hope you’re doing well!
I wanted to reach out to see if you needed any additional help with this, or if the answers you’ve gotten in this thread answered your question. If you’re unsure about anything or facing any problems feel free to ask so we can help you with them! Additionally if you’re unblocked on your current project if you could let us know that’d be great!

Hi skptak,
thanks for coming back to this case.
And thanks also for the explanations of aggarg and richard-damon. I have a clearer understanding now and changed the FreeRTOS setting in my project according to your recommendation.