ethercatmain.h
Go to the documentation of this file.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 #ifndef _ethercatmain_
00047 #define _ethercatmain_
00048
00049 #ifndef PACKED
00050 #define PACKED __attribute__((__packed__))
00051 #endif
00052
00053
00054 #define EC_MAXELIST 64
00055
00056 #define EC_MAXNAME 36
00057
00058 #define EC_MAXSLAVE 200
00059
00060 #define EC_MAXGROUP 8
00061
00062 #define EC_MAXIOSEGMENTS 64
00063
00064 #define EC_MAXMBX 0x3ff
00065
00066 #define EC_MAXEEPDO 0x200
00067
00068 #define EC_MAXSM 8
00069
00070 #define EC_MAXFMMU 4
00071
00072
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
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
00119 typedef struct
00120 {
00121
00122 uint16 state;
00123
00124 uint16 ALstatuscode;
00125
00126 uint16 configadr;
00127
00128 uint16 aliasadr;
00129
00130 uint32 eep_man;
00131
00132 uint32 eep_id;
00133
00134 uint32 eep_rev;
00135
00136 uint16 Itype;
00137
00138 uint16 Dtype;
00139
00140 uint16 Obits;
00141
00142 uint32 Obytes;
00143
00144 uint8 *outputs;
00145
00146 uint8 Ostartbit;
00147
00148 uint16 Ibits;
00149
00150 uint32 Ibytes;
00151
00152 uint8 *inputs;
00153
00154 uint8 Istartbit;
00155
00156 ec_smt SM[EC_MAXSM];
00157
00158 uint8 SMtype[EC_MAXSM];
00159
00160 ec_fmmut FMMU[EC_MAXFMMU];
00161
00162 uint8 FMMU0func;
00163
00164 uint8 FMMU1func;
00165
00166 uint8 FMMU2func;
00167
00168 uint8 FMMU3func;
00169
00170 uint16 mbx_l;
00171
00172 uint16 mbx_wo;
00173
00174 uint16 mbx_rl;
00175
00176 uint16 mbx_ro;
00177
00178 uint16 mbx_proto;
00179
00180 uint8 mbx_cnt;
00181
00182 boolean hasdc;
00183
00184 uint8 ptype;
00185
00186 uint8 topology;
00187
00188 uint8 activeports;
00189
00190 uint8 consumedports;
00191
00192 uint16 parent;
00193
00194 uint8 parentport;
00195
00196 uint8 entryport;
00197
00198 int32 DCrtA;
00199
00200 int32 DCrtB;
00201
00202 int32 DCrtC;
00203
00204 int32 DCrtD;
00205
00206 int32 pdelay;
00207
00208 uint16 DCnext;
00209
00210 uint16 DCprevious;
00211
00212 int32 DCcycle;
00213
00214 int32 DCshift;
00215
00216 uint8 DCactive;
00217
00218 uint16 configindex;
00219
00220 uint16 SIIindex;
00221
00222 uint8 eep_8byte;
00223
00224 uint8 eep_pdi;
00225
00226 uint8 CoEdetails;
00227
00228 uint8 FoEdetails;
00229
00230 uint8 EoEdetails;
00231
00232 uint8 SoEdetails;
00233
00234 int16 Ebuscurrent;
00235
00236 uint8 blockLRW;
00237
00238 uint8 group;
00239
00240 uint8 FMMUunused;
00241
00242 boolean islost;
00243
00244 int (*PO2SOconfig)(uint16 slave);
00245
00246 char name[EC_MAXNAME + 1];
00247 } ec_slavet;
00248
00249
00250 typedef struct
00251 {
00252
00253 uint32 logstartaddr;
00254
00255 uint32 Obytes;
00256
00257 uint8 *outputs;
00258
00259 uint32 Ibytes;
00260
00261 uint8 *inputs;
00262
00263 boolean hasdc;
00264
00265 uint16 DCnext;
00266
00267 int16 Ebuscurrent;
00268
00269 uint8 blockLRW;
00270
00271 uint16 nsegments;
00272
00273 uint16 Isegment;
00274
00275 uint16 Ioffset;
00276
00277 uint16 expectedWKC;
00278
00279 boolean docheckstate;
00280
00281 uint32 IOsegment[EC_MAXIOSEGMENTS];
00282 } ec_groupt;
00283
00284
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
00296 typedef struct
00297 {
00298 uint16 Startpos;
00299 uint8 nSM;
00300 uint16 PhStart;
00301 uint16 Plength;
00302 uint8 Creg;
00303 uint8 Sreg;
00304 uint8 Activate;
00305 uint8 PDIctrl;
00306 } ec_eepromSMt;
00307
00308
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
00321 typedef uint8 ec_mbxbuft[EC_MAXMBX + 1];
00322
00323
00324 typedef struct PACKED
00325 {
00326 uint16 length;
00327 uint16 address;
00328 uint8 priority;
00329 uint8 mbxtype;
00330 } ec_mbxheadert;
00331
00332
00333 typedef struct PACKED
00334 {
00335 uint16 alstatus;
00336 uint16 unused;
00337 uint16 alstatuscode;
00338 } ec_alstatust;
00339
00340
00341 extern ec_slavet ec_slave[EC_MAXSLAVE];
00342
00343 extern int ec_slavecount;
00344
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