IgH EtherCAT Master  1.7.0
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
94
95 sc->slave = NULL;
96
97 for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
99
100 sc->used_fmmus = 0;
101 sc->dc_assign_activate = 0x0000;
102 sc->dc_sync[0].cycle_time = 0U;
103 sc->dc_sync[1].cycle_time = 0;
104 sc->dc_sync[0].shift_time = 0U;
105 sc->dc_sync[1].shift_time = 0;
106
107 INIT_LIST_HEAD(&sc->sdo_configs);
108 INIT_LIST_HEAD(&sc->sdo_requests);
109 INIT_LIST_HEAD(&sc->soe_requests);
110 INIT_LIST_HEAD(&sc->reg_requests);
111 INIT_LIST_HEAD(&sc->voe_handlers);
112 INIT_LIST_HEAD(&sc->soe_configs);
113 INIT_LIST_HEAD(&sc->flags);
114 INIT_LIST_HEAD(&sc->al_timeouts);
115
116#ifdef EC_EOE
118#endif
119
121}
122
123/****************************************************************************/
124
131 )
132{
133 unsigned int i;
134 ec_sdo_request_t *req, *next_req;
135 ec_voe_handler_t *voe, *next_voe;
136 ec_reg_request_t *reg, *next_reg;
137 ec_soe_request_t *soe, *next_soe;
138 ec_flag_t *flag, *next_flag;
139 ec_al_timeout_t *timeout, *next_timeout;
140
142
143 // Free sync managers
144 for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
146
147 // free all SDO configurations
148 list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
149 list_del(&req->list);
151 kfree(req);
152 }
153
154 // free all SDO requests
155 list_for_each_entry_safe(req, next_req, &sc->sdo_requests, list) {
156 list_del(&req->list);
158 kfree(req);
159 }
160
161 // free all SoE requests
162 list_for_each_entry_safe(soe, next_soe, &sc->soe_requests, list) {
163 list_del(&soe->list);
165 kfree(soe);
166 }
167
168 // free all register requests
169 list_for_each_entry_safe(reg, next_reg, &sc->reg_requests, list) {
170 list_del(&reg->list);
172 kfree(reg);
173 }
174
175 // free all VoE handlers
176 list_for_each_entry_safe(voe, next_voe, &sc->voe_handlers, list) {
177 list_del(&voe->list);
179 kfree(voe);
180 }
181
182 // free all SoE configurations
183 list_for_each_entry_safe(soe, next_soe, &sc->soe_configs, list) {
184 list_del(&soe->list);
186 kfree(soe);
187 }
188
189 // free all flags
190 list_for_each_entry_safe(flag, next_flag, &sc->flags, list) {
191 list_del(&flag->list);
192 ec_flag_clear(flag);
193 kfree(flag);
194 }
195
196 // free all AL timeouts
197 list_for_each_entry_safe(timeout, next_timeout, &sc->al_timeouts, list) {
198 list_del(&timeout->list);
199 kfree(timeout);
200 }
201
203}
204
205/****************************************************************************/
206
221 ec_domain_t *domain,
222 uint8_t sync_index,
223 ec_direction_t dir
224 )
225{
226 unsigned int i;
227 ec_fmmu_config_t *fmmu;
228
229 // FMMU configuration already prepared?
230 for (i = 0; i < sc->used_fmmus; i++) {
231 fmmu = &sc->fmmu_configs[i];
232 if (fmmu->domain == domain && fmmu->sync_index == sync_index)
233 return fmmu->logical_start_address;
234 }
235
236 if (sc->used_fmmus == EC_MAX_FMMUS) {
237 EC_CONFIG_ERR(sc, "FMMU limit reached!\n");
238 return -EOVERFLOW;
239 }
240
241 fmmu = &sc->fmmu_configs[sc->used_fmmus++];
242
243 down(&sc->master->master_sem);
244 ec_fmmu_config_init(fmmu, sc, domain, sync_index, dir);
245 up(&sc->master->master_sem);
246
247 return fmmu->logical_start_address;
248}
249
250/****************************************************************************/
251
259 )
260{
261 ec_slave_t *slave;
262
263 if (sc->slave)
264 return 0; // already attached
265
266 if (!(slave = ec_master_find_slave(
267 sc->master, sc->alias, sc->position))) {
268 EC_CONFIG_DBG(sc, 1, "Failed to find slave for configuration.\n");
269 return -ENOENT;
270 }
271
272 if (slave->config) {
273 EC_CONFIG_DBG(sc, 1, "Failed to attach configuration. Slave %u"
274 " already has a configuration!\n", slave->ring_position);
275 return -EEXIST;
276 }
277
278 if (
279#ifdef EC_IDENT_WILDCARDS
280 sc->vendor_id != 0xffffffff &&
281#endif
282 slave->sii.vendor_id != sc->vendor_id
283 ) {
284 EC_CONFIG_DBG(sc, 1, "Slave %u has no matching vendor ID (0x%08X)"
285 " for configuration (0x%08X).\n",
286 slave->ring_position, slave->sii.vendor_id, sc->vendor_id);
287 return -EINVAL;
288 }
289
290 if (
291#ifdef EC_IDENT_WILDCARDS
292 sc->product_code != 0xffffffff &&
293#endif
294 slave->sii.product_code != sc->product_code
295 ) {
296 EC_CONFIG_DBG(sc, 1, "Slave %u has no matching product code (0x%08X)"
297 " for configuration (0x%08X).\n",
298 slave->ring_position, slave->sii.product_code,
299 sc->product_code);
300 return -EINVAL;
301 }
302
303 // attach slave
304 slave->config = sc;
305 sc->slave = slave;
306
307 EC_CONFIG_DBG(sc, 1, "Attached slave %u.\n", slave->ring_position);
308 return 0;
309}
310
311/****************************************************************************/
312
317 )
318{
319 if (sc->slave) {
320 ec_reg_request_t *reg;
321 ec_voe_handler_t *voe;
322
323 // abandon VoE reads holding the slave's mailbox read lock
324 list_for_each_entry(voe, &sc->voe_handlers, list) {
326 }
327
328 sc->slave->config = NULL;
329
330 // invalidate processing register request
331 list_for_each_entry(reg, &sc->reg_requests, list) {
332 if (sc->slave->fsm.reg_request == reg) {
333 sc->slave->fsm.reg_request = NULL;
334 break;
335 }
336 }
337
338 sc->slave = NULL;
339 }
340}
341
342/****************************************************************************/
343
347{
348 uint8_t sync_index;
349 ec_sync_config_t *sync_config;
350 const ec_sync_t *sync;
351
352 if (!sc->slave)
353 return;
354
355 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
356 sync_config = &sc->sync_configs[sync_index];
357 if ((sync = ec_slave_get_sync(sc->slave, sync_index))) {
358 sync_config->dir = ec_sync_default_direction(sync);
359 if (sync_config->dir == EC_DIR_INVALID)
361 "SM%u has an invalid direction field!\n", sync_index);
362 ec_pdo_list_copy(&sync_config->pdos, &sync->pdos);
363 }
364 }
365}
366
367/****************************************************************************/
368
372 const ec_slave_config_t *sc,
373 ec_pdo_t *pdo
374 )
375{
376 unsigned int i;
377 const ec_sync_t *sync;
378 const ec_pdo_t *default_pdo;
379
380 if (!sc->slave)
381 return;
382
383 EC_CONFIG_DBG(sc, 1, "Loading default mapping for PDO 0x%04X.\n",
384 pdo->index);
385
386 // find PDO in any sync manager (it could be reassigned later)
387 for (i = 0; i < sc->slave->sii.sync_count; i++) {
388 sync = &sc->slave->sii.syncs[i];
389
390 list_for_each_entry(default_pdo, &sync->pdos.list, list) {
391 if (default_pdo->index != pdo->index)
392 continue;
393
394 if (default_pdo->name) {
395 EC_CONFIG_DBG(sc, 1, "Found PDO name \"%s\".\n",
396 default_pdo->name);
397
398 // take PDO name from assigned one
399 ec_pdo_set_name(pdo, default_pdo->name);
400 }
401
402 // copy entries (= default PDO mapping)
403 if (ec_pdo_copy_entries(pdo, default_pdo))
404 return;
405
406 if (sc->master->debug_level) {
407 const ec_pdo_entry_t *entry;
408 list_for_each_entry(entry, &pdo->entries, list) {
409 EC_CONFIG_DBG(sc, 1, "Entry 0x%04X:%02X.\n",
410 entry->index, entry->subindex);
411 }
412 }
413
414 return;
415 }
416 }
417
418 EC_CONFIG_DBG(sc, 1, "No default mapping found.\n");
419}
420
421/****************************************************************************/
422
428 const ec_slave_config_t *sc
429 )
430{
431 const ec_sdo_request_t *req;
432 unsigned int count = 0;
433
434 list_for_each_entry(req, &sc->sdo_configs, list) {
435 count++;
436 }
437
438 return count;
439}
440
441/****************************************************************************/
442
450 const ec_slave_config_t *sc,
451 unsigned int pos
452 )
453{
454 const ec_sdo_request_t *req;
455
456 list_for_each_entry(req, &sc->sdo_configs, list) {
457 if (pos--)
458 continue;
459 return req;
460 }
461
462 return NULL;
463}
464
465/****************************************************************************/
466
472 const ec_slave_config_t *sc
473 )
474{
475 const ec_soe_request_t *req;
476 unsigned int count = 0;
477
478 list_for_each_entry(req, &sc->soe_configs, list) {
479 count++;
480 }
481
482 return count;
483}
484
485/****************************************************************************/
486
494 const ec_slave_config_t *sc,
495 unsigned int pos
496 )
497{
498 const ec_soe_request_t *req;
499
500 list_for_each_entry(req, &sc->soe_configs, list) {
501 if (pos--)
502 continue;
503 return req;
504 }
505
506 return NULL;
507}
508
509/****************************************************************************/
510
516 const ec_slave_config_t *sc
517 )
518{
519 const ec_flag_t *flag;
520 unsigned int count = 0;
521
522 list_for_each_entry(flag, &sc->flags, list) {
523 count++;
524 }
525
526 return count;
527}
528
529/****************************************************************************/
530
538 const ec_slave_config_t *sc,
539 unsigned int pos
540 )
541{
542 const ec_flag_t *flag;
543
544 list_for_each_entry(flag, &sc->flags, list) {
545 if (pos--)
546 continue;
547 return flag;
548 }
549
550 return NULL;
551}
552
553/****************************************************************************/
554
561 unsigned int pos
562 )
563{
564 ec_sdo_request_t *req;
565
566 list_for_each_entry(req, &sc->sdo_requests, list) {
567 if (pos--)
568 continue;
569 return req;
570 }
571
572 return NULL;
573}
574
575/****************************************************************************/
576
583 unsigned int pos
584 )
585{
586 ec_soe_request_t *req;
587
588 list_for_each_entry(req, &sc->soe_requests, list) {
589 if (pos--)
590 continue;
591 return req;
592 }
593
594 return NULL;
595}
596
597/****************************************************************************/
598
605 unsigned int pos
606 )
607{
608 ec_reg_request_t *reg;
609
610 list_for_each_entry(reg, &sc->reg_requests, list) {
611 if (pos--)
612 continue;
613 return reg;
614 }
615
616 return NULL;
617}
618
619/****************************************************************************/
620
627 unsigned int pos
628 )
629{
630 ec_voe_handler_t *voe;
631
632 list_for_each_entry(voe, &sc->voe_handlers, list) {
633 if (pos--)
634 continue;
635 return voe;
636 }
637
638 return NULL;
639}
640
641/****************************************************************************/
642
649 const char *key
650 )
651{
652 if (sc) {
653 ec_flag_t *flag;
654 list_for_each_entry(flag, &sc->flags, list) {
655 if (!strcmp(flag->key, key)) {
656 return flag;
657 }
658 }
659 }
660
661 return NULL;
662}
663
664/****************************************************************************/
665
672{
673 ec_al_timeout_t *timeout;
674
675 list_for_each_entry(timeout, &sc->al_timeouts, list) {
676 if (timeout->from == from && timeout->to == to) {
677 return timeout->timeout_ms;
678 }
679 }
680
681 return 0;
682}
683
684/*****************************************************************************
685 * Application interface
686 ****************************************************************************/
687
689 ec_direction_t dir, ec_watchdog_mode_t watchdog_mode)
690{
691 ec_sync_config_t *sync_config;
692
693 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, sync_index = %u, dir = %i,"
694 " watchdog_mode = %i)\n", __func__, sc, sync_index, dir,
695 watchdog_mode);
696
697 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
698 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n", sync_index);
699 return -ENOENT;
700 }
701
702 if (dir != EC_DIR_OUTPUT && dir != EC_DIR_INPUT) {
703 EC_CONFIG_ERR(sc, "Invalid direction %u!\n", (unsigned int) dir);
704 return -EINVAL;
705 }
706
707 sync_config = &sc->sync_configs[sync_index];
708 sync_config->dir = dir;
709 sync_config->watchdog_mode = watchdog_mode;
710 return 0;
711}
712
713/****************************************************************************/
714
716 uint16_t divider, uint16_t intervals)
717{
718 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, divider = %u, intervals = %u)\n",
719 __func__, sc, divider, intervals);
720
721 sc->watchdog_divider = divider;
722 sc->watchdog_intervals = intervals;
723 return 0;
724}
725
726/****************************************************************************/
727
729 ec_pdo_mode_t assign_mode, ec_pdo_mode_t config_mode)
730{
731 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, assign_mode = %u,"
732 " config_mode = %u)\n", __func__, sc, assign_mode, config_mode);
733
734 if (assign_mode > EC_PDO_MODE_WRITE_IF_DIFFERENT) {
735 EC_CONFIG_ERR(sc, "Invalid PDO assignment mode %u!\n", assign_mode);
736 return -EINVAL;
737 }
738
739 if (config_mode > EC_PDO_MODE_WRITE_IF_DIFFERENT) {
740 EC_CONFIG_ERR(sc, "Invalid PDO configuration mode %u!\n",
741 config_mode);
742 return -EINVAL;
743 }
744
745 sc->pdo_assign_mode = assign_mode;
746 sc->pdo_config_mode = config_mode;
747 return 0;
748}
749
750/****************************************************************************/
751
753 uint8_t sync_index, uint16_t pdo_index)
754{
755 ec_pdo_t *pdo;
756
757 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, sync_index = %u, "
758 "pdo_index = 0x%04X)\n", __func__, sc, sync_index, pdo_index);
759
760 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
761 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n", sync_index);
762 return -EINVAL;
763 }
764
765 down(&sc->master->master_sem);
766
767 pdo = ec_pdo_list_add_pdo(&sc->sync_configs[sync_index].pdos, pdo_index);
768 if (IS_ERR(pdo)) {
769 up(&sc->master->master_sem);
770 return PTR_ERR(pdo);
771 }
772 pdo->sync_index = sync_index;
773
775
776 up(&sc->master->master_sem);
777 return 0;
778}
779
780/****************************************************************************/
781
783 uint8_t sync_index)
784{
785 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, sync_index = %u)\n",
786 __func__, sc, sync_index);
787
788 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
789 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n", sync_index);
790 return -EINVAL;
791 }
792
793 down(&sc->master->master_sem);
794 ec_pdo_list_clear_pdos(&sc->sync_configs[sync_index].pdos);
795 up(&sc->master->master_sem);
796 return 0;
797}
798
799/****************************************************************************/
800
802 uint16_t pdo_index, uint16_t entry_index, uint8_t entry_subindex,
803 uint8_t entry_bit_length)
804{
805 uint8_t sync_index;
806 ec_pdo_t *pdo = NULL;
807 ec_pdo_entry_t *entry;
808 int retval = 0;
809
810 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, "
811 "pdo_index = 0x%04X, entry_index = 0x%04X, "
812 "entry_subindex = 0x%02X, entry_bit_length = %u)\n",
813 __func__, sc, pdo_index, entry_index, entry_subindex,
814 entry_bit_length);
815
816 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
817 if ((pdo = ec_pdo_list_find_pdo(
818 &sc->sync_configs[sync_index].pdos, pdo_index)))
819 break;
820
821 if (pdo) {
822 down(&sc->master->master_sem);
823 entry = ec_pdo_add_entry(pdo, entry_index, entry_subindex,
824 entry_bit_length);
825 up(&sc->master->master_sem);
826 if (IS_ERR(entry))
827 retval = PTR_ERR(entry);
828 } else {
829 EC_CONFIG_ERR(sc, "PDO 0x%04X is not assigned.\n", pdo_index);
830 retval = -ENOENT;
831 }
832
833 return retval;
834}
835
836/****************************************************************************/
837
839 uint16_t pdo_index)
840{
841 uint8_t sync_index;
842 ec_pdo_t *pdo = NULL;
843
844 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, pdo_index = 0x%04X)\n",
845 __func__, sc, pdo_index);
846
847 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
848 if ((pdo = ec_pdo_list_find_pdo(
849 &sc->sync_configs[sync_index].pdos, pdo_index)))
850 break;
851
852 if (pdo) {
853 down(&sc->master->master_sem);
855 up(&sc->master->master_sem);
856 } else {
857 EC_CONFIG_WARN(sc, "PDO 0x%04X is not assigned.\n", pdo_index);
858 }
859 return 0;
860}
861
862/****************************************************************************/
863
865 unsigned int n_syncs, const ec_sync_info_t syncs[])
866{
867 int ret;
868 unsigned int i, j, k;
869 const ec_sync_info_t *sync_info;
870 const ec_pdo_info_t *pdo_info;
871 const ec_pdo_entry_info_t *entry_info;
872
873 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, n_syncs = %u, syncs = 0x%p)\n",
874 __func__, sc, n_syncs, syncs);
875
876 if (!syncs)
877 return 0;
878
879 for (i = 0; i < n_syncs; i++) {
880 sync_info = &syncs[i];
881
882 if (sync_info->index == (uint8_t) EC_END)
883 break;
884
885 if (sync_info->index >= EC_MAX_SYNC_MANAGERS) {
886 EC_CONFIG_ERR(sc, "Invalid sync manager index %u!\n",
887 sync_info->index);
888 return -ENOENT;
889 }
890
891 ret = ecrt_slave_config_sync_manager(sc, sync_info->index,
892 sync_info->dir, sync_info->watchdog_mode);
893 if (ret)
894 return ret;
895
897
898 if (sync_info->n_pdos && sync_info->pdos) {
899 for (j = 0; j < sync_info->n_pdos; j++) {
900 pdo_info = &sync_info->pdos[j];
901
903 sc, sync_info->index, pdo_info->index);
904 if (ret)
905 return ret;
906
908
909 if (pdo_info->n_entries && pdo_info->entries) {
910 for (k = 0; k < pdo_info->n_entries; k++) {
911 entry_info = &pdo_info->entries[k];
912
914 pdo_info->index, entry_info->index,
915 entry_info->subindex,
916 entry_info->bit_length);
917 if (ret)
918 return ret;
919 }
920 }
921 }
922 }
923 }
924
925 return 0;
926}
927
928/****************************************************************************/
929
932 uint16_t index,
933 uint8_t subindex,
934 ec_domain_t *domain,
935 unsigned int *bit_position
936 )
937{
938 uint8_t sync_index;
939 const ec_sync_config_t *sync_config;
940 unsigned int bit_offset, bit_pos;
941 ec_pdo_t *pdo;
942 ec_pdo_entry_t *entry;
943 int sync_offset;
944
945 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
946 "subindex = 0x%02X, domain = 0x%p, bit_position = 0x%p)\n",
947 __func__, sc, index, subindex, domain, bit_position);
948
949 for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
950 sync_config = &sc->sync_configs[sync_index];
951 bit_offset = 0;
952
953 list_for_each_entry(pdo, &sync_config->pdos.list, list) {
954 list_for_each_entry(entry, &pdo->entries, list) {
955 if (entry->index != index || entry->subindex != subindex) {
956 bit_offset += entry->bit_length;
957 } else {
958 bit_pos = bit_offset % 8;
959 if (bit_position) {
960 *bit_position = bit_pos;
961 } else if (bit_pos) {
962 EC_CONFIG_ERR(sc, "PDO entry 0x%04X:%02X does"
963 " not byte-align.\n", index, subindex);
964 return -EFAULT;
965 }
966
967 sync_offset = ec_slave_config_prepare_fmmu(
968 sc, domain, sync_index, sync_config->dir);
969 if (sync_offset < 0)
970 return sync_offset;
971
972 return sync_offset + bit_offset / 8;
973 }
974 }
975 }
976 }
977
978 EC_CONFIG_ERR(sc, "PDO entry 0x%04X:%02X is not mapped.\n",
979 index, subindex);
980 return -ENOENT;
981}
982
983/****************************************************************************/
984
987 uint8_t sync_index,
988 unsigned int pdo_pos,
989 unsigned int entry_pos,
990 ec_domain_t *domain,
991 unsigned int *bit_position
992 )
993{
994 const ec_sync_config_t *sync_config;
995 unsigned int bit_offset, pp, ep;
996 ec_pdo_t *pdo;
997 ec_pdo_entry_t *entry;
998
999 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, sync_index = %u, pdo_pos = %u,"
1000 " entry_pos = %u, domain = 0x%p, bit_position = 0x%p)\n",
1001 __func__, sc, sync_index, pdo_pos, entry_pos,
1002 domain, bit_position);
1003
1004 if (sync_index >= EC_MAX_SYNC_MANAGERS) {
1005 EC_CONFIG_ERR(sc, "Invalid syncmanager position %u.\n", sync_index);
1006 return -EINVAL;
1007 }
1008
1009 sync_config = &sc->sync_configs[sync_index];
1010 bit_offset = 0;
1011 pp = 0;
1012
1013 list_for_each_entry(pdo, &sync_config->pdos.list, list) {
1014 ep = 0;
1015 list_for_each_entry(entry, &pdo->entries, list) {
1016 if (pp != pdo_pos || ep != entry_pos) {
1017 bit_offset += entry->bit_length;
1018 } else {
1019 unsigned int bit_pos = bit_offset % 8;
1020 int sync_offset;
1021
1022 if (bit_position) {
1023 *bit_position = bit_pos;
1024 } else if (bit_pos) {
1025 EC_CONFIG_ERR(sc, "PDO entry 0x%04X:%02X does"
1026 " not byte-align.\n",
1027 pdo->index, entry->subindex);
1028 return -EFAULT;
1029 }
1030
1031 sync_offset = ec_slave_config_prepare_fmmu(
1032 sc, domain, sync_index, sync_config->dir);
1033 if (sync_offset < 0)
1034 return sync_offset;
1035
1036 return sync_offset + bit_offset / 8;
1037 }
1038 ep++;
1039 }
1040 pp++;
1041 }
1042
1043 EC_CONFIG_ERR(sc, "PDO entry specification %u/%u/%u out of range.\n",
1044 sync_index, pdo_pos, entry_pos);
1045 return -ENOENT;
1046}
1047
1048/****************************************************************************/
1049
1050int ecrt_slave_config_dc(ec_slave_config_t *sc, uint16_t assign_activate,
1051 uint32_t sync0_cycle_time, int32_t sync0_shift_time,
1052 uint32_t sync1_cycle_time, int32_t sync1_shift_time)
1053{
1054 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, assign_activate = 0x%04X,"
1055 " sync0_cycle = %u, sync0_shift = %i,"
1056 " sync1_cycle = %u, sync1_shift = %i\n",
1057 __func__, sc, assign_activate, sync0_cycle_time, sync0_shift_time,
1058 sync1_cycle_time, sync1_shift_time);
1059
1060 sc->dc_assign_activate = assign_activate;
1061 sc->dc_sync[0].cycle_time = sync0_cycle_time;
1062 sc->dc_sync[0].shift_time = sync0_shift_time;
1063 sc->dc_sync[1].cycle_time = sync1_cycle_time;
1064 sc->dc_sync[1].shift_time = sync1_shift_time;
1065 return 0;
1066}
1067
1068/****************************************************************************/
1069
1071 uint8_t subindex, const uint8_t *data, size_t size)
1072{
1073 ec_slave_t *slave = sc->slave;
1074 ec_sdo_request_t *req;
1075 int ret;
1076
1077 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1078 "subindex = 0x%02X, data = 0x%p, size = %zu)\n",
1079 __func__, sc, index, subindex, data, size);
1080
1081 if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
1082 EC_CONFIG_WARN(sc, "Attached slave does not support CoE!\n");
1083 }
1084
1085 if (!(req = (ec_sdo_request_t *)
1086 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
1087 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1088 " SDO configuration!\n");
1089 return -ENOMEM;
1090 }
1091
1093 ecrt_sdo_request_index(req, index, subindex);
1094
1095 ret = ec_sdo_request_copy_data(req, data, size);
1096 if (ret < 0) {
1098 kfree(req);
1099 return ret;
1100 }
1101
1102 down(&sc->master->master_sem);
1103 list_add_tail(&req->list, &sc->sdo_configs);
1104 up(&sc->master->master_sem);
1105 return 0;
1106}
1107
1108/****************************************************************************/
1109
1111 uint8_t subindex, uint8_t value)
1112{
1113 uint8_t data[1];
1114
1115 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1116 "subindex = 0x%02X, value = %u)\n",
1117 __func__, sc, index, subindex, (unsigned int) value);
1118
1119 EC_WRITE_U8(data, value);
1120 return ecrt_slave_config_sdo(sc, index, subindex, data, 1);
1121}
1122
1123/****************************************************************************/
1124
1126 uint8_t subindex, uint16_t value)
1127{
1128 uint8_t data[2];
1129
1130 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1131 "subindex = 0x%02X, value = %u)\n",
1132 __func__, sc, index, subindex, value);
1133
1134 EC_WRITE_U16(data, value);
1135 return ecrt_slave_config_sdo(sc, index, subindex, data, 2);
1136}
1137
1138/****************************************************************************/
1139
1141 uint8_t subindex, uint32_t value)
1142{
1143 uint8_t data[4];
1144
1145 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1146 "subindex = 0x%02X, value = %u)\n",
1147 __func__, sc, index, subindex, value);
1148
1149 EC_WRITE_U32(data, value);
1150 return ecrt_slave_config_sdo(sc, index, subindex, data, 4);
1151}
1152
1153/****************************************************************************/
1154
1156 const uint8_t *data, size_t size)
1157{
1158 ec_slave_t *slave = sc->slave;
1159 ec_sdo_request_t *req;
1160 int ret;
1161
1162 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, index = 0x%04X, "
1163 "data = 0x%p, size = %zu)\n", __func__, sc, index, data, size);
1164
1165 if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
1166 EC_CONFIG_WARN(sc, "Attached slave does not support CoE!\n");
1167 }
1168
1169 if (!(req = (ec_sdo_request_t *)
1170 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
1171 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1172 " SDO configuration!\n");
1173 return -ENOMEM;
1174 }
1175
1177 ecrt_sdo_request_index(req, index, 0);
1178 req->complete_access = 1;
1179
1180 ret = ec_sdo_request_copy_data(req, data, size);
1181 if (ret < 0) {
1183 kfree(req);
1184 return ret;
1185 }
1186
1187 down(&sc->master->master_sem);
1188 list_add_tail(&req->list, &sc->sdo_configs);
1189 up(&sc->master->master_sem);
1190 return 0;
1191}
1192
1193/****************************************************************************/
1194
1196{
1197 return ec_coe_emerg_ring_size(&sc->emerg_ring, elements);
1198}
1199
1200/****************************************************************************/
1201
1203{
1204 return ec_coe_emerg_ring_pop(&sc->emerg_ring, target);
1205}
1206
1207/****************************************************************************/
1208
1213
1214/****************************************************************************/
1215
1220
1221/****************************************************************************/
1222
1227 ec_slave_config_t *sc, uint16_t index, uint8_t subindex, size_t size)
1228{
1229 ec_sdo_request_t *req;
1230 int ret;
1231
1232 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, "
1233 "index = 0x%04X, subindex = 0x%02X, size = %zu)\n",
1234 __func__, sc, index, subindex, size);
1235
1236 if (!(req = (ec_sdo_request_t *)
1237 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
1238 EC_CONFIG_ERR(sc, "Failed to allocate SDO request memory!\n");
1239 return ERR_PTR(-ENOMEM);
1240 }
1241
1243 ecrt_sdo_request_index(req, index, subindex);
1244
1245 ret = ec_sdo_request_alloc(req, size);
1246 if (ret < 0) {
1248 kfree(req);
1249 return ERR_PTR(ret);
1250 }
1251
1252 // prepare data for optional writing
1253 memset(req->data, 0x00, size);
1254 req->data_size = size;
1255
1256 down(&sc->master->master_sem);
1257 list_add_tail(&req->list, &sc->sdo_requests);
1258 up(&sc->master->master_sem);
1259
1260 return req;
1261}
1262
1263/****************************************************************************/
1264
1266 ec_slave_config_t *sc, uint16_t index, uint8_t subindex, size_t size)
1267{
1269 subindex, size);
1270 return IS_ERR(s) ? NULL : s;
1271}
1272
1273/****************************************************************************/
1274
1279 ec_slave_config_t *sc, uint8_t drive_no, uint16_t idn, size_t size)
1280{
1281 ec_soe_request_t *req;
1282 int ret;
1283
1284 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, "
1285 "drive_no = 0x%02X, idn = 0x%04X, size = %zu)\n",
1286 __func__, sc, drive_no, idn, size);
1287
1288 if (!(req = (ec_soe_request_t *)
1289 kmalloc(sizeof(ec_soe_request_t), GFP_KERNEL))) {
1290 EC_CONFIG_ERR(sc, "Failed to allocate IDN request memory!\n");
1291 return ERR_PTR(-ENOMEM);
1292 }
1293
1295 ecrt_soe_request_idn(req, drive_no, idn);
1296
1297 ret = ec_soe_request_alloc(req, size);
1298 if (ret < 0) {
1300 kfree(req);
1301 return ERR_PTR(ret);
1302 }
1303
1304 // prepare data for optional writing
1305 memset(req->data, 0x00, size);
1306 req->data_size = size;
1307
1308 down(&sc->master->master_sem);
1309 list_add_tail(&req->list, &sc->soe_requests);
1310 up(&sc->master->master_sem);
1311
1312 return req;
1313}
1314
1315/****************************************************************************/
1316
1318 ec_slave_config_t *sc, uint8_t drive_no, uint16_t idn, size_t size)
1319{
1321 drive_no, idn, size);
1322 return IS_ERR(req) ? NULL : req;
1323}
1324
1325/****************************************************************************/
1326
1331 ec_slave_config_t *sc, size_t size)
1332{
1333 ec_reg_request_t *reg;
1334 int ret;
1335
1336 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, size = %zu)\n",
1337 __func__, sc, size);
1338
1339 if (!(reg = (ec_reg_request_t *)
1340 kmalloc(sizeof(ec_reg_request_t), GFP_KERNEL))) {
1341 EC_CONFIG_ERR(sc, "Failed to allocate register request memory!\n");
1342 return ERR_PTR(-ENOMEM);
1343 }
1344
1345 ret = ec_reg_request_init(reg, size);
1346 if (ret) {
1347 kfree(reg);
1348 return ERR_PTR(ret);
1349 }
1350
1351 down(&sc->master->master_sem);
1352 list_add_tail(&reg->list, &sc->reg_requests);
1353 up(&sc->master->master_sem);
1354
1355 return reg;
1356}
1357
1358/****************************************************************************/
1359
1361 ec_slave_config_t *sc, size_t size)
1362{
1363 ec_reg_request_t *reg =
1365 return IS_ERR(reg) ? NULL : reg;
1366}
1367
1368/****************************************************************************/
1369
1374 ec_slave_config_t *sc, size_t size)
1375{
1376 ec_voe_handler_t *voe;
1377 int ret;
1378
1379 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, size = %zu)\n", __func__, sc, size);
1380
1381 if (!(voe = (ec_voe_handler_t *)
1382 kmalloc(sizeof(ec_voe_handler_t), GFP_KERNEL))) {
1383 EC_CONFIG_ERR(sc, "Failed to allocate VoE request memory!\n");
1384 return ERR_PTR(-ENOMEM);
1385 }
1386
1387 ret = ec_voe_handler_init(voe, sc, size);
1388 if (ret < 0) {
1389 kfree(voe);
1390 return ERR_PTR(ret);
1391 }
1392
1393 down(&sc->master->master_sem);
1394 list_add_tail(&voe->list, &sc->voe_handlers);
1395 up(&sc->master->master_sem);
1396
1397 return voe;
1398}
1399
1400/****************************************************************************/
1401
1403 ec_slave_config_t *sc, size_t size)
1404{
1406 size);
1407 return IS_ERR(voe) ? NULL : voe;
1408}
1409
1410/****************************************************************************/
1411
1414{
1415 const ec_slave_t *slave = sc->slave;
1416
1417 state->online = slave ? 1 : 0;
1418 if (state->online) {
1419 state->operational =
1420 slave->current_state == EC_SLAVE_STATE_OP && !slave->force_config;
1421 state->al_state = slave->current_state;
1422 } else {
1423 state->operational = 0;
1425 }
1426 return 0;
1427}
1428
1429/****************************************************************************/
1430
1432 uint16_t idn, ec_al_state_t state, const uint8_t *data,
1433 size_t size)
1434{
1435 ec_slave_t *slave = sc->slave;
1436 ec_soe_request_t *req;
1437 int ret;
1438
1439 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, drive_no = %u, idn = 0x%04X, "
1440 "state = %u, data = 0x%p, size = %zu)\n",
1441 __func__, sc, drive_no, idn, state, data, size);
1442
1443 if (drive_no > 7) {
1444 EC_CONFIG_ERR(sc, "Invalid drive number %u!\n",
1445 (unsigned int) drive_no);
1446 return -EINVAL;
1447 }
1448
1449 if (state != EC_AL_STATE_PREOP && state != EC_AL_STATE_SAFEOP) {
1450 EC_CONFIG_ERR(sc, "AL state for IDN config"
1451 " must be PREOP or SAFEOP!\n");
1452 return -EINVAL;
1453 }
1454
1455 if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_SOE)) {
1456 EC_CONFIG_WARN(sc, "Attached slave does not support SoE!\n");
1457 }
1458
1459 if (!(req = (ec_soe_request_t *)
1460 kmalloc(sizeof(ec_soe_request_t), GFP_KERNEL))) {
1461 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1462 " IDN configuration!\n");
1463 return -ENOMEM;
1464 }
1465
1467 ec_soe_request_set_drive_no(req, drive_no);
1468 ec_soe_request_set_idn(req, idn);
1469 req->al_state = state;
1470
1471 ret = ec_soe_request_copy_data(req, data, size);
1472 if (ret < 0) {
1474 kfree(req);
1475 return ret;
1476 }
1477
1478 down(&sc->master->master_sem);
1479 list_add_tail(&req->list, &sc->soe_configs);
1480 up(&sc->master->master_sem);
1481 return 0;
1482}
1483
1484/****************************************************************************/
1485
1487 int32_t value)
1488{
1489 ec_flag_t *flag;
1490
1491 EC_CONFIG_DBG(sc, 1, "%s(sc = 0x%p, key = %s, value = %i)\n",
1492 __func__, sc, key, value);
1493
1494
1495 flag = ec_slave_config_find_flag(sc, key);
1496 if (flag) {
1497 flag->value = value; // overwrite value
1498 }
1499 else { // new flag
1500 int ret;
1501
1502 if (!(flag = (ec_flag_t *) kmalloc(sizeof(ec_flag_t), GFP_KERNEL))) {
1503 EC_CONFIG_ERR(sc, "Failed to allocate memory for flag!\n");
1504 return -ENOMEM;
1505 }
1506
1507 ret = ec_flag_init(flag, key, value);
1508 if (ret) {
1509 kfree(flag);
1510 return ret;
1511 }
1512
1513 down(&sc->master->master_sem);
1514 list_add_tail(&flag->list, &sc->flags);
1515 up(&sc->master->master_sem);
1516 }
1517 return 0;
1518}
1519
1520/****************************************************************************/
1521
1522#ifdef EC_EOE
1523
1525 const unsigned char *mac_address)
1526{
1527 memcpy(sc->eoe_ip_param_request.mac_address, mac_address, EC_ETH_ALEN);
1528 sc->eoe_ip_param_request.mac_address_included = 1;
1529 return 0;
1530}
1531
1532/****************************************************************************/
1533
1535 struct in_addr ip_address)
1536{
1537 sc->eoe_ip_param_request.ip_address = ip_address;
1538 sc->eoe_ip_param_request.ip_address_included = 1;
1539 return 0;
1540}
1541
1542/****************************************************************************/
1543
1545 struct in_addr subnet_mask)
1546{
1547 sc->eoe_ip_param_request.subnet_mask = subnet_mask;
1548 sc->eoe_ip_param_request.subnet_mask_included = 1;
1549 return 0;
1550}
1551
1552/****************************************************************************/
1553
1555 struct in_addr gateway_address)
1556{
1557 sc->eoe_ip_param_request.gateway = gateway_address;
1558 sc->eoe_ip_param_request.gateway_included = 1;
1559 return 0;
1560}
1561
1562/****************************************************************************/
1563
1565 struct in_addr dns_address)
1566{
1567 sc->eoe_ip_param_request.dns = dns_address;
1568 sc->eoe_ip_param_request.dns_included = 1;
1569 return 0;
1570}
1571
1572/****************************************************************************/
1573
1575 const char *name)
1576{
1577 strscpy(sc->eoe_ip_param_request.name, name, EC_MAX_HOSTNAME_SIZE - 1);
1578 sc->eoe_ip_param_request.name_included = 1;
1579 return 0;
1580}
1581
1582#endif
1583
1584/****************************************************************************/
1585
1587 ec_al_state_t from, ec_al_state_t to, unsigned int timeout_ms)
1588{
1589 ec_al_timeout_t *timeout;
1590 ec_slave_state_t from_state, to_state;
1591
1592 if (from != EC_AL_STATE_INIT && from != EC_AL_STATE_PREOP &&
1593 from != EC_AL_STATE_SAFEOP && from != EC_AL_STATE_OP) {
1594 EC_CONFIG_ERR(sc, "Invalid from state %i.\n", from);
1595 return -EINVAL;
1596 }
1597 if (to != EC_AL_STATE_INIT && to != EC_AL_STATE_PREOP &&
1598 to != EC_AL_STATE_SAFEOP && to != EC_AL_STATE_OP) {
1599 EC_CONFIG_ERR(sc, "Invalid to state %i.\n", to);
1600 return -EINVAL;
1601 }
1602
1603 from_state = (ec_slave_state_t) from;
1604 to_state = (ec_slave_state_t) to;
1605
1606 /* try to find an already configured timeout. */
1607 list_for_each_entry(timeout, &sc->al_timeouts, list) {
1608 if (timeout->from == from_state && timeout->to == to_state) {
1609 if (timeout_ms == 0) {
1610 // delete configured value
1611 list_del(&timeout->list);
1612 kfree(timeout);
1613 return 0;
1614 }
1615 timeout->timeout_ms = timeout_ms;
1616 return 0;
1617 }
1618 }
1619
1620 if (timeout_ms == 0) {
1621 return 0;
1622 }
1623
1624 /* no timeout found. create one. */
1625 if (!(timeout = (ec_al_timeout_t *)
1626 kmalloc(sizeof(ec_al_timeout_t), GFP_KERNEL))) {
1627 EC_CONFIG_ERR(sc, "Failed to allocate memory for"
1628 " AL timeout configuration!\n");
1629 return -ENOMEM;
1630 }
1631
1632 timeout->from = from_state;
1633 timeout->to = to_state;
1634 timeout->timeout_ms = timeout_ms;
1635
1636 down(&sc->master->master_sem);
1637 list_add_tail(&timeout->list, &sc->al_timeouts);
1638 up(&sc->master->master_sem);
1639 return 0;
1640}
1641
1642/****************************************************************************/
1643
1645
1646EXPORT_SYMBOL(ecrt_slave_config_sync_manager);
1647EXPORT_SYMBOL(ecrt_slave_config_watchdog);
1648EXPORT_SYMBOL(ecrt_slave_config_pdo_mode);
1653EXPORT_SYMBOL(ecrt_slave_config_pdos);
1654EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry);
1656EXPORT_SYMBOL(ecrt_slave_config_dc);
1657EXPORT_SYMBOL(ecrt_slave_config_sdo);
1658EXPORT_SYMBOL(ecrt_slave_config_sdo8);
1659EXPORT_SYMBOL(ecrt_slave_config_sdo16);
1660EXPORT_SYMBOL(ecrt_slave_config_sdo32);
1661EXPORT_SYMBOL(ecrt_slave_config_complete_sdo);
1662EXPORT_SYMBOL(ecrt_slave_config_emerg_size);
1663EXPORT_SYMBOL(ecrt_slave_config_emerg_pop);
1664EXPORT_SYMBOL(ecrt_slave_config_emerg_clear);
1670EXPORT_SYMBOL(ecrt_slave_config_state);
1671EXPORT_SYMBOL(ecrt_slave_config_idn);
1672EXPORT_SYMBOL(ecrt_slave_config_flag);
1673#ifdef EOE
1679EXPORT_SYMBOL(ecrt_slave_config_eoe_hostname);
1680#endif
1681EXPORT_SYMBOL(ecrt_slave_config_state_timeout);
1682
1684
1685/****************************************************************************/
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:127
@ EC_SLAVE_STATE_OP
OP (mailbox communication and input/output update).
Definition globals.h:138
@ EC_SLAVE_STATE_UNKNOWN
unknown state
Definition globals.h:128
@ EC_MBOX_COE
CANopen over EtherCAT.
Definition globals.h:152
@ EC_MBOX_SOE
Servo-Profile over EtherCAT.
Definition globals.h:154
#define EC_MAX_FMMUS
Maximum number of FMMUs per slave.
Definition globals.h:98
struct ec_slave ec_slave_t
Definition globals.h:315
#define EC_MAX_HOSTNAME_SIZE
Maximum hostname size.
Definition globals.h:116
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:330
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:669
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_pdo_mode(ec_slave_config_t *sc, ec_pdo_mode_t assign_mode, ec_pdo_mode_t config_mode)
Selects how a slave's PDO assignment and PDO configuration are read from resp.
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:3267
struct ec_voe_handler ec_voe_handler_t
Definition ecrt.h:333
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:327
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:318
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_pdo_mode_t
PDO handling mode.
Definition ecrt.h:551
ec_direction_t
Direction type for PDO assignment functions.
Definition ecrt.h:522
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:324
struct ec_slave_config ec_slave_config_t
Definition ecrt.h:321
struct ec_reg_request ec_reg_request_t
Definition ecrt.h:336
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:3301
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:535
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:281
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:285
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:3284
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.
#define EC_PDO_MODE_DEFAULT
Default PDO handling mode: read via CoE while scanning, and unconditionally (re-)write via CoE every ...
Definition ecrt.h:575
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:670
@ EC_AL_STATE_OP
Operational.
Definition ecrt.h:673
@ EC_AL_STATE_PREOP
Pre-operational.
Definition ecrt.h:671
@ EC_AL_STATE_SAFEOP
Safe-operational.
Definition ecrt.h:672
@ EC_PDO_MODE_WRITE_IF_DIFFERENT
Read the current state via CoE while scanning the slave, and write it back only if it differs from th...
Definition ecrt.h:562
@ EC_DIR_INVALID
Invalid direction.
Definition ecrt.h:523
@ EC_DIR_INPUT
Values read by the master.
Definition ecrt.h:525
@ EC_DIR_OUTPUT
Values written by the master.
Definition ecrt.h:524
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:2016
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:864
#define EC_SLAVE_WARN(slave, fmt, args...)
Convenience macro for printing slave-specific warnings to syslog.
Definition slave.h:84
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:205
unsigned int debug_level
Master debug level.
Definition master.h:286
PDO entry configuration information.
Definition ecrt.h:585
uint8_t subindex
PDO entry subindex.
Definition ecrt.h:587
uint8_t bit_length
Size of the PDO entry in bit.
Definition ecrt.h:588
uint16_t index
PDO entry index.
Definition ecrt.h:586
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:599
unsigned int n_entries
Number of PDO entries in entries to map.
Definition ecrt.h:601
uint16_t index
PDO index.
Definition ecrt.h:600
ec_pdo_entry_info_t const * entries
Array of PDO entries to map.
Definition ecrt.h:605
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:159
uint32_t product_code
Vendor-specific product code.
Definition slave.h:130
uint16_t mailbox_protocols
Supported mailbox protocols.
Definition slave.h:141
uint32_t vendor_id
Vendor ID.
Definition slave.h:129
unsigned int sync_count
Number of sync managers.
Definition slave.h:160
Slave configuration state.
Definition ecrt.h:394
unsigned int online
The slave is online.
Definition ecrt.h:395
unsigned int operational
The slave was brought into OP state using the specified configuration.
Definition ecrt.h:396
unsigned int al_state
The application-layer state of the slave.
Definition ecrt.h:398
ec_pdo_mode_t pdo_assign_mode
Whether/how to read resp.
uint32_t product_code
Slave product code.
ec_pdo_mode_t pdo_config_mode
Whether/how to read resp.
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:218
unsigned int force_config
Force (re-)configuration.
Definition slave.h:188
uint16_t ring_position
Ring position.
Definition slave.h:177
ec_slave_config_t * config
Current configuration.
Definition slave.h:184
ec_slave_state_t current_state
Current application state.
Definition slave.h:186
ec_fsm_slave_t fsm
Slave state machine.
Definition slave.h:230
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:618
unsigned int n_pdos
Number of PDOs in pdos.
Definition ecrt.h:623
ec_direction_t dir
Sync manager direction.
Definition ecrt.h:622
uint8_t index
Sync manager index.
Definition ecrt.h:619
ec_pdo_info_t const * pdos
Array with PDOs to assign.
Definition ecrt.h:624
ec_watchdog_mode_t watchdog_mode
Watchdog mode.
Definition ecrt.h:626
uint32_t cycle_time
Cycle time [ns].
Definition globals.h:186
int32_t shift_time
Shift time [ns].
Definition globals.h:187
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:43
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:85
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:61
void ec_voe_handler_release_mbox_lock(ec_voe_handler_t *voe)
Releases the mailbox read lock, if the handler holds it.
Vendor specific over EtherCAT protocol handler.