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 idle task

Posted on : Wed , 08 2014 by : virusi

Theory on FREE RTOS idle task :


The processor always needs something to execute – there must always be at least one task that can enter the Running state. To ensure this is the case an idle task is automatically created by the scheduler when vTaskStartScheduler() is called. The idle task has the lowest possible priority (priority 0) to ensure it never prevents a higher priority application task from entering the Running state – although there is nothing to prevent application designers creating task at, and therefore sharing, the idle task priority if desired. Running at the lowest priority ensures the idle task will be immediately transitioned out of the Running state as soon as a higher priority task enters the Ready state.

Common uses for the idle task hook include :

– Executing low priority, background or continuous processing.

– Measuring the amount of spare processing capacity (the idle task will only run when all the other tasks have no work to perform, so measuring the amount of processing time allocated to the idle task provides a clear indication of how much processing time is spare).

– Placing the processor into a low power mode – providing an automatic method of saving power whenever there is no application processing to be performed.

Limitations on the Implementation of Idle Task Hook Functions :

– They must never attempt to block or suspend. The Idle task will only execute when no other tasks are able to do so (unless application tasks are sharing the idle priority). Blocking the idle task in any way could therefore cause a scenario where no tasks are available to enter the Running state!

– If the application makes use of the vTaskDelete() API function then the Idle task hook must always return to its caller within a reasonable time period. This is because the idle task is responsible for cleaning up kernel resources after a task has been deleted. If the idle task remains permanently in the idle hook function then this clean up cannot occur.

LPC1768 Practical Example :


In this example will create a 500ms task and add an idle hock. In the 10ms task will turn all LED’s on but in the idle hock will turn the LED’s off. Because the 10ms task is executed every 500 ms but the idle task is executed the rest of the time this will cause the LED’s to flicker.

Schematic :

IO_PIN
Fig.2 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 and add a hock to the idle task.

1. Download the source code from Free Rtos code

FreeRtosLink
Fig.3 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.4 “Rtos” component.

4. Add flowing files into the “rtos” component

FreeRtosTree
Fig.5 “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.6 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 the LED’s in the 500ms task :

const portTickType	delay500ms = (500/portTICK_RATE_MS);
static void fnc_500msTask(void *pvParameters)
 {
 	portTickType xLastWakeTime;
 	xLastWakeTime = xTaskGetTickCount();

   	for(;;)
   	{
		/* turn on all leds */
		LPC_GPIO2->FIOPIN = 0xFF;  

		/* delay task for 500ms */	
	   	vTaskDelayUntil( &xLastWakeTime, delay500ms );

		/* Allow the other sender task to execute. */
		taskYIELD();
   	}
 }

5. Turn off the LED’s in the idle task :

void vApplicationIdleHook(void)
 {
	/* turn off all leds */
	LPC_GPIO2->FIOPIN = 0x00;  
 }

Adapt FreeRtosConfig.h

1. Activate TaskDelayUntil :

#define INCLUDE_vTaskDelayUntil	1

2. Activate use of the idle hook :

#define configUSE_IDLE_HOOK	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 :

After all the necessary changes are done the LEDS should be turned on in the 500ms task and turned off in the idle task. Let’s take a look at the RTOS execution sequence.
FreeRtosSequenceCall
Fig.7 Task sequence call

1. The RTOS calls highest priority task .

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

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 and the LED is turned off.

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 RTOS idle.

Last updated on Mon , 09 2014
SHARE THIS PAGE :

2 comments on "FREE RTOS idle task"

  1. […] Welcome – Embedded Systems Academy. 557. PICTURE TO ASCII CONVERT – PICASCII. FREE RTOS idle task | Microcontrollers |Eager Learning. […]

  2. […] FREE RTOS idle task | Microcontrollers |Eager Learning. […]

Share and Leave a comment.

You must be logged in to post a comment.

Back to Top