Actions

EmSys

Difference between revisions of "FreeRTOS Exercise Lab04"

From EdWiki

(Created page with "__NOTOC__ == FreeRTOS Lab 04 == * The tasks created in the previous examples spend most of their time in the Blocked state. While in this state, they are not able to run, so c...")
 
m
Line 6: Line 6:
 
* It is possible to add application specific functionality directly into the idle task through the use of an idle hook (or idle callback) function — a function that is called automatically by the idle task once per iteration of the idle task loop.
 
* It is possible to add application specific functionality directly into the idle task through the use of an idle hook (or idle callback) function — a function that is called automatically by the idle task once per iteration of the idle task loop.
  
# Create a CCS Project using FreeRTOS [[EmSys:Create a Project using FreeRTOS Project Template| Project Template]]
+
# Create two Tasks as in the [[EmSys:FreeRTOS Exercise Lab01 | Lab 01]]
# Add [{{SERVER}}/emsys/rtos/freertos/printf-stdarg.c printf-stdarg.c] file to project ('''Project > Add Files ...''')
+
# Create a third Task which will print the number of idle counts.
# Initialize [[EmSys:TM4C123G Launchpad UART Programming | UART0]] for 115,200 baud rate (assuming 16 MHz bus clock), 8 bit word length, no parity bits, one stop bit, FIFOs enabled. (UART0 Echo Source Code is available [{{SERVER}}/emsys/tivac/tm4c_uart_echo.c here])
+
 
 +
* configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h for the idle hook function to get called.
 +
* Idle task hook function must have the name and prototype as shown below
 +
void vApplicationIdleHook( void );
 +
 
 +
<syntaxhighlight lang="c">
 +
/* Declare a variable that will be incremented by the hook function. */
 +
volatile uint32_t ulIdleCycleCount = 0UL;
 +
 
 +
/* Idle hook functions MUST be called vApplicationIdleHook(), take no parameters, and return void. */
 +
void vApplicationIdleHook( void )
 +
{
 +
    /* This hook function does nothing but increment a counter. */
 +
    ulIdleCycleCount++;
 +
}
 +
</syntaxhighlight>
 +
 
  
  

Revision as of 11:24, 1 August 2019

FreeRTOS Lab 04

  • The tasks created in the previous examples spend most of their time in the Blocked state. While in this state, they are not able to run, so cannot be selected by the scheduler.
  • 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 does very little more than sit in a loop—so, it is always able to run.
  • The idle task has the lowest possible priority (priority zero), to ensure it never prevents a higher priority application task from entering the Running state.
  • It is possible to add application specific functionality directly into the idle task through the use of an idle hook (or idle callback) function — a function that is called automatically by the idle task once per iteration of the idle task loop.
  1. Create two Tasks as in the Lab 01
  2. Create a third Task which will print the number of idle counts.
  • configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h for the idle hook function to get called.
  • Idle task hook function must have the name and prototype as shown below
void vApplicationIdleHook( void );
/* Declare a variable that will be incremented by the hook function. */
volatile uint32_t ulIdleCycleCount = 0UL;
 
/* Idle hook functions MUST be called vApplicationIdleHook(), take no parameters, and return void. */
void vApplicationIdleHook( void )
{
    /* This hook function does nothing but increment a counter. */
    ulIdleCycleCount++;
}



Prev.gif
Home.gif