You are not logged in

Log in into our community

Log in so you acess some hidden content

* Fields are required.

Register into our community!

Sign up now for some good content

* Fields are required.

Lost something?

Enter your username or email to reset your password.

* Fields are required.

FREE RTOS install

Posted on : Wed , 07 2014 by : virusi

Theory on FREE RTOS :


Today the response to the input data should be as fast as possible but because the data that should be processed is to big the program should be organized in such a manger that the processing of the big data should be done slower but the acquisition of the input data should be done faster and RTOS dose solve this problem. RTOS dose implement both soft and hard real time requirements.

Soft real-time requirements are those that state a time deadline but breaching the deadline would not render the system useless. For example, responding to keystrokes too slowly may make a system seem annoyingly unresponsive without actually making it unusable.

Hard real-time requirements are those that state a time deadline—and breaching the deadline would result in absolute failure of the system. For example, a driver’s airbag would be worse than useless if it responded to crash sensor inputs too slowly.

An RTOS includes the kernel component, which provides scheduling, communication and synchronization, timers, and interrupt handling. A kernel is not an RTOS, but this can be a confusing issue because of the inappropriate naming chosen for some popular kernels, ‘freeRTOS’ for example.

What are the benefits of the RTOS :

RTOS are time “deterministic”. “Deterministic” timing means that operating system services consume only known and expected amounts of time.

Task Scheduling. A task or a thread of execution is a user defined function that is called based on the priority that is was assigned. The basic rule that governs priority-based preemptive scheduling is that at every moment in time, “The Highest Priority Task that is ready to run will be the task that must be running”.

Fixed time switching. Because the number of tasks is predefined at the initialization we know what the switching time between tasks is.

Modularity. Is the possibility to include and exclude modules to control the size and the speed of the application.

Terminology :

Interrupt Latency is measured as the amount of time between when a device generates an interrupt and when that device is serviced.

Task or a thread of execution is a user defined function.

Task Priority is the number assigned the task. he low-priority task will only get to run after the higher-priority task has finished with its current work.

Jitter is the amount of error in the timing of a task over subsequent iterations of a program or loop is referred to as jitter.

Kernel is the part of an operation system that provides the most basic services to application software running on the processor.

Context switch is the actual process of changing from one task to another.

Let’s create a new task and check the task sequence of the created task.

LPC1768 Practical Example :


Schematic :

IO_PIN
Fig.1 Schematic of LPC1768 with Led connection.

Step by step software tutorial :

In this example will configure and create a task that will be called at every 10ms using FreeRtos kernel.

1. Download the source code from Free Rtos code example ,

FreeRtosLink
Fig.2 Download link.

2. Create a new uVision project

In our projects we are uVision to compile and build our soft and we have decided to make a tutorial on how to create and compile a new project using uVision. Let’s begin.

1. We need to create our skeleton of our project. Create our core folder where everything will be kept (In our case it is project). After this we should create 3 folders where the code, object and Listing files will be kept. Inside of the code folder will create the same 3 folders ( Core where the main file will be kept , Startup where the configuration file will be keep , and system folder where all system files will be kept)

3. Add a new component

RtosFolder
Fig.3 “Rtos” component.

4. Add flowing files into the “rtos” component

FreeRtosTree
Fig.4 “Rtos” Component files.

5. And don’t forget to include path for the “rtos“ component in the Flash >> Configure Flash Tools >> C/C++.

FreeRtosLink
Fig.5 Include Path.

main.c

1. Init the system clock:

/* Initialize clocks */
SystemInit();

2. Set Port direction as output and turn off all the LED’s :

static void PortInit(void)
 {
	/* Configure P 2.00... P 2.07 as output */
	LPC_GPIO2->FIODIR |= ((1UL << 0u)|(1UL << 1u)|
  						  (1UL << 2u)|(1UL << 3u)|
                          (1UL << 4u)|(1UL << 5u)|
                          (1UL << 6u)|(1UL << 7u)) ;
	/* turn off all the LEDs */            
	LPC_GPIO2->FIOCLR = 0x000000FF;		
 }

3. Create a 500ms task and start the RTOS :

static void RtosInit(void)
 {
	xTaskCreate( fnc_500msTask, "500msTask", 240, NULL , 1 , NULL );

	/* Start the scheduler so the tasks start executing. */
	vTaskStartScheduler(); 
 }

4. Turn on and off the LED’s in the 500ms task :

 const portTickType	delay = ( 500 / portTICK_RATE_MS );
static void fnc_500msTask(void *pvParameters)
 {
 	static unsigned char portval = 0x00;
 	portTickType xLastWakeTime;
 	xLastWakeTime = xTaskGetTickCount();

   	for(;;)
   	{
		/* Toogle all outputs leds */
		portval = portval^0xFF;
		LPC_GPIO2->FIOPIN = portval;  

		/* delay task for 5ms */	
	   	vTaskDelayUntil( &xLastWakeTime, delay );
   	}
 }

Adapt FreeRtosConfig.h

1. Activate TaskDelayUntil

#define INCLUDE_vTaskDelayUntil	1

Adapt startup_LPC17xx.s

1. Add SVCHandler , PendSVHandler , SysTickHandler functions used for RTOS :

__heap_limit

                PRESERVE8
                THUMB
			; FreeRTOS specific handlers.
			EXTERN 	vPortSVCHandler
			EXTERN  xPortPendSVHandler
			EXTERN  xPortSysTickHandler

2. Adapt Interrupt vector table :

DCD     vPortSVCHandler           ; SVCall Handler
DCD     DebugMon_Handler          ; Debug Monitor Handler
DCD     0                         ; Reserved
DCD     xPortPendSVHandler        ; PendSV Handler
DCD     xPortSysTickHandler       ; SysTick Handle

Task sequence call :

FreeRtosSequenceCall
Fig.6 Task sequence call

1. The Kernel calls the task with the highest priority.

2. The 500ms task is called and the LED is turned on or off.

3. After the 500ms task is over the kernel is called and the idle task is called because the 500ms task is in block state, waiting for the delay to pass.

4. The idle task is called.

5. After the delay has passed the kernel is called again and the 500ms task is called.

6. The 500ms task is executed.

7. The process is executed continuously.

Download :


Interested in the running and tested version FreeRTOS install example.

Last updated on Wed , 08 2014
SHARE THIS PAGE :

This page is waiting for your comment.

Share and Leave a comment.

You must be logged in to post a comment.

Back to Top