IgH EtherCAT Master  1.5.3
fsm_pdo.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with the IgH EtherCAT Master; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
34 /*****************************************************************************/
35 
36 #include "globals.h"
37 #include "master.h"
38 #include "mailbox.h"
39 #include "slave_config.h"
40 
41 #include "fsm_pdo.h"
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  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:56
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:223
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:60
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:106
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:329
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:177
void ec_fsm_pdo_print(ec_fsm_pdo_t *fsm)
Print the current and desired PDO assignment.
Definition: fsm_pdo.c:104
ec_slave_t * slave
Slave the FSM runs on.
Definition: fsm_pdo.h:63
#define EC_SLAVE_WARN(slave, fmt, args...)
Convenience macro for printing slave-specific warnings to syslog.
Definition: slave.h:90
ec_pdo_t * pdo
Current PDO.
Definition: fsm_pdo.h:66
void ec_pdo_list_clear(ec_pdo_list_t *pl)
PDO list destructor.
Definition: pdo_list.c:61
EtherCAT datagram.
Definition: datagram.h:87
struct list_head list
List of PDOs.
Definition: pdo_list.h:50
EtherCAT PDO configuration state machine structures.
ec_sii_coe_details_t coe_details
CoE detail flags.
Definition: slave.h:160
uint16_t index
SDO index.
Definition: sdo_request.h:48
#define EC_WRITE_U8(DATA, VAL)
Write an 8-bit unsigned value to EtherCAT data.
Definition: ecrt.h:2401
void ec_pdo_list_clear_pdos(ec_pdo_list_t *pl)
Clears the list of mapped PDOs.
Definition: pdo_list.c:70
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:106
void ec_pdo_init(ec_pdo_t *pdo)
PDO constructor.
Definition: pdo.c:46
const ec_pdo_t * ec_slave_find_pdo(const ec_slave_t *slave, uint16_t index)
Finds a mapped PDO.
Definition: slave.c:725
uint8_t * data
Pointer to SDO data.
Definition: sdo_request.h:50
int ec_fsm_coe_success(const ec_fsm_coe_t *fsm)
Returns, if the state machine terminated with success.
Definition: fsm_coe.c:262
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:57
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: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:94
uint16_t index
PDO index.
Definition: pdo.h:51
int8_t sync_index
Assigned sync manager.
Definition: pdo.h:52
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:403
EtherCAT slave.
Definition: slave.h:176
void ec_fsm_pdo_state_error(ec_fsm_pdo_t *, ec_datagram_t *)
State: ERROR.
Definition: fsm_pdo.c:788
void ecrt_sdo_request_read(ec_sdo_request_t *req)
Schedule an SDO read operation.
Definition: sdo_request.c:224
void ec_sdo_request_clear(ec_sdo_request_t *req)
SDO request destructor.
Definition: sdo_request.c:76
ec_sync_config_t sync_configs[EC_MAX_SYNC_MANAGERS]
Sync manager configurations.
Definition: slave_config.h:135
ec_slave_config_t * config
Current configuration.
Definition: slave.h:190
PDO description.
Definition: pdo.h:49
uint16_t mailbox_protocols
Supported mailbox protocols.
Definition: slave.h:147
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:285
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
Definition: slave.h:76
ec_pdo_list_t pdos
Current PDO assignment.
Definition: sync_config.h:49
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:222
#define EC_WRITE_U16(DATA, VAL)
Write a 16-bit unsigned value to EtherCAT data.
Definition: ecrt.h:2418
struct list_head entries
List of PDO entries.
Definition: pdo.h:54
void ec_fsm_pdo_read_state_pdo_count(ec_fsm_pdo_t *, ec_datagram_t *)
Count assigned PDOs.
Definition: fsm_pdo.c:243
ec_master_t * master
Master owning the slave.
Definition: slave.h:178
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:64
CANopen over EtherCAT.
Definition: globals.h:137
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:54
uint8_t subindex
SDO subindex.
Definition: sdo_request.h:49
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:186
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:52
#define EC_READ_U16(DATA)
Read a 16-bit unsigned value from EtherCAT data.
Definition: ecrt.h:2313
Mailbox functionality.
void ec_sdo_request_init(ec_sdo_request_t *req)
SDO request constructor.
Definition: sdo_request.c:54
ec_sync_t * sync
Current sync manager.
Definition: fsm_pdo.h:65
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:228
unsigned int pdo_count
Number of assigned PDOs.
Definition: fsm_pdo.h:68
ec_pdo_list_t pdos
Current PDO assignment.
Definition: sync.h:53
void ec_pdo_list_init(ec_pdo_list_t *pl)
PDO list constructor.
Definition: pdo_list.c:50
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:299
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:2297
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:205
int ec_sdo_request_alloc(ec_sdo_request_t *req, size_t size)
Pre-allocates the data memory.
Definition: sdo_request.c:127
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:207
ec_fsm_pdo_entry_t fsm_pdo_entry
PDO entry state machine.
Definition: fsm_pdo.h:58
struct list_head list
List item.
Definition: pdo.h:50
uint8_t enable_pdo_configuration
PDO configuration possible.
Definition: globals.h:149
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:226
ec_pdo_list_t pdos
PDO configuration.
Definition: fsm_pdo.h:59
void ec_fsm_pdo_read_state_pdo_entries(ec_fsm_pdo_t *, ec_datagram_t *)
Fetch PDO information.
Definition: fsm_pdo.c:356
void ecrt_sdo_request_write(ec_sdo_request_t *req)
Schedule an SDO write operation.
Definition: sdo_request.c:235
void 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:187
unsigned int pdo_pos
Assignment position of current PDOs.
Definition: fsm_pdo.h:67
unsigned int has_general
General category present.
Definition: slave.h:154
ec_pdo_t slave_pdo
PDO actually appearing in a slave.
Definition: fsm_pdo.h:61
Finite state machines for the CANopen over EtherCAT protocol.
Definition: fsm_coe.h:52
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:590
uint8_t enable_pdo_assign
PDO mapping configurable.
Definition: globals.h:148