IgH EtherCAT Master  1.6.0
fsm_pdo.c
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
4  *
5  * This file is part of the IgH EtherCAT Master.
6  *
7  * The IgH EtherCAT Master is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version 2, as
9  * published by the Free Software Foundation.
10  *
11  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with the IgH EtherCAT Master; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  ****************************************************************************/
21 
26 /****************************************************************************/
27 
28 #include "globals.h"
29 #include "master.h"
30 #include "mailbox.h"
31 #include "slave_config.h"
32 
33 #include "fsm_pdo.h"
34 
35 /****************************************************************************/
36 
41 
44 
51 
58 
61 
62 /****************************************************************************/
63 
67  ec_fsm_pdo_t *fsm,
68  ec_fsm_coe_t *fsm_coe
69  )
70 {
71  fsm->fsm_coe = fsm_coe;
72  ec_fsm_pdo_entry_init(&fsm->fsm_pdo_entry, fsm_coe);
73  ec_pdo_list_init(&fsm->pdos);
75  ec_pdo_init(&fsm->slave_pdo);
76 }
77 
78 /****************************************************************************/
79 
83  ec_fsm_pdo_t *fsm
84  )
85 {
87  ec_pdo_list_clear(&fsm->pdos);
89  ec_pdo_clear(&fsm->slave_pdo);
90 }
91 
92 /****************************************************************************/
93 
97  ec_fsm_pdo_t *fsm
98  )
99 {
100  printk(KERN_CONT "Currently assigned PDOs: ");
101  ec_pdo_list_print(&fsm->sync->pdos);
102  printk(KERN_CONT ". PDOs to assign: ");
103  ec_pdo_list_print(&fsm->pdos);
104  printk(KERN_CONT "\n");
105 }
106 
107 /****************************************************************************/
108 
112  ec_fsm_pdo_t *fsm,
113  ec_slave_t *slave
114  )
115 {
116  fsm->slave = slave;
118 }
119 
120 /****************************************************************************/
121 
125  ec_fsm_pdo_t *fsm,
126  ec_slave_t *slave
127  )
128 {
129  fsm->slave = slave;
131 }
132 
133 /****************************************************************************/
134 
140  const ec_fsm_pdo_t *fsm
141  )
142 {
143  return fsm->state != ec_fsm_pdo_state_end
144  && fsm->state != ec_fsm_pdo_state_error;
145 }
146 
147 /****************************************************************************/
148 
157  ec_fsm_pdo_t *fsm,
158  ec_datagram_t *datagram
159  )
160 {
161  fsm->state(fsm, datagram);
162 
163  return ec_fsm_pdo_running(fsm);
164 }
165 
166 /****************************************************************************/
167 
173  const ec_fsm_pdo_t *fsm
174  )
175 {
176  return fsm->state == ec_fsm_pdo_state_end;
177 }
178 
179 /*****************************************************************************
180  * Reading state funtions.
181  ****************************************************************************/
182 
186  ec_fsm_pdo_t *fsm,
187  ec_datagram_t *datagram
188  )
189 {
190  // read PDO assignment for first sync manager not reserved for mailbox
191  fsm->sync_index = 1; // next is 2
192  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
193 }
194 
195 /****************************************************************************/
196 
200  ec_fsm_pdo_t *fsm,
201  ec_datagram_t *datagram
202  )
203 {
204  ec_slave_t *slave = fsm->slave;
205 
206  fsm->sync_index++;
207 
208  for (; fsm->sync_index < EC_MAX_SYNC_MANAGERS; fsm->sync_index++) {
209  if (!(fsm->sync = ec_slave_get_sync(slave, fsm->sync_index)))
210  continue;
211 
212  EC_SLAVE_DBG(slave, 1, "Reading PDO assignment of SM%u.\n",
213  fsm->sync_index);
214 
216 
217  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
220  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
221  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
222  return;
223  }
224 
225  EC_SLAVE_DBG(slave, 1, "Reading of PDO configuration finished.\n");
226 
229 }
230 
231 /****************************************************************************/
232 
236  ec_fsm_pdo_t *fsm,
237  ec_datagram_t *datagram
238  )
239 {
240  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
241  return;
242  }
243 
244  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
245  EC_SLAVE_ERR(fsm->slave, "Failed to read number of assigned PDOs"
246  " for SM%u.\n", fsm->sync_index);
247  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
248  return;
249  }
250 
251  if (fsm->request.data_size != sizeof(uint8_t)) {
252  EC_SLAVE_ERR(fsm->slave, "Invalid data size %zu returned"
253  " when uploading SDO 0x%04X:%02X.\n", fsm->request.data_size,
254  fsm->request.index, fsm->request.subindex);
255  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
256  return;
257  }
258  fsm->pdo_count = EC_READ_U8(fsm->request.data);
259 
260  EC_SLAVE_DBG(fsm->slave, 1, "%u PDOs assigned.\n", fsm->pdo_count);
261 
262  // read first PDO
263  fsm->pdo_pos = 1;
264  ec_fsm_pdo_read_action_next_pdo(fsm, datagram);
265 }
266 
267 /****************************************************************************/
268 
272  ec_fsm_pdo_t *fsm,
273  ec_datagram_t *datagram
274  )
275 {
276  if (fsm->pdo_pos <= fsm->pdo_count) {
277  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index,
278  fsm->pdo_pos);
281  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
282  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
283  return;
284  }
285 
286  // finished reading PDO configuration
287 
288  ec_pdo_list_copy(&fsm->sync->pdos, &fsm->pdos);
290 
291  // next sync manager
292  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
293 }
294 
295 /****************************************************************************/
296 
300  ec_fsm_pdo_t *fsm,
301  ec_datagram_t *datagram
302  )
303 {
304  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
305  return;
306  }
307 
308  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
309  EC_SLAVE_ERR(fsm->slave, "Failed to read index of"
310  " assigned PDO %u from SM%u.\n",
311  fsm->pdo_pos, fsm->sync_index);
312  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
313  return;
314  }
315 
316  if (fsm->request.data_size != sizeof(uint16_t)) {
317  EC_SLAVE_ERR(fsm->slave, "Invalid data size %zu returned"
318  " when uploading SDO 0x%04X:%02X.\n", fsm->request.data_size,
319  fsm->request.index, fsm->request.subindex);
320  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
321  return;
322  }
323 
324  if (!(fsm->pdo = (ec_pdo_t *)
325  kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
326  EC_SLAVE_ERR(fsm->slave, "Failed to allocate PDO.\n");
327  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
328  return;
329  }
330 
331  ec_pdo_init(fsm->pdo);
332  fsm->pdo->index = EC_READ_U16(fsm->request.data);
333  fsm->pdo->sync_index = fsm->sync_index;
334 
335  EC_SLAVE_DBG(fsm->slave, 1, "PDO 0x%04X.\n", fsm->pdo->index);
336 
337  list_add_tail(&fsm->pdo->list, &fsm->pdos.list);
338 
341  fsm->state(fsm, datagram); // execute immediately
342 }
343 
344 /****************************************************************************/
345 
349  ec_fsm_pdo_t *fsm,
350  ec_datagram_t *datagram
351  )
352 {
353  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
354  return;
355  }
356 
358  EC_SLAVE_ERR(fsm->slave, "Failed to read mapped PDO entries"
359  " for PDO 0x%04X.\n", fsm->pdo->index);
360  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
361  return;
362  }
363 
364  // next PDO
365  fsm->pdo_pos++;
366  ec_fsm_pdo_read_action_next_pdo(fsm, datagram);
367 }
368 
369 /*****************************************************************************
370  * Writing state functions.
371  ****************************************************************************/
372 
376  ec_fsm_pdo_t *fsm,
377  ec_datagram_t *datagram
378  )
379 {
380  if (!fsm->slave->config) {
382  return;
383  }
384 
385  fsm->sync_index = 1; // next is 2
386  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
387 }
388 
389 /****************************************************************************/
390 
396  const ec_fsm_pdo_t *fsm,
397  const struct list_head *list
398  )
399 {
400  list = list->next;
401  if (list == &fsm->pdos.list)
402  return NULL; // no next PDO
403  return list_entry(list, ec_pdo_t, list);
404 }
405 
406 /****************************************************************************/
407 
411  ec_fsm_pdo_t *fsm,
412  ec_datagram_t *datagram
413  )
414 {
415  fsm->sync_index++;
416 
417  for (; fsm->sync_index < EC_MAX_SYNC_MANAGERS; fsm->sync_index++) {
418  if (!fsm->slave->config) {
419  // slave configuration removed in the meantime
421  return;
422  }
423 
424  if (ec_pdo_list_copy(&fsm->pdos,
425  &fsm->slave->config->sync_configs[fsm->sync_index].pdos))
426  {
428  return;
429  }
430 
431  if (!(fsm->sync = ec_slave_get_sync(fsm->slave, fsm->sync_index))) {
432  if (!list_empty(&fsm->pdos.list))
433  EC_SLAVE_WARN(fsm->slave, "PDOs configured for SM%u,"
434  " but slave does not provide the"
435  " sync manager information!\n",
436  fsm->sync_index);
437  continue;
438  }
439 
440  // get first configured PDO
441  if (!(fsm->pdo =
443  // no pdos configured
445  return;
446  }
447 
448  ec_fsm_pdo_conf_action_pdo_mapping(fsm, datagram);
449  return;
450  }
451 
453 }
454 
455 /****************************************************************************/
456 
460  ec_fsm_pdo_t *fsm,
461  ec_datagram_t *datagram
462  )
463 {
464  const ec_pdo_t *assigned_pdo;
465 
466  fsm->slave_pdo.index = fsm->pdo->index;
467 
468  if ((assigned_pdo = ec_slave_find_pdo(fsm->slave, fsm->pdo->index))) {
469  ec_pdo_copy_entries(&fsm->slave_pdo, assigned_pdo);
470  } else { // configured PDO is not assigned and thus unknown
472  }
473 
474  if (list_empty(&fsm->slave_pdo.entries)) {
475  EC_SLAVE_DBG(fsm->slave, 1, "Reading mapping of PDO 0x%04X.\n",
476  fsm->pdo->index);
477 
478  // pdo mapping is unknown; start loading it
480  &fsm->slave_pdo);
482  fsm->state(fsm, datagram); // execute immediately
483  return;
484  }
485 
486  // pdo mapping is known, check if it most be re-configured
488 }
489 
490 /****************************************************************************/
491 
495  ec_fsm_pdo_t *fsm,
496  ec_datagram_t *datagram
497  )
498 {
499  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
500  return;
501  }
502 
504  EC_SLAVE_WARN(fsm->slave,
505  "Failed to read PDO entries for PDO 0x%04X.\n",
506  fsm->pdo->index);
507 
508  // check if the mapping must be re-configured
510 }
511 
512 /****************************************************************************/
513 
519  ec_fsm_pdo_t *fsm,
520  ec_datagram_t *datagram
521  )
522 {
523  // check, if slave supports PDO configuration
524  if ((fsm->slave->sii.mailbox_protocols & EC_MBOX_COE)
525  && fsm->slave->sii.has_general
527 
528  // always write PDO mapping
530  fsm->pdo, &fsm->slave_pdo);
532  fsm->state(fsm, datagram); // execure immediately
533  return;
534  }
535  else if (!ec_pdo_equal_entries(fsm->pdo, &fsm->slave_pdo)) {
536  EC_SLAVE_WARN(fsm->slave, "Slave does not support"
537  " changing the PDO mapping!\n");
538  EC_SLAVE_WARN(fsm->slave, "");
539  printk(KERN_CONT "Currently mapped PDO entries: ");
541  printk(KERN_CONT ". Entries to map: ");
543  printk(KERN_CONT "\n");
544  }
545 
547 }
548 
549 /****************************************************************************/
550 
554  ec_fsm_pdo_t *fsm,
555  ec_datagram_t *datagram
556  )
557 {
558  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
559  return;
560  }
561 
563  EC_SLAVE_WARN(fsm->slave,
564  "Failed to configure mapping of PDO 0x%04X.\n",
565  fsm->pdo->index);
566 
568 }
569 
570 /****************************************************************************/
571 
575  ec_fsm_pdo_t *fsm,
576  ec_datagram_t *datagram
577  )
578 {
579  // get next configured PDO
580  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
581  // no more configured pdos
583  return;
584  }
585 
586  ec_fsm_pdo_conf_action_pdo_mapping(fsm, datagram);
587 }
588 
589 /****************************************************************************/
590 
594  ec_fsm_pdo_t *fsm,
595  ec_datagram_t *datagram
596  )
597 {
598  if ((fsm->slave->sii.mailbox_protocols & EC_MBOX_COE)
599  && fsm->slave->sii.has_general
601 
602  // always write PDO assignment
603  if (fsm->slave->master->debug_level) {
604  EC_SLAVE_DBG(fsm->slave, 1, "Setting PDO assignment of SM%u:\n",
605  fsm->sync_index);
606  EC_SLAVE_DBG(fsm->slave, 1, ""); ec_fsm_pdo_print(fsm);
607  }
608 
609  if (ec_sdo_request_alloc(&fsm->request, 2)) {
611  return;
612  }
613 
614  // set mapped PDO count to zero
615  EC_WRITE_U8(fsm->request.data, 0); // zero PDOs mapped
616  fsm->request.data_size = 1;
617  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
619 
620  EC_SLAVE_DBG(fsm->slave, 1, "Setting number of assigned"
621  " PDOs to zero.\n");
622 
624  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
625  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
626  return;
627  }
628  else if (!ec_pdo_list_equal(&fsm->sync->pdos, &fsm->pdos)) {
629  EC_SLAVE_WARN(fsm->slave, "Slave does not support assigning PDOs!\n");
630  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
631  }
632 
633  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
634 }
635 
636 /****************************************************************************/
637 
641  ec_fsm_pdo_t *fsm,
642  ec_datagram_t *datagram
643  )
644 {
645  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
646  return;
647  }
648 
649  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
650  EC_SLAVE_WARN(fsm->slave, "Failed to clear PDO assignment of SM%u.\n",
651  fsm->sync_index);
652  EC_SLAVE_WARN(fsm->slave, "");
653  ec_fsm_pdo_print(fsm);
654  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
655  return;
656  }
657 
658  // the sync manager's assigned PDOs have been cleared
660 
661  // assign all PDOs belonging to the current sync manager
662 
663  // find first PDO
664  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdos.list))) {
665  // check for mapping to be altered
666  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
667  return;
668  }
669 
670  // assign first PDO
671  fsm->pdo_pos = 1;
672  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
673 }
674 
675 /****************************************************************************/
676 
680  ec_fsm_pdo_t *fsm,
681  ec_datagram_t *datagram
682  )
683 {
684  EC_WRITE_U16(fsm->request.data, fsm->pdo->index);
685  fsm->request.data_size = 2;
687  0x1C10 + fsm->sync_index, fsm->pdo_pos);
689 
690  EC_SLAVE_DBG(fsm->slave, 1, "Assigning PDO 0x%04X at position %u.\n",
691  fsm->pdo->index, fsm->pdo_pos);
692 
694  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
695  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
696 }
697 
698 /****************************************************************************/
699 
703  ec_fsm_pdo_t *fsm,
704  ec_datagram_t *datagram
705  )
706 {
707  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
708  return;
709  }
710 
711  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
712  EC_SLAVE_WARN(fsm->slave, "Failed to assign PDO 0x%04X at position %u"
713  " of SM%u.\n",
714  fsm->pdo->index, fsm->pdo_pos, fsm->sync_index);
715  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
717  return;
718  }
719 
720  // find next PDO
721  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
722  // no more PDOs to assign, set PDO count
723  EC_WRITE_U8(fsm->request.data, fsm->pdo_pos);
724  fsm->request.data_size = 1;
725  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
727 
728  EC_SLAVE_DBG(fsm->slave, 1,
729  "Setting number of assigned PDOs to %u.\n",
730  fsm->pdo_pos);
731 
733  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
734  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
735  return;
736  }
737 
738  // add next PDO to assignment
739  fsm->pdo_pos++;
740  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
741 }
742 
743 /****************************************************************************/
744 
748  ec_fsm_pdo_t *fsm,
749  ec_datagram_t *datagram
750  )
751 {
752  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
753  return;
754  }
755 
756  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
757  EC_SLAVE_WARN(fsm->slave, "Failed to set number of"
758  " assigned PDOs of SM%u.\n", fsm->sync_index);
759  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
761  return;
762  }
763 
764  // PDOs have been configured
765  ec_pdo_list_copy(&fsm->sync->pdos, &fsm->pdos);
766 
767  EC_SLAVE_DBG(fsm->slave, 1, "Successfully configured"
768  " PDO assignment of SM%u.\n", fsm->sync_index);
769 
770  // check if PDO mapping has to be altered
771  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
772 }
773 
774 /*****************************************************************************
775  * Common state functions
776  ****************************************************************************/
777 
781  ec_fsm_pdo_t *fsm,
782  ec_datagram_t *datagram
783  )
784 {
785 }
786 
787 /****************************************************************************/
788 
792  ec_fsm_pdo_t *fsm,
793  ec_datagram_t *datagram
794  )
795 {
796 }
797 
798 /****************************************************************************/
void(* state)(ec_fsm_pdo_t *, ec_datagram_t *)
State function.
Definition: fsm_pdo.h:48
CANopen over EtherCAT.
Definition: globals.h:146
void ec_fsm_pdo_conf_state_assign_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Add a PDO to the sync managers PDO assignment.
Definition: fsm_pdo.c:702
void ec_fsm_pdo_read_action_next_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Read next PDO.
Definition: fsm_pdo.c:271
ec_sii_t sii
Extracted SII data.
Definition: slave.h:215
int ec_fsm_pdo_exec(ec_fsm_pdo_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
Definition: fsm_pdo.c:156
ec_sdo_request_t request
SDO request.
Definition: fsm_pdo.h:52
void ec_fsm_pdo_conf_state_read_mapping(ec_fsm_pdo_t *, ec_datagram_t *)
Execute the PDO entry state machine to read the current PDO&#39;s mapping.
Definition: fsm_pdo.c:494
void ec_fsm_pdo_conf_action_next_sync(ec_fsm_pdo_t *, ec_datagram_t *)
Get the next sync manager for a pdo configuration.
Definition: fsm_pdo.c:410
#define EC_SLAVE_DBG(slave, level, fmt, args...)
Convenience macro for printing slave-specific debug messages to syslog.
Definition: slave.h:98
void ec_fsm_pdo_start_configuration(ec_fsm_pdo_t *fsm, ec_slave_t *slave)
Start writing the PDO configuration.
Definition: fsm_pdo.c:124
void ec_fsm_pdo_read_state_start(ec_fsm_pdo_t *, ec_datagram_t *)
Start reading PDO assignment.
Definition: fsm_pdo.c:185
void ec_pdo_list_print(const ec_pdo_list_t *pl)
Outputs the PDOs in the list.
Definition: pdo_list.c:321
void ec_fsm_pdo_conf_state_set_pdo_count(ec_fsm_pdo_t *, ec_datagram_t *)
Set the number of assigned PDOs.
Definition: fsm_pdo.c:747
int ec_pdo_list_copy(ec_pdo_list_t *pl, const ec_pdo_list_t *other)
Makes a deep copy of another PDO list.
Definition: pdo_list.c:169
void ec_fsm_pdo_print(ec_fsm_pdo_t *fsm)
Print the current and desired PDO assignment.
Definition: fsm_pdo.c:96
ec_slave_t * slave
Slave the FSM runs on.
Definition: fsm_pdo.h:55
#define EC_SLAVE_WARN(slave, fmt, args...)
Convenience macro for printing slave-specific warnings to syslog.
Definition: slave.h:82
ec_pdo_t * pdo
Current PDO.
Definition: fsm_pdo.h:58
void ec_pdo_list_clear(ec_pdo_list_t *pl)
PDO list destructor.
Definition: pdo_list.c:53
EtherCAT datagram.
Definition: datagram.h:79
struct list_head list
List of PDOs.
Definition: pdo_list.h:42
EtherCAT PDO configuration state machine structures.
ec_sii_coe_details_t coe_details
CoE detail flags.
Definition: slave.h:152
uint16_t index
SDO index.
Definition: sdo_request.h:42
#define EC_WRITE_U8(DATA, VAL)
Write an 8-bit unsigned value to EtherCAT data.
Definition: ecrt.h:2699
void ec_pdo_list_clear_pdos(ec_pdo_list_t *pl)
Clears the list of mapped PDOs.
Definition: pdo_list.c:62
void ec_fsm_pdo_entry_start_reading(ec_fsm_pdo_entry_t *fsm, ec_slave_t *slave, ec_pdo_t *pdo)
Start reading a PDO&#39;s entries.
Definition: fsm_pdo_entry.c:99
void ec_pdo_clear_entries(ec_pdo_t *pdo)
Clear PDO entry list.
Definition: pdo.c:98
void ec_pdo_init(ec_pdo_t *pdo)
PDO constructor.
Definition: pdo.c:38
const ec_pdo_t * ec_slave_find_pdo(const ec_slave_t *slave, uint16_t index)
Finds a mapped PDO.
Definition: slave.c:729
uint8_t * data
Pointer to SDO data.
Definition: sdo_request.h:44
int ec_fsm_coe_success(const ec_fsm_coe_t *fsm)
Returns, if the state machine terminated with success.
Definition: fsm_coe.c:254
void ec_fsm_pdo_conf_state_start(ec_fsm_pdo_t *, ec_datagram_t *)
Start PDO configuration.
Definition: fsm_pdo.c:375
ec_fsm_coe_t * fsm_coe
CoE state machine to use.
Definition: fsm_pdo.h:49
void ec_fsm_pdo_entry_start_configuration(ec_fsm_pdo_entry_t *fsm, ec_slave_t *slave, const ec_pdo_t *pdo, const ec_pdo_t *cur_pdo)
Start PDO mapping state machine.
int ec_fsm_pdo_running(const ec_fsm_pdo_t *fsm)
Get running state.
Definition: fsm_pdo.c:139
Global definitions and macros.
void ec_fsm_pdo_conf_state_mapping(ec_fsm_pdo_t *, ec_datagram_t *)
Let the PDO entry state machine configure the current PDO&#39;s mapping.
Definition: fsm_pdo.c:553
void ec_fsm_pdo_state_end(ec_fsm_pdo_t *, ec_datagram_t *)
State: END.
Definition: fsm_pdo.c:791
void ec_fsm_pdo_clear(ec_fsm_pdo_t *fsm)
Destructor.
Definition: fsm_pdo.c:82
EtherCAT master structure.
void ec_fsm_pdo_conf_action_pdo_mapping(ec_fsm_pdo_t *, ec_datagram_t *)
Check if the mapping has to be read, otherwise start to configure it.
Definition: fsm_pdo.c:459
void ec_pdo_clear(ec_pdo_t *pdo)
PDO destructor.
Definition: pdo.c:86
uint16_t index
PDO index.
Definition: pdo.h:43
int8_t sync_index
Assigned sync manager.
Definition: pdo.h:44
ec_pdo_t * ec_fsm_pdo_conf_action_next_pdo(const ec_fsm_pdo_t *fsm, const struct list_head *list)
Assign next PDO.
Definition: fsm_pdo.c:395
EtherCAT slave.
Definition: slave.h:168
void ec_fsm_pdo_state_error(ec_fsm_pdo_t *, ec_datagram_t *)
State: ERROR.
Definition: fsm_pdo.c:780
void ec_sdo_request_clear(ec_sdo_request_t *req)
SDO request destructor.
Definition: sdo_request.c:70
ec_sync_config_t sync_configs[EC_MAX_SYNC_MANAGERS]
Sync manager configurations.
Definition: slave_config.h:129
int ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index, uint8_t subindex)
Set the SDO index and subindex.
Definition: sdo_request.c:181
ec_slave_config_t * config
Current configuration.
Definition: slave.h:182
PDO description.
Definition: pdo.h:41
uint16_t mailbox_protocols
Supported mailbox protocols.
Definition: slave.h:139
void ec_fsm_pdo_start_reading(ec_fsm_pdo_t *fsm, ec_slave_t *slave)
Start reading the PDO configuration.
Definition: fsm_pdo.c:111
int ec_fsm_pdo_entry_success(const ec_fsm_pdo_entry_t *fsm)
Get execution result.
unsigned int debug_level
Master debug level.
Definition: master.h:271
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
Definition: slave.h:68
ec_pdo_list_t pdos
Current PDO assignment.
Definition: sync_config.h:41
int ecrt_sdo_request_write(ec_sdo_request_t *req)
Schedule an SDO write operation.
Definition: sdo_request.c:232
void ec_fsm_pdo_init(ec_fsm_pdo_t *fsm, ec_fsm_coe_t *fsm_coe)
Constructor.
Definition: fsm_pdo.c:66
int ec_fsm_pdo_entry_exec(ec_fsm_pdo_entry_t *fsm, ec_datagram_t *datagram)
Executes the current state.
int ec_pdo_equal_entries(const ec_pdo_t *pdo1, const ec_pdo_t *pdo2)
Compares the entries of two PDOs.
Definition: pdo.c:214
#define EC_WRITE_U16(DATA, VAL)
Write a 16-bit unsigned value to EtherCAT data.
Definition: ecrt.h:2716
struct list_head entries
List of PDO entries.
Definition: pdo.h:46
void ec_fsm_pdo_read_state_pdo_count(ec_fsm_pdo_t *, ec_datagram_t *)
Count assigned PDOs.
Definition: fsm_pdo.c:235
ec_master_t * master
Master owning the slave.
Definition: slave.h:170
void ec_fsm_pdo_conf_action_next_pdo_mapping(ec_fsm_pdo_t *, ec_datagram_t *)
Check mapping of next PDO, otherwise configure assignment.
Definition: fsm_pdo.c:574
uint8_t sync_index
Current sync manager index.
Definition: fsm_pdo.h:56
void ec_fsm_pdo_conf_action_check_mapping(ec_fsm_pdo_t *, ec_datagram_t *)
Check if the mapping has to be re-configured.
Definition: fsm_pdo.c:518
void ec_fsm_pdo_read_action_next_sync(ec_fsm_pdo_t *, ec_datagram_t *)
Read PDO assignment of next sync manager.
Definition: fsm_pdo.c:199
PDO configuration state machine.
Definition: fsm_pdo.h:46
uint8_t subindex
SDO subindex.
Definition: sdo_request.h:43
int ec_fsm_pdo_success(const ec_fsm_pdo_t *fsm)
Get execution result.
Definition: fsm_pdo.c:172
int ec_pdo_copy_entries(ec_pdo_t *pdo, const ec_pdo_t *other)
Copy PDO entries from another PDO.
Definition: pdo.c:178
void ec_fsm_pdo_entry_init(ec_fsm_pdo_entry_t *fsm, ec_fsm_coe_t *fsm_coe)
Constructor.
Definition: fsm_pdo_entry.c:60
size_t data_size
Size of SDO data.
Definition: sdo_request.h:46
#define EC_READ_U16(DATA)
Read a 16-bit unsigned value from EtherCAT data.
Definition: ecrt.h:2611
Mailbox functionality.
void ec_sdo_request_init(ec_sdo_request_t *req)
SDO request constructor.
Definition: sdo_request.c:48
ec_sync_t * sync
Current sync manager.
Definition: fsm_pdo.h:57
int ec_fsm_coe_exec(ec_fsm_coe_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
Definition: fsm_coe.c:220
int ecrt_sdo_request_read(ec_sdo_request_t *req)
Schedule an SDO read operation.
Definition: sdo_request.c:220
unsigned int pdo_count
Number of assigned PDOs.
Definition: fsm_pdo.h:60
ec_pdo_list_t pdos
Current PDO assignment.
Definition: sync.h:45
void ec_pdo_list_init(ec_pdo_list_t *pl)
PDO list constructor.
Definition: pdo_list.c:42
void ec_fsm_pdo_read_state_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Fetch PDO information.
Definition: fsm_pdo.c:299
void ec_pdo_print_entries(const ec_pdo_t *pdo)
Outputs the PDOs in the list.
Definition: pdo.c:291
void ec_fsm_pdo_conf_action_check_assignment(ec_fsm_pdo_t *, ec_datagram_t *)
Check if the PDO assignment of the current SM has to be re-configured.
Definition: fsm_pdo.c:593
#define EC_READ_U8(DATA)
Read an 8-bit unsigned value from EtherCAT data.
Definition: ecrt.h:2595
void ec_fsm_pdo_conf_action_assign_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Assign a PDO.
Definition: fsm_pdo.c:679
EtherCAT slave configuration structure.
void ec_fsm_pdo_entry_clear(ec_fsm_pdo_entry_t *fsm)
Destructor.
Definition: fsm_pdo_entry.c:73
void ec_fsm_coe_transfer(ec_fsm_coe_t *fsm, ec_slave_t *slave, ec_sdo_request_t *request)
Starts to transfer an SDO to/from a slave.
Definition: fsm_coe.c:197
int ec_sdo_request_alloc(ec_sdo_request_t *req, size_t size)
Pre-allocates the data memory.
Definition: sdo_request.c:121
int ec_pdo_list_equal(const ec_pdo_list_t *pl1, const ec_pdo_list_t *pl2)
Compares two PDO lists.
Definition: pdo_list.c:199
ec_fsm_pdo_entry_t fsm_pdo_entry
PDO entry state machine.
Definition: fsm_pdo.h:50
struct list_head list
List item.
Definition: pdo.h:42
uint8_t enable_pdo_configuration
PDO configuration possible.
Definition: globals.h:158
void ec_fsm_pdo_conf_state_zero_pdo_count(ec_fsm_pdo_t *, ec_datagram_t *)
Set the number of assigned PDOs to zero.
Definition: fsm_pdo.c:640
#define EC_MAX_SYNC_MANAGERS
Maximum number of sync managers per slave.
Definition: ecrt.h:264
ec_pdo_list_t pdos
PDO configuration.
Definition: fsm_pdo.h:51
void ec_fsm_pdo_read_state_pdo_entries(ec_fsm_pdo_t *, ec_datagram_t *)
Fetch PDO information.
Definition: fsm_pdo.c:348
unsigned int pdo_pos
Assignment position of current PDOs.
Definition: fsm_pdo.h:59
unsigned int has_general
General category present.
Definition: slave.h:146
ec_pdo_t slave_pdo
PDO actually appearing in a slave.
Definition: fsm_pdo.h:53
Finite state machines for the CANopen over EtherCAT protocol.
Definition: fsm_coe.h:44
ec_sync_t * ec_slave_get_sync(ec_slave_t *slave, uint8_t sync_index)
Get the sync manager given an index.
Definition: slave.c:594
uint8_t enable_pdo_assign
PDO mapping configurable.
Definition: globals.h:157