AB&T / SOEM

Dependents:   EasyCAT_LAB_simple EasyCAT_LAB_very_simple EasyCAT_LAB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ethercatmain.h Source File

ethercatmain.h

Go to the documentation of this file.
00001 /*
00002  * Licensed under the GNU General Public License version 2 with exceptions. See
00003  * LICENSE file in the project root for full license information
00004  */
00005 
00006 /** \file
00007  * \brief
00008  * Headerfile for ethercatmain.c
00009  */
00010 
00011 #ifndef _ethercatmain_
00012 #define _ethercatmain_
00013 
00014 
00015 #ifdef __cplusplus
00016 extern "C"
00017 {
00018 #endif
00019 
00020 /** max. entries in EtherCAT error list */
00021 #define EC_MAXELIST       64
00022 /** max. length of readable name in slavelist and Object Description List */
00023 #define EC_MAXNAME        40
00024 /** max. number of slaves in array */
00025 #define EC_MAXSLAVE       200
00026 /** max. number of groups */
00027 #define EC_MAXGROUP       2
00028 /** max. number of IO segments per group */
00029 #define EC_MAXIOSEGMENTS  64
00030 /** max. mailbox size */
00031 #define EC_MAXMBX         1486
00032 /** max. eeprom PDO entries */
00033 #define EC_MAXEEPDO       0x200
00034 /** max. SM used */
00035 #define EC_MAXSM          8
00036 /** max. FMMU used */
00037 #define EC_MAXFMMU        4
00038 /** max. Adapter */
00039 #define EC_MAXLEN_ADAPTERNAME    128
00040 /** define maximum number of concurrent threads in mapping */
00041 #define EC_MAX_MAPT           1
00042 
00043 typedef struct ec_adapter ec_adaptert;
00044 struct ec_adapter
00045 {
00046    char   name[EC_MAXLEN_ADAPTERNAME];
00047    char   desc[EC_MAXLEN_ADAPTERNAME];
00048    ec_adaptert *next;
00049 };
00050 
00051 /** record for FMMU */
00052 PACKED_BEGIN
00053 typedef struct PACKED ec_fmmu
00054 {
00055    uint32  LogStart;
00056    uint16  LogLength;
00057    uint8   LogStartbit;
00058    uint8   LogEndbit;
00059    uint16  PhysStart;
00060    uint8   PhysStartBit;
00061    uint8   FMMUtype;
00062    uint8   FMMUactive;
00063    uint8   unused1;
00064    uint16  unused2;
00065 }  ec_fmmut;
00066 PACKED_END
00067 
00068 /** record for sync manager */
00069 PACKED_BEGIN
00070 typedef struct PACKED ec_sm
00071 {
00072    uint16  StartAddr;
00073    uint16  SMlength;
00074    uint32  SMflags;
00075 } ec_smt;
00076 PACKED_END
00077 
00078 PACKED_BEGIN
00079 typedef struct PACKED ec_state_status
00080 {
00081    uint16  State;
00082    uint16  Unused;
00083    uint16  ALstatuscode;
00084 } ec_state_status;
00085 PACKED_END
00086 
00087 #define ECT_MBXPROT_AOE      0x0001
00088 #define ECT_MBXPROT_EOE      0x0002
00089 #define ECT_MBXPROT_COE      0x0004
00090 #define ECT_MBXPROT_FOE      0x0008
00091 #define ECT_MBXPROT_SOE      0x0010
00092 #define ECT_MBXPROT_VOE      0x0020
00093 
00094 #define ECT_COEDET_SDO       0x01
00095 #define ECT_COEDET_SDOINFO   0x02
00096 #define ECT_COEDET_PDOASSIGN 0x04
00097 #define ECT_COEDET_PDOCONFIG 0x08
00098 #define ECT_COEDET_UPLOAD    0x10
00099 #define ECT_COEDET_SDOCA     0x20
00100 
00101 #define EC_SMENABLEMASK      0xfffeffff
00102 
00103 /** for list of ethercat slaves detected */
00104 typedef struct ec_slave
00105 {
00106    /** state of slave */
00107    uint16           state;
00108    /** AL status code */
00109    uint16           ALstatuscode;
00110    /** Configured address */
00111    uint16           configadr;
00112    /** Alias address */
00113    uint16           aliasadr;
00114    /** Manufacturer from EEprom */
00115    uint32           eep_man;
00116    /** ID from EEprom */
00117    uint32           eep_id;
00118    /** revision from EEprom */
00119    uint32           eep_rev;
00120    /** Interface type */
00121    uint16           Itype;
00122    /** Device type */
00123    uint16           Dtype;
00124    /** output bits */
00125    uint16           Obits;
00126    /** output bytes, if Obits < 8 then Obytes = 0 */
00127    uint32           Obytes;
00128    /** output pointer in IOmap buffer */
00129    uint8            *outputs;
00130    /** startbit in first output byte */
00131    uint8            Ostartbit;
00132    /** input bits */
00133    uint16           Ibits;
00134    /** input bytes, if Ibits < 8 then Ibytes = 0 */
00135    uint32           Ibytes;
00136    /** input pointer in IOmap buffer */
00137    uint8            *inputs;
00138    /** startbit in first input byte */
00139    uint8            Istartbit;
00140    /** SM structure */
00141    ec_smt           SM[EC_MAXSM];
00142    /** SM type 0=unused 1=MbxWr 2=MbxRd 3=Outputs 4=Inputs */
00143    uint8            SMtype[EC_MAXSM];
00144    /** FMMU structure */
00145    ec_fmmut         FMMU[EC_MAXFMMU];
00146    /** FMMU0 function */
00147    uint8            FMMU0func;
00148    /** FMMU1 function */
00149    uint8            FMMU1func;
00150    /** FMMU2 function */
00151    uint8            FMMU2func;
00152    /** FMMU3 function */
00153    uint8            FMMU3func;
00154    /** length of write mailbox in bytes, if no mailbox then 0 */
00155    uint16           mbx_l;
00156    /** mailbox write offset */
00157    uint16           mbx_wo;
00158    /** length of read mailbox in bytes */
00159    uint16           mbx_rl;
00160    /** mailbox read offset */
00161    uint16           mbx_ro;
00162    /** mailbox supported protocols */
00163    uint16           mbx_proto;
00164    /** Counter value of mailbox link layer protocol 1..7 */
00165    uint8            mbx_cnt;
00166    /** has DC capability */
00167    boolean          hasdc;
00168    /** Physical type; Ebus, EtherNet combinations */
00169    uint8            ptype;
00170    /** topology: 1 to 3 links */
00171    uint8            topology;
00172    /** active ports bitmap : ....3210 , set if respective port is active **/
00173    uint8            activeports;
00174    /** consumed ports bitmap : ....3210, used for internal delay measurement **/
00175    uint8            consumedports;
00176    /** slave number for parent, 0=master */
00177    uint16           parent;
00178    /** port number on parent this slave is connected to **/
00179    uint8            parentport;
00180    /** port number on this slave the parent is connected to **/
00181    uint8            entryport;
00182    /** DC receivetimes on port A */
00183    int32            DCrtA;
00184    /** DC receivetimes on port B */
00185    int32            DCrtB;
00186    /** DC receivetimes on port C */
00187    int32            DCrtC;
00188    /** DC receivetimes on port D */
00189    int32            DCrtD;
00190    /** propagation delay */
00191    int32            pdelay;
00192    /** next DC slave */
00193    uint16           DCnext;
00194    /** previous DC slave */
00195    uint16           DCprevious;
00196    /** DC cycle time in ns */
00197    int32            DCcycle;
00198    /** DC shift from clock modulus boundary */
00199    int32            DCshift;
00200    /** DC sync activation, 0=off, 1=on */
00201    uint8            DCactive;
00202    /** link to config table */
00203    uint16           configindex;
00204    /** link to SII config */
00205    uint16           SIIindex;
00206    /** 1 = 8 bytes per read, 0 = 4 bytes per read */
00207    uint8            eep_8byte;
00208    /** 0 = eeprom to master , 1 = eeprom to PDI */
00209    uint8            eep_pdi;
00210    /** CoE details */
00211    uint8            CoEdetails;
00212    /** FoE details */
00213    uint8            FoEdetails;
00214    /** EoE details */
00215    uint8            EoEdetails;
00216    /** SoE details */
00217    uint8            SoEdetails;
00218    /** E-bus current */
00219    int16            Ebuscurrent;
00220    /** if >0 block use of LRW in processdata */
00221    uint8            blockLRW;
00222    /** group */
00223    uint8            group;
00224    /** first unused FMMU */
00225    uint8            FMMUunused;
00226    /** Boolean for tracking whether the slave is (not) responding, not used/set by the SOEM library */
00227    boolean          islost;
00228    /** registered configuration function PO->SO */
00229    int              (*PO2SOconfig)(uint16 slave);
00230    /** readable name */
00231    char             name[EC_MAXNAME + 1];
00232 } ec_slavet;
00233 
00234 /** for list of ethercat slave groups */
00235 typedef struct ec_group
00236 {
00237    /** logical start address for this group */
00238    uint32           logstartaddr;
00239    /** output bytes, if Obits < 8 then Obytes = 0 */
00240    uint32           Obytes;
00241    /** output pointer in IOmap buffer */
00242    uint8            *outputs;
00243    /** input bytes, if Ibits < 8 then Ibytes = 0 */
00244    uint32           Ibytes;
00245    /** input pointer in IOmap buffer */
00246    uint8            *inputs;
00247    /** has DC capabillity */
00248    boolean          hasdc;
00249    /** next DC slave */
00250    uint16           DCnext;
00251    /** E-bus current */
00252    int16            Ebuscurrent;
00253    /** if >0 block use of LRW in processdata */
00254    uint8            blockLRW;
00255    /** IO segments used */
00256    uint16           nsegments;
00257    /** 1st input segment */
00258    uint16           Isegment;
00259    /** Offset in input segment */
00260    uint16           Ioffset;
00261    /** Expected workcounter outputs */
00262    uint16           outputsWKC;
00263    /** Expected workcounter inputs */
00264    uint16           inputsWKC;
00265    /** check slave states */
00266    boolean          docheckstate;
00267    /** IO segmentation list. Datagrams must not break SM in two. */
00268    uint32           IOsegment[EC_MAXIOSEGMENTS];
00269 } ec_groupt;
00270 
00271 /** SII FMMU structure */
00272 typedef struct ec_eepromFMMU
00273 {
00274    uint16  Startpos;
00275    uint8   nFMMU;
00276    uint8   FMMU0;
00277    uint8   FMMU1;
00278    uint8   FMMU2;
00279    uint8   FMMU3;
00280 } ec_eepromFMMUt;
00281 
00282 /** SII SM structure */
00283 typedef struct ec_eepromSM
00284 {
00285    uint16  Startpos;
00286    uint8   nSM;
00287    uint16  PhStart;
00288    uint16  Plength;
00289    uint8   Creg;
00290    uint8   Sreg;       /* don't care */
00291    uint8   Activate;
00292    uint8   PDIctrl;      /* don't care */
00293 } ec_eepromSMt;
00294 
00295 /** record to store rxPDO and txPDO table from eeprom */
00296 typedef struct ec_eepromPDO
00297 {
00298    uint16  Startpos;
00299    uint16  Length;
00300    uint16  nPDO;
00301    uint16  Index[EC_MAXEEPDO];
00302    uint16  SyncM[EC_MAXEEPDO];
00303    uint16  BitSize[EC_MAXEEPDO];
00304    uint16  SMbitsize[EC_MAXSM];
00305 } ec_eepromPDOt;
00306 
00307 /** mailbox buffer array */
00308 typedef uint8 ec_mbxbuft[EC_MAXMBX + 1];
00309 
00310 /** standard ethercat mailbox header */
00311 PACKED_BEGIN
00312 typedef struct PACKED ec_mbxheader
00313 {
00314    uint16  length;
00315    uint16  address;
00316    uint8   priority;
00317    uint8   mbxtype;
00318 } ec_mbxheadert;
00319 PACKED_END
00320 
00321 /** ALstatus and ALstatus code */
00322 PACKED_BEGIN
00323 typedef struct PACKED ec_alstatus
00324 {
00325    uint16  alstatus;
00326    uint16  unused;
00327    uint16  alstatuscode;
00328 } ec_alstatust;
00329 PACKED_END
00330 
00331 /** stack structure to store segmented LRD/LWR/LRW constructs */
00332 typedef struct ec_idxstack
00333 {
00334    uint8   pushed;
00335    uint8   pulled;
00336    uint8   idx[EC_MAXBUF];
00337    void    *data[EC_MAXBUF];
00338    uint16  length[EC_MAXBUF];
00339 } ec_idxstackT;
00340 
00341 /** ringbuf for error storage */
00342 typedef struct ec_ering
00343 {
00344    int16     head;
00345    int16     tail;
00346    ec_errort Error[EC_MAXELIST + 1];
00347 } ec_eringt;
00348 
00349 /** SyncManager Communication Type structure for CA */
00350 PACKED_BEGIN
00351 typedef struct PACKED ec_SMcommtype
00352 {
00353    uint8   n;
00354    uint8   nu1;
00355    uint8   SMtype[EC_MAXSM];
00356 } ec_SMcommtypet;
00357 PACKED_END
00358 
00359 /** SDO assign structure for CA */
00360 PACKED_BEGIN
00361 typedef struct PACKED ec_PDOassign
00362 {
00363    uint8   n;
00364    uint8   nu1;
00365    uint16  index[256];
00366 } ec_PDOassignt;
00367 PACKED_END
00368 
00369 /** SDO description structure for CA */
00370 PACKED_BEGIN
00371 typedef struct PACKED ec_PDOdesc
00372 {
00373    uint8   n;
00374    uint8   nu1;
00375    uint32  PDO[256];
00376 } ec_PDOdesct;
00377 PACKED_END
00378 
00379 /** Context structure , referenced by all ecx functions*/
00380 typedef struct ecx_context ecx_contextt;
00381 struct ecx_context
00382 {
00383    /** port reference, may include red_port */
00384    ecx_portt      *port;
00385    /** slavelist reference */
00386    ec_slavet      *slavelist;
00387    /** number of slaves found in configuration */
00388    int            *slavecount;
00389    /** maximum number of slaves allowed in slavelist */
00390    int            maxslave;
00391    /** grouplist reference */
00392    ec_groupt      *grouplist;
00393    /** maximum number of groups allowed in grouplist */
00394    int            maxgroup;
00395    /** internal, reference to eeprom cache buffer */
00396    uint8          *esibuf;
00397    /** internal, reference to eeprom cache map */
00398    uint32         *esimap;
00399    /** internal, current slave for eeprom cache */
00400    uint16         esislave;
00401    /** internal, reference to error list */
00402    ec_eringt      *elist;
00403    /** internal, reference to processdata stack buffer info */
00404    ec_idxstackT   *idxstack;
00405    /** reference to ecaterror state */
00406    boolean        *ecaterror;
00407    /** internal, position of DC datagram in process data packet */
00408    uint16         DCtO;
00409    /** internal, length of DC datagram */
00410    uint16         DCl;
00411    /** reference to last DC time from slaves */
00412    int64          *DCtime;
00413    /** internal, SM buffer */
00414    ec_SMcommtypet *SMcommtype;
00415    /** internal, PDO assign list */
00416    ec_PDOassignt  *PDOassign;
00417    /** internal, PDO description list */
00418    ec_PDOdesct    *PDOdesc;
00419    /** internal, SM list from eeprom */
00420    ec_eepromSMt   *eepSM;
00421    /** internal, FMMU list from eeprom */
00422    ec_eepromFMMUt *eepFMMU;
00423    /** registered FoE hook */
00424    int            (*FOEhook)(uint16 slave, int packetnumber, int datasize);
00425    /** registered EoE hook */
00426    int            (*EOEhook)(ecx_contextt * context, uint16 slave, void * eoembx);
00427 };
00428 
00429 #ifdef EC_VER1
00430 /** global struct to hold default master context */
00431 extern ecx_contextt  ecx_context;
00432 /** main slave data structure array */
00433 extern ec_slavet   ec_slave[EC_MAXSLAVE];
00434 /** number of slaves found by configuration function */
00435 extern int         ec_slavecount;
00436 /** slave group structure */
00437 extern ec_groupt   ec_group[EC_MAXGROUP];
00438 extern boolean     EcatError;
00439 extern int64       ec_DCtime;
00440 
00441 void ec_pusherror(const ec_errort *Ec);
00442 boolean ec_poperror(ec_errort *Ec);
00443 boolean ec_iserror(void);
00444 void ec_packeterror(uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode);
00445 int ec_init(const char * ifname);
00446 int ec_init_redundant(const char *ifname, char *if2name);
00447 void ec_close(void);
00448 uint8 ec_siigetbyte(uint16 slave, uint16 address);
00449 int16 ec_siifind(uint16 slave, uint16 cat);
00450 void ec_siistring(char *str, uint16 slave, uint16 Sn);
00451 uint16 ec_siiFMMU(uint16 slave, ec_eepromFMMUt* FMMU);
00452 uint16 ec_siiSM(uint16 slave, ec_eepromSMt* SM);
00453 uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt* SM, uint16 n);
00454 int ec_siiPDO(uint16 slave, ec_eepromPDOt* PDO, uint8 t);
00455 int ec_readstate(void);
00456 int ec_writestate(uint16 slave);
00457 uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout);
00458 int ec_mbxempty(uint16 slave, int timeout);
00459 int ec_mbxsend(uint16 slave,ec_mbxbuft *mbx, int timeout);
00460 int ec_mbxreceive(uint16 slave, ec_mbxbuft *mbx, int timeout);
00461 void ec_esidump(uint16 slave, uint8 *esibuf);
00462 uint32 ec_readeeprom(uint16 slave, uint16 eeproma, int timeout);
00463 int ec_writeeeprom(uint16 slave, uint16 eeproma, uint16 data, int timeout);
00464 int ec_eeprom2master(uint16 slave);
00465 int ec_eeprom2pdi(uint16 slave);
00466 uint64 ec_readeepromAP(uint16 aiadr, uint16 eeproma, int timeout);
00467 int ec_writeeepromAP(uint16 aiadr, uint16 eeproma, uint16 data, int timeout);
00468 uint64 ec_readeepromFP(uint16 configadr, uint16 eeproma, int timeout);
00469 int ec_writeeepromFP(uint16 configadr, uint16 eeproma, uint16 data, int timeout);
00470 void ec_readeeprom1(uint16 slave, uint16 eeproma);
00471 uint32 ec_readeeprom2(uint16 slave, int timeout);
00472 int ec_send_processdata_group(uint8 group);
00473 int ec_send_overlap_processdata_group(uint8 group);
00474 int ec_receive_processdata_group(uint8 group, int timeout);
00475 int ec_send_processdata(void);
00476 int ec_send_overlap_processdata(void);
00477 int ec_receive_processdata(int timeout);
00478 #endif
00479 
00480 ec_adaptert * ec_find_adapters(void);
00481 void ec_free_adapters(ec_adaptert * adapter);
00482 uint8 ec_nextmbxcnt(uint8 cnt);
00483 void ec_clearmbx(ec_mbxbuft *Mbx);
00484 void ecx_pusherror(ecx_contextt *context, const ec_errort *Ec);
00485 boolean ecx_poperror(ecx_contextt *context, ec_errort *Ec);
00486 boolean ecx_iserror(ecx_contextt *context);
00487 void ecx_packeterror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode);
00488 int ecx_init(ecx_contextt *context, const char * ifname);
00489 int ecx_init_redundant(ecx_contextt *context, ecx_redportt *redport, const char *ifname, char *if2name);
00490 void ecx_close(ecx_contextt *context);
00491 uint8 ecx_siigetbyte(ecx_contextt *context, uint16 slave, uint16 address);
00492 int16 ecx_siifind(ecx_contextt *context, uint16 slave, uint16 cat);
00493 void ecx_siistring(ecx_contextt *context, char *str, uint16 slave, uint16 Sn);
00494 uint16 ecx_siiFMMU(ecx_contextt *context, uint16 slave, ec_eepromFMMUt* FMMU);
00495 uint16 ecx_siiSM(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM);
00496 uint16 ecx_siiSMnext(ecx_contextt *context, uint16 slave, ec_eepromSMt* SM, uint16 n);
00497 int ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt* PDO, uint8 t);
00498 int ecx_readstate(ecx_contextt *context);
00499 int ecx_writestate(ecx_contextt *context, uint16 slave);
00500 uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout);
00501 int ecx_mbxempty(ecx_contextt *context, uint16 slave, int timeout);
00502 int ecx_mbxsend(ecx_contextt *context, uint16 slave,ec_mbxbuft *mbx, int timeout);
00503 int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout);
00504 void ecx_esidump(ecx_contextt *context, uint16 slave, uint8 *esibuf);
00505 uint32 ecx_readeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, int timeout);
00506 int ecx_writeeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, uint16 data, int timeout);
00507 int ecx_eeprom2master(ecx_contextt *context, uint16 slave);
00508 int ecx_eeprom2pdi(ecx_contextt *context, uint16 slave);
00509 uint64 ecx_readeepromAP(ecx_contextt *context, uint16 aiadr, uint16 eeproma, int timeout);
00510 int ecx_writeeepromAP(ecx_contextt *context, uint16 aiadr, uint16 eeproma, uint16 data, int timeout);
00511 uint64 ecx_readeepromFP(ecx_contextt *context, uint16 configadr, uint16 eeproma, int timeout);
00512 int ecx_writeeepromFP(ecx_contextt *context, uint16 configadr, uint16 eeproma, uint16 data, int timeout);
00513 void ecx_readeeprom1(ecx_contextt *context, uint16 slave, uint16 eeproma);
00514 uint32 ecx_readeeprom2(ecx_contextt *context, uint16 slave, int timeout);
00515 int ecx_send_overlap_processdata_group(ecx_contextt *context, uint8 group);
00516 int ecx_receive_processdata_group(ecx_contextt *context, uint8 group, int timeout);
00517 int ecx_send_processdata(ecx_contextt *context);
00518 int ecx_send_overlap_processdata(ecx_contextt *context);
00519 int ecx_receive_processdata(ecx_contextt *context, int timeout);
00520 int ecx_send_processdata_group(ecx_contextt *context, uint8 group);
00521 
00522 #ifdef __cplusplus
00523 }
00524 #endif
00525 
00526 #endif