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

Preemptive scheduling

Posted by manish9161 on July 9, 2014

Hello I am Manish Baing working on stm32f3Discovery with freeRTOS . What I have implemented 1.Created 4 task with priority 4,3,2,2 respectively 2.Toggle LED 3 ,LED 4,LED 5,LED 8 in task callback function of respective task. 3.set #define configUSE_PREEMPTION 1 in FreeRTOSConfig.h

what I will be expecting from this code 1.I am trying to implement preemptive scheduling of task but in this case only task with priority 4 is running and get competed successfully. 2.Why other task should not be running if task with highest priority has already completed with its work. 3.how do I test preemptive scheduling..?

Thanks in advance my code...

#####......
include "FreeRTOS.h"
include "timers.h"
include "task.h"
include "stm32f3_discovery.h"
include
include

/*!************************************************************** * fn init() * brief LED init function *
* param - * return - ******************************************************************/ void init() {

STMEVALLEDInit(LED3 ); STMEVALLEDInit(LED4 ); STMEVALLEDInit(LED5 ); STMEVALLEDInit(LED8 ); }

/*!************************************************************** * fn
* brief taskA callback function *
******************************************************************/ void TaskA() { for(uint8t i= 0; i< 100 ; i++) //while(1) { STMEVALLEDOn(LED3); vTaskDelay(500); STMEVAL_LEDOff(LED3); vTaskDelay(500); }

} /*!************************************************************** * fn
* brief taskB callback function *
******************************************************************/ void TaskB() { for(uint8t i= 0; i< 100 ; i++) //while(1) { STMEVALLEDOn(LED4); vTaskDelay(500); STMEVAL_LEDOff(LED4); vTaskDelay(500); } }

/!************************************************************** * fn
* brief taskC callback function *
******************************************************************/ void TaskC() { for(uint8t i= 0; i< 100 ; i++) // while(1) { STMEVALLEDOn(LED5); vTaskDelay(500); STMEVAL_LEDOff(LED5); vTaskDelay(500); } } /!************************************************************** * fn
* brief taskD callback function *
******************************************************************/ void TaskD() { for(uint8t i= 0; i< 100 ; i++) // while(1) { STMEVALLEDOn(LED8); vTaskDelay(500); STMEVAL_LEDOff(LED8); vTaskDelay(500); }

} int main(void) { init(); xTaskHandle xHandle1 ,xHandle2,xHandle3,xHandle4; xHandle1 = NULL; xHandle2 = NULL; xHandle3 = NULL; xHandle4 = NULL; /! TaskA is having highest priority */ xTaskCreate(TaskA, (signed char)"TaskA", 1000, NULL,4, &xHandle1); if( xHandle1 != NULL ) { vTaskDelete( xHandle1 ); } /! TaskB having medium priority */ xTaskCreate(TaskB, (signed char)"TaskB", 1000, NULL, 3, &xHandle2); if( xHandle2 != NULL ) { vTaskDelete( xHandle2 ); } /! TaskC ,and TaskD Idle tasks */ xTaskCreate(TaskC, (signed char)"TaskC", 1000, NULL, 2, &xHandle3); if( xHandle3 != NULL ) { vTaskDelete( xHandle3 ); } xTaskCreate(TaskD, (signed char*)"TaskD", 1000, NULL, 2, &xHandle4); if( xHandle4 != NULL ) { vTaskDelete( xHandle4 ); } vTaskStartScheduler(); return 0; }


Preemptive scheduling

Posted by edwards3 on July 9, 2014

Looks like you tasks dont use an infinite loop. See this page for how to write a task. http://www.freertos.org/implementing-a-FreeRTOS-task.html


Preemptive scheduling

Posted by markwrichardson on July 9, 2014

This was my first mistake too. I haven't used any other small RTOSes, but it was hard to adjust my brain to remember that the delay in task create is the only initial delay. Afterwards, the task itself must regulate it's own loop rate or block while waiting on some flag.

The task has it's own stack and the locals there are persistent. Returning from a task will crash the system because there is no return value on the stack for the task-function to return to.

Your sample will probably blink all four LEDs evenly 500ms On, 500 ms Off.


Preemptive scheduling

Posted by manish9161 on July 10, 2014

Thanks a lot again.Its really help me to clear my doubts.Actually I have test preemptive sheduling beacause I have to built real time application where 1.single higher priority task and multiple general or medium priority task. 2.But how do i test preemptive sheduling using LED blink sample code mentioned above. 3.Please suggest some changes in mentioned code so as to test preemptive sheduling of task.

Thanks in advance.


Preemptive scheduling

Posted by davedoors on July 10, 2014

Rather than ask people to change your code, why don't you look at and use the code that has already been provided for you. Nearly every demo in the download flashes an led, and there is even a flash.c file in FreeRTOS/demo/common/minimal that creates multiple tasks that do nothing but flash an led.


Preemptive scheduling

Posted by manish9161 on July 10, 2014

Hello Dave don't take me wrong .Actually I am new to FreeRTOS andI don't want to just blink LED .But I have to test and analyse preemptive shedling using LED code .so main goal is to test preemptive sheduling algorithum not to flash an LED using FreeRTOS.


Preemptive scheduling

Posted by rtel on July 10, 2014

What is it about the preemptive scheduling algorithm you want to test. It is a traditional algorithm, used by nearly all small schedulers. It will always run the highest priority task that is able to run (not blocked) and time slice tasks of equal priority if there are multiple ready tasks of the same priority. If you can say exactly which aspect you want to test then I will be able to point you to a file that will already test it - you can then just run that file rather than writing your own.

Regards.


Preemptive scheduling

Posted by manish9161 on July 10, 2014

Thanks again. 1.I have created 4 task one with higest priority and other 3 with same priority (less than 1st task). 2.I have to just test that 1st task shedule first and then remaining task will get sheduling time. 3.I am not tring to test sheduling algorithums i know its already verified by experts.I just want to test my application with that algorithum.


Preemptive scheduling

Posted by manish9161 on July 11, 2014

hello Real Time Engineers ltd , Can I get that file which you already mentioned so as to proceed further ..? if possible please provide .I think I need to work more to get familiar with FreeRTOS.I will try my best.

Reagrds


[ 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