0
|
1 |
/*
|
|
2 |
This file is part of CanFestival, a library implementing CanOpen Stack.
|
|
3 |
|
|
4 |
Author: CANopen Canada (canfestival@canopencanada.ca)
|
|
5 |
|
|
6 |
See COPYING file for copyrights details.
|
|
7 |
|
|
8 |
This library is free software; you can redistribute it and/or
|
|
9 |
modify it under the terms of the GNU Lesser General Public
|
|
10 |
License as published by the Free Software Foundation; either
|
|
11 |
version 2.1 of the License, or (at your option) any later version.
|
|
12 |
|
|
13 |
This library is distributed in the hope that it will be useful,
|
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 |
Lesser General Public License for more details.
|
|
17 |
|
|
18 |
You should have received a copy of the GNU Lesser General Public
|
|
19 |
License along with this library; if not, write to the Free Software
|
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 |
|
|
22 |
DS-303-3
|
|
23 |
LED implementation
|
|
24 |
*/
|
|
25 |
|
|
26 |
#include <stdlib.h>
|
|
27 |
#include <string.h>
|
|
28 |
|
|
29 |
#include <sys/time.h>
|
|
30 |
#include <signal.h>
|
|
31 |
|
|
32 |
#include <applicfg.h>
|
|
33 |
|
|
34 |
#include <data.h>
|
|
35 |
#include <can_driver.h>
|
|
36 |
|
|
37 |
#include "led.h"
|
|
38 |
|
|
39 |
|
|
40 |
void led_start_timer(CO_Data *, UNS32 t0);
|
|
41 |
void led_stop_timer(void);
|
|
42 |
void led_set_green(UNS8 on);
|
|
43 |
void led_set_red(UNS8 on);
|
|
44 |
void led_callback(CO_Data* d, UNS32 id);
|
|
45 |
|
|
46 |
|
|
47 |
// 0 = always off, 1 = always on, 2 = flashing
|
|
48 |
static UNS8 led_state_red, led_state_green;
|
|
49 |
|
|
50 |
static UNS16 led_sequence_red, led_seq_index_red;
|
|
51 |
static UNS16 led_sequence_green, led_seq_index_green;
|
|
52 |
|
|
53 |
static UNS8 led_error_code = LED_NO_ERROR;
|
|
54 |
|
|
55 |
const char *led_sequence_table[6] = // up and downs of the sequence
|
|
56 |
{
|
|
57 |
"01", // flickering
|
|
58 |
"01", // blinking
|
|
59 |
"100000", // single flash
|
|
60 |
"10100000", // double flash
|
|
61 |
"1010100000", // triple flash
|
|
62 |
"101010100000" // quadruple flash
|
|
63 |
};
|
|
64 |
|
|
65 |
|
|
66 |
void led_set_state(CO_Data *d, int state)
|
|
67 |
{
|
3
|
68 |
printf("led_set_state(%x)\n", state);
|
|
69 |
|
0
|
70 |
switch(state)
|
|
71 |
{
|
|
72 |
case Initialisation:
|
|
73 |
/*
|
|
74 |
must create a timer for the leds with the scheduler
|
|
75 |
*/
|
|
76 |
break;
|
|
77 |
case LED_AUTOBITRATE:
|
|
78 |
led_state_green = 2;
|
|
79 |
led_sequence_green = 0;
|
|
80 |
break;
|
|
81 |
case Pre_operational:
|
|
82 |
led_state_green = 2;
|
|
83 |
led_sequence_green = 1;
|
|
84 |
break;
|
|
85 |
case Stopped:
|
|
86 |
led_state_green = 2;
|
|
87 |
led_sequence_green = 2;
|
|
88 |
break;
|
|
89 |
case LED_PRG_DOWNLOAD:
|
|
90 |
led_state_green = 2;
|
|
91 |
led_sequence_green = 4;
|
|
92 |
break;
|
|
93 |
case Operational:
|
|
94 |
led_state_green = 1;
|
|
95 |
break;
|
|
96 |
}
|
|
97 |
|
|
98 |
if (state == LED_AUTOBITRATE)
|
|
99 |
led_start_timer(d, 50);
|
|
100 |
|
|
101 |
else if (led_state_green < 2 && led_state_red < 2)
|
|
102 |
{
|
|
103 |
led_stop_timer();
|
|
104 |
|
3
|
105 |
//led_set_green(led_state_green);
|
|
106 |
//led_set_red(led_state_red);
|
0
|
107 |
}
|
|
108 |
|
|
109 |
else
|
|
110 |
led_start_timer(d, 200);
|
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
void led_set_error(CO_Data *d, UNS8 error)
|
|
115 |
{
|
|
116 |
if (error == LED_NO_ERROR)
|
|
117 |
{
|
|
118 |
led_error_code = error;
|
|
119 |
|
|
120 |
led_state_green = 0;
|
|
121 |
}
|
|
122 |
|
|
123 |
else if (error == LED_AUTOBITRATE)
|
|
124 |
{
|
|
125 |
led_error_code = error;
|
|
126 |
|
|
127 |
led_state_red = 2;
|
|
128 |
led_sequence_red = 0;
|
|
129 |
|
|
130 |
led_start_timer(d, 50);
|
|
131 |
}
|
|
132 |
|
|
133 |
else if (error > led_error_code)
|
|
134 |
{
|
|
135 |
led_error_code = error;
|
|
136 |
|
|
137 |
if (error & LED_INVALID_CONFIG)
|
|
138 |
{
|
|
139 |
led_state_red = 2;
|
|
140 |
led_sequence_red = 1;
|
|
141 |
}
|
|
142 |
|
|
143 |
else if (error & LED_WARNING_LIMIT_REACH)
|
|
144 |
{
|
|
145 |
led_state_red = 2;
|
|
146 |
led_sequence_red = 2;
|
|
147 |
}
|
|
148 |
|
|
149 |
else if (error & LED_ERROR_CTRL_EVENT)
|
|
150 |
{
|
|
151 |
led_state_red = 2;
|
|
152 |
led_sequence_red = 3;
|
|
153 |
}
|
|
154 |
|
|
155 |
else if (error & LED_SYNC_ERROR)
|
|
156 |
{
|
|
157 |
led_state_red = 2;
|
|
158 |
led_sequence_red = 4;
|
|
159 |
}
|
|
160 |
|
|
161 |
else if (error & LED_EVENT_TIMER_ERROR)
|
|
162 |
{
|
|
163 |
led_state_red = 2;
|
|
164 |
led_sequence_green = 5;
|
|
165 |
}
|
|
166 |
|
|
167 |
else if (error & LED_BUS_OFF)
|
|
168 |
{
|
|
169 |
led_state_green = 1;
|
|
170 |
}
|
|
171 |
|
|
172 |
led_start_timer(d, 200);
|
3
|
173 |
//led_set_red(led_state_red);
|
0
|
174 |
}
|
|
175 |
|
|
176 |
if (led_state_green < 2 && led_state_red < 2)
|
|
177 |
{
|
|
178 |
led_stop_timer();
|
|
179 |
|
3
|
180 |
//led_set_green(led_state_green);
|
|
181 |
//led_set_red(led_state_red);
|
0
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
void led_start_timer(CO_Data* d, UNS32 tm)
|
|
187 |
{
|
|
188 |
SetAlarm(d, 0, &led_callback, MS_TO_TIMEVAL(tm), MS_TO_TIMEVAL(tm));
|
|
189 |
|
|
190 |
led_seq_index_red = 0;
|
|
191 |
led_seq_index_green = 0;
|
|
192 |
}
|
|
193 |
|
|
194 |
|
|
195 |
void led_stop_timer(void)
|
|
196 |
{
|
|
197 |
}
|
|
198 |
|
|
199 |
|
|
200 |
void led_callback(CO_Data *d, UNS32 id)
|
|
201 |
{
|
3
|
202 |
UNS8 bits = 0;
|
0
|
203 |
|
|
204 |
// RED LED
|
|
205 |
if (led_sequence_table[led_sequence_red][led_seq_index_red] == '1')
|
|
206 |
{
|
|
207 |
if (led_state_red > 0)
|
|
208 |
bits = 1;
|
|
209 |
/* led_set_red(1); */
|
|
210 |
}
|
|
211 |
else
|
|
212 |
{
|
|
213 |
/*if (led_state_red != 1)
|
|
214 |
led_set_red(0);*/
|
|
215 |
}
|
|
216 |
|
|
217 |
led_seq_index_red++;
|
|
218 |
if (led_seq_index_red > strlen(led_sequence_table[led_sequence_red]))
|
|
219 |
led_seq_index_red = 0;
|
|
220 |
|
|
221 |
// GREEN LED
|
|
222 |
if (led_sequence_table[led_sequence_green][led_seq_index_green] == '1')
|
|
223 |
{
|
|
224 |
if (led_state_green > 0)
|
|
225 |
bits = bits | 2;
|
|
226 |
/* led_set_green(1); */
|
|
227 |
}
|
|
228 |
else
|
|
229 |
{
|
|
230 |
/* if (led_state_green != 1)
|
|
231 |
led_set_green(0); */
|
|
232 |
}
|
|
233 |
|
|
234 |
led_seq_index_green++;
|
|
235 |
if (led_seq_index_green > strlen(led_sequence_table[led_sequence_green]))
|
|
236 |
led_seq_index_green = 0;
|
|
237 |
|
3
|
238 |
led_set_redgreen(d, bits);
|
0
|
239 |
}
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
/*
|
|
246 |
char state(state);
|
|
247 |
|
|
248 |
|
|
249 |
Input function to set all the bihaviour indicator
|
|
250 |
typical state are:
|
|
251 |
NoError
|
|
252 |
RedLED=off
|
|
253 |
AutoBitRate_LSS
|
|
254 |
RedLED=flickering
|
|
255 |
GreenLED=flickering
|
|
256 |
InvalidConfiguration
|
|
257 |
RedLED=blinking
|
|
258 |
WarningLimitReached
|
|
259 |
RedLED=singleflash
|
|
260 |
ErrorControlEvent
|
|
261 |
RedLED=doubleflash
|
|
262 |
SyncError
|
|
263 |
RedLED=tripleflash
|
|
264 |
EventTimerError
|
|
265 |
RedLED=quadrupleflash
|
|
266 |
BusOFF
|
|
267 |
RedLED=on
|
|
268 |
PRE_OPERATIONAL
|
|
269 |
GreenLED=blinking
|
|
270 |
STOPPED
|
|
271 |
GreenLED=singleflash
|
|
272 |
Programm_Firmware_download
|
|
273 |
GreenLED=tripleflash
|
|
274 |
OPERATIONNAL
|
|
275 |
GreenLED=on
|
|
276 |
*/
|
|
277 |
|
|
278 |
/*
|
|
279 |
case LEDbihaviour:
|
|
280 |
on
|
|
281 |
|
|
282 |
flickeringerror
|
|
283 |
RedLED(on)
|
|
284 |
RedLED(off)
|
|
285 |
flickeringerror
|
|
286 |
GreenLED(off)
|
|
287 |
GreenLED(on)
|
|
288 |
blinking
|
|
289 |
|
|
290 |
singleflash
|
|
291 |
|
|
292 |
doubleflash
|
|
293 |
|
|
294 |
tripleflash
|
|
295 |
|
|
296 |
quadrupleflash
|
|
297 |
|
|
298 |
off
|
|
299 |
*/
|
|
300 |
|
|
301 |
/*
|
|
302 |
char LED(bitLEDs);
|
|
303 |
*/
|
|
304 |
|
|
305 |
/*
|
|
306 |
Output function to call the driver.
|
|
307 |
if bit=0, then turn LED Off
|
|
308 |
if bit=1, then turn LED On
|
|
309 |
|
|
310 |
bit# color name
|
|
311 |
0 red error/status
|
|
312 |
1 green run/status
|
|
313 |
2
|
|
314 |
3
|
|
315 |
4
|
|
316 |
5
|
|
317 |
6
|
|
318 |
7
|
|
319 |
*/
|
|
320 |
|