Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Task won't run without taskYield() called from within it?

Posted by adamneilward on December 17, 2013

Hi, I'm new to FreeRTOS and I am puzzled by something. I have 4 tasks, three of which are run using the vTaskDelayUntil() call to have them execute periodically (all three of these tasks works as expected). The 4th task however never gets called UNLESS I put a taskYield() inside it. All 4 tasks have the same priority.

static void taskFFT(void *pvParameters) { UNUSED(pvParameters); while(1) { taskFFT_DebugCounter++; //one of the other tasks prints this value out //taskYIELD(); //<--- commenting out this call seems to prevent this task from running } }

Since the first 3 tasks are periodic and mostly waiting, shouldn't all the remaining runtime be used for the task_FFT task? I have clearly misunderstood the workings of the scheduler but I'm not sure what I should be asking specifically.

Can someone please explain why task_FFT() never gets any CPU time? The counter never gets incremented, showing that the function is not being scheduled.

The other 3 tasks are run every 1000ms, 500ms and 100ms respectively and I don't believe they are using 100% cpu between them.

Task won't run without taskYield() called from within it?

Posted by davedoors on December 17, 2013

What is the priority of the task? If it is >0 then it should get all the time not used by your other tasks, if it is ==0 then it should share the time not used by your other tasks with the task.

Is taskFFTDebugCounter declared volatile? If not the ++ can simply be optimized away as the value is never used.

Do you have configUSE_PREEMPTION set to 1 in FreeRTOSConfig.h?

Task won't run without taskYield() called from within it?

Posted by adamneilward on December 18, 2013

You were right about the volatile declaration. I was using 7 for all four tasks' priorities and configUSE_PREEMPTION is set to 1. Does seem to work correctly now without the taskYield call.

Oddly enough, even though all four tasks were using task???DebugCounter variables to indicate that they were all running, only the FFT task's counter was being optimized out. In any case I've simply used the volatile constraint on all 4 timers now and everything is fine. I can throw in some other tasks now at different priorities to explore the system further.

The optimizer moves in mysterious ways.

Thanks for the help Dave, much appreciated.

Task won't run without taskYield() called from within it?

Posted by jdurand on December 18, 2013

I've had the optimizer take out an array I was reading/writing in a function. I would have thought it would notice both reads and writes in the same place and leave it alone.

VOLATILE is becoming like LET in BASIC, use it everywhere.

Task won't run without taskYield() called from within it?

Posted by adamneilward on December 18, 2013

To be honest, I've been seeing weirdness in my code ever since I started playing with this scheduling system. That is not a criticism, I simply have not become accustomed so the ways of the FreeRTOS yet. In time it will come to me I'm sure. It is certainly a different way of thinking about embedded firmware.

I'm finding it rather fascinating and educational.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists