nico@215: nico@215: nico@215: CanFestival: examples/gene_SYNC_HCS12/appli.c Source File nico@215: nico@215: nico@215: nico@215: nico@215:
nico@215:
nico@215:
nico@215:
nico@215: nico@215:

appli.c

Go to the documentation of this file.
00001 /*
nico@215: 00002 This file is part of CanFestival, a library implementing CanOpen Stack. 
nico@215: 00003 
nico@215: 00004 Copyright (C): Edouard TISSERANT and Francis DUPIN
nico@215: 00005 
nico@215: 00006 See COPYING file for copyrights details.
nico@215: 00007 
nico@215: 00008 This library is free software; you can redistribute it and/or
nico@215: 00009 modify it under the terms of the GNU Lesser General Public
nico@215: 00010 License as published by the Free Software Foundation; either
nico@215: 00011 version 2.1 of the License, or (at your option) any later version.
nico@215: 00012 
nico@215: 00013 This library is distributed in the hope that it will be useful,
nico@215: 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
nico@215: 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nico@215: 00016 Lesser General Public License for more details.
nico@215: 00017 
nico@215: 00018 You should have received a copy of the GNU Lesser General Public
nico@215: 00019 License along with this library; if not, write to the Free Software
nico@215: 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
nico@215: 00021 */
nico@215: 00022 
nico@215: 00023 // Uncomment if you don't need console informations.
etisserant@240: 00024 #define DEBUG_WAR_CONSOLE_ON
etisserant@240: 00025 #define DEBUG_ERR_CONSOLE_ON
nico@215: 00026 
nico@215: 00027 #include <stddef.h> /* for NULL */
nico@215: 00028 
nico@215: 00029 #include <asm-m68hc12/portsaccess.h>
nico@215: 00030 #include <asm-m68hc12/ports_def.h>
nico@215: 00031 #include <asm-m68hc12/ports.h>
nico@215: 00032 #include  <interrupt.h>
nico@215: 00033 
nico@215: 00034 #include "../include/data.h"
nico@215: 00035 #include <applicfg.h>
nico@215: 00036 
nico@215: 00037 
nico@215: 00038 
nico@215: 00039 #include "../include/hcs12/candriver.h"
nico@215: 00040 #include "../include/hcs12/canOpenDriver.h"
nico@215: 00041 #include "../include/def.h"
nico@215: 00042 #include "../include/can.h"
nico@215: 00043 #include "../include/objdictdef.h"
nico@215: 00044 #include "../include/objacces.h"
nico@215: 00045 #include "../include/sdo.h"
nico@215: 00046 #include "../include/pdo.h"
nico@215: 00047 #include "../include/timer.h"
nico@215: 00048 #include "../include/lifegrd.h"
nico@215: 00049 #include "../include/sync.h"
nico@215: 00050 
nico@215: 00051 #include "../include/nmtSlave.h"
nico@215: 00052 
nico@215: 00053 // File created by the GUI 
nico@215: 00054 #include "objdict.h"
nico@215: 00055 
nico@215: 00056 
nico@215: 00057 
nico@215: 00058 
nico@215: 00059 
nico@215: 00060 // HCS12 configuration
nico@215: 00061 // -----------------------------------------------------
nico@215: 00062 
etisserant@240: 00063 enum E_CanBaudrate 
nico@215: 00064 {
etisserant@240: 00065    CAN_BAUDRATE_250K,
etisserant@240: 00066    CAN_BAUDRATE_500K,
etisserant@240: 00067    CAN_BAUDRATE_1M,
nico@215: 00068 };
nico@215: 00069 
nico@215: 00070 
etisserant@240: 00071 const canBusTime CAN_Baudrates[] =
nico@215: 00072 {
nico@215: 00073    {
nico@215: 00074       1,  /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board        */
nico@215: 00075       3,  /* brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) */
nico@215: 00076       0,  /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          */
nico@215: 00077       0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
nico@215: 00078       1,  /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       */
nico@215: 00079      12,  /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      */
nico@215: 00080 
nico@215: 00081       /*
nico@215: 00082       With these values, 
nico@215: 00083       - The width of the bit time is 16 time quantum :
nico@215: 00084           - 1 tq for the SYNC segment (could not be modified)
nico@215: 00085           - 13 tq for the TIME 1 segment (tseg1 = 12)
nico@215: 00086           - 2 tq for the TIME 2 segment (tseg2 = 1)
nico@215: 00087       - Because the bus clock of the MSCAN is 16 MHZ, and the 
nico@215: 00088         freq of the time quantum is 4 MHZ (brp = 3+1), and  there are 16 tq in the bit time,
nico@215: 00089         so the freq of the bit time is 250 kHz.
nico@215: 00090       */
nico@215: 00091    },
nico@215: 00092 
nico@215: 00093    {
nico@215: 00094       1,  /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board        */
nico@215: 00095       1,  /* brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) */
nico@215: 00096       0,  /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          */
nico@215: 00097       0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
nico@215: 00098       1,  /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       */
nico@215: 00099      12,  /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      */
nico@215: 00100 
nico@215: 00101       /*
nico@215: 00102       With these values, 
nico@215: 00103       - The width of the bit time is 16 time quantum :
nico@215: 00104           - 1 tq for the SYNC segment (could not be modified)
nico@215: 00105           - 13 tq for the TIME 1 segment (tseg1 = 12)
nico@215: 00106           - 2 tq for the TIME 2 segment (tseg2 = 1)
nico@215: 00107       - Because the bus clock of the MSCAN is 16 MHZ, and the 
nico@215: 00108         freq of the time quantum is 8 MHZ (brp = 1+1), and  there are 16 tq in the bit time,
nico@215: 00109         so the freq of the bit time is 500 kHz.
nico@215: 00110       */
nico@215: 00111     },
nico@215: 00112 
nico@215: 00113         {
nico@215: 00114       1,  /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board        */
nico@215: 00115       1,  /* brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) */
nico@215: 00116       0,  /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          */
nico@215: 00117       0,  /* samp : chose btw 0 and 3 (2 bits) (samp +MSG_WAR(0x3F33, "Je suis le noeud ", getNodeId());    1 ) samples per bit              */
nico@215: 00118       1,  /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       */
nico@215: 00119       4,  /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      */
nico@215: 00120 
nico@215: 00121       /*
nico@215: 00122       With these values, 
nico@215: 00123       - The width of the bit time is 16 time quantum :
nico@215: 00124           - 1 tq for the SYNC segment (could not be modified)
nico@215: 00125           - 5 tq for the TIME 1 segment (tseg1 = 4)
nico@215: 00126           - 2 tq for the TIME 2 segment (tseg2 = 1)
nico@215: 00127       - Because the bus clock of the MSCAN is 16 MHZ, and the 
nico@215: 00128         freq of the time quantum is 8 MHZ (brp = 1+1), and  there are 8 tq in the bit time,
nico@215: 00129         so the freq of the bit time is 1 MHz.
nico@215: 00130       */
nico@215: 00131     }
nico@215: 00132 };
nico@215: 00133 
nico@215: 00134 
nico@215: 00135 
nico@215: 00136 
nico@215: 00137 /**************************prototypes*****************************************/
nico@215: 00138 
nico@215: 00139 //Init can bus and Canopen
etisserant@240: 00140 void initCanopencapteur (void);
nico@215: 00141 // Init the sensor
etisserant@240: 00142 void initSensor(void);
etisserant@240: 00143 void initPortB(void);
etisserant@240: 00144 void initPortH(void);
nico@215: 00145 
nico@215: 00146 
nico@215: 00147 //------------------------------------------------------------------------------
nico@215: 00148 //Initialisation of the port B for the leds.
etisserant@240: 00149 void initPortB(void)
nico@215: 00150 {
nico@215: 00151   // Port B is output
etisserant@240: 00152   IO_PORTS_8(DDRB)= 0XFF;
nico@215: 00153   // RAZ
etisserant@240: 00154   IO_PORTS_8(PORTB) = 0xFF;
nico@215: 00155 }
nico@215: 00156 
nico@215: 00157 //------------------------------------------------------------------------------
nico@215: 00158 // Init of port H to choose the CAN rate by switch, and the nodeId
etisserant@240: 00159 void initPortH(void)
nico@215: 00160 {
nico@215: 00161   // Port H is input
etisserant@240: 00162   IO_PORTS_8(DDRH)= 0X00;
nico@215: 00163   // Enable pull device
etisserant@240: 00164   IO_PORTS_8(PERH) = 0XFF;
nico@215: 00165   // Choose the pull-up device
etisserant@240: 00166   IO_PORTS_8(PPSH) = 0X00;
nico@215: 00167 }
nico@215: 00168 
nico@215: 00169 //------------------------------------------------------------------------------
etisserant@240: 00170 void initSensor(void)
nico@215: 00171 { 
etisserant@240: 00172   UNS8 baudrate = 0; 
etisserant@240: 00173   UNS8 nodeId = 0; 
nico@215: 00174   // Init led control
etisserant@240: 00175   initPortB(); 
etisserant@240: 00176   IO_PORTS_8(PORTB) &= ~ 0x01; //One led ON
etisserant@240: 00177   initPortH();
nico@215: 00178   
nico@215: 00179     /* Defining the node Id */
nico@215: 00180   // Uncomment to have a fixed nodeId
nico@215: 00181   //setNodeId(&gene_SYNC_Data, 0x03);
nico@215: 00182   
nico@215: 00183   // Comment below to have a fixed nodeId
etisserant@240: 00184   nodeId = ~(IO_PORTS_8(PTH)) & 0x3F;
nico@215: 00185   if (nodeId == 0) {
etisserant@240: 00186         MSG_WAR(0x3F33, "Using default nodeId :  ", getNodeId(&gene_SYNC_Data));
nico@215: 00187   }
nico@215: 00188   else  
etisserant@240: 00189     setNodeId(&gene_SYNC_Data, nodeId);
nico@215: 00190   
etisserant@240: 00191   MSG_WAR(0x3F33, "My nodeId is :  ", getNodeId(&gene_SYNC_Data));
nico@215: 00192   
nico@215: 00193   canBusInit bi0 = {
nico@215: 00194     0,    /* no low power                 */ 
nico@215: 00195     0,    /* no time stamp                */
nico@215: 00196     1,    /* enable MSCAN                 */
nico@215: 00197     0,    /* clock source : oscillator (In fact, it is not used)   */
nico@215: 00198     0,    /* no loop back                 */
nico@215: 00199     0,    /* no listen only               */
nico@215: 00200     0,    /* no low pass filter for wk up */
etisserant@240: 00201         CAN_Baudrates[CAN_BAUDRATE_250K],
nico@215: 00202     {
nico@215: 00203       0x00,    /* Filter on 16 bits. See Motorola Block Guide V02.14 fig 4-3 */
nico@215: 00204       0x00, 0xFF, /* filter 0 hight accept all msg      */
nico@215: 00205       0x00, 0xFF, /* filter 0 low accept all msg        */
nico@215: 00206       0x00, 0xFF, /* filter 1 hight filter all of  msg  */
nico@215: 00207       0x00, 0xFF, /* filter 1 low filter all of  msg    */
nico@215: 00208       0x00, 0xFF, /* filter 2 hight filter most of  msg */
nico@215: 00209       0x00, 0xFF, /* filter 2 low filter most of  msg   */
nico@215: 00210       0x00, 0xFF, /* filter 3 hight filter most of  msg */
nico@215: 00211       0x00, 0xFF, /* filter 3 low filter most of  msg   */
nico@215: 00212     }
nico@215: 00213   };
nico@215: 00214   
nico@215: 00215   //Init the HCS12 microcontroler for CanOpen 
etisserant@240: 00216   initHCS12();
nico@215: 00217    
nico@215: 00218   // Chose the CAN rate (On our board, whe have switch for all purpose)
nico@215: 00219   //  7    8
nico@215: 00220   //  ON   ON   => 1000 kpbs
nico@215: 00221   //  OFF  ON   =>  500 kpbs
nico@215: 00222   //  ON   OFF  =>  250 kpbs
nico@215: 00223   
etisserant@240: 00224   baudrate = ~(IO_PORTS_8(PTH)) & 0xC0;
nico@215: 00225   
nico@215: 00226   // Uncomment to have a fixed baudrate of 250 kbps
nico@215: 00227   //baudrate = 1;
nico@215: 00228   
nico@215: 00229   switch (baudrate) {
nico@215: 00230   case 0x40:
etisserant@240: 00231     bi0.clk = CAN_Baudrates[CAN_BAUDRATE_250K];
etisserant@240: 00232     MSG_WAR(0x3F30, "CAN 250 kbps ", 0);
nico@215: 00233     break;
nico@215: 00234   case 0x80:
etisserant@240: 00235     bi0.clk = CAN_Baudrates[CAN_BAUDRATE_500K];
etisserant@240: 00236     MSG_WAR(0x3F31, "CAN 500 kbps ", 0);
nico@215: 00237     break;
nico@215: 00238   case 0xC0:
etisserant@240: 00239     bi0.clk = CAN_Baudrates[CAN_BAUDRATE_1M];
etisserant@240: 00240     MSG_WAR(0x3F31, "CAN 1000 kbps ", 0);
nico@215: 00241     break;   
nico@215: 00242   default:
etisserant@240: 00243     bi0.clk = CAN_Baudrates[CAN_BAUDRATE_250K];
etisserant@240: 00244     MSG_WAR(0x2F32, "CAN BAUD RATE NOT DEFINED => 250 kbps ", 0);
nico@215: 00245   }
nico@215: 00246 
nico@215: 00247    
nico@215: 00248 
etisserant@240: 00249   MSG_WAR(0x3F33, "SYNC signal generator ", 0);
nico@215: 00250 
etisserant@240: 00251   canInit(CANOPEN_LINE_NUMBER_USED, bi0);  //initialize filters...
etisserant@240: 00252   initTimer(); // Init hcs12 timer used by CanFestival. (see timerhw.c)
etisserant@240: 00253   unlock(); // Allow interruptions  
nico@215: 00254 }
nico@215: 00255 
nico@215: 00256 
nico@215: 00257 
nico@215: 00258 
nico@215: 00259 
nico@215: 00260 
nico@215: 00261 //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
nico@215: 00262 // FUNCTIONS WHICH ARE PART OF CANFESTIVAL and *must* be implemented here.
nico@215: 00263 
nico@215: 00264 //------------------------------------------------------------------------------
etisserant@240: 00265 void gene_SYNC_heartbeatError( UNS8 heartbeatID )
nico@215: 00266 {
nico@215: 00267   
etisserant@240: 00268   MSG_ERR(0x1F00, "HeartBeat not received from node : ", heartbeatID);
nico@215: 00269 }
nico@215: 00270 
nico@215: 00271 //------------------------------------------------------------------------------
etisserant@240: 00272 void gene_SYNC_initialisation()
nico@215: 00273 {  
etisserant@240: 00274   MSG_WAR (0x3F00, "Entering in INIT ", 0); 
etisserant@240: 00275   initSensor();  
nico@215: 00276 
etisserant@240: 00277   IO_PORTS_8(PORTB) &= ~ 0x01; // led  0         : ON
etisserant@240: 00278   IO_PORTS_8(PORTB) |=   0x0E; // leds 1, 2, 3   : OFF
nico@215: 00279   
nico@215: 00280 }
nico@215: 00281 
nico@215: 00282 
nico@215: 00283 //------------------------------------------------------------------------------
etisserant@240: 00284 void gene_SYNC_preOperational()
nico@215: 00285 {
etisserant@240: 00286   MSG_WAR (0x3F01, "Entering in PRE-OPERATIONAL ", 0); 
etisserant@240: 00287   IO_PORTS_8(PORTB) &= ~ 0x03; // leds 0, 1      : ON
etisserant@240: 00288   IO_PORTS_8(PORTB) |=   0x0C; // leds 2, 3      : OFF
nico@215: 00289     /* default values for the msg CAN filters */
nico@215: 00290   /* Accept all */
nico@215: 00291     {
nico@215: 00292           canBusFilterInit filterConfiguration = 
nico@215: 00293           {
nico@215: 00294           0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
nico@215: 00295       /*canidarx, canidmrx */                        
nico@215: 00296       0x00, 0xFF,          /* filter 0 */
nico@215: 00297       0x00, 0xFF,                  /* filter 0 */
nico@215: 00298       0x00, 0xFF,          /* filter 1 */
nico@215: 00299       0x00, 0xFF,                  /* filter 1 */
nico@215: 00300       0x00, 0xFF,          /* filter 2 */
nico@215: 00301       0x00, 0xFF,                  /* filter 2 */
nico@215: 00302       0x00, 0xFF,          /* filter 3 */
nico@215: 00303       0x00, 0xFF,              /* filter 3 */
nico@215: 00304          };
etisserant@240: 00305          canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);
nico@215: 00306    } 
nico@215: 00307    // Reset the automatic change by SDO
etisserant@240: 00308    applyDownloadedFilters = 0;
nico@215: 00309    
nico@215: 00310 }
nico@215: 00311 
nico@215: 00312 
nico@215: 00313 //------------------------------------------------------------------------------
etisserant@240: 00314 void gene_SYNC_operational()
nico@215: 00315 { 
etisserant@240: 00316    MSG_WAR (0x3F02, "Entering in OPERATIONAL ", 0); 
etisserant@240: 00317    IO_PORTS_8(PORTB) &= ~ 0x07; // leds 0, 1, 2   : ON
etisserant@240: 00318    IO_PORTS_8(PORTB) |=   0x08; // leds 3         : OFF
nico@215: 00319    
nico@215: 00320    // Filtering the CAN received msgs.
nico@215: 00321    // 2 ways
nico@215: 00322    // First :applying an automatic filter
nico@215: 00323    // Second : The values of the filtering registers are mapped in the object dictionary,
nico@215: 00324    // So that a filtering configuration can be downloaded by SDO in pre-operational mode
nico@215: 00325         
etisserant@240: 00326         if (applyDownloadedFilters == 0) {// No downloaded configuration to apply
etisserant@240: 00327                 UNS16 accept1 = 0x0000; // Accept NMT
etisserant@240: 00328                 UNS16 mask1 = 0x0FFF;   // Mask NMT
etisserant@240: 00329                 UNS16 accept2 = 0xE000; // Accept NMT error control (heartbeat, nodeguard)
etisserant@240: 00330                 UNS16 mask2 = 0x0FFF;   // Mask NMT error control (heartbeat, nodeguard)
nico@215: 00331                 
nico@215: 00332                 canBusFilterInit filterConfiguration = 
nico@215: 00333                                 {// filters 3 and 4 not used, so configured like filter 1.
nico@215: 00334                         0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
nico@215: 00335             /*canidarx, canidmrx */                        
etisserant@240: 00336                 (UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 1 id10...3*/
etisserant@240: 00337                 (UNS8)accept1       , (UNS8)mask1,                     /* filter 1 id2 ... */
etisserant@240: 00338                 (UNS8)(accept2 >> 8), (UNS8)(mask2 >> 8),    /* filter 2 id10...3*/
etisserant@240: 00339                 (UNS8)accept2       , (UNS8)mask2,                     /* filter 2 id2 ... */
etisserant@240: 00340                 (UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 3 id10...3*/
etisserant@240: 00341                 (UNS8)accept1       , (UNS8)mask1,                     /* filter 3 id2 ... */
etisserant@240: 00342                 (UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 4 id10...3*/
etisserant@240: 00343                 (UNS8)accept1       , (UNS8)mask1                      /* filter 4 id2 ... */           
nico@215: 00344                         };
etisserant@240: 00345                         canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);
etisserant@240: 00346                         MSG_WAR (0x3F03, "Internal CAN Rcv filter applied ", 0); 
nico@215: 00347         } 
nico@215: 00348           else { // Apply filters downnloaded
nico@215: 00349                         canBusFilterInit filterConfiguration = 
nico@215: 00350                                 {// filters 3 and 4 not used, so configured like filter 1.
nico@215: 00351                         0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
nico@215: 00352             /*canidarx, canidmrx */                        
etisserant@240: 00353                 (UNS8)( acceptanceFilter1>> 8), (UNS8)(mask1 >> 8),    /* filter 1 id10...3*/
etisserant@240: 00354                 (UNS8)acceptanceFilter1       , (UNS8)mask1,                   /* filter 1 id2 ... */
etisserant@240: 00355                 (UNS8)(acceptanceFilter2 >> 8), (UNS8)(mask2 >> 8),     /* filter 2 id10...3*/
etisserant@240: 00356                 (UNS8)acceptanceFilter2       , (UNS8)mask2,                   /* filter 2 id2 ... */
etisserant@240: 00357                 (UNS8)(acceptanceFilter3 >> 8), (UNS8)(mask3 >> 8),    /* filter 3 id10...3*/
etisserant@240: 00358                 (UNS8)acceptanceFilter3       , (UNS8)mask3,                   /* filter 3 id2 ... */
etisserant@240: 00359                 (UNS8)(acceptanceFilter4 >> 8), (UNS8)(mask4 >> 8),    /* filter 4 id10...3*/
etisserant@240: 00360                 (UNS8)acceptanceFilter4       , (UNS8)mask4                    /* filter 4 id2 ... */           
nico@215: 00361                         };
etisserant@240: 00362                         canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);                 
etisserant@240: 00363                         MSG_WAR (0x3F04, "Downloaded CAN Rcv filter applied ", 0); 
nico@215: 00364         }
nico@215: 00365 }
nico@215: 00366 
nico@215: 00367 //------------------------------------------------------------------------------
etisserant@240: 00368 void gene_SYNC_stopped()
nico@215: 00369 {
etisserant@240: 00370   MSG_WAR (0x3F02, "Entering in STOPPED ", 0); 
etisserant@240: 00371   IO_PORTS_8(PORTB) |=   0x0E; // leds 1, 2, 3, 4   : OFF
nico@215: 00372 }
nico@215: 00373 
nico@215: 00374 // End functions which are part of Canfestival
nico@215: 00375 //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
nico@215: 00376 
nico@215: 00377 
nico@215: 00378 /******************************************************************************/
nico@215: 00379 /********************************* MAIN ***************************************/
nico@215: 00380 /******************************************************************************/
nico@215: 00381 
nico@215: 00382  
etisserant@240: 00383 UNS8 main (void)
nico@215: 00384 {
nico@215: 00385 
etisserant@240: 00386   MSG_WAR(0x3F34, "Entering in the main ", 0);
nico@215: 00387   //----------------------------- INITIALISATION --------------------------------
etisserant@240: 00388   gene_SYNC_Data.heartbeatError = gene_SYNC_heartbeatError;
etisserant@240: 00389   gene_SYNC_Data.initialisation = gene_SYNC_initialisation;
etisserant@240: 00390   gene_SYNC_Data.preOperational = gene_SYNC_preOperational;
etisserant@240: 00391   gene_SYNC_Data.preOperational = gene_SYNC_operational;
etisserant@240: 00392   gene_SYNC_Data.stopped = gene_SYNC_stopped;
nico@215: 00393 
nico@215: 00394   
nico@215: 00395   /* Put the node in Initialisation mode */
etisserant@240: 00396   MSG_WAR(0x3F35, "Will entering in INIT ", 0);
etisserant@240: 00397   setState(&gene_SYNC_Data, Initialisation);
nico@215: 00398 
nico@215: 00399   //----------------------------- START -----------------------------------------
nico@215: 00400   /* Put the node in pre-operational mode */
nico@215: 00401   //MSG_WAR(0x3F36, "va passer en pre-op", 0);
nico@215: 00402   //setState(&gene_SYNC_Data, Pre_operational);
nico@215: 00403 
nico@215: 00404         // Loop of receiving messages
nico@215: 00405   while (1) {
nico@215: 00406         Message m;
etisserant@240: 00407         if (f_can_receive(0, &m)) {
nico@215: 00408           //MSG_WAR(0x3F36, "Msg received", m.cob_id.w);
etisserant@240: 00409           lock(); // Not to have interruptions by timer, which can corrupt the data
etisserant@240: 00410           canDispatch(&gene_SYNC_Data, &m);
etisserant@240: 00411           unlock();
nico@215: 00412         }  
nico@215: 00413         }
nico@215: 00414 
nico@215: 00415   return (0); 
nico@215: 00416 }
nico@215: 00417 
nico@215: 00418 
nico@215: 00419 
etisserant@240: 

Generated on Mon Jul 2 19:10:16 2007 for CanFestival by  nico@215: nico@215: doxygen 1.5.1
nico@215: nico@215: