#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"
#include "partest.h"
#include "flash.h"
Go to the source code of this file.
Defines | |
#define | ledFLASH_RATE_BASE ( ( portTickType ) 333 ) |
#define | ledNUMBER_OF_LEDS ( 3 ) |
#define | ledSTACK_SIZE configMINIMAL_STACK_SIZE |
This version of flash .c is for use on systems that have limited stack space and no display facilities. | |
Functions | |
static | portTASK_FUNCTION (vLEDFlashTask, pvParameters) |
static | portTASK_FUNCTION_PROTO (vLEDFlashTask, pvParameters) |
void | vStartLEDFlashTasks (unsigned portBASE_TYPE uxPriority) |
Variables | |
static volatile unsigned portBASE_TYPE | uxFlashTaskNumber = 0 |
#define ledFLASH_RATE_BASE ( ( portTickType ) 333 ) |
#define ledNUMBER_OF_LEDS ( 3 ) |
#define ledSTACK_SIZE configMINIMAL_STACK_SIZE |
This version of flash .c is for use on systems that have limited stack space and no display facilities.
The complete version can be found in the Demo/Common/Full directory.
Three tasks are created, each of which flash an LED at a different rate. The first LED flashes every 200ms, the second every 400ms, the third every 600ms.
The LED flash tasks provide instant visual feedback. They show that the scheduler is still operational.
Definition at line 78 of file flash.c.
Referenced by vStartLEDFlashTasks().
static portTASK_FUNCTION | ( | vLEDFlashTask | , | |
pvParameters | ||||
) | [static] |
Definition at line 104 of file flash.c.
References ledFLASH_RATE_BASE, portBASE_TYPE, portENTER_CRITICAL, portEXIT_CRITICAL, portTICK_RATE_MS, uxFlashTaskNumber, vParTestToggleLED(), vTaskDelayUntil(), and xTaskGetTickCount().
00105 { 00106 portTickType xFlashRate, xLastFlashTime; 00107 unsigned portBASE_TYPE uxLED; 00108 00109 /* The parameters are not used. */ 00110 ( void ) pvParameters; 00111 00112 /* Calculate the LED and flash rate. */ 00113 portENTER_CRITICAL(); 00114 { 00115 /* See which of the eight LED's we should use. */ 00116 uxLED = uxFlashTaskNumber; 00117 00118 /* Update so the next task uses the next LED. */ 00119 uxFlashTaskNumber++; 00120 } 00121 portEXIT_CRITICAL(); 00122 00123 xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( portTickType ) uxLED ); 00124 xFlashRate /= portTICK_RATE_MS; 00125 00126 /* We will turn the LED on and off again in the delay period, so each 00127 delay is only half the total period. */ 00128 xFlashRate /= ( portTickType ) 2; 00129 00130 /* We need to initialise xLastFlashTime prior to the first call to 00131 vTaskDelayUntil(). */ 00132 xLastFlashTime = xTaskGetTickCount(); 00133 00134 for(;;) 00135 { 00136 /* Delay for half the flash period then turn the LED on. */ 00137 vTaskDelayUntil( &xLastFlashTime, xFlashRate ); 00138 vParTestToggleLED( uxLED ); 00139 00140 /* Delay for half the flash period then turn the LED off. */ 00141 vTaskDelayUntil( &xLastFlashTime, xFlashRate ); 00142 vParTestToggleLED( uxLED ); 00143 } 00144 } /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
static portTASK_FUNCTION_PROTO | ( | vLEDFlashTask | , | |
pvParameters | ||||
) | [static] |
void vStartLEDFlashTasks | ( | unsigned portBASE_TYPE | uxPriority | ) |
Definition at line 91 of file flash.c.
References ledNUMBER_OF_LEDS, ledSTACK_SIZE, portBASE_TYPE, and xTaskCreate.
Referenced by main().
00092 { 00093 signed portBASE_TYPE xLEDTask; 00094 00095 /* Create the three tasks. */ 00096 for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask ) 00097 { 00098 /* Spawn the task. */ 00099 xTaskCreate( vLEDFlashTask, ( signed char * ) "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL ); 00100 } 00101 }
volatile unsigned portBASE_TYPE uxFlashTaskNumber = 0 [static] |