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