etisserant@0: /* etisserant@0: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: etisserant@0: Copyright (C): Edouard TISSERANT and Francis DUPIN 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: etisserant@0: #include /* for NULL */ etisserant@0: etisserant@0: #include etisserant@0: #include etisserant@0: #include etisserant@0: #include etisserant@0: etisserant@0: #include etisserant@0: #include etisserant@0: #include etisserant@0: etisserant@0: #include "../include/def.h" etisserant@0: #include "../include/can.h" etisserant@0: #include "../include/objdictdef.h" etisserant@0: #include "../include/objacces.h" etisserant@0: #include "../include/canOpenDriver.h" etisserant@0: #include "../include/sdo.h" etisserant@0: #include "../include/pdo.h" etisserant@0: #include "../include/init.h" etisserant@0: #include "../include/timer.h" etisserant@0: #include "../include/lifegrd.h" etisserant@0: #include "../include/sync.h" etisserant@0: etisserant@0: #include "../include/nmtSlave.h" etisserant@0: etisserant@0: etisserant@0: etisserant@0: // HCS12 configuration etisserant@0: // ----------------------------------------------------- etisserant@0: etisserant@0: enum E_CanBaudrate etisserant@0: { etisserant@0: CAN_BAUDRATE_250K, etisserant@0: CAN_BAUDRATE_500K, etisserant@0: CAN_BAUDRATE_1M, etisserant@0: CAN_BAUDRATE_OLD_VALUE etisserant@0: }; etisserant@0: etisserant@0: const canBusTime CAN_Baudrates[] = etisserant@0: { etisserant@0: { etisserant@0: 1, /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board */ etisserant@0: 3, /* brp : chose btw 0 and 63 (6 bits). freq time quantum = 16MHz / (brp + 1) */ etisserant@0: 0, /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum */ etisserant@0: 0, /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit */ etisserant@0: 1, /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1) tq */ etisserant@0: 12, /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1) tq */ etisserant@0: etisserant@0: /* etisserant@0: With these values, etisserant@0: - The width of the bit time is 16 time quantum : etisserant@0: - 1 tq for the SYNC segment (could not be modified) etisserant@0: - 13 tq for the TIME 1 segment (tseg1 = 12) etisserant@0: - 2 tq for the TIME 2 segment (tseg2 = 1) etisserant@0: - Because the bus clock of the MSCAN is 16 MHZ, and the etisserant@0: freq of the time quantum is 4 MHZ (brp = 3+1), and there are 16 tq in the bit time, etisserant@0: so the freq of the bit time is 250 kHz. etisserant@0: */ etisserant@0: }, etisserant@0: etisserant@0: { etisserant@0: 1, /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board */ etisserant@0: 1, /* brp : chose btw 0 and 63 (6 bits). freq time quantum = 16MHz / (brp + 1) */ etisserant@0: 0, /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum */ etisserant@0: 0, /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit */ etisserant@0: 1, /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1) tq */ etisserant@0: 12, /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1) tq */ etisserant@0: etisserant@0: /* etisserant@0: With these values, etisserant@0: - The width of the bit time is 16 time quantum : etisserant@0: - 1 tq for the SYNC segment (could not be modified) etisserant@0: - 13 tq for the TIME 1 segment (tseg1 = 12) etisserant@0: - 2 tq for the TIME 2 segment (tseg2 = 1) etisserant@0: - Because the bus clock of the MSCAN is 16 MHZ, and the etisserant@0: freq of the time quantum is 8 MHZ (brp = 1+1), and there are 16 tq in the bit time, etisserant@0: so the freq of the bit time is 500 kHz. etisserant@0: */ etisserant@0: }, etisserant@0: etisserant@0: { etisserant@0: 1, /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board */ etisserant@0: 1, /* brp : chose btw 0 and 63 (6 bits). freq time quantum = 16MHz / (brp + 1) */ etisserant@0: 0, /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum */ etisserant@0: 0, /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit */ etisserant@0: 1, /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1) tq */ etisserant@0: 4, /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1) tq */ etisserant@0: etisserant@0: /* etisserant@0: With these values, etisserant@0: - The width of the bit time is 16 time quantum : etisserant@0: - 1 tq for the SYNC segment (could not be modified) etisserant@0: - 5 tq for the TIME 1 segment (tseg1 = 4) etisserant@0: - 2 tq for the TIME 2 segment (tseg2 = 1) etisserant@0: - Because the bus clock of the MSCAN is 16 MHZ, and the etisserant@0: freq of the time quantum is 8 MHZ (brp = 1+1), and there are 8 tq in the bit time, etisserant@0: so the freq of the bit time is 1 MHz. etisserant@0: */ etisserant@0: }, etisserant@0: etisserant@0: { etisserant@0: 1, /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board */ etisserant@0: 0, /* brp : chose btw 0 and 63 (6 bits). freq time quantum = 16MHz / (brp + 1) */ etisserant@0: 1, /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum */ etisserant@0: 1, /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit */ etisserant@0: 4, /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1) tq */ etisserant@0: 9, /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1) tq */ etisserant@0: etisserant@0: /* etisserant@0: With these values, etisserant@0: - The width of the bit time is 16 time quantum : etisserant@0: - 1 tq for the SYNC segment (could not be modified) etisserant@0: - 10 tq for the TIME 1 segment (tseg1 = 9) etisserant@0: - 5 tq for the TIME 2 segment (tseg2 = 4) etisserant@0: - Because the bus clock of the MSCAN is 16 MHZ, and the etisserant@0: freq of the time quantum is 16 MHZ (brp = 0), and there are 16 tq in the bit time, etisserant@0: so the freq of the bit time is 1 MHz. etisserant@0: */ etisserant@0: } etisserant@0: }; etisserant@0: etisserant@0: etisserant@0: // The variables sent or updated by PDO etisserant@0: // ----------------------------------------------------- etisserant@0: extern UNS8 seconds; // Mapped at index 0x2000, subindex 0x1 etisserant@0: extern UNS8 minutes; // Mapped at index 0x2000, subindex 0x2 etisserant@0: extern UNS8 hours; // Mapped at index 0x2000, subindex 0x3 etisserant@0: extern UNS8 day; // Mapped at index 0x2000, subindex 0x4 etisserant@0: extern UNS32 canopenErrNB; // Mapped at index 0x6000, subindex 0x0 etisserant@0: extern UNS32 canopenErrVAL; // Mapped at index 0x6001, subindex 0x0 etisserant@0: etisserant@0: // Required definition variables etisserant@0: // ----------------------------- etisserant@0: // The variables that you should define for debugging. etisserant@0: // They are used by the macro MSG_ERR and MSG_WAR in applicfg.h etisserant@0: // if the node is a slave, they can be mapped in the object dictionnary. etisserant@0: // if not null, allow the printing of message to the console etisserant@0: // Could be managed by PDO etisserant@0: UNS8 printMsgErrToConsole = 1; etisserant@0: UNS8 printMsgWarToConsole = 1; etisserant@0: etisserant@0: etisserant@0: etisserant@0: /*************************User's variables declaration**************************/ etisserant@0: UNS8 softCount = 0; etisserant@0: UNS8 lastMinute = 0; etisserant@0: UNS8 lastSecond = 0; etisserant@0: UNS8 sendingError = 0; etisserant@0: //--------------------------------FONCTIONS------------------------------------- etisserant@0: /* You *must* have these 2 functions in your code*/ etisserant@0: void heartbeatError(UNS8 heartbeatID); etisserant@0: void SD0timeoutError(UNS8 bus_id, UNS8 line); etisserant@0: etisserant@0: // Interruption timer 3. (The timer 4 is used by CanOpen) etisserant@0: void __attribute__((interrupt)) timer3Hdl (void); etisserant@0: etisserant@0: void incDate(void); etisserant@0: void initLeds(void); etisserant@0: void initTimerClk(void); etisserant@0: void initCanHCS12 (void); etisserant@0: void initialisation(void); etisserant@0: void preOperational(void); etisserant@0: void operational(void); etisserant@0: void stopped(void); etisserant@0: //------------------------------------------------------------------------------ etisserant@0: etisserant@0: etisserant@0: //------------------------------------------------------------------------------ etisserant@0: // Interruption timer 3 etisserant@0: void __attribute__((interrupt)) timer3Hdl (void) etisserant@0: { etisserant@0: //IO_PORTS_8(PORTB) ^= 0x10; etisserant@0: //IO_PORTS_8(PORTB) &= ~0x20; etisserant@0: IO_PORTS_8(TFLG1) = 0x08; // RAZ du flag interruption timer 3 etisserant@0: // Calcul evt suivant. Clock 8 MHz -> 8000 evt de 1 ms!! Doit tenir sur 16 bits etisserant@0: // Attention, ça change si on utilise la pll etisserant@0: // Lorsque le timer atteindra la valeur de TC3 (16 bits), l'interruption timer3Hdl sera déclenchée etisserant@0: // Si on utilise la PLL à 24 MHZ, alors la vitesse du bus est multipliée par 3. etisserant@0: etisserant@0: /* Assume that our board uses a 16 MHz quartz */ etisserant@0: /* Without pre-division, 8000 counts takes 1 ms. */ etisserant@0: /* We are using a pre-divisor of 32. (register TSCR2) See in CanOpenDriverHC12/timerhw.c */ etisserant@0: /* So 10000 counts takes 40 ms. */ etisserant@0: /* We must have a soft counter of 25 to count a second. */ etisserant@0: etisserant@0: IO_PORTS_16(TC3H) += (10000); // IT every 40000 count. etisserant@0: softCount++; etisserant@0: if (softCount == 25) { etisserant@0: softCount = 0; etisserant@0: incDate(); etisserant@0: } etisserant@0: } etisserant@0: etisserant@0: //------------------------------------------------------------------------------ etisserant@0: void heartbeatError(UNS8 heartbeatID) etisserant@0: { etisserant@0: MSG_ERR(0x1F00, "!!! No heart beat received from node : ", heartbeatID); etisserant@0: } etisserant@0: etisserant@0: //------------------------------------------------------------------------------ etisserant@0: void SD0timeoutError (UNS8 bus_id, UNS8 line) etisserant@0: { etisserant@0: // Informations on what occurs are in transfers[bus_id][line].... etisserant@0: // See scanSDOtimeout() in sdo.c etisserant@0: } etisserant@0: etisserant@0: //------------------------------------------------------------------------------ etisserant@0: // Incrementation of the date, every second etisserant@0: void incDate(void) etisserant@0: { etisserant@0: if (seconds == 59) { etisserant@0: seconds = 0; etisserant@0: if (minutes == 59) { etisserant@0: minutes = 0; etisserant@0: if (hours == 23) { etisserant@0: hours = 0; etisserant@0: day++; etisserant@0: } etisserant@0: else etisserant@0: hours++; etisserant@0: } etisserant@0: else etisserant@0: minutes++; etisserant@0: } etisserant@0: else etisserant@0: seconds++; etisserant@0: etisserant@0: // Toggle the led 4 every seconds etisserant@0: IO_PORTS_8(PORTB) ^= 0x10; etisserant@0: etisserant@0: } etisserant@0: etisserant@0: //Initialisation of the port B for the leds. etisserant@0: void initLeds(void) etisserant@0: { etisserant@0: // Port B is output etisserant@0: IO_PORTS_8(DDRB)= 0XFF; etisserant@0: // RAZ etisserant@0: IO_PORTS_8(PORTB) = 0xFF; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: etisserant@0: //------------------------------------------------------------------------------ etisserant@0: // Init the timer for the clock demo etisserant@0: void initTimerClk(void) etisserant@0: { etisserant@0: etisserant@0: lock(); // Inhibe les interruptions etisserant@0: etisserant@0: // Configuration du Channel 3 etisserant@0: IO_PORTS_8(TIOS) |= 0x08; // Canal 3 en sortie etisserant@0: IO_PORTS_8(TCTL2) &= ~(0xC0); // Canal 3 déconnecté du pin de sortie etisserant@0: IO_PORTS_8(TIE) |= 0x08; // Autorise interruption Canal 3 etisserant@0: IO_PORTS_8(TSCR1) |= 0x80; // Mise en route du timer etisserant@0: unlock(); // Autorise les interruptions etisserant@0: } etisserant@0: etisserant@0: etisserant@0: //------------------------------------------------------------------------------ etisserant@0: etisserant@0: // A placer avant initTimer de la bibliothèque CanOpen etisserant@0: /* void initTimerbis(void) */ etisserant@0: /* { */ etisserant@0: etisserant@0: /* lock(); // Inhibe les interruptions */ etisserant@0: /* // Configuration des IT Channels (0..3) */ etisserant@0: /* IO_PORTS_8(TIOS) &= 0xF0; // Canals 0->3 en entrées. */ etisserant@0: /* IO_PORTS_8(TCTL4) &= 0XFD; // Canal 0 détection sur front montant. */ etisserant@0: /* IO_PORTS_8(TCTL4) |= 0X01; */ etisserant@0: /* IO_PORTS_8(TCTL4) &= 0XF7; // Canal 1 détection sur front montant. */ etisserant@0: /* IO_PORTS_8(TCTL4) |= 0X04; */ etisserant@0: /* IO_PORTS_8(TCTL4) &= 0XDF; // Canal 2 détection sur front montant. */ etisserant@0: /* IO_PORTS_8(TCTL4) |= 0X10; */ etisserant@0: /* IO_PORTS_8(TCTL4) &= 0X7F; // Canal 3 détection sur front montant. */ etisserant@0: /* IO_PORTS_8(TCTL4) |= 0X40; */ etisserant@0: /* IO_PORTS_8(TSCR2) |= 0X05; // Pre-scaler = 32. */ etisserant@0: etisserant@0: /* IO_PORTS_8(ICOVW) |= 0x0F; // La sauvgrade des valeures de TC0 et TC0H */ etisserant@0: /* // correspondant aux canals (0..3) jusqu'a la */ etisserant@0: /* // prochaine lecture dans ces registres. */ etisserant@0: /* MASK = IO_PORTS_8(ICSYS); */ etisserant@0: /* MASK &= 0xFE; // Canals (0..3) en IC QUEUE MODE. */ etisserant@0: /* MASK |= 0x08; // Canals (0..3) : génére une interruption aprés */ etisserant@0: /* // la capture de deux valeures du timer sur detection */ etisserant@0: /* // d'un front montant à l'entrée des canals (0..3). */ etisserant@0: /* MASK |= 0x02; */ etisserant@0: /* IO_PORTS_8(ICSYS) = MASK; */ etisserant@0: /* IO_PORTS_16(TC0HH); // Vider le registre holding correspondant au canal0. */ etisserant@0: /* IO_PORTS_8(TSCR1) |= 0x10; // RAZ automatique des flags d'interruption aprés lecture */ etisserant@0: /* // dans les registres correspondant. */ etisserant@0: etisserant@0: /* IO_PORTS_8(TIE) |= 0x0F; // Autorise interruption Canals (0..3). */ etisserant@0: /* IO_PORTS_8(TSCR2) |= 0X80; // Autorise interruption sur l'Overflow. */ etisserant@0: /* unlock(); // Autorise les interruptions */ etisserant@0: etisserant@0: /* } */ etisserant@0: etisserant@0: //------------------------------------------------------------------------------ etisserant@0: etisserant@0: etisserant@0: etisserant@0: void initCanHCS12 (void) etisserant@0: { etisserant@0: //Init the HCS12 microcontroler for CanOpen etisserant@0: initHCS12(); etisserant@0: // Init the HCS12 CAN driver etisserant@0: const canBusInit bi0 = { etisserant@0: 0, /* no low power */ etisserant@0: 0, /* no time stamp */ etisserant@0: 1, /* enable MSCAN */ etisserant@0: 0, /* clock source : oscillator (In fact, it is not used) */ etisserant@0: 0, /* no loop back */ etisserant@0: 0, /* no listen only */ etisserant@0: 0, /* no low pass filter for wk up */ etisserant@0: CAN_Baudrates[CAN_BAUDRATE_250K], etisserant@0: { etisserant@0: 0x00, /* Filter on 16 bits. See Motorola Block Guide V02.14 fig 4-3 */ etisserant@0: 0x00, 0xFF, /* filter 0 hight accept all msg */ etisserant@0: 0x00, 0xFF, /* filter 0 low accept all msg */ etisserant@0: 0x00, 0xFF, /* filter 1 hight filter all of msg */ etisserant@0: 0x00, 0xFF, /* filter 1 low filter all of msg */ etisserant@0: 0x00, 0xFF, /* filter 2 hight filter most of msg */ etisserant@0: 0x00, 0xFF, /* filter 2 low filter most of msg */ etisserant@0: 0x00, 0xFF, /* filter 3 hight filter most of msg */ etisserant@0: 0x00, 0xFF, /* filter 3 low filter most of msg */ etisserant@0: } etisserant@0: }; etisserant@0: etisserant@0: canInit(CANOPEN_LINE_NUMBER_USED, bi0); //initialize filters... etisserant@0: unlock(); // Allow interruptions etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /*********************************************************************/ etisserant@0: void initialisation( void ) etisserant@0: { etisserant@0: //initcapteur(); //initialisation du capteur, timer, compteurs logiciels etisserant@0: initCanHCS12(); //initialisation du bus Can etisserant@0: MSG_WAR(0X3F05, "I am in INITIALISATION mode ", 0); etisserant@0: /* Defining the node Id */ etisserant@0: setNodeId(0x05); etisserant@0: MSG_WAR(0x3F06, "My node ID is : ", getNodeId()); etisserant@0: { etisserant@0: UNS8 *data; etisserant@0: UNS8 size; etisserant@0: UNS8 dataType; etisserant@0: // Manufacturer Device name (default = empty string) etisserant@0: getODentry(0x1008, 0x0, (void **)&data, &size, &dataType, 0); etisserant@0: MSG_WAR(0x3F09, data, 0); etisserant@0: // Manufacturer Hardware version. (default = compilation. date) etisserant@0: getODentry(0x1009, 0x0, (void **)&data, &size, &dataType, 0); etisserant@0: MSG_WAR(0x3F09, data, 0); etisserant@0: // Manufacturer Software version. (default = compilation. time) etisserant@0: getODentry(0x100A, 0x0, (void **)&data, &size, &dataType, 0); etisserant@0: MSG_WAR(0x3F09, data, 0); etisserant@0: } etisserant@0: initCANopenMain(); //initialisation du canopen etisserant@0: heartbeatInit(); //initialisation du lifeguarding etisserant@0: initResetMode(); etisserant@0: initTimer(); //initialisation of the timer used by Canopen etisserant@0: initTimerClk(); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /*********************************************************************/ etisserant@0: void preOperational(void) etisserant@0: { etisserant@0: // Test if the heartBeat have been received. Send headbeat etisserant@0: heartbeatMGR(); etisserant@0: // Read message etisserant@0: receiveMsgHandler(0); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /********************************************************************/ etisserant@0: void operational( void ) etisserant@0: { etisserant@0: etisserant@0: // Init the errors etisserant@0: canopenErrNB = 0; etisserant@0: canopenErrVAL = 0; etisserant@0: etisserant@0: // Test if the heartBeat have been received. Send headbeat etisserant@0: heartbeatMGR(); etisserant@0: // Read message etisserant@0: receiveMsgHandler(0); etisserant@0: etisserant@0: if (lastMinute != minutes) { etisserant@0: MSG_WAR(0x3F00, "event : minutes change -> node decides to send it. Value : ", minutes); etisserant@0: sendPDOevent( 0, &minutes ); etisserant@0: lastMinute = minutes; etisserant@0: } etisserant@0: etisserant@0: if (canopenErrNB == 0) etisserant@0: sendingError = 0; etisserant@0: etisserant@0: etisserant@0: if (lastSecond != seconds) { etisserant@0: MSG_WAR (0x3F50, "Seconds = ", seconds); etisserant@0: if ((seconds == 50) && (sendingError == 0)) etisserant@0: { etisserant@0: MSG_ERR(0x1F55, "DEMO of ERROR. Sent by PDO. Value : ", 0xABCD); etisserant@0: sendingError = 1; etisserant@0: } etisserant@0: etisserant@0: if (canopenErrNB) { etisserant@0: MSG_WAR(0x3F56, "ERROR nb : ", canopenErrNB); etisserant@0: } etisserant@0: lastSecond = seconds; etisserant@0: etisserant@0: } etisserant@0: etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /*****************************************************************************/ etisserant@0: void stopped( void ) etisserant@0: { etisserant@0: heartbeatMGR(); etisserant@0: // Read message etisserant@0: receiveMsgHandler(0); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /*****************************************************************************/ etisserant@0: etisserant@0: etisserant@0: etisserant@0: /********************************* MAIN ***************************************/ etisserant@0: etisserant@0: etisserant@0: int main () etisserant@0: { etisserant@0: e_nodeState lastState = Unknown_state; etisserant@0: etisserant@0: /* CanOpen slave state machine */ etisserant@0: /* ------------------------------------*/ etisserant@0: etisserant@0: while(1) { /* slave's state machine */ etisserant@0: etisserant@0: switch( getState() ) { etisserant@0: case Initialisation: etisserant@0: if (lastState != getState()) { etisserant@0: initLeds(); etisserant@0: IO_PORTS_8(PORTB) &= ~ 0x01; // led 0 : ON etisserant@0: IO_PORTS_8(PORTB) |= 0x0E; // leds 1, 2, 3 : OFF etisserant@0: MSG_WAR(0X3F10, "Entering in INITIALISATION mode ", 0); etisserant@0: } etisserant@0: initialisation(); etisserant@0: /* change automatically into pre_operational state */ etisserant@0: lastState = Initialisation; etisserant@0: setState(Pre_operational); etisserant@0: break; etisserant@0: etisserant@0: case Pre_operational: etisserant@0: if (lastState != getState()) { etisserant@0: IO_PORTS_8(PORTB) &= ~ 0x03; // leds 0, 1 : ON etisserant@0: IO_PORTS_8(PORTB) |= 0x0C; // leds 2, 3 : OFF etisserant@0: MSG_WAR(0X3F11, "Entering in PRE_OPERATIONAL mode ", 0); etisserant@0: initPreOperationalMode(); etisserant@0: } etisserant@0: preOperational(); etisserant@0: if (lastState == Initialisation) etisserant@0: slaveSendBootUp(0); etisserant@0: lastState = Pre_operational; etisserant@0: break; etisserant@0: etisserant@0: case Operational: etisserant@0: if (lastState != getState()) { etisserant@0: IO_PORTS_8(PORTB) &= ~ 0x07; // leds 0, 1, 2 : ON etisserant@0: IO_PORTS_8(PORTB) |= 0x08; // leds 3 : OFF etisserant@0: MSG_WAR(0X3F12, "Entering in OPERATIONAL mode ", 0); etisserant@0: } etisserant@0: operational(); etisserant@0: lastState = Operational; etisserant@0: break; etisserant@0: etisserant@0: case Stopped: etisserant@0: if (lastState != getState()) { etisserant@0: IO_PORTS_8(PORTB) |= 0x0F; // leds 0, 1, 2, 3 : OFF etisserant@0: MSG_WAR(0X3F13, "Entering in STOPPED mode", 0); etisserant@0: } etisserant@0: stopped(); etisserant@0: lastState = Stopped; etisserant@0: break; etisserant@0: }//end switch case etisserant@0: etisserant@0: } etisserant@0: return (0); etisserant@0: } etisserant@0: