manish9161 wrote on Wednesday, July 09, 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 <string.h>
#include <stdio.h>
/*!**************************************************************
- \fn init()
- \brief LED init function
-
\param -
-
\return -
******************************************************************/
void init()
{
STM_EVAL_LEDInit(LED3 );
STM_EVAL_LEDInit(LED4 );
STM_EVAL_LEDInit(LED5 );
STM_EVAL_LEDInit(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(uint8_t i= 0; i< 100 ; i++)
// while(1)
{
STM_EVAL_LEDOn(LED8);
vTaskDelay(500);
STM_EVAL_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;
}