36 * |
36 * |
37 * EtherCAT interface for realtime applications. This interface is designed |
37 * EtherCAT interface for realtime applications. This interface is designed |
38 * for realtime modules that want to use EtherCAT. There are functions to |
38 * for realtime modules that want to use EtherCAT. There are functions to |
39 * request a master, to map process data, to communicate with slaves via CoE |
39 * request a master, to map process data, to communicate with slaves via CoE |
40 * and to configure and activate the bus. |
40 * and to configure and activate the bus. |
|
41 * |
|
42 * Changes in version 1.5.2: |
|
43 * |
|
44 * - Added redundancy_active flag to ec_domain_state_t. |
|
45 * - Added ecrt_master_link_state() method and ec_master_link_state_t to query |
|
46 * the state of a redundant link. |
|
47 * - Added the EC_HAVE_REDUNDANCY define, to check, if the interface contains |
|
48 * redundancy features. |
|
49 * - Added ecrt_sdo_request_index() to change SDO index and subindex after |
|
50 * handler creation. |
|
51 * - Added interface for retrieving CoE emergency messages, i. e. |
|
52 * ecrt_slave_config_emerg_size(), ecrt_slave_config_emerg_pop(), |
|
53 * ecrt_slave_config_emerg_clear(), ecrt_slave_config_emerg_overruns() and |
|
54 * the defines EC_HAVE_EMERGENCY and EC_COE_EMERGENCY_MSG_SIZE. |
|
55 * - Added interface for direct EtherCAT register access: Added data type |
|
56 * ec_reg_request_t and methods ecrt_slave_config_create_reg_request(), |
|
57 * ecrt_reg_request_data(), ecrt_reg_request_state(), |
|
58 * ecrt_reg_request_write(), ecrt_reg_request_read() and the feature flag |
|
59 * EC_HAVE_REG_ACCESS. |
|
60 * - Added method to select the reference clock, |
|
61 * ecrt_master_select_reference_clock() and the feature flag |
|
62 * EC_HAVE_SELECT_REF_CLOCK to check, if the method is available. |
|
63 * - Added method to get the reference clock time, |
|
64 * ecrt_master_reference_clock_time() and the feature flag |
|
65 * EC_HAVE_REF_CLOCK_TIME to have the possibility to synchronize the master |
|
66 * clock to the reference clock. |
|
67 * - Changed the data types of the shift times in ecrt_slave_config_dc() to |
|
68 * int32_t to correctly display negative shift times. |
|
69 * - Added ecrt_slave_config_reg_pdo_entry_pos() and the feature flag |
|
70 * EC_HAVE_REG_BY_POS for registering PDO entries with non-unique indices |
|
71 * via their positions in the mapping. |
41 * |
72 * |
42 * Changes in version 1.5: |
73 * Changes in version 1.5: |
43 * |
74 * |
44 * - Added the distributed clocks feature and the respective method |
75 * - Added the distributed clocks feature and the respective method |
45 * ecrt_slave_config_dc() to configure a slave for cyclic operation, and |
76 * ecrt_slave_config_dc() to configure a slave for cyclic operation, and |
47 * ecrt_master_sync_slave_clocks() for offset and drift compensation. The |
78 * ecrt_master_sync_slave_clocks() for offset and drift compensation. The |
48 * EC_TIMEVAL2NANO() macro can be used for epoch time conversion, while the |
79 * EC_TIMEVAL2NANO() macro can be used for epoch time conversion, while the |
49 * ecrt_master_sync_monitor_queue() and ecrt_master_sync_monitor_process() |
80 * ecrt_master_sync_monitor_queue() and ecrt_master_sync_monitor_process() |
50 * methods can be used to monitor the synchrony. |
81 * methods can be used to monitor the synchrony. |
51 * - Improved the callback mechanism. ecrt_master_callbacks() now takes two |
82 * - Improved the callback mechanism. ecrt_master_callbacks() now takes two |
52 * callback functions for locking and unlocking the fsm datagram queue. |
83 * callback functions for sending and receiving datagrams. |
|
84 * ecrt_master_send_ext() is used to execute the sending of non-application |
|
85 * datagrams. |
53 * - Added watchdog configuration (method ecrt_slave_config_watchdog(), |
86 * - Added watchdog configuration (method ecrt_slave_config_watchdog(), |
54 * #ec_watchdog_mode_t, \a watchdog_mode parameter in ec_sync_info_t and |
87 * #ec_watchdog_mode_t, \a watchdog_mode parameter in ec_sync_info_t and |
55 * ecrt_slave_config_sync_manager()). |
88 * ecrt_slave_config_sync_manager()). |
56 * - Added ecrt_slave_config_complete_sdo() method to download an SDO during |
89 * - Added ecrt_slave_config_complete_sdo() method to download an SDO during |
57 * configuration via CompleteAccess. |
90 * configuration via CompleteAccess. |
76 * - Added 64-bit data access macros. |
109 * - Added 64-bit data access macros. |
77 * - Added ecrt_slave_config_idn() method for storing SoE IDN configurations, |
110 * - Added ecrt_slave_config_idn() method for storing SoE IDN configurations, |
78 * and ecrt_master_read_idn() and ecrt_master_write_idn() to read/write IDNs |
111 * and ecrt_master_read_idn() and ecrt_master_write_idn() to read/write IDNs |
79 * ad-hoc via the user-space library. |
112 * ad-hoc via the user-space library. |
80 * - Added ecrt_master_reset() to initiate retrying to configure slaves. |
113 * - Added ecrt_master_reset() to initiate retrying to configure slaves. |
81 * - Added support for overlapping PDOs which allows inputs to use the same |
|
82 * space as outputs on the frame. This reduces the frame length. |
|
83 * |
114 * |
84 * @{ |
115 * @{ |
85 */ |
116 */ |
86 |
117 |
87 /*****************************************************************************/ |
118 /*****************************************************************************/ |
117 |
148 |
118 /** EtherCAT realtime interface version word. |
149 /** EtherCAT realtime interface version word. |
119 */ |
150 */ |
120 #define ECRT_VERSION_MAGIC ECRT_VERSION(ECRT_VER_MAJOR, ECRT_VER_MINOR) |
151 #define ECRT_VERSION_MAGIC ECRT_VERSION(ECRT_VER_MAJOR, ECRT_VER_MINOR) |
121 |
152 |
|
153 /****************************************************************************** |
|
154 * Feature flags |
|
155 *****************************************************************************/ |
|
156 |
|
157 /** Defined, if the redundancy features are available. |
|
158 * |
|
159 * I. e. if the \a redundancy_active flag in ec_domain_state_t and the |
|
160 * ecrt_master_link_state() method are available. |
|
161 */ |
|
162 #define EC_HAVE_REDUNDANCY |
|
163 |
|
164 /** Defined, if the CoE emergency ring feature is available. |
|
165 * |
|
166 * I. e. if the ecrt_slave_config_emerg_*() methods are available. |
|
167 */ |
|
168 #define EC_HAVE_EMERGENCY |
|
169 |
|
170 /** Defined, if the register access interface is available. |
|
171 * |
|
172 * I. e. if the methods ecrt_slave_config_create_reg_request(), |
|
173 * ecrt_reg_request_data(), ecrt_reg_request_state(), ecrt_reg_request_write() |
|
174 * and ecrt_reg_request_read() are available. |
|
175 */ |
|
176 #define EC_HAVE_REG_ACCESS |
|
177 |
|
178 /** Defined if the method ecrt_master_select_reference_clock() is available. |
|
179 */ |
|
180 #define EC_HAVE_SELECT_REF_CLOCK |
|
181 |
|
182 /** Defined if the method ecrt_master_reference_clock_time() is available. |
|
183 */ |
|
184 #define EC_HAVE_REF_CLOCK_TIME |
|
185 |
|
186 /** Defined if the method ecrt_slave_config_reg_pdo_entry_pos() is available. |
|
187 */ |
|
188 #define EC_HAVE_REG_BY_POS |
|
189 |
122 /*****************************************************************************/ |
190 /*****************************************************************************/ |
123 |
191 |
124 /** End of list marker. |
192 /** End of list marker. |
125 * |
193 * |
126 * This can be used with ecrt_slave_config_pdos(). |
194 * This can be used with ecrt_slave_config_pdos(). |
148 * |
216 * |
149 * \param TV struct timeval containing epoch time. |
217 * \param TV struct timeval containing epoch time. |
150 */ |
218 */ |
151 #define EC_TIMEVAL2NANO(TV) \ |
219 #define EC_TIMEVAL2NANO(TV) \ |
152 (((TV).tv_sec - 946684800ULL) * 1000000000ULL + (TV).tv_usec * 1000ULL) |
220 (((TV).tv_sec - 946684800ULL) * 1000000000ULL + (TV).tv_usec * 1000ULL) |
|
221 |
|
222 /** Size of a CoE emergency message in byte. |
|
223 * |
|
224 * \see ecrt_slave_config_emerg_pop(). |
|
225 */ |
|
226 #define EC_COE_EMERGENCY_MSG_SIZE 8 |
153 |
227 |
154 /****************************************************************************** |
228 /****************************************************************************** |
155 * Data types |
229 * Data types |
156 *****************************************************************************/ |
230 *****************************************************************************/ |
157 |
231 |
168 typedef struct ec_sdo_request ec_sdo_request_t; /**< \see ec_sdo_request. */ |
242 typedef struct ec_sdo_request ec_sdo_request_t; /**< \see ec_sdo_request. */ |
169 |
243 |
170 struct ec_voe_handler; |
244 struct ec_voe_handler; |
171 typedef struct ec_voe_handler ec_voe_handler_t; /**< \see ec_voe_handler. */ |
245 typedef struct ec_voe_handler ec_voe_handler_t; /**< \see ec_voe_handler. */ |
172 |
246 |
|
247 struct ec_reg_request; |
|
248 typedef struct ec_reg_request ec_reg_request_t; /**< \see ec_sdo_request. */ |
|
249 |
173 /*****************************************************************************/ |
250 /*****************************************************************************/ |
174 |
251 |
175 /** Master state. |
252 /** Master state. |
176 * |
253 * |
177 * This is used for the output parameter of ecrt_master_state() and |
254 * This is used for the output parameter of ecrt_master_state(). |
178 * ecrt_master_configured_slaves_state(). |
|
179 * |
255 * |
180 * \see ecrt_master_state(). |
256 * \see ecrt_master_state(). |
181 * \see ecrt_master_configured_slaves_state(). |
|
182 */ |
257 */ |
183 typedef struct { |
258 typedef struct { |
184 unsigned int slaves_responding; /**< Number of slaves in the bus. */ |
259 unsigned int slaves_responding; /**< Sum of responding slaves on all |
|
260 Ethernet devices. */ |
185 unsigned int al_states : 4; /**< Application-layer states of all slaves. |
261 unsigned int al_states : 4; /**< Application-layer states of all slaves. |
186 The states are coded in the lower 4 bits. |
262 The states are coded in the lower 4 bits. |
187 If a bit is set, it means that at least one |
263 If a bit is set, it means that at least one |
188 slave in the bus is in the corresponding |
264 slave in the bus is in the corresponding |
189 state: |
265 state: |
190 - Bit 0: \a INIT |
266 - Bit 0: \a INIT |
191 - Bit 1: \a PREOP |
267 - Bit 1: \a PREOP |
192 - Bit 2: \a SAFEOP |
268 - Bit 2: \a SAFEOP |
193 - Bit 3: \a OP */ |
269 - Bit 3: \a OP */ |
194 unsigned int link_up : 1; /**< \a true, if the network link is up. */ |
270 unsigned int link_up : 1; /**< \a true, if at least one Ethernet link is |
|
271 up. */ |
195 } ec_master_state_t; |
272 } ec_master_state_t; |
|
273 |
|
274 /*****************************************************************************/ |
|
275 |
|
276 /** Redundant link state. |
|
277 * |
|
278 * This is used for the output parameter of ecrt_master_link_state(). |
|
279 * |
|
280 * \see ecrt_master_link_state(). |
|
281 */ |
|
282 typedef struct { |
|
283 unsigned int slaves_responding; /**< Sum of responding slaves on the given |
|
284 link. */ |
|
285 unsigned int al_states : 4; /**< Application-layer states of the slaves on |
|
286 the given link. The states are coded in the |
|
287 lower 4 bits. If a bit is set, it means |
|
288 that at least one slave in the bus is in the |
|
289 corresponding state: |
|
290 - Bit 0: \a INIT |
|
291 - Bit 1: \a PREOP |
|
292 - Bit 2: \a SAFEOP |
|
293 - Bit 3: \a OP */ |
|
294 unsigned int link_up : 1; /**< \a true, if the given Ethernet link is up. |
|
295 */ |
|
296 } ec_master_link_state_t; |
196 |
297 |
197 /*****************************************************************************/ |
298 /*****************************************************************************/ |
198 |
299 |
199 /** Slave configuration state. |
300 /** Slave configuration state. |
200 * |
301 * |
236 /** EtherCAT slave port descriptor. |
337 /** EtherCAT slave port descriptor. |
237 */ |
338 */ |
238 typedef enum { |
339 typedef enum { |
239 EC_PORT_NOT_IMPLEMENTED, /**< Port is not implemented. */ |
340 EC_PORT_NOT_IMPLEMENTED, /**< Port is not implemented. */ |
240 EC_PORT_NOT_CONFIGURED, /**< Port is not configured. */ |
341 EC_PORT_NOT_CONFIGURED, /**< Port is not configured. */ |
241 EC_PORT_EBUS, /**< Port is an e-bus. */ |
342 EC_PORT_EBUS, /**< Port is an E-Bus. */ |
242 EC_PORT_MII /**< Port is a mii. */ |
343 EC_PORT_MII /**< Port is a MII. */ |
243 } ec_slave_port_desc_t; |
344 } ec_slave_port_desc_t; |
244 |
345 |
245 /*****************************************************************************/ |
346 /*****************************************************************************/ |
246 |
347 |
247 /** EtherCAT slave port information. |
348 /** EtherCAT slave port information. |
484 |
586 |
485 /** Releases a requested EtherCAT master. |
587 /** Releases a requested EtherCAT master. |
486 * |
588 * |
487 * After use, a master it has to be released to make it available for other |
589 * After use, a master it has to be released to make it available for other |
488 * applications. |
590 * applications. |
|
591 * |
|
592 * This method frees all created data structures. It should not be called in |
|
593 * realtime context. |
|
594 * |
|
595 * If the master was activated, ecrt_master_deactivate() is called internally. |
489 */ |
596 */ |
490 void ecrt_release_master( |
597 void ecrt_release_master( |
491 ec_master_t *master /**< EtherCAT master */ |
598 ec_master_t *master /**< EtherCAT master */ |
492 ); |
599 ); |
493 |
|
494 #ifdef __KERNEL__ |
|
495 |
|
496 /** Attach to a running master |
|
497 * |
|
498 * This function returns the master handle for the RTDM-Interface |
|
499 * |
|
500 * \return Pointer to the opened master, otherwise \a NULL. |
|
501 */ |
|
502 ec_master_t *ecrt_attach_master( |
|
503 unsigned int master_index /**< Index of the master to request. */ |
|
504 ); |
|
505 |
|
506 #endif // #ifdef __KERNEL__ |
|
507 |
600 |
508 /****************************************************************************** |
601 /****************************************************************************** |
509 * Master methods |
602 * Master methods |
510 *****************************************************************************/ |
603 *****************************************************************************/ |
511 |
604 |
527 |
619 |
528 #ifdef __KERNEL__ |
620 #ifdef __KERNEL__ |
529 |
621 |
530 /** Sets the locking callbacks. |
622 /** Sets the locking callbacks. |
531 * |
623 * |
532 * For concurrent master access, the application has to provide a locking |
624 * For concurrent master access, i. e. if other instances than the application |
533 * mechanism. The method takes two function pointers and a data value as |
625 * want to send and receive datagrams on the bus, the application has to |
534 * its parameters. |
626 * provide a callback mechanism. This method takes two function pointers as |
535 * The arbitrary \a cb_data value will be passed as argument on every callback. |
627 * its parameters. Asynchronous master access (like EoE processing) is only |
536 * |
628 * possible if the callbacks have been set. |
|
629 * |
|
630 * The task of the send callback (\a send_cb) is to decide, if the bus is |
|
631 * currently accessible and whether or not to call the ecrt_master_send_ext() |
|
632 * method. |
|
633 * |
|
634 * The task of the receive callback (\a receive_cb) is to decide, if a call to |
|
635 * ecrt_master_receive() is allowed and to execute it respectively. |
|
636 * |
|
637 * \attention This method has to be called before ecrt_master_activate(). |
537 */ |
638 */ |
538 void ecrt_master_callbacks( |
639 void ecrt_master_callbacks( |
539 ec_master_t *master, /**< EtherCAT master */ |
640 ec_master_t *master, /**< EtherCAT master */ |
540 void (*lock_cb)(void *), /**< Lock function. */ |
641 void (*send_cb)(void *), /**< Datagram sending callback. */ |
541 void (*unlock_cb)(void *), /**< Unlock function. */ |
642 void (*receive_cb)(void *), /**< Receive callback. */ |
542 void *cb_data /**< Arbitrary user data. */ |
643 void *cb_data /**< Arbitrary pointer passed to the callback functions. |
543 ); |
644 */ |
544 |
645 ); |
545 /** Returns domain structure pointer |
|
546 * |
|
547 * \fixme The application knows the domain pointers! |
|
548 * |
|
549 * This functions return the domain structure pointer for usage inside the |
|
550 * RTDM-Interface. |
|
551 * |
|
552 * \return Pointer to the domain on success, else NULL. |
|
553 */ |
|
554 ec_domain_t *ecrt_master_find_domain( |
|
555 ec_master_t *master, |
|
556 unsigned int index); |
|
557 |
646 |
558 #endif /* __KERNEL__ */ |
647 #endif /* __KERNEL__ */ |
559 |
|
560 #ifndef __KERNEL__ |
|
561 |
|
562 /** Return the domain index of a given domain strucure |
|
563 * |
|
564 * Return the domain index of a given domain strucure. Usage inside of the |
|
565 * RTDM Interface |
|
566 * |
|
567 * \return Index of the domain strucure |
|
568 * |
|
569 */ |
|
570 unsigned int ecrt_domain_index( |
|
571 ec_domain_t *domain |
|
572 ); |
|
573 |
|
574 #endif // #ifndef __KERNEL__ |
|
575 |
648 |
576 /** Creates a new process data domain. |
649 /** Creates a new process data domain. |
577 * |
650 * |
578 * For process data exchange, at least one process data domain is needed. |
651 * For process data exchange, at least one process data domain is needed. |
579 * This method creates a new process data domain and returns a pointer to the |
652 * This method creates a new process data domain and returns a pointer to the |
580 * new domain object. This object can be used for registering PDOs and |
653 * new domain object. This object can be used for registering PDOs and |
581 * exchanging them in cyclic operation. |
654 * exchanging them in cyclic operation. |
|
655 * |
|
656 * This method allocates memory and should be called in non-realtime context |
|
657 * before ecrt_master_activate(). |
582 * |
658 * |
583 * \return Pointer to the new domain on success, else NULL. |
659 * \return Pointer to the new domain on success, else NULL. |
584 */ |
660 */ |
585 ec_domain_t *ecrt_master_create_domain( |
661 ec_domain_t *ecrt_master_create_domain( |
586 ec_master_t *master /**< EtherCAT master. */ |
662 ec_master_t *master /**< EtherCAT master. */ |
608 * |
684 * |
609 * If different slave configurations are pointing to the same slave during bus |
685 * If different slave configurations are pointing to the same slave during bus |
610 * configuration, a warning is raised and only the first configuration is |
686 * configuration, a warning is raised and only the first configuration is |
611 * applied. |
687 * applied. |
612 * |
688 * |
|
689 * This method allocates memory and should be called in non-realtime context |
|
690 * before ecrt_master_activate(). |
|
691 * |
613 * \retval >0 Pointer to the slave configuration structure. |
692 * \retval >0 Pointer to the slave configuration structure. |
614 * \retval NULL in the error case. |
693 * \retval NULL in the error case. |
615 */ |
694 */ |
616 ec_slave_config_t *ecrt_master_slave_config( |
695 ec_slave_config_t *ecrt_master_slave_config( |
617 ec_master_t *master, /**< EtherCAT master */ |
696 ec_master_t *master, /**< EtherCAT master */ |
618 uint16_t alias, /**< Slave alias. */ |
697 uint16_t alias, /**< Slave alias. */ |
619 uint16_t position, /**< Slave position. */ |
698 uint16_t position, /**< Slave position. */ |
620 uint32_t vendor_id, /**< Expected vendor ID. */ |
699 uint32_t vendor_id, /**< Expected vendor ID. */ |
621 uint32_t product_code /**< Expected product code. */ |
700 uint32_t product_code /**< Expected product code. */ |
|
701 ); |
|
702 |
|
703 /** Selects the reference clock for distributed clocks. |
|
704 * |
|
705 * If this method is not called for a certain master, or if the slave |
|
706 * configuration pointer is NULL, then the first slave with DC functionality |
|
707 * will provide the reference clock. |
|
708 * |
|
709 * \return 0 on success, otherwise negative error code. |
|
710 */ |
|
711 int ecrt_master_select_reference_clock( |
|
712 ec_master_t *master, /**< EtherCAT master. */ |
|
713 ec_slave_config_t *sc /**< Slave config of the slave to use as the |
|
714 * reference slave (or NULL). */ |
622 ); |
715 ); |
623 |
716 |
624 /** Obtains master information. |
717 /** Obtains master information. |
625 * |
718 * |
626 * No memory is allocated on the heap in |
719 * No memory is allocated on the heap in |
770 * |
863 * |
771 * Starts writing an IDN and blocks until the request was processed, or an |
864 * Starts writing an IDN and blocks until the request was processed, or an |
772 * error occurred. |
865 * error occurred. |
773 * |
866 * |
774 * \retval 0 Success. |
867 * \retval 0 Success. |
775 * \retval -1 An error occured. |
868 * \retval <0 Error code. |
776 */ |
869 */ |
777 int ecrt_master_write_idn( |
870 int ecrt_master_write_idn( |
778 ec_master_t *master, /**< EtherCAT master. */ |
871 ec_master_t *master, /**< EtherCAT master. */ |
779 uint16_t slave_position, /**< Slave position. */ |
872 uint16_t slave_position, /**< Slave position. */ |
780 uint8_t drive_no, /**< Drive number. */ |
873 uint8_t drive_no, /**< Drive number. */ |
789 * |
882 * |
790 * Starts reading an IDN and blocks until the request was processed, or an |
883 * Starts reading an IDN and blocks until the request was processed, or an |
791 * error occurred. |
884 * error occurred. |
792 * |
885 * |
793 * \retval 0 Success. |
886 * \retval 0 Success. |
794 * \retval -1 An error occured. |
887 * \retval <0 Error code. |
795 */ |
888 */ |
796 int ecrt_master_read_idn( |
889 int ecrt_master_read_idn( |
797 ec_master_t *master, /**< EtherCAT master. */ |
890 ec_master_t *master, /**< EtherCAT master. */ |
798 uint16_t slave_position, /**< Slave position. */ |
891 uint16_t slave_position, /**< Slave position. */ |
799 uint8_t drive_no, /**< Drive number. */ |
892 uint8_t drive_no, /**< Drive number. */ |
816 * |
909 * |
817 * \attention After this function has been called, the realtime application is |
910 * \attention After this function has been called, the realtime application is |
818 * in charge of cyclically calling ecrt_master_send() and |
911 * in charge of cyclically calling ecrt_master_send() and |
819 * ecrt_master_receive() to ensure bus communication. Before calling this |
912 * ecrt_master_receive() to ensure bus communication. Before calling this |
820 * function, the master thread is responsible for that, so these functions may |
913 * function, the master thread is responsible for that, so these functions may |
821 * not be called! |
914 * not be called! The method itself allocates memory and should not be called |
|
915 * in realtime context. |
822 * |
916 * |
823 * \return 0 in case of success, else < 0 |
917 * \return 0 in case of success, else < 0 |
824 */ |
918 */ |
825 int ecrt_master_activate( |
919 int ecrt_master_activate( |
826 ec_master_t *master /**< EtherCAT master. */ |
920 ec_master_t *master /**< EtherCAT master. */ |
831 * Removes the bus configuration. All objects created by |
925 * Removes the bus configuration. All objects created by |
832 * ecrt_master_create_domain(), ecrt_master_slave_config(), ecrt_domain_data() |
926 * ecrt_master_create_domain(), ecrt_master_slave_config(), ecrt_domain_data() |
833 * ecrt_slave_config_create_sdo_request() and |
927 * ecrt_slave_config_create_sdo_request() and |
834 * ecrt_slave_config_create_voe_handler() are freed, so pointers to them |
928 * ecrt_slave_config_create_voe_handler() are freed, so pointers to them |
835 * become invalid. |
929 * become invalid. |
|
930 * |
|
931 * This method should not be called in realtime context. |
836 */ |
932 */ |
837 void ecrt_master_deactivate( |
933 void ecrt_master_deactivate( |
838 ec_master_t *master /**< EtherCAT master. */ |
934 ec_master_t *master /**< EtherCAT master. */ |
839 ); |
935 ); |
840 |
936 |
841 /** Set interval between calls to ecrt_master_send |
937 /** Set interval between calls to ecrt_master_send(). |
842 * |
938 * |
|
939 * This information helps the master to decide, how much data can be appended |
|
940 * to a frame by the master state machine. When the master is configured with |
|
941 * --enable-hrtimers, this is used to calculate the scheduling of the master |
|
942 * thread. |
|
943 * |
|
944 * \retval 0 on success. |
|
945 * \retval <0 Error code. |
843 */ |
946 */ |
844 int ecrt_master_set_send_interval( |
947 int ecrt_master_set_send_interval( |
845 ec_master_t *master, /**< EtherCAT master. */ |
948 ec_master_t *master, /**< EtherCAT master. */ |
846 size_t send_interval /**< Send interval in us */ |
949 size_t send_interval /**< Send interval in us */ |
847 ); |
950 ); |
870 */ |
973 */ |
871 void ecrt_master_receive( |
974 void ecrt_master_receive( |
872 ec_master_t *master /**< EtherCAT master. */ |
975 ec_master_t *master /**< EtherCAT master. */ |
873 ); |
976 ); |
874 |
977 |
|
978 /** Sends non-application datagrams. |
|
979 * |
|
980 * This method has to be called in the send callback function passed via |
|
981 * ecrt_master_callbacks() to allow the sending of non-application datagrams. |
|
982 */ |
|
983 void ecrt_master_send_ext( |
|
984 ec_master_t *master /**< EtherCAT master. */ |
|
985 ); |
|
986 |
875 /** Reads the current master state. |
987 /** Reads the current master state. |
876 * |
988 * |
877 * Stores the master state information in the given \a state structure. |
989 * Stores the master state information in the given \a state structure. |
|
990 * |
|
991 * This method returns a global state. For the link-specific states in a |
|
992 * redundant bus topology, use the ecrt_master_link_state() method. |
878 */ |
993 */ |
879 void ecrt_master_state( |
994 void ecrt_master_state( |
880 const ec_master_t *master, /**< EtherCAT master. */ |
995 const ec_master_t *master, /**< EtherCAT master. */ |
881 ec_master_state_t *state /**< Structure to store the information. */ |
996 ec_master_state_t *state /**< Structure to store the information. */ |
882 ); |
997 ); |
883 |
998 |
884 /** Reads the current master state and the al_state of all configured slaves. |
999 /** Reads the current state of a redundant link. |
885 * |
1000 * |
886 * Use this function instead of ecrt_master_state() if there are unused slaves |
1001 * Stores the link state information in the given \a state structure. |
887 * on the bus. Stores the master state information in the given \a state |
1002 * |
888 * structure. |
1003 * \return Zero on success, otherwise negative error code. |
889 * |
1004 */ |
890 * \see ecrt_master_state() |
1005 int ecrt_master_link_state( |
891 */ |
|
892 void ecrt_master_configured_slaves_state( |
|
893 const ec_master_t *master, /**< EtherCAT master. */ |
1006 const ec_master_t *master, /**< EtherCAT master. */ |
894 ec_master_state_t *state /**< Structure to store the information. */ |
1007 unsigned int dev_idx, /**< Index of the device (0 = main device, 1 = |
|
1008 first backup device, ...). */ |
|
1009 ec_master_link_state_t *state /**< Structure to store the information. |
|
1010 */ |
895 ); |
1011 ); |
896 |
1012 |
897 /** Sets the application time. |
1013 /** Sets the application time. |
898 * |
1014 * |
899 * The master has to know the application's time when operating slaves with |
1015 * The master has to know the application's time when operating slaves with |
900 * distributed clocks. The time is not incremented by the master itself, so |
1016 * distributed clocks. The time is not incremented by the master itself, so |
901 * this method has to be called cyclically. |
1017 * this method has to be called cyclically. |
|
1018 * |
|
1019 * \attention The first call of this method is used to calculate the phase |
|
1020 * delay for the slaves' SYNC0/1 interrupts. Either the method has to be |
|
1021 * called during the realtime cycle *only*, or the first time submitted must |
|
1022 * be in-phase with the realtime cycle. Otherwise synchronisation problems can |
|
1023 * occur. |
902 * |
1024 * |
903 * The time is used when setting the slaves' <tt>System Time Offset</tt> and |
1025 * The time is used when setting the slaves' <tt>System Time Offset</tt> and |
904 * <tt>Cyclic Operation Start Time</tt> registers and when synchronizing the |
1026 * <tt>Cyclic Operation Start Time</tt> registers and when synchronizing the |
905 * DC reference clock to the application time via |
1027 * DC reference clock to the application time via |
906 * ecrt_master_sync_reference_clock(). |
1028 * ecrt_master_sync_reference_clock(). |
928 */ |
1050 */ |
929 void ecrt_master_sync_slave_clocks( |
1051 void ecrt_master_sync_slave_clocks( |
930 ec_master_t *master /**< EtherCAT master. */ |
1052 ec_master_t *master /**< EtherCAT master. */ |
931 ); |
1053 ); |
932 |
1054 |
933 /** Queues the DC synchonity monitoring datagram for sending. |
1055 /** Get the lower 32 bit of the reference clock system time. |
|
1056 * |
|
1057 * This method can be used to synchronize the master to the reference clock. |
|
1058 * |
|
1059 * The reference clock system time is queried via the |
|
1060 * ecrt_master_sync_slave_clocks() method, that reads the system time of the |
|
1061 * reference clock and writes it to the slave clocks (so be sure to call it |
|
1062 * cyclically to get valid data). |
|
1063 * |
|
1064 * \attention The returned time is the system time of the reference clock |
|
1065 * minus the transmission delay of the reference clock. |
|
1066 * |
|
1067 * \retval 0 success, system time was written into \a time. |
|
1068 * \retval -ENXIO No reference clock found. |
|
1069 * \retval -EIO Slave synchronization datagram was not received. |
|
1070 */ |
|
1071 int ecrt_master_reference_clock_time( |
|
1072 ec_master_t *master, /**< EtherCAT master. */ |
|
1073 uint32_t *time /**< Pointer to store the queried system time. */ |
|
1074 ); |
|
1075 |
|
1076 /** Queues the DC synchrony monitoring datagram for sending. |
934 * |
1077 * |
935 * The datagram broadcast-reads all "System time difference" registers (\a |
1078 * The datagram broadcast-reads all "System time difference" registers (\a |
936 * 0x092c) to get an upper estiomation of the DC synchony. The result can be |
1079 * 0x092c) to get an upper estimation of the DC synchrony. The result can be |
937 * checked with the ecrt_master_sync_monitor_process() method. |
1080 * checked with the ecrt_master_sync_monitor_process() method. |
938 */ |
1081 */ |
939 void ecrt_master_sync_monitor_queue( |
1082 void ecrt_master_sync_monitor_queue( |
940 ec_master_t *master /**< EtherCAT master. */ |
1083 ec_master_t *master /**< EtherCAT master. */ |
941 ); |
1084 ); |
942 |
1085 |
943 /** Processes the DC synchonity monitoring datagram. |
1086 /** Processes the DC synchrony monitoring datagram. |
944 * |
1087 * |
945 * If the sync monitoring datagram was sent before with |
1088 * If the sync monitoring datagram was sent before with |
946 * ecrt_master_sync_monitor_queue(), the result can be queried with this |
1089 * ecrt_master_sync_monitor_queue(), the result can be queried with this |
947 * method. |
1090 * method. |
948 * |
1091 * |
949 * \return Upper estination of the maximum time difference in ns. |
1092 * \return Upper estimation of the maximum time difference in ns. |
950 */ |
1093 */ |
951 uint32_t ecrt_master_sync_monitor_process( |
1094 uint32_t ecrt_master_sync_monitor_process( |
952 ec_master_t *master /**< EtherCAT master. */ |
1095 ec_master_t *master /**< EtherCAT master. */ |
953 ); |
1096 ); |
954 |
1097 |
969 |
1112 |
970 /** Configure a sync manager. |
1113 /** Configure a sync manager. |
971 * |
1114 * |
972 * Sets the direction of a sync manager. This overrides the direction bits |
1115 * Sets the direction of a sync manager. This overrides the direction bits |
973 * from the default control register from SII. |
1116 * from the default control register from SII. |
|
1117 * |
|
1118 * This method has to be called in non-realtime context before |
|
1119 * ecrt_master_activate(). |
974 * |
1120 * |
975 * \return zero on success, else non-zero |
1121 * \return zero on success, else non-zero |
976 */ |
1122 */ |
977 int ecrt_slave_config_sync_manager( |
1123 int ecrt_slave_config_sync_manager( |
978 ec_slave_config_t *sc, /**< Slave configuration. */ |
1124 ec_slave_config_t *sc, /**< Slave configuration. */ |
981 ec_direction_t direction, /**< Input/Output. */ |
1127 ec_direction_t direction, /**< Input/Output. */ |
982 ec_watchdog_mode_t watchdog_mode /** Watchdog mode. */ |
1128 ec_watchdog_mode_t watchdog_mode /** Watchdog mode. */ |
983 ); |
1129 ); |
984 |
1130 |
985 /** Configure a slave's watchdog times. |
1131 /** Configure a slave's watchdog times. |
|
1132 * |
|
1133 * This method has to be called in non-realtime context before |
|
1134 * ecrt_master_activate(). |
986 */ |
1135 */ |
987 void ecrt_slave_config_watchdog( |
1136 void ecrt_slave_config_watchdog( |
988 ec_slave_config_t *sc, /**< Slave configuration. */ |
1137 ec_slave_config_t *sc, /**< Slave configuration. */ |
989 uint16_t watchdog_divider, /**< Number of 40 ns intervals. Used as a |
1138 uint16_t watchdog_divider, /**< Number of 40 ns intervals. Used as a |
990 base unit for all slave watchdogs. If set |
1139 base unit for all slave watchdogs. If set |
991 to zero, the value is not written, so the |
1140 to zero, the value is not written, so the |
992 default ist used. */ |
1141 default is used. */ |
993 uint16_t watchdog_intervals /**< Number of base intervals for process |
1142 uint16_t watchdog_intervals /**< Number of base intervals for process |
994 data watchdog. If set to zero, the value |
1143 data watchdog. If set to zero, the value |
995 is not written, so the default is used. |
1144 is not written, so the default is used. |
996 */ |
1145 */ |
997 ); |
1146 ); |
998 |
1147 |
999 /** Configure wether a slave allows overlapping PDOs. |
|
1000 * |
|
1001 * Overlapping PDOs allows inputs to use the same space as outputs on the frame. |
|
1002 * This reduces the frame length. |
|
1003 */ |
|
1004 void ecrt_slave_config_overlapping_pdos( |
|
1005 ec_slave_config_t *sc, /**< Slave configuration. */ |
|
1006 uint8_t allow_overlapping_pdos /**< Allow overlapping PDOs */ |
|
1007 ); |
|
1008 |
|
1009 |
|
1010 /** Add a PDO to a sync manager's PDO assignment. |
1148 /** Add a PDO to a sync manager's PDO assignment. |
|
1149 * |
|
1150 * This method has to be called in non-realtime context before |
|
1151 * ecrt_master_activate(). |
1011 * |
1152 * |
1012 * \see ecrt_slave_config_pdos() |
1153 * \see ecrt_slave_config_pdos() |
1013 * \return zero on success, else non-zero |
1154 * \return zero on success, else non-zero |
1014 */ |
1155 */ |
1015 int ecrt_slave_config_pdo_assign_add( |
1156 int ecrt_slave_config_pdo_assign_add( |
1023 * |
1164 * |
1024 * This can be called before assigning PDOs via |
1165 * This can be called before assigning PDOs via |
1025 * ecrt_slave_config_pdo_assign_add(), to clear the default assignment of a |
1166 * ecrt_slave_config_pdo_assign_add(), to clear the default assignment of a |
1026 * sync manager. |
1167 * sync manager. |
1027 * |
1168 * |
|
1169 * This method has to be called in non-realtime context before |
|
1170 * ecrt_master_activate(). |
|
1171 * |
1028 * \see ecrt_slave_config_pdos() |
1172 * \see ecrt_slave_config_pdos() |
1029 */ |
1173 */ |
1030 void ecrt_slave_config_pdo_assign_clear( |
1174 void ecrt_slave_config_pdo_assign_clear( |
1031 ec_slave_config_t *sc, /**< Slave configuration. */ |
1175 ec_slave_config_t *sc, /**< Slave configuration. */ |
1032 uint8_t sync_index /**< Sync manager index. Must be less |
1176 uint8_t sync_index /**< Sync manager index. Must be less |
1033 than #EC_MAX_SYNC_MANAGERS. */ |
1177 than #EC_MAX_SYNC_MANAGERS. */ |
1034 ); |
1178 ); |
1035 |
1179 |
1036 /** Add a PDO entry to the given PDO's mapping. |
1180 /** Add a PDO entry to the given PDO's mapping. |
|
1181 * |
|
1182 * This method has to be called in non-realtime context before |
|
1183 * ecrt_master_activate(). |
1037 * |
1184 * |
1038 * \see ecrt_slave_config_pdos() |
1185 * \see ecrt_slave_config_pdos() |
1039 * \return zero on success, else non-zero |
1186 * \return zero on success, else non-zero |
1040 */ |
1187 */ |
1041 int ecrt_slave_config_pdo_mapping_add( |
1188 int ecrt_slave_config_pdo_mapping_add( |
1051 /** Clear the mapping of a given PDO. |
1198 /** Clear the mapping of a given PDO. |
1052 * |
1199 * |
1053 * This can be called before mapping PDO entries via |
1200 * This can be called before mapping PDO entries via |
1054 * ecrt_slave_config_pdo_mapping_add(), to clear the default mapping. |
1201 * ecrt_slave_config_pdo_mapping_add(), to clear the default mapping. |
1055 * |
1202 * |
|
1203 * This method has to be called in non-realtime context before |
|
1204 * ecrt_master_activate(). |
|
1205 * |
1056 * \see ecrt_slave_config_pdos() |
1206 * \see ecrt_slave_config_pdos() |
1057 */ |
1207 */ |
1058 void ecrt_slave_config_pdo_mapping_clear( |
1208 void ecrt_slave_config_pdo_mapping_clear( |
1059 ec_slave_config_t *sc, /**< Slave configuration. */ |
1209 ec_slave_config_t *sc, /**< Slave configuration. */ |
1060 uint16_t pdo_index /**< Index of the PDO. */ |
1210 uint16_t pdo_index /**< Index of the PDO. */ |
1123 * Processing of \a syncs will stop, if |
1273 * Processing of \a syncs will stop, if |
1124 * - the number of processed items reaches \a n_syncs, or |
1274 * - the number of processed items reaches \a n_syncs, or |
1125 * - the \a index member of an ec_sync_info_t item is 0xff. In this case, |
1275 * - the \a index member of an ec_sync_info_t item is 0xff. In this case, |
1126 * \a n_syncs should set to a number greater than the number of list items; |
1276 * \a n_syncs should set to a number greater than the number of list items; |
1127 * using EC_END is recommended. |
1277 * using EC_END is recommended. |
|
1278 * |
|
1279 * This method has to be called in non-realtime context before |
|
1280 * ecrt_master_activate(). |
1128 * |
1281 * |
1129 * \return zero on success, else non-zero |
1282 * \return zero on success, else non-zero |
1130 */ |
1283 */ |
1131 int ecrt_slave_config_pdos( |
1284 int ecrt_slave_config_pdos( |
1132 ec_slave_config_t *sc, /**< Slave configuration. */ |
1285 ec_slave_config_t *sc, /**< Slave configuration. */ |
1146 * the domain's process data is returned. Optionally, the PDO entry bit |
1299 * the domain's process data is returned. Optionally, the PDO entry bit |
1147 * position (0-7) can be retrieved via the \a bit_position output parameter. |
1300 * position (0-7) can be retrieved via the \a bit_position output parameter. |
1148 * This pointer may be \a NULL, in this case an error is raised if the PDO |
1301 * This pointer may be \a NULL, in this case an error is raised if the PDO |
1149 * entry does not byte-align. |
1302 * entry does not byte-align. |
1150 * |
1303 * |
|
1304 * This method has to be called in non-realtime context before |
|
1305 * ecrt_master_activate(). |
|
1306 * |
1151 * \retval >=0 Success: Offset of the PDO entry's process data. |
1307 * \retval >=0 Success: Offset of the PDO entry's process data. |
1152 * \retval <0 Error code. |
1308 * \retval <0 Error code. |
1153 */ |
1309 */ |
1154 int ecrt_slave_config_reg_pdo_entry( |
1310 int ecrt_slave_config_reg_pdo_entry( |
1155 ec_slave_config_t *sc, /**< Slave configuration. */ |
1311 ec_slave_config_t *sc, /**< Slave configuration. */ |
1158 ec_domain_t *domain, /**< Domain. */ |
1314 ec_domain_t *domain, /**< Domain. */ |
1159 unsigned int *bit_position /**< Optional address if bit addressing |
1315 unsigned int *bit_position /**< Optional address if bit addressing |
1160 is desired */ |
1316 is desired */ |
1161 ); |
1317 ); |
1162 |
1318 |
|
1319 /** Registers a PDO entry using its position. |
|
1320 * |
|
1321 * Similar to ecrt_slave_config_reg_pdo_entry(), but not using PDO indices but |
|
1322 * offsets in the PDO mapping, because PDO entry indices may not be unique |
|
1323 * inside a slave's PDO mapping. An error is raised, if |
|
1324 * one of the given positions is out of range. |
|
1325 * |
|
1326 * This method has to be called in non-realtime context before |
|
1327 * ecrt_master_activate(). |
|
1328 * |
|
1329 * \retval >=0 Success: Offset of the PDO entry's process data. |
|
1330 * \retval <0 Error code. |
|
1331 */ |
|
1332 int ecrt_slave_config_reg_pdo_entry_pos( |
|
1333 ec_slave_config_t *sc, /**< Slave configuration. */ |
|
1334 uint8_t sync_index, /**< Sync manager index. */ |
|
1335 unsigned int pdo_pos, /**< Position of the PDO inside the SM. */ |
|
1336 unsigned int entry_pos, /**< Position of the entry inside the PDO. */ |
|
1337 ec_domain_t *domain, /**< Domain. */ |
|
1338 unsigned int *bit_position /**< Optional address if bit addressing |
|
1339 is desired */ |
|
1340 ); |
|
1341 |
1163 /** Configure distributed clocks. |
1342 /** Configure distributed clocks. |
1164 * |
1343 * |
1165 * Sets the AssignActivate word and the cycle and shift times for the sync |
1344 * Sets the AssignActivate word and the cycle and shift times for the sync |
1166 * signals. |
1345 * signals. |
1167 * |
1346 * |
1168 * The AssignActivate word is vendor-specific and can be taken from the XML |
1347 * The AssignActivate word is vendor-specific and can be taken from the XML |
1169 * device description file (Device -> Dc -> AssignActivate). Set this to zero, |
1348 * device description file (Device -> Dc -> AssignActivate). Set this to zero, |
1170 * if the slave shall be operated without distributed clocks (default). |
1349 * if the slave shall be operated without distributed clocks (default). |
|
1350 * |
|
1351 * This method has to be called in non-realtime context before |
|
1352 * ecrt_master_activate(). |
|
1353 * |
|
1354 * \attention The \a sync1_shift time is ignored. |
1171 */ |
1355 */ |
1172 void ecrt_slave_config_dc( |
1356 void ecrt_slave_config_dc( |
1173 ec_slave_config_t *sc, /**< Slave configuration. */ |
1357 ec_slave_config_t *sc, /**< Slave configuration. */ |
1174 uint16_t assign_activate, /**< AssignActivate word. */ |
1358 uint16_t assign_activate, /**< AssignActivate word. */ |
1175 uint32_t sync0_cycle, /**< SYNC0 cycle time [ns]. */ |
1359 uint32_t sync0_cycle, /**< SYNC0 cycle time [ns]. */ |
1176 uint32_t sync0_shift, /**< SYNC0 shift time [ns]. */ |
1360 int32_t sync0_shift, /**< SYNC0 shift time [ns]. */ |
1177 uint32_t sync1_cycle, /**< SYNC1 cycle time [ns]. */ |
1361 uint32_t sync1_cycle, /**< SYNC1 cycle time [ns]. */ |
1178 uint32_t sync1_shift /**< SYNC1 shift time [ns]. */ |
1362 int32_t sync1_shift /**< SYNC1 shift time [ns]. */ |
1179 ); |
1363 ); |
1180 |
1364 |
1181 /** Add an SDO configuration. |
1365 /** Add an SDO configuration. |
1182 * |
1366 * |
1183 * An SDO configuration is stored in the slave configuration object and is |
1367 * An SDO configuration is stored in the slave configuration object and is |
1190 * configured with this function, because they are part of the slave |
1374 * configured with this function, because they are part of the slave |
1191 * configuration done by the master. Please use ecrt_slave_config_pdos() and |
1375 * configuration done by the master. Please use ecrt_slave_config_pdos() and |
1192 * friends instead. |
1376 * friends instead. |
1193 * |
1377 * |
1194 * This is the generic function for adding an SDO configuration. Please note |
1378 * This is the generic function for adding an SDO configuration. Please note |
1195 * that the this function does not do any endianess correction. If |
1379 * that the this function does not do any endianness correction. If |
1196 * datatype-specific functions are needed (that automatically correct the |
1380 * datatype-specific functions are needed (that automatically correct the |
1197 * endianess), have a look at ecrt_slave_config_sdo8(), |
1381 * endianness), have a look at ecrt_slave_config_sdo8(), |
1198 * ecrt_slave_config_sdo16() and ecrt_slave_config_sdo32(). |
1382 * ecrt_slave_config_sdo16() and ecrt_slave_config_sdo32(). |
|
1383 * |
|
1384 * This method has to be called in non-realtime context before |
|
1385 * ecrt_master_activate(). |
1199 * |
1386 * |
1200 * \retval 0 Success. |
1387 * \retval 0 Success. |
1201 * \retval <0 Error code. |
1388 * \retval <0 Error code. |
1202 */ |
1389 */ |
1203 int ecrt_slave_config_sdo( |
1390 int ecrt_slave_config_sdo( |
1253 /** Add configuration data for a complete SDO. |
1449 /** Add configuration data for a complete SDO. |
1254 * |
1450 * |
1255 * The SDO data are transferred via CompleteAccess. Data for the first |
1451 * The SDO data are transferred via CompleteAccess. Data for the first |
1256 * subindex (0) have to be included. |
1452 * subindex (0) have to be included. |
1257 * |
1453 * |
|
1454 * This method has to be called in non-realtime context before |
|
1455 * ecrt_master_activate(). |
|
1456 * |
1258 * \see ecrt_slave_config_sdo(). |
1457 * \see ecrt_slave_config_sdo(). |
1259 * |
1458 * |
1260 * \retval 0 Success. |
1459 * \retval 0 Success. |
1261 * \retval <0 Error code. |
1460 * \retval <0 Error code. |
1262 */ |
1461 */ |
1265 uint16_t index, /**< Index of the SDO to configure. */ |
1464 uint16_t index, /**< Index of the SDO to configure. */ |
1266 const uint8_t *data, /**< Pointer to the data. */ |
1465 const uint8_t *data, /**< Pointer to the data. */ |
1267 size_t size /**< Size of the \a data. */ |
1466 size_t size /**< Size of the \a data. */ |
1268 ); |
1467 ); |
1269 |
1468 |
|
1469 /** Set the size of the CoE emergency ring buffer. |
|
1470 * |
|
1471 * The initial size is zero, so all messages will be dropped. This method can |
|
1472 * be called even after master activation, but it will clear the ring buffer! |
|
1473 * |
|
1474 * This method has to be called in non-realtime context before |
|
1475 * ecrt_master_activate(). |
|
1476 * |
|
1477 * \return 0 on success, or negative error code. |
|
1478 */ |
|
1479 int ecrt_slave_config_emerg_size( |
|
1480 ec_slave_config_t *sc, /**< Slave configuration. */ |
|
1481 size_t elements /**< Number of records of the CoE emergency ring. */ |
|
1482 ); |
|
1483 |
|
1484 /** Read and remove one record from the CoE emergency ring buffer. |
|
1485 * |
|
1486 * A record consists of 8 bytes: |
|
1487 * |
|
1488 * Byte 0-1: Error code (little endian) |
|
1489 * Byte 2: Error register |
|
1490 * Byte 3-7: Data |
|
1491 * |
|
1492 * \return 0 on success (record popped), or negative error code (i. e. |
|
1493 * -ENOENT, if ring is empty). |
|
1494 */ |
|
1495 int ecrt_slave_config_emerg_pop( |
|
1496 ec_slave_config_t *sc, /**< Slave configuration. */ |
|
1497 uint8_t *target /**< Pointer to target memory (at least |
|
1498 EC_COE_EMERGENCY_MSG_SIZE bytes). */ |
|
1499 ); |
|
1500 |
|
1501 /** Clears CoE emergency ring buffer and the overrun counter. |
|
1502 * |
|
1503 * \return 0 on success, or negative error code. |
|
1504 */ |
|
1505 int ecrt_slave_config_emerg_clear( |
|
1506 ec_slave_config_t *sc /**< Slave configuration. */ |
|
1507 ); |
|
1508 |
|
1509 /** Read the number of CoE emergency overruns. |
|
1510 * |
|
1511 * The overrun counter will be incremented when a CoE emergency message could |
|
1512 * not be stored in the ring buffer and had to be dropped. Call |
|
1513 * ecrt_slave_config_emerg_clear() to reset the counter. |
|
1514 * |
|
1515 * \return Number of overruns since last clear, or negative error code. |
|
1516 */ |
|
1517 int ecrt_slave_config_emerg_overruns( |
|
1518 ec_slave_config_t *sc /**< Slave configuration. */ |
|
1519 ); |
|
1520 |
1270 /** Create an SDO request to exchange SDOs during realtime operation. |
1521 /** Create an SDO request to exchange SDOs during realtime operation. |
1271 * |
1522 * |
1272 * The created SDO request object is freed automatically when the master is |
1523 * The created SDO request object is freed automatically when the master is |
1273 * released. |
1524 * released. |
|
1525 * |
|
1526 * This method has to be called in non-realtime context before |
|
1527 * ecrt_master_activate(). |
|
1528 * |
|
1529 * \return New SDO request, or NULL on error. |
1274 */ |
1530 */ |
1275 ec_sdo_request_t *ecrt_slave_config_create_sdo_request( |
1531 ec_sdo_request_t *ecrt_slave_config_create_sdo_request( |
1276 ec_slave_config_t *sc, /**< Slave configuration. */ |
1532 ec_slave_config_t *sc, /**< Slave configuration. */ |
1277 uint16_t index, /**< SDO index. */ |
1533 uint16_t index, /**< SDO index. */ |
1278 uint8_t subindex, /**< SDO subindex. */ |
1534 uint8_t subindex, /**< SDO subindex. */ |
1286 * usually it is enough to create one for sending and one for receiving, if |
1542 * usually it is enough to create one for sending and one for receiving, if |
1287 * both can be done simultaneously. |
1543 * both can be done simultaneously. |
1288 * |
1544 * |
1289 * The created VoE handler object is freed automatically when the master is |
1545 * The created VoE handler object is freed automatically when the master is |
1290 * released. |
1546 * released. |
|
1547 * |
|
1548 * This method has to be called in non-realtime context before |
|
1549 * ecrt_master_activate(). |
|
1550 * |
|
1551 * \return New VoE handler, or NULL on error. |
1291 */ |
1552 */ |
1292 ec_voe_handler_t *ecrt_slave_config_create_voe_handler( |
1553 ec_voe_handler_t *ecrt_slave_config_create_voe_handler( |
|
1554 ec_slave_config_t *sc, /**< Slave configuration. */ |
|
1555 size_t size /**< Data size to reserve. */ |
|
1556 ); |
|
1557 |
|
1558 /** Create a register request to exchange EtherCAT register contents during |
|
1559 * realtime operation. |
|
1560 * |
|
1561 * This interface should not be used to take over master functionality, |
|
1562 * instead it is intended for debugging and monitoring reasons. |
|
1563 * |
|
1564 * The created register request object is freed automatically when the master |
|
1565 * is released. |
|
1566 * |
|
1567 * This method has to be called in non-realtime context before |
|
1568 * ecrt_master_activate(). |
|
1569 * |
|
1570 * \return New register request, or NULL on error. |
|
1571 */ |
|
1572 ec_reg_request_t *ecrt_slave_config_create_reg_request( |
1293 ec_slave_config_t *sc, /**< Slave configuration. */ |
1573 ec_slave_config_t *sc, /**< Slave configuration. */ |
1294 size_t size /**< Data size to reserve. */ |
1574 size_t size /**< Data size to reserve. */ |
1295 ); |
1575 ); |
1296 |
1576 |
1297 /** Outputs the state of the slave configuration. |
1577 /** Outputs the state of the slave configuration. |
1314 * configuration object and is written to the slave whenever the slave is |
1594 * configuration object and is written to the slave whenever the slave is |
1315 * being configured by the master. This usually happens once on master |
1595 * being configured by the master. This usually happens once on master |
1316 * activation, but can be repeated subsequently, for example after the slave's |
1596 * activation, but can be repeated subsequently, for example after the slave's |
1317 * power supply failed. |
1597 * power supply failed. |
1318 * |
1598 * |
1319 * The \a idn parameter can be separated into serveral sections: |
1599 * The \a idn parameter can be separated into several sections: |
1320 * - Bit 15: Standard data (0) or Product data (1) |
1600 * - Bit 15: Standard data (0) or Product data (1) |
1321 * - Bit 14 - 12: Parameter set (0 - 7) |
1601 * - Bit 14 - 12: Parameter set (0 - 7) |
1322 * - Bit 11 - 0: Data block number (0 - 4095) |
1602 * - Bit 11 - 0: Data block number (0 - 4095) |
1323 * |
1603 * |
1324 * Please note that the this function does not do any endianess correction. |
1604 * Please note that the this function does not do any endianness correction. |
1325 * Multi-byte data have to be passed in EtherCAT endianess (little-endian). |
1605 * Multi-byte data have to be passed in EtherCAT endianness (little-endian). |
|
1606 * |
|
1607 * This method has to be called in non-realtime context before |
|
1608 * ecrt_master_activate(). |
1326 * |
1609 * |
1327 * \retval 0 Success. |
1610 * \retval 0 Success. |
1328 * \retval <0 Error code. |
1611 * \retval <0 Error code. |
1329 */ |
1612 */ |
1330 int ecrt_slave_config_idn( |
1613 int ecrt_slave_config_idn( |
1341 * Domain methods |
1624 * Domain methods |
1342 *****************************************************************************/ |
1625 *****************************************************************************/ |
1343 |
1626 |
1344 /** Registers a bunch of PDO entries for a domain. |
1627 /** Registers a bunch of PDO entries for a domain. |
1345 * |
1628 * |
1346 * \todo doc |
1629 * This method has to be called in non-realtime context before |
|
1630 * ecrt_master_activate(). |
|
1631 * |
|
1632 * \see ecrt_slave_config_reg_pdo_entry() |
|
1633 * |
1347 * \attention The registration array has to be terminated with an empty |
1634 * \attention The registration array has to be terminated with an empty |
1348 * structure, or one with the \a index field set to zero! |
1635 * structure, or one with the \a index field set to zero! |
1349 * \return 0 on success, else non-zero. |
1636 * \return 0 on success, else non-zero. |
1350 */ |
1637 */ |
1351 int ecrt_domain_reg_pdo_entry_list( |
1638 int ecrt_domain_reg_pdo_entry_list( |
1352 ec_domain_t *domain, /**< Domain. */ |
1639 ec_domain_t *domain, /**< Domain. */ |
1353 const ec_pdo_entry_reg_t *pdo_entry_regs /**< Array of PDO |
1640 const ec_pdo_entry_reg_t *pdo_entry_regs /**< Array of PDO |
1354 registrations. */ |
1641 registrations. */ |
1355 ); |
1642 ); |
1356 |
1643 |
1357 #ifdef __KERNEL__ |
|
1358 |
|
1359 /** Returns the current size of the domain's process data. |
1644 /** Returns the current size of the domain's process data. |
1360 * |
1645 * |
1361 * \return Size of the process data image. |
1646 * \return Size of the process data image, or a negative error code. |
1362 */ |
1647 */ |
1363 size_t ecrt_domain_size( |
1648 size_t ecrt_domain_size( |
1364 const ec_domain_t *domain /**< Domain. */ |
1649 const ec_domain_t *domain /**< Domain. */ |
1365 ); |
1650 ); |
1366 |
1651 |
|
1652 #ifdef __KERNEL__ |
|
1653 |
1367 /** Provide external memory to store the domain's process data. |
1654 /** Provide external memory to store the domain's process data. |
1368 * |
1655 * |
1369 * Call this after all PDO entries have been registered and before activating |
1656 * Call this after all PDO entries have been registered and before activating |
1370 * the master. |
1657 * the master. |
1371 * |
1658 * |
1372 * The size of the allocated memory must be at least ecrt_domain_size(), after |
1659 * The size of the allocated memory must be at least ecrt_domain_size(), after |
1373 * all PDO entries have been registered. |
1660 * all PDO entries have been registered. |
|
1661 * |
|
1662 * This method has to be called in non-realtime context before |
|
1663 * ecrt_master_activate(). |
|
1664 * |
1374 */ |
1665 */ |
1375 void ecrt_domain_external_memory( |
1666 void ecrt_domain_external_memory( |
1376 ec_domain_t *domain, /**< Domain. */ |
1667 ec_domain_t *domain, /**< Domain. */ |
1377 uint8_t *memory /**< Address of the memory to store the process |
1668 uint8_t *memory /**< Address of the memory to store the process |
1378 data in. */ |
1669 data in. */ |
1430 ); |
1721 ); |
1431 |
1722 |
1432 /***************************************************************************** |
1723 /***************************************************************************** |
1433 * SDO request methods. |
1724 * SDO request methods. |
1434 ****************************************************************************/ |
1725 ****************************************************************************/ |
|
1726 |
|
1727 /** Set the SDO index and subindex. |
|
1728 * |
|
1729 * \attention If the SDO index and/or subindex is changed while |
|
1730 * ecrt_sdo_request_state() returns EC_REQUEST_BUSY, this may lead to |
|
1731 * unexpected results. |
|
1732 */ |
|
1733 void ecrt_sdo_request_index( |
|
1734 ec_sdo_request_t *req, /**< SDO request. */ |
|
1735 uint16_t index, /**< SDO index. */ |
|
1736 uint8_t subindex /**< SDO subindex. */ |
|
1737 ); |
1435 |
1738 |
1436 /** Set the timeout for an SDO request. |
1739 /** Set the timeout for an SDO request. |
1437 * |
1740 * |
1438 * If the request cannot be processed in the specified time, if will be marked |
1741 * If the request cannot be processed in the specified time, if will be marked |
1439 * as failed. |
1742 * as failed. |
1501 #endif |
1804 #endif |
1502 |
1805 |
1503 /** Schedule an SDO write operation. |
1806 /** Schedule an SDO write operation. |
1504 * |
1807 * |
1505 * \attention This method may not be called while ecrt_sdo_request_state() |
1808 * \attention This method may not be called while ecrt_sdo_request_state() |
1506 * returns EC_SDO_REQUEST_BUSY. |
1809 * returns EC_REQUEST_BUSY. |
1507 */ |
1810 */ |
1508 void ecrt_sdo_request_write( |
1811 void ecrt_sdo_request_write( |
1509 ec_sdo_request_t *req /**< SDO request. */ |
1812 ec_sdo_request_t *req /**< SDO request. */ |
1510 ); |
1813 ); |
1511 |
1814 |
1512 /** Schedule an SDO read operation. |
1815 /** Schedule an SDO read operation. |
1513 * |
1816 * |
1514 * \attention This method may not be called while ecrt_sdo_request_state() |
1817 * \attention This method may not be called while ecrt_sdo_request_state() |
1515 * returns EC_SDO_REQUEST_BUSY. |
1818 * returns EC_REQUEST_BUSY. |
1516 * |
1819 * |
1517 * \attention After calling this function, the return value of |
1820 * \attention After calling this function, the return value of |
1518 * ecrt_sdo_request_data() must be considered as invalid while |
1821 * ecrt_sdo_request_data() must be considered as invalid while |
1519 * ecrt_sdo_request_state() returns EC_SDO_REQUEST_BUSY. |
1822 * ecrt_sdo_request_state() returns EC_REQUEST_BUSY. |
1520 */ |
1823 */ |
1521 void ecrt_sdo_request_read( |
1824 void ecrt_sdo_request_read( |
1522 ec_sdo_request_t *req /**< SDO request. */ |
1825 ec_sdo_request_t *req /**< SDO request. */ |
1523 ); |
1826 ); |
1524 |
1827 |
1641 ec_voe_handler_t *voe /**< VoE handler. */ |
1944 ec_voe_handler_t *voe /**< VoE handler. */ |
1642 ); |
1945 ); |
1643 |
1946 |
1644 /** Execute the handler. |
1947 /** Execute the handler. |
1645 * |
1948 * |
1646 * This method executes the VoE handler. It has to be called in every bus cycle |
1949 * This method executes the VoE handler. It has to be called in every bus |
1647 * as long as it returns EC_REQUEST_BUSY. |
1950 * cycle as long as it returns EC_REQUEST_BUSY. |
1648 * |
1951 * |
1649 * \return Handler state. |
1952 * \return Handler state. |
1650 */ |
1953 */ |
1651 ec_request_state_t ecrt_voe_handler_execute( |
1954 ec_request_state_t ecrt_voe_handler_execute( |
1652 ec_voe_handler_t *voe /**< VoE handler. */ |
1955 ec_voe_handler_t *voe /**< VoE handler. */ |
1653 ); |
1956 ); |
|
1957 |
|
1958 /***************************************************************************** |
|
1959 * Register request methods. |
|
1960 ****************************************************************************/ |
|
1961 |
|
1962 /** Access to the register request's data. |
|
1963 * |
|
1964 * This function returns a pointer to the request's internal memory. |
|
1965 * |
|
1966 * - After a read operation was successful, integer data can be evaluated |
|
1967 * using the EC_READ_*() macros as usual. Example: |
|
1968 * \code |
|
1969 * uint16_t value = EC_READ_U16(ecrt_reg_request_data(reg_request))); |
|
1970 * \endcode |
|
1971 * - If a write operation shall be triggered, the data have to be written to |
|
1972 * the internal memory. Use the EC_WRITE_*() macros, if you are writing |
|
1973 * integer data. Be sure, that the data fit into the memory. The memory size |
|
1974 * is a parameter of ecrt_slave_config_create_reg_request(). |
|
1975 * \code |
|
1976 * EC_WRITE_U16(ecrt_reg_request_data(reg_request), 0xFFFF); |
|
1977 * \endcode |
|
1978 * |
|
1979 * \return Pointer to the internal memory. |
|
1980 */ |
|
1981 uint8_t *ecrt_reg_request_data( |
|
1982 ec_reg_request_t *req /**< Register request. */ |
|
1983 ); |
|
1984 |
|
1985 /** Get the current state of the register request. |
|
1986 * |
|
1987 * \return Request state. |
|
1988 */ |
|
1989 #ifdef __KERNEL__ |
|
1990 ec_request_state_t ecrt_reg_request_state( |
|
1991 const ec_reg_request_t *req /**< Register request. */ |
|
1992 ); |
|
1993 #else |
|
1994 ec_request_state_t ecrt_reg_request_state( |
|
1995 ec_reg_request_t *req /**< Register request. */ |
|
1996 ); |
|
1997 #endif |
|
1998 |
|
1999 /** Schedule an register write operation. |
|
2000 * |
|
2001 * \attention This method may not be called while ecrt_reg_request_state() |
|
2002 * returns EC_REQUEST_BUSY. |
|
2003 * |
|
2004 * \attention The \a size parameter is truncated to the size given at request |
|
2005 * creation. |
|
2006 */ |
|
2007 void ecrt_reg_request_write( |
|
2008 ec_reg_request_t *req, /**< Register request. */ |
|
2009 uint16_t address, /**< Register address. */ |
|
2010 size_t size /**< Size to write. */ |
|
2011 ); |
|
2012 |
|
2013 /** Schedule a register read operation. |
|
2014 * |
|
2015 * \attention This method may not be called while ecrt_reg_request_state() |
|
2016 * returns EC_REQUEST_BUSY. |
|
2017 * |
|
2018 * \attention The \a size parameter is truncated to the size given at request |
|
2019 * creation. |
|
2020 */ |
|
2021 void ecrt_reg_request_read( |
|
2022 ec_reg_request_t *req, /**< Register request. */ |
|
2023 uint16_t address, /**< Register address. */ |
|
2024 size_t size /**< Size to write. */ |
|
2025 ); |
1654 |
2026 |
1655 /*****************************************************************************/ |
2027 /*****************************************************************************/ |
1656 |
2028 |
1657 #ifdef __cplusplus |
2029 #ifdef __cplusplus |
1658 } |
2030 } |