IgH EtherCAT Master  1.6.12
slave_config.c
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Copyright (C) 2006-2024 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 * vim: expandtab
21 *
22 ****************************************************************************/
23
28
29/****************************************************************************/
30
31#include "slave_config.h"
32
33#include "globals.h"
34#include "master.h"
35#include "voe_handler.h"
36#include "flag.h"
37#include "ioctl.h"
38
39#ifdef EC_EOE
40#include "eoe_request.h"
41#endif
42
43#include <linux/module.h>
44#include <linux/slab.h>
45
46/****************************************************************************/
47
48// prototypes for private methods
52 ec_pdo_t *);
53
54/****************************************************************************/
55
58typedef struct {
59 struct list_head list;
62 unsigned int timeout_ms;
64
65/****************************************************************************/
66
74 ec_master_t *master,
75 uint16_t alias,
76 uint16_t position,
77 uint32_t vendor_id,
78 uint32_t product_code
79 )
80{
81 unsigned int i;
82
83 sc->master = master;
84
85 sc->alias = alias;
86 sc->position = position;
87 sc->vendor_id = vendor_id;
88 sc->product_code = product_code;
89 sc->watchdog_divider = 0; // use default
90 sc->watchdog_intervals = 0; // use default
91
92 sc->slave = NULL;
93
94 for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
96
97 sc->used_fmmus = 0;
98 sc->dc_assign_activate = 0x0000;
99 sc->dc_sync[0].cycle_time = 0U;
100 sc->dc_sync[1].cycle_time = 0;
101 sc->dc_sync[0].shift_time = 0U;
102 sc->dc_sync[1].shift_time = 0;
103
104 INIT_LIST_HEAD(&sc->sdo_configs);
105 INIT_LIST_HEAD(&sc->sdo_requests);
106 INIT_LIST_HEAD(&sc->soe_requests);
107 INIT_LIST_HEAD(&sc->reg_requests);
108 INIT_LIST_HEAD(&sc->voe_handlers);
109 INIT_LIST_HEAD(&sc->soe_configs);
110 INIT_LIST_HEAD(&sc->flags);
111 INIT_LIST_HEAD(&sc->al_timeouts);
112
113#ifdef EC_EOE
115#endif
116
118}
119
120/****************************************************************************/
121
128 )
129{
130 unsigned int i;
131 ec_sdo_request_t *req, *next_req;
132 ec_voe_handler_t *voe, *next_voe;
133 ec_reg_request_t *reg, *next_reg;
134 ec_soe_request_t *soe, *next_soe;
135 ec_flag_t *flag, *next_flag;
136 ec_al_timeout_t *timeout, *next_timeout;
137
139
140 // Free sync managers
141 for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
143
144 // free all SDO configurations
145 list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
146 list_del(&req->list);
148 kfree(req);
149 }
150
151 // free all SDO requests
152 list_for_each_entry_safe(req, next_req, &sc->sdo_requests, list) {
153 list_del(&req->list);
155 kfree(req);
156 }
157
158 // free all SoE requests
159 list_for_each_entry_safe(soe, next_soe, &sc->soe_requests, list) {
160 list_del(&soe->list);
162 kfree(soe);
163 }
164
165 // free all register requests
166 list_for_each_entry_safe(reg, next_reg, &sc->reg_requests, list) {
167 list_del(&reg->list);
169 kfree(reg);
170 }
171
172 // free all VoE handlers
173 list_for_each_entry_safe(voe, next_voe, &sc->voe_handlers, list) {
174 list_del(&voe->list);
176 kfree(voe);
177 }
178
179 // free all SoE configurations
180 list_for_each_entry_safe(soe, next_soe, &sc->soe_configs, list) {
181 list_del(&soe->list);
183 kfree(soe);
184 }
185
186 // free all flags
187 list_for_each_entry_safe(flag, next_flag, &sc->flags, list) {
188 list_del(&flag->list);
189 ec_flag_clear(flag);
190 kfree(flag);
191 }
192
193 // free all AL timeouts
194 list_for_each_entry_safe(timeout, next_timeout, &sc->al_timeouts, list) {
195 list_del(&timeout->list);
196 kfree(timeout);
197 }
198
200}
201
202/****************************************************************************/
203
218 ec_domain_t *domain,
219 uint8_t sync_index,
220 ec_direction_t dir
221 )
222{
223 unsigned int i;
224 ec_fmmu_config_t *fmmu;
225
226 // FMMU configuration already prepared?
227 for (i = 0; i < sc->used_fmmus; i++) {
228 fmmu = &sc->fmmu_configs[i];
229 if (fmmu->domain == domain && fmmu->sync_index == sync_index)
230 return fmmu->logical_start_address;
231 }
232
233 if (sc->used_fmmus == EC_MAX_FMMUS) {
234 EC_CONFIG_ERR(sc, "FMMU limit reached!\n");
235 return -EOVERFLOW;
236 }
237
238 fmmu = &sc->fmmu_configs[sc->used_fmmus++];
239
240 down(&sc->master->master_sem);
241 ec_fmmu_config_init(fmmu, sc, domain, sync_index, dir);
242 up(&sc->master->master_sem);
243
244 return fmmu->logical_start_address;
245}
246
247/****************************************************************************/
248
256 )
257{
258 ec_slave_t *slave;
259
260 if (sc->slave)
261 return 0; // already attached
262
263 if (!(slave = ec_master_find_slave(
264 sc->master, sc->alias, sc->position))) {
265 EC_CONFIG_DBG(sc, 1, "Failed to find slave for configuration.\n");
266 return -ENOENT;
267 }
268
269 if (slave->config) {
270 EC_CONFIG_DBG(sc, 1, "Failed to attach configuration. Slave %u"
271 " already has a configuration!\n", slave->ring_position);
272 return -EEXIST;
273 }
274
275 if (
276#ifdef EC_IDENT_WILDCARDS
277 sc->vendor_id != 0xffffffff &&
278#endif
279 slave->sii.vendor_id != sc->vendor_id
280 ) {
281 EC_CONFIG_DBG(sc, 1, "Slave %u has no matching vendor ID (0x%08X)"
282 " for configuration (0x%08X).\n",
283 slave->ring_position, slave->sii.vendor_id, sc->vendor_id);
284 return -EINVAL;
285 }
286
287 if (
288#ifdef EC_IDENT_WILDCARDS
289 sc->product_code != 0xffffffff &&
290#endif
291 slave->sii.product_code != sc->product_code
292 ) {
293 EC_CONFIG_DBG(sc, 1, "Slave %u has no matching product code (0x%08X)"
294 " for configuration (0x%08X).\n",
295 slave->ring_position, slave->sii.product_code,
296 sc->product_code);
297 return -EINVAL;
298 }
299
300 // attach slave
301 slave->config = sc;
302 sc->slave = slave;
303
304 EC_CONFIG_DBG(sc, 1, "Attached slave %u.\n", slave->ring_position);
305 return 0;
306}
307
308/****************************************************************************/
309
314 )
315{
316 if (sc->slave) {
317 ec_reg_request_t *reg;
318
319 sc->slave->config = NULL;
320
321 // invalidate processing register request
322 list_for_each_entry(reg, &sc->reg_requests, list) {
323 if (sc->slave->fsm.reg_request == reg) {
324 sc->slave->fsm.reg_request = NULL;
325 break;
326 }
327 }
328
329 sc->slave = NULL;
330 }
331}
332
333/****************************************************************************/
334
338{
339 uint8_t sync_index;
340 ec_sync_config_t *sync_config;
341 const ec_sync_t *sync;
342
343 if (!sc->slave)
344 return;
345
346 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
347 sync_config = &sc->sync_configs[sync_index];
348 if ((sync = ec_slave_get_sync(sc->slave, sync_index))) {
349 sync_config->dir = ec_sync_default_direction(sync);
350 if (sync_config->dir == EC_DIR_INVALID)
352 "SM%u has an invalid direction field!\n", sync_index);
353 ec_pdo_list_copy(&sync_config->pdos, &sync->pdos);
354 }
355 }
356}
357
358/****************************************************************************/
359
363 const ec_slave_config_t *sc,
364 ec_pdo_t *pdo
365 )
366{
367 unsigned int i;
368 const ec_sync_t *sync;
369 const ec_pdo_t *default_pdo;
370
371 if (!sc->slave)
372 return;
373
374 EC_CONFIG_DBG(sc, 1, "Loading default mapping for PDO 0x%04X.\n",
375 pdo->index);
376
377 // find PDO in any sync manager (it could be reassigned later)
378 for (i = 0; i < sc->slave->sii.sync_count; i++) {
379 sync = &sc->slave->sii.syncs[i];
380
381 list_for_each_entry(default_pdo, &sync->pdos.list, list) {
382 if (default_pdo->index != pdo->index)
383 continue;
384
385 if (default_pdo->name) {
386 EC_CONFIG_DBG(sc, 1, "Found PDO name \"%s\".\n",
387 default_pdo->name);
388
389 // take PDO name from assigned one
390 ec_pdo_set_name(pdo, default_pdo->name);
391 }
392
393 // copy entries (= default PDO mapping)
394 if (ec_pdo_copy_entries(pdo, default_pdo))
395 return;
396
397 if (sc->master->debug_level) {
398 const ec_pdo_entry_t *entry;
399 list_for_each_entry(entry, &pdo->entries, list) {
400 EC_CONFIG_DBG(sc, 1, "Entry 0x%04X:%02X.\n",
401 entry->index, entry->subindex);
402 }
403 }
404
405 return;
406 }
407 }
408
409 EC_CONFIG_DBG(sc, 1, "No default mapping found.\n");
410}
411
412/****************************************************************************/
413
419 const ec_slave_config_t *sc
420 )
421{
422 const ec_sdo_request_t *req;
423 unsigned int count = 0;
424
425 list_for_each_entry(req, &sc->sdo_configs, list) {
426 count++;
427 }
428
429 return count;
430}
431
432/****************************************************************************/
433
441 const ec_slave_config_t *sc,
442 unsigned int pos
443 )
444{
445 const ec_sdo_request_t *req;
446
447 list_for_each_entry(req, &sc->sdo_configs, list) {
448 if (pos--)
449 continue;
450 return req;
451 }
452
453 return NULL;
454}
455
456/****************************************************************************/
457
463 const ec_slave_config_t *sc
464 )
465{
466 const ec_soe_request_t *req;
467 unsigned int count = 0;
468
469 list_for_each_entry(req, &sc->soe_configs, list) {
470 count++;
471 }
472
473 return count;
474}
475
476/****************************************************************************/
477
485 const ec_slave_config_t *sc,
486 unsigned int pos
487 )
488{
489 const ec_soe_request_t *req;
490
491 list_for_each_entry(req, &sc->soe_configs, list) {
492 if (pos--)
493 continue;
494 return req;
495 }
496
497 return NULL;
498}
499
500/****************************************************************************/
501
507 const ec_slave_config_t *sc
508 )
509{
510 const ec_flag_t *flag;
511 unsigned int count = 0;
512
513 list_for_each_entry(flag, &sc->flags, list) {
514 count++;
515 }
516
517 return count;
518}
519
520/****************************************************************************/
521
529 const ec_slave_config_t *sc,
530 unsigned int pos
531 )
532{
533 const ec_flag_t *flag;
534
535 list_for_each_entry(flag, &sc->flags, list) {
536 if (pos--)
537 continue;
538 return flag;
539 }
540
541 return NULL;
542}
543
544/****************************************************************************/
545
552 unsigned int pos
553 )
554{
555 ec_sdo_request_t *req;
556
557 list_for_each_entry(req, &sc->sdo_requests, list) {
558 if (pos--)
559 continue;
560 return req;
561 }
562
563 return NULL;
564}
565
566/****************************************************************************/
567
574 unsigned int pos
575 )
576{
577 ec_soe_request_t *req;
578
579 list_for_each_entry(req, &sc->soe_requests, list) {
580 if (pos--)
581 continue;
582 return req;
583 }
584
585 return NULL;
586}
587
588/****************************************************************************/
589
596 unsigned int pos
597 )
598{
599 ec_reg_request_t *reg;
600
601 list_for_each_entry(reg, &sc->reg_requests, list) {
602 if (pos--)
603 continue;
604 return reg;
605 }
606
607 return NULL;
608}
609
610/****************************************************************************/
611
618 unsigned int pos
619 )
620{
621 ec_voe_handler_t *voe;
622
623 list_for_each_entry(voe, &sc->voe_handlers, list) {
624 if (pos--)
625 continue;
626 return voe;
627 }
628
629 return NULL;
630}
631
632/****************************************************************************/
633
640 const char *key
641 )
642{
643 if (sc) {
644 ec_flag_t *flag;
645 list_for_each_entry(flag, &sc->flags, list) {
646 if (!strcmp(flag->key, key)) {
647 return flag;
648 }
649 }
650 }
651
652 return NULL;
653}
654
655/****************************************************************************/
656
663{
664 ec_al_timeout_t *timeout;
665
666 list_for_each_entry(timeout, &sc->al_timeouts, list) {
667 if (timeout->from == from && timeout->to == to) {
668 return timeout->timeout_ms;
669 }
670 }
671
672 return 0;
673}
674
675/*****************************************************************************
676 * Application interface
677 ****************************************************************************/
678
680 ec_direction_t dir, ec_watchdog_mode_t watchdog_mode)
681{
682 ec_sync_config_t *sync_config;
683
684 EC_CONFIG_DBG(sc, 1, "ecrt_slave_config_sync_manager(sc = 0x%p,"
685 " sync_index = %u, dir = %i, watchdog_mode = %i)\n",
686 sc, sync_index, dir, watchdog_mode);
687
688 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
689 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n", sync_index);
690 return -ENOENT;
691 }
692
693 if (dir != EC_DIR_OUTPUT && dir != EC_DIR_INPUT) {
694 EC_CONFIG_ERR(sc, "Invalid direction %u!\n", (unsigned int) dir);
695 return -EINVAL;
696 }
697
698 sync_config = &sc->sync_configs[sync_index];
699 sync_config->dir = dir;
700 sync_config->watchdog_mode = watchdog_mode;
701 return 0;
702}
703
704/****************************************************************************/
705
707 uint16_t divider, uint16_t intervals)
708{
709 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, divider = %u, intervals = %u)\n",
710 __func__, sc, divider, intervals);
711
712 sc->watchdog_divider = divider;
713 sc->watchdog_intervals = intervals;
714 return 0;
715}
716
717/****************************************************************************/
718
720 uint8_t sync_index, uint16_t pdo_index)
721{
722 ec_pdo_t *pdo;
723
724 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, sync_index = %u, "
725 "pdo_index = 0x%04X)\n", __func__, sc, sync_index, pdo_index);
726
727 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
728 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n", sync_index);
729 return -EINVAL;
730 }
731
732 down(&sc->master->master_sem);
733
734 pdo = ec_pdo_list_add_pdo(&sc->sync_configs[sync_index].pdos, pdo_index);
735 if (IS_ERR(pdo)) {
736 up(&sc->master->master_sem);
737 return PTR_ERR(pdo);
738 }
739 pdo->sync_index = sync_index;
740
742
743 up(&sc->master->master_sem);
744 return 0;
745}
746
747/****************************************************************************/
748
750 uint8_t sync_index)
751{
752 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, sync_index = %u)\n",
753 __func__, sc, sync_index);
754
755 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
756 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n", sync_index);
757 return -EINVAL;
758 }
759
760 down(&sc->master->master_sem);
761 ec_pdo_list_clear_pdos(&sc->sync_configs[sync_index].pdos);
762 up(&sc->master->master_sem);
763 return 0;
764}
765
766/****************************************************************************/
767
769 uint16_t pdo_index, uint16_t entry_index, uint8_t entry_subindex,
770 uint8_t entry_bit_length)
771{
772 uint8_t sync_index;
773 ec_pdo_t *pdo = NULL;
774 ec_pdo_entry_t *entry;
775 int retval = 0;
776
777 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, "
778 "pdo_index = 0x%04X, entry_index = 0x%04X, "
779 "entry_subindex = 0x%02X, entry_bit_length = %u)\n",
780 __func__, sc, pdo_index, entry_index, entry_subindex,
781 entry_bit_length);
782
783 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
784 if ((pdo = ec_pdo_list_find_pdo(
785 &sc->sync_configs[sync_index].pdos, pdo_index)))
786 break;
787
788 if (pdo) {
789 down(&sc->master->master_sem);
790 entry = ec_pdo_add_entry(pdo, entry_index, entry_subindex,
791 entry_bit_length);
792 up(&sc->master->master_sem);
793 if (IS_ERR(entry))
794 retval = PTR_ERR(entry);
795 } else {
796 EC_CONFIG_ERR(sc, "PDO 0x%04X is not assigned.\n", pdo_index);
797 retval = -ENOENT;
798 }
799
800 return retval;
801}
802
803/****************************************************************************/
804
806 uint16_t pdo_index)
807{
808 uint8_t sync_index;
809 ec_pdo_t *pdo = NULL;
810
811 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, pdo_index = 0x%04X)\n",
812 __func__, sc, pdo_index);
813
814 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
815 if ((pdo = ec_pdo_list_find_pdo(
816 &sc->sync_configs[sync_index].pdos, pdo_index)))
817 break;
818
819 if (pdo) {
820 down(&sc->master->master_sem);
822 up(&sc->master->master_sem);
823 } else {
824 EC_CONFIG_WARN(sc, "PDO 0x%04X is not assigned.\n", pdo_index);
825 }
826 return 0;
827}
828
829/****************************************************************************/
830
832 unsigned int n_syncs, const ec_sync_info_t syncs[])
833{
834 int ret;
835 unsigned int i, j, k;
836 const ec_sync_info_t *sync_info;
837 const ec_pdo_info_t *pdo_info;
838 const ec_pdo_entry_info_t *entry_info;
839
840 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, n_syncs = %u, syncs = 0x%p)\n",
841 __func__, sc, n_syncs, syncs);
842
843 if (!syncs)
844 return 0;
845
846 for (i = 0; i < n_syncs; i++) {
847 sync_info = &syncs[i];
848
849 if (sync_info->index == (uint8_t) EC_END)
850 break;
851
852 if (sync_info->index >= EC_MAX_SYNC_MANAGERS) {
853 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n",
854 sync_info->index);
855 return -ENOENT;
856 }
857
858 ret = ecrt_slave_config_sync_manager(sc, sync_info->index,
859 sync_info->dir, sync_info->watchdog_mode);
860 if (ret)
861 return ret;
862
864
865 if (sync_info->n_pdos && sync_info->pdos) {
866 for (j = 0; j < sync_info->n_pdos; j++) {
867 pdo_info = &sync_info->pdos[j];
868
870 sc, sync_info->index, pdo_info->index);
871 if (ret)
872 return ret;
873
875
876 if (pdo_info->n_entries && pdo_info->entries) {
877 for (k = 0; k < pdo_info->n_entries; k++) {
878 entry_info = &pdo_info->entries[k];
879
881 pdo_info->index, entry_info->index,
882 entry_info->subindex,
883 entry_info->bit_length);
884 if (ret)
885 return ret;
886 }
887 }
888 }
889 }
890 }
891
892 return 0;
893}
894
895/****************************************************************************/
896
899 uint16_t index,
900 uint8_t subindex,
901 ec_domain_t *domain,
902 unsigned int *bit_position
903 )
904{
905 uint8_t sync_index;
906 const ec_sync_config_t *sync_config;
907 unsigned int bit_offset, bit_pos;
908 ec_pdo_t *pdo;
909 ec_pdo_entry_t *entry;
910 int sync_offset;
911
912 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
913 "subindex = 0x%02X, domain = 0x%p, bit_position = 0x%p)\n",
914 __func__, sc, index, subindex, domain, bit_position);
915
916 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
917 sync_config = &sc->sync_configs[sync_index];
918 bit_offset = 0;
919
920 list_for_each_entry(pdo, &sync_config->pdos.list, list) {
921 list_for_each_entry(entry, &pdo->entries, list) {
922 if (entry->index != index || entry->subindex != subindex) {
923 bit_offset += entry->bit_length;
924 } else {
925 bit_pos = bit_offset % 8;
926 if (bit_position) {
927 *bit_position = bit_pos;
928 } else if (bit_pos) {
929 EC_CONFIG_ERR(sc, "PDO entry 0x%04X:%02X does"
930 " not byte-align.\n", index, subindex);
931 return -EFAULT;
932 }
933
934 sync_offset = ec_slave_config_prepare_fmmu(
935 sc, domain, sync_index, sync_config->dir);
936 if (sync_offset < 0)
937 return sync_offset;
938
939 return sync_offset + bit_offset / 8;
940 }
941 }
942 }
943 }
944
945 EC_CONFIG_ERR(sc, "PDO entry 0x%04X:%02X is not mapped.\n",
946 index, subindex);
947 return -ENOENT;
948}
949
950/****************************************************************************/
951
954 uint8_t sync_index,
955 unsigned int pdo_pos,
956 unsigned int entry_pos,
957 ec_domain_t *domain,
958 unsigned int *bit_position
959 )
960{
961 const ec_sync_config_t *sync_config;
962 unsigned int bit_offset, pp, ep;
963 ec_pdo_t *pdo;
964 ec_pdo_entry_t *entry;
965
966 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, sync_index = %u, pdo_pos = %u,"
967 " entry_pos = %u, domain = 0x%p, bit_position = 0x%p)\n",
968 __func__, sc, sync_index, pdo_pos, entry_pos,
969 domain, bit_position);
970
971 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
972 EC_CONFIG_ERR(sc, "Invalid syncmanager position %u.\n", sync_index);
973 return -EINVAL;
974 }
975
976 sync_config = &sc->sync_configs[sync_index];
977 bit_offset = 0;
978 pp = 0;
979
980 list_for_each_entry(pdo, &sync_config->pdos.list, list) {
981 ep = 0;
982 list_for_each_entry(entry, &pdo->entries, list) {
983 if (pp != pdo_pos || ep != entry_pos) {
984 bit_offset += entry->bit_length;
985 } else {
986 unsigned int bit_pos = bit_offset % 8;
987 int sync_offset;
988
989 if (bit_position) {
990 *bit_position = bit_pos;
991 } else if (bit_pos) {
992 EC_CONFIG_ERR(sc, "PDO entry 0x%04X:%02X does"
993 " not byte-align.\n",
994 pdo->index, entry->subindex);
995 return -EFAULT;
996 }
997
998 sync_offset = ec_slave_config_prepare_fmmu(
999 sc, domain, sync_index, sync_config->dir);
1000 if (sync_offset < 0)
1001 return sync_offset;
1002
1003 return sync_offset + bit_offset / 8;
1004 }
1005 ep++;
1006 }
1007 pp++;
1008 }
1009
1010 EC_CONFIG_ERR(sc, "PDO entry specification %u/%u/%u out of range.\n",
1011 sync_index, pdo_pos, entry_pos);
1012 return -ENOENT;
1013}
1014
1015/****************************************************************************/
1016
1017int ecrt_slave_config_dc(ec_slave_config_t *sc, uint16_t assign_activate,
1018 uint32_t sync0_cycle_time, int32_t sync0_shift_time,
1019 uint32_t sync1_cycle_time, int32_t sync1_shift_time)
1020{
1021 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, assign_activate = 0x%04X,"
1022 " sync0_cycle = %u, sync0_shift = %i,"
1023 " sync1_cycle = %u, sync1_shift = %i\n",
1024 __func__, sc, assign_activate, sync0_cycle_time, sync0_shift_time,
1025 sync1_cycle_time, sync1_shift_time);
1026
1027 sc->dc_assign_activate = assign_activate;
1028 sc->dc_sync[0].cycle_time = sync0_cycle_time;
1029 sc->dc_sync[0].shift_time = sync0_shift_time;
1030 sc->dc_sync[1].cycle_time = sync1_cycle_time;
1031 sc->dc_sync[1].shift_time = sync1_shift_time;
1032 return 0;
1033}
1034
1035/****************************************************************************/
1036
1038 uint8_t subindex, const uint8_t *data, size_t size)
1039{
1040 ec_slave_t *slave = sc->slave;
1041 ec_sdo_request_t *req;
1042 int ret;
1043
1044 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1045 "subindex = 0x%02X, data = 0x%p, size = %zu)\n",
1046 __func__, sc, index, subindex, data, size);
1047
1048 if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
1049 EC_CONFIG_WARN(sc, "Attached slave does not support CoE!\n");
1050 }
1051
1052 if (!(req = (ec_sdo_request_t *)
1053 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
1054 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1055 " SDO configuration!\n");
1056 return -ENOMEM;
1057 }
1058
1060 ecrt_sdo_request_index(req, index, subindex);
1061
1062 ret = ec_sdo_request_copy_data(req, data, size);
1063 if (ret < 0) {
1065 kfree(req);
1066 return ret;
1067 }
1068
1069 down(&sc->master->master_sem);
1070 list_add_tail(&req->list, &sc->sdo_configs);
1071 up(&sc->master->master_sem);
1072 return 0;
1073}
1074
1075/****************************************************************************/
1076
1078 uint8_t subindex, uint8_t value)
1079{
1080 uint8_t data[1];
1081
1082 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1083 "subindex = 0x%02X, value = %u)\n",
1084 __func__, sc, index, subindex, (unsigned int) value);
1085
1086 EC_WRITE_U8(data, value);
1087 return ecrt_slave_config_sdo(sc, index, subindex, data, 1);
1088}
1089
1090/****************************************************************************/
1091
1093 uint8_t subindex, uint16_t value)
1094{
1095 uint8_t data[2];
1096
1097 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1098 "subindex = 0x%02X, value = %u)\n",
1099 __func__, sc, index, subindex, value);
1100
1101 EC_WRITE_U16(data, value);
1102 return ecrt_slave_config_sdo(sc, index, subindex, data, 2);
1103}
1104
1105/****************************************************************************/
1106
1108 uint8_t subindex, uint32_t value)
1109{
1110 uint8_t data[4];
1111
1112 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1113 "subindex = 0x%02X, value = %u)\n",
1114 __func__, sc, index, subindex, value);
1115
1116 EC_WRITE_U32(data, value);
1117 return ecrt_slave_config_sdo(sc, index, subindex, data, 4);
1118}
1119
1120/****************************************************************************/
1121
1123 const uint8_t *data, size_t size)
1124{
1125 ec_slave_t *slave = sc->slave;
1126 ec_sdo_request_t *req;
1127 int ret;
1128
1129 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1130 "data = 0x%p, size = %zu)\n", __func__, sc, index, data, size);
1131
1132 if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
1133 EC_CONFIG_WARN(sc, "Attached slave does not support CoE!\n");
1134 }
1135
1136 if (!(req = (ec_sdo_request_t *)
1137 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
1138 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1139 " SDO configuration!\n");
1140 return -ENOMEM;
1141 }
1142
1144 ecrt_sdo_request_index(req, index, 0);
1145 req->complete_access = 1;
1146
1147 ret = ec_sdo_request_copy_data(req, data, size);
1148 if (ret < 0) {
1150 kfree(req);
1151 return ret;
1152 }
1153
1154 down(&sc->master->master_sem);
1155 list_add_tail(&req->list, &sc->sdo_configs);
1156 up(&sc->master->master_sem);
1157 return 0;
1158}
1159
1160/****************************************************************************/
1161
1163{
1164 return ec_coe_emerg_ring_size(&sc->emerg_ring, elements);
1165}
1166
1167/****************************************************************************/
1168
1170{
1171 return ec_coe_emerg_ring_pop(&sc->emerg_ring, target);
1172}
1173
1174/****************************************************************************/
1175
1180
1181/****************************************************************************/
1182
1187
1188/****************************************************************************/
1189
1194 ec_slave_config_t *sc, uint16_t index, uint8_t subindex, size_t size)
1195{
1196 ec_sdo_request_t *req;
1197 int ret;
1198
1199 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, "
1200 "index = 0x%04X, subindex = 0x%02X, size = %zu)\n",
1201 __func__, sc, index, subindex, size);
1202
1203 if (!(req = (ec_sdo_request_t *)
1204 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
1205 EC_CONFIG_ERR(sc, "Failed to allocate SDO request memory!\n");
1206 return ERR_PTR(-ENOMEM);
1207 }
1208
1210 ecrt_sdo_request_index(req, index, subindex);
1211
1212 ret = ec_sdo_request_alloc(req, size);
1213 if (ret < 0) {
1215 kfree(req);
1216 return ERR_PTR(ret);
1217 }
1218
1219 // prepare data for optional writing
1220 memset(req->data, 0x00, size);
1221 req->data_size = size;
1222
1223 down(&sc->master->master_sem);
1224 list_add_tail(&req->list, &sc->sdo_requests);
1225 up(&sc->master->master_sem);
1226
1227 return req;
1228}
1229
1230/****************************************************************************/
1231
1233 ec_slave_config_t *sc, uint16_t index, uint8_t subindex, size_t size)
1234{
1236 subindex, size);
1237 return IS_ERR(s) ? NULL : s;
1238}
1239
1240/****************************************************************************/
1241
1246 ec_slave_config_t *sc, uint8_t drive_no, uint16_t idn, size_t size)
1247{
1248 ec_soe_request_t *req;
1249 int ret;
1250
1251 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, "
1252 "drive_no = 0x%02X, idn = 0x%04X, size = %zu)\n",
1253 __func__, sc, drive_no, idn, size);
1254
1255 if (!(req = (ec_soe_request_t *)
1256 kmalloc(sizeof(ec_soe_request_t), GFP_KERNEL))) {
1257 EC_CONFIG_ERR(sc, "Failed to allocate IDN request memory!\n");
1258 return ERR_PTR(-ENOMEM);
1259 }
1260
1262 ecrt_soe_request_idn(req, drive_no, idn);
1263
1264 ret = ec_soe_request_alloc(req, size);
1265 if (ret < 0) {
1267 kfree(req);
1268 return ERR_PTR(ret);
1269 }
1270
1271 // prepare data for optional writing
1272 memset(req->data, 0x00, size);
1273 req->data_size = size;
1274
1275 down(&sc->master->master_sem);
1276 list_add_tail(&req->list, &sc->soe_requests);
1277 up(&sc->master->master_sem);
1278
1279 return req;
1280}
1281
1282/****************************************************************************/
1283
1285 ec_slave_config_t *sc, uint8_t drive_no, uint16_t idn, size_t size)
1286{
1288 drive_no, idn, size);
1289 return IS_ERR(req) ? NULL : req;
1290}
1291
1292/****************************************************************************/
1293
1298 ec_slave_config_t *sc, size_t size)
1299{
1300 ec_reg_request_t *reg;
1301 int ret;
1302
1303 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, size = %zu)\n",
1304 __func__, sc, size);
1305
1306 if (!(reg = (ec_reg_request_t *)
1307 kmalloc(sizeof(ec_reg_request_t), GFP_KERNEL))) {
1308 EC_CONFIG_ERR(sc, "Failed to allocate register request memory!\n");
1309 return ERR_PTR(-ENOMEM);
1310 }
1311
1312 ret = ec_reg_request_init(reg, size);
1313 if (ret) {
1314 kfree(reg);
1315 return ERR_PTR(ret);
1316 }
1317
1318 down(&sc->master->master_sem);
1319 list_add_tail(&reg->list, &sc->reg_requests);
1320 up(&sc->master->master_sem);
1321
1322 return reg;
1323}
1324
1325/****************************************************************************/
1326
1328 ec_slave_config_t *sc, size_t size)
1329{
1330 ec_reg_request_t *reg =
1332 return IS_ERR(reg) ? NULL : reg;
1333}
1334
1335/****************************************************************************/
1336
1341 ec_slave_config_t *sc, size_t size)
1342{
1343 ec_voe_handler_t *voe;
1344 int ret;
1345
1346 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, size = %zu)\n", __func__, sc, size);
1347
1348 if (!(voe = (ec_voe_handler_t *)
1349 kmalloc(sizeof(ec_voe_handler_t), GFP_KERNEL))) {
1350 EC_CONFIG_ERR(sc, "Failed to allocate VoE request memory!\n");
1351 return ERR_PTR(-ENOMEM);
1352 }
1353
1354 ret = ec_voe_handler_init(voe, sc, size);
1355 if (ret < 0) {
1356 kfree(voe);
1357 return ERR_PTR(ret);
1358 }
1359
1360 down(&sc->master->master_sem);
1361 list_add_tail(&voe->list, &sc->voe_handlers);
1362 up(&sc->master->master_sem);
1363
1364 return voe;
1365}
1366
1367/****************************************************************************/
1368
1370 ec_slave_config_t *sc, size_t size)
1371{
1373 size);
1374 return IS_ERR(voe) ? NULL : voe;
1375}
1376
1377/****************************************************************************/
1378
1381{
1382 const ec_slave_t *slave = sc->slave;
1383
1384 state->online = slave ? 1 : 0;
1385 if (state->online) {
1386 state->operational =
1387 slave->current_state == EC_SLAVE_STATE_OP && !slave->force_config;
1388 state->al_state = slave->current_state;
1389 } else {
1390 state->operational = 0;
1392 }
1393 return 0;
1394}
1395
1396/****************************************************************************/
1397
1399 uint16_t idn, ec_al_state_t state, const uint8_t *data,
1400 size_t size)
1401{
1402 ec_slave_t *slave = sc->slave;
1403 ec_soe_request_t *req;
1404 int ret;
1405
1406 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, drive_no = %u, idn = 0x%04X, "
1407 "state = %u, data = 0x%p, size = %zu)\n",
1408 __func__, sc, drive_no, idn, state, data, size);
1409
1410 if (drive_no > 7) {
1411 EC_CONFIG_ERR(sc, "Invalid drive number %u!\n",
1412 (unsigned int) drive_no);
1413 return -EINVAL;
1414 }
1415
1416 if (state != EC_AL_STATE_PREOP && state != EC_AL_STATE_SAFEOP) {
1417 EC_CONFIG_ERR(sc, "AL state for IDN config"
1418 " must be PREOP or SAFEOP!\n");
1419 return -EINVAL;
1420 }
1421
1422 if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_SOE)) {
1423 EC_CONFIG_WARN(sc, "Attached slave does not support SoE!\n");
1424 }
1425
1426 if (!(req = (ec_soe_request_t *)
1427 kmalloc(sizeof(ec_soe_request_t), GFP_KERNEL))) {
1428 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1429 " IDN configuration!\n");
1430 return -ENOMEM;
1431 }
1432
1434 ec_soe_request_set_drive_no(req, drive_no);
1435 ec_soe_request_set_idn(req, idn);
1436 req->al_state = state;
1437
1438 ret = ec_soe_request_copy_data(req, data, size);
1439 if (ret < 0) {
1441 kfree(req);
1442 return ret;
1443 }
1444
1445 down(&sc->master->master_sem);
1446 list_add_tail(&req->list, &sc->soe_configs);
1447 up(&sc->master->master_sem);
1448 return 0;
1449}
1450
1451/****************************************************************************/
1452
1454 int32_t value)
1455{
1456 ec_flag_t *flag;
1457
1458 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, key = %s, value = %i)\n",
1459 __func__, sc, key, value);
1460
1461
1462 flag = ec_slave_config_find_flag(sc, key);
1463 if (flag) {
1464 flag->value = value; // overwrite value
1465 }
1466 else { // new flag
1467 int ret;
1468
1469 if (!(flag = (ec_flag_t *) kmalloc(sizeof(ec_flag_t), GFP_KERNEL))) {
1470 EC_CONFIG_ERR(sc, "Failed to allocate memory for flag!\n");
1471 return -ENOMEM;
1472 }
1473
1474 ret = ec_flag_init(flag, key, value);
1475 if (ret) {
1476 kfree(flag);
1477 return ret;
1478 }
1479
1480 down(&sc->master->master_sem);
1481 list_add_tail(&flag->list, &sc->flags);
1482 up(&sc->master->master_sem);
1483 }
1484 return 0;
1485}
1486
1487/****************************************************************************/
1488
1489#ifdef EC_EOE
1490
1492 const unsigned char *mac_address)
1493{
1494 memcpy(sc->eoe_ip_param_request.mac_address, mac_address, EC_ETH_ALEN);
1495 sc->eoe_ip_param_request.mac_address_included = 1;
1496 return 0;
1497}
1498
1499/****************************************************************************/
1500
1502 struct in_addr ip_address)
1503{
1504 sc->eoe_ip_param_request.ip_address = ip_address;
1505 sc->eoe_ip_param_request.ip_address_included = 1;
1506 return 0;
1507}
1508
1509/****************************************************************************/
1510
1512 struct in_addr subnet_mask)
1513{
1514 sc->eoe_ip_param_request.subnet_mask = subnet_mask;
1515 sc->eoe_ip_param_request.subnet_mask_included = 1;
1516 return 0;
1517}
1518
1519/****************************************************************************/
1520
1522 struct in_addr gateway_address)
1523{
1524 sc->eoe_ip_param_request.gateway = gateway_address;
1525 sc->eoe_ip_param_request.gateway_included = 1;
1526 return 0;
1527}
1528
1529/****************************************************************************/
1530
1532 struct in_addr dns_address)
1533{
1534 sc->eoe_ip_param_request.dns = dns_address;
1535 sc->eoe_ip_param_request.dns_included = 1;
1536 return 0;
1537}
1538
1539/****************************************************************************/
1540
1542 const char *name)
1543{
1544 strncpy(sc->eoe_ip_param_request.name, name, EC_MAX_HOSTNAME_SIZE - 1);
1545 sc->eoe_ip_param_request.name_included = 1;
1546 return 0;
1547}
1548
1549#endif
1550
1551/****************************************************************************/
1552
1554 ec_al_state_t from, ec_al_state_t to, unsigned int timeout_ms)
1555{
1556 ec_al_timeout_t *timeout;
1557 ec_slave_state_t from_state, to_state;
1558
1559 if (from != EC_AL_STATE_INIT && from != EC_AL_STATE_PREOP &&
1560 from != EC_AL_STATE_SAFEOP && from != EC_AL_STATE_OP) {
1561 EC_CONFIG_ERR(sc, "Invalid from state %i.\n", from);
1562 return -EINVAL;
1563 }
1564 if (to != EC_AL_STATE_INIT && to != EC_AL_STATE_PREOP &&
1565 to != EC_AL_STATE_SAFEOP && to != EC_AL_STATE_OP) {
1566 EC_CONFIG_ERR(sc, "Invalid to state %i.\n", to);
1567 return -EINVAL;
1568 }
1569
1570 from_state = (ec_slave_state_t) from;
1571 to_state = (ec_slave_state_t) to;
1572
1573 /* try to find an already configured timeout. */
1574 list_for_each_entry(timeout, &sc->al_timeouts, list) {
1575 if (timeout->from == from_state && timeout->to == to_state) {
1576 if (timeout_ms == 0) {
1577 // delete configured value
1578 list_del(&timeout->list);
1579 kfree(timeout);
1580 return 0;
1581 }
1582 timeout->timeout_ms = timeout_ms;
1583 return 0;
1584 }
1585 }
1586
1587 if (timeout_ms == 0) {
1588 return 0;
1589 }
1590
1591 /* no timeout found. create one. */
1592 if (!(timeout = (ec_al_timeout_t *)
1593 kmalloc(sizeof(ec_al_timeout_t), GFP_KERNEL))) {
1594 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1595 " AL timeout configuration!\n");
1596 return -ENOMEM;
1597 }
1598
1599 timeout->from = from_state;
1600 timeout->to = to_state;
1601 timeout->timeout_ms = timeout_ms;
1602
1603 down(&sc->master->master_sem);
1604 list_add_tail(&timeout->list, &sc->al_timeouts);
1605 up(&sc->master->master_sem);
1606 return 0;
1607}
1608
1609/****************************************************************************/
1610
1612
1613EXPORT_SYMBOL(ecrt_slave_config_sync_manager);
1614EXPORT_SYMBOL(ecrt_slave_config_watchdog);
1619EXPORT_SYMBOL(ecrt_slave_config_pdos);
1620EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry);
1622EXPORT_SYMBOL(ecrt_slave_config_dc);
1623EXPORT_SYMBOL(ecrt_slave_config_sdo);
1624EXPORT_SYMBOL(ecrt_slave_config_sdo8);
1625EXPORT_SYMBOL(ecrt_slave_config_sdo16);
1626EXPORT_SYMBOL(ecrt_slave_config_sdo32);
1627EXPORT_SYMBOL(ecrt_slave_config_complete_sdo);
1628EXPORT_SYMBOL(ecrt_slave_config_emerg_size);
1629EXPORT_SYMBOL(ecrt_slave_config_emerg_pop);
1630EXPORT_SYMBOL(ecrt_slave_config_emerg_clear);
1636EXPORT_SYMBOL(ecrt_slave_config_state);
1637EXPORT_SYMBOL(ecrt_slave_config_idn);
1638EXPORT_SYMBOL(ecrt_slave_config_flag);
1639#ifdef EOE
1645EXPORT_SYMBOL(ecrt_slave_config_eoe_hostname);
1646#endif
1647EXPORT_SYMBOL(ecrt_slave_config_state_timeout);
1648
1650
1651/****************************************************************************/
int ec_coe_emerg_ring_overruns(const ec_coe_emerg_ring_t *ring)
Read the number of overruns.
void ec_coe_emerg_ring_init(ec_coe_emerg_ring_t *ring, ec_slave_config_t *sc)
Emergency ring buffer constructor.
int ec_coe_emerg_ring_pop(ec_coe_emerg_ring_t *ring, u8 *msg)
Remove an emergency message from the ring.
int ec_coe_emerg_ring_clear_ring(ec_coe_emerg_ring_t *ring)
Clear the ring.
int ec_coe_emerg_ring_size(ec_coe_emerg_ring_t *ring, size_t size)
Set the ring size.
void ec_coe_emerg_ring_clear(ec_coe_emerg_ring_t *ring)
Emergency ring buffer destructor.
void ec_eoe_request_init(ec_eoe_request_t *req)
EoE request constructor.
Definition eoe_request.c:38
EtherCAT EoE request structure.
int ec_flag_init(ec_flag_t *flag, const char *key, int32_t value)
SDO request constructor.
Definition flag.c:36
void ec_flag_clear(ec_flag_t *flag)
SDO request destructor.
Definition flag.c:59
EtherCAT Slave Configuration Feature Flag.
void ec_fmmu_config_init(ec_fmmu_config_t *fmmu, ec_slave_config_t *sc, ec_domain_t *domain, uint8_t sync_index, ec_direction_t dir)
FMMU configuration constructor.
Definition fmmu_config.c:42
Global definitions and macros.
ec_slave_state_t
State of an EtherCAT slave.
Definition globals.h:121
@ EC_SLAVE_STATE_OP
OP (mailbox communication and input/output update).
Definition globals.h:132
@ EC_SLAVE_STATE_UNKNOWN
unknown state
Definition globals.h:122
@ EC_MBOX_COE
CANopen over EtherCAT.
Definition globals.h:146
@ EC_MBOX_SOE
Servo-Profile over EtherCAT.
Definition globals.h:148
#define EC_MAX_FMMUS
Maximum number of FMMUs per slave.
Definition globals.h:92
struct ec_slave ec_slave_t
Definition globals.h:309
#define EC_MAX_HOSTNAME_SIZE
Maximum hostname size.
Definition globals.h:110
int ecrt_slave_config_pdos(ec_slave_config_t *sc, unsigned int n_syncs, const ec_sync_info_t syncs[])
Specify a complete PDO configuration.
struct ec_soe_request ec_soe_request_t
Definition ecrt.h:312
int ecrt_slave_config_emerg_clear(ec_slave_config_t *sc)
Clears CoE emergency ring buffer and the overrun counter.
int ecrt_slave_config_sync_manager(ec_slave_config_t *sc, uint8_t sync_index, ec_direction_t dir, ec_watchdog_mode_t watchdog_mode)
Configure a sync manager.
int ecrt_soe_request_idn(ec_soe_request_t *req, uint8_t drive_no, uint16_t idn)
Set the request's drive and Sercos ID numbers.
ec_al_state_t
Application-layer state.
Definition ecrt.h:615
ec_sdo_request_t * ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, size_t size)
Create an SDO request to exchange SDOs during realtime operation.
int ecrt_slave_config_reg_pdo_entry_pos(ec_slave_config_t *sc, uint8_t sync_index, unsigned int pdo_pos, unsigned int entry_pos, ec_domain_t *domain, unsigned int *bit_position)
Registers a PDO entry using its position.
int ecrt_slave_config_watchdog(ec_slave_config_t *sc, uint16_t divider, uint16_t intervals)
Configure a slave's watchdog times.
ec_soe_request_t * ecrt_slave_config_create_soe_request(ec_slave_config_t *sc, uint8_t drive_no, uint16_t idn, size_t size)
Create an SoE request to exchange SoE IDNs during realtime operation.
int ecrt_slave_config_idn(ec_slave_config_t *sc, uint8_t drive_no, uint16_t idn, ec_al_state_t state, const uint8_t *data, size_t size)
Add an SoE IDN configuration.
int ecrt_slave_config_eoe_subnet_mask(ec_slave_config_t *sc, struct in_addr subnet_mask)
Sets the subnet mask for Ethernet-over-EtherCAT (EoE) operation.
int ecrt_slave_config_sdo32(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, uint32_t value)
Add a configuration value for a 32-bit SDO.
int ecrt_slave_config_emerg_overruns(const ec_slave_config_t *sc)
Read the number of CoE emergency overruns.
#define EC_WRITE_U8(DATA, VAL)
Write an 8-bit unsigned value to EtherCAT data.
Definition ecrt.h:3040
struct ec_voe_handler ec_voe_handler_t
Definition ecrt.h:315
int ecrt_slave_config_state(const ec_slave_config_t *sc, ec_slave_config_state_t *state)
Outputs the state of the slave configuration.
ec_voe_handler_t * ecrt_slave_config_create_voe_handler(ec_slave_config_t *sc, size_t size)
Create an VoE handler to exchange vendor-specific data during realtime operation.
int ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc, uint8_t sync_index)
Clear a sync manager's PDO assignment.
struct ec_sdo_request ec_sdo_request_t
Definition ecrt.h:309
int ecrt_slave_config_dc(ec_slave_config_t *sc, uint16_t assign_activate, uint32_t sync0_cycle_time, int32_t sync0_shift_time, uint32_t sync1_cycle_time, int32_t sync1_shift_time)
Configure distributed clocks.
int ecrt_slave_config_flag(ec_slave_config_t *sc, const char *key, int32_t value)
Adds a feature flag to a slave configuration.
struct ec_master ec_master_t
Definition ecrt.h:300
int ecrt_slave_config_eoe_default_gateway(ec_slave_config_t *sc, struct in_addr gateway_address)
Sets the gateway address for Ethernet-over-EtherCAT (EoE) operation.
int ecrt_slave_config_pdo_mapping_add(ec_slave_config_t *sc, uint16_t pdo_index, uint16_t entry_index, uint8_t entry_subindex, uint8_t entry_bit_length)
Add a PDO entry to the given PDO's mapping.
ec_direction_t
Direction type for PDO assignment functions.
Definition ecrt.h:504
int ecrt_slave_config_sdo(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, const uint8_t *data, size_t size)
Add an SDO configuration.
struct ec_domain ec_domain_t
Definition ecrt.h:306
struct ec_slave_config ec_slave_config_t
Definition ecrt.h:303
struct ec_reg_request ec_reg_request_t
Definition ecrt.h:318
int ecrt_slave_config_reg_pdo_entry(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, ec_domain_t *domain, unsigned int *bit_position)
Registers a PDO entry for process data exchange in a domain.
#define EC_WRITE_U32(DATA, VAL)
Write a 32-bit unsigned value to EtherCAT data.
Definition ecrt.h:3074
int ecrt_slave_config_eoe_mac_address(ec_slave_config_t *sc, const unsigned char *mac_address)
Sets the link/MAC address for Ethernet-over-EtherCAT (EoE) operation.
int ecrt_slave_config_complete_sdo(ec_slave_config_t *sc, uint16_t index, const uint8_t *data, size_t size)
Add configuration data for a complete SDO.
ec_watchdog_mode_t
Watchdog mode for sync manager configuration.
Definition ecrt.h:517
int ecrt_slave_config_eoe_ip_address(ec_slave_config_t *sc, struct in_addr ip_address)
Sets the IP address for Ethernet-over-EtherCAT (EoE) operation.
int ecrt_slave_config_eoe_dns_address(ec_slave_config_t *sc, struct in_addr dns_address)
Sets the IPv4 address of the DNS server for Ethernet-over-EtherCAT (EoE) operation.
int ecrt_slave_config_eoe_hostname(ec_slave_config_t *sc, const char *name)
Sets the host name for Ethernet-over-EtherCAT (EoE) operation.
#define EC_END
End of list marker.
Definition ecrt.h:263
int ecrt_slave_config_pdo_mapping_clear(ec_slave_config_t *sc, uint16_t pdo_index)
Clear the mapping of a given PDO.
int ecrt_slave_config_sdo8(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, uint8_t value)
Add a configuration value for an 8-bit SDO.
#define EC_MAX_SYNC_MANAGERS
Maximum number of sync managers per slave.
Definition ecrt.h:267
ec_reg_request_t * ecrt_slave_config_create_reg_request(ec_slave_config_t *sc, size_t size)
Create a register request to exchange EtherCAT register contents during realtime operation.
int ecrt_slave_config_sdo16(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, uint16_t value)
Add a configuration value for a 16-bit SDO.
#define EC_WRITE_U16(DATA, VAL)
Write a 16-bit unsigned value to EtherCAT data.
Definition ecrt.h:3057
int ecrt_slave_config_pdo_assign_add(ec_slave_config_t *sc, uint8_t sync_index, uint16_t pdo_index)
Add a PDO to a sync manager's PDO assignment.
int ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index, uint8_t subindex)
Set the SDO index and subindex.
int ecrt_slave_config_state_timeout(ec_slave_config_t *sc, ec_al_state_t from, ec_al_state_t to, unsigned int timeout_ms)
Sets the application-layer state transition timeout in ms.
int ecrt_slave_config_emerg_pop(ec_slave_config_t *sc, uint8_t *target)
Read and remove one record from the CoE emergency ring buffer.
int ecrt_slave_config_emerg_size(ec_slave_config_t *sc, size_t elements)
Set the size of the CoE emergency ring buffer.
@ EC_AL_STATE_INIT
Init.
Definition ecrt.h:616
@ EC_AL_STATE_OP
Operational.
Definition ecrt.h:619
@ EC_AL_STATE_PREOP
Pre-operational.
Definition ecrt.h:617
@ EC_AL_STATE_SAFEOP
Safe-operational.
Definition ecrt.h:618
@ EC_DIR_INVALID
Invalid direction.
Definition ecrt.h:505
@ EC_DIR_INPUT
Values read by the master.
Definition ecrt.h:507
@ EC_DIR_OUTPUT
Values written by the master.
Definition ecrt.h:506
EtherCAT master character device IOCTL commands.
ec_slave_t * ec_master_find_slave(ec_master_t *master, uint16_t alias, uint16_t position)
Finds a slave in the bus, given the alias and position.
Definition master.c:1830
EtherCAT master structure.
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_pdo_clear_entries(ec_pdo_t *pdo)
Clear PDO entry list.
Definition pdo.c:98
ec_pdo_entry_t * ec_pdo_add_entry(ec_pdo_t *pdo, uint16_t index, uint8_t subindex, uint8_t bit_length)
Add a new PDO entry to the configuration.
Definition pdo.c:149
int ec_pdo_set_name(ec_pdo_t *pdo, const char *name)
Set PDO name.
Definition pdo.c:117
ec_pdo_t * ec_pdo_list_add_pdo(ec_pdo_list_t *pl, uint16_t index)
Add a new PDO to the list.
Definition pdo_list.c:109
ec_pdo_t * ec_pdo_list_find_pdo(const ec_pdo_list_t *pl, uint16_t index)
Finds a PDO with the given index.
Definition pdo_list.c:235
int ec_pdo_list_copy(ec_pdo_list_t *pl, const ec_pdo_list_t *other)
Makes a deep copy of another PDO list.
Definition pdo_list.c:169
void ec_pdo_list_clear_pdos(ec_pdo_list_t *pl)
Clears the list of mapped PDOs.
Definition pdo_list.c:62
void ec_reg_request_clear(ec_reg_request_t *reg)
Register request destructor.
Definition reg_request.c:65
int ec_reg_request_init(ec_reg_request_t *reg, size_t size)
Register request constructor.
Definition reg_request.c:40
void ec_sdo_request_init(ec_sdo_request_t *req)
SDO request constructor.
Definition sdo_request.c:48
int ec_sdo_request_alloc(ec_sdo_request_t *req, size_t size)
Pre-allocates the data memory.
void ec_sdo_request_clear(ec_sdo_request_t *req)
SDO request destructor.
Definition sdo_request.c:70
int ec_sdo_request_copy_data(ec_sdo_request_t *req, const uint8_t *source, size_t size)
Copies SDO data from an external source.
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
#define EC_SLAVE_WARN(slave, fmt, args...)
Convenience macro for printing slave-specific warnings to syslog.
Definition slave.h:82
ec_voe_handler_t * ec_slave_config_find_voe_handler(ec_slave_config_t *sc, unsigned int pos)
Finds a VoE handler via its position in the list.
ec_sdo_request_t * ecrt_slave_config_create_sdo_request_err(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, size_t size)
Same as ecrt_slave_config_create_sdo_request(), but with ERR_PTR() return value.
ec_soe_request_t * ec_slave_config_find_soe_request(ec_slave_config_t *sc, unsigned int pos)
Finds a SoE request via its position in the list.
void ec_slave_config_load_default_sync_config(ec_slave_config_t *sc)
Loads the default PDO assignment from the slave object.
const ec_sdo_request_t * ec_slave_config_get_sdo_by_pos_const(const ec_slave_config_t *sc, unsigned int pos)
Finds an SDO configuration via its position in the list.
ec_voe_handler_t * ecrt_slave_config_create_voe_handler_err(ec_slave_config_t *sc, size_t size)
Same as ecrt_slave_config_create_voe_handler(), but with ERR_PTR() return value.
int ec_slave_config_prepare_fmmu(ec_slave_config_t *, ec_domain_t *, uint8_t, ec_direction_t)
Prepares an FMMU configuration.
void ec_slave_config_clear(ec_slave_config_t *sc)
Slave configuration destructor.
unsigned int ec_slave_config_idn_count(const ec_slave_config_t *sc)
Get the number of IDN configurations.
const ec_flag_t * ec_slave_config_get_flag_by_pos_const(const ec_slave_config_t *sc, unsigned int pos)
Finds a flag via its position in the list.
void ec_slave_config_init(ec_slave_config_t *sc, ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
Slave configuration constructor.
ec_reg_request_t * ec_slave_config_find_reg_request(ec_slave_config_t *sc, unsigned int pos)
Finds a register handler via its position in the list.
ec_soe_request_t * ecrt_slave_config_create_soe_request_err(ec_slave_config_t *sc, uint8_t drive_no, uint16_t idn, size_t size)
Same as ecrt_slave_config_create_soe_request(), but with ERR_PTR() return value.
ec_sdo_request_t * ec_slave_config_find_sdo_request(ec_slave_config_t *sc, unsigned int pos)
Finds a CoE SDO request via its position in the list.
void ec_slave_config_load_default_mapping(const ec_slave_config_t *, ec_pdo_t *)
Loads the default mapping for a PDO from the slave object.
int ec_slave_config_attach(ec_slave_config_t *sc)
Attaches the configuration to the addressed slave object.
unsigned int ec_slave_config_sdo_count(const ec_slave_config_t *sc)
Get the number of SDO configurations.
ec_flag_t * ec_slave_config_find_flag(ec_slave_config_t *sc, const char *key)
Finds a flag.
unsigned int ec_slave_config_flag_count(const ec_slave_config_t *sc)
Get the number of feature flags.
unsigned int ec_slave_config_al_timeout(const ec_slave_config_t *sc, ec_slave_state_t from, ec_slave_state_t to)
Return an AL state timeout.
const ec_soe_request_t * ec_slave_config_get_idn_by_pos_const(const ec_slave_config_t *sc, unsigned int pos)
Finds an IDN configuration via its position in the list.
void ec_slave_config_detach(ec_slave_config_t *sc)
Detaches the configuration from a slave object.
ec_reg_request_t * ecrt_slave_config_create_reg_request_err(ec_slave_config_t *sc, size_t size)
Same as ecrt_slave_config_create_reg_request(), but with ERR_PTR() return value.
EtherCAT slave configuration structure.
#define EC_CONFIG_ERR(sc, fmt, args...)
Convenience macro for printing configuration-specific errors to syslog.
#define EC_CONFIG_WARN(sc, fmt, args...)
Convenience macro for printing configuration-specific warnings to syslog.
#define EC_CONFIG_DBG(sc, level, fmt, args...)
Convenience macro for printing configuration-specific debug messages to syslog.
void ec_soe_request_set_idn(ec_soe_request_t *req, uint16_t idn)
Set IDN.
void ec_soe_request_set_drive_no(ec_soe_request_t *req, uint8_t drive_no)
Set drive number.
Definition soe_request.c:99
int ec_soe_request_copy_data(ec_soe_request_t *req, const uint8_t *source, size_t size)
Copies SoE data from an external source.
void ec_soe_request_init(ec_soe_request_t *req)
SoE request constructor.
Definition soe_request.c:48
int ec_soe_request_alloc(ec_soe_request_t *req, size_t size)
Pre-allocates the data memory.
void ec_soe_request_clear(ec_soe_request_t *req)
SoE request destructor.
Definition soe_request.c:71
EtherCAT application-layer transition timeout.
Slave configutation feature flag.
Definition flag.h:38
char * key
Flag key (null-terminated ASCII string.
Definition flag.h:40
struct list_head list
List item.
Definition flag.h:39
int32_t value
Flag value (meaning depends on key).
Definition flag.h:41
FMMU configuration.
Definition fmmu_config.h:38
uint32_t logical_start_address
Logical start address.
Definition fmmu_config.h:44
const ec_domain_t * domain
Domain.
Definition fmmu_config.h:41
uint8_t sync_index
Index of sync manager to use.
Definition fmmu_config.h:42
ec_reg_request_t * reg_request
Register request to process.
Definition fsm_slave.h:59
struct semaphore master_sem
Master semaphore.
Definition master.h:198
unsigned int debug_level
Master debug level.
Definition master.h:275
PDO entry configuration information.
Definition ecrt.h:531
uint8_t subindex
PDO entry subindex.
Definition ecrt.h:533
uint8_t bit_length
Size of the PDO entry in bit.
Definition ecrt.h:534
uint16_t index
PDO entry index.
Definition ecrt.h:532
PDO entry description.
Definition pdo_entry.h:40
uint8_t bit_length
entry length in bit
Definition pdo_entry.h:45
uint8_t subindex
PDO entry subindex.
Definition pdo_entry.h:43
uint16_t index
PDO entry index.
Definition pdo_entry.h:42
PDO configuration information.
Definition ecrt.h:545
unsigned int n_entries
Number of PDO entries in entries to map.
Definition ecrt.h:547
uint16_t index
PDO index.
Definition ecrt.h:546
ec_pdo_entry_info_t const * entries
Array of PDO entries to map.
Definition ecrt.h:551
struct list_head list
List of PDOs.
Definition pdo_list.h:42
PDO description.
Definition pdo.h:41
struct list_head entries
List of PDO entries.
Definition pdo.h:46
int8_t sync_index
Assigned sync manager.
Definition pdo.h:44
uint16_t index
PDO index.
Definition pdo.h:43
char * name
PDO name.
Definition pdo.h:45
struct list_head list
List item.
Definition reg_request.h:41
struct list_head list
List item.
Definition sdo_request.h:41
uint8_t complete_access
SDO shall be transferred completely.
Definition sdo_request.h:47
size_t data_size
Size of SDO data.
Definition sdo_request.h:46
uint8_t * data
Pointer to SDO data.
Definition sdo_request.h:44
ec_sync_t * syncs
SYNC MANAGER categories.
Definition slave.h:157
uint32_t product_code
Vendor-specific product code.
Definition slave.h:128
uint16_t mailbox_protocols
Supported mailbox protocols.
Definition slave.h:139
uint32_t vendor_id
Vendor ID.
Definition slave.h:127
unsigned int sync_count
Number of sync managers.
Definition slave.h:158
Slave configuration state.
Definition ecrt.h:376
unsigned int online
The slave is online.
Definition ecrt.h:377
unsigned int operational
The slave was brought into OP state using the specified configuration.
Definition ecrt.h:378
unsigned int al_state
The application-layer state of the slave.
Definition ecrt.h:380
uint32_t product_code
Slave product code.
ec_sync_config_t sync_configs[EC_MAX_SYNC_MANAGERS]
Sync manager configurations.
struct list_head flags
List of feature flags.
struct list_head reg_requests
List of register requests.
uint16_t dc_assign_activate
Vendor-specific AssignActivate word.
struct list_head sdo_requests
List of SDO requests.
uint16_t watchdog_intervals
Process data watchdog intervals (see spec.
uint16_t alias
Slave alias.
ec_fmmu_config_t fmmu_configs[EC_MAX_FMMUS]
FMMU configurations.
ec_coe_emerg_ring_t emerg_ring
CoE emergency ring buffer.
ec_sync_signal_t dc_sync[EC_SYNC_SIGNAL_COUNT]
DC sync signals.
struct list_head soe_requests
List of SoE requests.
struct list_head soe_configs
List of SoE configurations.
struct list_head sdo_configs
List of SDO configurations.
uint16_t watchdog_divider
Watchdog divider as a number of 40ns intervals (see spec.
uint8_t used_fmmus
Number of FMMUs used.
ec_master_t * master
Master owning the slave configuration.
ec_slave_t * slave
Slave pointer.
struct list_head al_timeouts
List of specific AL state timeouts.
uint32_t vendor_id
Slave vendor ID.
uint16_t position
Index after alias.
ec_eoe_request_t eoe_ip_param_request
EoE IP parameters.
struct list_head voe_handlers
List of VoE handlers.
ec_sii_t sii
Extracted SII data.
Definition slave.h:215
unsigned int force_config
Force (re-)configuration.
Definition slave.h:186
uint16_t ring_position
Ring position.
Definition slave.h:175
ec_slave_config_t * config
Current configuration.
Definition slave.h:182
ec_slave_state_t current_state
Current application state.
Definition slave.h:184
ec_fsm_slave_t fsm
Slave state machine.
Definition slave.h:227
ec_al_state_t al_state
AL state (only valid for IDN config).
Definition soe_request.h:44
size_t data_size
Size of SDO data.
Definition soe_request.h:47
uint8_t * data
Pointer to SDO data.
Definition soe_request.h:45
struct list_head list
List item.
Definition soe_request.h:41
Sync manager configuration.
Definition sync_config.h:38
ec_direction_t dir
Sync manager direction.
Definition sync_config.h:39
ec_watchdog_mode_t watchdog_mode
Watchdog mode.
Definition sync_config.h:40
ec_pdo_list_t pdos
Current PDO assignment.
Definition sync_config.h:41
Sync manager configuration information.
Definition ecrt.h:564
unsigned int n_pdos
Number of PDOs in pdos.
Definition ecrt.h:569
ec_direction_t dir
Sync manager direction.
Definition ecrt.h:568
uint8_t index
Sync manager index.
Definition ecrt.h:565
ec_pdo_info_t const * pdos
Array with PDOs to assign.
Definition ecrt.h:570
ec_watchdog_mode_t watchdog_mode
Watchdog mode.
Definition ecrt.h:572
uint32_t cycle_time
Cycle time [ns].
Definition globals.h:180
int32_t shift_time
Shift time [ns].
Definition globals.h:181
Sync manager.
Definition sync.h:39
ec_pdo_list_t pdos
Current PDO assignment.
Definition sync.h:45
struct list_head list
List item.
Definition voe_handler.h:42
ec_direction_t ec_sync_default_direction(const ec_sync_t *sync)
Determines the default direction from the control register.
Definition sync.c:159
void ec_sync_config_clear(ec_sync_config_t *sync_config)
Destructor.
Definition sync_config.c:48
void ec_sync_config_init(ec_sync_config_t *sync_config)
Constructor.
Definition sync_config.c:35
void ec_voe_handler_clear(ec_voe_handler_t *voe)
VoE handler destructor.
Definition voe_handler.c:87
int ec_voe_handler_init(ec_voe_handler_t *voe, ec_slave_config_t *sc, size_t size)
VoE handler constructor.
Definition voe_handler.c:64
Vendor specific over EtherCAT protocol handler.