ethercatmain.h

Go to the documentation of this file.
00001 /*
00002  * Simple Open EtherCAT Master Library 
00003  *
00004  * File    : ethercatmain.h
00005  * Version : 1.2.5
00006  * Date    : 09-04-2011
00007  * Copyright (C) 2005-2011 Speciaal Machinefabriek Ketels v.o.f.
00008  * Copyright (C) 2005-2011 Arthur Ketels
00009  * Copyright (C) 2008-2009 TU/e Technische Universiteit Eindhoven 
00010  *
00011  * SOEM is free software; you can redistribute it and/or modify it under
00012  * the terms of the GNU General Public License version 2 as published by the Free
00013  * Software Foundation.
00014  *
00015  * SOEM is distributed in the hope that it will be useful, but WITHOUT ANY
00016  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00017  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00018  * for more details.
00019  *
00020  * As a special exception, if other files instantiate templates or use macros
00021  * or inline functions from this file, or you compile this file and link it
00022  * with other works to produce a work based on this file, this file does not
00023  * by itself cause the resulting work to be covered by the GNU General Public
00024  * License. However the source code for this file must still be made available
00025  * in accordance with section (3) of the GNU General Public License.
00026  *
00027  * This exception does not invalidate any other reasons why a work based on
00028  * this file might be covered by the GNU General Public License.
00029  *
00030  * The EtherCAT Technology, the trade name and logo “EtherCAT” are the intellectual
00031  * property of, and protected by Beckhoff Automation GmbH. You can use SOEM for
00032  * the sole purpose of creating, using and/or selling or otherwise distributing
00033  * an EtherCAT network master provided that an EtherCAT Master License is obtained
00034  * from Beckhoff Automation GmbH.
00035  *
00036  * In case you did not receive a copy of the EtherCAT Master License along with
00037  * SOEM write to Beckhoff Automation GmbH, Eiserstraße 5, D-33415 Verl, Germany
00038  * (www.beckhoff.com).
00039  */
00040 
00041 /** \file 
00042  * \brief
00043  * Headerfile for ethercatmain.c 
00044  */
00045 
00046 #ifndef _ethercatmain_
00047 #define _ethercatmain_
00048 
00049 #ifndef PACKED
00050 #define PACKED  __attribute__((__packed__))
00051 #endif
00052 
00053 /** max. etries in EtherCAT error list */
00054 #define EC_MAXELIST   64
00055 /** max. length of readable name in slavelist and Object Description List */
00056 #define EC_MAXNAME    36
00057 /** max. number of slaves in array */
00058 #define EC_MAXSLAVE   200
00059 /** max. number of groups */
00060 #define EC_MAXGROUP   8
00061 /** max. number of IO segments per group */
00062 #define EC_MAXIOSEGMENTS 64
00063 /** max. mailbox size */
00064 #define EC_MAXMBX   0x3ff
00065 /** max. eeprom PDO entries */
00066 #define EC_MAXEEPDO   0x200
00067 /** max. SM used */
00068 #define EC_MAXSM    8
00069 /** max. FMMU used */
00070 #define EC_MAXFMMU    4
00071 
00072 /** record for FMMU */
00073 typedef struct PACKED
00074 {
00075   uint32  LogStart;
00076   uint16  LogLength;
00077   uint8   LogStartbit;
00078   uint8   LogEndbit;
00079   uint16  PhysStart;
00080   uint8   PhysStartBit;
00081   uint8   FMMUtype;
00082   uint8   FMMUactive;
00083   uint8   unused1;
00084   uint16  unused2;  
00085 }  ec_fmmut;
00086 
00087 /** record for sync manager */
00088 typedef struct PACKED
00089 {
00090     uint16  StartAddr;
00091     uint16  SMlength;
00092     uint32  SMflags;
00093 } ec_smt;
00094 
00095 typedef struct PACKED
00096 {
00097   uint16  State;
00098   uint16  Unused;
00099   uint16  ALstatuscode;
00100 } ec_state_status;
00101 
00102 #define ECT_MBXPROT_AOE   0x0001
00103 #define ECT_MBXPROT_EOE   0x0002
00104 #define ECT_MBXPROT_COE   0x0004
00105 #define ECT_MBXPROT_FOE   0x0008
00106 #define ECT_MBXPROT_SOE   0x0010
00107 #define ECT_MBXPROT_VOE   0x0020
00108 
00109 #define ECT_COEDET_SDO      0x01
00110 #define ECT_COEDET_SDOINFO    0x02
00111 #define ECT_COEDET_PDOASSIGN  0x04
00112 #define ECT_COEDET_PDOCONFIG  0x08
00113 #define ECT_COEDET_UPLOAD   0x10
00114 #define ECT_COEDET_SDOCA    0x20
00115 
00116 #define EC_SMENABLEMASK   0xfffeffff
00117 
00118 /** for list of ethercat slaves detected */
00119 typedef struct
00120 {
00121     /** state of slave */
00122     uint16        state;
00123   /** AL status code */
00124   uint16        ALstatuscode;
00125   /** Configured address */
00126   uint16        configadr;
00127   /** Alias address */
00128   uint16        aliasadr;
00129     /** Manufacturer from EEprom */
00130     uint32        eep_man;
00131     /** ID from EEprom */
00132     uint32        eep_id;
00133     /** revision from EEprom */
00134     uint32        eep_rev;
00135     /** Interface type */
00136     uint16        Itype;
00137     /** Device type */
00138     uint16        Dtype;
00139     /** output bits */
00140     uint16        Obits;
00141     /** output bytes, if Obits < 8 then Obytes = 0 */
00142     uint32        Obytes;
00143     /** output pointer in IOmap buffer */
00144     uint8       *outputs;
00145     /** startbit in first output byte */
00146     uint8       Ostartbit;
00147     /** input bits */
00148     uint16        Ibits;
00149     /** input bytes, if Ibits < 8 then Ibytes = 0 */
00150     uint32        Ibytes;
00151     /** input pointer in IOmap buffer */
00152     uint8       *inputs;
00153     /** startbit in first input byte */
00154     uint8       Istartbit;
00155   /** SM structure */
00156   ec_smt        SM[EC_MAXSM];
00157   /** SM type 0=unused 1=MbxWr 2=MbxRd 3=Outputs 4=Inputs */
00158   uint8       SMtype[EC_MAXSM];
00159     /** FMMU structure */
00160     ec_fmmut      FMMU[EC_MAXFMMU];
00161     /** FMMU0 function */
00162     uint8       FMMU0func;
00163     /** FMMU1 function */
00164     uint8       FMMU1func;
00165     /** FMMU2 function */
00166     uint8       FMMU2func;
00167     /** FMMU3 function */
00168     uint8       FMMU3func;
00169     /** length of write mailbox in bytes, if no mailbox then 0 */
00170     uint16        mbx_l;
00171     /** mailbox write offset */
00172     uint16        mbx_wo;
00173     /** length of read mailbox in bytes */
00174     uint16        mbx_rl;
00175     /** mailbox read offset */
00176     uint16        mbx_ro;
00177     /** mailbox supported protocols */
00178     uint16        mbx_proto;
00179     /** Counter value of mailbox link layer protocol 1..7 */
00180     uint8       mbx_cnt;
00181     /** has DC capabillity */
00182     boolean       hasdc;
00183     /** Physical type; Ebus, EtherNet combinations */
00184     uint8       ptype;
00185     /** topology: 1 to 3 links */
00186     uint8       topology;
00187   /** active ports bitmap : ....3210 , set if respective port is active **/
00188   uint8       activeports;
00189   /** consumed ports bitmap : ....3210, used for internal delay measurement **/
00190   uint8       consumedports;
00191     /** slave number for parent, 0=master */
00192     uint16        parent;
00193   /** port number on parent this slave is connected to **/
00194   uint8       parentport;
00195   /** port number on this slave the parent is connected to **/
00196   uint8       entryport;
00197     /** DC receivetimes on port A */
00198     int32       DCrtA;
00199     /** DC receivetimes on port B */
00200     int32       DCrtB; 
00201     /** DC receivetimes on port C */
00202     int32       DCrtC;
00203     /** DC receivetimes on port D */
00204     int32       DCrtD;
00205     /** propagation delay */
00206     int32       pdelay;
00207   /** next DC slave */
00208   uint16        DCnext;
00209   /** previous DC slave */
00210   uint16        DCprevious;
00211     /** DC cyle time in ns */
00212     int32       DCcycle;
00213     /** DC shift from clock modulus boundary */
00214     int32       DCshift;
00215     /** DC sync activation, 0=off, 1=on */
00216     uint8       DCactive;
00217     /** link to config table */
00218     uint16        configindex;
00219     /** link to SII config */
00220     uint16        SIIindex;
00221     /** 1 = 8 bytes per read, 0 = 4 bytes per read */
00222     uint8       eep_8byte;
00223   /** 0 = eeprom to master , 1 = eeprom to PDI */
00224   uint8       eep_pdi;
00225     /** CoE details */
00226     uint8       CoEdetails;
00227     /** FoE details */
00228     uint8       FoEdetails;
00229     /** EoE details */
00230     uint8       EoEdetails;
00231     /** SoE details */
00232     uint8       SoEdetails;
00233     /** E-bus current */
00234     int16       Ebuscurrent;
00235   /** if >0 block use of LRW in processdata */
00236   uint8       blockLRW;
00237   /** group */
00238   uint8       group;
00239   /** first unused FMMU */
00240   uint8       FMMUunused;
00241   /** TRUE is slave is not responding at all */
00242   boolean       islost;
00243   /** registered configuration function PO->SO */
00244   int         (*PO2SOconfig)(uint16 slave);
00245     /** readable name */
00246     char        name[EC_MAXNAME + 1];
00247 } ec_slavet;
00248 
00249 /** for list of ethercat slave groups */
00250 typedef struct
00251 {
00252   /** logical start address for this group */
00253   uint32        logstartaddr;
00254     /** output bytes, if Obits < 8 then Obytes = 0 */
00255     uint32        Obytes;
00256     /** output pointer in IOmap buffer */
00257     uint8       *outputs;
00258     /** input bytes, if Ibits < 8 then Ibytes = 0 */
00259     uint32        Ibytes;
00260     /** input pointer in IOmap buffer */
00261     uint8       *inputs;
00262     /** has DC capabillity */
00263     boolean       hasdc;
00264   /** next DC slave */
00265   uint16        DCnext;
00266     /** E-bus current */
00267     int16       Ebuscurrent;
00268   /** if >0 block use of LRW in processdata */
00269   uint8       blockLRW;
00270   /** IO segegments used */
00271   uint16        nsegments;
00272   /** 1st input segment */
00273   uint16        Isegment;
00274   /** Offset in input segment */
00275   uint16        Ioffset;
00276   /** Expected workcounter */
00277   uint16        expectedWKC;
00278   /** check slave states */
00279   boolean       docheckstate;
00280   /** IO segmentation list. Datagrams must not break SM in two. */
00281   uint32        IOsegment[EC_MAXIOSEGMENTS];
00282 } ec_groupt;
00283 
00284 /** SII FMMU structure */
00285 typedef struct
00286 {
00287     uint16 Startpos;
00288     uint8 nFMMU;
00289     uint8 FMMU0;
00290     uint8 FMMU1;
00291     uint8 FMMU2;
00292     uint8 FMMU3;
00293 } ec_eepromFMMUt;
00294 
00295 /** SII SM structure */
00296 typedef struct
00297 {
00298     uint16 Startpos;
00299     uint8 nSM;
00300     uint16 PhStart;
00301     uint16 Plength;
00302     uint8 Creg;
00303     uint8 Sreg;     /* dont care */
00304     uint8 Activate;
00305     uint8 PDIctrl;    /* dont care */
00306 } ec_eepromSMt;
00307 
00308 /** record to store rxPDO and txPDO table from eeprom */
00309 typedef struct 
00310 {
00311     uint16 Startpos;
00312     uint16 Length;
00313     uint16 nPDO;
00314     uint16 Index[EC_MAXEEPDO];
00315     uint16 SyncM[EC_MAXEEPDO];
00316     uint16 BitSize[EC_MAXEEPDO];
00317   uint16 SMbitsize[EC_MAXSM];
00318 } ec_eepromPDOt;
00319 
00320 /** mailbox buffer array */
00321 typedef uint8 ec_mbxbuft[EC_MAXMBX + 1];
00322 
00323 /** standard ethercat mailbox header */
00324 typedef struct PACKED
00325 {
00326     uint16  length;
00327     uint16  address;
00328     uint8   priority;
00329     uint8   mbxtype;
00330 } ec_mbxheadert;
00331 
00332 /** ALstatus and ALstatus code */
00333 typedef struct PACKED
00334 {
00335   uint16  alstatus;
00336   uint16  unused;
00337   uint16  alstatuscode;
00338 } ec_alstatust;
00339 
00340 /** main slave data structure array */
00341 extern ec_slavet  ec_slave[EC_MAXSLAVE];
00342 /** number of slaves found by configuration function */
00343 extern int      ec_slavecount;
00344 /** slave group structure */
00345 extern ec_groupt  ec_group[EC_MAXGROUP];
00346 extern boolean    EcatError;
00347 
00348 extern uint16 ec_DCtO;
00349 extern int64 ec_DCtime;
00350 
00351 void ec_pusherror(const ec_errort *Ec);
00352 boolean ec_poperror(ec_errort *Ec);
00353 boolean ec_iserror(void);
00354 void ec_packeterror(uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode);
00355 int ec_init(const char * ifname);
00356 int ec_init_redundant(const char *ifname, const char *if2name);
00357 void ec_close(void);
00358 uint8 ec_siigetbyte(uint16 slave, uint16 address);
00359 int16 ec_siifind(uint16 slave, uint16 cat);
00360 void ec_siistring(char *str, uint16 slave, uint16 Sn);
00361 uint16 ec_siiFMMU(uint16 slave, ec_eepromFMMUt* FMMU);
00362 uint16 ec_siiSM(uint16 slave, ec_eepromSMt* SM);
00363 uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt* SM, uint16 n);
00364 int ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t);
00365 int ec_readstate(void);
00366 int ec_writestate(uint16 slave);
00367 uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout);
00368 uint8 ec_nextmbxcnt(uint8 cnt);
00369 void ec_clearmbx(ec_mbxbuft *Mbx);
00370 int ec_mbxempty(uint16 slave, int timeout);
00371 int ec_mbxsend(uint16 slave,ec_mbxbuft *mbx, int timeout);
00372 int ec_mbxreceive(uint16 slave, ec_mbxbuft *mbx, int timeout);
00373 void ec_esidump(uint16 slave, uint8 *esibuf, uint8 test);
00374 uint32 ec_readeeprom(uint16 slave, uint16 eeproma, int timeout);
00375 int ec_writeeeprom(uint16 slave, uint16 eeproma, uint16 data, int timeout);
00376 int ec_eeprom2master(uint16 slave);
00377 int ec_eeprom2pdi(uint16 slave);
00378 uint64 ec_readeepromAP(uint16 aiadr, uint16 eeproma, int timeout);
00379 int ec_writeeepromAP(uint16 aiadr, uint16 eeproma, uint16 data, int timeout);
00380 uint64 ec_readeepromFP(uint16 configadr, uint16 eeproma, int timeout);
00381 int ec_writeeepromFP(uint16 configadr, uint16 eeproma, uint16 data, int timeout);
00382 void ec_readeeprom1(uint16 slave, uint16 eeproma);
00383 uint32 ec_readeeprom2(uint16 slave, int timeout);
00384 int ec_send_processdata_group(uint8 group);
00385 int ec_receive_processdata_group(uint8 group, int timeout);
00386 int ec_send_processdata(void);
00387 int ec_receive_processdata(int timeout);
00388 
00389 #endif
Generated by  doxygen 1.6.3