ethercattype.h
Go to the documentation of this file.
00001 /*
00002  * Simple Open EtherCAT Master Library 
00003  *
00004  * File    : ethercattype.h
00005  * Version : 1.3.0
00006  * Date    : 24-02-2013
00007  * Copyright (C) 2005-2013 Speciaal Machinefabriek Ketels v.o.f.
00008  * Copyright (C) 2005-2013 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 
00053 #ifndef _EC_TYPE_H
00054 #define _EC_TYPE_H
00055 
00056 #ifdef __cplusplus
00057 extern "C"
00058 {
00059 #endif
00060 
00062 #define EC_LITTLE_ENDIAN
00063 
00066 #define EC_VER1
00067 
00068 #include "osal.h"
00069 
00071 #define EC_ERROR           -3
00072 
00073 #define EC_NOFRAME         -1
00074 
00075 #define EC_OTHERFRAME      -2
00076 
00077 #define EC_MAXECATFRAME    1518
00078 
00079 /* MTU - Ethernet header - length - datagram header - WCK - FCS */
00080 #define EC_MAXLRWDATA      (EC_MAXECATFRAME - 14 - 2 - 10 - 2 - 4)
00081 
00082 #define EC_FIRSTDCDATAGRAM 20
00083 
00084 #define EC_BUFSIZE         EC_MAXECATFRAME
00085 
00086 #define EC_ECATTYPE        0x1000
00087 
00088 #define EC_MAXBUF          16
00089 
00090 #define EC_TIMEOUTRET      2000
00091 
00092 #define EC_TIMEOUTRET3     (EC_TIMEOUTRET * 3)
00093 
00094 #define EC_TIMEOUTSAFE     20000
00095 
00096 #define EC_TIMEOUTEEP      20000
00097 
00098 #define EC_TIMEOUTTXM      20000
00099 
00100 #define EC_TIMEOUTRXM      700000
00101 
00102 #define EC_TIMEOUTSTATE    2000000
00103 
00104 #define EC_MAXEEPBITMAP    128
00105 
00106 #define EC_MAXEEPBUF       EC_MAXEEPBITMAP << 5
00107 
00108 #define EC_DEFAULTRETRIES  3
00109 
00111 typedef uint8 ec_bufT[EC_BUFSIZE];
00112 
00114 PACKED_BEGIN
00115 typedef struct PACKED
00116 {
00118    uint16  da0,da1,da2;
00120    uint16  sa0,sa1,sa2;
00122    uint16  etype;
00123 } ec_etherheadert;
00124 PACKED_END
00125 
00127 #define ETH_HEADERSIZE      sizeof(ec_etherheadert)
00128 
00130 PACKED_BEGIN
00131 typedef struct PACKED
00132 {
00134    uint16  elength;
00136    uint8   command;
00138    uint8   index;
00140    uint16  ADP;
00142    uint16  ADO;
00144    uint16  dlength;
00146    uint16  irpt;
00147 } ec_comt;
00148 PACKED_END
00149 
00151 #define EC_HEADERSIZE       sizeof(ec_comt)
00152 
00153 #define EC_ELENGTHSIZE      sizeof(uint16)
00154 
00155 #define EC_CMDOFFSET        EC_ELENGTHSIZE
00156 
00157 #define EC_WKCSIZE          sizeof(uint16)
00158 
00159 #define EC_DATAGRAMFOLLOWS  (1 << 15)
00160 
00162 typedef enum
00163 {
00165    EC_ERR_OK         = 0,
00167    EC_ERR_ALREADY_INITIALIZED,
00169    EC_ERR_NOT_INITIALIZED,
00171    EC_ERR_TIMEOUT,
00173    EC_ERR_NO_SLAVES,
00175    EC_ERR_NOK
00176 } ec_err;
00177 
00179 typedef enum
00180 {
00182    EC_STATE_INIT           = 0x01,
00184    EC_STATE_PRE_OP         = 0x02,
00186    EC_STATE_BOOT            = 0x03,
00188    EC_STATE_SAFE_OP        = 0x04,
00190    EC_STATE_OPERATIONAL    = 0x08,
00192    EC_STATE_ACK            = 0x10,
00193    EC_STATE_ERROR          = 0x10
00194 } ec_state;
00195 
00197 typedef enum
00198 {
00200    EC_BUF_EMPTY        = 0x00,
00202    EC_BUF_ALLOC        = 0x01,
00204    EC_BUF_TX           = 0x02,
00206    EC_BUF_RCVD         = 0x03,
00208    EC_BUF_COMPLETE     = 0x04
00209 } ec_bufstate;
00210 
00212 typedef enum
00213 {
00214    ECT_BOOLEAN         = 0x0001,
00215    ECT_INTEGER8        = 0x0002,
00216    ECT_INTEGER16       = 0x0003,
00217    ECT_INTEGER32       = 0x0004,
00218    ECT_UNSIGNED8       = 0x0005,
00219    ECT_UNSIGNED16      = 0x0006,
00220    ECT_UNSIGNED32      = 0x0007,
00221    ECT_REAL32          = 0x0008,
00222    ECT_VISIBLE_STRING  = 0x0009,
00223    ECT_OCTET_STRING    = 0x000A,
00224    ECT_UNICODE_STRING  = 0x000B,
00225    ECT_TIME_OF_DAY     = 0x000C,
00226    ECT_TIME_DIFFERENCE = 0x000D,
00227    ECT_DOMAIN          = 0x000F,
00228    ECT_INTEGER24       = 0x0010,
00229    ECT_REAL64          = 0x0011,
00230    ECT_INTEGER64       = 0x0015,
00231    ECT_UNSIGNED24      = 0x0016,
00232    ECT_UNSIGNED64      = 0x001B,
00233    ECT_BIT1            = 0x0030,
00234    ECT_BIT2            = 0x0031,
00235    ECT_BIT3            = 0x0032,
00236    ECT_BIT4            = 0x0033,
00237    ECT_BIT5            = 0x0034,
00238    ECT_BIT6            = 0x0035,
00239    ECT_BIT7            = 0x0036,
00240    ECT_BIT8            = 0x0037
00241 } ec_datatype;
00242 
00244 typedef enum 
00245 {
00247    EC_CMD_NOP          = 0x00,
00249    EC_CMD_APRD,
00251    EC_CMD_APWR,
00253    EC_CMD_APRW,
00255    EC_CMD_FPRD,
00257    EC_CMD_FPWR,
00259    EC_CMD_FPRW,
00261    EC_CMD_BRD,
00263    EC_CMD_BWR,
00265    EC_CMD_BRW,
00267    EC_CMD_LRD,
00269    EC_CMD_LWR,
00271    EC_CMD_LRW,
00273    EC_CMD_ARMW,
00275    EC_CMD_FRMW
00277 } ec_cmdtype;
00278 
00280 typedef enum 
00281 {
00283    EC_ECMD_NOP         = 0x0000,
00285    EC_ECMD_READ        = 0x0100,
00287    EC_ECMD_WRITE       = 0x0201,
00289    EC_ECMD_RELOAD      = 0x0300
00290 } ec_ecmdtype;
00291 
00293 #define EC_ESTAT_R64    0x0040
00294 
00295 #define EC_ESTAT_BUSY   0x8000
00296 
00297 #define EC_ESTAT_EMASK  0x7800
00298 
00299 #define EC_ESTAT_NACK   0x2000
00300 
00301 /* Ethercat SSI (Slave Information Interface) */
00302 
00304 #define ECT_SII_START   0x0040
00305 
00306 enum
00307 {
00309    ECT_SII_STRING      = 10,
00311    ECT_SII_GENERAL     = 30,
00313    ECT_SII_FMMU        = 40,
00315    ECT_SII_SM          = 41,
00317    ECT_SII_PDO         = 50
00318 };
00319 
00321 enum
00322 {
00323    ECT_SII_MANUF       = 0x0008,
00324    ECT_SII_ID          = 0x000a,
00325    ECT_SII_REV         = 0x000c,
00326    ECT_SII_BOOTRXMBX   = 0x0014,
00327    ECT_SII_BOOTTXMBX   = 0x0016,
00328    ECT_SII_MBXSIZE     = 0x0019,
00329    ECT_SII_TXMBXADR    = 0x001a,
00330    ECT_SII_RXMBXADR    = 0x0018,
00331    ECT_SII_MBXPROTO    = 0x001c
00332 };
00333 
00335 enum
00336 {
00338    ECT_MBXT_ERR        = 0x00,
00340    ECT_MBXT_AOE,
00342    ECT_MBXT_EOE,
00344    ECT_MBXT_COE,
00346    ECT_MBXT_FOE,
00348    ECT_MBXT_SOE,
00350    ECT_MBXT_VOE        = 0x0f
00351 };
00352 
00354 enum
00355 {
00356    ECT_COES_EMERGENCY  = 0x01,
00357    ECT_COES_SDOREQ,
00358    ECT_COES_SDORES,
00359    ECT_COES_TXPDO,
00360    ECT_COES_RXPDO,
00361    ECT_COES_TXPDO_RR,
00362    ECT_COES_RXPDO_RR,
00363    ECT_COES_SDOINFO
00364 };
00365 
00367 enum
00368 {
00369    ECT_SDO_DOWN_INIT    = 0x21,
00370    ECT_SDO_DOWN_EXP     = 0x23,
00371    ECT_SDO_DOWN_INIT_CA = 0x31,
00372    ECT_SDO_UP_REQ       = 0x40,
00373    ECT_SDO_UP_REQ_CA    = 0x50,
00374    ECT_SDO_SEG_UP_REQ   = 0x60,
00375    ECT_SDO_ABORT        = 0x80
00376 };
00377 
00379 enum
00380 {
00381    ECT_GET_ODLIST_REQ  = 0x01,
00382    ECT_GET_ODLIST_RES  = 0x02,
00383    ECT_GET_OD_REQ      = 0x03,
00384    ECT_GET_OD_RES      = 0x04,
00385    ECT_GET_OE_REQ      = 0x05,
00386    ECT_GET_OE_RES      = 0x06,
00387    ECT_SDOINFO_ERROR   = 0x07
00388 };
00389 
00391 enum
00392 {
00393    ECT_FOE_READ        = 0x01,
00394    ECT_FOE_WRITE,
00395    ECT_FOE_DATA,
00396    ECT_FOE_ACK,
00397    ECT_FOE_ERROR,
00398    ECT_FOE_BUSY
00399 };
00400 
00402 enum
00403 {
00404    ECT_SOE_READREQ     = 0x01,
00405    ECT_SOE_READRES,
00406    ECT_SOE_WRITEREQ,
00407    ECT_SOE_WRITERES,
00408    ECT_SOE_NOTIFICATION,
00409    ECT_SOE_EMERGENCY
00410 };
00411 
00413 enum 
00414 {
00415    ECT_REG_TYPE        = 0x0000,
00416    ECT_REG_PORTDES     = 0x0007,
00417    ECT_REG_ESCSUP      = 0x0008,
00418    ECT_REG_STADR       = 0x0010,
00419    ECT_REG_ALIAS       = 0x0012,
00420    ECT_REG_DLCTL       = 0x0100,
00421    ECT_REG_DLPORT      = 0x0101,
00422    ECT_REG_DLALIAS     = 0x0103,
00423    ECT_REG_DLSTAT      = 0x0110,
00424    ECT_REG_ALCTL       = 0x0120,
00425    ECT_REG_ALSTAT      = 0x0130,
00426    ECT_REG_ALSTATCODE  = 0x0134,
00427    ECT_REG_PDICTL      = 0x0140,
00428    ECT_REG_IRQMASK     = 0x0200,
00429    ECT_REG_RXERR       = 0x0300,
00430    ECT_REG_EEPCFG      = 0x0500,
00431    ECT_REG_EEPCTL      = 0x0502,
00432    ECT_REG_EEPSTAT     = 0x0502,
00433    ECT_REG_EEPADR      = 0x0504,
00434    ECT_REG_EEPDAT      = 0x0508,
00435    ECT_REG_FMMU0       = 0x0600,
00436    ECT_REG_FMMU1       = ECT_REG_FMMU0 + 0x10,
00437    ECT_REG_FMMU2       = ECT_REG_FMMU1 + 0x10,
00438    ECT_REG_FMMU3       = ECT_REG_FMMU2 + 0x10,
00439    ECT_REG_SM0         = 0x0800,
00440    ECT_REG_SM1         = ECT_REG_SM0 + 0x08,
00441    ECT_REG_SM2         = ECT_REG_SM1 + 0x08,
00442    ECT_REG_SM3         = ECT_REG_SM2 + 0x08,
00443    ECT_REG_SM0STAT     = ECT_REG_SM0 + 0x05,
00444    ECT_REG_SM1STAT     = ECT_REG_SM1 + 0x05,
00445    ECT_REG_SM1ACT      = ECT_REG_SM1 + 0x06,
00446    ECT_REG_SM1CONTR    = ECT_REG_SM1 + 0x07,
00447    ECT_REG_DCTIME0     = 0x0900,
00448    ECT_REG_DCTIME1     = 0x0904,
00449    ECT_REG_DCTIME2     = 0x0908,
00450    ECT_REG_DCTIME3     = 0x090C,
00451    ECT_REG_DCSYSTIME   = 0x0910,
00452    ECT_REG_DCSOF       = 0x0918,
00453    ECT_REG_DCSYSOFFSET = 0x0920,
00454    ECT_REG_DCSYSDELAY  = 0x0928,
00455    ECT_REG_DCSYSDIFF   = 0x092C,
00456    ECT_REG_DCSPEEDCNT  = 0x0930,
00457    ECT_REG_DCTIMEFILT  = 0x0934,
00458    ECT_REG_DCCUC       = 0x0980,
00459    ECT_REG_DCSYNCACT   = 0x0981,
00460    ECT_REG_DCSTART0    = 0x0990,
00461    ECT_REG_DCCYCLE0    = 0x09A0,
00462    ECT_REG_DCCYCLE1    = 0x09A4
00463 };
00464 
00466 #define ECT_SDO_SMCOMMTYPE      0x1c00
00467 
00468 #define ECT_SDO_PDOASSIGN       0x1c10
00469 
00470 #define ECT_SDO_RXPDOASSIGN     0x1c12
00471 
00472 #define ECT_SDO_TXPDOASSIGN     0x1c13
00473 
00475 #define ETH_P_ECAT              0x88A4
00476 
00478 typedef enum
00479 {
00480    EC_ERR_TYPE_SDO_ERROR        = 0,
00481    EC_ERR_TYPE_EMERGENCY        = 1,
00482    EC_ERR_TYPE_PACKET_ERROR     = 3,
00483    EC_ERR_TYPE_SDOINFO_ERROR    = 4,
00484    EC_ERR_TYPE_FOE_ERROR        = 5,
00485    EC_ERR_TYPE_FOE_BUF2SMALL    = 6,
00486    EC_ERR_TYPE_FOE_PACKETNUMBER = 7,
00487    EC_ERR_TYPE_SOE_ERROR        = 8,
00488    EC_ERR_TYPE_MBX_ERROR        = 9
00489 } ec_err_type;
00490 
00492 typedef struct
00493 {
00495    ec_timet Time;
00497    boolean     Signal;
00499    uint16      Slave;
00501    uint16      Index;
00503    uint8       SubIdx;
00505    ec_err_type Etype;
00506    union
00507    {
00509       int32   AbortCode;
00511       struct
00512       {
00513          uint16  ErrorCode;
00514          uint8   ErrorReg;
00515          uint8   b1;
00516          uint16  w1;
00517          uint16  w2;
00518       };
00519    };
00520 } ec_errort;
00521 
00524 #define MK_WORD(msb, lsb)   ((((uint16)(msb))<<8) | (lsb))
00525 
00526 #define HI_BYTE(w)          ((w) >> 8)
00527 
00528 #define LO_BYTE(w)          ((w) & 0x00ff)
00529 
00530 #define SWAP(w)             ((((w)& 0xff00) >> 8) | (((w) & 0x00ff) << 8))
00531 
00532 #define LO_WORD(l)          ((l) & 0xffff)
00533 
00534 #define HI_WORD(l)          ((l) >> 16)
00535 
00536 #define get_unaligned(ptr) \
00537   ({ __typeof__(*(ptr)) __tmp; memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
00538 
00539 #define put_unaligned32(val, ptr)        \
00540   (memcpy((ptr), &(val), 4))
00541 
00542 #define put_unaligned64(val, ptr)        \
00543   (memcpy((ptr), &(val), 8))
00544 
00545 #if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN)
00546 
00547   #define htoes(A) (A)
00548   #define htoel(A) (A)
00549   #define htoell(A) (A)
00550   #define etohs(A) (A)
00551   #define etohl(A) (A)
00552   #define etohll(A) (A)
00553 
00554 #elif !defined(EC_LITTLE_ENDIAN) && defined(EC_BIG_ENDIAN)
00555 
00556   #define htoes(A) ((((uint16)(A) & 0xff00) >> 8) | \
00557                     (((uint16)(A) & 0x00ff) << 8))
00558   #define htoel(A) ((((uint32)(A) & 0xff000000) >> 24) | \
00559                     (((uint32)(A) & 0x00ff0000) >> 8)  | \
00560                     (((uint32)(A) & 0x0000ff00) << 8)  | \
00561                     (((uint32)(A) & 0x000000ff) << 24))
00562   #define htoell(A) ((((uint64)(A) & (uint64)0xff00000000000000ULL) >> 56) | \
00563                      (((uint64)(A) & (uint64)0x00ff000000000000ULL) >> 40) | \
00564                      (((uint64)(A) & (uint64)0x0000ff0000000000ULL) >> 24) | \
00565                      (((uint64)(A) & (uint64)0x000000ff00000000ULL) >> 8)  | \
00566                      (((uint64)(A) & (uint64)0x00000000ff000000ULL) << 8)  | \
00567                      (((uint64)(A) & (uint64)0x0000000000ff0000ULL) << 24) | \
00568                      (((uint64)(A) & (uint64)0x000000000000ff00ULL) << 40) | \
00569                      (((uint64)(A) & (uint64)0x00000000000000ffULL) << 56))
00570 
00571   #define etohs  htoes
00572   #define etohl  htoel
00573   #define etohll htoell
00574 
00575 #else
00576 
00577   #error "Must define one of EC_BIG_ENDIAN or EC_LITTLE_ENDIAN"
00578 
00579 #endif
00580 
00581 #ifdef __cplusplus
00582 }
00583 #endif
00584 
00585 #endif /* _EC_TYPE_H */


ethercat_soem
Author(s): Arthur Ketels, M.J.G. van de Molengraft
autogenerated on Wed Aug 26 2015 11:32:40