IgH EtherCAT Master  1.6.2
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 *);
42 
43 /****************************************************************************/
44 
49 
52 
59 
66 
69 
70 /****************************************************************************/
71 
75  ec_fsm_pdo_t *fsm,
76  ec_fsm_coe_t *fsm_coe
77  )
78 {
79  fsm->fsm_coe = fsm_coe;
80  ec_fsm_pdo_entry_init(&fsm->fsm_pdo_entry, fsm_coe);
81  ec_pdo_list_init(&fsm->pdos);
83  ec_pdo_init(&fsm->slave_pdo);
84 }
85 
86 /****************************************************************************/
87 
91  ec_fsm_pdo_t *fsm
92  )
93 {
95  ec_pdo_list_clear(&fsm->pdos);
97  ec_pdo_clear(&fsm->slave_pdo);
98 }
99 
100 /****************************************************************************/
101 
105  const ec_fsm_pdo_t *fsm
106  )
107 {
108  printk(KERN_CONT "Currently assigned PDOs: ");
109  ec_pdo_list_print(&fsm->sync->pdos);
110  printk(KERN_CONT ". PDOs to assign: ");
111  ec_pdo_list_print(&fsm->pdos);
112  printk(KERN_CONT "\n");
113 }
114 
115 /****************************************************************************/
116 
120  ec_fsm_pdo_t *fsm,
121  ec_slave_t *slave
122  )
123 {
124  fsm->slave = slave;
126 }
127 
128 /****************************************************************************/
129 
133  ec_fsm_pdo_t *fsm,
134  ec_slave_t *slave
135  )
136 {
137  fsm->slave = slave;
139 }
140 
141 /****************************************************************************/
142 
148  const ec_fsm_pdo_t *fsm
149  )
150 {
151  return fsm->state != ec_fsm_pdo_state_end
152  && fsm->state != ec_fsm_pdo_state_error;
153 }
154 
155 /****************************************************************************/
156 
165  ec_fsm_pdo_t *fsm,
166  ec_datagram_t *datagram
167  )
168 {
169  fsm->state(fsm, datagram);
170 
171  return ec_fsm_pdo_running(fsm);
172 }
173 
174 /****************************************************************************/
175 
181  const ec_fsm_pdo_t *fsm
182  )
183 {
184  return fsm->state == ec_fsm_pdo_state_end;
185 }
186 
187 /*****************************************************************************
188  * Reading state funtions.
189  ****************************************************************************/
190 
194  ec_fsm_pdo_t *fsm,
195  ec_datagram_t *datagram
196  )
197 {
198  // read PDO assignment for first sync manager not reserved for mailbox
199  fsm->sync_index = 1; // next is 2
200  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
201 }
202 
203 /****************************************************************************/
204 
208  ec_fsm_pdo_t *fsm,
209  ec_datagram_t *datagram
210  )
211 {
212  ec_slave_t *slave = fsm->slave;
213 
214  fsm->sync_index++;
215 
216  for (; fsm->sync_index < EC_MAX_SYNC_MANAGERS; fsm->sync_index++) {
217  if (!(fsm->sync = ec_slave_get_sync(slave, fsm->sync_index)))
218  continue;
219 
220  EC_SLAVE_DBG(slave, 1, "Reading PDO assignment of SM%u.\n",
221  fsm->sync_index);
222 
224 
225  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
228  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
229  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
230  return;
231  }
232 
233  EC_SLAVE_DBG(slave, 1, "Reading of PDO configuration finished.\n");
234 
237 }
238 
239 /****************************************************************************/
240 
244  ec_fsm_pdo_t *fsm,
245  ec_datagram_t *datagram
246  )
247 {
248  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
249  return;
250  }
251 
252  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
253  EC_SLAVE_ERR(fsm->slave, "Failed to read number of assigned PDOs"
254  " for SM%u.\n", fsm->sync_index);
255  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
256  return;
257  }
258 
259  if (fsm->request.data_size != sizeof(uint8_t)) {
260  EC_SLAVE_ERR(fsm->slave, "Invalid data size %zu returned"
261  " when uploading SDO 0x%04X:%02X.\n", fsm->request.data_size,
262  fsm->request.index, fsm->request.subindex);
263  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
264  return;
265  }
266  fsm->pdo_count = EC_READ_U8(fsm->request.data);
267 
268  EC_SLAVE_DBG(fsm->slave, 1, "%u PDOs assigned.\n", fsm->pdo_count);
269 
270  // read first PDO
271  fsm->pdo_pos = 1;
272  ec_fsm_pdo_read_action_next_pdo(fsm, datagram);
273 }
274 
275 /****************************************************************************/
276 
280  ec_fsm_pdo_t *fsm,
281  ec_datagram_t *datagram
282  )
283 {
284  if (fsm->pdo_pos <= fsm->pdo_count) {
285  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index,
286  fsm->pdo_pos);
289  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
290  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
291  return;
292  }
293 
294  // finished reading PDO configuration
295 
296  ec_pdo_list_copy(&fsm->sync->pdos, &fsm->pdos);
298 
299  // next sync manager
300  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
301 }
302 
303 /****************************************************************************/
304 
308  ec_fsm_pdo_t *fsm,
309  ec_datagram_t *datagram
310  )
311 {
312  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
313  return;
314  }
315 
316  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
317  EC_SLAVE_ERR(fsm->slave, "Failed to read index of"
318  " assigned PDO %u from SM%u.\n",
319  fsm->pdo_pos, fsm->sync_index);
320  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
321  return;
322  }
323 
324  if (fsm->request.data_size != sizeof(uint16_t)) {
325  EC_SLAVE_ERR(fsm->slave, "Invalid data size %zu returned"
326  " when uploading SDO 0x%04X:%02X.\n", fsm->request.data_size,
327  fsm->request.index, fsm->request.subindex);
328  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
329  return;
330  }
331 
332  if (!(fsm->pdo = (ec_pdo_t *)
333  kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
334  EC_SLAVE_ERR(fsm->slave, "Failed to allocate PDO.\n");
335  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
336  return;
337  }
338 
339  ec_pdo_init(fsm->pdo);
340  fsm->pdo->index = EC_READ_U16(fsm->request.data);
341  fsm->pdo->sync_index = fsm->sync_index;
342 
343  EC_SLAVE_DBG(fsm->slave, 1, "PDO 0x%04X.\n", fsm->pdo->index);
344 
345  list_add_tail(&fsm->pdo->list, &fsm->pdos.list);
346 
349  fsm->state(fsm, datagram); // execute immediately
350 }
351 
352 /****************************************************************************/
353 
357  ec_fsm_pdo_t *fsm,
358  ec_datagram_t *datagram
359  )
360 {
361  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
362  return;
363  }
364 
366  EC_SLAVE_ERR(fsm->slave, "Failed to read mapped PDO entries"
367  " for PDO 0x%04X.\n", fsm->pdo->index);
368  ec_fsm_pdo_read_action_next_sync(fsm, datagram);
369  return;
370  }
371 
372  // next PDO
373  fsm->pdo_pos++;
374  ec_fsm_pdo_read_action_next_pdo(fsm, datagram);
375 }
376 
377 /*****************************************************************************
378  * Writing state functions.
379  ****************************************************************************/
380 
384  ec_fsm_pdo_t *fsm,
385  ec_datagram_t *datagram
386  )
387 {
388  if (!fsm->slave->config) {
390  return;
391  }
392 
393  fsm->sync_index = 1; // next is 2
394  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
395 }
396 
397 /****************************************************************************/
398 
404  const ec_fsm_pdo_t *fsm,
405  const struct list_head *list
406  )
407 {
408  list = list->next;
409  if (list == &fsm->pdos.list)
410  return NULL; // no next PDO
411  return list_entry(list, ec_pdo_t, list);
412 }
413 
414 /****************************************************************************/
415 
419  ec_fsm_pdo_t *fsm,
420  ec_datagram_t *datagram
421  )
422 {
423  fsm->sync_index++;
424 
425  for (; fsm->sync_index < EC_MAX_SYNC_MANAGERS; fsm->sync_index++) {
426  if (!fsm->slave->config) {
427  // slave configuration removed in the meantime
429  return;
430  }
431 
432  if (ec_pdo_list_copy(&fsm->pdos,
433  &fsm->slave->config->sync_configs[fsm->sync_index].pdos))
434  {
436  return;
437  }
438 
439  if (!(fsm->sync = ec_slave_get_sync(fsm->slave, fsm->sync_index))) {
440  if (!list_empty(&fsm->pdos.list))
441  EC_SLAVE_WARN(fsm->slave, "PDOs configured for SM%u,"
442  " but slave does not provide the"
443  " sync manager information!\n",
444  fsm->sync_index);
445  continue;
446  }
447 
448  // get first configured PDO
449  if (!(fsm->pdo =
451  // no pdos configured
453  return;
454  }
455 
456  ec_fsm_pdo_conf_action_pdo_mapping(fsm, datagram);
457  return;
458  }
459 
461 }
462 
463 /****************************************************************************/
464 
468  ec_fsm_pdo_t *fsm,
469  ec_datagram_t *datagram
470  )
471 {
472  const ec_pdo_t *assigned_pdo;
473 
474  fsm->slave_pdo.index = fsm->pdo->index;
475 
476  if ((assigned_pdo = ec_slave_find_pdo(fsm->slave, fsm->pdo->index))) {
477  ec_pdo_copy_entries(&fsm->slave_pdo, assigned_pdo);
478  } else { // configured PDO is not assigned and thus unknown
480  }
481 
482  if (list_empty(&fsm->slave_pdo.entries)) {
483  EC_SLAVE_DBG(fsm->slave, 1, "Reading mapping of PDO 0x%04X.\n",
484  fsm->pdo->index);
485 
486  // pdo mapping is unknown; start loading it
488  &fsm->slave_pdo);
490  fsm->state(fsm, datagram); // execute immediately
491  return;
492  }
493 
494  // pdo mapping is known, check if it most be re-configured
496 }
497 
498 /****************************************************************************/
499 
503  ec_fsm_pdo_t *fsm,
504  ec_datagram_t *datagram
505  )
506 {
507  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
508  return;
509  }
510 
512  EC_SLAVE_WARN(fsm->slave,
513  "Failed to read PDO entries for PDO 0x%04X.\n",
514  fsm->pdo->index);
515 
516  // check if the mapping must be re-configured
518 }
519 
520 /****************************************************************************/
521 
527  ec_fsm_pdo_t *fsm,
528  ec_datagram_t *datagram
529  )
530 {
531  // check, if slave supports PDO configuration
532  if ((fsm->slave->sii.mailbox_protocols & EC_MBOX_COE)
533  && fsm->slave->sii.has_general
535 
536  // always write PDO mapping
538  fsm->pdo, &fsm->slave_pdo);
540  fsm->state(fsm, datagram); // execure immediately
541  return;
542  }
543  else if (!ec_pdo_equal_entries(fsm->pdo, &fsm->slave_pdo)) {
544  EC_SLAVE_WARN(fsm->slave, "Slave does not support"
545  " changing the PDO mapping!\n");
546  EC_SLAVE_WARN(fsm->slave, "");
547  printk(KERN_CONT "Currently mapped PDO entries: ");
549  printk(KERN_CONT ". Entries to map: ");
551  printk(KERN_CONT "\n");
552  }
553 
555 }
556 
557 /****************************************************************************/
558 
562  ec_fsm_pdo_t *fsm,
563  ec_datagram_t *datagram
564  )
565 {
566  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
567  return;
568  }
569 
571  EC_SLAVE_WARN(fsm->slave,
572  "Failed to configure mapping of PDO 0x%04X.\n",
573  fsm->pdo->index);
574 
576 }
577 
578 /****************************************************************************/
579 
583  ec_fsm_pdo_t *fsm,
584  ec_datagram_t *datagram
585  )
586 {
587  // get next configured PDO
588  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
589  // no more configured pdos
591  return;
592  }
593 
594  ec_fsm_pdo_conf_action_pdo_mapping(fsm, datagram);
595 }
596 
597 /****************************************************************************/
598 
602  ec_fsm_pdo_t *fsm,
603  ec_datagram_t *datagram
604  )
605 {
606  if ((fsm->slave->sii.mailbox_protocols & EC_MBOX_COE)
607  && fsm->slave->sii.has_general
609 
610  // always write PDO assignment
611  if (fsm->slave->master->debug_level) {
612  EC_SLAVE_DBG(fsm->slave, 1, "Setting PDO assignment of SM%u:\n",
613  fsm->sync_index);
614  EC_SLAVE_DBG(fsm->slave, 1, ""); ec_fsm_pdo_print(fsm);
615  }
616 
617  if (ec_sdo_request_alloc(&fsm->request, 2)) {
619  return;
620  }
621 
622  // set mapped PDO count to zero
623  EC_WRITE_U8(fsm->request.data, 0); // zero PDOs mapped
624  fsm->request.data_size = 1;
625  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
627 
628  EC_SLAVE_DBG(fsm->slave, 1, "Setting number of assigned"
629  " PDOs to zero.\n");
630 
632  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
633  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
634  return;
635  }
636  else if (!ec_pdo_list_equal(&fsm->sync->pdos, &fsm->pdos)) {
637  EC_SLAVE_WARN(fsm->slave, "Slave does not support assigning PDOs!\n");
638  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
639  }
640 
641  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
642 }
643 
644 /****************************************************************************/
645 
649  ec_fsm_pdo_t *fsm,
650  ec_datagram_t *datagram
651  )
652 {
653  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
654  return;
655  }
656 
657  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
658  EC_SLAVE_WARN(fsm->slave, "Failed to clear PDO assignment of SM%u.\n",
659  fsm->sync_index);
660  EC_SLAVE_WARN(fsm->slave, "");
661  ec_fsm_pdo_print(fsm);
662  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
663  return;
664  }
665 
666  // the sync manager's assigned PDOs have been cleared
668 
669  // assign all PDOs belonging to the current sync manager
670 
671  // find first PDO
672  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdos.list))) {
673  // check for mapping to be altered
674  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
675  return;
676  }
677 
678  // assign first PDO
679  fsm->pdo_pos = 1;
680  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
681 }
682 
683 /****************************************************************************/
684 
688  ec_fsm_pdo_t *fsm,
689  ec_datagram_t *datagram
690  )
691 {
692  EC_WRITE_U16(fsm->request.data, fsm->pdo->index);
693  fsm->request.data_size = 2;
695  0x1C10 + fsm->sync_index, fsm->pdo_pos);
697 
698  EC_SLAVE_DBG(fsm->slave, 1, "Assigning PDO 0x%04X at position %u.\n",
699  fsm->pdo->index, fsm->pdo_pos);
700 
702  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
703  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
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 assign PDO 0x%04X at position %u"
721  " of SM%u.\n",
722  fsm->pdo->index, fsm->pdo_pos, fsm->sync_index);
723  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
725  return;
726  }
727 
728  // find next PDO
729  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
730  // no more PDOs to assign, set PDO count
731  EC_WRITE_U8(fsm->request.data, fsm->pdo_pos);
732  fsm->request.data_size = 1;
733  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
735 
736  EC_SLAVE_DBG(fsm->slave, 1,
737  "Setting number of assigned PDOs to %u.\n",
738  fsm->pdo_pos);
739 
741  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
742  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
743  return;
744  }
745 
746  // add next PDO to assignment
747  fsm->pdo_pos++;
748  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
749 }
750 
751 /****************************************************************************/
752 
756  ec_fsm_pdo_t *fsm,
757  ec_datagram_t *datagram
758  )
759 {
760  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
761  return;
762  }
763 
764  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
765  EC_SLAVE_WARN(fsm->slave, "Failed to set number of"
766  " assigned PDOs of SM%u.\n", fsm->sync_index);
767  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
769  return;
770  }
771 
772  // PDOs have been configured
773  ec_pdo_list_copy(&fsm->sync->pdos, &fsm->pdos);
774 
775  EC_SLAVE_DBG(fsm->slave, 1, "Successfully configured"
776  " PDO assignment of SM%u.\n", fsm->sync_index);
777 
778  // check if PDO mapping has to be altered
779  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
780 }
781 
782 /*****************************************************************************
783  * Common state functions
784  ****************************************************************************/
785 
789  ec_fsm_pdo_t *fsm,
790  ec_datagram_t *datagram
791  )
792 {
793 }
794 
795 /****************************************************************************/
796 
800  ec_fsm_pdo_t *fsm,
801  ec_datagram_t *datagram
802  )
803 {
804 }
805 
806 /****************************************************************************/
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:710
void ec_fsm_pdo_read_action_next_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Read next PDO.
Definition: fsm_pdo.c:279
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:164
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:502
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:418
#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:132
void ec_fsm_pdo_read_state_start(ec_fsm_pdo_t *, ec_datagram_t *)
Start reading PDO assignment.
Definition: fsm_pdo.c:193
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:755
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:82
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: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:3137
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:735
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
void ec_fsm_pdo_conf_state_start(ec_fsm_pdo_t *, ec_datagram_t *)
Start PDO configuration.
Definition: fsm_pdo.c:383
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:147
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:561
void ec_fsm_pdo_state_end(ec_fsm_pdo_t *, ec_datagram_t *)
State: END.
Definition: fsm_pdo.c:799
void ec_fsm_pdo_clear(ec_fsm_pdo_t *fsm)
Destructor.
Definition: fsm_pdo.c:90
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:467
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:104
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:788
void ec_sdo_request_clear(ec_sdo_request_t *req)
SDO request destructor.
Definition: sdo_request.c:70
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:129
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:119
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:275
#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
void ec_fsm_pdo_init(ec_fsm_pdo_t *fsm, ec_fsm_coe_t *fsm_coe)
Constructor.
Definition: fsm_pdo.c:74
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:3154
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:243
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:403
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:582
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:526
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:207
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:180
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:3045
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:307
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:601
#define EC_READ_U8(DATA)
Read an 8-bit unsigned value from EtherCAT data.
Definition: ecrt.h:3029
void ec_fsm_pdo_conf_action_assign_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Assign a PDO.
Definition: fsm_pdo.c:687
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_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:648
#define EC_MAX_SYNC_MANAGERS
Maximum number of sync managers per slave.
Definition: ecrt.h:267
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:356
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:600
uint8_t enable_pdo_assign
PDO mapping configurable.
Definition: globals.h:157