IgH EtherCAT Master  1.5.2
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  if (fsm->slave->sii_image) {
532  // check, if slave supports PDO configuration
534  && fsm->slave->sii_image->sii.has_general
536 
537  // always write PDO mapping
539  fsm->pdo, &fsm->slave_pdo);
541  fsm->state(fsm, datagram); // execure immediately
542  return;
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  } else {
554  EC_SLAVE_ERR(fsm->slave, "Slave cannot do PDO mapping."
555  " SII data not available.\n");
556  }
557 
559 }
560 
561 /*****************************************************************************/
562 
566  ec_fsm_pdo_t *fsm,
567  ec_datagram_t *datagram
568  )
569 {
570  if (ec_fsm_pdo_entry_exec(&fsm->fsm_pdo_entry, datagram)) {
571  return;
572  }
573 
575  EC_SLAVE_WARN(fsm->slave,
576  "Failed to configure mapping of PDO 0x%04X.\n",
577  fsm->pdo->index);
578 
580 }
581 
582 /*****************************************************************************/
583 
587  ec_fsm_pdo_t *fsm,
588  ec_datagram_t *datagram
589  )
590 {
591  // get next configured PDO
592  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
593  // no more configured pdos
595  return;
596  }
597 
598  ec_fsm_pdo_conf_action_pdo_mapping(fsm, datagram);
599 }
600 
601 /*****************************************************************************/
602 
606  ec_fsm_pdo_t *fsm,
607  ec_datagram_t *datagram
608  )
609 {
610  if (fsm->slave->sii_image) {
612  && fsm->slave->sii_image->sii.has_general
614 
615  // always write PDO assignment
616  if (fsm->slave->master->debug_level) {
617  EC_SLAVE_DBG(fsm->slave, 1, "Setting PDO assignment of SM%u:\n",
618  fsm->sync_index);
619  EC_SLAVE_DBG(fsm->slave, 1, ""); ec_fsm_pdo_print(fsm);
620  }
621 
622  if (ec_sdo_request_alloc(&fsm->request, 2)) {
624  return;
625  }
626 
627  // set mapped PDO count to zero
628  EC_WRITE_U8(fsm->request.data, 0); // zero PDOs mapped
629  fsm->request.data_size = 1;
630  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
632 
633  EC_SLAVE_DBG(fsm->slave, 1, "Setting number of assigned"
634  " PDOs to zero.\n");
635 
637  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
638  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
639  return;
640  }
641  else if (!ec_pdo_list_equal(&fsm->sync->pdos, &fsm->pdos)) {
642  EC_SLAVE_WARN(fsm->slave, "Slave does not support assigning PDOs!\n");
643  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
644  }
645  }
646  else {
647  EC_SLAVE_ERR(fsm->slave, "Slave cannot do PDO assignment."
648  " SII data not available.\n");
649  }
650 
651  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
652 }
653 
654 /*****************************************************************************/
655 
659  ec_fsm_pdo_t *fsm,
660  ec_datagram_t *datagram
661  )
662 {
663  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
664  return;
665  }
666 
667  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
668  EC_SLAVE_WARN(fsm->slave, "Failed to clear PDO assignment of SM%u.\n",
669  fsm->sync_index);
670  EC_SLAVE_WARN(fsm->slave, "");
671  ec_fsm_pdo_print(fsm);
672  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
673  return;
674  }
675 
676  // the sync manager's assigned PDOs have been cleared
678 
679  // assign all PDOs belonging to the current sync manager
680 
681  // find first PDO
682  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdos.list))) {
683  // check for mapping to be altered
684  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
685  return;
686  }
687 
688  // assign first PDO
689  fsm->pdo_pos = 1;
690  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
691 }
692 
693 /*****************************************************************************/
694 
698  ec_fsm_pdo_t *fsm,
699  ec_datagram_t *datagram
700  )
701 {
702  EC_WRITE_U16(fsm->request.data, fsm->pdo->index);
703  fsm->request.data_size = 2;
705  0x1C10 + fsm->sync_index, fsm->pdo_pos);
707 
708  EC_SLAVE_DBG(fsm->slave, 1, "Assigning PDO 0x%04X at position %u.\n",
709  fsm->pdo->index, fsm->pdo_pos);
710 
712  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
713  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
714 }
715 
716 /*****************************************************************************/
717 
721  ec_fsm_pdo_t *fsm,
722  ec_datagram_t *datagram
723  )
724 {
725  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
726  return;
727  }
728 
729  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
730  EC_SLAVE_WARN(fsm->slave, "Failed to assign PDO 0x%04X at position %u"
731  " of SM%u.\n",
732  fsm->pdo->index, fsm->pdo_pos, fsm->sync_index);
733  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
735  return;
736  }
737 
738  // find next PDO
739  if (!(fsm->pdo = ec_fsm_pdo_conf_action_next_pdo(fsm, &fsm->pdo->list))) {
740  // no more PDOs to assign, set PDO count
741  EC_WRITE_U8(fsm->request.data, fsm->pdo_pos);
742  fsm->request.data_size = 1;
743  ecrt_sdo_request_index(&fsm->request, 0x1C10 + fsm->sync_index, 0);
745 
746  EC_SLAVE_DBG(fsm->slave, 1,
747  "Setting number of assigned PDOs to %u.\n",
748  fsm->pdo_pos);
749 
751  ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
752  ec_fsm_coe_exec(fsm->fsm_coe, datagram); // execute immediately
753  return;
754  }
755 
756  // add next PDO to assignment
757  fsm->pdo_pos++;
758  ec_fsm_pdo_conf_action_assign_pdo(fsm, datagram);
759 }
760 
761 /*****************************************************************************/
762 
766  ec_fsm_pdo_t *fsm,
767  ec_datagram_t *datagram
768  )
769 {
770  if (ec_fsm_coe_exec(fsm->fsm_coe, datagram)) {
771  return;
772  }
773 
774  if (!ec_fsm_coe_success(fsm->fsm_coe)) {
775  EC_SLAVE_WARN(fsm->slave, "Failed to set number of"
776  " assigned PDOs of SM%u.\n", fsm->sync_index);
777  EC_SLAVE_WARN(fsm->slave, ""); ec_fsm_pdo_print(fsm);
779  return;
780  }
781 
782  // PDOs have been configured
783  ec_pdo_list_copy(&fsm->sync->pdos, &fsm->pdos);
784 
785  EC_SLAVE_DBG(fsm->slave, 1, "Successfully configured"
786  " PDO assignment of SM%u.\n", fsm->sync_index);
787 
788  // check if PDO mapping has to be altered
789  ec_fsm_pdo_conf_action_next_sync(fsm, datagram);
790 }
791 
792 /******************************************************************************
793  * Common state functions
794  *****************************************************************************/
795 
799  ec_fsm_pdo_t *fsm,
800  ec_datagram_t *datagram
801  )
802 {
803 }
804 
805 /*****************************************************************************/
806 
810  ec_fsm_pdo_t *fsm,
811  ec_datagram_t *datagram
812  )
813 {
814 }
815 
816 /*****************************************************************************/
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:720
void ec_fsm_pdo_read_action_next_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Read next PDO.
Definition: fsm_pdo.c:279
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:108
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:765
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:91
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:88
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:185
uint16_t index
SDO index.
Definition: sdo_request.h:50
#define EC_WRITE_U8(DATA, VAL)
Write an 8-bit unsigned value to EtherCAT data.
Definition: ecrt.h:2642
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:908
uint8_t * data
Pointer to SDO data.
Definition: sdo_request.h:52
int ec_fsm_coe_success(const ec_fsm_coe_t *fsm)
Returns, if the state machine terminated with success.
Definition: fsm_coe.c:259
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:565
void ec_fsm_pdo_state_end(ec_fsm_pdo_t *, ec_datagram_t *)
State: END.
Definition: fsm_pdo.c:809
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:214
void ec_fsm_pdo_state_error(ec_fsm_pdo_t *, ec_datagram_t *)
State: ERROR.
Definition: fsm_pdo.c:798
void ecrt_sdo_request_read(ec_sdo_request_t *req)
Schedule an SDO read operation.
Definition: sdo_request.c:232
void ec_sdo_request_clear(ec_sdo_request_t *req)
SDO request destructor.
Definition: sdo_request.c:76
ec_sii_image_t * sii_image
Current complete SII image.
Definition: slave.h:267
ec_sync_config_t sync_configs[EC_MAX_SYNC_MANAGERS]
Sync manager configurations.
Definition: slave_config.h:138
CANopen over EtherCAT.
Definition: globals.h:184
ec_slave_config_t * config
Current configuration.
Definition: slave.h:235
PDO description.
Definition: pdo.h:49
uint16_t mailbox_protocols
Supported mailbox protocols.
Definition: slave.h:172
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:310
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
Definition: slave.h:77
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:2659
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:216
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:586
uint8_t sync_index
Current sync manager index.
Definition: fsm_pdo.h:64
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:51
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:54
#define EC_READ_U16(DATA)
Read a 16-bit unsigned value from EtherCAT data.
Definition: ecrt.h:2554
Mailbox functionality.
void ec_sdo_request_init(ec_sdo_request_t *req)
SDO request constructor.
Definition: sdo_request.c:56
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:235
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:605
#define EC_READ_U8(DATA)
Read an 8-bit unsigned value from EtherCAT data.
Definition: ecrt.h:2538
void ec_fsm_pdo_conf_action_assign_pdo(ec_fsm_pdo_t *, ec_datagram_t *)
Assign a PDO.
Definition: fsm_pdo.c:697
EtherCAT slave configuration structure.
ec_sii_t sii
Extracted SII data.
Definition: slave.h:207
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:212
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:196
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:658
#define EC_MAX_SYNC_MANAGERS
Maximum number of sync managers per slave.
Definition: ecrt.h:208
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:243
void ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index, uint8_t subindex)
Set the SDO index and subindex and prepare for non-complete-access.
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:179
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:767
uint8_t enable_pdo_assign
PDO mapping configurable.
Definition: globals.h:195