1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <status_led.h>
26
27
28
29
30
31
32
33
34
35
36
37
38typedef struct {
39 led_id_t mask;
40 int state;
41 int period;
42 int cnt;
43} led_dev_t;
44
45led_dev_t led_dev[] = {
46 { STATUS_LED_BIT,
47 STATUS_LED_STATE,
48 STATUS_LED_PERIOD,
49 0,
50 },
51#if defined(STATUS_LED_BIT1)
52 { STATUS_LED_BIT1,
53 STATUS_LED_STATE1,
54 STATUS_LED_PERIOD1,
55 0,
56 },
57#endif
58#if defined(STATUS_LED_BIT2)
59 { STATUS_LED_BIT2,
60 STATUS_LED_STATE2,
61 STATUS_LED_PERIOD2,
62 0,
63 },
64#endif
65#if defined(STATUS_LED_BIT3)
66 { STATUS_LED_BIT3,
67 STATUS_LED_STATE3,
68 STATUS_LED_PERIOD3,
69 0,
70 },
71#endif
72};
73
74#define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
75
76static int status_led_init_done = 0;
77
78static void status_led_init (void)
79{
80 led_dev_t *ld;
81 int i;
82
83 for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++)
84 __led_init (ld->mask, ld->state);
85 status_led_init_done = 1;
86}
87
88void status_led_tick (ulong timestamp)
89{
90 led_dev_t *ld;
91 int i;
92
93 if (!status_led_init_done)
94 status_led_init ();
95
96 for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
97
98 if (ld->state != STATUS_LED_BLINKING)
99 continue;
100
101 if (++ld->cnt >= ld->period) {
102 __led_toggle (ld->mask);
103 ld->cnt -= ld->period;
104 }
105
106 }
107}
108
109void status_led_set (int led, int state)
110{
111 led_dev_t *ld;
112
113 if (led < 0 || led >= MAX_LED_DEV)
114 return;
115
116 if (!status_led_init_done)
117 status_led_init ();
118
119 ld = &led_dev[led];
120
121 ld->state = state;
122 if (state == STATUS_LED_BLINKING) {
123 ld->cnt = 0;
124 state = STATUS_LED_ON;
125 }
126 __led_set (ld->mask, state);
127}
128