Preemptive scheduling

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 <string.h>

include <stdio.h>

/*!************************************************************** * 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(uint8_t i= 0; i< 100 ; i++) //while(1) { STM_EVAL_LEDOn(LED3); vTaskDelay(500); STM_EVAL_LEDOff(LED3); vTaskDelay(500); } } /*!************************************************************** * fn
* brief taskB callback function *
******************************************************************/ void TaskB() { for(uint8_t i= 0; i< 100 ; i++) //while(1) { STM_EVAL_LEDOn(LED4); vTaskDelay(500); STM_EVAL_LEDOff(LED4); vTaskDelay(500); } } /!************************************************************** * fn
* brief taskC callback function *
******************************************************************/ void TaskC() { for(uint8_t i= 0; i< 100 ; i++) // while(1) { STM_EVAL_LEDOn(LED5); vTaskDelay(500); STM_EVAL_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

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

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

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

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

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

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

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

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