IgH EtherCAT Master  1.5.3
ecrt.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2006-2023 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  *
23  * The license mentioned above concerns the source code only. Using the
24  * EtherCAT technology and brand is only permitted in compliance with the
25  * industrial property and similar rights of Beckhoff Automation GmbH.
26  *
27  *****************************************************************************/
28 
128 /*****************************************************************************/
129 
130 #ifndef __ECRT_H__
131 #define __ECRT_H__
132 
133 #ifdef __KERNEL__
134 #include <asm/byteorder.h>
135 #include <linux/types.h>
136 #include <linux/time.h>
137 #else
138 #include <stdlib.h> // for size_t
139 #include <stdint.h>
140 #include <sys/time.h> // for struct timeval
141 #endif
142 
143 /******************************************************************************
144  * Global definitions
145  *****************************************************************************/
146 
149 #define ECRT_VER_MAJOR 1
150 
153 #define ECRT_VER_MINOR 5
154 
157 #define ECRT_VERSION(a, b) (((a) << 8) + (b))
158 
161 #define ECRT_VERSION_MAGIC ECRT_VERSION(ECRT_VER_MAJOR, ECRT_VER_MINOR)
162 
163 /******************************************************************************
164  * Feature flags
165  *****************************************************************************/
166 
172 #define EC_HAVE_REDUNDANCY
173 
178 #define EC_HAVE_EMERGENCY
179 
186 #define EC_HAVE_REG_ACCESS
187 
190 #define EC_HAVE_SELECT_REF_CLOCK
191 
194 #define EC_HAVE_REF_CLOCK_TIME
195 
198 #define EC_HAVE_REG_BY_POS
199 
202 #define EC_HAVE_SYNC_TO
203 
206 #define EC_HAVE_FLAGS
207 
214 #define EC_HAVE_SOE_REQUESTS
215 
216 /*****************************************************************************/
217 
222 #define EC_END ~0U
223 
226 #define EC_MAX_SYNC_MANAGERS 16
227 
232 #define EC_MAX_STRING_LENGTH 64
233 
235 #define EC_MAX_PORTS 4
236 
245 #define EC_TIMEVAL2NANO(TV) \
246  (((TV).tv_sec - 946684800ULL) * 1000000000ULL + (TV).tv_usec * 1000ULL)
247 
252 #define EC_COE_EMERGENCY_MSG_SIZE 8
253 
254 /******************************************************************************
255  * Data types
256  *****************************************************************************/
257 
258 struct ec_master;
259 typedef struct ec_master ec_master_t;
261 struct ec_slave_config;
264 struct ec_domain;
265 typedef struct ec_domain ec_domain_t;
267 struct ec_sdo_request;
270 struct ec_soe_request;
273 struct ec_voe_handler;
276 struct ec_reg_request;
279 /*****************************************************************************/
280 
287 typedef struct {
288  unsigned int slaves_responding;
290  unsigned int al_states : 4;
299  unsigned int link_up : 1;
302 
303 /*****************************************************************************/
304 
311 typedef struct {
312  unsigned int slaves_responding;
314  unsigned int al_states : 4;
323  unsigned int link_up : 1;
326 
327 /*****************************************************************************/
328 
335 typedef struct {
336  unsigned int online : 1;
337  unsigned int operational : 1;
339  unsigned int al_state : 4;
348 
349 /*****************************************************************************/
350 
357 typedef struct {
358  unsigned int slave_count;
359  unsigned int link_up : 1;
360  uint8_t scan_busy;
361  uint64_t app_time;
363 
364 /*****************************************************************************/
365 
368 typedef enum {
374 
375 /*****************************************************************************/
376 
379 typedef struct {
380  uint8_t link_up;
381  uint8_t loop_closed;
382  uint8_t signal_detected;
384 
385 /*****************************************************************************/
386 
393 typedef struct {
394  uint16_t position;
395  uint32_t vendor_id;
396  uint32_t product_code;
397  uint32_t revision_number;
398  uint32_t serial_number;
399  uint16_t alias;
400  int16_t current_on_ebus;
401  struct {
404  uint32_t receive_time;
406  uint16_t next_slave;
408  uint32_t delay_to_next_dc;
409  } ports[EC_MAX_PORTS];
410  uint8_t al_state;
411  uint8_t error_flag;
412  uint8_t sync_count;
413  uint16_t sdo_count;
414  char name[EC_MAX_STRING_LENGTH];
416 
417 /*****************************************************************************/
418 
423 typedef enum {
428 } ec_wc_state_t;
429 
430 /*****************************************************************************/
431 
436 typedef struct {
437  unsigned int working_counter;
439  unsigned int redundancy_active;
441 
442 /*****************************************************************************/
443 
446 typedef enum {
452 
453 /*****************************************************************************/
454 
459 typedef enum {
464 
465 /*****************************************************************************/
466 
473 typedef struct {
474  uint16_t index;
475  uint8_t subindex;
476  uint8_t bit_length;
478 
479 /*****************************************************************************/
480 
487 typedef struct {
488  uint16_t index;
489  unsigned int n_entries;
496 } ec_pdo_info_t;
497 
498 /*****************************************************************************/
499 
506 typedef struct {
507  uint8_t index;
511  unsigned int n_pdos;
516 
517 /*****************************************************************************/
518 
524 typedef struct {
525  uint16_t alias;
526  uint16_t position;
527  uint32_t vendor_id;
528  uint32_t product_code;
529  uint16_t index;
530  uint8_t subindex;
531  unsigned int *offset;
533  unsigned int *bit_position;
538 
539 /*****************************************************************************/
540 
546 typedef enum {
552 
553 /*****************************************************************************/
554 
557 typedef enum {
562 } ec_al_state_t;
563 
564 /******************************************************************************
565  * Global functions
566  *****************************************************************************/
567 
568 #ifdef __cplusplus
569 extern "C" {
570 #endif
571 
576 unsigned int ecrt_version_magic(void);
577 
594  unsigned int master_index
595  );
596 
597 #ifndef __KERNEL__
598 
610 ec_master_t *ecrt_open_master(
611  unsigned int master_index
612  );
613 
614 #endif // #ifndef __KERNEL__
615 
627  ec_master_t *master
628  );
629 
630 /******************************************************************************
631  * Master methods
632  *****************************************************************************/
633 
634 #ifndef __KERNEL__
635 
643 int ecrt_master_reserve(
644  ec_master_t *master
645  );
646 
647 #endif // #ifndef __KERNEL__
648 
649 #ifdef __KERNEL__
650 
669  ec_master_t *master,
670  void (*send_cb)(void *),
671  void (*receive_cb)(void *),
672  void *cb_data
674  );
675 
676 #endif /* __KERNEL__ */
677 
691  ec_master_t *master
692  );
693 
725  ec_master_t *master,
726  uint16_t alias,
727  uint16_t position,
728  uint32_t vendor_id,
729  uint32_t product_code
730  );
731 
741  ec_master_t *master,
742  ec_slave_config_t *sc
744  );
745 
755 int ecrt_master(
756  ec_master_t *master,
757  ec_master_info_t *master_info
759  );
760 
772  ec_master_t *master,
773  uint16_t slave_position,
774  ec_slave_info_t *slave_info
776  );
777 
778 #ifndef __KERNEL__
779 
788 int ecrt_master_get_sync_manager(
789  ec_master_t *master,
790  uint16_t slave_position,
791  uint8_t sync_index,
793  ec_sync_info_t *sync
794  );
795 
805 int ecrt_master_get_pdo(
806  ec_master_t *master,
807  uint16_t slave_position,
808  uint8_t sync_index,
810  uint16_t pos,
811  ec_pdo_info_t *pdo
812  );
813 
821 int ecrt_master_get_pdo_entry(
822  ec_master_t *master,
823  uint16_t slave_position,
824  uint8_t sync_index,
826  uint16_t pdo_pos,
827  uint16_t entry_pos,
828  ec_pdo_entry_info_t *entry
829  );
830 
831 #endif /* #ifndef __KERNEL__ */
832 
843  ec_master_t *master,
844  uint16_t slave_position,
845  uint16_t index,
846  uint8_t subindex,
847  uint8_t *data,
848  size_t data_size,
849  uint32_t *abort_code
850  );
851 
863  ec_master_t *master,
864  uint16_t slave_position,
865  uint16_t index,
866  uint8_t *data,
867  size_t data_size,
868  uint32_t *abort_code
869  );
870 
881  ec_master_t *master,
882  uint16_t slave_position,
883  uint16_t index,
884  uint8_t subindex,
885  uint8_t *target,
886  size_t target_size,
887  size_t *result_size,
888  uint32_t *abort_code
889  );
890 
900  ec_master_t *master,
901  uint16_t slave_position,
902  uint8_t drive_no,
903  uint16_t idn,
904  uint8_t *data,
905  size_t data_size,
906  uint16_t *error_code
908  );
909 
919  ec_master_t *master,
920  uint16_t slave_position,
921  uint8_t drive_no,
922  uint16_t idn,
923  uint8_t *target,
925  size_t target_size,
926  size_t *result_size,
927  uint16_t *error_code
929  );
930 
949  ec_master_t *master
950  );
951 
963  ec_master_t *master
964  );
965 
977  ec_master_t *master,
978  size_t send_interval
979  );
980 
989 void ecrt_master_send(
990  ec_master_t *master
991  );
992 
1003 void ecrt_master_receive(
1004  ec_master_t *master
1005  );
1006 
1013  ec_master_t *master
1014  );
1015 
1023 void ecrt_master_state(
1024  const ec_master_t *master,
1025  ec_master_state_t *state
1026  );
1027 
1035  const ec_master_t *master,
1036  unsigned int dev_idx,
1038  ec_master_link_state_t *state
1040  );
1041 
1063  ec_master_t *master,
1064  uint64_t app_time
1065  );
1066 
1073  ec_master_t *master
1074  );
1075 
1082  ec_master_t *master,
1083  uint64_t sync_time
1084  );
1085 
1091  ec_master_t *master
1092  );
1093 
1111  ec_master_t *master,
1112  uint32_t *time
1113  );
1114 
1122  ec_master_t *master
1123  );
1124 
1134  ec_master_t *master
1135  );
1136 
1144 void ecrt_master_reset(
1145  ec_master_t *master
1146  );
1147 
1148 /******************************************************************************
1149  * Slave configuration methods
1150  *****************************************************************************/
1151 
1163  ec_slave_config_t *sc,
1164  uint8_t sync_index,
1166  ec_direction_t direction,
1167  ec_watchdog_mode_t watchdog_mode
1168  );
1169 
1176  ec_slave_config_t *sc,
1177  uint16_t watchdog_divider,
1182  uint16_t watchdog_intervals
1186  );
1187 
1197  ec_slave_config_t *sc,
1198  uint8_t sync_index,
1200  uint16_t index
1201  );
1202 
1215  ec_slave_config_t *sc,
1216  uint8_t sync_index
1218  );
1219 
1229  ec_slave_config_t *sc,
1230  uint16_t pdo_index,
1231  uint16_t entry_index,
1233  uint8_t entry_subindex,
1235  uint8_t entry_bit_length
1236  );
1237 
1249  ec_slave_config_t *sc,
1250  uint16_t pdo_index
1251  );
1252 
1325  ec_slave_config_t *sc,
1326  unsigned int n_syncs,
1328  const ec_sync_info_t syncs[]
1330  );
1331 
1351  ec_slave_config_t *sc,
1352  uint16_t entry_index,
1353  uint8_t entry_subindex,
1354  ec_domain_t *domain,
1355  unsigned int *bit_position
1357  );
1358 
1373  ec_slave_config_t *sc,
1374  uint8_t sync_index,
1375  unsigned int pdo_pos,
1376  unsigned int entry_pos,
1377  ec_domain_t *domain,
1378  unsigned int *bit_position
1380  );
1381 
1397  ec_slave_config_t *sc,
1398  uint16_t assign_activate,
1399  uint32_t sync0_cycle,
1400  int32_t sync0_shift,
1401  uint32_t sync1_cycle,
1402  int32_t sync1_shift
1403  );
1404 
1431  ec_slave_config_t *sc,
1432  uint16_t index,
1433  uint8_t subindex,
1434  const uint8_t *data,
1435  size_t size
1436  );
1437 
1449  ec_slave_config_t *sc,
1450  uint16_t sdo_index,
1451  uint8_t sdo_subindex,
1452  uint8_t value
1453  );
1454 
1466  ec_slave_config_t *sc,
1467  uint16_t sdo_index,
1468  uint8_t sdo_subindex,
1469  uint16_t value
1470  );
1471 
1483  ec_slave_config_t *sc,
1484  uint16_t sdo_index,
1485  uint8_t sdo_subindex,
1486  uint32_t value
1487  );
1488 
1503  ec_slave_config_t *sc,
1504  uint16_t index,
1505  const uint8_t *data,
1506  size_t size
1507  );
1508 
1520  ec_slave_config_t *sc,
1521  size_t elements
1522  );
1523 
1536  ec_slave_config_t *sc,
1537  uint8_t *target
1539  );
1540 
1546  ec_slave_config_t *sc
1547  );
1548 
1558  ec_slave_config_t *sc
1559  );
1560 
1572  ec_slave_config_t *sc,
1573  uint16_t index,
1574  uint8_t subindex,
1575  size_t size
1576  );
1577 
1589  ec_slave_config_t *sc,
1590  uint8_t drive_no,
1591  uint16_t idn,
1592  size_t size
1593  );
1594 
1611  ec_slave_config_t *sc,
1612  size_t size
1613  );
1614 
1630  ec_slave_config_t *sc,
1631  size_t size
1632  );
1633 
1644  const ec_slave_config_t *sc,
1645  ec_slave_config_state_t *state
1646  );
1647 
1671  ec_slave_config_t *sc,
1672  uint8_t drive_no,
1673  uint16_t idn,
1674  ec_al_state_t state,
1676  const uint8_t *data,
1677  size_t size
1678  );
1679 
1703  ec_slave_config_t *sc,
1704  const char *key,
1705  int32_t value
1706  );
1707 
1708 /******************************************************************************
1709  * Domain methods
1710  *****************************************************************************/
1711 
1724  ec_domain_t *domain,
1725  const ec_pdo_entry_reg_t *pdo_entry_regs
1727  );
1728 
1733 size_t ecrt_domain_size(
1734  const ec_domain_t *domain
1735  );
1736 
1737 #ifdef __KERNEL__
1738 
1752  ec_domain_t *domain,
1753  uint8_t *memory
1755  );
1756 
1757 #endif /* __KERNEL__ */
1758 
1772 uint8_t *ecrt_domain_data(
1773  ec_domain_t *domain
1774  );
1775 
1783 void ecrt_domain_process(
1784  ec_domain_t *domain
1785  );
1786 
1792 void ecrt_domain_queue(
1793  ec_domain_t *domain
1794  );
1795 
1802 void ecrt_domain_state(
1803  const ec_domain_t *domain,
1804  ec_domain_state_t *state
1806  );
1807 
1808 /*****************************************************************************
1809  * SDO request methods.
1810  ****************************************************************************/
1811 
1819  ec_sdo_request_t *req,
1820  uint16_t index,
1821  uint8_t subindex
1822  );
1823 
1833  ec_sdo_request_t *req,
1834  uint32_t timeout
1836  );
1837 
1861 uint8_t *ecrt_sdo_request_data(
1862  ec_sdo_request_t *req
1863  );
1864 
1874  const ec_sdo_request_t *req
1875  );
1876 
1881 #ifdef __KERNEL__
1883  const ec_sdo_request_t *req
1884  );
1885 #else
1887  ec_sdo_request_t *req
1888  );
1889 #endif
1890 
1897  ec_sdo_request_t *req
1898  );
1899 
1910  ec_sdo_request_t *req
1911  );
1912 
1913 /*****************************************************************************
1914  * SoE request methods.
1915  ****************************************************************************/
1916 
1924  ec_soe_request_t *req,
1925  uint8_t drive_no,
1926  uint16_t idn
1927  );
1928 
1938  ec_soe_request_t *req,
1939  uint32_t timeout
1941  );
1942 
1966 uint8_t *ecrt_soe_request_data(
1967  ec_soe_request_t *req
1968  );
1969 
1979  const ec_soe_request_t *req
1980  );
1981 
1987  ec_soe_request_t *req
1988  );
1989 
1996  ec_soe_request_t *req
1997  );
1998 
2009  ec_soe_request_t *req
2010  );
2011 
2012 /*****************************************************************************
2013  * VoE handler methods.
2014  ****************************************************************************/
2015 
2024  ec_voe_handler_t *voe,
2025  uint32_t vendor_id,
2026  uint16_t vendor_type
2027  );
2028 
2038  const ec_voe_handler_t *voe,
2039  uint32_t *vendor_id,
2040  uint16_t *vendor_type
2041  );
2042 
2063 uint8_t *ecrt_voe_handler_data(
2064  ec_voe_handler_t *voe
2065  );
2066 
2080  const ec_voe_handler_t *voe
2081  );
2082 
2090  ec_voe_handler_t *voe,
2091  size_t size
2092  );
2093 
2109  ec_voe_handler_t *voe
2110  );
2111 
2128  ec_voe_handler_t *voe
2129  );
2130 
2139  ec_voe_handler_t *voe
2140  );
2141 
2142 /*****************************************************************************
2143  * Register request methods.
2144  ****************************************************************************/
2145 
2165 uint8_t *ecrt_reg_request_data(
2166  ec_reg_request_t *req
2167  );
2168 
2173 #ifdef __KERNEL__
2175  const ec_reg_request_t *req
2176  );
2177 #else
2179  ec_reg_request_t *req
2180  );
2181 #endif
2182 
2192  ec_reg_request_t *req,
2193  uint16_t address,
2194  size_t size
2195  );
2196 
2206  ec_reg_request_t *req,
2207  uint16_t address,
2208  size_t size
2209  );
2210 
2211 /******************************************************************************
2212  * Bitwise read/write macros
2213  *****************************************************************************/
2214 
2220 #define EC_READ_BIT(DATA, POS) ((*((uint8_t *) (DATA)) >> (POS)) & 0x01)
2221 
2228 #define EC_WRITE_BIT(DATA, POS, VAL) \
2229  do { \
2230  if (VAL) *((uint8_t *) (DATA)) |= (1 << (POS)); \
2231  else *((uint8_t *) (DATA)) &= ~(1 << (POS)); \
2232  } while (0)
2233 
2234 /******************************************************************************
2235  * Byte-swapping functions for user space
2236  *****************************************************************************/
2237 
2238 #ifndef __KERNEL__
2239 
2240 #if __BYTE_ORDER == __LITTLE_ENDIAN
2241 
2242 #define le16_to_cpu(x) x
2243 #define le32_to_cpu(x) x
2244 #define le64_to_cpu(x) x
2245 
2246 #define cpu_to_le16(x) x
2247 #define cpu_to_le32(x) x
2248 #define cpu_to_le64(x) x
2249 
2250 #elif __BYTE_ORDER == __BIG_ENDIAN
2251 
2252 #define swap16(x) \
2253  ((uint16_t)( \
2254  (((uint16_t)(x) & 0x00ffU) << 8) | \
2255  (((uint16_t)(x) & 0xff00U) >> 8) ))
2256 #define swap32(x) \
2257  ((uint32_t)( \
2258  (((uint32_t)(x) & 0x000000ffUL) << 24) | \
2259  (((uint32_t)(x) & 0x0000ff00UL) << 8) | \
2260  (((uint32_t)(x) & 0x00ff0000UL) >> 8) | \
2261  (((uint32_t)(x) & 0xff000000UL) >> 24) ))
2262 #define swap64(x) \
2263  ((uint64_t)( \
2264  (((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
2265  (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
2266  (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
2267  (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
2268  (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
2269  (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
2270  (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
2271  (((uint64_t)(x) & 0xff00000000000000ULL) >> 56) ))
2272 
2273 #define le16_to_cpu(x) swap16(x)
2274 #define le32_to_cpu(x) swap32(x)
2275 #define le64_to_cpu(x) swap64(x)
2276 
2277 #define cpu_to_le16(x) swap16(x)
2278 #define cpu_to_le32(x) swap32(x)
2279 #define cpu_to_le64(x) swap64(x)
2280 
2281 #endif
2282 
2283 #define le16_to_cpup(x) le16_to_cpu(*((uint16_t *)(x)))
2284 #define le32_to_cpup(x) le32_to_cpu(*((uint32_t *)(x)))
2285 #define le64_to_cpup(x) le64_to_cpu(*((uint64_t *)(x)))
2286 
2287 #endif /* ifndef __KERNEL__ */
2288 
2289 /******************************************************************************
2290  * Read macros
2291  *****************************************************************************/
2292 
2297 #define EC_READ_U8(DATA) \
2298  ((uint8_t) *((uint8_t *) (DATA)))
2299 
2305 #define EC_READ_S8(DATA) \
2306  ((int8_t) *((uint8_t *) (DATA)))
2307 
2313 #define EC_READ_U16(DATA) \
2314  ((uint16_t) le16_to_cpup((void *) (DATA)))
2315 
2321 #define EC_READ_S16(DATA) \
2322  ((int16_t) le16_to_cpup((void *) (DATA)))
2323 
2329 #define EC_READ_U32(DATA) \
2330  ((uint32_t) le32_to_cpup((void *) (DATA)))
2331 
2337 #define EC_READ_S32(DATA) \
2338  ((int32_t) le32_to_cpup((void *) (DATA)))
2339 
2345 #define EC_READ_U64(DATA) \
2346  ((uint64_t) le64_to_cpup((void *) (DATA)))
2347 
2353 #define EC_READ_S64(DATA) \
2354  ((int64_t) le64_to_cpup((void *) (DATA)))
2355 
2356 /******************************************************************************
2357  * Floating-point read functions and macros (userspace only)
2358  *****************************************************************************/
2359 
2360 #ifndef __KERNEL__
2361 
2367 float ecrt_read_real(const void *data);
2368 
2374 #define EC_READ_REAL(DATA) ecrt_read_real(DATA)
2375 
2381 double ecrt_read_lreal(const void *data);
2382 
2388 #define EC_READ_LREAL(DATA) ecrt_read_lreal(DATA)
2389 
2390 #endif // ifndef __KERNEL__
2391 
2392 /******************************************************************************
2393  * Write macros
2394  *****************************************************************************/
2395 
2401 #define EC_WRITE_U8(DATA, VAL) \
2402  do { \
2403  *((uint8_t *)(DATA)) = ((uint8_t) (VAL)); \
2404  } while (0)
2405 
2411 #define EC_WRITE_S8(DATA, VAL) EC_WRITE_U8(DATA, VAL)
2412 
2418 #define EC_WRITE_U16(DATA, VAL) \
2419  do { \
2420  *((uint16_t *) (DATA)) = cpu_to_le16((uint16_t) (VAL)); \
2421  } while (0)
2422 
2428 #define EC_WRITE_S16(DATA, VAL) EC_WRITE_U16(DATA, VAL)
2429 
2435 #define EC_WRITE_U32(DATA, VAL) \
2436  do { \
2437  *((uint32_t *) (DATA)) = cpu_to_le32((uint32_t) (VAL)); \
2438  } while (0)
2439 
2445 #define EC_WRITE_S32(DATA, VAL) EC_WRITE_U32(DATA, VAL)
2446 
2452 #define EC_WRITE_U64(DATA, VAL) \
2453  do { \
2454  *((uint64_t *) (DATA)) = cpu_to_le64((uint64_t) (VAL)); \
2455  } while (0)
2456 
2462 #define EC_WRITE_S64(DATA, VAL) EC_WRITE_U64(DATA, VAL)
2463 
2464 /******************************************************************************
2465  * Floating-point write functions and macros (userspace only)
2466  *****************************************************************************/
2467 
2468 #ifndef __KERNEL__
2469 
2475 void ecrt_write_real(void *data, float value);
2476 
2482 #define EC_WRITE_REAL(DATA, VAL) ecrt_write_real(DATA, VAL)
2483 
2489 void ecrt_write_lreal(void *data, double value);
2490 
2496 #define EC_WRITE_LREAL(DATA, VAL) ecrt_write_lreal(DATA, VAL)
2497 
2498 #endif // ifndef __KERNEL__
2499 
2500 /*****************************************************************************/
2501 
2502 #ifdef __cplusplus
2503 }
2504 #endif
2505 
2506 /*****************************************************************************/
2507 
2510 #endif
unsigned int working_counter
Value of the last working counter.
Definition: ecrt.h:437
size_t ecrt_domain_size(const ec_domain_t *domain)
Returns the current size of the domain&#39;s process data.
Definition: domain.c:427
void ecrt_reg_request_write(ec_reg_request_t *req, uint16_t address, size_t size)
Schedule an register write operation.
Definition: reg_request.c:100
uint32_t serial_number
Serial-Number stored on the slave.
Definition: ecrt.h:398
ec_slave_port_desc_t desc
Physical port type.
Definition: ecrt.h:402
uint8_t subindex
PDO entry subindex.
Definition: ecrt.h:530
Pre-operational.
Definition: ecrt.h:559
uint16_t position
Slave position.
Definition: ecrt.h:526
int ecrt_slave_config_emerg_size(ec_slave_config_t *sc, size_t elements)
Set the size of the CoE emergency ring buffer.
uint32_t ecrt_master_sync_monitor_process(ec_master_t *master)
Processes the DC synchrony monitoring datagram.
Definition: master.c:2867
void 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.
Definition: voe_handler.c:132
void ecrt_reg_request_read(ec_reg_request_t *req, uint16_t address, size_t size)
Schedule a register read operation.
Definition: reg_request.c:111
size_t ecrt_voe_handler_data_size(const ec_voe_handler_t *voe)
Returns the current data size.
Definition: voe_handler.c:152
void ecrt_release_master(ec_master_t *master)
Releases a requested EtherCAT master.
Definition: module.c:625
uint8_t sync_count
Number of sync managers.
Definition: ecrt.h:412
unsigned int n_entries
Number of PDO entries in entries to map.
Definition: ecrt.h:489
uint8_t bit_length
Size of the PDO entry in bit.
Definition: ecrt.h:476
ec_direction_t dir
Sync manager direction.
Definition: ecrt.h:510
uint8_t error_flag
Error flag for that slave.
Definition: ecrt.h:411
ec_watchdog_mode_t
Watchdog mode for sync manager configuration.
Definition: ecrt.h:459
void ecrt_master_sync_slave_clocks(ec_master_t *master)
Queues the DC clock drift compensation datagram for sending.
Definition: master.c:2849
ec_slave_port_desc_t
EtherCAT slave port descriptor.
Definition: ecrt.h:368
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.
Definition: slave_config.c:984
ec_al_state_t
Application-layer state.
Definition: ecrt.h:557
ec_pdo_info_t * pdos
Array with PDOs to assign.
Definition: ecrt.h:512
int ecrt_slave_config_pdo_assign_add(ec_slave_config_t *sc, uint8_t sync_index, uint16_t index)
Add a PDO to a sync manager&#39;s PDO assignment.
Definition: slave_config.c:668
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:2780
void ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
Sets the application time.
Definition: master.c:2796
unsigned int redundancy_active
Redundant link is in use.
Definition: ecrt.h:439
CANopen SDO request.
Definition: sdo_request.h:46
unsigned int slave_count
Number of slaves in the bus.
Definition: ecrt.h:358
uint16_t index
PDO entry index.
Definition: ecrt.h:529
Operational.
Definition: ecrt.h:561
uint32_t vendor_id
Vendor-ID stored on the slave.
Definition: ecrt.h:395
int ecrt_master_sdo_download_complete(ec_master_t *master, uint16_t slave_position, uint16_t index, 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:2957
Register request.
Definition: reg_request.h:48
ec_slave_port_link_t link
Port link state.
Definition: ecrt.h:403
Safe-operational.
Definition: ecrt.h:560
int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain, const ec_pdo_entry_reg_t *pdo_entry_regs)
Registers a bunch of PDO entries for a domain.
Definition: domain.c:398
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:2743
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:2681
Disable the watchdog.
Definition: ecrt.h:462
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.
Definition: slave_config.c:900
uint32_t delay_to_next_dc
Delay [ns] to next DC slave.
Definition: ecrt.h:408
void ecrt_master_send_ext(ec_master_t *master)
Sends non-application datagrams.
Definition: master.c:2561
Enable the watchdog.
Definition: ecrt.h:461
ec_wc_state_t wc_state
Working counter interpretation.
Definition: ecrt.h:438
PDO configuration information.
Definition: ecrt.h:487
ec_domain_t * ecrt_master_create_domain(ec_master_t *master)
Creates a new process data domain.
Definition: master.c:2311
void ecrt_voe_handler_read(ec_voe_handler_t *voe)
Start a VoE read operation.
Definition: voe_handler.c:159
uint8_t * ecrt_soe_request_data(ec_soe_request_t *req)
Access to the SoE request&#39;s data.
Definition: soe_request.c:288
Sync manager configuration information.
Definition: ecrt.h:506
ec_wc_state_t
Domain working counter interpretation.
Definition: ecrt.h:423
unsigned int slaves_responding
Sum of responding slaves on all Ethernet devices.
Definition: ecrt.h:288
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
Reads the current master state.
Definition: master.c:2757
void ecrt_voe_handler_read_nosync(ec_voe_handler_t *voe)
Start a VoE read operation without querying the sync manager status.
Definition: voe_handler.c:168
int ecrt_slave_config_emerg_clear(ec_slave_config_t *sc)
Clears CoE emergency ring buffer and the overrun counter.
void ecrt_domain_external_memory(ec_domain_t *domain, uint8_t *memory)
Provide external memory to store the domain&#39;s process data.
Definition: domain.c:434
void 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:2836
void ecrt_soe_request_idn(ec_soe_request_t *req, uint8_t drive_no, uint16_t idn)
Set the request&#39;s drive and Sercos ID numbers.
Definition: soe_request.c:272
void ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout)
Set the timeout for an SDO request.
Definition: sdo_request.c:196
unsigned int link_up
true, if the network link is up.
Definition: ecrt.h:359
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_flag(ec_slave_config_t *sc, const char *key, int32_t value)
Adds a feature flag to a slave configuration.
void ecrt_slave_config_dc(ec_slave_config_t *sc, uint16_t assign_activate, uint32_t sync0_cycle, int32_t sync0_shift, uint32_t sync1_cycle, int32_t sync1_shift)
Configure distributed clocks.
Definition: slave_config.c:965
int ecrt_slave_config_sdo16(ec_slave_config_t *sc, uint16_t sdo_index, uint8_t sdo_subindex, uint16_t value)
Add a configuration value for a 16-bit SDO.
Some of the registered process data were exchanged.
Definition: ecrt.h:425
uint32_t revision_number
Revision-Number stored on the slave.
Definition: ecrt.h:397
uint8_t * ecrt_sdo_request_data(ec_sdo_request_t *req)
Access to the SDO request&#39;s data.
Definition: sdo_request.c:203
Use the default setting of the sync manager.
Definition: ecrt.h:460
uint16_t alias
Slave alias address.
Definition: ecrt.h:525
Not requested.
Definition: ecrt.h:547
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.
uint16_t index
PDO index.
Definition: ecrt.h:488
void ecrt_sdo_request_read(ec_sdo_request_t *req)
Schedule an SDO read operation.
Definition: sdo_request.c:224
ec_master_t * ecrt_request_master(unsigned int master_index)
Requests an EtherCAT master for realtime operation.
Definition: module.c:617
Master state.
Definition: ecrt.h:287
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.
Slave configuration state.
Definition: ecrt.h:335
Request is being processed.
Definition: ecrt.h:548
uint64_t app_time
Application time.
Definition: ecrt.h:361
ec_watchdog_mode_t watchdog_mode
Watchdog mode.
Definition: ecrt.h:514
unsigned int n_pdos
Number of PDOs in pdos.
Definition: ecrt.h:511
Domain state.
Definition: ecrt.h:436
uint32_t vendor_id
Slave vendor ID.
Definition: ecrt.h:527
unsigned int al_state
The application-layer state of the slave.
Definition: ecrt.h:339
unsigned int * bit_position
Pointer to a variable to store a bit position (0-7) within the offset.
Definition: ecrt.h:533
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t subindex, 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:2878
Port is an E-Bus.
Definition: ecrt.h:371
unsigned int operational
The slave was brought into OP state using the specified configuration.
Definition: ecrt.h:337
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:2647
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_direction_t
Direction type for PDO assignment functions.
Definition: ecrt.h:446
int ecrt_master_set_send_interval(ec_master_t *master, size_t send_interval)
Set interval between calls to ecrt_master_send().
unsigned int ecrt_version_magic(void)
Returns the version magic of the realtime interface.
Definition: module.c:651
Port is a MII.
Definition: ecrt.h:372
Vendor specific over EtherCAT handler.
Definition: voe_handler.h:49
ec_request_state_t ecrt_voe_handler_execute(ec_voe_handler_t *voe)
Execute the handler.
Definition: voe_handler.c:187
int ecrt_slave_config_sdo32(ec_slave_config_t *sc, uint16_t sdo_index, uint8_t sdo_subindex, uint32_t value)
Add a configuration value for a 32-bit SDO.
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:3038
ec_request_state_t ecrt_soe_request_state(ec_soe_request_t *req)
Get the current state of the SoE request.
Definition: soe_request.c:302
Values read by the master.
Definition: ecrt.h:449
ec_request_state_t ecrt_sdo_request_state(const ec_sdo_request_t *req)
Get the current state of the SDO request.
Definition: sdo_request.c:217
unsigned int online
The slave is online.
Definition: ecrt.h:336
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.
void ecrt_master_reset(ec_master_t *master)
Retry configuring slaves.
Definition: master.c:3281
Port is not configured.
Definition: ecrt.h:370
Port is not implemented.
Definition: ecrt.h:369
Slave information.
Definition: ecrt.h:393
void ecrt_master_sync_monitor_queue(ec_master_t *master)
Queues the DC synchrony monitoring datagram for sending.
Definition: master.c:2859
void ecrt_voe_handler_write(ec_voe_handler_t *voe, size_t size)
Start a VoE write operation.
Definition: voe_handler.c:177
int ecrt_slave_config_sdo8(ec_slave_config_t *sc, uint16_t sdo_index, uint8_t sdo_subindex, uint8_t value)
Add a configuration value for an 8-bit SDO.
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&#39;s mapping.
Definition: slave_config.c:716
int ecrt_slave_config_reg_pdo_entry(ec_slave_config_t *sc, uint16_t entry_index, uint8_t entry_subindex, ec_domain_t *domain, unsigned int *bit_position)
Registers a PDO entry for process data exchange in a domain.
Definition: slave_config.c:845
uint16_t index
PDO entry index.
Definition: ecrt.h:474
uint8_t al_state
Current state of the slave.
Definition: ecrt.h:410
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:2636
uint8_t scan_busy
true, while the master is scanning the bus
Definition: ecrt.h:360
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.
Definition: slave_config.c:778
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:3197
int ecrt_master_activate(ec_master_t *master)
Finishes the configuration phase and prepares for cyclic operation.
Definition: master.c:2321
int16_t current_on_ebus
Used current in mA.
Definition: ecrt.h:400
size_t ecrt_sdo_request_data_size(const ec_sdo_request_t *req)
Returns the current SDO data size.
Definition: sdo_request.c:210
void ecrt_slave_config_pdo_mapping_clear(ec_slave_config_t *sc, uint16_t pdo_index)
Clear the mapping of a given PDO.
Definition: slave_config.c:753
Invalid direction.
Definition: ecrt.h:447
#define EC_MAX_PORTS
Maximum number of slave ports.
Definition: ecrt.h:235
Number of directions.
Definition: ecrt.h:450
uint16_t sdo_count
Number of SDOs.
Definition: ecrt.h:413
#define EC_MAX_STRING_LENGTH
Maximum string length.
Definition: ecrt.h:232
uint8_t * ecrt_domain_data(ec_domain_t *domain)
Returns the domain&#39;s process data.
Definition: domain.c:451
List record type for PDO entry mass-registration.
Definition: ecrt.h:524
unsigned int link_up
true, if at least one Ethernet link is up.
Definition: ecrt.h:299
void ecrt_soe_request_write(ec_soe_request_t *req)
Schedule an SoE IDN write operation.
Definition: soe_request.c:316
uint16_t next_slave
Ring position of next DC slave on that port.
Definition: ecrt.h:406
void ecrt_soe_request_read(ec_soe_request_t *req)
Schedule an SoE IDN read operation.
Definition: soe_request.c:309
No registered process data were exchanged.
Definition: ecrt.h:424
All registered process data were exchanged.
Definition: ecrt.h:427
void ecrt_slave_config_watchdog(ec_slave_config_t *sc, uint16_t watchdog_divider, uint16_t watchdog_intervals)
Configure a slave&#39;s watchdog times.
Definition: slave_config.c:656
void ecrt_master_deactivate(ec_master_t *master)
Deactivates the master.
Definition: master.c:2395
unsigned int al_states
Application-layer states of all slaves.
Definition: ecrt.h:290
int ecrt_slave_config_sync_manager(ec_slave_config_t *sc, uint8_t sync_index, ec_direction_t direction, ec_watchdog_mode_t watchdog_mode)
Configure a sync manager.
Definition: slave_config.c:629
uint16_t alias
The slaves alias if not equal to 0.
Definition: ecrt.h:399
int ecrt_master(ec_master_t *master, ec_master_info_t *master_info)
Obtains master information.
Definition: master.c:2667
int ecrt_master_write_idn(ec_master_t *master, uint16_t slave_position, uint8_t drive_no, uint16_t idn, uint8_t *data, size_t data_size, uint16_t *error_code)
Executes an SoE write request.
Definition: master.c:3121
EtherCAT slave configuration.
Definition: slave_config.h:117
uint32_t product_code
Product-Code stored on the slave.
Definition: ecrt.h:396
void 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.
Definition: voe_handler.c:123
Request was processed successfully.
Definition: ecrt.h:549
void ecrt_soe_request_timeout(ec_soe_request_t *req, uint32_t timeout)
Set the timeout for an SoE request.
Definition: soe_request.c:281
unsigned int * offset
Pointer to a variable to store the PDO entry&#39;s (byte-)offset in the process data. ...
Definition: ecrt.h:531
ec_request_state_t
Request state.
Definition: ecrt.h:546
uint8_t * ecrt_reg_request_data(ec_reg_request_t *req)
Access to the register request&#39;s data.
Definition: reg_request.c:86
int ecrt_master_reference_clock_time(ec_master_t *master, uint32_t *time)
Get the lower 32 bit of the reference clock system time.
Definition: master.c:2807
Master information.
Definition: ecrt.h:357
void ecrt_domain_state(const ec_domain_t *domain, ec_domain_state_t *state)
Reads the state of a domain.
Definition: domain.c:678
PDO entry configuration information.
Definition: ecrt.h:473
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.
void ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc, uint8_t sync_index)
Clear a sync manager&#39;s PDO assignment.
Definition: slave_config.c:698
void ecrt_domain_process(ec_domain_t *domain)
Determines the states of the domain&#39;s datagrams.
Definition: domain.c:458
uint8_t index
Sync manager index.
Definition: ecrt.h:507
void ecrt_slave_config_state(const ec_slave_config_t *sc, ec_slave_config_state_t *state)
Outputs the state of the slave configuration.
Values written by the master.
Definition: ecrt.h:448
Init.
Definition: ecrt.h:558
void ecrt_domain_queue(ec_domain_t *domain)
(Re-)queues all domain datagrams in the master&#39;s datagram queue.
Definition: domain.c:648
uint16_t position
Offset of the slave in the ring.
Definition: ecrt.h:394
uint32_t receive_time
Receive time on DC transmission delay measurement.
Definition: ecrt.h:404
uint32_t product_code
Slave product code.
Definition: ecrt.h:528
EtherCAT master.
Definition: master.h:194
Request processing failed.
Definition: ecrt.h:550
size_t ecrt_soe_request_data_size(const ec_soe_request_t *req)
Returns the current IDN data size.
Definition: soe_request.c:295
void ecrt_master_sync_reference_clock(ec_master_t *master)
Queues the DC reference clock drift compensation datagram for sending.
Definition: master.c:2826
uint8_t subindex
PDO entry subindex.
Definition: ecrt.h:475
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.
uint8_t * ecrt_voe_handler_data(ec_voe_handler_t *voe)
Access to the VoE handler&#39;s data.
Definition: voe_handler.c:145
void ecrt_sdo_request_write(ec_sdo_request_t *req)
Schedule an SDO write operation.
Definition: sdo_request.c:235
int ecrt_slave_config_emerg_overruns(ec_slave_config_t *sc)
Read the number of CoE emergency overruns.
Sercos-over-EtherCAT request.
Definition: soe_request.h:48
ec_request_state_t ecrt_reg_request_state(const ec_reg_request_t *req)
Get the current state of the register request.
Definition: reg_request.c:93
EtherCAT domain.
Definition: domain.h:54
void ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index, uint8_t subindex)
Set the SDO index and subindex.
Definition: sdo_request.c:187
ec_pdo_entry_info_t * entries
Array of PDO entries to map.
Definition: ecrt.h:493
void ecrt_master_receive(ec_master_t *master)
Fetches received frames from the hardware and processes the datagrams.
Definition: master.c:2509
void ecrt_master_send(ec_master_t *master)
Sends all datagrams in the queue.
Definition: master.c:2465