IgH EtherCAT Master  1.6.13
ecrt.h
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 userspace library.
6 *
7 * The IgH EtherCAT master userspace library is free software; you can
8 * redistribute it and/or modify it under the terms of the GNU Lesser General
9 * Public License as published by the Free Software Foundation; version 2.1
10 * of the License.
11 *
12 * The IgH EtherCAT master userspace library is distributed in the hope that
13 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the IgH EtherCAT master userspace library. If not, see
19 * <http://www.gnu.org/licenses/>.
20 *
21 ****************************************************************************/
22
137
138/****************************************************************************/
139
140#ifndef __ECRT_H__
141#define __ECRT_H__
142
143#ifdef __KERNEL__
144#include <asm/byteorder.h>
145#include <linux/types.h>
146#include <linux/time.h>
147#include <linux/in.h> // struct in_addr
148#else
149#include <stdlib.h> // for size_t
150#include <stdint.h>
151#include <sys/time.h> // for struct timeval
152#include <netinet/in.h> // struct in_addr
153#endif
154
155/*****************************************************************************
156 * Global definitions
157 ****************************************************************************/
158
161#define ECRT_VER_MAJOR 1
162
165#define ECRT_VER_MINOR 6
166
169#define ECRT_VERSION(a, b) (((a) << 8) + (b))
170
173#define ECRT_VERSION_MAGIC ECRT_VERSION(ECRT_VER_MAJOR, ECRT_VER_MINOR)
174
175/*****************************************************************************
176 * Feature flags
177 ****************************************************************************/
178
184#define EC_HAVE_REDUNDANCY
185
190#define EC_HAVE_EMERGENCY
191
198#define EC_HAVE_REG_ACCESS
199
202#define EC_HAVE_SELECT_REF_CLOCK
203
206#define EC_HAVE_REF_CLOCK_TIME
207
210#define EC_HAVE_REG_BY_POS
211
214#define EC_HAVE_SYNC_TO
215
218#define EC_HAVE_FLAGS
219
226#define EC_HAVE_SOE_REQUESTS
227
231#define EC_HAVE_SCAN_PROGRESS
232
239#define EC_HAVE_SET_IP
240
243#define EC_HAVE_STATE_TIMEOUT
244
245/****************************************************************************/
246
249#ifndef EC_PUBLIC_API
250# if defined(ethercat_EXPORTS) && !defined(__KERNEL__)
251# define EC_PUBLIC_API __attribute__ ((visibility ("default")))
252# else
253# define EC_PUBLIC_API
254# endif
255#endif
256
257/****************************************************************************/
258
263#define EC_END ~0U
264
267#define EC_MAX_SYNC_MANAGERS 16
268
273#define EC_MAX_STRING_LENGTH 64
274
276#define EC_MAX_PORTS 4
277
286#define EC_TIMEVAL2NANO(TV) \
287 (((TV).tv_sec - 946684800ULL) * 1000000000ULL + (TV).tv_usec * 1000ULL)
288
293#define EC_COE_EMERGENCY_MSG_SIZE 8
294
295/*****************************************************************************
296 * Data types
297 ****************************************************************************/
298
299struct ec_master;
300typedef struct ec_master ec_master_t;
301
302struct ec_slave_config;
304
305struct ec_domain;
306typedef struct ec_domain ec_domain_t;
307
308struct ec_sdo_request;
310
311struct ec_soe_request;
313
314struct ec_voe_handler;
316
317struct ec_reg_request;
319
320/****************************************************************************/
321
328typedef struct {
329 unsigned int slaves_responding;
331 unsigned int al_states : 4;
340 unsigned int link_up : 1;
343
344/****************************************************************************/
345
352typedef struct {
353 unsigned int slaves_responding;
355 unsigned int al_states : 4;
364 unsigned int link_up : 1;
367
368/****************************************************************************/
369
376typedef struct {
377 unsigned int online : 1;
378 unsigned int operational : 1;
380 unsigned int al_state : 4;
389
390/****************************************************************************/
391
398typedef struct {
399 unsigned int slave_count;
400 unsigned int link_up : 1;
401 uint8_t scan_busy;
403 uint64_t app_time;
405
406/****************************************************************************/
407
414typedef struct {
415 unsigned int slave_count;
416 unsigned int scan_index;
421
422/****************************************************************************/
423
432
433/****************************************************************************/
434
437typedef struct {
438 uint8_t link_up;
439 uint8_t loop_closed;
442
443/****************************************************************************/
444
451typedef struct {
452 uint16_t position;
453 uint32_t vendor_id;
454 uint32_t product_code;
456 uint32_t serial_number;
457 uint16_t alias;
459 struct {
462 uint32_t receive_time;
464 uint16_t next_slave;
466 uint32_t delay_to_next_dc;
467 } ports[EC_MAX_PORTS];
468 uint8_t al_state;
469 uint8_t error_flag;
470 uint8_t sync_count;
471 uint16_t sdo_count;
474
475/****************************************************************************/
476
487
488/****************************************************************************/
489
499
500/****************************************************************************/
501
510
511/****************************************************************************/
512
522
523/****************************************************************************/
524
531typedef struct {
532 uint16_t index;
533 uint8_t subindex;
534 uint8_t bit_length;
536
537/****************************************************************************/
538
545typedef struct {
546 uint16_t index;
547 unsigned int n_entries;
555
556/****************************************************************************/
557
574
575/****************************************************************************/
576
582typedef struct {
583 uint16_t alias;
584 uint16_t position;
585 uint32_t vendor_id;
586 uint32_t product_code;
587 uint16_t index;
588 uint8_t subindex;
589 unsigned int *offset;
591 unsigned int *bit_position;
596
597/****************************************************************************/
598
610
611/****************************************************************************/
612
621
622/*****************************************************************************
623 * Global functions
624 ****************************************************************************/
625
626#ifdef __cplusplus
627extern "C" {
628#endif
629
636EC_PUBLIC_API unsigned int ecrt_version_magic(void);
637
656 unsigned int master_index
657 );
658
659#ifndef __KERNEL__
660
674EC_PUBLIC_API ec_master_t *ecrt_open_master(
675 unsigned int master_index
676 );
677
678#endif // #ifndef __KERNEL__
679
693 ec_master_t *master
694 );
695
696/*****************************************************************************
697 * Master methods
698 ****************************************************************************/
699
700#ifndef __KERNEL__
701
711EC_PUBLIC_API int ecrt_master_reserve(
712 ec_master_t *master
713 );
714
715#endif // #ifndef __KERNEL__
716
717#ifdef __KERNEL__
718
739 ec_master_t *master,
740 void (*send_cb)(void *),
741 void (*receive_cb)(void *),
742 void *cb_data
744 );
745
746#endif /* __KERNEL__ */
747
763 ec_master_t *master
764 );
765
799 ec_master_t *master,
800 uint16_t alias,
801 uint16_t position,
802 uint32_t vendor_id,
803 uint32_t product_code
804 );
805
817 ec_master_t *master,
820 );
821
833 ec_master_t *master,
834 ec_master_info_t *master_info
836 );
837
849 ec_master_t *master,
852 );
853
867 ec_master_t *master,
868 uint16_t slave_position,
869 ec_slave_info_t *slave_info
871 );
872
873#ifndef __KERNEL__
874
885EC_PUBLIC_API int ecrt_master_get_sync_manager(
886 ec_master_t *master,
887 uint16_t slave_position,
888 uint8_t sync_index,
890 ec_sync_info_t *sync
891 );
892
904EC_PUBLIC_API int ecrt_master_get_pdo(
905 ec_master_t *master,
906 uint16_t slave_position,
907 uint8_t sync_index,
909 uint16_t pos,
910 ec_pdo_info_t *pdo
911 );
912
922EC_PUBLIC_API int ecrt_master_get_pdo_entry(
923 ec_master_t *master,
924 uint16_t slave_position,
925 uint8_t sync_index,
927 uint16_t pdo_pos,
928 uint16_t entry_pos,
929 ec_pdo_entry_info_t *entry
930 );
931
932#endif /* #ifndef __KERNEL__ */
933
946 ec_master_t *master,
947 uint16_t slave_position,
948 uint16_t index,
949 uint8_t subindex,
950 const uint8_t *data,
951 size_t data_size,
952 uint32_t *abort_code
953 );
954
968 ec_master_t *master,
969 uint16_t slave_position,
970 uint16_t index,
971 const uint8_t *data,
972 size_t data_size,
973 uint32_t *abort_code
974 );
975
988 ec_master_t *master,
989 uint16_t slave_position,
990 uint16_t index,
991 uint8_t subindex,
992 uint8_t *target,
993 size_t target_size,
994 size_t *result_size,
995 uint32_t *abort_code
996 );
997
1009 ec_master_t *master,
1010 uint16_t slave_position,
1011 uint8_t drive_no,
1012 uint16_t idn,
1013 const uint8_t *data,
1014 size_t data_size,
1015 uint16_t *error_code
1017 );
1018
1030 ec_master_t *master,
1031 uint16_t slave_position,
1032 uint8_t drive_no,
1033 uint16_t idn,
1034 uint8_t *target,
1036 size_t target_size,
1037 size_t *result_size,
1038 uint16_t *error_code
1040 );
1041
1062 ec_master_t *master
1063 );
1064
1081 ec_master_t *master
1082 );
1083
1097 ec_master_t *master,
1098 size_t send_interval
1099 );
1100
1114 ec_master_t *master
1115 );
1116
1132 ec_master_t *master
1133 );
1134
1135#ifdef __KERNEL__
1147 ec_master_t *master
1148 );
1149#endif
1150
1163 const ec_master_t *master,
1164 ec_master_state_t *state
1165 );
1166
1176 const ec_master_t *master,
1177 unsigned int dev_idx,
1181 );
1182
1209 ec_master_t *master,
1210 uint64_t app_time
1211 );
1212
1225 ec_master_t *master
1226 );
1227
1243 ec_master_t *master,
1244 uint64_t sync_time
1245 );
1246
1261 ec_master_t *master
1262 );
1263
1287 const ec_master_t *master,
1288 uint32_t *time
1289 );
1290
1302 ec_master_t *master
1303 );
1304
1317 const ec_master_t *master
1318 );
1319
1335 ec_master_t *master
1336 );
1337
1338/*****************************************************************************
1339 * Slave configuration methods
1340 ****************************************************************************/
1341
1355 ec_slave_config_t *sc,
1356 uint8_t sync_index,
1358 ec_direction_t direction,
1359 ec_watchdog_mode_t watchdog_mode
1360 );
1361
1372 ec_slave_config_t *sc,
1373 uint16_t watchdog_divider,
1378 uint16_t watchdog_intervals
1382 );
1383
1395 ec_slave_config_t *sc,
1396 uint8_t sync_index,
1398 uint16_t index
1399 );
1400
1416 ec_slave_config_t *sc,
1417 uint8_t sync_index
1419 );
1420
1432 ec_slave_config_t *sc,
1433 uint16_t pdo_index,
1434 uint16_t entry_index,
1436 uint8_t entry_subindex,
1438 uint8_t entry_bit_length
1439 );
1440
1455 ec_slave_config_t *sc,
1456 uint16_t pdo_index
1457 );
1458
1533 ec_slave_config_t *sc,
1534 unsigned int n_syncs,
1536 const ec_sync_info_t syncs[]
1538 );
1539
1561 ec_slave_config_t *sc,
1562 uint16_t entry_index,
1563 uint8_t entry_subindex,
1564 ec_domain_t *domain,
1565 unsigned int *bit_position
1567 );
1568
1585 ec_slave_config_t *sc,
1586 uint8_t sync_index,
1587 unsigned int pdo_pos,
1588 unsigned int entry_pos,
1589 ec_domain_t *domain,
1590 unsigned int *bit_position
1592 );
1593
1667 ec_slave_config_t *sc,
1668 uint16_t assign_activate,
1669 uint32_t sync0_cycle,
1670 int32_t sync0_shift,
1671 uint32_t sync1_cycle,
1672 int32_t sync1_shift
1673 );
1674
1703 ec_slave_config_t *sc,
1704 uint16_t index,
1705 uint8_t subindex,
1706 const uint8_t *data,
1707 size_t size
1708 );
1709
1723 ec_slave_config_t *sc,
1724 uint16_t sdo_index,
1725 uint8_t sdo_subindex,
1726 uint8_t value
1727 );
1728
1742 ec_slave_config_t *sc,
1743 uint16_t sdo_index,
1744 uint8_t sdo_subindex,
1745 uint16_t value
1746 );
1747
1761 ec_slave_config_t *sc,
1762 uint16_t sdo_index,
1763 uint8_t sdo_subindex,
1764 uint32_t value
1765 );
1766
1783 ec_slave_config_t *sc,
1784 uint16_t index,
1785 const uint8_t *data,
1786 size_t size
1787 );
1788
1802 ec_slave_config_t *sc,
1803 size_t elements
1804 );
1805
1823 ec_slave_config_t *sc,
1824 uint8_t *target
1826 );
1827
1840 );
1841
1857 const ec_slave_config_t *sc
1858 );
1859
1873 ec_slave_config_t *sc,
1874 uint16_t index,
1875 uint8_t subindex,
1876 size_t size
1877 );
1878
1892 ec_slave_config_t *sc,
1893 uint8_t drive_no,
1894 uint16_t idn,
1895 size_t size
1896 );
1897
1916 ec_slave_config_t *sc,
1917 size_t size
1918 );
1919
1937 ec_slave_config_t *sc,
1938 size_t size
1939 );
1940
1959 const ec_slave_config_t *sc,
1961 );
1962
1988 ec_slave_config_t *sc,
1989 uint8_t drive_no,
1990 uint16_t idn,
1991 ec_al_state_t state,
1993 const uint8_t *data,
1994 size_t size
1995 );
1996
2022 ec_slave_config_t *sc,
2023 const char *key,
2024 int32_t value
2025 );
2026
2041 ec_slave_config_t *sc,
2042 const unsigned char *mac_address
2043 );
2044
2079 ec_slave_config_t *sc,
2080 struct in_addr ip_address
2081 );
2082
2103 ec_slave_config_t *sc,
2104 struct in_addr subnet_mask
2105 );
2106
2127 ec_slave_config_t *sc,
2128 struct in_addr gateway_address
2129 );
2130
2152 ec_slave_config_t *sc,
2153 struct in_addr dns_address
2154 );
2155
2173 ec_slave_config_t *sc,
2174 const char *name
2175 );
2176
2194 ec_slave_config_t *sc,
2195 ec_al_state_t from_state,
2196 ec_al_state_t to_state,
2197 unsigned int timeout_ms
2198 );
2199
2200/*****************************************************************************
2201 * Domain methods
2202 ****************************************************************************/
2203
2219 ec_domain_t *domain,
2220 const ec_pdo_entry_reg_t *pdo_entry_regs
2222 );
2223
2233 const ec_domain_t *domain
2234 );
2235
2236#ifdef __KERNEL__
2237
2252 ec_domain_t *domain,
2253 uint8_t *memory
2255 );
2256
2257#endif /* __KERNEL__ */
2258
2275 const ec_domain_t *domain
2276 );
2277
2290 ec_domain_t *domain
2291 );
2292
2303 ec_domain_t *domain
2304 );
2305
2317 const ec_domain_t *domain,
2318 ec_domain_state_t *state
2320 );
2321
2322/*****************************************************************************
2323 * SDO request methods.
2324 ****************************************************************************/
2325
2341 ec_sdo_request_t *req,
2342 uint16_t index,
2343 uint8_t subindex
2344 );
2345
2362 ec_sdo_request_t *req,
2363 uint32_t timeout
2365 );
2366
2397 const ec_sdo_request_t *req
2398 );
2399
2415 const ec_sdo_request_t *req
2416 );
2417
2432#ifdef __KERNEL__
2433 const
2434#endif
2435 ec_sdo_request_t *req
2436 );
2437
2454 ec_sdo_request_t *req
2455 );
2456
2474 ec_sdo_request_t *req
2475 );
2476
2477/*****************************************************************************
2478 * SoE request methods.
2479 ****************************************************************************/
2480
2496 ec_soe_request_t *req,
2497 uint8_t drive_no,
2498 uint16_t idn
2499 );
2500
2517 ec_soe_request_t *req,
2518 uint32_t timeout
2520 );
2521
2552 const ec_soe_request_t *req
2553 );
2554
2566 const ec_soe_request_t *req
2567 );
2568
2582#ifdef __KERNEL__
2583 const
2584#endif
2585 ec_soe_request_t *req
2586 );
2587
2604 ec_soe_request_t *req
2605 );
2606
2624 ec_soe_request_t *req
2625 );
2626
2627/*****************************************************************************
2628 * VoE handler methods.
2629 ****************************************************************************/
2630
2647 ec_voe_handler_t *voe,
2648 uint32_t vendor_id,
2649 uint16_t vendor_type
2650 );
2651
2668 const ec_voe_handler_t *voe,
2669 uint32_t *vendor_id,
2670 uint16_t *vendor_type
2671 );
2672
2696 const ec_voe_handler_t *voe
2697 );
2698
2714 const ec_voe_handler_t *voe
2715 );
2716
2734 ec_voe_handler_t *voe,
2735 size_t size
2736 );
2737
2761 ec_voe_handler_t *voe
2762 );
2763
2788 ec_voe_handler_t *voe
2789 );
2790
2805 ec_voe_handler_t *voe
2806 );
2807
2808/*****************************************************************************
2809 * Register request methods.
2810 ****************************************************************************/
2811
2838 const ec_reg_request_t *req
2839 );
2840
2852 const ec_reg_request_t *req
2853 );
2854
2873 ec_reg_request_t *req,
2874 uint16_t address,
2875 size_t size
2876 );
2877
2896 ec_reg_request_t *req,
2897 uint16_t address,
2898 size_t size
2899 );
2900
2901/*****************************************************************************
2902 * Bitwise read/write macros
2903 ****************************************************************************/
2904
2910#define EC_READ_BIT(DATA, POS) ((*((uint8_t *) (DATA)) >> (POS)) & 0x01)
2911
2918#define EC_WRITE_BIT(DATA, POS, VAL) \
2919 do { \
2920 if (VAL) *((uint8_t *) (DATA)) |= (1 << (POS)); \
2921 else *((uint8_t *) (DATA)) &= ~(1 << (POS)); \
2922 } while (0)
2923
2924/*****************************************************************************
2925 * Byte-swapping functions for user space
2926 ****************************************************************************/
2927
2928#ifndef __KERNEL__
2929
2930#if __BYTE_ORDER == __LITTLE_ENDIAN
2931
2932#define le16_to_cpu(x) x
2933#define le32_to_cpu(x) x
2934#define le64_to_cpu(x) x
2935
2936#define cpu_to_le16(x) x
2937#define cpu_to_le32(x) x
2938#define cpu_to_le64(x) x
2939
2940#elif __BYTE_ORDER == __BIG_ENDIAN
2941
2942#define swap16(x) \
2943 ((uint16_t)( \
2944 (((uint16_t)(x) & 0x00ffU) << 8) | \
2945 (((uint16_t)(x) & 0xff00U) >> 8) ))
2946#define swap32(x) \
2947 ((uint32_t)( \
2948 (((uint32_t)(x) & 0x000000ffUL) << 24) | \
2949 (((uint32_t)(x) & 0x0000ff00UL) << 8) | \
2950 (((uint32_t)(x) & 0x00ff0000UL) >> 8) | \
2951 (((uint32_t)(x) & 0xff000000UL) >> 24) ))
2952#define swap64(x) \
2953 ((uint64_t)( \
2954 (((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
2955 (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
2956 (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
2957 (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
2958 (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
2959 (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
2960 (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
2961 (((uint64_t)(x) & 0xff00000000000000ULL) >> 56) ))
2962
2963#define le16_to_cpu(x) swap16(x)
2964#define le32_to_cpu(x) swap32(x)
2965#define le64_to_cpu(x) swap64(x)
2966
2967#define cpu_to_le16(x) swap16(x)
2968#define cpu_to_le32(x) swap32(x)
2969#define cpu_to_le64(x) swap64(x)
2970
2971#endif
2972
2973#define le16_to_cpup(x) le16_to_cpu(*((uint16_t *)(x)))
2974#define le32_to_cpup(x) le32_to_cpu(*((uint32_t *)(x)))
2975#define le64_to_cpup(x) le64_to_cpu(*((uint64_t *)(x)))
2976
2977#endif /* ifndef __KERNEL__ */
2978
2979/*****************************************************************************
2980 * Read macros
2981 ****************************************************************************/
2982
2987#define EC_READ_U8(DATA) \
2988 ((uint8_t) *((uint8_t *) (DATA)))
2989
2995#define EC_READ_S8(DATA) \
2996 ((int8_t) *((uint8_t *) (DATA)))
2997
3003#define EC_READ_U16(DATA) \
3004 ((uint16_t) le16_to_cpup((void *) (DATA)))
3005
3011#define EC_READ_S16(DATA) \
3012 ((int16_t) le16_to_cpup((void *) (DATA)))
3013
3019#define EC_READ_U32(DATA) \
3020 ((uint32_t) le32_to_cpup((void *) (DATA)))
3021
3027#define EC_READ_S32(DATA) \
3028 ((int32_t) le32_to_cpup((void *) (DATA)))
3029
3035#define EC_READ_U64(DATA) \
3036 ((uint64_t) le64_to_cpup((void *) (DATA)))
3037
3043#define EC_READ_S64(DATA) \
3044 ((int64_t) le64_to_cpup((void *) (DATA)))
3045
3046/*****************************************************************************
3047 * Floating-point read functions and macros (userspace only)
3048 ****************************************************************************/
3049
3050#ifndef __KERNEL__
3051
3059EC_PUBLIC_API float ecrt_read_real(const void *data);
3060
3066#define EC_READ_REAL(DATA) ecrt_read_real(DATA)
3067
3075EC_PUBLIC_API double ecrt_read_lreal(const void *data);
3076
3082#define EC_READ_LREAL(DATA) ecrt_read_lreal(DATA)
3083
3084#endif // ifndef __KERNEL__
3085
3086/*****************************************************************************
3087 * Write macros
3088 ****************************************************************************/
3089
3095#define EC_WRITE_U8(DATA, VAL) \
3096 do { \
3097 *((uint8_t *)(DATA)) = ((uint8_t) (VAL)); \
3098 } while (0)
3099
3105#define EC_WRITE_S8(DATA, VAL) EC_WRITE_U8(DATA, VAL)
3106
3112#define EC_WRITE_U16(DATA, VAL) \
3113 do { \
3114 *((uint16_t *) (DATA)) = cpu_to_le16((uint16_t) (VAL)); \
3115 } while (0)
3116
3122#define EC_WRITE_S16(DATA, VAL) EC_WRITE_U16(DATA, VAL)
3123
3129#define EC_WRITE_U32(DATA, VAL) \
3130 do { \
3131 *((uint32_t *) (DATA)) = cpu_to_le32((uint32_t) (VAL)); \
3132 } while (0)
3133
3139#define EC_WRITE_S32(DATA, VAL) EC_WRITE_U32(DATA, VAL)
3140
3146#define EC_WRITE_U64(DATA, VAL) \
3147 do { \
3148 *((uint64_t *) (DATA)) = cpu_to_le64((uint64_t) (VAL)); \
3149 } while (0)
3150
3156#define EC_WRITE_S64(DATA, VAL) EC_WRITE_U64(DATA, VAL)
3157
3158/*****************************************************************************
3159 * Floating-point write functions and macros (userspace only)
3160 ****************************************************************************/
3161
3162#ifndef __KERNEL__
3163
3171EC_PUBLIC_API void ecrt_write_real(void *data, float value);
3172
3178#define EC_WRITE_REAL(DATA, VAL) ecrt_write_real(DATA, VAL)
3179
3187EC_PUBLIC_API void ecrt_write_lreal(void *data, double value);
3188
3194#define EC_WRITE_LREAL(DATA, VAL) ecrt_write_lreal(DATA, VAL)
3195
3196#endif // ifndef __KERNEL__
3197
3198/****************************************************************************/
3199
3200#ifdef __cplusplus
3201}
3202#endif
3203
3204/****************************************************************************/
3205
3207
3208#endif
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.
ec_wc_state_t
Domain working counter interpretation.
Definition ecrt.h:481
int ecrt_sdo_request_read(ec_sdo_request_t *req)
Schedule an SDO read operation.
uint8_t * ecrt_reg_request_data(const ec_reg_request_t *reg)
Access to the register request's data.
Definition reg_request.c:78
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_soe_request_write(ec_soe_request_t *req)
Schedule an SoE IDN write operation.
int ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address, size_t size)
Schedule an register write operation.
Definition reg_request.c:92
void ecrt_release_master(ec_master_t *master)
Releases a requested EtherCAT master.
Definition module.c:621
int ecrt_master_sdo_download_complete(ec_master_t *master, uint16_t slave_position, uint16_t index, const uint8_t *data, size_t data_size, uint32_t *abort_code)
Executes an SDO download request to write data to a slave via complete access.
Definition master.c:2973
int ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout)
Set the timeout for an SDO request.
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_master_read_idn(ec_master_t *master, uint16_t slave_position, uint8_t drive_no, uint16_t idn, uint8_t *target, size_t target_size, size_t *result_size, uint16_t *error_code)
Executes an SoE read request.
Definition master.c:3213
ec_slave_port_desc_t
EtherCAT slave port descriptor.
Definition ecrt.h:426
int ecrt_domain_process(ec_domain_t *domain)
Determines the states of the domain's datagrams.
Definition domain.c:457
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
#define EC_MAX_PORTS
Maximum number of slave ports.
Definition ecrt.h:276
int ecrt_master_sync_reference_clock_to(ec_master_t *master, uint64_t sync_time)
Queues the DC reference clock drift compensation datagram for sending.
Definition master.c:2845
size_t ecrt_domain_size(const ec_domain_t *domain)
Returns the current size of the domain's process data.
Definition domain.c:426
uint8_t * ecrt_voe_handler_data(const ec_voe_handler_t *voe)
Access to the VoE handler's data.
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_master_write_idn(ec_master_t *master, uint16_t slave_position, uint8_t drive_no, uint16_t idn, const uint8_t *data, size_t data_size, uint16_t *error_code)
Executes an SoE write request.
Definition master.c:3137
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.
int ecrt_master_scan_progress(ec_master_t *master, ec_master_scan_progress_t *progress)
Obtains network scan progress information.
Definition master.c:2671
uint32_t ecrt_master_sync_monitor_process(const ec_master_t *master)
Processes the DC synchrony monitoring datagram.
Definition master.c:2883
ec_request_state_t ecrt_soe_request_state(const ec_soe_request_t *req)
Get the current state of the SoE request.
int ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
Reads the current master state.
Definition master.c:2760
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_master_sync_slave_clocks(ec_master_t *master)
Queues the DC clock drift compensation datagram for sending.
Definition master.c:2861
int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t subindex, uint8_t *target, size_t target_size, size_t *result_size, uint32_t *abort_code)
Executes an SDO upload request to read data from a slave.
Definition master.c:3054
int ecrt_slave_config_emerg_overruns(const ec_slave_config_t *sc)
Read the number of CoE emergency overruns.
size_t ecrt_soe_request_data_size(const ec_soe_request_t *req)
Returns the current IDN data size.
int ecrt_master_receive(ec_master_t *master)
Fetches received frames from the hardware and processes the datagrams.
Definition master.c:2494
size_t ecrt_sdo_request_data_size(const ec_sdo_request_t *req)
Returns the current SDO data size.
struct ec_voe_handler ec_voe_handler_t
Definition ecrt.h:315
ec_domain_t * ecrt_master_create_domain(ec_master_t *master)
Creates a new process data domain.
Definition master.c:2292
int ecrt_slave_config_state(const ec_slave_config_t *sc, ec_slave_config_state_t *state)
Outputs the state of the slave configuration.
int ecrt_master_select_reference_clock(ec_master_t *master, ec_slave_config_t *sc)
Selects the reference clock for distributed clocks.
Definition master.c:2637
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.
unsigned int ecrt_version_magic(void)
Returns the version magic of the realtime interface.
Definition module.c:647
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_domain_queue(ec_domain_t *domain)
(Re-)queues all domain datagrams in the master's datagram queue.
Definition domain.c:648
ec_master_t * ecrt_request_master(unsigned int master_index)
Requests an EtherCAT master for realtime operation.
Definition module.c:613
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.
void ecrt_master_callbacks(ec_master_t *master, void(*send_cb)(void *), void(*receive_cb)(void *), void *cb_data)
Sets the locking callbacks.
Definition master.c:2746
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.
uint8_t * ecrt_soe_request_data(const ec_soe_request_t *req)
Access to the SoE request's data.
int ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
Sets the application time.
Definition master.c:2800
int ecrt_voe_handler_read(ec_voe_handler_t *voe)
Start a VoE read operation.
uint8_t * ecrt_sdo_request_data(const ec_sdo_request_t *req)
Access to the SDO request's data.
int ecrt_master_send(ec_master_t *master)
Sends all datagrams in the queue.
Definition master.c:2446
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.
int ecrt_domain_state(const ec_domain_t *domain, ec_domain_state_t *state)
Reads the state of a domain.
Definition domain.c:679
int ecrt_master_link_state(const ec_master_t *master, unsigned int dev_idx, ec_master_link_state_t *state)
Reads the current state of a redundant link.
Definition master.c:2784
int ecrt_voe_handler_received_header(const ec_voe_handler_t *voe, uint32_t *vendor_id, uint16_t *vendor_type)
Reads the header data of a received VoE message.
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
#define EC_PUBLIC_API
Symbol visibility control macro.
Definition ecrt.h:253
int ecrt_master_reference_clock_time(const ec_master_t *master, uint32_t *time)
Get the lower 32 bit of the reference clock system time.
Definition master.c:2812
ec_request_state_t ecrt_reg_request_state(const ec_reg_request_t *reg)
Get the current state of the register request.
Definition reg_request.c:85
size_t ecrt_voe_handler_data_size(const ec_voe_handler_t *voe)
Returns the current data size.
int ecrt_master_send_ext(ec_master_t *master)
Sends non-application datagrams.
Definition master.c:2547
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.
int ecrt_master_sync_reference_clock(ec_master_t *master)
Queues the DC reference clock drift compensation datagram for sending.
Definition master.c:2832
int ecrt_voe_handler_write(ec_voe_handler_t *voe, size_t size)
Start a VoE write operation.
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_sdo_request_write(ec_sdo_request_t *req)
Schedule an SDO write operation.
int ecrt_master(ec_master_t *master, ec_master_info_t *master_info)
Obtains master information.
Definition master.c:2657
int ecrt_voe_handler_send_header(ec_voe_handler_t *voe, uint32_t vendor_id, uint16_t vendor_type)
Sets the VoE header for future send operations.
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.
int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position, ec_slave_info_t *slave_info)
Obtains slave information.
Definition master.c:2684
ec_watchdog_mode_t
Watchdog mode for sync manager configuration.
Definition ecrt.h:517
int ecrt_voe_handler_read_nosync(ec_voe_handler_t *voe)
Start a VoE read operation without querying the sync manager status.
int ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address, size_t size)
Schedule a register read operation.
int ecrt_master_activate(ec_master_t *master)
Finishes the configuration phase and prepares for cyclic operation.
Definition master.c:2302
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.
void ecrt_domain_external_memory(ec_domain_t *domain, uint8_t *mem)
Provide external memory to store the domain's process data.
Definition domain.c:433
uint8_t * ecrt_domain_data(const ec_domain_t *domain)
Returns the domain's process data.
Definition domain.c:450
int ecrt_slave_config_eoe_hostname(ec_slave_config_t *sc, const char *name)
Sets the host name for Ethernet-over-EtherCAT (EoE) operation.
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.
EC_PUBLIC_API int ecrt_master_set_send_interval(ec_master_t *master, size_t send_interval)
Set interval between calls to ecrt_master_send().
ec_request_state_t ecrt_voe_handler_execute(ec_voe_handler_t *voe)
Execute the handler.
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.
ec_request_state_t ecrt_sdo_request_state(const ec_sdo_request_t *req)
Get the current state of the SDO request.
int ecrt_master_deactivate(ec_master_t *master)
Deactivates the master.
Definition master.c:2376
int ecrt_master_sync_monitor_queue(ec_master_t *master)
Queues the DC synchrony monitoring datagram for sending.
Definition master.c:2874
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.
int ecrt_master_reset(ec_master_t *master)
Retry configuring slaves.
Definition master.c:3297
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t subindex, const uint8_t *data, size_t data_size, uint32_t *abort_code)
Executes an SDO download request to write data to a slave.
Definition master.c:2894
#define EC_MAX_STRING_LENGTH
Maximum string length.
Definition ecrt.h:273
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_domain_reg_pdo_entry_list(ec_domain_t *domain, const ec_pdo_entry_reg_t *regs)
Registers a bunch of PDO entries for a domain.
Definition domain.c:397
ec_request_state_t
Request state.
Definition ecrt.h:604
ec_slave_config_t * ecrt_master_slave_config(ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
Obtains a slave configuration.
Definition master.c:2626
int ecrt_soe_request_read(ec_soe_request_t *req)
Schedule an SoE IDN read operation.
int ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index, uint8_t subindex)
Set the SDO index and subindex.
int ecrt_soe_request_timeout(ec_soe_request_t *req, uint32_t timeout)
Set the timeout for an SoE request.
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_WC_COMPLETE
All registered process data were exchanged.
Definition ecrt.h:485
@ EC_WC_ZERO
No registered process data were exchanged.
Definition ecrt.h:482
@ EC_WC_INCOMPLETE
Some of the registered process data were exchanged.
Definition ecrt.h:483
@ EC_PORT_MII
Port is a MII.
Definition ecrt.h:430
@ EC_PORT_NOT_CONFIGURED
Port is not configured.
Definition ecrt.h:428
@ EC_PORT_NOT_IMPLEMENTED
Port is not implemented.
Definition ecrt.h:427
@ EC_PORT_EBUS
Port is an E-Bus.
Definition ecrt.h:429
@ 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_COUNT
Number of directions.
Definition ecrt.h:508
@ EC_DIR_INPUT
Values read by the master.
Definition ecrt.h:507
@ EC_DIR_OUTPUT
Values written by the master.
Definition ecrt.h:506
@ EC_WD_DEFAULT
Use the default setting of the sync manager.
Definition ecrt.h:518
@ EC_WD_DISABLE
Disable the watchdog.
Definition ecrt.h:520
@ EC_WD_ENABLE
Enable the watchdog.
Definition ecrt.h:519
@ EC_REQUEST_ERROR
Request processing failed.
Definition ecrt.h:608
@ EC_REQUEST_UNUSED
Not requested.
Definition ecrt.h:605
@ EC_REQUEST_SUCCESS
Request was processed successfully.
Definition ecrt.h:607
@ EC_REQUEST_BUSY
Request is being processed.
Definition ecrt.h:606
Domain state.
Definition ecrt.h:494
ec_wc_state_t wc_state
Working counter interpretation.
Definition ecrt.h:496
unsigned int working_counter
Value of the last working counter.
Definition ecrt.h:495
unsigned int redundancy_active
Redundant link is in use.
Definition ecrt.h:497
EtherCAT domain.
Definition domain.h:47
Master information.
Definition ecrt.h:398
unsigned int slave_count
Number of slaves in the network.
Definition ecrt.h:399
uint64_t app_time
Application time.
Definition ecrt.h:403
uint8_t scan_busy
true, while the master is scanning the network.
Definition ecrt.h:401
unsigned int link_up
true, if the network link is up.
Definition ecrt.h:400
Master scan progress information.
Definition ecrt.h:414
unsigned int slave_count
Number of slaves detected.
Definition ecrt.h:415
unsigned int scan_index
Index of the slave that is currently scanned.
Definition ecrt.h:416
Master state.
Definition ecrt.h:328
unsigned int al_states
Application-layer states of all slaves.
Definition ecrt.h:331
unsigned int slaves_responding
Sum of responding slaves on all Ethernet devices.
Definition ecrt.h:329
unsigned int link_up
true, if at least one Ethernet link is up.
Definition ecrt.h:340
EtherCAT master.
Definition master.h:194
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
List record type for PDO entry mass-registration.
Definition ecrt.h:582
uint32_t product_code
Slave product code.
Definition ecrt.h:586
unsigned int * offset
Pointer to a variable to store the PDO entry's (byte-)offset in the process data.
Definition ecrt.h:589
unsigned int * bit_position
Pointer to a variable to store a bit position (0-7) within the offset.
Definition ecrt.h:591
uint8_t subindex
PDO entry subindex.
Definition ecrt.h:588
uint16_t index
PDO entry index.
Definition ecrt.h:587
uint16_t alias
Slave alias address.
Definition ecrt.h:583
uint32_t vendor_id
Slave vendor ID.
Definition ecrt.h:585
uint16_t position
Slave position.
Definition ecrt.h:584
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
Register request.
Definition reg_request.h:40
CANopen SDO request.
Definition sdo_request.h:40
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
EtherCAT slave configuration.
ec_slave_port_link_t link
Port link state.
uint32_t delay_to_next_dc
Delay [ns] to next DC slave.
uint16_t next_slave
Ring position of next DC slave on that port.
ec_slave_port_desc_t desc
Physical port type.
uint32_t receive_time
Receive time on DC transmission delay measurement.
Slave information.
Definition ecrt.h:451
uint32_t revision_number
Revision-Number stored on the slave.
Definition ecrt.h:455
uint8_t error_flag
Error flag for that slave.
Definition ecrt.h:469
int16_t current_on_ebus
Used current in mA.
Definition ecrt.h:458
uint16_t position
Offset of the slave in the ring.
Definition ecrt.h:452
uint8_t al_state
Current state of the slave.
Definition ecrt.h:468
uint32_t product_code
Product-Code stored on the slave.
Definition ecrt.h:454
uint32_t vendor_id
Vendor-ID stored on the slave.
Definition ecrt.h:453
uint16_t alias
The slaves alias if not equal to 0.
Definition ecrt.h:457
uint32_t serial_number
Serial-Number stored on the slave.
Definition ecrt.h:456
char name[EC_MAX_STRING_LENGTH]
Name of the slave.
Definition ecrt.h:472
uint16_t sdo_count
Number of SDOs.
Definition ecrt.h:471
uint8_t sync_count
Number of sync managers.
Definition ecrt.h:470
Sercos-over-EtherCAT request.
Definition soe_request.h:40
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
Vendor specific over EtherCAT handler.
Definition voe_handler.h:41