(Created page with "category: RTOS Tutorials ---- ==Intro== This is our first tutorial with FreeRTOS so start with a simple example of how to create and use a task. Before going to this tut...")
 
m
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[category: RTOS Tutorials]]
 
[[category: RTOS Tutorials]]
 
+
[[User:Amruta|Amruta]] ([[User talk:Amruta|talk]]) 13:44, 8 April 2015 (IST)
 
----
 
----
 
==Intro==
 
==Intro==
  
 
This is our first tutorial with FreeRTOS so start with a simple example of how to create and use a task.
 
This is our first tutorial with FreeRTOS so start with a simple example of how to create and use a task.
 +
 
Before going to this tutorial its recommended to first go through the FreeRTOS basics tutorial.
 
Before going to this tutorial its recommended to first go through the FreeRTOS basics tutorial.
  
In main function we will create 3 tasks viz., MyTask1, MyTask2 and MyTask3 with priorities 1,2 and 3 respectively.
+
#In main function we will create 3 tasks viz., MyTask1, MyTask2 and MyTask3 with priorities 1,2 and 3 respectively.
 
+
#An idle task is also created, which will be run when there are no tasks in RUN state.  
An idle task is also created, which will be run when there are no tasks in RUN state.  
+
#Only creating task is not sufficient. Tasks will be executed only when the scheduler is started.
 
+
::So call vTaskStartScheduler() to start the scheduler.
Only creating task is not sufficient. Tasks will be executed once the scheduler is started.
+
So call vTaskStartScheduler() to start the scheduler.
+
  
 
==Code==
 
==Code==
Line 18: Line 17:
 
For making it easier to understand what is happening, we are displaying some data on UART.
 
For making it easier to understand what is happening, we are displaying some data on UART.
  
You can find the function prototypes in the code libraries.
+
You can find the function prototypes and details [[RTOS Basics : TASK|here]].
 
+
<syntaxhighlight>
+
 
+
/* Scheduler include files */
+
#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);
+
 
+
int main(void)
+
+
SystemInit(); /* Initialize the micro-controller */
+
UART_Init(38400); /* Initialize the UART module with baud rate 38400 */
+
 
+
/* Create the three tasks with priorities 1,2,3. Only tasks will be created. */
+
+
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");
+
+
/* Start the schedular */
+
vTaskStartScheduler();
+
 
+
while(1);
+
}
+
 
+
static void MyTask1(void* pvParameters) /* Task1 with priority 1 */
+
{
+
while(1)
+
{
+
UART_Printf("\n\rTask1");
+
vTaskDelay(100);
+
}
+
}
+
 
+
static void MyTask2(void* pvParameters) /* Task1 with priority 2 */
+
{
+
while(1)
+
{
+
UART_Printf("\n\rTask2");
+
vTaskDelay(250);
+
}
+
}
+
 
+
static void MyTask3(void* pvParameters) /* Task1 with priority 3 */
+
{
+
while(1)
+
{
+
UART_Printf("\n\rTask3");
+
vTaskDelay(600);
+
}
+
}
+
  
static void MyIdleTask(void* pvParameters) /* Task1 with priority 4 */
+
<html><script src="https://gist.github.com/Amritach/840e2f9c6b570bfe5b8a.js"></script></html>
{
+
{{DISQUS}}
while(1)
+
{
+
UART_Printf("\n\rIn idle state");
+
}
+
}
+

Latest revision as of 15:16, 24 April 2015

Amruta (talk) 13:44, 8 April 2015 (IST)


Intro

This is our first tutorial with FreeRTOS so start with a simple example of how to create and use a task.

Before going to this tutorial its recommended to first go through the FreeRTOS basics tutorial.

  1. In main function we will create 3 tasks viz., MyTask1, MyTask2 and MyTask3 with priorities 1,2 and 3 respectively.
  2. An idle task is also created, which will be run when there are no tasks in RUN state.
  3. Only creating task is not sufficient. Tasks will be executed only when the scheduler is started.
So call vTaskStartScheduler() to start the scheduler.

Code

For making it easier to understand what is happening, we are displaying some data on UART.

You can find the function prototypes and details here.