ethercatmain.c
Go to the documentation of this file.
1 /*
2  * Simple Open EtherCAT Master Library
3  *
4  * File : ethercatmain.c
5  * Version : 1.3.0
6  * Date : 24-02-2013
7  * Copyright (C) 2005-2013 Speciaal Machinefabriek Ketels v.o.f.
8  * Copyright (C) 2005-2013 Arthur Ketels
9  * Copyright (C) 2008-2009 TU/e Technische Universiteit Eindhoven
10  *
11  * SOEM is free software; you can redistribute it and/or modify it under
12  * the terms of the GNU General Public License version 2 as published by the Free
13  * Software Foundation.
14  *
15  * SOEM is distributed in the hope that it will be useful, but WITHOUT ANY
16  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18  * for more details.
19  *
20  * As a special exception, if other files instantiate templates or use macros
21  * or inline functions from this file, or you compile this file and link it
22  * with other works to produce a work based on this file, this file does not
23  * by itself cause the resulting work to be covered by the GNU General Public
24  * License. However the source code for this file must still be made available
25  * in accordance with section (3) of the GNU General Public License.
26  *
27  * This exception does not invalidate any other reasons why a work based on
28  * this file might be covered by the GNU General Public License.
29  *
30  * The EtherCAT Technology, the trade name and logo EtherCAT are the intellectual
31  * property of, and protected by Beckhoff Automation GmbH. You can use SOEM for
32  * the sole purpose of creating, using and/or selling or otherwise distributing
33  * an EtherCAT network master provided that an EtherCAT Master License is obtained
34  * from Beckhoff Automation GmbH.
35  *
36  * In case you did not receive a copy of the EtherCAT Master License along with
37  * SOEM write to Beckhoff Automation GmbH, Eiserstraße 5, D-33415 Verl, Germany
38  * (www.beckhoff.com).
39  */
40 
53 #include <stdio.h>
54 #include <string.h>
55 #include "osal.h"
56 #include "oshw.h"
57 #include "ethercattype.h"
58 #include "ethercatbase.h"
59 #include "ethercatmain.h"
60 
61 
63 #define EC_LOCALDELAY 200
64 
66 PACKED_BEGIN
67 typedef struct PACKED
68 {
72 } ec_eepromt;
73 PACKED_END
74 
76 PACKED_BEGIN
77 typedef struct PACKED
78 {
82 } ec_mbxerrort;
83 PACKED_END
84 
86 PACKED_BEGIN
87 typedef struct PACKED
88 {
95 } ec_emcyt;
96 PACKED_END
97 
98 #ifdef EC_VER1
99 
109 
117 
124 
130 boolean EcatError = FALSE;
131 
133 
136 
138  &ecx_port, // .port =
139  &ec_slave[0], // .slavelist =
140  &ec_slavecount, // .slavecount =
141  EC_MAXSLAVE, // .maxslave =
142  &ec_group[0], // .grouplist =
143  EC_MAXGROUP, // .maxgroup =
144  &esibuf[0], // .esibuf =
145  &esimap[0], // .esimap =
146  0, // .esislave =
147  &ec_elist, // .elist =
148  &ec_idxstack, // .idxstack =
149  &EcatError, // .ecaterror =
150  0, // .DCtO =
151  0, // .DCl =
152  &ec_DCtime, // .DCtime =
153  &ec_SMcommtype, // .SMcommtype =
154  &ec_PDOassign, // .PDOassign =
155  &ec_PDOdesc, // .PDOdesc =
156  &ec_SM, // .eepSM =
157  &ec_FMMU // .eepFMMU =
158 };
159 #endif
160 
166 {
167  ec_adaptert * ret_adapter;
168 
169  ret_adapter = oshw_find_adapters ();
170 
171  return ret_adapter;
172 }
173 
179 {
180  oshw_free_adapters (adapter);
181 }
182 
188 void ecx_pusherror(ecx_contextt *context, const ec_errort *Ec)
189 {
190  context->elist->Error[context->elist->head] = *Ec;
191  context->elist->Error[context->elist->head].Signal = TRUE;
192  context->elist->head++;
193  if (context->elist->head > EC_MAXELIST)
194  {
195  context->elist->head = 0;
196  }
197  if (context->elist->head == context->elist->tail)
198  {
199  context->elist->tail++;
200  }
201  if (context->elist->tail > EC_MAXELIST)
202  {
203  context->elist->tail = 0;
204  }
205  *(context->ecaterror) = TRUE;
206 }
207 
214 boolean ecx_poperror(ecx_contextt *context, ec_errort *Ec)
215 {
216  boolean notEmpty = (context->elist->head != context->elist->tail);
217 
218  *Ec = context->elist->Error[context->elist->tail];
219  context->elist->Error[context->elist->tail].Signal = FALSE;
220  if (notEmpty)
221  {
222  context->elist->tail++;
223  if (context->elist->tail > EC_MAXELIST)
224  {
225  context->elist->tail = 0;
226  }
227  }
228  else
229  {
230  *(context->ecaterror) = FALSE;
231  }
232  return notEmpty;
233 }
234 
240 boolean ecx_iserror(ecx_contextt *context)
241 {
242  return (context->elist->head != context->elist->tail);
243 }
244 
254 {
255  ec_errort Ec;
256 
257  Ec.Time = osal_current_time();
258  Ec.Slave = Slave;
259  Ec.Index = Index;
260  Ec.SubIdx = SubIdx;
261  *(context->ecaterror) = TRUE;
263  Ec.ErrorCode = ErrorCode;
264  ecx_pusherror(context, &Ec);
265 }
266 
273 static void ecx_mbxerror(ecx_contextt *context, uint16 Slave,uint16 Detail)
274 {
275  ec_errort Ec;
276 
277  Ec.Time = osal_current_time();
278  Ec.Slave = Slave;
279  Ec.Index = 0;
280  Ec.SubIdx = 0;
282  Ec.ErrorCode = Detail;
283  ecx_pusherror(context, &Ec);
284 }
285 
297  uint8 b1, uint16 w1, uint16 w2)
298 {
299  ec_errort Ec;
300 
301  Ec.Time = osal_current_time();
302  Ec.Slave = Slave;
303  Ec.Index = 0;
304  Ec.SubIdx = 0;
306  Ec.ErrorCode = ErrorCode;
307  Ec.ErrorReg = (uint8)ErrorReg;
308  Ec.b1 = b1;
309  Ec.w1 = w1;
310  Ec.w2 = w2;
311  ecx_pusherror(context, &Ec);
312 }
313 
319 int ecx_init(ecx_contextt *context, char * ifname)
320 {
321  return ecx_setupnic(context->port, ifname, FALSE);
322 }
323 
331 int ecx_init_redundant(ecx_contextt *context, ecx_redportt *redport, char *ifname, char *if2name)
332 {
333  int rval, zbuf;
334  ec_etherheadert *ehp;
335 
336  context->port->redport = redport;
337  ecx_setupnic(context->port, ifname, FALSE);
338  rval = ecx_setupnic(context->port, if2name, TRUE);
339  /* prepare "dummy" BRD tx frame for redundant operation */
340  ehp = (ec_etherheadert *)&(context->port->txbuf2);
341  ehp->sa1 = oshw_htons(secMAC[0]);
342  zbuf = 0;
343  ecx_setupdatagram(context->port, &(context->port->txbuf2), EC_CMD_BRD, 0, 0x0000, 0x0000, 2, &zbuf);
345 
346  return rval;
347 }
348 
352 void ecx_close(ecx_contextt *context)
353 {
354  ecx_closenic(context->port);
355 };
356 
366 {
367  uint16 configadr, eadr;
368  uint64 edat;
369  uint16 mapw, mapb;
370  int lp,cnt;
371  uint8 retval;
372 
373  retval = 0xff;
374  if (slave != context->esislave) /* not the same slave? */
375  {
376  memset(context->esimap, 0x00, EC_MAXEEPBITMAP); /* clear esibuf cache map */
377  context->esislave = slave;
378  }
379  if (address < EC_MAXEEPBUF)
380  {
381  mapw = address >> 5;
382  mapb = address - (mapw << 5);
383  if (context->esimap[mapw] & (uint32)(1 << mapb))
384  {
385  /* byte is already in buffer */
386  retval = context->esibuf[address];
387  }
388  else
389  {
390  /* byte is not in buffer, put it there */
391  configadr = context->slavelist[slave].configadr;
392  ecx_eeprom2master(context, slave); /* set eeprom control to master */
393  eadr = address >> 1;
394  edat = ecx_readeepromFP (context, configadr, eadr, EC_TIMEOUTEEP);
395  /* 8 byte response */
396  if (context->slavelist[slave].eep_8byte)
397  {
398  put_unaligned64(edat, &(context->esibuf[eadr << 1]));
399  cnt = 8;
400  }
401  /* 4 byte response */
402  else
403  {
404  put_unaligned32(edat, &(context->esibuf[eadr << 1]));
405  cnt = 4;
406  }
407  /* find bitmap location */
408  mapw = eadr >> 4;
409  mapb = (eadr << 1) - (mapw << 5);
410  for(lp = 0 ; lp < cnt ; lp++)
411  {
412  /* set bitmap for each byte that is read */
413  context->esimap[mapw] |= (1 << mapb);
414  mapb++;
415  if (mapb > 31)
416  {
417  mapb = 0;
418  mapw++;
419  }
420  }
421  retval = context->esibuf[address];
422  }
423  }
424 
425  return retval;
426 }
427 
435 {
436  int16 a;
437  uint16 p;
438  uint8 eectl = context->slavelist[slave].eep_pdi;
439 
440  a = ECT_SII_START << 1;
441  /* read first SII section category */
442  p = ecx_siigetbyte(context, slave, a++);
443  p += (ecx_siigetbyte(context, slave, a++) << 8);
444  /* traverse SII while category is not found and not EOF */
445  while ((p != cat) && (p != 0xffff))
446  {
447  /* read section length */
448  p = ecx_siigetbyte(context, slave, a++);
449  p += (ecx_siigetbyte(context, slave, a++) << 8);
450  /* locate next section category */
451  a += p << 1;
452  /* read section category */
453  p = ecx_siigetbyte(context, slave, a++);
454  p += (ecx_siigetbyte(context, slave, a++) << 8);
455  }
456  if (p != cat)
457  {
458  a = 0;
459  }
460  if (eectl)
461  {
462  ecx_eeprom2pdi(context, slave); /* if eeprom control was previously pdi then restore */
463  }
464 
465  return a;
466 }
467 
474 void ecx_siistring(ecx_contextt *context, char *str, uint16 slave, uint16 Sn)
475 {
476  uint16 a,i,j,l,n,ba;
477  char *ptr;
478  uint8 eectl = context->slavelist[slave].eep_pdi;
479 
480  ptr = str;
481  a = ecx_siifind (context, slave, ECT_SII_STRING); /* find string section */
482  if (a > 0)
483  {
484  ba = a + 2; /* skip SII section header */
485  n = ecx_siigetbyte(context, slave, ba++); /* read number of strings in section */
486  if (Sn <= n) /* is req string available? */
487  {
488  for (i = 1; i <= Sn; i++) /* walk through strings */
489  {
490  l = ecx_siigetbyte(context, slave, ba++); /* length of this string */
491  if (i < Sn)
492  {
493  ba += l;
494  }
495  else
496  {
497  ptr = str;
498  for (j = 1; j <= l; j++) /* copy one string */
499  {
500  if(j <= EC_MAXNAME)
501  {
502  *ptr = (char)ecx_siigetbyte(context, slave, ba++);
503  ptr++;
504  }
505  else
506  {
507  ba++;
508  }
509  }
510  }
511  }
512  *ptr = 0; /* add zero terminator */
513  }
514  else
515  {
516  ptr = str;
517  *ptr = 0; /* empty string */
518  }
519  }
520  if (eectl)
521  {
522  ecx_eeprom2pdi(context, slave); /* if eeprom control was previously pdi then restore */
523  }
524 }
525 
533 {
534  uint16 a;
535  uint8 eectl = context->slavelist[slave].eep_pdi;
536 
537  FMMU->nFMMU = 0;
538  FMMU->FMMU0 = 0;
539  FMMU->FMMU1 = 0;
540  FMMU->FMMU2 = 0;
541  FMMU->FMMU3 = 0;
542  FMMU->Startpos = ecx_siifind(context, slave, ECT_SII_FMMU);
543 
544  if (FMMU->Startpos > 0)
545  {
546  a = FMMU->Startpos;
547  FMMU->nFMMU = ecx_siigetbyte(context, slave, a++);
548  FMMU->nFMMU += (ecx_siigetbyte(context, slave, a++) << 8);
549  FMMU->nFMMU *= 2;
550  FMMU->FMMU0 = ecx_siigetbyte(context, slave, a++);
551  FMMU->FMMU1 = ecx_siigetbyte(context, slave, a++);
552  if (FMMU->nFMMU > 2)
553  {
554  FMMU->FMMU2 = ecx_siigetbyte(context, slave, a++);
555  FMMU->FMMU3 = ecx_siigetbyte(context, slave, a++);
556  }
557  }
558  if (eectl)
559  {
560  ecx_eeprom2pdi(context, slave); /* if eeprom control was previously pdi then restore */
561  }
562 
563  return FMMU->nFMMU;
564 }
565 
573 {
574  uint16 a,w;
575  uint8 eectl = context->slavelist[slave].eep_pdi;
576 
577  SM->nSM = 0;
578  SM->Startpos = ecx_siifind(context, slave, ECT_SII_SM);
579  if (SM->Startpos > 0)
580  {
581  a = SM->Startpos;
582  w = ecx_siigetbyte(context, slave, a++);
583  w += (ecx_siigetbyte(context, slave, a++) << 8);
584  SM->nSM = (w / 4);
585  SM->PhStart = ecx_siigetbyte(context, slave, a++);
586  SM->PhStart += (ecx_siigetbyte(context, slave, a++) << 8);
587  SM->Plength = ecx_siigetbyte(context, slave, a++);
588  SM->Plength += (ecx_siigetbyte(context, slave, a++) << 8);
589  SM->Creg = ecx_siigetbyte(context, slave, a++);
590  SM->Sreg = ecx_siigetbyte(context, slave, a++);
591  SM->Activate = ecx_siigetbyte(context, slave, a++);
592  SM->PDIctrl = ecx_siigetbyte(context, slave, a++);
593  }
594  if (eectl)
595  {
596  ecx_eeprom2pdi(context, slave); /* if eeprom control was previously pdi then restore */
597  }
598 
599  return SM->nSM;
600 }
601 
610 {
611  uint16 a;
612  uint16 retVal = 0;
613  uint8 eectl = context->slavelist[slave].eep_pdi;
614 
615  if (n < SM->nSM)
616  {
617  a = SM->Startpos + 2 + (n * 8);
618  SM->PhStart = ecx_siigetbyte(context, slave, a++);
619  SM->PhStart += (ecx_siigetbyte(context, slave, a++) << 8);
620  SM->Plength = ecx_siigetbyte(context, slave, a++);
621  SM->Plength += (ecx_siigetbyte(context, slave, a++) << 8);
622  SM->Creg = ecx_siigetbyte(context, slave, a++);
623  SM->Sreg = ecx_siigetbyte(context, slave, a++);
624  SM->Activate = ecx_siigetbyte(context, slave, a++);
625  SM->PDIctrl = ecx_siigetbyte(context, slave, a++);
626  retVal = 1;
627  }
628  if (eectl)
629  {
630  ecx_eeprom2pdi(context, slave); /* if eeprom control was previously pdi then restore */
631  }
632 
633  return retVal;
634 }
635 
644 {
645  uint16 a , w, c, e, er, Size;
646  uint8 eectl = context->slavelist[slave].eep_pdi;
647 
648  Size = 0;
649  PDO->nPDO = 0;
650  PDO->Length = 0;
651  PDO->Index[1] = 0;
652  for (c = 0 ; c < EC_MAXSM ; c++) PDO->SMbitsize[c] = 0;
653  if (t > 1)
654  t = 1;
655  PDO->Startpos = ecx_siifind(context, slave, ECT_SII_PDO + t);
656  if (PDO->Startpos > 0)
657  {
658  a = PDO->Startpos;
659  w = ecx_siigetbyte(context, slave, a++);
660  w += (ecx_siigetbyte(context, slave, a++) << 8);
661  PDO->Length = w;
662  c = 1;
663  /* traverse through all PDOs */
664  do
665  {
666  PDO->nPDO++;
667  PDO->Index[PDO->nPDO] = ecx_siigetbyte(context, slave, a++);
668  PDO->Index[PDO->nPDO] += (ecx_siigetbyte(context, slave, a++) << 8);
669  PDO->BitSize[PDO->nPDO] = 0;
670  c++;
671  e = ecx_siigetbyte(context, slave, a++);
672  PDO->SyncM[PDO->nPDO] = ecx_siigetbyte(context, slave, a++);
673  a += 4;
674  c += 2;
675  if (PDO->SyncM[PDO->nPDO] < EC_MAXSM) /* active and in range SM? */
676  {
677  /* read all entries defined in PDO */
678  for (er = 1; er <= e; er++)
679  {
680  c += 4;
681  a += 5;
682  PDO->BitSize[PDO->nPDO] += ecx_siigetbyte(context, slave, a++);
683  a += 2;
684  }
685  PDO->SMbitsize[ PDO->SyncM[PDO->nPDO] ] += PDO->BitSize[PDO->nPDO];
686  Size += PDO->BitSize[PDO->nPDO];
687  c++;
688  }
689  else /* PDO deactivated because SM is 0xff or > EC_MAXSM */
690  {
691  c += 4 * e;
692  a += 8 * e;
693  c++;
694  }
695  if (PDO->nPDO >= (EC_MAXEEPDO - 1))
696  {
697  c = PDO->Length; /* limit number of PDO entries in buffer */
698  }
699  }
700  while (c < PDO->Length);
701  }
702  if (eectl)
703  {
704  ecx_eeprom2pdi(context, slave); /* if eeprom control was previously pdi then restore */
705  }
706 
707  return (Size);
708 }
709 
715 {
716  uint16 slave, configadr, lowest, rval;
717  ec_alstatust slstat;
718 
719  lowest = 0xff;
720  context->slavelist[0].ALstatuscode = 0;
721  for (slave = 1; slave <= *(context->slavecount); slave++)
722  {
723  configadr = context->slavelist[slave].configadr;
724  slstat.alstatus = 0;
725  slstat.alstatuscode = 0;
726  ecx_FPRD(context->port, configadr, ECT_REG_ALSTAT, sizeof(slstat), &slstat, EC_TIMEOUTRET3);
727  rval = etohs(slstat.alstatus);
728  context->slavelist[slave].ALstatuscode = etohs(slstat.alstatuscode);
729  if (rval < lowest)
730  {
731  lowest = rval;
732  }
733  context->slavelist[slave].state = rval;
734  context->slavelist[0].ALstatuscode |= context->slavelist[slave].ALstatuscode;
735  }
736  context->slavelist[0].state = lowest;
737 
738  return lowest;
739 }
740 
748 {
749  uint16 configadr, slstate;
750 
751  if (slave == 0)
752  {
753  slstate = htoes(context->slavelist[slave].state);
754  ecx_BWR(context->port, 0, ECT_REG_ALCTL, sizeof(slstate), &slstate, EC_TIMEOUTRET3); /* write slave status */
755  }
756  else
757  {
758  configadr = context->slavelist[slave].configadr;
759 
760  ecx_FPWRw(context->port, configadr, ECT_REG_ALCTL, htoes(context->slavelist[slave].state), EC_TIMEOUTRET3); /* write slave status */
761  }
762  return 0;
763 }
764 
773 uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout)
774 {
775  uint16 configadr, state, rval;
776  ec_alstatust slstat;
777  osal_timert timer;
778 
779  if ( slave > *(context->slavecount) )
780  {
781  return 0;
782  }
783  osal_timer_start(&timer, timeout);
784  configadr = context->slavelist[slave].configadr;
785  do
786  {
787  if (slave < 1)
788  {
789  rval = 0;
790  ecx_BRD(context->port, 0, ECT_REG_ALSTAT, sizeof(rval), &rval , EC_TIMEOUTRET);
791  rval = etohs(rval);
792  }
793  else
794  {
795  slstat.alstatus = 0;
796  slstat.alstatuscode = 0;
797  ecx_FPRD(context->port, configadr, ECT_REG_ALSTAT, sizeof(slstat), &slstat, EC_TIMEOUTRET);
798  rval = etohs(slstat.alstatus);
799  context->slavelist[slave].ALstatuscode = etohs(slstat.alstatuscode);
800  }
801  state = rval & 0x000f; /* read slave status */
802  if (state != reqstate)
803  {
804  osal_usleep(1000);
805  }
806  }
807  while ((state != reqstate) && (osal_timer_is_expired(&timer) == FALSE));
808  context->slavelist[slave].state = rval;
809 
810  return state;
811 }
812 
819 {
820  cnt++;
821  if (cnt > 7)
822  {
823  cnt = 1; /* wrap around to 1, not 0 */
824  }
825 
826  return cnt;
827 }
828 
833 {
834  memset(*Mbx, 0x00, EC_MAXMBX);
835 }
836 
843 int ecx_mbxempty(ecx_contextt *context, uint16 slave, int timeout)
844 {
845  uint16 configadr;
846  uint8 SMstat;
847  int wkc;
848  osal_timert timer;
849 
850  osal_timer_start(&timer, timeout);
851  configadr = context->slavelist[slave].configadr;
852  do
853  {
854  wkc = ecx_FPRD(context->port, configadr, ECT_REG_SM0STAT, sizeof(SMstat), &SMstat, EC_TIMEOUTRET);
855  SMstat = etohs(SMstat);
856  if (((SMstat & 0x08) != 0) && (timeout > EC_LOCALDELAY))
857  {
859  }
860  }
861  while (((wkc <= 0) || ((SMstat & 0x08) != 0)) && (osal_timer_is_expired(&timer) == FALSE));
862 
863  if ((wkc > 0) && ((SMstat & 0x08) == 0))
864  {
865  return 1;
866  }
867 
868  return 0;
869 }
870 
878 int ecx_mbxsend(ecx_contextt *context, uint16 slave,ec_mbxbuft *mbx, int timeout)
879 {
880  uint16 mbxwo,mbxl,configadr;
881  int wkc;
882 
883  wkc = 0;
884  configadr = context->slavelist[slave].configadr;
885  mbxl = context->slavelist[slave].mbx_l;
886  if (mbxl > 0)
887  {
888  if (ecx_mbxempty(context, slave, timeout))
889  {
890  mbxwo = context->slavelist[slave].mbx_wo;
891  /* write slave in mailbox */
892  wkc = ecx_FPWR(context->port, configadr, mbxwo, mbxl, mbx, EC_TIMEOUTRET3);
893  }
894  else
895  {
896  wkc = 0;
897  }
898  }
899 
900  return wkc;
901 }
902 
911 int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
912 {
913  uint16 mbxro,mbxl,configadr;
914  int wkc=0;
915  int wkc2;
916  uint16 SMstat;
917  uint8 SMcontr;
918  ec_mbxheadert *mbxh;
919  ec_emcyt *EMp;
920  ec_mbxerrort *MBXEp;
921 
922  configadr = context->slavelist[slave].configadr;
923  mbxl = context->slavelist[slave].mbx_rl;
924  if (mbxl > 0)
925  {
926  osal_timert timer;
927 
928  osal_timer_start(&timer, timeout);
929  wkc = 0;
930  do /* wait for read mailbox available */
931  {
932  wkc = ecx_FPRD(context->port, configadr, ECT_REG_SM1STAT, sizeof(SMstat), &SMstat, EC_TIMEOUTRET);
933  SMstat = etohs(SMstat);
934  if (((SMstat & 0x08) == 0) && (timeout > EC_LOCALDELAY))
935  {
937  }
938  }
939  while (((wkc <= 0) || ((SMstat & 0x08) == 0)) && (osal_timer_is_expired(&timer) == FALSE));
940 
941  if ((wkc > 0) && ((SMstat & 0x08) > 0)) /* read mailbox available ? */
942  {
943  mbxro = context->slavelist[slave].mbx_ro;
944  mbxh = (ec_mbxheadert *)mbx;
945  do
946  {
947  wkc = ecx_FPRD(context->port, configadr, mbxro, mbxl, mbx, EC_TIMEOUTRET); /* get mailbox */
948  if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == 0x00)) /* Mailbox error response? */
949  {
950  MBXEp = (ec_mbxerrort *)mbx;
951  ecx_mbxerror(context, slave, etohs(MBXEp->Detail));
952  wkc = 0; /* prevent emergency to cascade up, it is already handled. */
953  }
954  else if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == 0x03)) /* CoE response? */
955  {
956  EMp = (ec_emcyt *)mbx;
957  if ((etohs(EMp->CANOpen) >> 12) == 0x01) /* Emergency request? */
958  {
959  ecx_mbxemergencyerror(context, slave, etohs(EMp->ErrorCode), EMp->ErrorReg,
960  EMp->bData, etohs(EMp->w1), etohs(EMp->w2));
961  wkc = 0; /* prevent emergency to cascade up, it is already handled. */
962  }
963  }
964  else
965  {
966  if (wkc <= 0) /* read mailbox lost */
967  {
968  SMstat ^= 0x0200; /* toggle repeat request */
969  SMstat = htoes(SMstat);
970  wkc2 = ecx_FPWR(context->port, configadr, ECT_REG_SM1STAT, sizeof(SMstat), &SMstat, EC_TIMEOUTRET);
971  SMstat = etohs(SMstat);
972  do /* wait for toggle ack */
973  {
974  wkc2 = ecx_FPRD(context->port, configadr, ECT_REG_SM1CONTR, sizeof(SMcontr), &SMcontr, EC_TIMEOUTRET);
975  } while (((wkc2 <= 0) || ((SMcontr & 0x02) != (HI_BYTE(SMstat) & 0x02))) && (osal_timer_is_expired(&timer) == FALSE));
976  do /* wait for read mailbox available */
977  {
978  wkc2 = ecx_FPRD(context->port, configadr, ECT_REG_SM1STAT, sizeof(SMstat), &SMstat, EC_TIMEOUTRET);
979  SMstat = etohs(SMstat);
980  if (((SMstat & 0x08) == 0) && (timeout > EC_LOCALDELAY))
981  {
983  }
984  } while (((wkc2 <= 0) || ((SMstat & 0x08) == 0)) && (osal_timer_is_expired(&timer) == FALSE));
985  }
986  }
987  } while ((wkc <= 0) && (osal_timer_is_expired(&timer) == FALSE)); /* if WKC<=0 repeat */
988  }
989  else /* no read mailbox available */
990  {
991  wkc = 0;
992  }
993  }
994 
995  return wkc;
996 }
997 
1004 {
1005  int address, incr;
1006  uint16 configadr;
1007  uint64 *p64;
1008  uint16 *p16;
1009  uint64 edat;
1010  uint8 eectl = context->slavelist[slave].eep_pdi;
1011 
1012  ecx_eeprom2master(context, slave); /* set eeprom control to master */
1013  configadr = context->slavelist[slave].configadr;
1014  address = ECT_SII_START;
1015  p16=(uint16*)esibuf;
1016  if (context->slavelist[slave].eep_8byte)
1017  {
1018  incr = 4;
1019  }
1020  else
1021  {
1022  incr = 2;
1023  }
1024  do
1025  {
1026  edat = ecx_readeepromFP(context, configadr, address, EC_TIMEOUTEEP);
1027  p64 = (uint64*)p16;
1028  *p64 = edat;
1029  p16 += incr;
1030  address += incr;
1031  } while ((address <= (EC_MAXEEPBUF >> 1)) && ((uint32)edat != 0xffffffff));
1032 
1033  if (eectl)
1034  {
1035  ecx_eeprom2pdi(context, slave); /* if eeprom control was previously pdi then restore */
1036  }
1037 }
1038 
1046 uint32 ecx_readeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, int timeout)
1047 {
1048  uint16 configadr;
1049 
1050  ecx_eeprom2master(context, slave); /* set eeprom control to master */
1051  configadr = context->slavelist[slave].configadr;
1052 
1053  return ((uint32)ecx_readeepromFP(context, configadr, eeproma, timeout));
1054 }
1055 
1064 int ecx_writeeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, uint16 data, int timeout)
1065 {
1066  uint16 configadr;
1067 
1068  ecx_eeprom2master(context, slave); /* set eeprom control to master */
1069  configadr = context->slavelist[slave].configadr;
1070  return (ecx_writeeepromFP(context, configadr, eeproma, data, timeout));
1071 }
1072 
1079 {
1080  int wkc = 1, cnt = 0;
1081  uint16 configadr;
1082  uint8 eepctl;
1083 
1084  if ( context->slavelist[slave].eep_pdi )
1085  {
1086  configadr = context->slavelist[slave].configadr;
1087  eepctl = 2;
1088  do
1089  {
1090  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET); /* force Eeprom from PDI */
1091  }
1092  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1093  eepctl = 0;
1094  cnt = 0;
1095  do
1096  {
1097  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET); /* set Eeprom to master */
1098  }
1099  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1100  context->slavelist[slave].eep_pdi = 0;
1101  }
1102 
1103  return wkc;
1104 }
1105 
1112 {
1113  int wkc = 1, cnt = 0;
1114  uint16 configadr;
1115  uint8 eepctl;
1116 
1117  if ( !context->slavelist[slave].eep_pdi )
1118  {
1119  configadr = context->slavelist[slave].configadr;
1120  eepctl = 1;
1121  do
1122  {
1123  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPCFG, sizeof(eepctl), &eepctl , EC_TIMEOUTRET); /* set Eeprom to PDI */
1124  }
1125  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1126  context->slavelist[slave].eep_pdi = 1;
1127  }
1128 
1129  return wkc;
1130 }
1131 
1132 uint16 ecx_eeprom_waitnotbusyAP(ecx_contextt *context, uint16 aiadr,uint16 *estat, int timeout)
1133 {
1134  int wkc, cnt = 0, retval = 0;
1135  osal_timert timer;
1136 
1137  osal_timer_start(&timer, timeout);
1138  do
1139  {
1140  if (cnt++)
1141  {
1143  }
1144  wkc=ecx_APRD(context->port, aiadr, ECT_REG_EEPSTAT, sizeof(*estat), estat, EC_TIMEOUTRET);
1145  *estat = etohs(*estat);
1146  }
1147  while (((wkc <= 0) || ((*estat & EC_ESTAT_BUSY) > 0)) && (osal_timer_is_expired(&timer) == FALSE)); /* wait for eeprom ready */
1148  if ((*estat & EC_ESTAT_BUSY) == 0)
1149  {
1150  retval = 1;
1151  }
1152 
1153  return retval;
1154 }
1155 
1163 uint64 ecx_readeepromAP(ecx_contextt *context, uint16 aiadr, uint16 eeproma, int timeout)
1164 {
1165  uint16 estat;
1166  uint32 edat32;
1167  uint64 edat64;
1168  ec_eepromt ed;
1169  int wkc, cnt, nackcnt = 0;
1170 
1171  edat64 = 0;
1172  edat32 = 0;
1173  if (ecx_eeprom_waitnotbusyAP(context, aiadr, &estat, timeout))
1174  {
1175  if (estat & EC_ESTAT_EMASK) /* error bits are set */
1176  {
1177  estat = htoes(EC_ECMD_NOP); /* clear error bits */
1178  wkc = ecx_APWR(context->port, aiadr, ECT_REG_EEPCTL, sizeof(estat), &estat, EC_TIMEOUTRET3);
1179  }
1180 
1181  do
1182  {
1183  ed.comm = htoes(EC_ECMD_READ);
1184  ed.addr = htoes(eeproma);
1185  ed.d2 = 0x0000;
1186  cnt = 0;
1187  do
1188  {
1189  wkc = ecx_APWR(context->port, aiadr, ECT_REG_EEPCTL, sizeof(ed), &ed, EC_TIMEOUTRET);
1190  }
1191  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1192  if (wkc)
1193  {
1195  estat = 0x0000;
1196  if (ecx_eeprom_waitnotbusyAP(context, aiadr, &estat, timeout))
1197  {
1198  if (estat & EC_ESTAT_NACK)
1199  {
1200  nackcnt++;
1202  }
1203  else
1204  {
1205  nackcnt = 0;
1206  if (estat & EC_ESTAT_R64)
1207  {
1208  cnt = 0;
1209  do
1210  {
1211  wkc = ecx_APRD(context->port, aiadr, ECT_REG_EEPDAT, sizeof(edat64), &edat64, EC_TIMEOUTRET);
1212  }
1213  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1214  }
1215  else
1216  {
1217  cnt = 0;
1218  do
1219  {
1220  wkc = ecx_APRD(context->port, aiadr, ECT_REG_EEPDAT, sizeof(edat32), &edat32, EC_TIMEOUTRET);
1221  }
1222  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1223  edat64=(uint64)edat32;
1224  }
1225  }
1226  }
1227  }
1228  }
1229  while ((nackcnt > 0) && (nackcnt < 3));
1230  }
1231 
1232  return edat64;
1233 }
1234 
1243 int ecx_writeeepromAP(ecx_contextt *context, uint16 aiadr, uint16 eeproma, uint16 data, int timeout)
1244 {
1245  uint16 estat;
1246  ec_eepromt ed;
1247  int wkc, rval = 0, cnt = 0, nackcnt = 0;
1248 
1249  if (ecx_eeprom_waitnotbusyAP(context, aiadr, &estat, timeout))
1250  {
1251  if (estat & EC_ESTAT_EMASK) /* error bits are set */
1252  {
1253  estat = htoes(EC_ECMD_NOP); /* clear error bits */
1254  wkc = ecx_APWR(context->port, aiadr, ECT_REG_EEPCTL, sizeof(estat), &estat, EC_TIMEOUTRET3);
1255  }
1256  do
1257  {
1258  cnt = 0;
1259  do
1260  {
1261  wkc = ecx_APWR(context->port, aiadr, ECT_REG_EEPDAT, sizeof(data), &data, EC_TIMEOUTRET);
1262  }
1263  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1264 
1265  ed.comm = EC_ECMD_WRITE;
1266  ed.addr = eeproma;
1267  ed.d2 = 0x0000;
1268  cnt = 0;
1269  do
1270  {
1271  wkc = ecx_APWR(context->port, aiadr, ECT_REG_EEPCTL, sizeof(ed), &ed, EC_TIMEOUTRET);
1272  }
1273  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1274  if (wkc)
1275  {
1277  estat = 0x0000;
1278  if (ecx_eeprom_waitnotbusyAP(context, aiadr, &estat, timeout))
1279  {
1280  if (estat & EC_ESTAT_NACK)
1281  {
1282  nackcnt++;
1284  }
1285  else
1286  {
1287  nackcnt = 0;
1288  rval = 1;
1289  }
1290  }
1291  }
1292 
1293  }
1294  while ((nackcnt > 0) && (nackcnt < 3));
1295  }
1296 
1297  return rval;
1298 }
1299 
1300 uint16 ecx_eeprom_waitnotbusyFP(ecx_contextt *context, uint16 configadr,uint16 *estat, int timeout)
1301 {
1302  int wkc, cnt = 0, retval = 0;
1303  osal_timert timer;
1304 
1305  osal_timer_start(&timer, timeout);
1306  do
1307  {
1308  if (cnt++)
1309  {
1311  }
1312  wkc=ecx_FPRD(context->port, configadr, ECT_REG_EEPSTAT, sizeof(*estat), estat, EC_TIMEOUTRET);
1313  *estat = etohs(*estat);
1314  }
1315  while (((wkc <= 0) || ((*estat & EC_ESTAT_BUSY) > 0)) && (osal_timer_is_expired(&timer) == FALSE)); /* wait for eeprom ready */
1316  if ((*estat & EC_ESTAT_BUSY) == 0)
1317  {
1318  retval = 1;
1319  }
1320 
1321  return retval;
1322 }
1323 
1331 uint64 ecx_readeepromFP(ecx_contextt *context, uint16 configadr, uint16 eeproma, int timeout)
1332 {
1333  uint16 estat;
1334  uint32 edat32;
1335  uint64 edat64;
1336  ec_eepromt ed;
1337  int wkc, cnt, nackcnt = 0;
1338 
1339  edat64 = 0;
1340  edat32 = 0;
1341  if (ecx_eeprom_waitnotbusyFP(context, configadr, &estat, timeout))
1342  {
1343  if (estat & EC_ESTAT_EMASK) /* error bits are set */
1344  {
1345  estat = htoes(EC_ECMD_NOP); /* clear error bits */
1346  wkc=ecx_FPWR(context->port, configadr, ECT_REG_EEPCTL, sizeof(estat), &estat, EC_TIMEOUTRET3);
1347  }
1348 
1349  do
1350  {
1351  ed.comm = htoes(EC_ECMD_READ);
1352  ed.addr = htoes(eeproma);
1353  ed.d2 = 0x0000;
1354  cnt = 0;
1355  do
1356  {
1357  wkc=ecx_FPWR(context->port, configadr, ECT_REG_EEPCTL, sizeof(ed), &ed, EC_TIMEOUTRET);
1358  }
1359  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1360  if (wkc)
1361  {
1363  estat = 0x0000;
1364  if (ecx_eeprom_waitnotbusyFP(context, configadr, &estat, timeout))
1365  {
1366  if (estat & EC_ESTAT_NACK)
1367  {
1368  nackcnt++;
1370  }
1371  else
1372  {
1373  nackcnt = 0;
1374  if (estat & EC_ESTAT_R64)
1375  {
1376  cnt = 0;
1377  do
1378  {
1379  wkc=ecx_FPRD(context->port, configadr, ECT_REG_EEPDAT, sizeof(edat64), &edat64, EC_TIMEOUTRET);
1380  }
1381  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1382  }
1383  else
1384  {
1385  cnt = 0;
1386  do
1387  {
1388  wkc=ecx_FPRD(context->port, configadr, ECT_REG_EEPDAT, sizeof(edat32), &edat32, EC_TIMEOUTRET);
1389  }
1390  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1391  edat64=(uint64)edat32;
1392  }
1393  }
1394  }
1395  }
1396  }
1397  while ((nackcnt > 0) && (nackcnt < 3));
1398  }
1399 
1400  return edat64;
1401 }
1402 
1411 int ecx_writeeepromFP(ecx_contextt *context, uint16 configadr, uint16 eeproma, uint16 data, int timeout)
1412 {
1413  uint16 estat;
1414  ec_eepromt ed;
1415  int wkc, rval = 0, cnt = 0, nackcnt = 0;
1416 
1417  if (ecx_eeprom_waitnotbusyFP(context, configadr, &estat, timeout))
1418  {
1419  if (estat & EC_ESTAT_EMASK) /* error bits are set */
1420  {
1421  estat = htoes(EC_ECMD_NOP); /* clear error bits */
1422  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPCTL, sizeof(estat), &estat, EC_TIMEOUTRET3);
1423  }
1424  do
1425  {
1426  cnt = 0;
1427  do
1428  {
1429  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPDAT, sizeof(data), &data, EC_TIMEOUTRET);
1430  }
1431  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1432  ed.comm = EC_ECMD_WRITE;
1433  ed.addr = eeproma;
1434  ed.d2 = 0x0000;
1435  cnt = 0;
1436  do
1437  {
1438  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPCTL, sizeof(ed), &ed, EC_TIMEOUTRET);
1439  }
1440  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1441  if (wkc)
1442  {
1444  estat = 0x0000;
1445  if (ecx_eeprom_waitnotbusyFP(context, configadr, &estat, timeout))
1446  {
1447  if (estat & EC_ESTAT_NACK)
1448  {
1449  nackcnt++;
1451  }
1452  else
1453  {
1454  nackcnt = 0;
1455  rval = 1;
1456  }
1457  }
1458  }
1459  }
1460  while ((nackcnt > 0) && (nackcnt < 3));
1461  }
1462 
1463  return rval;
1464 }
1465 
1473 {
1474  uint16 configadr, estat;
1475  ec_eepromt ed;
1476  int wkc, cnt = 0;
1477 
1478  ecx_eeprom2master(context, slave); /* set eeprom control to master */
1479  configadr = context->slavelist[slave].configadr;
1480  if (ecx_eeprom_waitnotbusyFP(context, configadr, &estat, EC_TIMEOUTEEP))
1481  {
1482  if (estat & EC_ESTAT_EMASK) /* error bits are set */
1483  {
1484  estat = htoes(EC_ECMD_NOP); /* clear error bits */
1485  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPCTL, sizeof(estat), &estat, EC_TIMEOUTRET3);
1486  }
1487  ed.comm = htoes(EC_ECMD_READ);
1488  ed.addr = htoes(eeproma);
1489  ed.d2 = 0x0000;
1490  do
1491  {
1492  wkc = ecx_FPWR(context->port, configadr, ECT_REG_EEPCTL, sizeof(ed), &ed, EC_TIMEOUTRET);
1493  }
1494  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1495  }
1496 }
1497 
1506 {
1507  uint16 estat, configadr;
1508  uint32 edat;
1509  int wkc, cnt = 0;
1510 
1511  configadr = context->slavelist[slave].configadr;
1512  edat = 0;
1513  estat = 0x0000;
1514  if (ecx_eeprom_waitnotbusyFP(context, configadr, &estat, timeout))
1515  {
1516  do
1517  {
1518  wkc = ecx_FPRD(context->port, configadr, ECT_REG_EEPDAT, sizeof(edat), &edat, EC_TIMEOUTRET);
1519  }
1520  while ((wkc <= 0) && (cnt++ < EC_DEFAULTRETRIES));
1521  }
1522 
1523  return edat;
1524 }
1525 
1532 static void ecx_pushindex(ecx_contextt *context, uint8 idx, void *data, uint16 length)
1533 {
1534  if(context->idxstack->pushed < EC_MAXBUF)
1535  {
1536  context->idxstack->idx[context->idxstack->pushed] = idx;
1537  context->idxstack->data[context->idxstack->pushed] = data;
1538  context->idxstack->length[context->idxstack->pushed] = length;
1539  context->idxstack->pushed++;
1540  }
1541 }
1542 
1547 static int ecx_pullindex(ecx_contextt *context)
1548 {
1549  int rval = -1;
1550  if(context->idxstack->pulled < context->idxstack->pushed)
1551  {
1552  rval = context->idxstack->pulled;
1553  context->idxstack->pulled++;
1554  }
1555 
1556  return rval;
1557 }
1558 
1572 {
1573  uint32 LogAdr;
1574  uint16 w1, w2;
1575  int length, sublength;
1576  uint8 idx;
1577  int wkc;
1578  uint8* data;
1579  boolean first=FALSE;
1580  uint16 currentsegment = 0;
1581 
1582  wkc = 0;
1583  if(context->grouplist[group].hasdc)
1584  {
1585  first = TRUE;
1586  }
1587  length = context->grouplist[group].Obytes + context->grouplist[group].Ibytes;
1588  LogAdr = context->grouplist[group].logstartaddr;
1589  if (length)
1590  {
1591  if(!group)
1592  {
1593  context->idxstack->pushed = 0;
1594  context->idxstack->pulled = 0;
1595  }
1596  wkc = 1;
1597  /* LRW blocked by one or more slaves ? */
1598  if (context->grouplist[group].blockLRW)
1599  {
1600  /* if inputs available generate LRD */
1601  if(context->grouplist[group].Ibytes)
1602  {
1603  currentsegment = context->grouplist[group].Isegment;
1604  data = context->grouplist[group].inputs;
1605  length = context->grouplist[group].Ibytes;
1606  LogAdr += context->grouplist[group].Obytes;
1607  /* segment transfer if needed */
1608  do
1609  {
1610  if(currentsegment == context->grouplist[group].Isegment)
1611  {
1612  sublength = context->grouplist[group].IOsegment[currentsegment++] - context->grouplist[group].Ioffset;
1613  }
1614  else
1615  {
1616  sublength = context->grouplist[group].IOsegment[currentsegment++];
1617  }
1618  /* get new index */
1619  idx = ecx_getindex(context->port);
1620  w1 = LO_WORD(LogAdr);
1621  w2 = HI_WORD(LogAdr);
1622  ecx_setupdatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_LRD, idx, w1, w2, sublength, data);
1623  if(first)
1624  {
1625  context->DCl = sublength;
1626  /* FPRMW in second datagram */
1627  context->DCtO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE,
1628  context->slavelist[context->grouplist[group].DCnext].configadr,
1629  ECT_REG_DCSYSTIME, sizeof(context->DCtime), context->DCtime);
1630  first = FALSE;
1631  }
1632  /* send frame */
1633  ecx_outframe_red(context->port, idx);
1634  /* push index and data pointer on stack */
1635  ecx_pushindex(context, idx, data, sublength);
1636  length -= sublength;
1637  LogAdr += sublength;
1638  data += sublength;
1639  } while (length && (currentsegment < context->grouplist[group].nsegments));
1640  }
1641  /* if outputs available generate LWR */
1642  if(context->grouplist[group].Obytes)
1643  {
1644  data = context->grouplist[group].outputs;
1645  length = context->grouplist[group].Obytes;
1646  LogAdr = context->grouplist[group].logstartaddr;
1647  currentsegment = 0;
1648  /* segment transfer if needed */
1649  do
1650  {
1651  sublength = context->grouplist[group].IOsegment[currentsegment++];
1652  if((length - sublength) < 0)
1653  {
1654  sublength = length;
1655  }
1656  /* get new index */
1657  idx = ecx_getindex(context->port);
1658  w1 = LO_WORD(LogAdr);
1659  w2 = HI_WORD(LogAdr);
1660  ecx_setupdatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_LWR, idx, w1, w2, sublength, data);
1661  if(first)
1662  {
1663  context->DCl = sublength;
1664  /* FPRMW in second datagram */
1665  context->DCtO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE,
1666  context->slavelist[context->grouplist[group].DCnext].configadr,
1667  ECT_REG_DCSYSTIME, sizeof(context->DCtime), context->DCtime);
1668  first = FALSE;
1669  }
1670  /* send frame */
1671  ecx_outframe_red(context->port, idx);
1672  /* push index and data pointer on stack */
1673  ecx_pushindex(context, idx, data, sublength);
1674  length -= sublength;
1675  LogAdr += sublength;
1676  data += sublength;
1677  } while (length && (currentsegment < context->grouplist[group].nsegments));
1678  }
1679  }
1680  /* LRW can be used */
1681  else
1682  {
1683  if (context->grouplist[group].Obytes)
1684  {
1685  data = context->grouplist[group].outputs;
1686  }
1687  else
1688  {
1689  data = context->grouplist[group].inputs;
1690  }
1691  /* segment transfer if needed */
1692  do
1693  {
1694  sublength = context->grouplist[group].IOsegment[currentsegment++];
1695  /* get new index */
1696  idx = ecx_getindex(context->port);
1697  w1 = LO_WORD(LogAdr);
1698  w2 = HI_WORD(LogAdr);
1699  ecx_setupdatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_LRW, idx, w1, w2, sublength, data);
1700  if(first)
1701  {
1702  context->DCl = sublength;
1703  /* FPRMW in second datagram */
1704  context->DCtO = ecx_adddatagram(context->port, &(context->port->txbuf[idx]), EC_CMD_FRMW, idx, FALSE,
1705  context->slavelist[context->grouplist[group].DCnext].configadr,
1706  ECT_REG_DCSYSTIME, sizeof(context->DCtime), context->DCtime);
1707  first = FALSE;
1708  }
1709  /* send frame */
1710  ecx_outframe_red(context->port, idx);
1711  /* push index and data pointer on stack */
1712  ecx_pushindex(context, idx, data, sublength);
1713  length -= sublength;
1714  LogAdr += sublength;
1715  data += sublength;
1716  } while (length && (currentsegment < context->grouplist[group].nsegments));
1717  }
1718  }
1719 
1720  return wkc;
1721 }
1722 
1732 int ecx_receive_processdata_group(ecx_contextt *context, uint8 group, int timeout)
1733 {
1734  int pos, idx;
1735  int wkc = 0, wkc2;
1736  uint16 le_wkc = 0;
1737  int64 le_DCtime;
1738  boolean first = FALSE;
1739 
1740  if(context->grouplist[group].hasdc)
1741  {
1742  first = TRUE;
1743  }
1744  /* get first index */
1745  pos = ecx_pullindex(context);
1746  /* read the same number of frames as send */
1747  while (pos >= 0)
1748  {
1749  idx = context->idxstack->idx[pos];
1750  wkc2 = ecx_waitinframe(context->port, context->idxstack->idx[pos], timeout);
1751  /* check if there is input data in frame */
1752  if (wkc2 > EC_NOFRAME)
1753  {
1754  if((context->port->rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LRD) || (context->port->rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LRW))
1755  {
1756  if(first)
1757  {
1758  memcpy(context->idxstack->data[pos], &(context->port->rxbuf[idx][EC_HEADERSIZE]), context->DCl);
1759  memcpy(&le_wkc, &(context->port->rxbuf[idx][EC_HEADERSIZE + context->DCl]), EC_WKCSIZE);
1760  wkc = etohs(le_wkc);
1761  memcpy(&le_DCtime, &(context->port->rxbuf[idx][context->DCtO]), sizeof(le_DCtime));
1762  *(context->DCtime) = etohll(le_DCtime);
1763  first = FALSE;
1764  }
1765  else
1766  {
1767  /* copy input data back to process data buffer */
1768  memcpy(context->idxstack->data[pos], &(context->port->rxbuf[idx][EC_HEADERSIZE]), context->idxstack->length[pos]);
1769  wkc += wkc2;
1770  }
1771  }
1772  else if(context->port->rxbuf[idx][EC_CMDOFFSET]==EC_CMD_LWR)
1773  {
1774  if(first)
1775  {
1776  memcpy(&le_wkc, &(context->port->rxbuf[idx][EC_HEADERSIZE + context->DCl]), EC_WKCSIZE);
1777  /* output WKC counts 2 times when using LRW, emulate the same for LWR */
1778  wkc = etohs(le_wkc) * 2;
1779  memcpy(&le_DCtime, &(context->port->rxbuf[idx][context->DCtO]), sizeof(le_DCtime));
1780  *(context->DCtime) = etohll(le_DCtime);
1781  first = FALSE;
1782  }
1783  else
1784  {
1785  /* output WKC counts 2 times when using LRW, emulate the same for LWR */
1786  wkc += wkc2 * 2;
1787  }
1788  }
1789  }
1790  /* release buffer */
1791  ecx_setbufstat(context->port, idx, EC_BUF_EMPTY);
1792  /* get next index */
1793  pos = ecx_pullindex(context);
1794  }
1795 
1796  return wkc;
1797 }
1798 
1799 
1801 {
1802  return ecx_send_processdata_group(context, 0);
1803 }
1804 
1805 int ecx_receive_processdata(ecx_contextt *context, int timeout)
1806 {
1807  return ecx_receive_processdata_group(context, 0, timeout);
1808 }
1809 
1810 #ifdef EC_VER1
1811 void ec_pusherror(const ec_errort *Ec)
1812 {
1813  ecx_pusherror(&ecx_context, Ec);
1814 }
1815 
1817 {
1818  return ecx_poperror(&ecx_context, Ec);
1819 }
1820 
1821 boolean ec_iserror(void)
1822 {
1823  return ecx_iserror(&ecx_context);
1824 }
1825 
1827 {
1828  ecx_packeterror(&ecx_context, Slave, Index, SubIdx, ErrorCode);
1829 }
1830 
1831 static void ec_mbxerror(uint16 Slave,uint16 Detail)
1832 {
1833  ecx_mbxerror (&ecx_context, Slave, Detail);
1834 }
1835 
1837  uint8 b1, uint16 w1, uint16 w2)
1838 {
1839  ecx_mbxemergencyerror (&ecx_context, Slave, ErrorCode, ErrorReg, b1, w1, w2);
1840 }
1841 
1842 int ec_init(char * ifname)
1843 {
1844  return ecx_init(&ecx_context, ifname);
1845 }
1846 
1847 int ec_init_redundant(char *ifname, char *if2name)
1848 {
1849  return ecx_init_redundant (&ecx_context, &ecx_redport, ifname, if2name);
1850 }
1851 
1852 void ec_close(void)
1853 {
1854  ecx_close(&ecx_context);
1855 };
1856 
1858 {
1859  return ecx_siigetbyte (&ecx_context, slave, address);
1860 }
1861 
1863 {
1864  return ecx_siifind (&ecx_context, slave, cat);
1865 }
1866 
1867 void ec_siistring(char *str, uint16 slave, uint16 Sn)
1868 {
1869  ecx_siistring(&ecx_context, str, slave, Sn);
1870 }
1871 
1873 {
1874  return ecx_siiFMMU (&ecx_context, slave, FMMU);
1875 }
1876 
1878 {
1879  return ecx_siiSM (&ecx_context, slave, SM);
1880 }
1881 
1883 {
1884  return ecx_siiSMnext (&ecx_context, slave, SM, n);
1885 }
1886 
1888 {
1889  return ecx_siiPDO (&ecx_context, slave, PDO, t);
1890 }
1891 
1892 int ec_readstate(void)
1893 {
1894  return ecx_readstate (&ecx_context);
1895 }
1896 
1898 {
1899  return ecx_writestate(&ecx_context, slave);
1900 }
1901 
1902 uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)
1903 {
1904  return ecx_statecheck (&ecx_context, slave, reqstate, timeout);
1905 }
1906 
1907 int ec_mbxempty(uint16 slave, int timeout)
1908 {
1909  return ecx_mbxempty (&ecx_context, slave, timeout);
1910 }
1911 
1912 int ec_mbxsend(uint16 slave,ec_mbxbuft *mbx, int timeout)
1913 {
1914  return ecx_mbxsend (&ecx_context, slave, mbx, timeout);
1915 }
1916 
1917 int ec_mbxreceive(uint16 slave, ec_mbxbuft *mbx, int timeout)
1918 {
1919  return ecx_mbxreceive (&ecx_context, slave, mbx, timeout);
1920 }
1921 
1923 {
1924  ecx_esidump (&ecx_context, slave, esibuf);
1925 }
1926 
1927 uint32 ec_readeeprom(uint16 slave, uint16 eeproma, int timeout)
1928 {
1929  return ecx_readeeprom (&ecx_context, slave, eeproma, timeout);
1930 }
1931 
1932 int ec_writeeeprom(uint16 slave, uint16 eeproma, uint16 data, int timeout)
1933 {
1934  return ecx_writeeeprom (&ecx_context, slave, eeproma, data, timeout);
1935 }
1936 
1938 {
1939  return ecx_eeprom2master(&ecx_context, slave);
1940 }
1941 
1943 {
1944  return ecx_eeprom2pdi(&ecx_context, slave);
1945 }
1946 
1947 uint16 ec_eeprom_waitnotbusyAP(uint16 aiadr,uint16 *estat, int timeout)
1948 {
1949  return ecx_eeprom_waitnotbusyAP (&ecx_context, aiadr, estat, timeout);
1950 }
1951 
1952 uint64 ec_readeepromAP(uint16 aiadr, uint16 eeproma, int timeout)
1953 {
1954  return ecx_readeepromAP (&ecx_context, aiadr, eeproma, timeout);
1955 }
1956 
1957 int ec_writeeepromAP(uint16 aiadr, uint16 eeproma, uint16 data, int timeout)
1958 {
1959  return ecx_writeeepromAP (&ecx_context, aiadr, eeproma, data, timeout);
1960 }
1961 
1962 uint16 ec_eeprom_waitnotbusyFP(uint16 configadr,uint16 *estat, int timeout)
1963 {
1964  return ecx_eeprom_waitnotbusyFP (&ecx_context, configadr, estat, timeout);
1965 }
1966 
1967 uint64 ec_readeepromFP(uint16 configadr, uint16 eeproma, int timeout)
1968 {
1969  return ecx_readeepromFP (&ecx_context, configadr, eeproma, timeout);
1970 }
1971 
1972 int ec_writeeepromFP(uint16 configadr, uint16 eeproma, uint16 data, int timeout)
1973 {
1974  return ecx_writeeepromFP (&ecx_context, configadr, eeproma, data, timeout);
1975 }
1976 
1978 {
1979  ecx_readeeprom1 (&ecx_context, slave, eeproma);
1980 }
1981 
1983 {
1984  return ecx_readeeprom2 (&ecx_context, slave, timeout);
1985 }
1986 
1988 {
1989  return ecx_send_processdata_group (&ecx_context, group);
1990 }
1991 
1992 int ec_receive_processdata_group(uint8 group, int timeout)
1993 {
1994  return ecx_receive_processdata_group (&ecx_context, group, timeout);
1995 }
1996 
1998 {
1999  return ec_send_processdata_group(0);
2000 }
2001 
2002 int ec_receive_processdata(int timeout)
2003 {
2004  return ec_receive_processdata_group(0, timeout);
2005 }
2006 #endif
int ecx_send_processdata(ecx_contextt *context)
uint16 ErrorCode
Definition: ethercatmain.c:91
int ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data)
Definition: ethercatbase.c:113
ec_groupt ec_group[EC_MAXGROUP]
Definition: ethercatmain.c:108
uint16 mbx_rl
Definition: ethercatmain.h:192
int ecx_getindex(ecx_portt *port)
Definition: linux/nicdrv.c:239
int ecx_mbxempty(ecx_contextt *context, uint16 slave, int timeout)
Definition: ethercatmain.c:843
#define EC_MAXMBX
Definition: ethercatmain.h:66
uint16 BitSize[EC_MAXEEPDO]
Definition: ethercatmain.h:336
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
Definition: linux/osal.c:63
#define EC_ESTAT_NACK
Definition: ethercattype.h:299
uint8 eep_pdi
Definition: ethercatmain.h:242
uint16 Ioffset
Definition: ethercatmain.h:293
uint8 ErrorReg
Definition: ethercatmain.c:92
int ec_writeeepromAP(uint16 aiadr, uint16 eeproma, uint16 data, int timeout)
ec_bufT txbuf[EC_MAXBUF]
Definition: linux/nicdrv.h:106
uint64 ec_readeepromFP(uint16 configadr, uint16 eeproma, int timeout)
uint16 ec_eeprom_waitnotbusyFP(uint16 configadr, uint16 *estat, int timeout)
uint16 Plength
Definition: ethercatmain.h:321
ec_slavet * slavelist
Definition: ethercatmain.h:418
int ec_readstate(void)
uint8 ecx_siigetbyte(ecx_contextt *context, uint16 slave, uint16 address)
Definition: ethercatmain.c:365
uint8 ec_siigetbyte(uint16 slave, uint16 address)
int ec_send_processdata(void)
#define EC_MAXGROUP
Definition: ethercatmain.h:62
void ec_free_adapters(ec_adaptert *adapter)
Definition: ethercatmain.c:178
boolean ec_poperror(ec_errort *Ec)
static ec_PDOdesct ec_PDOdesc
Definition: ethercatmain.c:123
uint16 comm
Definition: ethercatmain.c:69
PACKED_END ec_slavet ec_slave[EC_MAXSLAVE]
Definition: ethercatmain.c:104
uint16 d2
Definition: ethercatmain.c:71
int ecx_init(ecx_contextt *context, char *ifname)
Definition: ethercatmain.c:319
int16 head
Definition: ethercatmain.h:377
void ecx_close(ecx_contextt *context)
Definition: ethercatmain.c:352
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
Definition: linux/nicdrv.c:116
ec_groupt * grouplist
Definition: ethercatmain.h:424
#define EC_MAXBUF
Definition: ethercattype.h:88
uint8_t uint8
Definition: osal.h:33
uint16 ecx_statecheck(ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout)
Definition: ethercatmain.c:773
void ecx_pusherror(ecx_contextt *context, const ec_errort *Ec)
Definition: ethercatmain.c:188
uint16 mbx_l
Definition: ethercatmain.h:188
int ec_init_redundant(char *ifname, char *if2name)
ec_bufT txbuf2
Definition: linux/nicdrv.h:110
#define EC_MAXEEPBUF
Definition: ethercattype.h:106
int ec_receive_processdata(int timeout)
int ecx_FPWRw(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 data, int timeout)
Definition: ethercatbase.c:431
ec_adaptert * oshw_find_adapters(void)
Definition: linux/oshw.c:57
uint32 Obytes
Definition: ethercatmain.h:273
PACKED_BEGIN struct PACKED ec_etherheadert
uint16 Startpos
Definition: ethercatmain.h:318
uint8 SubIdx
Definition: ethercattype.h:503
uint16 w2
Definition: ethercattype.h:517
static void ec_mbxemergencyerror(uint16 Slave, uint16 ErrorCode, uint16 ErrorReg, uint8 b1, uint16 w1, uint16 w2)
void ecx_siistring(ecx_contextt *context, char *str, uint16 slave, uint16 Sn)
Definition: ethercatmain.c:474
int ecx_FPWR(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
Definition: ethercatbase.c:409
uint8 idx[EC_MAXBUF]
Definition: ethercatmain.h:369
void oshw_free_adapters(ec_adaptert *adapter)
Definition: linux/oshw.c:121
int txbuflength2
Definition: linux/nicdrv.h:112
uint16_t uint16
Definition: osal.h:34
uint16 DCnext
Definition: ethercatmain.h:283
#define EC_MAXEEPBITMAP
Definition: ethercattype.h:104
int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data)
Definition: ethercatbase.c:72
PACKED_BEGIN struct PACKED ec_eepromt
void ecx_packeterror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode)
Definition: ethercatmain.c:253
static ec_SMcommtypet ec_SMcommtype
Definition: ethercatmain.c:119
int64 ec_DCtime
Definition: ethercatmain.c:132
boolean ec_iserror(void)
uint16 SyncM[EC_MAXEEPDO]
Definition: ethercatmain.h:335
uint32 PDO[256]
Definition: ethercatmain.h:408
int ecx_eeprom2master(ecx_contextt *context, uint16 slave)
int ecx_APWR(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
Definition: ethercatbase.c:372
General typedefs and defines for EtherCAT.
ec_timet osal_current_time(void)
Definition: linux/osal.c:52
#define EC_MAXEEPDO
Definition: ethercatmain.h:68
#define etohs(A)
Definition: ethercattype.h:550
uint32 ec_readeeprom(uint16 slave, uint16 eeproma, int timeout)
uint16 ecx_siiFMMU(ecx_contextt *context, uint16 slave, ec_eepromFMMUt *FMMU)
Definition: ethercatmain.c:532
#define TRUE
Definition: osal.h:28
uint32 ecx_readeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, int timeout)
void ec_siistring(char *str, uint16 slave, uint16 Sn)
static void ec_mbxerror(uint16 Slave, uint16 Detail)
#define ETH_HEADERSIZE
Definition: ethercattype.h:127
int ecx_FPRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
Definition: ethercatbase.c:328
ec_err_type Etype
Definition: ethercattype.h:505
void ecx_esidump(ecx_contextt *context, uint16 slave, uint8 *esibuf)
void ec_clearmbx(ec_mbxbuft *Mbx)
Definition: ethercatmain.c:832
static ec_PDOassignt ec_PDOassign
Definition: ethercatmain.c:121
static ec_eepromFMMUt ec_FMMU
Definition: ethercatmain.c:128
uint16 ec_siiFMMU(uint16 slave, ec_eepromFMMUt *FMMU)
static void ecx_mbxerror(ecx_contextt *context, uint16 Slave, uint16 Detail)
Definition: ethercatmain.c:273
#define HI_BYTE(w)
Definition: ethercattype.h:526
#define EC_ESTAT_BUSY
Definition: ethercattype.h:295
ecx_portt ecx_port
Definition: ethercatmain.c:134
#define EC_MAXSM
Definition: ethercatmain.h:70
uint16 ecx_siiSMnext(ecx_contextt *context, uint16 slave, ec_eepromSMt *SM, uint16 n)
Definition: ethercatmain.c:609
boolean * ecaterror
Definition: ethercatmain.h:438
ec_bufT rxbuf[EC_MAXBUF]
Definition: linux/nicdrv.h:96
int ec_eeprom2pdi(uint16 slave)
int ecx_writeeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, uint16 data, int timeout)
int ecx_mbxsend(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
Definition: ethercatmain.c:878
uint16 ALstatuscode
Definition: ethercatmain.h:142
PACKED_END PACKED_BEGIN struct PACKED ec_PDOassignt
PACKED_END PACKED_BEGIN struct PACKED ec_mbxerrort
static void ecx_mbxemergencyerror(ecx_contextt *context, uint16 Slave, uint16 ErrorCode, uint16 ErrorReg, uint8 b1, uint16 w1, uint16 w2)
Definition: ethercatmain.c:296
PACKED_BEGIN struct PACKED ec_mbxheadert
int ecx_BRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
Definition: ethercatbase.c:195
uint32 IOsegment[EC_MAXIOSEGMENTS]
Definition: ethercatmain.h:301
int ecx_writeeepromAP(ecx_contextt *context, uint16 aiadr, uint16 eeproma, uint16 data, int timeout)
#define put_unaligned32(val, ptr)
Definition: ethercattype.h:539
uint8 n
Definition: ethercatmain.h:386
uint16 mbx_ro
Definition: ethercatmain.h:194
static uint8 esibuf[EC_MAXEEPBUF]
Definition: ethercatmain.c:111
int ec_init(char *ifname)
uint32 ecx_readeeprom2(ecx_contextt *context, uint16 slave, int timeout)
#define EC_HEADERSIZE
Definition: ethercattype.h:151
uint16 SMbitsize[EC_MAXSM]
Definition: ethercatmain.h:337
void ec_pusherror(const ec_errort *Ec)
boolean hasdc
Definition: ethercatmain.h:281
int ec_eeprom2master(uint16 slave)
int ecx_writeeepromFP(ecx_contextt *context, uint16 configadr, uint16 eeproma, uint16 data, int timeout)
uint16 Slave
Definition: ethercattype.h:499
uint64 ecx_readeepromAP(ecx_contextt *context, uint16 aiadr, uint16 eeproma, int timeout)
ec_mbxheadert MbxHeader
Definition: ethercatcoe.c:61
uint16 Index
Definition: ethercatcoe.c:64
int ec_siiPDO(uint16 slave, ec_eepromPDOt *PDO, uint8 t)
int ecx_writestate(ecx_contextt *context, uint16 slave)
Definition: ethercatmain.c:747
PACKED_END PACKED_BEGIN struct PACKED ec_emcyt
void ec_packeterror(uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode)
int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
Definition: ethercatmain.c:911
void ec_readeeprom1(uint16 slave, uint16 eeproma)
const uint16 secMAC[3]
Definition: linux/nicdrv.c:103
int slave
Definition: aliastool.c:51
int ecx_receive_processdata_group(ecx_contextt *context, uint8 group, int timeout)
int64_t int64
Definition: osal.h:36
#define FALSE
Definition: osal.h:29
ec_errort Error[EC_MAXELIST+1]
Definition: ethercatmain.h:379
uint16 CANOpen
Definition: ethercatcoe.c:62
uint16 Isegment
Definition: ethercatmain.h:291
ecx_portt * port
Definition: ethercatmain.h:416
ecx_redportt * redport
Definition: linux/nicdrv.h:118
int ecx_waitinframe(ecx_portt *port, int idx, int timeout)
Definition: linux/nicdrv.c:564
uint16 ec_siiSM(uint16 slave, ec_eepromSMt *SM)
int ec_mbxsend(uint16 slave, ec_mbxbuft *mbx, int timeout)
uint32 ec_readeeprom2(uint16 slave, int timeout)
int64 * DCtime
Definition: ethercatmain.h:444
int ecx_BWR(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
Definition: ethercatbase.c:168
ec_idxstackT * idxstack
Definition: ethercatmain.h:436
#define ECT_SII_START
Definition: ethercattype.h:304
int16 ec_siifind(uint16 slave, uint16 cat)
#define EC_TIMEOUTEEP
Definition: ethercattype.h:96
#define EC_CMDOFFSET
Definition: ethercattype.h:155
int ecx_APRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
Definition: ethercatbase.c:227
boolean EcatError
Definition: ethercatmain.c:130
#define EC_MAXELIST
Definition: ethercatmain.h:56
boolean Signal
Definition: ethercattype.h:497
PACKED_END PACKED_BEGIN struct PACKED ec_PDOdesct
uint64_t uint64
Definition: osal.h:37
static uint32 esimap[EC_MAXEEPBITMAP]
Definition: ethercatmain.c:113
int ecx_send_processdata_group(ecx_contextt *context, uint8 group)
int ec_mbxempty(uint16 slave, int timeout)
#define HI_WORD(l)
Definition: ethercattype.h:534
int ec_send_processdata_group(uint8 group)
uint8 eep_8byte
Definition: ethercatmain.h:240
static ec_eepromSMt ec_SM
Definition: ethercatmain.c:126
uint16 oshw_htons(uint16 host)
Definition: linux/oshw.c:36
void ecx_readeeprom1(ecx_contextt *context, uint16 slave, uint16 eeproma)
uint16 esislave
Definition: ethercatmain.h:432
ec_eringt * elist
Definition: ethercatmain.h:434
uint64 ecx_readeepromFP(ecx_contextt *context, uint16 configadr, uint16 eeproma, int timeout)
int ecx_init_redundant(ecx_contextt *context, ecx_redportt *redport, char *ifname, char *if2name)
Definition: ethercatmain.c:331
#define EC_TIMEOUTRET
Definition: ethercattype.h:90
#define LO_WORD(l)
Definition: ethercattype.h:532
uint16 length[EC_MAXBUF]
Definition: ethercatmain.h:371
ecx_redportt ecx_redport
Definition: ethercatmain.c:135
static ec_idxstackT ec_idxstack
Definition: ethercatmain.c:116
int ec_writestate(uint16 slave)
ec_timet Time
Definition: ethercattype.h:495
boolean ecx_iserror(ecx_contextt *context)
Definition: ethercatmain.c:240
uint16 ErrorCode
Definition: ethercattype.h:513
int ec_writeeeprom(uint16 slave, uint16 eeproma, uint16 data, int timeout)
Headerfile for ethercatbase.c.
int wkc
Definition: aliastool.c:54
#define EC_MAXSLAVE
Definition: ethercatmain.h:60
uint16 length
Definition: ethercatmain.h:347
#define htoes(A)
Definition: ethercattype.h:547
#define EC_MAXNAME
Definition: ethercatmain.h:58
#define EC_DEFAULTRETRIES
Definition: ethercattype.h:108
int ecx_siiPDO(ecx_contextt *context, uint16 slave, ec_eepromPDOt *PDO, uint8 t)
Definition: ethercatmain.c:643
int ecx_eeprom2pdi(ecx_contextt *context, uint16 slave)
uint16 Index
Definition: ethercattype.h:501
uint32 logstartaddr
Definition: ethercatmain.h:271
uint64 ec_readeepromAP(uint16 aiadr, uint16 eeproma, int timeout)
uint32 ErrorCode
Definition: ethercatfoe.c:74
ecx_contextt ecx_context
Definition: ethercatmain.c:137
#define etohll(A)
Definition: ethercattype.h:552
uint16 mbx_wo
Definition: ethercatmain.h:190
Headerfile for ethercatmain.c.
int ecx_closenic(ecx_portt *port)
Definition: linux/nicdrv.c:207
int ec_receive_processdata_group(uint8 group, int timeout)
boolean ecx_poperror(ecx_contextt *context, ec_errort *Ec)
Definition: ethercatmain.c:214
uint8 blockLRW
Definition: ethercatmain.h:287
uint16 Detail
Definition: ethercatmain.c:81
uint16 w2
Definition: ethercatmain.c:94
#define EC_LOCALDELAY
Definition: ethercatmain.c:63
uint16 ec_eeprom_waitnotbusyAP(uint16 aiadr, uint16 *estat, int timeout)
uint16 ec_siiSMnext(uint16 slave, ec_eepromSMt *SM, uint16 n)
static int ecx_pullindex(ecx_contextt *context)
int16 tail
Definition: ethercatmain.h:378
uint32_t uint32
Definition: osal.h:35
void ec_esidump(uint16 slave, uint8 *esibuf)
#define EC_TIMEOUTRET3
Definition: ethercattype.h:92
uint16 addr
Definition: ethercatmain.c:70
uint16 address
Definition: ethercatmain.h:348
int ecx_readstate(ecx_contextt *context)
Definition: ethercatmain.c:714
int ecx_outframe_red(ecx_portt *port, int idx)
Definition: linux/nicdrv.c:316
ec_adaptert * ec_find_adapters(void)
Definition: ethercatmain.c:165
uint32 * esimap
Definition: ethercatmain.h:430
int ec_writeeepromFP(uint16 configadr, uint16 eeproma, uint16 data, int timeout)
uint32 Ibytes
Definition: ethercatmain.h:277
int16_t int16
Definition: osal.h:31
int16 ecx_siifind(ecx_contextt *context, uint16 slave, uint16 cat)
Definition: ethercatmain.c:434
uint16 state
Definition: ethercatmain.h:140
uint16 Type
Definition: ethercatmain.c:80
static void ecx_pushindex(ecx_contextt *context, uint8 idx, void *data, uint16 length)
uint8 * inputs
Definition: ethercatmain.h:279
int osal_usleep(uint32 usec)
Definition: linux/osal.c:28
boolean osal_timer_is_expired(const osal_timert *self)
Definition: linux/osal.c:78
#define EC_NOFRAME
Definition: ethercattype.h:73
void ec_close(void)
int ecx_receive_processdata(ecx_contextt *context, int timeout)
uint16 ecx_siiSM(ecx_contextt *context, uint16 slave, ec_eepromSMt *SM)
Definition: ethercatmain.c:572
uint16 PhStart
Definition: ethercatmain.h:320
uint16 w1
Definition: ethercattype.h:516
uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)
uint8 bData
Definition: ethercatmain.c:93
int ec_slavecount
Definition: ethercatmain.c:106
uint16 Index[EC_MAXEEPDO]
Definition: ethercatmain.h:334
PACKED_END PACKED_BEGIN struct PACKED ec_alstatust
uint16 ecx_eeprom_waitnotbusyFP(ecx_contextt *context, uint16 configadr, uint16 *estat, int timeout)
uint8 * outputs
Definition: ethercatmain.h:275
static ec_eringt ec_elist
Definition: ethercatmain.c:115
uint16 configadr
Definition: ethercatmain.h:144
int ec_mbxreceive(uint16 slave, ec_mbxbuft *mbx, int timeout)
void ecx_setbufstat(ecx_portt *port, int idx, int bufstat)
Definition: linux/nicdrv.c:278
#define EC_ESTAT_EMASK
Definition: ethercattype.h:297
void * data[EC_MAXBUF]
Definition: ethercatmain.h:370
#define EC_ESTAT_R64
Definition: ethercattype.h:293
uint8 ErrorReg
Definition: ethercattype.h:514
#define EC_WKCSIZE
Definition: ethercattype.h:157
uint8 * esibuf
Definition: ethercatmain.h:428
PACKED_BEGIN struct PACKED ec_SMcommtypet
uint16 w1
Definition: ethercatmain.c:94
uint8 ec_mbxbuft[EC_MAXMBX+1]
Definition: ethercatmain.h:341
int * slavecount
Definition: ethercatmain.h:420
uint8 ec_nextmbxcnt(uint8 cnt)
Definition: ethercatmain.c:818
#define put_unaligned64(val, ptr)
Definition: ethercattype.h:542
uint16 ecx_eeprom_waitnotbusyAP(ecx_contextt *context, uint16 aiadr, uint16 *estat, int timeout)


soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Sat Jun 8 2019 18:02:17