ESP32 Multitasking
Posted: Sun Nov 21, 2021 11:05 am
The ESP32 runs Free RTOS - this is a 'multitasking' operating system.
This can be used from within Flowcode to allow timed or multiple threads to execution to occur 'simultaneously' without any timing or intervention from the program. The 'threads' must 'yield' control to the OS to allow the multitasking to occur - this can easily be achieved by adding a delay. This allows multiple tasks to be handled very easily
The relevant function to use is xTaskCreate (which needs to be used in a C block)
The arguments to this are:
Function (or task) (a Flowcode macro's address)
Task name
Stack size
Parameters
Priority
Task Handle
To get the address of a macro in FC we use &FCM_Name
A simple example.
This toggles 3 pins on and off (in this case at 1, 2.5 and 5 Hz) I used A18, A19 and A5 (Note that initially the pins I used 'crashed' with pins ... are input only although FC doesn't complain)
One pin is toggled in the main loop - the other 2 are toggled 'independently' by Flash_1 and Flash_2 -which are added as tasks. Note that stack size depends on the macro (1024 used here is probably overkill!)
Martin
This can be used from within Flowcode to allow timed or multiple threads to execution to occur 'simultaneously' without any timing or intervention from the program. The 'threads' must 'yield' control to the OS to allow the multitasking to occur - this can easily be achieved by adding a delay. This allows multiple tasks to be handled very easily

The relevant function to use is xTaskCreate (which needs to be used in a C block)
The arguments to this are:
Function (or task) (a Flowcode macro's address)
Task name
Stack size
Parameters
Priority
Task Handle
To get the address of a macro in FC we use &FCM_Name
A simple example.
This toggles 3 pins on and off (in this case at 1, 2.5 and 5 Hz) I used A18, A19 and A5 (Note that initially the pins I used 'crashed' with pins ... are input only although FC doesn't complain)
One pin is toggled in the main loop - the other 2 are toggled 'independently' by Flash_1 and Flash_2 -which are added as tasks. Note that stack size depends on the macro (1024 used here is probably overkill!)
Martin