17 * GNU Lesser General Public License for more details. |
17 * GNU Lesser General Public License for more details. |
18 * |
18 * |
19 * You should have received a copy of the GNU Lesser General Public License |
19 * You should have received a copy of the GNU Lesser General Public License |
20 * along with the IgH EtherCAT master userspace library. If not, see |
20 * along with the IgH EtherCAT master userspace library. If not, see |
21 * <http://www.gnu.org/licenses/>. |
21 * <http://www.gnu.org/licenses/>. |
22 * |
22 * |
23 * --- |
23 * --- |
24 * |
24 * |
25 * The license mentioned above concerns the source code only. Using the |
25 * The license mentioned above concerns the source code only. Using the |
26 * EtherCAT technology and brand is only permitted in compliance with the |
26 * EtherCAT technology and brand is only permitted in compliance with the |
27 * industrial property and similar rights of Beckhoff Automation GmbH. |
27 * industrial property and similar rights of Beckhoff Automation GmbH. |
28 * |
28 * |
29 *****************************************************************************/ |
29 *****************************************************************************/ |
45 * ecrt_slave_config_dc() to configure a slave for cyclic operation, and |
45 * ecrt_slave_config_dc() to configure a slave for cyclic operation, and |
46 * ecrt_master_application_time(), ecrt_master_sync_reference_clock() and |
46 * ecrt_master_application_time(), ecrt_master_sync_reference_clock() and |
47 * ecrt_master_sync_slave_clocks() for offset and drift compensation. The |
47 * ecrt_master_sync_slave_clocks() for offset and drift compensation. The |
48 * EC_TIMEVAL2NANO() macro can be used for epoch time conversion, while the |
48 * EC_TIMEVAL2NANO() macro can be used for epoch time conversion, while the |
49 * ecrt_master_sync_monitor_queue() and ecrt_master_sync_monitor_process() |
49 * ecrt_master_sync_monitor_queue() and ecrt_master_sync_monitor_process() |
50 * methods can be used to monitor the synchrony. |
50 * methods can be used to monitor the synchrony. |
51 * - Improved the callback mechanism. ecrt_master_callbacks() now takes two |
51 * - Improved the callback mechanism. ecrt_master_callbacks() now takes two |
52 * callback functions for sending and receiving datagrams. |
52 * callback functions for sending and receiving datagrams. |
53 * ecrt_master_send_ext() is used to execute the sending of non-application |
53 * ecrt_master_send_ext() is used to execute the sending of non-application |
54 * datagrams. |
54 * datagrams. |
55 * - Added watchdog configuration (method ecrt_slave_config_watchdog(), |
55 * - Added watchdog configuration (method ecrt_slave_config_watchdog(), |
220 * \see ecrt_master(). |
223 * \see ecrt_master(). |
221 */ |
224 */ |
222 typedef struct { |
225 typedef struct { |
223 unsigned int slave_count; /**< Number of slaves in the bus. */ |
226 unsigned int slave_count; /**< Number of slaves in the bus. */ |
224 unsigned int link_up : 1; /**< \a true, if the network link is up. */ |
227 unsigned int link_up : 1; /**< \a true, if the network link is up. */ |
225 uint8_t scan_busy; /**< \a true, while the master is scanning the bus */ |
228 uint8_t scan_busy; /**< \a true, while the master is scanning the bus */ |
226 uint64_t app_time; /**< Application time. */ |
229 uint64_t app_time; /**< Application time. */ |
227 } ec_master_info_t; |
230 } ec_master_info_t; |
|
231 |
|
232 /*****************************************************************************/ |
|
233 |
|
234 /** EtherCAT slave port descriptor. |
|
235 */ |
|
236 typedef enum { |
|
237 EC_PORT_NOT_IMPLEMENTED, /**< Port is not implemented. */ |
|
238 EC_PORT_NOT_CONFIGURED, /**< Port is not configured. */ |
|
239 EC_PORT_EBUS, /**< Port is an e-bus. */ |
|
240 EC_PORT_MII /**< Port is a mii. */ |
|
241 } ec_slave_port_desc_t; |
|
242 |
|
243 /*****************************************************************************/ |
|
244 |
|
245 /** EtherCAT slave port information. |
|
246 */ |
|
247 typedef struct { |
|
248 uint8_t link_up; /**< Link detected. */ |
|
249 uint8_t loop_closed; /**< Loop closed. */ |
|
250 uint8_t signal_detected; /**< Detected signal on RX port. */ |
|
251 } ec_slave_port_link_t; |
228 |
252 |
229 /*****************************************************************************/ |
253 /*****************************************************************************/ |
230 |
254 |
231 /** Slave information. |
255 /** Slave information. |
232 * |
256 * |
240 uint32_t product_code; /**< Product-Code stored on the slave. */ |
264 uint32_t product_code; /**< Product-Code stored on the slave. */ |
241 uint32_t revision_number; /**< Revision-Number stored on the slave. */ |
265 uint32_t revision_number; /**< Revision-Number stored on the slave. */ |
242 uint32_t serial_number; /**< Serial-Number stored on the slave. */ |
266 uint32_t serial_number; /**< Serial-Number stored on the slave. */ |
243 uint16_t alias; /**< The slaves alias if not equal to 0. */ |
267 uint16_t alias; /**< The slaves alias if not equal to 0. */ |
244 int16_t current_on_ebus; /**< Used current in mA. */ |
268 int16_t current_on_ebus; /**< Used current in mA. */ |
|
269 struct { |
|
270 ec_slave_port_desc_t desc; /**< Physical port type. */ |
|
271 ec_slave_port_link_t link; /**< Port link state. */ |
|
272 uint32_t receive_time; /**< Receive time on DC transmission delay |
|
273 measurement. */ |
|
274 uint16_t next_slave; /**< Ring position of next DC slave on that |
|
275 port. */ |
|
276 uint32_t delay_to_next_dc; /**< Delay [ns] to next DC slave. */ |
|
277 } ports[EC_MAX_PORTS]; /**< Port information. */ |
245 uint8_t al_state; /**< Current state of the slave. */ |
278 uint8_t al_state; /**< Current state of the slave. */ |
246 uint8_t error_flag; /**< Error flag for that slave. */ |
279 uint8_t error_flag; /**< Error flag for that slave. */ |
247 uint8_t sync_count; /**< Number of sync managers. */ |
280 uint8_t sync_count; /**< Number of sync managers. */ |
248 uint16_t sdo_count; /**< Number of SDOs. */ |
281 uint16_t sdo_count; /**< Number of SDOs. */ |
249 char name[EC_MAX_STRING_LENGTH]; /**< Name of the slave. */ |
282 char name[EC_MAX_STRING_LENGTH]; /**< Name of the slave. */ |
311 } ec_pdo_entry_info_t; |
344 } ec_pdo_entry_info_t; |
312 |
345 |
313 /*****************************************************************************/ |
346 /*****************************************************************************/ |
314 |
347 |
315 /** PDO configuration information. |
348 /** PDO configuration information. |
316 * |
349 * |
317 * This is the data type of the \a pdos field in ec_sync_info_t. |
350 * This is the data type of the \a pdos field in ec_sync_info_t. |
318 * |
351 * |
319 * \see ecrt_slave_config_pdos(). |
352 * \see ecrt_slave_config_pdos(). |
320 */ |
353 */ |
321 typedef struct { |
354 typedef struct { |
322 uint16_t index; /**< PDO index. */ |
355 uint16_t index; /**< PDO index. */ |
323 unsigned int n_entries; /**< Number of PDO entries in \a entries to map. |
356 unsigned int n_entries; /**< Number of PDO entries in \a entries to map. |
362 uint32_t product_code; /**< Slave product code. */ |
395 uint32_t product_code; /**< Slave product code. */ |
363 uint16_t index; /**< PDO entry index. */ |
396 uint16_t index; /**< PDO entry index. */ |
364 uint8_t subindex; /**< PDO entry subindex. */ |
397 uint8_t subindex; /**< PDO entry subindex. */ |
365 unsigned int *offset; /**< Pointer to a variable to store the PDO entry's |
398 unsigned int *offset; /**< Pointer to a variable to store the PDO entry's |
366 (byte-)offset in the process data. */ |
399 (byte-)offset in the process data. */ |
367 unsigned int *bit_position; /**< Pointer to a variable to store a bit |
400 unsigned int *bit_position; /**< Pointer to a variable to store a bit |
368 position (0-7) within the \a offset. Can be |
401 position (0-7) within the \a offset. Can be |
369 NULL, in which case an error is raised if the |
402 NULL, in which case an error is raised if the |
370 PDO entry does not byte-align. */ |
403 PDO entry does not byte-align. */ |
371 } ec_pdo_entry_reg_t; |
404 } ec_pdo_entry_reg_t; |
372 |
405 |
408 * \return Value of ECRT_VERSION_MAGIC() at EtherCAT master compile time. |
441 * \return Value of ECRT_VERSION_MAGIC() at EtherCAT master compile time. |
409 */ |
442 */ |
410 unsigned int ecrt_version_magic(void); |
443 unsigned int ecrt_version_magic(void); |
411 |
444 |
412 /** Requests an EtherCAT master for realtime operation. |
445 /** Requests an EtherCAT master for realtime operation. |
413 * |
446 * |
414 * Before an application can access an EtherCAT master, it has to reserve one |
447 * Before an application can access an EtherCAT master, it has to reserve one |
415 * for exclusive use. |
448 * for exclusive use. |
416 * |
449 * |
417 * In userspace, this is a convenience function for ecrt_open_master() and |
450 * In userspace, this is a convenience function for ecrt_open_master() and |
418 * ecrt_master_reserve(). |
451 * ecrt_master_reserve(). |
824 /** Sets the application time. |
857 /** Sets the application time. |
825 * |
858 * |
826 * The master has to know the application's time when operating slaves with |
859 * The master has to know the application's time when operating slaves with |
827 * distributed clocks. The time is not incremented by the master itself, so |
860 * distributed clocks. The time is not incremented by the master itself, so |
828 * this method has to be called cyclically. |
861 * this method has to be called cyclically. |
829 * |
862 * |
830 * The time is used when setting the slaves' <tt>System Time Offset</tt> and |
863 * The time is used when setting the slaves' <tt>System Time Offset</tt> and |
831 * <tt>Cyclic Operation Start Time</tt> registers and when synchronizing the |
864 * <tt>Cyclic Operation Start Time</tt> registers and when synchronizing the |
832 * DC reference clock to the application time via |
865 * DC reference clock to the application time via |
833 * ecrt_master_sync_reference_clock(). |
866 * ecrt_master_sync_reference_clock(). |
834 * |
867 * |
835 * The time is defined as nanoseconds from 2000-01-01 00:00. Converting an |
868 * The time is defined as nanoseconds from 2000-01-01 00:00. Converting an |
836 * epoch time can be done with the EC_TIMEVAL2NANO() macro. |
869 * epoch time can be done with the EC_TIMEVAL2NANO() macro. |
837 */ |
870 */ |
838 void ecrt_master_application_time( |
871 void ecrt_master_application_time( |
839 ec_master_t *master, /**< EtherCAT master. */ |
872 ec_master_t *master, /**< EtherCAT master. */ |
938 /** Clear a sync manager's PDO assignment. |
971 /** Clear a sync manager's PDO assignment. |
939 * |
972 * |
940 * This can be called before assigning PDOs via |
973 * This can be called before assigning PDOs via |
941 * ecrt_slave_config_pdo_assign_add(), to clear the default assignment of a |
974 * ecrt_slave_config_pdo_assign_add(), to clear the default assignment of a |
942 * sync manager. |
975 * sync manager. |
943 * |
976 * |
944 * \see ecrt_slave_config_pdos() |
977 * \see ecrt_slave_config_pdos() |
945 */ |
978 */ |
946 void ecrt_slave_config_pdo_assign_clear( |
979 void ecrt_slave_config_pdo_assign_clear( |
947 ec_slave_config_t *sc, /**< Slave configuration. */ |
980 ec_slave_config_t *sc, /**< Slave configuration. */ |
948 uint8_t sync_index /**< Sync manager index. Must be less |
981 uint8_t sync_index /**< Sync manager index. Must be less |
992 * \code |
1025 * \code |
993 * ec_pdo_entry_info_t el3162_channel1[] = { |
1026 * ec_pdo_entry_info_t el3162_channel1[] = { |
994 * {0x3101, 1, 8}, // status |
1027 * {0x3101, 1, 8}, // status |
995 * {0x3101, 2, 16} // value |
1028 * {0x3101, 2, 16} // value |
996 * }; |
1029 * }; |
997 * |
1030 * |
998 * ec_pdo_entry_info_t el3162_channel2[] = { |
1031 * ec_pdo_entry_info_t el3162_channel2[] = { |
999 * {0x3102, 1, 8}, // status |
1032 * {0x3102, 1, 8}, // status |
1000 * {0x3102, 2, 16} // value |
1033 * {0x3102, 2, 16} // value |
1001 * }; |
1034 * }; |
1002 * |
1035 * |
1003 * ec_pdo_info_t el3162_pdos[] = { |
1036 * ec_pdo_info_t el3162_pdos[] = { |
1004 * {0x1A00, 2, el3162_channel1}, |
1037 * {0x1A00, 2, el3162_channel1}, |
1005 * {0x1A01, 2, el3162_channel2} |
1038 * {0x1A01, 2, el3162_channel2} |
1006 * }; |
1039 * }; |
1007 * |
1040 * |
1008 * ec_sync_info_t el3162_syncs[] = { |
1041 * ec_sync_info_t el3162_syncs[] = { |
1009 * {2, EC_DIR_OUTPUT}, |
1042 * {2, EC_DIR_OUTPUT}, |
1010 * {3, EC_DIR_INPUT, 2, el3162_pdos}, |
1043 * {3, EC_DIR_INPUT, 2, el3162_pdos}, |
1011 * {0xff} |
1044 * {0xff} |
1012 * }; |
1045 * }; |
1013 * |
1046 * |
1014 * if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_syncs)) { |
1047 * if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_syncs)) { |
1015 * // handle error |
1048 * // handle error |
1016 * } |
1049 * } |
1017 * \endcode |
1050 * \endcode |
1018 * |
1051 * |
1019 * The next example shows, how to configure the PDO assignment only. The |
1052 * The next example shows, how to configure the PDO assignment only. The |
1020 * entries for each assigned PDO are taken from the PDO's default mapping. |
1053 * entries for each assigned PDO are taken from the PDO's default mapping. |
1021 * Please note, that PDO entry registration will fail, if the PDO |
1054 * Please note, that PDO entry registration will fail, if the PDO |
1022 * configuration is left empty and the slave is offline. |
1055 * configuration is left empty and the slave is offline. |
1023 * |
1056 * |
1024 * \code |
1057 * \code |
1025 * ec_pdo_info_t pdos[] = { |
1058 * ec_pdo_info_t pdos[] = { |
1026 * {0x1600}, // Channel 1 |
1059 * {0x1600}, // Channel 1 |
1027 * {0x1601} // Channel 2 |
1060 * {0x1601} // Channel 2 |
1028 * }; |
1061 * }; |
1029 * |
1062 * |
1030 * ec_sync_info_t syncs[] = { |
1063 * ec_sync_info_t syncs[] = { |
1031 * {3, EC_DIR_INPUT, 2, pdos}, |
1064 * {3, EC_DIR_INPUT, 2, pdos}, |
1032 * }; |
1065 * }; |
1033 * |
1066 * |
1034 * if (ecrt_slave_config_pdos(slave_config_ana_in, 1, syncs)) { |
1067 * if (ecrt_slave_config_pdos(slave_config_ana_in, 1, syncs)) { |
1035 * // handle error |
1068 * // handle error |
1036 * } |
1069 * } |
1037 * \endcode |
1070 * \endcode |
1038 * |
1071 * |
1070 int ecrt_slave_config_reg_pdo_entry( |
1103 int ecrt_slave_config_reg_pdo_entry( |
1071 ec_slave_config_t *sc, /**< Slave configuration. */ |
1104 ec_slave_config_t *sc, /**< Slave configuration. */ |
1072 uint16_t entry_index, /**< Index of the PDO entry to register. */ |
1105 uint16_t entry_index, /**< Index of the PDO entry to register. */ |
1073 uint8_t entry_subindex, /**< Subindex of the PDO entry to register. */ |
1106 uint8_t entry_subindex, /**< Subindex of the PDO entry to register. */ |
1074 ec_domain_t *domain, /**< Domain. */ |
1107 ec_domain_t *domain, /**< Domain. */ |
1075 unsigned int *bit_position /**< Optional address if bit addressing |
1108 unsigned int *bit_position /**< Optional address if bit addressing |
1076 is desired */ |
1109 is desired */ |
1077 ); |
1110 ); |
1078 |
1111 |
1079 /** Configure distributed clocks. |
1112 /** Configure distributed clocks. |
1080 * |
1113 * |