Infinite loop When the scheduler active the lowest priority task

pauldufay wrote on Tuesday, March 17, 2015:

Hi,

I have a problem with the scheduler and i am new with freeRTOS. It have a good fonctionnement with all other task but when it comes to active the lowest priority task, when the task is finish, it restarts at the beginning of this task infinitly. It loop.

Can you explain me why?

Thank for any explication

Creation of My Lowest Task :

xTaskCreate( TaskLog,“TaskLog”, configMINIMAL_STACK_SIZE,NULL ,tskIDLE_PRIORITY + 2, NULL );

Definition of My Task:

static void TaskLog (void * pvParameters)
{

TickType_t 			xLastWakeTime;
const TickType_t 	xFrequency = 80;
FRESULT 			rc;
xLastWakeTime = xTaskGetTickCount();

for(;;)
{

vTaskDelayUntil( &xLastWakeTime, xFrequency );

f_mount(0, &fatfsLOG);
rc = f_open(&filLOG, FileNameSdCard, FA_WRITE | FA_OPEN_ALWAYS);    
                         WriteSdCardFile(RTC_DateStructure,RTC_TimeStructure,sec_frac,GPSData_Wk,IMU1Data_Wk,IMU2Data_Wk);
DisableInterrupts();

f_close(&filLOG);
f_mount(0, NULL);
WriteBauderatefile();

DisableInterrupts();

}

}

rtel wrote on Tuesday, March 17, 2015:

I’m not sure I follow the description of the problem. Your task is implemented as an infinite loop - as would be normal. When it gets to the bottom of the for(;:wink: loop I would expect it to go back to the top of the for(;:wink: loop - are you saying instead of doing that it is going right back to the top of the function - so executing the call to xTaskGetTickCount() again?

By the way - you should not disable and enable interrupts directly, but use taskENTER_CRITICAL() and taskEXIT_CRITICAL() instead.

Regards.

pauldufay wrote on Tuesday, March 17, 2015:

No, sorry i think my explication was not very complete. I have 6 task. and when the scheduler run, it active task 1 ( the highest priority task ) , after task 2, task 3 ,… and when it active the last and lowest priority task ( My TaskLog joined before ), the scheduler don’t active the task 1 when this task is finish. It just active always the last task.

Thanks for explication.

rtel wrote on Tuesday, March 17, 2015:

So TaskLog() never starts at all - is that right?

If so, what happens? Does the system crash, or does the higher priority
task just continue running?

If the higher priority task continues running, does it ever enter the
Blocked state? If it does not enter the Blocked state then it will
starve the lower priority tasks of processing time.

Regards.

pauldufay wrote on Wednesday, March 18, 2015:

No, TaskLog is the lowest priority task, and when the scheduler reach it (it is the last task call in my program ), TaskLog repeat itself infinity. The scheduler never pause this task for reaching the highest or an other task.

When i done a eTaskGetState() for all task; All task are ready to execute.

i have 4 task with priority of 3 , 1 task with priority of 2 and TaskLog priority of 2.

I just want that the scheduler authorize the highest task just after the lowest task is finish.

Is my Problem more clear?

Thanks for explication

ps: I use Eclipse and OpenOCD like debugger.

pauldufay wrote on Wednesday, March 18, 2015:

I found that, the task loops infinitly just when i put the f_open function in. Now when i erase f_open, the task finish but the scheduler do nothing and the program look like it don't crash, but probably scheduler crash and no others task is reach.

static void TaskLog (void * pvParameters)
{

TickType_t 			xLastWakeTime;
const TickType_t 	xFrequency = 80;
FRESULT 			rc;
xLastWakeTime = xTaskGetTickCount();

eTaskState EtatGPS, EtatCal, EtatLog;

for(;;)
{

vTaskDelayUntil( &xLastWakeTime, xFrequency );
WriteSdCardFile(RTC_DateStructure,RTC_TimeStructure,sec_frac,GPSData_Wk,IMU1Data_Wk,IMU2Data_Wk);

EtatGPS = eTaskGetState( TaskGps );
EtatCal = eTaskGetState( TaskCal );
EtatLog = eTaskGetState( TaskLog );

}

}

pauldufay wrote on Wednesday, March 18, 2015:

I found the solution. The Stack size was to small.
Now :
configMINIMAL_STACK_SIZE * 15

Thanks for your time
Have a Good Day

rtel wrote on Wednesday, March 18, 2015:

Maybe a helpful link:

http://www.freertos.org/FAQHelp.html

It mentions how to monitor the stack and check for stack overflows.

Regards.