Hey everyone,
Currently I’m working on the FreeRTOS / Scheduling part of the system. The problem is related to the scheduling in FreeRTOS in combination with the tasks which get scheduled by the SDK itself. The code below is an example of how the issue can be faced. The code is built on top of the Arduino SDK.
#include "FreeRTOS.h"
#include "task.h"
void Task1( void *pvParameters );
void Task2( void *pvParameters );
void setup() {
Serial.begin(115200);
while(!Serial){};
// Now set up two tasks to run independently.
xTaskCreate(
Task1
, "First Task"
, 4096 // Stack size
, NULL
, 1000 // priority
, NULL );
xTaskCreate(
Task2
, "Second Task"
, 4096
, NULL
, 1000
, NULL );
}
void loop()
{
// Empty. Things are done in Tasks.
}
void Task1(void *pvParameters)
{
(void) pvParameters;
for (;;) // A Task shall never return or exit.
{
printf("\nThead 1");
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
}
}
void Task2(void *pvParameters)
{
(void) pvParameters;
for (;;) // A Task shall never return or exit.
{
printf("\nThead 2");
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
}
}
As shown above I’m starting adding two tasks which will run continuously. However, the SDK also makes use of tasks and I’m curious if this could have any problems related to the priority. For example, the ‘wifi_set_promisc()’ function (sdk/component/common/api/wifi/wifi_conf.h) makes use of a callback function which will be triggered whenever a management frame is detected. To be making sure that this function is getting called, the main tasks have to be delayed. So for example:
wifi_set_mode(RTW_MODE_PROMISC);
wifi_enter_promisc_mode();
wifi_set_channel(5)
wifi_set_promisc(3, callbackFunc, 1);
while(1)
{
printf("Delaying task...");
delay(5000);
}
The assumption I make is that the set_promisc function operates from other tasks (osPriorityRealtime), which gets scheduled whenever the main task gets delayed. That’s where the delay loop is for. Is this assumption correct? And if so, how could we combine a task from the SDK such as the example, with a task of your own software. Currently both tasks (own tasks) are getting scheduled, as the example has shown. I think since both of these tasks are high in priority, there isn’t a chance for the callback tasks to run since both tasks (task1 & task2) are higher in priority, and gets rescheduled every time.
Have any of you guys faced an issue while running your own tasks in combination with tasks from tasks which are used in the SDK? Would love hearing your experiences, and how to fix this.