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




Loading

Task switching does not work without osDelay in loop

Posted by erikclaij on June 13, 2017

Hi,

In this simple example, I have created a task where I start a Timer (for a blinking LED). After the timer is running a start the endless loop. The LED will only blink if I include the osDelay(1) function in it.

Am I missing something?

Best, Erik

~~~ void ControlCenter(void const *argument) { osTimerId activityLedID;

osTimerDef(activityLed, ActivityLed);
activityLedID = osTimerCreate(osTimer(activityLed), osTimerPeriodic, NULL);
osTimerStart(activityLedID, 20UL);

while(1)
{
  osDelay(1); // Why do I need this ????
}

} ~~~


Task switching does not work without osDelay in loop

Posted by hs2sf on June 13, 2017

Check your task prio vs. configTIMERTASKPRIORITY. Seems that your task starves the timer task due to running at higher prio than the timer service. The delay puts your task in blocked state and allows the timer task to run for a while. You should block your task(s) somehow (waiting for an event) to avoid hogging the CPU doing nothing.


Task switching does not work without osDelay in loop

Posted by richard_damon on June 14, 2017

Another posibility is that you have configured FreeRTOS to not use preemption, in which case the loop needs some call that allows FreeRTOS to preempt the task.

Also, there is no reason for a user task to just have a while(1) {} loop, a task should only use the CPU when it has something to do, and when it doesn't, it should block till it has something (or exit if it is totally done).


Task switching does not work without osDelay in loop

Posted by erikclaij on June 15, 2017

Thanks, it was indeed a prio problem.


[ 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