Page 1 of 1
WiFi, FreeRTOS task and event loops
Posted: Fri Dec 01, 2023 12:21 pm
by papadeltasierra
If I want to use FreeRTOS tasks and queues but also the ESP-NETIF WiFi support, do I need to have an ESP event loop callback that just forwards the ESP (event loop) events to the FreeRTOS queue for the task I have created?
I don't see any way to register a FreeRTOS queue as the recipient of WiFi event - did I miss this or is my suggestion about the correct way to go?
Thanks.
Re: WiFi, FreeRTOS task and event loops
Posted: Fri Dec 01, 2023 3:11 pm
by papadeltasierra
I suspect the answer to my question is not use FreeRTOS task and queues directly but to use the ESP event loop library and create multiple event loops, which seems to create tasks and queues "under the covers". So you get the ESP event loops that much ESP code expects but the tasks and queues that spread work nicely across a more complex project.
Re: WiFi, FreeRTOS task and event loops
Posted: Fri Dec 01, 2023 3:44 pm
by MicroController
From what I have seen so far, the event loops aren't much of a thing in most applications, i.e. most never actively use them besides initialitzing one for the WiFi stack.
The IDF itself uses the (default) event loop in some places, and it may also benefit some other use cases, but generally I think that 'native' queues &c. are a 'better' way to communicate between components because, as you noticed, they often integrate better into the code structure/flow. Event loops/handlers may be beneficial if you can/want to directly react to an event, i.e. inside the handler callback; no need for extra tasks for those small, infrequent jobs in this case.
If you look at the UART driver for example, you'll notice that it doesn't use the event loop but (optionally) provides a queue from which you can consume its events. So this pattern is not too unusual either.