ethercatcoe.c
Go to the documentation of this file.
1 /*
2  * Licensed under the GNU General Public License version 2 with exceptions. See
3  * LICENSE file in the project root for full license information
4  */
5 
13 #include <stdio.h>
14 #include <string.h>
15 #include "osal.h"
16 #include "oshw.h"
17 #include "ethercattype.h"
18 #include "ethercatbase.h"
19 #include "ethercatmain.h"
20 #include "ethercatcoe.h"
21 
24 typedef struct PACKED
25 {
31  union
32  {
33  uint8 bdata[0x200]; /* variants for easy data access */
34  uint16 wdata[0x100];
35  uint32 ldata[0x80];
36  };
37 } ec_SDOt;
39 
42 typedef struct PACKED
43 {
49  union
50  {
51  uint8 bdata[0x200]; /* variants for easy data access */
52  uint16 wdata[0x100];
53  uint32 ldata[0x80];
54  };
57 
66 void ecx_SDOerror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode)
67 {
68  ec_errort Ec;
69 
70  memset(&Ec, 0, sizeof(Ec));
71  Ec.Time = osal_current_time();
72  Ec.Slave = Slave;
73  Ec.Index = Index;
74  Ec.SubIdx = SubIdx;
75  *(context->ecaterror) = TRUE;
77  Ec.AbortCode = AbortCode;
78  ecx_pusherror(context, &Ec);
79 }
80 
89 static void ecx_SDOinfoerror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode)
90 {
91  ec_errort Ec;
92 
93  memset(&Ec, 0, sizeof(Ec));
94  Ec.Slave = Slave;
95  Ec.Index = Index;
96  Ec.SubIdx = SubIdx;
97  *(context->ecaterror) = TRUE;
99  Ec.AbortCode = AbortCode;
100  ecx_pusherror(context, &Ec);
101 }
102 
121  boolean CA, int *psize, void *p, int timeout)
122 {
123  ec_SDOt *SDOp, *aSDOp;
124  uint16 bytesize, Framedatasize;
125  int wkc;
126  int32 SDOlen;
127  uint8 *bp;
128  uint8 *hp;
129  ec_mbxbuft MbxIn, MbxOut;
130  uint8 cnt, toggle;
131  boolean NotLast;
132 
133  ec_clearmbx(&MbxIn);
134  /* Empty slave out mailbox if something is in. Timeout set to 0 */
135  wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, 0);
136  ec_clearmbx(&MbxOut);
137  aSDOp = (ec_SDOt *)&MbxIn;
138  SDOp = (ec_SDOt *)&MbxOut;
139  SDOp->MbxHeader.length = htoes(0x000a);
140  SDOp->MbxHeader.address = htoes(0x0000);
141  SDOp->MbxHeader.priority = 0x00;
142  /* get new mailbox count value, used as session handle */
143  cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt);
144  context->slavelist[slave].mbx_cnt = cnt;
145  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
146  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits (SDO request) */
147  if (CA)
148  {
149  SDOp->Command = ECT_SDO_UP_REQ_CA; /* upload request complete access */
150  }
151  else
152  {
153  SDOp->Command = ECT_SDO_UP_REQ; /* upload request normal */
154  }
155  SDOp->Index = htoes(index);
156  if (CA && (subindex > 1))
157  {
158  subindex = 1;
159  }
160  SDOp->SubIndex = subindex;
161  SDOp->ldata[0] = 0;
162  /* send CoE request to slave */
163  wkc = ecx_mbxsend(context, slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
164  if (wkc > 0) /* succeeded to place mailbox in slave ? */
165  {
166  /* clean mailboxbuffer */
167  ec_clearmbx(&MbxIn);
168  /* read slave response */
169  wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, timeout);
170  if (wkc > 0) /* succeeded to read slave response ? */
171  {
172  /* slave response should be CoE, SDO response and the correct index */
173  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
174  ((etohs(aSDOp->CANOpen) >> 12) == ECT_COES_SDORES) &&
175  (aSDOp->Index == SDOp->Index))
176  {
177  if ((aSDOp->Command & 0x02) > 0)
178  {
179  /* expedited frame response */
180  bytesize = 4 - ((aSDOp->Command >> 2) & 0x03);
181  if (*psize >= bytesize) /* parameter buffer big enough ? */
182  {
183  /* copy parameter in parameter buffer */
184  memcpy(p, &aSDOp->ldata[0], bytesize);
185  /* return the real parameter size */
186  *psize = bytesize;
187  }
188  else
189  {
190  wkc = 0;
191  ecx_packeterror(context, slave, index, subindex, 3); /* data container too small for type */
192  }
193  }
194  else
195  { /* normal frame response */
196  SDOlen = etohl(aSDOp->ldata[0]);
197  /* Does parameter fit in parameter buffer ? */
198  if (SDOlen <= *psize)
199  {
200  bp = p;
201  hp = p;
202  /* calculate mailbox transfer size */
203  Framedatasize = (etohs(aSDOp->MbxHeader.length) - 10);
204  if (Framedatasize < SDOlen) /* transfer in segments? */
205  {
206  /* copy parameter data in parameter buffer */
207  memcpy(hp, &aSDOp->ldata[1], Framedatasize);
208  /* increment buffer pointer */
209  hp += Framedatasize;
210  *psize = Framedatasize;
211  NotLast = TRUE;
212  toggle= 0x00;
213  while (NotLast) /* segmented transfer */
214  {
215  SDOp = (ec_SDOt *)&MbxOut;
216  SDOp->MbxHeader.length = htoes(0x000a);
217  SDOp->MbxHeader.address = htoes(0x0000);
218  SDOp->MbxHeader.priority = 0x00;
219  cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt);
220  context->slavelist[slave].mbx_cnt = cnt;
221  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
222  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits (SDO request) */
223  SDOp->Command = ECT_SDO_SEG_UP_REQ + toggle; /* segment upload request */
224  SDOp->Index = htoes(index);
225  SDOp->SubIndex = subindex;
226  SDOp->ldata[0] = 0;
227  /* send segmented upload request to slave */
228  wkc = ecx_mbxsend(context, slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
229  /* is mailbox transferred to slave ? */
230  if (wkc > 0)
231  {
232  ec_clearmbx(&MbxIn);
233  /* read slave response */
234  wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, timeout);
235  /* has slave responded ? */
236  if (wkc > 0)
237  {
238  /* slave response should be CoE, SDO response */
239  if ((((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
240  ((etohs(aSDOp->CANOpen) >> 12) == ECT_COES_SDORES) &&
241  ((aSDOp->Command & 0xe0) == 0x00)))
242  {
243  /* calculate mailbox transfer size */
244  Framedatasize = etohs(aSDOp->MbxHeader.length) - 3;
245  if ((aSDOp->Command & 0x01) > 0)
246  { /* last segment */
247  NotLast = FALSE;
248  if (Framedatasize == 7)
249  /* subtract unused bytes from frame */
250  Framedatasize = Framedatasize - ((aSDOp->Command & 0x0e) >> 1);
251  /* copy to parameter buffer */
252  memcpy(hp, &(aSDOp->Index), Framedatasize);
253  }
254  else /* segments follow */
255  {
256  /* copy to parameter buffer */
257  memcpy(hp, &(aSDOp->Index), Framedatasize);
258  /* increment buffer pointer */
259  hp += Framedatasize;
260  }
261  /* update parameter size */
262  *psize += Framedatasize;
263  }
264  /* unexpected frame returned from slave */
265  else
266  {
267  NotLast = FALSE;
268  if ((aSDOp->Command) == ECT_SDO_ABORT) /* SDO abort frame received */
269  ecx_SDOerror(context, slave, index, subindex, etohl(aSDOp->ldata[0]));
270  else
271  ecx_packeterror(context, slave, index, subindex, 1); /* Unexpected frame returned */
272  wkc = 0;
273  }
274  }
275  }
276  toggle = toggle ^ 0x10; /* toggle bit for segment request */
277  }
278  }
279  /* non segmented transfer */
280  else
281  {
282  /* copy to parameter buffer */
283  memcpy(bp, &aSDOp->ldata[1], SDOlen);
284  *psize = SDOlen;
285  }
286  }
287  /* parameter buffer too small */
288  else
289  {
290  wkc = 0;
291  ecx_packeterror(context, slave, index, subindex, 3); /* data container too small for type */
292  }
293  }
294  }
295  /* other slave response */
296  else
297  {
298  if ((aSDOp->Command) == ECT_SDO_ABORT) /* SDO abort frame received */
299  {
300  ecx_SDOerror(context, slave, index, subindex, etohl(aSDOp->ldata[0]));
301  }
302  else
303  {
304  ecx_packeterror(context, slave, index, subindex, 1); /* Unexpected frame returned */
305  }
306  wkc = 0;
307  }
308  }
309  }
310  return wkc;
311 }
312 
331  boolean CA, int psize, void *p, int Timeout)
332 {
333  ec_SDOt *SDOp, *aSDOp;
334  int wkc, maxdata;
335  ec_mbxbuft MbxIn, MbxOut;
336  uint8 cnt, toggle;
337  uint16 framedatasize;
338  boolean NotLast;
339  uint8 *hp;
340 
341  ec_clearmbx(&MbxIn);
342  /* Empty slave out mailbox if something is in. Timeout set to 0 */
343  wkc = ecx_mbxreceive(context, Slave, (ec_mbxbuft *)&MbxIn, 0);
344  ec_clearmbx(&MbxOut);
345  aSDOp = (ec_SDOt *)&MbxIn;
346  SDOp = (ec_SDOt *)&MbxOut;
347  maxdata = context->slavelist[Slave].mbx_l - 0x10; /* data section=mailbox size - 6 mbx - 2 CoE - 8 sdo req */
348  /* if small data use expedited transfer */
349  if ((psize <= 4) && !CA)
350  {
351  SDOp->MbxHeader.length = htoes(0x000a);
352  SDOp->MbxHeader.address = htoes(0x0000);
353  SDOp->MbxHeader.priority = 0x00;
354  /* get new mailbox counter, used for session handle */
355  cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt);
356  context->slavelist[Slave].mbx_cnt = cnt;
357  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
358  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits */
359  SDOp->Command = ECT_SDO_DOWN_EXP | (((4 - psize) << 2) & 0x0c); /* expedited SDO download transfer */
360  SDOp->Index = htoes(Index);
361  SDOp->SubIndex = SubIndex;
362  hp = p;
363  /* copy parameter data to mailbox */
364  memcpy(&SDOp->ldata[0], hp, psize);
365  /* send mailbox SDO download request to slave */
366  wkc = ecx_mbxsend(context, Slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
367  if (wkc > 0)
368  {
369  ec_clearmbx(&MbxIn);
370  /* read slave response */
371  wkc = ecx_mbxreceive(context, Slave, (ec_mbxbuft *)&MbxIn, Timeout);
372  if (wkc > 0)
373  {
374  /* response should be CoE, SDO response, correct index and subindex */
375  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
376  ((etohs(aSDOp->CANOpen) >> 12) == ECT_COES_SDORES) &&
377  (aSDOp->Index == SDOp->Index) &&
378  (aSDOp->SubIndex == SDOp->SubIndex))
379  {
380  /* all OK */
381  }
382  /* unexpected response from slave */
383  else
384  {
385  if (aSDOp->Command == ECT_SDO_ABORT) /* SDO abort frame received */
386  {
387  ecx_SDOerror(context, Slave, Index, SubIndex, etohl(aSDOp->ldata[0]));
388  }
389  else
390  {
391  ecx_packeterror(context, Slave, Index, SubIndex, 1); /* Unexpected frame returned */
392  }
393  wkc = 0;
394  }
395  }
396  }
397  }
398  else
399  {
400  framedatasize = psize;
401  NotLast = FALSE;
402  if (framedatasize > maxdata)
403  {
404  framedatasize = maxdata; /* segmented transfer needed */
405  NotLast = TRUE;
406  }
407  SDOp->MbxHeader.length = htoes(0x0a + framedatasize);
408  SDOp->MbxHeader.address = htoes(0x0000);
409  SDOp->MbxHeader.priority = 0x00;
410  /* get new mailbox counter, used for session handle */
411  cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt);
412  context->slavelist[Slave].mbx_cnt = cnt;
413  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
414  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits */
415  if (CA)
416  {
417  SDOp->Command = ECT_SDO_DOWN_INIT_CA; /* Complete Access, normal SDO init download transfer */
418  }
419  else
420  {
421  SDOp->Command = ECT_SDO_DOWN_INIT; /* normal SDO init download transfer */
422  }
423  SDOp->Index = htoes(Index);
424  SDOp->SubIndex = SubIndex;
425  if (CA && (SubIndex > 1))
426  {
427  SDOp->SubIndex = 1;
428  }
429  SDOp->ldata[0] = htoel(psize);
430  hp = p;
431  /* copy parameter data to mailbox */
432  memcpy(&SDOp->ldata[1], hp, framedatasize);
433  hp += framedatasize;
434  psize -= framedatasize;
435  /* send mailbox SDO download request to slave */
436  wkc = ecx_mbxsend(context, Slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
437  if (wkc > 0)
438  {
439  ec_clearmbx(&MbxIn);
440  /* read slave response */
441  wkc = ecx_mbxreceive(context, Slave, (ec_mbxbuft *)&MbxIn, Timeout);
442  if (wkc > 0)
443  {
444  /* response should be CoE, SDO response, correct index and subindex */
445  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
446  ((etohs(aSDOp->CANOpen) >> 12) == ECT_COES_SDORES) &&
447  (aSDOp->Index == SDOp->Index) &&
448  (aSDOp->SubIndex == SDOp->SubIndex))
449  {
450  /* all ok */
451  maxdata += 7;
452  toggle = 0;
453  /* repeat while segments left */
454  while (NotLast)
455  {
456  SDOp = (ec_SDOt *)&MbxOut;
457  framedatasize = psize;
458  NotLast = FALSE;
459  SDOp->Command = 0x01; /* last segment */
460  if (framedatasize > maxdata)
461  {
462  framedatasize = maxdata; /* more segments needed */
463  NotLast = TRUE;
464  SDOp->Command = 0x00; /* segments follow */
465  }
466  if (!NotLast && (framedatasize < 7))
467  {
468  SDOp->MbxHeader.length = htoes(0x0a); /* minimum size */
469  SDOp->Command = 0x01 + ((7 - framedatasize) << 1); /* last segment reduced octets */
470  }
471  else
472  {
473  SDOp->MbxHeader.length = htoes(framedatasize + 3); /* data + 2 CoE + 1 SDO */
474  }
475  SDOp->MbxHeader.address = htoes(0x0000);
476  SDOp->MbxHeader.priority = 0x00;
477  /* get new mailbox counter value */
478  cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt);
479  context->slavelist[Slave].mbx_cnt = cnt;
480  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
481  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOREQ << 12)); /* number 9bits service upper 4 bits (SDO request) */
482  SDOp->Command = SDOp->Command + toggle; /* add toggle bit to command byte */
483  /* copy parameter data to mailbox */
484  memcpy(&SDOp->Index, hp, framedatasize);
485  /* update parameter buffer pointer */
486  hp += framedatasize;
487  psize -= framedatasize;
488  /* send SDO download request */
489  wkc = ecx_mbxsend(context, Slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
490  if (wkc > 0)
491  {
492  ec_clearmbx(&MbxIn);
493  /* read slave response */
494  wkc = ecx_mbxreceive(context, Slave, (ec_mbxbuft *)&MbxIn, Timeout);
495  if (wkc > 0)
496  {
497  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
498  ((etohs(aSDOp->CANOpen) >> 12) == ECT_COES_SDORES) &&
499  ((aSDOp->Command & 0xe0) == 0x20))
500  {
501  /* all OK, nothing to do */
502  }
503  else
504  {
505  if (aSDOp->Command == ECT_SDO_ABORT) /* SDO abort frame received */
506  {
507  ecx_SDOerror(context, Slave, Index, SubIndex, etohl(aSDOp->ldata[0]));
508  }
509  else
510  {
511  ecx_packeterror(context, Slave, Index, SubIndex, 1); /* Unexpected frame returned */
512  }
513  wkc = 0;
514  NotLast = FALSE;
515  }
516  }
517  }
518  toggle = toggle ^ 0x10; /* toggle bit for segment request */
519  }
520  }
521  /* unexpected response from slave */
522  else
523  {
524  if (aSDOp->Command == ECT_SDO_ABORT) /* SDO abort frame received */
525  {
526  ecx_SDOerror(context, Slave, Index, SubIndex, etohl(aSDOp->ldata[0]));
527  }
528  else
529  {
530  ecx_packeterror(context, Slave, Index, SubIndex, 1); /* Unexpected frame returned */
531  }
532  wkc = 0;
533  }
534  }
535  }
536  }
537 
538  return wkc;
539 }
540 
552 int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber, int psize, void *p)
553 {
554  ec_SDOt *SDOp;
555  int wkc, maxdata;
556  ec_mbxbuft MbxIn, MbxOut;
557  uint8 cnt;
558  uint16 framedatasize;
559 
560  ec_clearmbx(&MbxIn);
561  /* Empty slave out mailbox if something is in. Timeout set to 0 */
562  wkc = ecx_mbxreceive(context, Slave, (ec_mbxbuft *)&MbxIn, 0);
563  ec_clearmbx(&MbxOut);
564  SDOp = (ec_SDOt *)&MbxOut;
565  maxdata = context->slavelist[Slave].mbx_l - 0x08; /* data section=mailbox size - 6 mbx - 2 CoE */
566  framedatasize = psize;
567  if (framedatasize > maxdata)
568  {
569  framedatasize = maxdata; /* limit transfer */
570  }
571  SDOp->MbxHeader.length = htoes(0x02 + framedatasize);
572  SDOp->MbxHeader.address = htoes(0x0000);
573  SDOp->MbxHeader.priority = 0x00;
574  /* get new mailbox counter, used for session handle */
575  cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt);
576  context->slavelist[Slave].mbx_cnt = cnt;
577  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
578  SDOp->CANOpen = htoes((RxPDOnumber & 0x01ff) + (ECT_COES_RXPDO << 12)); /* number 9bits service upper 4 bits */
579  /* copy PDO data to mailbox */
580  memcpy(&SDOp->Command, p, framedatasize);
581  /* send mailbox RxPDO request to slave */
582  wkc = ecx_mbxsend(context, Slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
583 
584  return wkc;
585 }
586 
599 int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout)
600 {
601  ec_SDOt *SDOp, *aSDOp;
602  int wkc;
603  ec_mbxbuft MbxIn, MbxOut;
604  uint8 cnt;
605  uint16 framedatasize;
606 
607  ec_clearmbx(&MbxIn);
608  /* Empty slave out mailbox if something is in. Timeout set to 0 */
609  wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, 0);
610  ec_clearmbx(&MbxOut);
611  aSDOp = (ec_SDOt *)&MbxIn;
612  SDOp = (ec_SDOt *)&MbxOut;
613  SDOp->MbxHeader.length = htoes(0x02);
614  SDOp->MbxHeader.address = htoes(0x0000);
615  SDOp->MbxHeader.priority = 0x00;
616  /* get new mailbox counter, used for session handle */
617  cnt = ec_nextmbxcnt(context->slavelist[slave].mbx_cnt);
618  context->slavelist[slave].mbx_cnt = cnt;
619  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
620  SDOp->CANOpen = htoes((TxPDOnumber & 0x01ff) + (ECT_COES_TXPDO_RR << 12)); /* number 9bits service upper 4 bits */
621  wkc = ecx_mbxsend(context, slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
622  if (wkc > 0)
623  {
624  /* clean mailboxbuffer */
625  ec_clearmbx(&MbxIn);
626  /* read slave response */
627  wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, timeout);
628  if (wkc > 0) /* succeeded to read slave response ? */
629  {
630  /* slave response should be CoE, TxPDO */
631  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
632  ((etohs(aSDOp->CANOpen) >> 12) == ECT_COES_TXPDO))
633  {
634  /* TxPDO response */
635  framedatasize = (aSDOp->MbxHeader.length - 2);
636  if (*psize >= framedatasize) /* parameter buffer big enough ? */
637  {
638  /* copy parameter in parameter buffer */
639  memcpy(p, &aSDOp->Command, framedatasize);
640  /* return the real parameter size */
641  *psize = framedatasize;
642  }
643  /* parameter buffer too small */
644  else
645  {
646  wkc = 0;
647  ecx_packeterror(context, slave, 0, 0, 3); /* data container too small for type */
648  }
649  }
650  /* other slave response */
651  else
652  {
653  if ((aSDOp->Command) == ECT_SDO_ABORT) /* SDO abort frame received */
654  {
655  ecx_SDOerror(context, slave, 0, 0, etohl(aSDOp->ldata[0]));
656  }
657  else
658  {
659  ecx_packeterror(context, slave, 0, 0, 1); /* Unexpected frame returned */
660  }
661  wkc = 0;
662  }
663  }
664  }
665 
666  return wkc;
667 }
668 
675 int ecx_readPDOassign(ecx_contextt *context, uint16 Slave, uint16 PDOassign)
676 {
677  uint16 idxloop, nidx, subidxloop, rdat, idx, subidx;
678  uint8 subcnt;
679  int wkc, bsize = 0, rdl;
680  int32 rdat2;
681 
682  rdl = sizeof(rdat); rdat = 0;
683  /* read PDO assign subindex 0 ( = number of PDO's) */
684  wkc = ecx_SDOread(context, Slave, PDOassign, 0x00, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
685  rdat = etohs(rdat);
686  /* positive result from slave ? */
687  if ((wkc > 0) && (rdat > 0))
688  {
689  /* number of available sub indexes */
690  nidx = rdat;
691  bsize = 0;
692  /* read all PDO's */
693  for (idxloop = 1; idxloop <= nidx; idxloop++)
694  {
695  rdl = sizeof(rdat); rdat = 0;
696  /* read PDO assign */
697  wkc = ecx_SDOread(context, Slave, PDOassign, (uint8)idxloop, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
698  /* result is index of PDO */
699  idx = etohs(rdat);
700  if (idx > 0)
701  {
702  rdl = sizeof(subcnt); subcnt = 0;
703  /* read number of subindexes of PDO */
704  wkc = ecx_SDOread(context, Slave,idx, 0x00, FALSE, &rdl, &subcnt, EC_TIMEOUTRXM);
705  subidx = subcnt;
706  /* for each subindex */
707  for (subidxloop = 1; subidxloop <= subidx; subidxloop++)
708  {
709  rdl = sizeof(rdat2); rdat2 = 0;
710  /* read SDO that is mapped in PDO */
711  wkc = ecx_SDOread(context, Slave, idx, (uint8)subidxloop, FALSE, &rdl, &rdat2, EC_TIMEOUTRXM);
712  rdat2 = etohl(rdat2);
713  /* extract bitlength of SDO */
714  if (LO_BYTE(rdat2) < 0xff)
715  {
716  bsize += LO_BYTE(rdat2);
717  }
718  else
719  {
720  rdl = sizeof(rdat); rdat = htoes(0xff);
721  /* read Object Entry in Object database */
722 // wkc = ec_readOEsingle(idx, (uint8)SubCount, pODlist, pOElist);
723  bsize += etohs(rdat);
724  }
725  }
726  }
727  }
728  }
729  /* return total found bitlength (PDO) */
730  return bsize;
731 }
732 
740 int ecx_readPDOassignCA(ecx_contextt *context, uint16 Slave, int Thread_n,
741  uint16 PDOassign)
742 {
743  uint16 idxloop, nidx, subidxloop, idx, subidx;
744  int wkc, bsize = 0, rdl;
745 
746  /* find maximum size of PDOassign buffer */
747  rdl = sizeof(ec_PDOassignt);
748  context->PDOassign[Thread_n].n=0;
749  /* read rxPDOassign in CA mode, all subindexes are read in one struct */
750  wkc = ecx_SDOread(context, Slave, PDOassign, 0x00, TRUE, &rdl,
751  &(context->PDOassign[Thread_n]), EC_TIMEOUTRXM);
752  /* positive result from slave ? */
753  if ((wkc > 0) && (context->PDOassign[Thread_n].n > 0))
754  {
755  nidx = context->PDOassign[Thread_n].n;
756  bsize = 0;
757  /* for each PDO do */
758  for (idxloop = 1; idxloop <= nidx; idxloop++)
759  {
760  /* get index from PDOassign struct */
761  idx = etohs(context->PDOassign[Thread_n].index[idxloop - 1]);
762  if (idx > 0)
763  {
764  rdl = sizeof(ec_PDOdesct); context->PDOdesc[Thread_n].n = 0;
765  /* read SDO's that are mapped in PDO, CA mode */
766  wkc = ecx_SDOread(context, Slave,idx, 0x00, TRUE, &rdl,
767  &(context->PDOdesc[Thread_n]), EC_TIMEOUTRXM);
768  subidx = context->PDOdesc[Thread_n].n;
769  /* extract all bitlengths of SDO's */
770  for (subidxloop = 1; subidxloop <= subidx; subidxloop++)
771  {
772  bsize += LO_BYTE(etohl(context->PDOdesc[Thread_n].PDO[subidxloop -1]));
773  }
774  }
775  }
776  }
777 
778  /* return total found bitlength (PDO) */
779  return bsize;
780 }
781 
810 int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize)
811 {
812  int wkc, rdl;
813  int retVal = 0;
814  uint8 nSM, iSM, tSM;
815  int Tsize;
816  uint8 SMt_bug_add;
817 
818  *Isize = 0;
819  *Osize = 0;
820  SMt_bug_add = 0;
821  rdl = sizeof(nSM); nSM = 0;
822  /* read SyncManager Communication Type object count */
823  wkc = ecx_SDOread(context, Slave, ECT_SDO_SMCOMMTYPE, 0x00, FALSE, &rdl, &nSM, EC_TIMEOUTRXM);
824  /* positive result from slave ? */
825  if ((wkc > 0) && (nSM > 2))
826  {
827  /* limit to maximum number of SM defined, if true the slave can't be configured */
828  if (nSM > EC_MAXSM)
829  nSM = EC_MAXSM;
830  /* iterate for every SM type defined */
831  for (iSM = 2 ; iSM < nSM ; iSM++)
832  {
833  rdl = sizeof(tSM); tSM = 0;
834  /* read SyncManager Communication Type */
835  wkc = ecx_SDOread(context, Slave, ECT_SDO_SMCOMMTYPE, iSM + 1, FALSE, &rdl, &tSM, EC_TIMEOUTRXM);
836  if (wkc > 0)
837  {
838 // start slave bug prevention code, remove if possible
839  if((iSM == 2) && (tSM == 2)) // SM2 has type 2 == mailbox out, this is a bug in the slave!
840  {
841  SMt_bug_add = 1; // try to correct, this works if the types are 0 1 2 3 and should be 1 2 3 4
842  }
843  if(tSM)
844  {
845  tSM += SMt_bug_add; // only add if SMt > 0
846  }
847  if((iSM == 2) && (tSM == 0)) // SM2 has type 0, this is a bug in the slave!
848  {
849  tSM = 3;
850  }
851  if((iSM == 3) && (tSM == 0)) // SM3 has type 0, this is a bug in the slave!
852  {
853  tSM = 4;
854  }
855 // end slave bug prevention code
856 
857  context->slavelist[Slave].SMtype[iSM] = tSM;
858  /* check if SM is unused -> clear enable flag */
859  if (tSM == 0)
860  {
861  context->slavelist[Slave].SM[iSM].SMflags =
862  htoel( etohl(context->slavelist[Slave].SM[iSM].SMflags) & EC_SMENABLEMASK);
863  }
864  if ((tSM == 3) || (tSM == 4))
865  {
866  /* read the assign PDO */
867  Tsize = ecx_readPDOassign(context, Slave, ECT_SDO_PDOASSIGN + iSM );
868  /* if a mapping is found */
869  if (Tsize)
870  {
871  context->slavelist[Slave].SM[iSM].SMlength = htoes((Tsize + 7) / 8);
872  if (tSM == 3)
873  {
874  /* we are doing outputs */
875  *Osize += Tsize;
876  }
877  else
878  {
879  /* we are doing inputs */
880  *Isize += Tsize;
881  }
882  }
883  }
884  }
885  }
886  }
887 
888  /* found some I/O bits ? */
889  if ((*Isize > 0) || (*Osize > 0))
890  {
891  retVal = 1;
892  }
893 
894  return retVal;
895 }
896 
910 int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize)
911 {
912  int wkc, rdl;
913  int retVal = 0;
914  uint8 nSM, iSM, tSM;
915  int Tsize;
916  uint8 SMt_bug_add;
917 
918  *Isize = 0;
919  *Osize = 0;
920  SMt_bug_add = 0;
921  rdl = sizeof(ec_SMcommtypet);
922  context->SMcommtype[Thread_n].n = 0;
923  /* read SyncManager Communication Type object count Complete Access*/
924  wkc = ecx_SDOread(context, Slave, ECT_SDO_SMCOMMTYPE, 0x00, TRUE, &rdl,
925  &(context->SMcommtype[Thread_n]), EC_TIMEOUTRXM);
926  /* positive result from slave ? */
927  if ((wkc > 0) && (context->SMcommtype[Thread_n].n > 2))
928  {
929  nSM = context->SMcommtype[Thread_n].n;
930  /* limit to maximum number of SM defined, if true the slave can't be configured */
931  if (nSM > EC_MAXSM)
932  {
933  nSM = EC_MAXSM;
934  ecx_packeterror(context, Slave, 0, 0, 10); /* #SM larger than EC_MAXSM */
935  }
936  /* iterate for every SM type defined */
937  for (iSM = 2 ; iSM < nSM ; iSM++)
938  {
939  tSM = context->SMcommtype[Thread_n].SMtype[iSM];
940 
941 // start slave bug prevention code, remove if possible
942  if((iSM == 2) && (tSM == 2)) // SM2 has type 2 == mailbox out, this is a bug in the slave!
943  {
944  SMt_bug_add = 1; // try to correct, this works if the types are 0 1 2 3 and should be 1 2 3 4
945  }
946  if(tSM)
947  {
948  tSM += SMt_bug_add; // only add if SMt > 0
949  }
950 // end slave bug prevention code
951 
952  context->slavelist[Slave].SMtype[iSM] = tSM;
953  /* check if SM is unused -> clear enable flag */
954  if (tSM == 0)
955  {
956  context->slavelist[Slave].SM[iSM].SMflags =
957  htoel( etohl(context->slavelist[Slave].SM[iSM].SMflags) & EC_SMENABLEMASK);
958  }
959  if ((tSM == 3) || (tSM == 4))
960  {
961  /* read the assign PDO */
962  Tsize = ecx_readPDOassignCA(context, Slave, Thread_n,
963  ECT_SDO_PDOASSIGN + iSM );
964  /* if a mapping is found */
965  if (Tsize)
966  {
967  context->slavelist[Slave].SM[iSM].SMlength = htoes((Tsize + 7) / 8);
968  if (tSM == 3)
969  {
970  /* we are doing outputs */
971  *Osize += Tsize;
972  }
973  else
974  {
975  /* we are doing inputs */
976  *Isize += Tsize;
977  }
978  }
979  }
980  }
981  }
982 
983  /* found some I/O bits ? */
984  if ((*Isize > 0) || (*Osize > 0))
985  {
986  retVal = 1;
987  }
988  return retVal;
989 }
990 
998 int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist)
999 {
1000  ec_SDOservicet *SDOp, *aSDOp;
1001  ec_mbxbuft MbxIn, MbxOut;
1002  int wkc;
1003  uint16 x, n, i, sp, offset;
1004  boolean stop;
1005  uint8 cnt;
1006  boolean First;
1007 
1008  pODlist->Slave = Slave;
1009  pODlist->Entries = 0;
1010  ec_clearmbx(&MbxIn);
1011  /* clear pending out mailbox in slave if available. Timeout is set to 0 */
1012  wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
1013  ec_clearmbx(&MbxOut);
1014  aSDOp = (ec_SDOservicet*)&MbxIn;
1015  SDOp = (ec_SDOservicet*)&MbxOut;
1016  SDOp->MbxHeader.length = htoes(0x0008);
1017  SDOp->MbxHeader.address = htoes(0x0000);
1018  SDOp->MbxHeader.priority = 0x00;
1019  /* Get new mailbox counter value */
1020  cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt);
1021  context->slavelist[Slave].mbx_cnt = cnt;
1022  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
1023  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOINFO << 12)); /* number 9bits service upper 4 bits */
1024  SDOp->Opcode = ECT_GET_ODLIST_REQ; /* get object description list request */
1025  SDOp->Reserved = 0;
1026  SDOp->Fragments = 0; /* fragments left */
1027  SDOp->wdata[0] = htoes(0x01); /* all objects */
1028  /* send get object description list request to slave */
1029  wkc = ecx_mbxsend(context, Slave, &MbxOut, EC_TIMEOUTTXM);
1030  /* mailbox placed in slave ? */
1031  if (wkc > 0)
1032  {
1033  x = 0;
1034  sp = 0;
1035  First = TRUE;
1036  offset = 1; /* offset to skip info header in first frame, otherwise set to 0 */
1037  do
1038  {
1039  stop = TRUE; /* assume this is last iteration */
1040  ec_clearmbx(&MbxIn);
1041  /* read slave response */
1042  wkc = ecx_mbxreceive(context, Slave, &MbxIn, EC_TIMEOUTRXM);
1043  /* got response ? */
1044  if (wkc > 0)
1045  {
1046  /* response should be CoE and "get object description list response" */
1047  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
1048  ((aSDOp->Opcode & 0x7f) == ECT_GET_ODLIST_RES))
1049  {
1050  if (First)
1051  {
1052  /* extract number of indexes from mailbox data size */
1053  n = (etohs(aSDOp->MbxHeader.length) - (6 + 2)) / 2;
1054  }
1055  else
1056  {
1057  /* extract number of indexes from mailbox data size */
1058  n = (etohs(aSDOp->MbxHeader.length) - 6) / 2;
1059  }
1060  /* check if indexes fit in buffer structure */
1061  if ((sp + n) > EC_MAXODLIST)
1062  {
1063  n = EC_MAXODLIST + 1 - sp;
1064  ecx_SDOinfoerror(context, Slave, 0, 0, 0xf000000); /* Too many entries for master buffer */
1065  stop = TRUE;
1066  }
1067  /* trim to maximum number of ODlist entries defined */
1068  if ((pODlist->Entries + n) > EC_MAXODLIST)
1069  {
1070  n = EC_MAXODLIST - pODlist->Entries;
1071  }
1072  pODlist->Entries += n;
1073  /* extract indexes one by one */
1074  for (i = 0; i < n; i++)
1075  {
1076  pODlist->Index[sp + i] = etohs(aSDOp->wdata[i + offset]);
1077  }
1078  sp += n;
1079  /* check if more fragments will follow */
1080  if (aSDOp->Fragments > 0)
1081  {
1082  stop = FALSE;
1083  }
1084  First = FALSE;
1085  offset = 0;
1086  }
1087  /* got unexpected response from slave */
1088  else
1089  {
1090  if ((aSDOp->Opcode & 0x7f) == ECT_SDOINFO_ERROR) /* SDO info error received */
1091  {
1092  ecx_SDOinfoerror(context, Slave, 0, 0, etohl(aSDOp->ldata[0]));
1093  stop = TRUE;
1094  }
1095  else
1096  {
1097  ecx_packeterror(context, Slave, 0, 0, 1); /* Unexpected frame returned */
1098  }
1099  wkc = 0;
1100  x += 20;
1101  }
1102  }
1103  x++;
1104  }
1105  while ((x <= 128) && !stop);
1106  }
1107  return wkc;
1108 }
1109 
1118 {
1119  ec_SDOservicet *SDOp, *aSDOp;
1120  int wkc;
1121  uint16 n, Slave;
1122  ec_mbxbuft MbxIn, MbxOut;
1123  uint8 cnt;
1124 
1125  Slave = pODlist->Slave;
1126  pODlist->DataType[Item] = 0;
1127  pODlist->ObjectCode[Item] = 0;
1128  pODlist->MaxSub[Item] = 0;
1129  pODlist->Name[Item][0] = 0;
1130  ec_clearmbx(&MbxIn);
1131  /* clear pending out mailbox in slave if available. Timeout is set to 0 */
1132  wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
1133  ec_clearmbx(&MbxOut);
1134  aSDOp = (ec_SDOservicet*)&MbxIn;
1135  SDOp = (ec_SDOservicet*)&MbxOut;
1136  SDOp->MbxHeader.length = htoes(0x0008);
1137  SDOp->MbxHeader.address = htoes(0x0000);
1138  SDOp->MbxHeader.priority = 0x00;
1139  /* Get new mailbox counter value */
1140  cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt);
1141  context->slavelist[Slave].mbx_cnt = cnt;
1142  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
1143  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOINFO << 12)); /* number 9bits service upper 4 bits */
1144  SDOp->Opcode = ECT_GET_OD_REQ; /* get object description request */
1145  SDOp->Reserved = 0;
1146  SDOp->Fragments = 0; /* fragments left */
1147  SDOp->wdata[0] = htoes(pODlist->Index[Item]); /* Data of Index */
1148  /* send get object description request to slave */
1149  wkc = ecx_mbxsend(context, Slave, &MbxOut, EC_TIMEOUTTXM);
1150  /* mailbox placed in slave ? */
1151  if (wkc > 0)
1152  {
1153  ec_clearmbx(&MbxIn);
1154  /* read slave response */
1155  wkc = ecx_mbxreceive(context, Slave, &MbxIn, EC_TIMEOUTRXM);
1156  /* got response ? */
1157  if (wkc > 0)
1158  {
1159  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
1160  ((aSDOp->Opcode & 0x7f) == ECT_GET_OD_RES))
1161  {
1162  n = (etohs(aSDOp->MbxHeader.length) - 12); /* length of string(name of object) */
1163  if (n > EC_MAXNAME)
1164  {
1165  n = EC_MAXNAME; /* max chars */
1166  }
1167  pODlist->DataType[Item] = etohs(aSDOp->wdata[1]);
1168  pODlist->ObjectCode[Item] = aSDOp->bdata[5];
1169  pODlist->MaxSub[Item] = aSDOp->bdata[4];
1170 
1171  strncpy(pODlist->Name[Item] , (char *)&aSDOp->bdata[6], n);
1172  pODlist->Name[Item][n] = 0x00; /* String terminator */
1173  }
1174  /* got unexpected response from slave */
1175  else
1176  {
1177  if (((aSDOp->Opcode & 0x7f) == ECT_SDOINFO_ERROR)) /* SDO info error received */
1178  {
1179  ecx_SDOinfoerror(context, Slave,pODlist->Index[Item], 0, etohl(aSDOp->ldata[0]));
1180  }
1181  else
1182  {
1183  ecx_packeterror(context, Slave,pODlist->Index[Item], 0, 1); /* Unexpected frame returned */
1184  }
1185  wkc = 0;
1186  }
1187  }
1188  }
1189 
1190  return wkc;
1191 }
1192 
1203 int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist)
1204 {
1205  ec_SDOservicet *SDOp, *aSDOp;
1206  int wkc;
1207  uint16 Index, Slave;
1208  int16 n;
1209  ec_mbxbuft MbxIn, MbxOut;
1210  uint8 cnt;
1211 
1212  wkc = 0;
1213  Slave = pODlist->Slave;
1214  Index = pODlist->Index[Item];
1215  ec_clearmbx(&MbxIn);
1216  /* clear pending out mailbox in slave if available. Timeout is set to 0 */
1217  wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
1218  ec_clearmbx(&MbxOut);
1219  aSDOp = (ec_SDOservicet*)&MbxIn;
1220  SDOp = (ec_SDOservicet*)&MbxOut;
1221  SDOp->MbxHeader.length = htoes(0x000a);
1222  SDOp->MbxHeader.address = htoes(0x0000);
1223  SDOp->MbxHeader.priority = 0x00;
1224  /* Get new mailbox counter value */
1225  cnt = ec_nextmbxcnt(context->slavelist[Slave].mbx_cnt);
1226  context->slavelist[Slave].mbx_cnt = cnt;
1227  SDOp->MbxHeader.mbxtype = ECT_MBXT_COE + (cnt << 4); /* CoE */
1228  SDOp->CANOpen = htoes(0x000 + (ECT_COES_SDOINFO << 12)); /* number 9bits service upper 4 bits */
1229  SDOp->Opcode = ECT_GET_OE_REQ; /* get object entry description request */
1230  SDOp->Reserved = 0;
1231  SDOp->Fragments = 0; /* fragments left */
1232  SDOp->wdata[0] = htoes(Index); /* Index */
1233  SDOp->bdata[2] = SubI; /* SubIndex */
1234  SDOp->bdata[3] = 1 + 2 + 4; /* get access rights, object category, PDO */
1235  /* send get object entry description request to slave */
1236  wkc = ecx_mbxsend(context, Slave, &MbxOut, EC_TIMEOUTTXM);
1237  /* mailbox placed in slave ? */
1238  if (wkc > 0)
1239  {
1240  ec_clearmbx(&MbxIn);
1241  /* read slave response */
1242  wkc = ecx_mbxreceive(context, Slave, &MbxIn, EC_TIMEOUTRXM);
1243  /* got response ? */
1244  if (wkc > 0)
1245  {
1246  if (((aSDOp->MbxHeader.mbxtype & 0x0f) == ECT_MBXT_COE) &&
1247  ((aSDOp->Opcode & 0x7f) == ECT_GET_OE_RES))
1248  {
1249  pOElist->Entries++;
1250  n = (etohs(aSDOp->MbxHeader.length) - 16); /* length of string(name of object) */
1251  if (n > EC_MAXNAME)
1252  {
1253  n = EC_MAXNAME; /* max string length */
1254  }
1255  if (n < 0 )
1256  {
1257  n = 0;
1258  }
1259  pOElist->ValueInfo[SubI] = aSDOp->bdata[3];
1260  pOElist->DataType[SubI] = etohs(aSDOp->wdata[2]);
1261  pOElist->BitLength[SubI] = etohs(aSDOp->wdata[3]);
1262  pOElist->ObjAccess[SubI] = etohs(aSDOp->wdata[4]);
1263 
1264  strncpy(pOElist->Name[SubI] , (char *)&aSDOp->wdata[5], n);
1265  pOElist->Name[SubI][n] = 0x00; /* string terminator */
1266  }
1267  /* got unexpected response from slave */
1268  else
1269  {
1270  if (((aSDOp->Opcode & 0x7f) == ECT_SDOINFO_ERROR)) /* SDO info error received */
1271  {
1272  ecx_SDOinfoerror(context, Slave, Index, SubI, etohl(aSDOp->ldata[0]));
1273  }
1274  else
1275  {
1276  ecx_packeterror(context, Slave, Index, SubI, 1); /* Unexpected frame returned */
1277  }
1278  wkc = 0;
1279  }
1280  }
1281  }
1282 
1283  return wkc;
1284 }
1285 
1294 int ecx_readOE(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist)
1295 {
1296  uint16 SubCount;
1297  int wkc;
1298  uint8 SubI;
1299 
1300  wkc = 0;
1301  pOElist->Entries = 0;
1302  SubI = pODlist->MaxSub[Item];
1303  /* for each entry found in ODlist */
1304  for (SubCount = 0; SubCount <= SubI; SubCount++)
1305  {
1306  /* read subindex of entry */
1307  wkc = ecx_readOEsingle(context, Item, (uint8)SubCount, pODlist, pOElist);
1308  }
1309 
1310  return wkc;
1311 }
1312 
1313 #ifdef EC_VER1
1314 
1322 void ec_SDOerror(uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode)
1323 {
1324  ecx_SDOerror(&ecx_context, Slave, Index, SubIdx, AbortCode);
1325 }
1326 
1345  boolean CA, int *psize, void *p, int timeout)
1346 {
1347  return ecx_SDOread(&ecx_context, slave, index, subindex, CA, psize, p, timeout);
1348 }
1349 
1368  boolean CA, int psize, void *p, int Timeout)
1369 {
1370  return ecx_SDOwrite(&ecx_context, Slave, Index, SubIndex, CA, psize, p, Timeout);
1371 }
1372 
1384 int ec_RxPDO(uint16 Slave, uint16 RxPDOnumber, int psize, void *p)
1385 {
1386  return ecx_RxPDO(&ecx_context, Slave, RxPDOnumber, psize, p);
1387 }
1388 
1401 int ec_TxPDO(uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout)
1402 {
1403  return ecx_TxPDO(&ecx_context, slave, TxPDOnumber, psize, p, timeout);
1404 }
1405 
1411 int ec_readPDOassign(uint16 Slave, uint16 PDOassign)
1412 {
1413  return ecx_readPDOassign(&ecx_context, Slave, PDOassign);
1414 }
1415 
1423 int ec_readPDOassignCA(uint16 Slave, uint16 PDOassign, int Thread_n)
1424 {
1425  return ecx_readPDOassignCA(&ecx_context, Slave, Thread_n, PDOassign);
1426 }
1427 
1441 int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize)
1442 {
1443  return ecx_readPDOmap(&ecx_context, Slave, Osize, Isize);
1444 }
1445 
1459 int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize)
1460 {
1461  return ecx_readPDOmapCA(&ecx_context, Slave, Thread_n, Osize, Isize);
1462 }
1463 
1471 int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist)
1472 {
1473  return ecx_readODlist(&ecx_context, Slave, pODlist);
1474 }
1475 
1484 {
1485  return ecx_readODdescription(&ecx_context, Item, pODlist);
1486 }
1487 
1488 int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist)
1489 {
1490  return ecx_readOEsingle(&ecx_context, Item, SubI, pODlist, pOElist);
1491 }
1492 
1501 int ec_readOE(uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist)
1502 {
1503  return ecx_readOE(&ecx_context, Item, pODlist, pOElist);
1504 }
1505 #endif
ec_smt SM[EC_MAXSM]
Definition: ethercatmain.h:143
uint16 ObjAccess[EC_MAXOELIST]
Definition: ethercatcoe.h:56
uint8 index
Definition: ethercattype.h:114
uint8 mbx_cnt
Definition: ethercatmain.h:167
int ecx_SDOread(ecx_contextt *context, uint16 slave, uint16 index, uint8 subindex, boolean CA, int *psize, void *p, int timeout)
Definition: ethercatcoe.c:120
#define EC_SMENABLEMASK
Definition: ethercatmain.h:101
void ec_SDOerror(uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode)
Definition: ethercatcoe.c:1322
#define htoel(A)
Definition: ethercattype.h:534
uint8 MaxSub[EC_MAXODLIST]
Definition: ethercatcoe.h:39
uint8_t uint8
Definition: osal.h:28
int ecx_readODdescription(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist)
Definition: ethercatcoe.c:1117
#define ECT_SDO_PDOASSIGN
Definition: ethercattype.h:452
int ecx_readPDOassignCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint16 PDOassign)
Definition: ethercatcoe.c:740
int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber, int psize, void *p)
Definition: ethercatcoe.c:552
void ecx_pusherror(ecx_contextt *context, const ec_errort *Ec)
Definition: ethercatmain.c:154
int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist)
Definition: ethercatcoe.c:998
uint8 ValueInfo[EC_MAXOELIST]
Definition: ethercatcoe.h:50
uint32 ldata[0x80]
Definition: ethercatcoe.c:35
uint8 SubIndex
Definition: ethercatcoe.c:30
int ec_readPDOmapCA(uint16 Slave, int Thread_n, int *Osize, int *Isize)
Definition: ethercatcoe.c:1459
PACKED_BEGIN struct PACKED ec_SMcommtype ec_SMcommtypet
uint8 SubIdx
Definition: ethercattype.h:489
PACKED_END PACKED_BEGIN struct PACKED ec_SDOservicet
int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber, int *psize, void *p, int timeout)
Definition: ethercatcoe.c:599
int ec_readPDOassignCA(uint16 Slave, uint16 PDOassign, int Thread_n)
Definition: ethercatcoe.c:1423
uint8 Command
Definition: ethercatcoe.c:28
uint16_t uint16
Definition: osal.h:29
int ecx_readOEsingle(ecx_contextt *context, uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist)
Definition: ethercatcoe.c:1203
uint8 SMtype[EC_MAXSM]
Definition: ethercatmain.h:145
void ecx_packeterror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode)
Definition: ethercatmain.c:219
uint16 Fragments
Definition: ethercatcoe.c:48
#define EC_TIMEOUTRXM
Definition: ethercattype.h:74
General typedefs and defines for EtherCAT.
#define etohs(A)
Definition: ethercattype.h:536
Headerfile for ethercatcoe.c.
#define TRUE
Definition: osal.h:19
int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist)
Definition: ethercatcoe.c:1471
ec_err_type Etype
Definition: ethercattype.h:491
void ec_clearmbx(ec_mbxbuft *Mbx)
Definition: ethercatmain.c:921
#define EC_MAXSM
Definition: ethercatmain.h:35
int ec_TxPDO(uint16 slave, uint16 TxPDOnumber, int *psize, void *p, int timeout)
Definition: ethercatcoe.c:1401
int ec_readPDOmap(uint16 Slave, int *Osize, int *Isize)
Definition: ethercatcoe.c:1441
int ecx_mbxsend(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
Definition: ethercatmain.c:968
int ec_readOE(uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist)
Definition: ethercatcoe.c:1501
#define ECT_SDO_SMCOMMTYPE
Definition: ethercattype.h:450
ec_timet osal_current_time(void)
Definition: erika/osal.c:37
int ec_readODdescription(uint16 Item, ec_ODlistt *pODlist)
Definition: ethercatcoe.c:1483
uint16 Slave
Definition: ethercatcoe.h:29
int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout)
Definition: ethercatcoe.c:330
ec_PDOdesct * PDOdesc
Definition: ethercatmain.h:421
uint16 Index[EC_MAXODLIST]
Definition: ethercatcoe.h:33
#define EC_TIMEOUTTXM
Definition: ethercattype.h:72
PACKED_END void ecx_SDOerror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode)
Definition: ethercatcoe.c:66
uint8 bdata[0x200]
Definition: ethercatcoe.c:33
PACKED_END PACKED_BEGIN struct PACKED ec_PDOassign ec_PDOassignt
uint16 Slave
Definition: ethercattype.h:485
ec_mbxheadert MbxHeader
Definition: ethercatcoe.c:26
uint16 Index
Definition: ethercatcoe.c:29
int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
int slave
Definition: aliastool.c:44
#define FALSE
Definition: osal.h:22
uint16 CANOpen
Definition: ethercatcoe.c:27
#define PACKED_END
int32_t int32
Definition: osal.h:27
#define LO_BYTE(w)
Definition: ethercattype.h:514
ec_PDOassignt * PDOassign
Definition: ethercatmain.h:419
int ec_RxPDO(uint16 Slave, uint16 RxPDOnumber, int psize, void *p)
Definition: ethercatcoe.c:1384
ec_SMcommtypet * SMcommtype
Definition: ethercatmain.h:417
uint16 BitLength[EC_MAXOELIST]
Definition: ethercatcoe.h:54
static void ecx_SDOinfoerror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode)
Definition: ethercatcoe.c:89
char Name[EC_MAXOELIST][EC_MAXNAME+1]
Definition: ethercatcoe.h:58
uint16 DataType[EC_MAXODLIST]
Definition: ethercatcoe.h:35
PACKED_END PACKED_BEGIN struct PACKED ec_PDOdesc ec_PDOdesct
int32 AbortCode
Definition: ethercattype.h:495
ec_timet Time
Definition: ethercattype.h:481
uint8 Reserved
Definition: ethercatcoe.c:47
Headerfile for ethercatbase.c.
int wkc
Definition: aliastool.c:47
#define htoes(A)
Definition: ethercattype.h:533
#define EC_MAXNAME
Definition: ethercatmain.h:23
uint16 Index
Definition: ethercattype.h:487
PACKED_BEGIN struct PACKED ec_mbxheader ec_mbxheadert
#define etohl(A)
Definition: ethercattype.h:537
Headerfile for ethercatmain.c.
uint8 ObjectCode[EC_MAXODLIST]
Definition: ethercatcoe.h:37
int ecx_readPDOassign(ecx_contextt *context, uint16 Slave, uint16 PDOassign)
Definition: ethercatcoe.c:675
uint32_t uint32
Definition: osal.h:30
uint8 Opcode
Definition: ethercatcoe.c:46
uint16 Entries
Definition: ethercatcoe.h:31
uint16 mbx_l
Definition: ethercatmain.h:157
uint16 Entries
Definition: ethercatcoe.h:48
int16_t int16
Definition: osal.h:26
int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, int *Osize, int *Isize)
Definition: ethercatcoe.c:910
PACKED_BEGIN struct PACKED ec_SDOt
#define EC_MAXODLIST
Definition: ethercatcoe.h:20
char Name[EC_MAXODLIST][EC_MAXNAME+1]
Definition: ethercatcoe.h:41
int ec_SDOread(uint16 slave, uint16 index, uint8 subindex, boolean CA, int *psize, void *p, int timeout)
Definition: ethercatcoe.c:1344
uint16 wdata[0x100]
Definition: ethercatcoe.c:34
int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist)
Definition: ethercatcoe.c:1488
int ec_SDOwrite(uint16 Slave, uint16 Index, uint8 SubIndex, boolean CA, int psize, void *p, int Timeout)
Definition: ethercatcoe.c:1367
boolean * ecaterror
Definition: ethercatmain.h:409
int ecx_readOE(ecx_contextt *context, uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist)
Definition: ethercatcoe.c:1294
int ec_readPDOassign(uint16 Slave, uint16 PDOassign)
Definition: ethercatcoe.c:1411
int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, int *Osize, int *Isize)
Definition: ethercatcoe.c:810
uint16 DataType[EC_MAXOELIST]
Definition: ethercatcoe.h:52
ec_slavet * slavelist
Definition: ethercatmain.h:389
uint8 ec_mbxbuft[EC_MAXMBX+1]
Definition: ethercatmain.h:312
uint8 ec_nextmbxcnt(uint8 cnt)
Definition: ethercatmain.c:907
#define PACKED_BEGIN


soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Mon Feb 28 2022 23:46:57