changing circuitry to disable RTC, update initialization to match
[fw/openalt] / leds / leds_reuse.c
1 //
2 //  This code was from the original demo package.  Although it is no longer 
3 //  used, it shows an excellent example of how to reuse task code with 
4 //  local variables.  
5 //
6 //  Each time the task is create with xTaskCreate, it increment the task
7 //  number, which it uses to calculate a flash rate and which LED to
8 //  flash.
9 //
10 #include "FreeRTOS.h"
11 #include "task.h"
12
13 #include "../cpu/cpu.h"
14 #include "leds.h"
15
16 //
17 //
18 //
19 #define ledFLASH_RATE_BASE ((portTickType) 333)
20 static portBASE_TYPE uxFlashTaskNumber = 0;
21
22 portTASK_FUNCTION (vLEDFlashTask, pvParameters __attribute__ ((unused)))
23 {
24   portTickType xFlashRate;
25   portTickType xLastFlashTime;
26   unsigned portBASE_TYPE uxLED;
27
28   //
29   // Calculate the LED and flash rate
30   //
31   portENTER_CRITICAL ();
32   {
33     uxLED = uxFlashTaskNumber;
34     uxFlashTaskNumber++;
35   }
36   portEXIT_CRITICAL ();
37
38   xFlashRate = ledFLASH_RATE_BASE + (ledFLASH_RATE_BASE * (portTickType) uxLED);
39   xFlashRate /= portTICK_RATE_MS;
40
41   //
42   //  We will turn the LED on and off again in the delay period, so each delay is only half the total period
43   //
44   xFlashRate /= (portTickType) 2;
45
46   //
47   //  We need to initialise xLastFlashTime prior to the first call to vTaskDelayUntil()
48   //
49   xLastFlashTime = xTaskGetTickCount();
50
51   for (;;)
52   {
53     vTaskDelayUntil (&xLastFlashTime, xFlashRate);
54     cpuToggleLED (uxLED);
55     vTaskDelayUntil (&xLastFlashTime, xFlashRate);
56     cpuToggleLED (uxLED);
57   }
58 }