IgH EtherCAT Master  1.7.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 
37 // prototypes for private methods
38 void ec_fsm_pdo_print(const ec_fsm_pdo_t *);
39 int ec_fsm_pdo_running(const ec_fsm_pdo_t *);
41  const struct list_head *);
43 
44 /****************************************************************************/
45 
50 
53 
60 
67 
70 
71 /****************************************************************************/
72 
76  ec_fsm_pdo_t *fsm,
77  ec_fsm_coe_t *fsm_coe
78  )
79 {
80  fsm->fsm_coe = fsm_coe;
81  ec_fsm_pdo_entry_init(&fsm->fsm_pdo_entry, fsm_coe);
82  ec_pdo_list_init(&fsm->pdos);
84  ec_pdo_init(&fsm->slave_pdo);
85 }
86 
87 /****************************************************************************/
88 
92  ec_fsm_pdo_t *fsm
93  )
94 {
96  ec_pdo_list_clear(&fsm->pdos);
98  ec_pdo_clear(&fsm->slave_pdo);
99 }
100 
101 /****************************************************************************/
102 
106  const ec_fsm_pdo_t *fsm
107  )
108 {
109  printk(KERN_CONT "Currently assigned PDOs: ");
110  ec_pdo_list_print(&fsm->sync->pdos);
111  printk(KERN_CONT ". PDOs to assign: ");
112  ec_pdo_list_print(&fsm->pdos);
113  printk(KERN_CONT "\n");
114 }
115 
116 /****************************************************************************/
117 
121  ec_fsm_pdo_t *fsm,
122  ec_slave_t *slave,
123  ec_pdo_mode_t assign_mode,
125  ec_pdo_mode_t config_mode
127  )
128 {
129  fsm->slave = slave;
130  fsm->assign_mode = assign_mode;
131  fsm->config_mode = config_mode;
133 }
134 
135 /****************************************************************************/
136 
140  ec_fsm_pdo_t *fsm,
141  ec_slave_t *slave
142  )
143 {
144  fsm->slave = slave;
146 }
147 
148 /****************************************************************************/
149 
155  const ec_fsm_pdo_t *fsm
156  )
157 {
158  return fsm->state != ec_fsm_pdo_state_end
159  && fsm->state != ec_fsm_pdo_state_error;
160 }
161 
162 /****************************************************************************/
163 
172  ec_fsm_pdo_t *fsm,
173  ec_datagram_t *datagram
174  )
175 {
176  fsm->state(fsm, datagram);
177 
178  return ec_fsm_pdo_running(fsm);
179 }
180 
181 /****************************************************************************/
182 
188  const ec_fsm_pdo_t *fsm
189  )
190 {
191  return fsm->state == ec_fsm_pdo_state_end;
192 }
193 
194 /****************************************************************************/
195 
198 static int ec_pdo_mode_reads(
199  ec_pdo_mode_t mode
200  )
201 {
202  return mode == EC_PDO_MODE_READ_WRITE
204 }
205 
206 /*****************************************************************************
207  * Reading state funtions.
208  ****************************************************************************/
209 
213  ec_fsm_pdo_t *fsm,
214  ec_datagram_t *datagram
215  )
216 {
217  // read PDO assignment for first sync manager not reserved for mailbox
218  fsm->sync_index = 1; // next is 2
219  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
220 }
221 
222 /****************************************************************************/
223 
227  ec_fsm_pdo_t *fsm,
228  ec_datagram_t *datagram
229  )
230 {
231  ec_slave_t *slave = fsm->slave;
232 
233  fsm->sync_index++;
234 
235  for (; fsm->sync_index < EC_MAX_SYNC_MANAGERS; fsm->sync_index++) {
236  if (!(fsm->sync = ec_slave_get_sync(slave, fsm->sync_index)))
237  continue;
238 
239  // reading the PDO configuration requires first discovering the PDO
240  // assignment, so a read is done if either aspect is to be read
241  if (!ec_pdo_mode_reads(fsm->assign_mode)
242  && !ec_pdo_mode_reads(fsm->config_mode)) {
243  continue;
244  }
245 
246  EC_SLAVE_DBG(slave, 1, "Reading PDO assignment of SM%u.\n",
247  fsm->sync_index);
248 
250 
251  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
254  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
255  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
256  return;
257  }
258 
259  EC_SLAVE_DBG(slave, 1, "Reading of PDO configuration finished.\n");
260 
263 }
264 
265 /****************************************************************************/
266 
270  ec_fsm_pdo_t *fsm,
271  ec_datagram_t *datagram
272  )
273 {
274  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
275  return;
276  }
277 
278  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
279  EC_SLAVE_ERR(fsm->slave, "Failed to read number of assigned PDOs"
280  " for SM%u.\n", fsm->sync_index);
281  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
282  return;
283  }
284 
285  if (fsm->request.data_size != sizeof(uint8_t)) {
286  EC_SLAVE_ERR(fsm->slave, "Invalid data size %zu returned"
287  " when uploading SDO 0x%04X:%02X.\n", fsm->request.data_size,
288  fsm->request.index, fsm->request.subindex);
289  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
290  return;
291  }
292  fsm->pdo_count = EC_READ_U8(fsm->request.data);
293 
294  EC_SLAVE_DBG(fsm->slave, 1, "%u PDOs assigned.\n", fsm->pdo_count);
295 
296  // read first PDO
297  fsm->pdo_pos = 1;
298  ec_fsm_pdo_read_action_next_pdo(fsm, datagram);
299 }
300 
301 /****************************************************************************/
302 
306  ec_fsm_pdo_t *fsm,
307  ec_datagram_t *datagram
308  )
309 {
310  if (fsm->pdo_pos <= fsm->pdo_count) {
311  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index,
312  fsm->pdo_pos);
315  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
316  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
317  return;
318  }
319 
320  // finished reading PDO configuration
321 
322  ec_pdo_list_copy(&fsm->sync->pdos, &fsm->pdos);
324 
325  // next sync manager
326  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
327 }
328 
329 /****************************************************************************/
330 
334  ec_fsm_pdo_t *fsm,
335  ec_datagram_t *datagram
336  )
337 {
338  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
339  return;
340  }
341 
342  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
343  EC_SLAVE_ERR(fsm->slave, "Failed to read index of"
344  " assigned PDO %u from SM%u.\n",
345  fsm->pdo_pos, fsm->sync_index);
346  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
347  return;
348  }
349 
350  if (fsm->request.data_size != sizeof(uint16_t)) {
351  EC_SLAVE_ERR(fsm->slave, "Invalid data size %zu returned"
352  " when uploading SDO 0x%04X:%02X.\n", fsm->request.data_size,
353  fsm->request.index, fsm->request.subindex);
354  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
355  return;
356  }
357 
358  if (!(fsm->pdo = (ec_pdo_t *)
359  kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
360  EC_SLAVE_ERR(fsm->slave, "Failed to allocate PDO.\n");
361  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
362  return;
363  }
364 
365  ec_pdo_init(fsm->pdo);
366  fsm->pdo->index = EC_READ_U16(fsm->request.data);
367  fsm->pdo->sync_index = fsm->sync_index;
368 
369  EC_SLAVE_DBG(fsm->slave, 1, "PDO 0x%04X.\n", fsm->pdo->index);
370 
371  list_add_tail(&fsm->pdo->list, &fsm->pdos.list);
372 
373  if (!ec_pdo_mode_reads(fsm->config_mode)) {
374  // PDO assignment only; the entries mapped into this PDO are not
375  // to be read
376  fsm->pdo_pos++;
377  ec_fsm_pdo_read_action_next_pdo(fsm, datagram);
378  return;
379  }
380 
383  fsm->state(fsm, datagram); // execute immediately
384 }
385 
386 /****************************************************************************/
387 
391  ec_fsm_pdo_t *fsm,
392  ec_datagram_t *datagram
393  )
394 {
395  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
396  return;
397  }
398 
400  EC_SLAVE_ERR(fsm->slave, "Failed to read mapped PDO entries"
401  " for PDO 0x%04X.\n", fsm->pdo->index);
402  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
403  return;
404  }
405 
406  // next PDO
407  fsm->pdo_pos++;
408  ec_fsm_pdo_read_action_next_pdo(fsm, datagram);
409 }
410 
411 /*****************************************************************************
412  * Writing state functions.
413  ****************************************************************************/
414 
418  ec_fsm_pdo_t *fsm,
419  ec_datagram_t *datagram
420  )
421 {
422  if (!fsm->slave->config) {
424  return;
425  }
426 
427  fsm->sync_index = 1; // next is 2
428  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
429 }
430 
431 /****************************************************************************/
432 
438  const ec_fsm_pdo_t *fsm,
439  const struct list_head *list
440  )
441 {
442  list = list->next;
443  if (list == &fsm->pdos.list)
444  return NULL; // no next PDO
445  return list_entry(list, ec_pdo_t, list);
446 }
447 
448 /****************************************************************************/
449 
453  ec_fsm_pdo_t *fsm,
454  ec_datagram_t *datagram
455  )
456 {
457  fsm->sync_index++;
458 
459  for (; fsm->sync_index < EC_MAX_SYNC_MANAGERS; fsm->sync_index++) {
460  if (!fsm->slave->config) {
461  // slave configuration removed in the meantime
463  return;
464  }
465 
466  fsm->assign_mode = fsm->slave->config->pdo_assign_mode;
467  fsm->config_mode = fsm->slave->config->pdo_config_mode;
468 
469  if (ec_pdo_list_copy(&fsm->pdos,
470  &fsm->slave->config->sync_configs[fsm->sync_index].pdos))
471  {
473  return;
474  }
475 
476  if (!(fsm->sync = ec_slave_get_sync(fsm->slave, fsm->sync_index))) {
477  if (!list_empty(&fsm->pdos.list))
478  EC_SLAVE_WARN(fsm->slave, "PDOs configured for SM%u,"
479  " but slave does not provide the"
480  " sync manager information!\n",
481  fsm->sync_index);
482  continue;
483  }
484 
485  // get first configured PDO
486  if (!(fsm->pdo =
488  // no pdos configured
490  return;
491  }
492 
493  ec_fsm_pdo_conf_action_pdo_mapping(fsm, datagram);
494  return;
495  }
496 
498 }
499 
500 /****************************************************************************/
501 
505  ec_fsm_pdo_t *fsm,
506  ec_datagram_t *datagram
507  )
508 {
509  const ec_pdo_t *assigned_pdo;
510 
511  fsm->slave_pdo.index = fsm->pdo->index;
512 
513  if ((assigned_pdo = ec_slave_find_pdo(fsm->slave, fsm->pdo->index))) {
514  ec_pdo_copy_entries(&fsm->slave_pdo, assigned_pdo);
515  } else { // configured PDO is not assigned and thus unknown
517  }
518 
519  if (list_empty(&fsm->slave_pdo.entries)
520  && ec_pdo_mode_reads(fsm->config_mode)) {
521  EC_SLAVE_DBG(fsm->slave, 1, "Reading mapping of PDO 0x%04X.\n",
522  fsm->pdo->index);
523 
524  // pdo mapping is unknown; start loading it
526  &fsm->slave_pdo);
528  fsm->state(fsm, datagram); // execute immediately
529  return;
530  }
531 
532  // pdo mapping is known, check if it most be re-configured
534 }
535 
536 /****************************************************************************/
537 
541  ec_fsm_pdo_t *fsm,
542  ec_datagram_t *datagram
543  )
544 {
545  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
546  return;
547  }
548 
550  EC_SLAVE_WARN(fsm->slave,
551  "Failed to read PDO entries for PDO 0x%04X.\n",
552  fsm->pdo->index);
553 
554  // check if the mapping must be re-configured
556 }
557 
558 /****************************************************************************/
559 
565  ec_fsm_pdo_t *fsm,
566  ec_datagram_t *datagram
567  )
568 {
569  if (fsm->config_mode == EC_PDO_MODE_FIXED) {
570  // PDO configuration is trusted to already match; do not touch it
572  return;
573  }
574 
575  // check, if slave supports PDO configuration
576  if ((fsm->slave->sii.mailbox_protocols & EC_MBOX_COE)
577  && fsm->slave->sii.has_general
580  && ec_pdo_equal_entries(fsm->pdo, &fsm->slave_pdo)) {
581  // mapping already matches the desired configuration
583  return;
584  }
585 
586  // write PDO mapping
588  fsm->pdo, &fsm->slave_pdo);
590  fsm->state(fsm, datagram); // execure immediately
591  return;
592  }
593  else if (!ec_pdo_equal_entries(fsm->pdo, &fsm->slave_pdo)) {
594  EC_SLAVE_WARN(fsm->slave, "Slave does not support"
595  " changing the PDO mapping!\n");
596  EC_SLAVE_WARN(fsm->slave, "");
597  printk(KERN_CONT "Currently mapped PDO entries: ");
599  printk(KERN_CONT ". Entries to map: ");
601  printk(KERN_CONT "\n");
602  }
603 
605 }
606 
607 /****************************************************************************/
608 
612  ec_fsm_pdo_t *fsm,
613  ec_datagram_t *datagram
614  )
615 {
616  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
617  return;
618  }
619 
621  EC_SLAVE_WARN(fsm->slave,
622  "Failed to configure mapping of PDO 0x%04X.\n",
623  fsm->pdo->index);
624 
626 }
627 
628 /****************************************************************************/
629 
633  ec_fsm_pdo_t *fsm,
634  ec_datagram_t *datagram
635  )
636 {
637  // get next configured PDO
638  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
639  // no more configured pdos
641  return;
642  }
643 
644  ec_fsm_pdo_conf_action_pdo_mapping(fsm, datagram);
645 }
646 
647 /****************************************************************************/
648 
652  ec_fsm_pdo_t *fsm,
653  ec_datagram_t *datagram
654  )
655 {
656  if (fsm->assign_mode == EC_PDO_MODE_FIXED) {
657  // PDO assignment is trusted to already match; do not touch it
658  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
659  return;
660  }
661 
662  if ((fsm->slave->sii.mailbox_protocols & EC_MBOX_COE)
663  && fsm->slave->sii.has_general
666  && ec_pdo_list_equal(&fsm->sync->pdos, &fsm->pdos)) {
667  // assignment already matches the desired configuration
668  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
669  return;
670  }
671 
672  // write PDO assignment
673  if (fsm->slave->master->debug_level) {
674  EC_SLAVE_DBG(fsm->slave, 1, "Setting PDO assignment of SM%u:\n",
675  fsm->sync_index);
676  EC_SLAVE_DBG(fsm->slave, 1, ""); ec_fsm_pdo_print(fsm);
677  }
678 
679  if (ec_sdo_request_alloc(&fsm->request, 2)) {
681  return;
682  }
683 
684  // set mapped PDO count to zero
685  EC_WRITE_U8(fsm->request.data, 0); // zero PDOs mapped
686  fsm->request.data_size = 1;
687  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
689 
690  EC_SLAVE_DBG(fsm->slave, 1, "Setting number of assigned"
691  " PDOs to zero.\n");
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  return;
697  }
698  else if (!ec_pdo_list_equal(&fsm->sync->pdos, &fsm->pdos)) {
699  EC_SLAVE_WARN(fsm->slave, "Slave does not support assigning PDOs!\n");
700  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
701  }
702 
703  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
704 }
705 
706 /****************************************************************************/
707 
711  ec_fsm_pdo_t *fsm,
712  ec_datagram_t *datagram
713  )
714 {
715  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
716  return;
717  }
718 
719  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
720  EC_SLAVE_WARN(fsm->slave, "Failed to clear PDO assignment of SM%u.\n",
721  fsm->sync_index);
722  EC_SLAVE_WARN(fsm->slave, "");
723  ec_fsm_pdo_print(fsm);
724  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
725  return;
726  }
727 
728  // the sync manager's assigned PDOs have been cleared
730 
731  // assign all PDOs belonging to the current sync manager
732 
733  // find first PDO
734  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdos.list))) {
735  // check for mapping to be altered
736  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
737  return;
738  }
739 
740  // assign first PDO
741  fsm->pdo_pos = 1;
742  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
743 }
744 
745 /****************************************************************************/
746 
750  ec_fsm_pdo_t *fsm,
751  ec_datagram_t *datagram
752  )
753 {
754  EC_WRITE_U16(fsm->request.data, fsm->pdo->index);
755  fsm->request.data_size = 2;
757  0x1C10 + fsm->sync_index, fsm->pdo_pos);
759 
760  EC_SLAVE_DBG(fsm->slave, 1, "Assigning PDO 0x%04X at position %u.\n",
761  fsm->pdo->index, fsm->pdo_pos);
762 
764  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
765  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
766 }
767 
768 /****************************************************************************/
769 
773  ec_fsm_pdo_t *fsm,
774  ec_datagram_t *datagram
775  )
776 {
777  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
778  return;
779  }
780 
781  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
782  EC_SLAVE_WARN(fsm->slave, "Failed to assign PDO 0x%04X at position %u"
783  " of SM%u.\n",
784  fsm->pdo->index, fsm->pdo_pos, fsm->sync_index);
785  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
787  return;
788  }
789 
790  // find next PDO
791  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
792  // no more PDOs to assign, set PDO count
793  EC_WRITE_U8(fsm->request.data, fsm->pdo_pos);
794  fsm->request.data_size = 1;
795  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
797 
798  EC_SLAVE_DBG(fsm->slave, 1,
799  "Setting number of assigned PDOs to %u.\n",
800  fsm->pdo_pos);
801 
803  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
804  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
805  return;
806  }
807 
808  // add next PDO to assignment
809  fsm->pdo_pos++;
810  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
811 }
812 
813 /****************************************************************************/
814 
818  ec_fsm_pdo_t *fsm,
819  ec_datagram_t *datagram
820  )
821 {
822  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
823  return;
824  }
825 
826  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
827  EC_SLAVE_WARN(fsm->slave, "Failed to set number of"
828  " assigned PDOs of SM%u.\n", fsm->sync_index);
829  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
831  return;
832  }
833 
834  // PDOs have been configured
835  ec_pdo_list_copy(&fsm->sync->pdos, &fsm->pdos);
836 
837  EC_SLAVE_DBG(fsm->slave, 1, "Successfully configured"
838  " PDO assignment of SM%u.\n", fsm->sync_index);
839 
840  // check if PDO mapping has to be altered
841  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
842 }
843 
844 /*****************************************************************************
845  * Common state functions
846  ****************************************************************************/
847 
851  ec_fsm_pdo_t *fsm,
852  ec_datagram_t *datagram
853  )
854 {
855 }
856 
857 /****************************************************************************/
858 
862  ec_fsm_pdo_t *fsm,
863  ec_datagram_t *datagram
864  )
865 {
866 }
867 
868 /****************************************************************************/
void(* state)(ec_fsm_pdo_t *, ec_datagram_t *)
State function.
Definition: fsm_pdo.h:48
CANopen over EtherCAT.
Definition: globals.h:152
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:772
void ec_fsm_pdo_read_action_next_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Read next PDO.
Definition: fsm_pdo.c:305
ec_sii_t sii
Extracted SII data.
Definition: slave.h:217
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:171
Neither read nor write via CoE.
Definition: ecrt.h:552
ec_sdo_request_t request
SDO request.
Definition: fsm_pdo.h:52
int ecrt_sdo_request_write(ec_sdo_request_t *req)
Schedule an SDO write operation.
Definition: sdo_request.c:232
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:540
ec_pdo_mode_t
PDO handling mode.
Definition: ecrt.h:551
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:452
#define EC_SLAVE_DBG(slave, level, fmt, args...)
Convenience macro for printing slave-specific debug messages to syslog.
Definition: slave.h:99
void ec_fsm_pdo_start_configuration(ec_fsm_pdo_t *fsm, ec_slave_t *slave)
Start writing the PDO configuration.
Definition: fsm_pdo.c:139
void ec_fsm_pdo_read_state_start(ec_fsm_pdo_t *, ec_datagram_t *)
Start reading PDO assignment.
Definition: fsm_pdo.c:212
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:817
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
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:83
int ecrt_sdo_request_read(ec_sdo_request_t *req)
Schedule an SDO read operation.
Definition: sdo_request.c:220
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:153
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:3298
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.
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:950
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:267
ec_pdo_mode_t pdo_config_mode
Whether/how to read resp.
Definition: slave_config.h:129
void ec_fsm_pdo_conf_state_start(ec_fsm_pdo_t *, ec_datagram_t *)
Start PDO configuration.
Definition: fsm_pdo.c:417
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 *)
Get running state.
Definition: fsm_pdo.c:154
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:611
void ec_fsm_pdo_state_end(ec_fsm_pdo_t *, ec_datagram_t *)
State: END.
Definition: fsm_pdo.c:861
void ec_fsm_pdo_clear(ec_fsm_pdo_t *fsm)
Destructor.
Definition: fsm_pdo.c:91
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:504
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
void ec_fsm_pdo_print(const ec_fsm_pdo_t *)
Print the current and desired PDO assignment.
Definition: fsm_pdo.c:105
EtherCAT slave.
Definition: slave.h:169
void ec_fsm_pdo_state_error(ec_fsm_pdo_t *, ec_datagram_t *)
State: ERROR.
Definition: fsm_pdo.c:850
void ec_sdo_request_clear(ec_sdo_request_t *req)
SDO request destructor.
Definition: sdo_request.c:70
Read the current state via CoE while scanning the slave, and write it back only if it differs from th...
Definition: ecrt.h:562
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_sync_config_t sync_configs[EC_MAX_SYNC_MANAGERS]
Sync manager configurations.
Definition: slave_config.h:136
ec_pdo_mode_t pdo_assign_mode
Whether/how to read resp.
Definition: slave_config.h:126
ec_slave_config_t * config
Current configuration.
Definition: slave.h:183
PDO description.
Definition: pdo.h:41
uint16_t mailbox_protocols
Supported mailbox protocols.
Definition: slave.h:140
static int ec_pdo_mode_reads(ec_pdo_mode_t)
Returns, if the given PDO handling mode implies reading via CoE.
Definition: fsm_pdo.c:198
Read the current state via CoE while scanning the slave, and unconditionally (re-)write it every time...
Definition: ecrt.h:558
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:277
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
Definition: slave.h:69
void ec_fsm_pdo_start_reading(ec_fsm_pdo_t *fsm, ec_slave_t *slave, ec_pdo_mode_t assign_mode, ec_pdo_mode_t config_mode)
Start reading the PDO configuration.
Definition: fsm_pdo.c:120
ec_pdo_list_t pdos
Current PDO assignment.
Definition: sync_config.h:41
void ec_fsm_pdo_init(ec_fsm_pdo_t *fsm, ec_fsm_coe_t *fsm_coe)
Constructor.
Definition: fsm_pdo.c:75
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:3315
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:269
ec_pdo_t * ec_fsm_pdo_conf_action_next_pdo(const ec_fsm_pdo_t *, const struct list_head *)
Assign next PDO.
Definition: fsm_pdo.c:437
ec_master_t * master
Master owning the slave.
Definition: slave.h:171
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:632
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:564
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:226
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:187
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:68
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:3206
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:233
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:333
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:651
#define EC_READ_U8(DATA)
Read an 8-bit unsigned value from EtherCAT data.
Definition: ecrt.h:3190
void ec_fsm_pdo_conf_action_assign_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Assign a PDO.
Definition: fsm_pdo.c:749
ec_pdo_mode_t config_mode
Whether/how to read resp.
Definition: fsm_pdo.h:67
EtherCAT slave configuration structure.
void ec_fsm_pdo_entry_clear(ec_fsm_pdo_entry_t *fsm)
Destructor.
Definition: fsm_pdo_entry.c:81
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:210
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_pdo_mode_t assign_mode
Whether/how to read resp.
Definition: fsm_pdo.h:62
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:164
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:710
#define EC_MAX_SYNC_MANAGERS
Maximum number of sync managers per slave.
Definition: ecrt.h:285
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:390
unsigned int pdo_pos
Assignment position of current PDOs.
Definition: fsm_pdo.h:59
unsigned int has_general
General category present.
Definition: slave.h:147
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:815
uint8_t enable_pdo_assign
PDO mapping configurable.
Definition: globals.h:163