m
m
 
Line 9: Line 9:
  
 
==Code==
 
==Code==
<syntaxhighlight>
+
<html>
 
+
<script src="https://gist.github.com/Amritach/d029e125c12402520bcc.js"></script>
/* Scheduler include files */
+
</html>
#include "FreeRtOSConfig.h"
+
#include "FreeRTOS.h"
+
#include "task.h"
+
#include "croutine.h"
+
#include "uart.h" // Explore Embedded UART library
+
 
+
/* Local Tasks declaration */
+
static void MyTask1(void* pvParameters);
+
static void MyTask2(void* pvParameters);
+
static void MyTask3(void* pvParameters);
+
static void MyIdleTask(void* pvParameters);
+
 
+
#define LED_IdleTask 0x01u
+
#define LED_Task1    0x02u
+
#define LED_Task2    0x04u
+
#define LED_Task3    0x08u
+
#define LED_Task4    0x10u
+
 
+
#define LED_PORT LPC_GPIO2->FIOPIN
+
 
+
+
int main(void)
+
{
+
 
+
  /* Initialize the Uart module */
+
    LPC_GPIO2->FIODIR = 0xffffffffu;
+
SystemInit();
+
UART_Init(38400);
+
 
+
/* Create the three tasks with priorities 1,2,3 */
+
xTaskCreate( MyTask1, ( signed char * )"Task1", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
+
xTaskCreate( MyTask2, ( signed char * )"Task2", configMINIMAL_STACK_SIZE, NULL, 2, NULL );
+
xTaskCreate( MyTask3, ( signed char * )"Task3", configMINIMAL_STACK_SIZE, NULL, 3, NULL );
+
xTaskCreate( MyIdleTask, ( signed char * )"IdleTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+
 
+
UART_Printf("\n\rIn the main");
+
+
vTaskStartScheduler(); /* Start the schedular */
+
 
+
while(1);
+
}
+
 
+
static void MyTask1(void* pvParameters) /* Task1 with priority 1 */
+
{
+
while(1)
+
{
+
    LED_PORT = LED_Task1;   /* Led to indicate the execution of Task1*/
+
UART_Printf("\n\rTask1"); 
+
vTaskDelay(100);
+
}
+
}
+
 
+
static void MyTask2(void* pvParameters) /* Task1 with priority 2 */
+
{
+
while(1)
+
{
+
    LED_PORT = LED_Task2;   /* Led to indicate the execution of Task2*/
+
UART_Printf("\n\rTask2");
+
vTaskDelay(250);
+
}
+
}
+
 
+
static void MyTask3(void* pvParameters) /* Task1 with priority 3 */
+
{
+
while(1)
+
{
+
    LED_PORT = LED_Task3;   /* Led to indicate the execution of Task3*/
+
UART_Printf("\n\rTask3");
+
vTaskDelay(600);
+
}
+
}
+
 
+
static void MyIdleTask(void* pvParameters) /* Task1 with priority 4 */
+
{
+
while(1)
+
{
+
    LED_PORT = LED_IdleTask; /* Led to indicate the execution of Idle Task*/
+
UART_Printf("\n\rIn idle state");
+
}
+
}
+
</syntaxhighlight>
+
 
{{DISQUS}}
 
{{DISQUS}}

Latest revision as of 17:50, 14 April 2015



Intro

In first tutorial we saw how to create and use a task. Now we will see how the scheduler works.

As we know, scheduler always executes the highest priority task ready to run and when the current task goes in blocked condition scheduler will look for next highest priority task in ready state.

Code