changing circuitry to disable RTC, update initialization to match
[fw/openalt] / leds / leds.c
1 //
2 //
3 //
4 #include "FreeRTOS.h"
5 #include "task.h"
6 #include "queue.h"
7
8 #include "../cpu/cpu.h"
9 #include "leds.h"
10
11 //
12 //
13 //
14 typedef struct
15 {
16   int timeOn;
17   int timeOff;
18 }
19 ledDutyCycles_t;
20
21 static ledDutyCycles_t ledDutyCycles [] = 
22 {
23   { (200 / portTICK_RATE_MS), (800 / portTICK_RATE_MS) },
24   { (400 / portTICK_RATE_MS), (600 / portTICK_RATE_MS) },
25   { (600 / portTICK_RATE_MS), (400 / portTICK_RATE_MS) },
26   { (800 / portTICK_RATE_MS), (200 / portTICK_RATE_MS) },
27 };
28
29 xQueueHandle xLEDQueue;
30
31 //
32 //
33 //
34 portTASK_FUNCTION (vLEDFlashTask, pvParameters __attribute__ ((unused)))
35 {
36   portTickType ledTimeOn = 1;
37   portTickType ledTimeOff = 1;
38   portTickType lastTickTime;
39   int dutyCycle = 0;
40
41   //
42   //  Create the queue, turn on LED and die if we can't
43   //
44   if ((xLEDQueue = xQueueCreate (1, sizeof (dutyCycle))) == 0)
45   {
46     GPIO0_IOSET = GPIO_IO_P10;
47
48     while (1)
49       vTaskDelay (100);
50   }
51
52   //
53   //  Send ourselves a message to init the flash time
54   //
55   xQueueSend (xLEDQueue, &dutyCycle, (portTickType) 0);
56
57   //
58   //  We need to initialise lastTickTime prior to the first call to vTaskDelayUntil()
59   //
60   lastTickTime = xTaskGetTickCount ();
61
62   for (;;)
63   {
64     vTaskDelayUntil (&lastTickTime, ledTimeOn);
65     GPIO0_IOSET = GPIO_IO_P10;
66     vTaskDelayUntil (&lastTickTime, ledTimeOff);
67     GPIO0_IOCLR = GPIO_IO_P10;
68
69     if (xQueueReceive (xLEDQueue, &dutyCycle, (portTickType) 0))
70     {
71       dutyCycle %= arrsizeof (ledDutyCycles);
72
73       ledTimeOn  = ledDutyCycles [dutyCycle].timeOn;
74       ledTimeOff = ledDutyCycles [dutyCycle].timeOff;
75     }
76   }
77 }