etisserant@0: /* etisserant@0: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: etisserant@0: Author: CANopen Canada (canfestival@canopencanada.ca) etisserant@0: etisserant@0: See COPYING file for copyrights details. etisserant@0: etisserant@0: This library is free software; you can redistribute it and/or etisserant@0: modify it under the terms of the GNU Lesser General Public etisserant@0: License as published by the Free Software Foundation; either etisserant@0: version 2.1 of the License, or (at your option) any later version. etisserant@0: etisserant@0: This library is distributed in the hope that it will be useful, etisserant@0: but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: Lesser General Public License for more details. etisserant@0: etisserant@0: You should have received a copy of the GNU Lesser General Public etisserant@0: License along with this library; if not, write to the Free Software etisserant@0: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: DS-303-3 etisserant@0: LED implementation etisserant@0: */ etisserant@0: etisserant@0: #include etisserant@0: #include etisserant@0: etisserant@0: #include etisserant@0: #include etisserant@0: etisserant@0: #include etisserant@0: etisserant@0: #include etisserant@0: #include etisserant@0: etisserant@0: #include "led.h" etisserant@0: etisserant@0: etisserant@0: void led_start_timer(CO_Data *, UNS32 t0); etisserant@0: void led_stop_timer(void); etisserant@0: void led_set_green(UNS8 on); etisserant@0: void led_set_red(UNS8 on); etisserant@0: void led_callback(CO_Data* d, UNS32 id); lbessard@31: void led_set_redgreen(CO_Data *d, unsigned char state); etisserant@0: etisserant@0: etisserant@0: // 0 = always off, 1 = always on, 2 = flashing etisserant@0: static UNS8 led_state_red, led_state_green; etisserant@0: etisserant@0: static UNS16 led_sequence_red, led_seq_index_red; etisserant@0: static UNS16 led_sequence_green, led_seq_index_green; etisserant@0: etisserant@0: static UNS8 led_error_code = LED_NO_ERROR; etisserant@0: etisserant@0: const char *led_sequence_table[6] = // up and downs of the sequence etisserant@0: { etisserant@0: "01", // flickering etisserant@0: "01", // blinking etisserant@0: "100000", // single flash etisserant@0: "10100000", // double flash etisserant@0: "1010100000", // triple flash etisserant@0: "101010100000" // quadruple flash etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: void led_set_state(CO_Data *d, int state) etisserant@0: { lbessard@35: //printf("led_set_state(%x)\n", state); oremeq@3: etisserant@0: switch(state) etisserant@0: { etisserant@0: case Initialisation: etisserant@0: /* etisserant@0: must create a timer for the leds with the scheduler etisserant@0: */ etisserant@0: break; etisserant@0: case LED_AUTOBITRATE: etisserant@0: led_state_green = 2; etisserant@0: led_sequence_green = 0; etisserant@0: break; etisserant@0: case Pre_operational: etisserant@0: led_state_green = 2; etisserant@0: led_sequence_green = 1; etisserant@0: break; etisserant@0: case Stopped: etisserant@0: led_state_green = 2; etisserant@0: led_sequence_green = 2; etisserant@0: break; etisserant@0: case LED_PRG_DOWNLOAD: etisserant@0: led_state_green = 2; etisserant@0: led_sequence_green = 4; etisserant@0: break; etisserant@0: case Operational: etisserant@0: led_state_green = 1; etisserant@0: break; etisserant@0: } etisserant@0: etisserant@0: if (state == LED_AUTOBITRATE) etisserant@0: led_start_timer(d, 50); etisserant@0: etisserant@0: else if (led_state_green < 2 && led_state_red < 2) etisserant@0: { etisserant@0: led_stop_timer(); etisserant@0: oremeq@3: //led_set_green(led_state_green); oremeq@3: //led_set_red(led_state_red); etisserant@0: } etisserant@0: etisserant@0: else etisserant@0: led_start_timer(d, 200); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void led_set_error(CO_Data *d, UNS8 error) etisserant@0: { etisserant@0: if (error == LED_NO_ERROR) etisserant@0: { etisserant@0: led_error_code = error; etisserant@0: etisserant@0: led_state_green = 0; etisserant@0: } etisserant@0: etisserant@0: else if (error == LED_AUTOBITRATE) etisserant@0: { etisserant@0: led_error_code = error; etisserant@0: etisserant@0: led_state_red = 2; etisserant@0: led_sequence_red = 0; etisserant@0: etisserant@0: led_start_timer(d, 50); etisserant@0: } etisserant@0: etisserant@0: else if (error > led_error_code) etisserant@0: { etisserant@0: led_error_code = error; etisserant@0: etisserant@0: if (error & LED_INVALID_CONFIG) etisserant@0: { etisserant@0: led_state_red = 2; etisserant@0: led_sequence_red = 1; etisserant@0: } etisserant@0: etisserant@0: else if (error & LED_WARNING_LIMIT_REACH) etisserant@0: { etisserant@0: led_state_red = 2; etisserant@0: led_sequence_red = 2; etisserant@0: } etisserant@0: etisserant@0: else if (error & LED_ERROR_CTRL_EVENT) etisserant@0: { etisserant@0: led_state_red = 2; etisserant@0: led_sequence_red = 3; etisserant@0: } etisserant@0: etisserant@0: else if (error & LED_SYNC_ERROR) etisserant@0: { etisserant@0: led_state_red = 2; etisserant@0: led_sequence_red = 4; etisserant@0: } etisserant@0: etisserant@0: else if (error & LED_EVENT_TIMER_ERROR) etisserant@0: { etisserant@0: led_state_red = 2; etisserant@0: led_sequence_green = 5; etisserant@0: } etisserant@0: etisserant@0: else if (error & LED_BUS_OFF) etisserant@0: { etisserant@0: led_state_green = 1; etisserant@0: } etisserant@0: etisserant@0: led_start_timer(d, 200); oremeq@3: //led_set_red(led_state_red); etisserant@0: } etisserant@0: etisserant@0: if (led_state_green < 2 && led_state_red < 2) etisserant@0: { etisserant@0: led_stop_timer(); etisserant@0: oremeq@3: //led_set_green(led_state_green); oremeq@3: //led_set_red(led_state_red); etisserant@0: } etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void led_start_timer(CO_Data* d, UNS32 tm) etisserant@0: { etisserant@0: SetAlarm(d, 0, &led_callback, MS_TO_TIMEVAL(tm), MS_TO_TIMEVAL(tm)); etisserant@0: etisserant@0: led_seq_index_red = 0; etisserant@0: led_seq_index_green = 0; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void led_stop_timer(void) etisserant@0: { etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void led_callback(CO_Data *d, UNS32 id) etisserant@0: { oremeq@3: UNS8 bits = 0; etisserant@0: etisserant@0: // RED LED etisserant@0: if (led_sequence_table[led_sequence_red][led_seq_index_red] == '1') etisserant@0: { etisserant@0: if (led_state_red > 0) etisserant@0: bits = 1; etisserant@0: /* led_set_red(1); */ etisserant@0: } etisserant@0: else etisserant@0: { etisserant@0: /*if (led_state_red != 1) etisserant@0: led_set_red(0);*/ etisserant@0: } etisserant@0: etisserant@0: led_seq_index_red++; etisserant@0: if (led_seq_index_red > strlen(led_sequence_table[led_sequence_red])) etisserant@0: led_seq_index_red = 0; etisserant@0: etisserant@0: // GREEN LED etisserant@0: if (led_sequence_table[led_sequence_green][led_seq_index_green] == '1') etisserant@0: { etisserant@0: if (led_state_green > 0) etisserant@0: bits = bits | 2; etisserant@0: /* led_set_green(1); */ etisserant@0: } etisserant@0: else etisserant@0: { etisserant@0: /* if (led_state_green != 1) etisserant@0: led_set_green(0); */ etisserant@0: } etisserant@0: etisserant@0: led_seq_index_green++; etisserant@0: if (led_seq_index_green > strlen(led_sequence_table[led_sequence_green])) etisserant@0: led_seq_index_green = 0; etisserant@0: lbessard@35: //led_set_redgreen(d, bits); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: /* etisserant@0: char state(state); etisserant@0: etisserant@0: etisserant@0: Input function to set all the bihaviour indicator etisserant@0: typical state are: etisserant@0: NoError etisserant@0: RedLED=off etisserant@0: AutoBitRate_LSS etisserant@0: RedLED=flickering etisserant@0: GreenLED=flickering etisserant@0: InvalidConfiguration etisserant@0: RedLED=blinking etisserant@0: WarningLimitReached etisserant@0: RedLED=singleflash etisserant@0: ErrorControlEvent etisserant@0: RedLED=doubleflash etisserant@0: SyncError etisserant@0: RedLED=tripleflash etisserant@0: EventTimerError etisserant@0: RedLED=quadrupleflash etisserant@0: BusOFF etisserant@0: RedLED=on etisserant@0: PRE_OPERATIONAL etisserant@0: GreenLED=blinking etisserant@0: STOPPED etisserant@0: GreenLED=singleflash etisserant@0: Programm_Firmware_download etisserant@0: GreenLED=tripleflash etisserant@0: OPERATIONNAL etisserant@0: GreenLED=on etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: case LEDbihaviour: etisserant@0: on etisserant@0: etisserant@0: flickeringerror etisserant@0: RedLED(on) etisserant@0: RedLED(off) etisserant@0: flickeringerror etisserant@0: GreenLED(off) etisserant@0: GreenLED(on) etisserant@0: blinking etisserant@0: etisserant@0: singleflash etisserant@0: etisserant@0: doubleflash etisserant@0: etisserant@0: tripleflash etisserant@0: etisserant@0: quadrupleflash etisserant@0: etisserant@0: off etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: char LED(bitLEDs); etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: Output function to call the driver. etisserant@0: if bit=0, then turn LED Off etisserant@0: if bit=1, then turn LED On etisserant@0: etisserant@0: bit# color name etisserant@0: 0 red error/status etisserant@0: 1 green run/status etisserant@0: 2 etisserant@0: 3 etisserant@0: 4 etisserant@0: 5 etisserant@0: 6 etisserant@0: 7 etisserant@0: */ etisserant@0: