*
* Copyright (C) 2006-2024 Florian Pose, Ingenieurgemeinschaft IgH
*
* This file is part of the IgH EtherCAT master userspace library.
*
* The IgH EtherCAT master userspace library is free software; you can
* redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; version 2.1
* of the License.
*
* The IgH EtherCAT master userspace library is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the IgH EtherCAT master userspace library. If not, see
* <http://www.gnu.org/licenses/>.
*
****************************************************************************/
*
* EtherCAT master application interface.
*
* \defgroup ApplicationInterface EtherCAT Application Interface
*
* EtherCAT interface for realtime applications. This interface is designed
* for realtime modules that want to use EtherCAT. There are functions to
* request a master, to map process data, to communicate with slaves via CoE
* and to configure and activate the bus.
*
*
* Changes in version 1.6.0:
*
* - Added the ecrt_master_scan_progress() method, the
* ec_master_scan_progress_t structure and the EC_HAVE_SCAN_PROGRESS
* definition to check for its existence.
* - Added the EoE configuration methods ecrt_slave_config_eoe_mac_address(),
* ecrt_slave_config_eoe_ip_address(), ecrt_slave_config_eoe_subnet_mask(),
* ecrt_slave_config_eoe_default_gateway(),
* ecrt_slave_config_eoe_dns_address(),
* ecrt_slave_config_eoe_hostname() and the EC_HAVE_SET_IP
* definition to check for its existence.
* - Added ecrt_slave_config_state_timeout() to set the application-layer
* state change timeout and EC_HAVE_STATE_TIMEOUT to check for its
* existence.
*
* Changes since version 1.5.2:
*
* - Added the ecrt_slave_config_flag() method and the EC_HAVE_FLAGS
* definition to check for its existence.
* - Added SoE IDN requests, including the datatype ec_soe_request_t and the
* methods ecrt_slave_config_create_soe_request(),
* ecrt_soe_request_object(), ecrt_soe_request_timeout(),
* ecrt_soe_request_data(), ecrt_soe_request_data_size(),
* ecrt_soe_request_state(), ecrt_soe_request_write() and
* ecrt_soe_request_read(). Use the EC_HAVE_SOE_REQUESTS to check, if the
* functionality is available.
*
* Changes in version 1.5.2:
*
* - Added redundancy_active flag to ec_domain_state_t.
* - Added ecrt_master_link_state() method and ec_master_link_state_t to query
* the state of a redundant link.
* - Added the EC_HAVE_REDUNDANCY define, to check, if the interface contains
* redundancy features.
* - Added ecrt_sdo_request_index() to change SDO index and subindex after
* request creation.
* - Added interface for retrieving CoE emergency messages, i. e.
* ecrt_slave_config_emerg_size(), ecrt_slave_config_emerg_pop(),
* ecrt_slave_config_emerg_clear(), ecrt_slave_config_emerg_overruns() and
* the defines EC_HAVE_EMERGENCY and EC_COE_EMERGENCY_MSG_SIZE.
* - Added interface for direct EtherCAT register access: Added data type
* ec_reg_request_t and methods ecrt_slave_config_create_reg_request(),
* ecrt_reg_request_data(), ecrt_reg_request_state(),
* ecrt_reg_request_write(), ecrt_reg_request_read() and the feature flag
* EC_HAVE_REG_ACCESS.
* - Added method to select the reference clock,
* ecrt_master_select_reference_clock() and the feature flag
* EC_HAVE_SELECT_REF_CLOCK to check, if the method is available.
* - Added method to get the reference clock time,
* ecrt_master_reference_clock_time() and the feature flag
* EC_HAVE_REF_CLOCK_TIME to have the possibility to synchronize the master
* clock to the reference clock.
* - Changed the data types of the shift times in ecrt_slave_config_dc() to
* int32_t to correctly display negative shift times.
* - Added ecrt_slave_config_reg_pdo_entry_pos() and the feature flag
* EC_HAVE_REG_BY_POS for registering PDO entries with non-unique indices
* via their positions in the mapping.
*
* Changes in version 1.5:
*
* - Added the distributed clocks feature and the respective method
* ecrt_slave_config_dc() to configure a slave for cyclic operation, and
* ecrt_master_application_time(), ecrt_master_sync_reference_clock() and
* ecrt_master_sync_slave_clocks() for offset and drift compensation. The
* EC_TIMEVAL2NANO() macro can be used for epoch time conversion, while the
* ecrt_master_sync_monitor_queue() and ecrt_master_sync_monitor_process()
* methods can be used to monitor the synchrony.
* - Improved the callback mechanism. ecrt_master_callbacks() now takes two
* callback functions for sending and receiving datagrams.
* ecrt_master_send_ext() is used to execute the sending of non-application
* datagrams.
* - Added watchdog configuration (method ecrt_slave_config_watchdog(),
* #ec_watchdog_mode_t, \a watchdog_mode parameter in ec_sync_info_t and
* ecrt_slave_config_sync_manager()).
* - Added ecrt_slave_config_complete_sdo() method to download an SDO during
* configuration via CompleteAccess.
* - Added ecrt_master_deactivate() to remove the master configuration.
* - Added ecrt_open_master() and ecrt_master_reserve() separation for
* userspace.
* - Added master information interface (methods ecrt_master(),
* ecrt_master_get_slave(), ecrt_master_get_sync_manager(),
* ecrt_master_get_pdo() and ecrt_master_get_pdo_entry()) to get information
* about the currently connected slaves and the PDO entries provided.
* - Added ecrt_master_sdo_download(), ecrt_master_sdo_download_complete() and
* ecrt_master_sdo_upload() methods to let an application transfer SDOs
* before activating the master.
* - Changed the meaning of the negative return values of
* ecrt_slave_config_reg_pdo_entry() and ecrt_slave_config_sdo*().
* - Implemented the Vendor-specific over EtherCAT mailbox protocol. See
* ecrt_slave_config_create_voe_handler().
* - Renamed ec_sdo_request_state_t to #ec_request_state_t, because it is also
* used by VoE handlers.
* - Removed 'const' from argument of ecrt_sdo_request_state(), because the
* userspace library has to modify object internals.
* - Added 64-bit data access macros.
* - Added ecrt_slave_config_idn() method for storing SoE IDN configurations,
* and ecrt_master_read_idn() and ecrt_master_write_idn() to read/write IDNs
* ad-hoc via the user-space library.
* - Added ecrt_master_reset() to initiate retrying to configure slaves.
*
* @{
*/
#ifndef __ECRT_H__
#define __ECRT_H__
#ifdef __KERNEL__
#include <asm/byteorder.h>
#include <linux/types.h>
#include <linux/time.h>
#include <linux/in.h>
#else
#include <stdlib.h>
#include <stdint.h>
#include <sys/time.h>
#include <netinet/in.h>
#endif
* Global definitions
****************************************************************************/
*/
#define ECRT_VER_MAJOR 1
*/
#define ECRT_VER_MINOR 6
*/
#define ECRT_VERSION(a, b) (((a) << 8) + (b))
*/
#define ECRT_VERSION_MAGIC ECRT_VERSION(ECRT_VER_MAJOR, ECRT_VER_MINOR)
* Feature flags
****************************************************************************/
*
* I. e. if the \a redundancy_active flag in ec_domain_state_t and the
* ecrt_master_link_state() method are available.
*/
#define EC_HAVE_REDUNDANCY
*
* I. e. if the ecrt_slave_config_emerg_*() methods are available.
*/
#define EC_HAVE_EMERGENCY
*
* I. e. if the methods ecrt_slave_config_create_reg_request(),
* ecrt_reg_request_data(), ecrt_reg_request_state(), ecrt_reg_request_write()
* and ecrt_reg_request_read() are available.
*/
#define EC_HAVE_REG_ACCESS
*/
#define EC_HAVE_SELECT_REF_CLOCK
*/
#define EC_HAVE_REF_CLOCK_TIME
*/
#define EC_HAVE_REG_BY_POS
*/
#define EC_HAVE_SYNC_TO
*/
#define EC_HAVE_FLAGS
* ecrt_soe_request_object(), ecrt_soe_request_timeout(),
* ecrt_soe_request_data(), ecrt_soe_request_data_size(),
* ecrt_soe_request_state(), ecrt_soe_request_write() and
* ecrt_soe_request_read() and the datatype ec_soe_request_t are available.
*/
#define EC_HAVE_SOE_REQUESTS
* ec_master_scan_progress_t structure are available.
*/
#define EC_HAVE_SCAN_PROGRESS
* ecrt_slave_config_eoe_ip_address(), ecrt_slave_config_eoe_subnet_mask(),
* ecrt_slave_config_eoe_default_gateway(),
* ecrt_slave_config_eoe_dns_address(), ecrt_slave_config_eoe_hostname() are
* available.
*/
#define EC_HAVE_SET_IP
*/
#define EC_HAVE_STATE_TIMEOUT
*/
#ifndef EC_PUBLIC_API
# if defined(ethercat_EXPORTS) && !defined(__KERNEL__)
# define EC_PUBLIC_API __attribute__ ((visibility ("default")))
# else
# define EC_PUBLIC_API
# endif
#endif
*
* This can be used with ecrt_slave_config_pdos().
*/
#define EC_END ~0U
*/
#define EC_MAX_SYNC_MANAGERS 16
*
* Used in ec_slave_info_t.
*/
#define EC_MAX_STRING_LENGTH 64
#define EC_MAX_PORTS 4
*
* This macro converts a Unix epoch time to EtherCAT DC time.
*
* \see void ecrt_master_application_time()
*
* \param TV struct timeval containing epoch time.
*/
#define EC_TIMEVAL2NANO(TV) \
(((TV).tv_sec - 946684800ULL) * 1000000000ULL + (TV).tv_usec * 1000ULL)
*
* \see ecrt_slave_config_emerg_pop().
*/
#define EC_COE_EMERGENCY_MSG_SIZE 8
* Data types
****************************************************************************/
struct ec_master;
typedef struct ec_master ec_master_t;
struct ec_slave_config;
typedef struct ec_slave_config ec_slave_config_t;
struct ec_domain;
typedef struct ec_domain ec_domain_t;
struct ec_sdo_request;
typedef struct ec_sdo_request ec_sdo_request_t;
struct ec_soe_request;
typedef struct ec_soe_request ec_soe_request_t;
struct ec_voe_handler;
typedef struct ec_voe_handler ec_voe_handler_t;
struct ec_reg_request;
typedef struct ec_reg_request ec_reg_request_t;
*
* This is used for the output parameter of ecrt_master_state().
*
* \see ecrt_master_state().
*/
typedef struct {
unsigned int slaves_responding;
Ethernet devices. */
unsigned int al_states : 4;
The states are coded in the lower 4 bits.
If a bit is set, it means that at least one
slave in the network is in the corresponding
state:
- Bit 0: \a INIT
- Bit 1: \a PREOP
- Bit 2: \a SAFEOP
- Bit 3: \a OP */
unsigned int link_up : 1;
up. */
} ec_master_state_t;
*
* This is used for the output parameter of ecrt_master_link_state().
*
* \see ecrt_master_link_state().
*/
typedef struct {
unsigned int slaves_responding;
link. */
unsigned int al_states : 4;
the given link. The states are coded in the
lower 4 bits. If a bit is set, it means
that at least one slave in the network is in
the corresponding state:
- Bit 0: \a INIT
- Bit 1: \a PREOP
- Bit 2: \a SAFEOP
- Bit 3: \a OP */
unsigned int link_up : 1;
*/
} ec_master_link_state_t;
*
* This is used as an output parameter of ecrt_slave_config_state().
*
* \see ecrt_slave_config_state().
*/
typedef struct {
unsigned int online : 1;
unsigned int operational : 1;
using the specified configuration. */
unsigned int al_state : 4;
- 1: \a INIT
- 2: \a PREOP
- 4: \a SAFEOP
- 8: \a OP
Note that each state is coded in a different
bit! */
} ec_slave_config_state_t;
*
* This is used as an output parameter of ecrt_master().
*
* \see ecrt_master().
*/
typedef struct {
unsigned int slave_count;
unsigned int link_up : 1;
uint8_t scan_busy;
*/
uint64_t app_time;
} ec_master_info_t;
*
* This is used as an output parameter of ecrt_master_scan_progress().
*
* \see ecrt_master_scan_progress().
*/
typedef struct {
unsigned int slave_count;
unsigned int scan_index;
scanned. If it is less than the \a
slave_count, the network scan is in progress.
*/
} ec_master_scan_progress_t;
*/
typedef enum {
EC_PORT_NOT_IMPLEMENTED,
EC_PORT_NOT_CONFIGURED,
EC_PORT_EBUS,
EC_PORT_MII
} ec_slave_port_desc_t;
*/
typedef struct {
uint8_t link_up;
uint8_t loop_closed;
uint8_t signal_detected;
} ec_slave_port_link_t;
*
* This is used as an output parameter of ecrt_master_get_slave().
*
* \see ecrt_master_get_slave().
*/
typedef struct {
uint16_t position;
uint32_t vendor_id;
uint32_t product_code;
uint32_t revision_number;
uint32_t serial_number;
uint16_t alias;
int16_t current_on_ebus;
struct {
ec_slave_port_desc_t desc;
ec_slave_port_link_t link;
uint32_t receive_time;
measurement. */
uint16_t next_slave;
port. */
uint32_t delay_to_next_dc;
} ports[EC_MAX_PORTS];
uint8_t al_state;
uint8_t error_flag;
uint8_t sync_count;
uint16_t sdo_count;
char name[EC_MAX_STRING_LENGTH];
} ec_slave_info_t;
*
* This is used in ec_domain_state_t.
*/
typedef enum {
EC_WC_ZERO = 0,
EC_WC_INCOMPLETE,
exchanged. */
EC_WC_COMPLETE
} ec_wc_state_t;
*
* This is used for the output parameter of ecrt_domain_state().
*/
typedef struct {
unsigned int working_counter;
ec_wc_state_t wc_state;
unsigned int redundancy_active;
} ec_domain_state_t;
*/
typedef enum {
EC_DIR_INVALID,
EC_DIR_OUTPUT,
EC_DIR_INPUT,
EC_DIR_COUNT
} ec_direction_t;
*
* Used to specify, if a sync manager's watchdog is to be enabled.
*/
typedef enum {
EC_WD_DEFAULT,
EC_WD_ENABLE,
EC_WD_DISABLE,
} ec_watchdog_mode_t;
*
* This is the data type of the \a entries field in ec_pdo_info_t.
*
* \see ecrt_slave_config_pdos().
*/
typedef struct {
uint16_t index;
uint8_t subindex;
uint8_t bit_length;
} ec_pdo_entry_info_t;
*
* This is the data type of the \a pdos field in ec_sync_info_t.
*
* \see ecrt_slave_config_pdos().
*/
typedef struct {
uint16_t index;
unsigned int n_entries;
Zero means, that the default mapping shall be
used (this can only be done if the slave is
present at configuration time). */
ec_pdo_entry_info_t const *entries;
either be \a NULL, or must contain
at least \a n_entries values. */
} ec_pdo_info_t;
*
* This can be use to configure multiple sync managers including the PDO
* assignment and PDO mapping. It is used as an input parameter type in
* ecrt_slave_config_pdos().
*/
typedef struct {
uint8_t index;
than #EC_MAX_SYNC_MANAGERS for a valid sync manager,
but can also be \a 0xff to mark the end of the list. */
ec_direction_t dir;
unsigned int n_pdos;
ec_pdo_info_t const *pdos;
contain at least \a n_pdos PDOs. */
ec_watchdog_mode_t watchdog_mode;
} ec_sync_info_t;
*
* This type is used for the array parameter of the
* ecrt_domain_reg_pdo_entry_list()
*/
typedef struct {
uint16_t alias;
uint16_t position;
uint32_t vendor_id;
uint32_t product_code;
uint16_t index;
uint8_t subindex;
unsigned int *offset;
(byte-)offset in the process data. */
unsigned int *bit_position;
position (0-7) within the \a offset. Can be
NULL, in which case an error is raised if
the PDO entry does not byte-align. */
} ec_pdo_entry_reg_t;
*
* This is used as return type for ecrt_sdo_request_state() and
* ecrt_voe_handler_state().
*/
typedef enum {
EC_REQUEST_UNUSED,
EC_REQUEST_BUSY,
EC_REQUEST_SUCCESS,
EC_REQUEST_ERROR,
} ec_request_state_t;
*/
typedef enum {
EC_AL_STATE_INIT = 1,
EC_AL_STATE_PREOP = 2,
EC_AL_STATE_SAFEOP = 4,
EC_AL_STATE_OP = 8,
} ec_al_state_t;
* Global functions
****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
*
* \apiusage{master_any,rt_safe}
*
* \return Value of ECRT_VERSION_MAGIC() at EtherCAT master compile time.
*/
EC_PUBLIC_API unsigned int ecrt_version_magic(void);
*
* Before an application can access an EtherCAT master, it has to reserve one
* for exclusive use.
*
* In userspace, this is a convenience function for ecrt_open_master() and
* ecrt_master_reserve().
*
* This function has to be the first function an application has to call to
* use EtherCAT. The function takes the index of the master as its argument.
* The first master has index 0, the n-th master has index n - 1. The number
* of masters has to be specified when loading the master module.
*
* \apiusage{master_idle,blocking}
*
* \return Pointer to the reserved master, otherwise \a NULL.
*/
EC_PUBLIC_API ec_master_t *ecrt_request_master(
unsigned int master_index
);
#ifndef __KERNEL__
*
* This function has to be the first function an application has to call to
* use EtherCAT. The function takes the index of the master as its argument.
* The first master has index 0, the n-th master has index n - 1. The number
* of masters has to be specified when loading the master module.
*
* For convenience, the function ecrt_request_master() can be used.
*
* \apiusage{master_idle,blocking}
*
* \return Pointer to the opened master, otherwise \a NULL.
*/
EC_PUBLIC_API ec_master_t *ecrt_open_master(
unsigned int master_index
);
#endif
*
* After use, a master it has to be released to make it available for other
* applications.
*
* This method frees all created data structures. It should not be called in
* realtime context.
*
* If the master was activated, ecrt_master_deactivate() is called internally.
*
* \apiusage{master_any,blocking}
*/
EC_PUBLIC_API void ecrt_release_master(
ec_master_t *master
);
* Master methods
****************************************************************************/
#ifndef __KERNEL__
*
* Before an application can use PDO/domain registration functions or SDO
* request functions on the master, it has to reserve one for exclusive use.
*
* \apiusage{master_idle,blocking}
*
* \return 0 in case of success, else < 0
*/
EC_PUBLIC_API int ecrt_master_reserve(
ec_master_t *master
);
#endif
#ifdef __KERNEL__
*
* For concurrent master access, i. e. if other instances than the application
* want to send and receive datagrams on the network, the application has to
* provide a callback mechanism. This method takes two function pointers as
* its parameters. Asynchronous master access (like EoE processing) is only
* possible if the callbacks have been set.
*
* The task of the send callback (\a send_cb) is to decide, if the network
* hardware is currently accessible and whether or not to call the
* ecrt_master_send_ext() method.
*
* The task of the receive callback (\a receive_cb) is to decide, if a call to
* ecrt_master_receive() is allowed and to execute it respectively.
*
* \apiusage{master_idle,blocking}
*
* \attention This method has to be called before ecrt_master_activate().
*/
void ecrt_master_callbacks(
ec_master_t *master,
void (*send_cb)(void *),
void (*receive_cb)(void *),
void *cb_data
*/
);
#endif
*
* For process data exchange, at least one process data domain is needed.
* This method creates a new process data domain and returns a pointer to the
* new domain object. This object can be used for registering PDOs and
* exchanging them in cyclic operation.
*
* This method allocates memory and should be called in non-realtime context
* before ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return Pointer to the new domain on success, else NULL.
*/
EC_PUBLIC_API ec_domain_t *ecrt_master_create_domain(
ec_master_t *master
);
*
* Creates a slave configuration object for the given \a alias and \a position
* tuple and returns it. If a configuration with the same \a alias and \a
* position already exists, it will be re-used. In the latter case, the given
* vendor ID and product code are compared to the stored ones. On mismatch, an
* error message is raised and the function returns \a NULL.
*
* Slaves are addressed with the \a alias and \a position parameters.
* - If \a alias is zero, \a position is interpreted as the desired slave's
* ring position.
* - If \a alias is non-zero, it matches a slave with the given alias. In this
* case, \a position is interpreted as ring offset, starting from the
* aliased slave, so a position of zero means the aliased slave itself and a
* positive value matches the n-th slave behind the aliased one.
*
* If the slave with the given address is found during the configuration,
* its vendor ID and product code are matched against the given value. On
* mismatch, the slave is not configured and an error message is raised.
*
* If different slave configurations are pointing to the same slave during
* configuration, a warning is raised and only the first configuration is
* applied.
*
* This method allocates memory and should be called in non-realtime context
* before ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \retval >0 Pointer to the slave configuration structure.
* \retval NULL in the error case.
*/
EC_PUBLIC_API 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
);
*
* If this method is not called for a certain master, or if the slave
* configuration pointer is NULL, then the first slave with DC functionality
* will provide the reference clock.
*
* \apiusage{master_idle,blocking}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_master_select_reference_clock(
ec_master_t *master,
ec_slave_config_t *sc
* reference slave (or NULL). */
);
*
* No memory is allocated on the heap in this function.
*
* \apiusage{master_any,rt_safe}
*
* \attention The pointer to this structure must point to a valid variable.
*
* \return 0 in case of success, else < 0
*/
EC_PUBLIC_API int ecrt_master(
ec_master_t *master,
ec_master_info_t *master_info
information */
);
*
* No memory is allocated on the heap in this function.
*
* \apiusage{master_any,rt_safe}
*
* \attention The pointer to this structure must point to a valid variable.
*
* \return 0 in case of success, else < 0
*/
EC_PUBLIC_API int ecrt_master_scan_progress(
ec_master_t *master,
ec_master_scan_progress_t *progress
the progress information. */
);
*
* Tries to find the slave with the given ring position. The obtained
* information is stored in a structure. No memory is allocated on the heap in
* this function.
*
* \apiusage{master_any,blocking}
*
* \attention The pointer to this structure must point to a valid variable.
*
* \return 0 in case of success, else < 0
*/
EC_PUBLIC_API int ecrt_master_get_slave(
ec_master_t *master,
uint16_t slave_position,
ec_slave_info_t *slave_info
information */
);
#ifndef __KERNEL__
*
* Fills a given ec_sync_info_t structure with the attributes of a sync
* manager. The \a pdos field of the return value is left empty. Use
* ecrt_master_get_pdo() to get the PDO information.
*
* \apiusage{master_any,blocking}
*
* \return zero on success, else non-zero
*/
EC_PUBLIC_API int ecrt_master_get_sync_manager(
ec_master_t *master,
uint16_t slave_position,
uint8_t sync_index,
than #EC_MAX_SYNC_MANAGERS. */
ec_sync_info_t *sync
);
*
* Fills a given ec_pdo_info_t structure with the attributes of a currently
* assigned PDO of the given sync manager. The \a entries field of the return
* value is left empty. Use ecrt_master_get_pdo_entry() to get the PDO
* entry information.
*
* \apiusage{master_any,blocking}
*
* \retval zero on success, else non-zero
*/
EC_PUBLIC_API int ecrt_master_get_pdo(
ec_master_t *master,
uint16_t slave_position,
uint8_t sync_index,
than #EC_MAX_SYNC_MANAGERS. */
uint16_t pos,
ec_pdo_info_t *pdo
);
*
* Fills a given ec_pdo_entry_info_t structure with the attributes of a
* currently mapped PDO entry of the given PDO.
*
* \apiusage{master_any,blocking}
*
* \retval zero on success, else non-zero
*/
EC_PUBLIC_API int ecrt_master_get_pdo_entry(
ec_master_t *master,
uint16_t slave_position,
uint8_t sync_index,
than #EC_MAX_SYNC_MANAGERS. */
uint16_t pdo_pos,
uint16_t entry_pos,
ec_pdo_entry_info_t *entry
);
#endif
*
* This request is processed by the master state machine. This method blocks,
* until the request has been processed and may not be called in realtime
* context.
*
* \apiusage{master_any,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_master_sdo_download(
ec_master_t *master,
uint16_t slave_position,
uint16_t index,
uint8_t subindex,
const uint8_t *data,
size_t data_size,
uint32_t *abort_code
);
* access.
*
* This request is processed by the master state machine. This method blocks,
* until the request has been processed and may not be called in realtime
* context.
*
* \apiusage{master_any,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_master_sdo_download_complete(
ec_master_t *master,
uint16_t slave_position,
uint16_t index,
const uint8_t *data,
size_t data_size,
uint32_t *abort_code
);
*
* This request is processed by the master state machine. This method blocks,
* until the request has been processed and may not be called in realtime
* context.
*
* \apiusage{master_any,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API 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
);
*
* Starts writing an IDN and blocks until the request was processed, or an
* error occurred.
*
* \apiusage{master_any,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_master_write_idn(
ec_master_t *master,
uint16_t slave_position,
uint8_t drive_no,
uint16_t idn,
const uint8_t *data,
size_t data_size,
uint16_t *error_code
can be stored. */
);
*
* Starts reading an IDN and blocks until the request was processed, or an
* error occurred.
*
* \apiusage{master_any,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_master_read_idn(
ec_master_t *master,
uint16_t slave_position,
uint8_t drive_no,
uint16_t idn,
uint8_t *target,
stored. */
size_t target_size,
size_t *result_size,
uint16_t *error_code
can be stored. */
);
*
* This function tells the master that the configuration phase is finished and
* the realtime operation will begin. The function allocates internal memory
* for the domains and calculates the logical FMMU addresses for domain
* members. It tells the master state machine that the configuration is
* now to be applied to the network.
*
* \apiusage{master_idle,blocking}
*
* \attention After this function has been called, the realtime application is
* in charge of cyclically calling ecrt_master_send() and
* ecrt_master_receive() to ensure network communication. Before calling this
* function, the master thread is responsible for that, so these functions may
* not be called! The method itself allocates memory and should not be called
* in realtime context.
*
* \return 0 in case of success, else < 0
*/
EC_PUBLIC_API int ecrt_master_activate(
ec_master_t *master
);
*
* Removes the master configuration. All objects created by
* ecrt_master_create_domain(), ecrt_master_slave_config(), ecrt_domain_data()
* ecrt_slave_config_create_sdo_request() and
* ecrt_slave_config_create_voe_handler() are freed, so pointers to them
* become invalid.
*
* \apiusage{master_op,blocking}
*
* This method should not be called in realtime context.
* \return 0 on success, otherwise negative error code.
* \retval 0 Success.
* \retval -EINVAL Master has not been activated before.
*/
EC_PUBLIC_API int ecrt_master_deactivate(
ec_master_t *master
);
*
* This information helps the master to decide, how much data can be appended
* to a frame by the master state machine. When the master is configured with
* --enable-hrtimers, this is used to calculate the scheduling of the master
* thread.
*
* \apiusage{master_idle,blocking}
*
* \retval 0 on success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_master_set_send_interval(
ec_master_t *master,
size_t send_interval
);
*
* This method takes all datagrams, that have been queued for transmission,
* puts them into frames, and passes them to the Ethernet device for sending.
*
* Has to be called cyclically by the application after ecrt_master_activate()
* has returned.
*
* \apiusage{master_op,rt_safe}
*
* \return Zero on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_master_send(
ec_master_t *master
);
*
* Queries the network device for received frames by calling the interrupt
* service routine. Extracts received datagrams and dispatches the results to
* the datagram objects in the queue. Received datagrams, and the ones that
* timed out, will be marked, and dequeued.
*
* Has to be called cyclically by the realtime application after
* ecrt_master_activate() has returned.
*
* \apiusage{master_op,rt_safe}
*
* \return Zero on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_master_receive(
ec_master_t *master
);
#ifdef __KERNEL__
*
* This method has to be called in the send callback function passed via
* ecrt_master_callbacks() to allow the sending of non-application datagrams.
*
* \apiusage{master_op,rt_safe}
*
* \return Zero on success, otherwise negative error code.
* \retval -EAGAIN Lock could not be acquired, try again later.
*/
int ecrt_master_send_ext(
ec_master_t *master
);
#endif
*
* Stores the master state information in the given \a state structure.
*
* This method returns a global state. For the link-specific states in a
* redundant network topology, use the ecrt_master_link_state() method.
*
* \apiusage{master_any,rt_safe}
*
* \return Zero on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_master_state(
const ec_master_t *master,
ec_master_state_t *state
);
*
* Stores the link state information in the given \a state structure.
*
* \apiusage{master_any,rt_safe}
*
* \return Zero on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_master_link_state(
const ec_master_t *master,
unsigned int dev_idx,
first backup device, ...). */
ec_master_link_state_t *state
*/
);
*
* The master has to know the application's time when operating slaves with
* distributed clocks. The time is not incremented by the master itself, so
* this method has to be called cyclically.
*
* \attention The time passed to this method is used to calculate the phase of
* the slaves' SYNC0/1 interrupts. It should be called constantly at the same
* point of the realtime cycle. So it is recommended to call it at the start
* of the calculations to avoid deviancies due to changing execution times.
* Avoid calling this method before the realtime cycle is established.
*
* The time is used when setting the slaves' <tt>System Time Offset</tt> and
* <tt>Cyclic Operation Start Time</tt> registers and when synchronizing the
* DC reference clock to the application time via
* ecrt_master_sync_reference_clock().
*
* The time is defined as nanoseconds from 2000-01-01 00:00. Converting an
* epoch time can be done with the EC_TIMEVAL2NANO() macro, but is not
* necessary, since the absolute value is not of any interest.
*
* \apiusage{master_op,rt_safe}
*
* \return Zero on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_master_application_time(
ec_master_t *master,
uint64_t app_time
);
*
* The reference clock will by synchronized to the application time provided
* by the last call off ecrt_master_application_time().
*
* \apiusage{master_op,rt_safe}
*
* \return Zero on success, otherwise negative error code.
* \retval 0 Success.
* \retval -ENXIO No reference clock found.
*/
EC_PUBLIC_API int ecrt_master_sync_reference_clock(
ec_master_t *master
);
*
* The reference clock will by synchronized to the time passed in the
* sync_time parameter.
*
* Has to be called by the application after ecrt_master_activate()
* has returned.
*
* \apiusage{master_op,rt_safe}
*
* \return Zero on success, otherwise negative error code.
* \retval 0 Success.
* \retval -ENXIO No reference clock found.
*/
EC_PUBLIC_API int ecrt_master_sync_reference_clock_to(
ec_master_t *master,
uint64_t sync_time
);
*
* All slave clocks synchronized to the reference clock.
*
* Has to be called by the application after ecrt_master_activate()
* has returned.
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
* \retval 0 Success.
* \retval -ENXIO No reference clock found.
*/
EC_PUBLIC_API int ecrt_master_sync_slave_clocks(
ec_master_t *master
);
*
* This method can be used to synchronize the master to the reference clock.
*
* The reference clock system time is queried via the
* ecrt_master_sync_slave_clocks() method, that reads the system time of the
* reference clock and writes it to the slave clocks (so be sure to call it
* cyclically to get valid data).
*
* \attention The returned time is the system time of the reference clock
* minus the transmission delay of the reference clock.
*
* Calling this method makes only sense in realtime context (after master
* activation), when the ecrt_master_sync_slave_clocks() method is called
* cyclically.
*
* \apiusage{master_op,rt_safe}
*
* \retval 0 success, system time was written into \a time.
* \retval -ENXIO No reference clock found.
* \retval -EIO Slave synchronization datagram was not received.
*/
EC_PUBLIC_API int ecrt_master_reference_clock_time(
const ec_master_t *master,
uint32_t *time
);
*
* The datagram broadcast-reads all "System time difference" registers (\a
* 0x092c) to get an upper estimation of the DC synchrony. The result can be
* checked with the ecrt_master_sync_monitor_process() method.
*
* \apiusage{master_op,rt_safe}
*
* \return Zero on success, otherwise a negative error code.
*/
EC_PUBLIC_API int ecrt_master_sync_monitor_queue(
ec_master_t *master
);
*
* If the sync monitoring datagram was sent before with
* ecrt_master_sync_monitor_queue(), the result can be queried with this
* method.
*
* \apiusage{master_op,rt_safe}
*
* \return Upper estimation of the maximum time difference in ns, -1 on error.
* \retval (uint32_t)-1 Error.
*/
EC_PUBLIC_API uint32_t ecrt_master_sync_monitor_process(
const ec_master_t *master
);
*
* Via this method, the application can tell the master to bring all slaves to
* OP state. In general, this is not necessary, because it is automatically
* done by the master. But with special slaves, that can be reconfigured by
* the vendor during runtime, it can be useful.
*
* Calling this method only makes sense in realtime context (after
* activation), because slaves will not be configured before.
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_master_reset(
ec_master_t *master
);
* Slave configuration methods
****************************************************************************/
*
* Sets the direction of a sync manager. This overrides the direction bits
* from the default control register from SII.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return zero on success, else non-zero
*/
EC_PUBLIC_API int ecrt_slave_config_sync_manager(
ec_slave_config_t *sc,
uint8_t sync_index,
than #EC_MAX_SYNC_MANAGERS. */
ec_direction_t direction,
ec_watchdog_mode_t watchdog_mode
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_slave_config_watchdog(
ec_slave_config_t *sc,
uint16_t watchdog_divider,
0x0400). Used as a base unit for all
slave watchdogs^. If set to zero, the
value is not written, so the default is
used. */
uint16_t watchdog_intervals
manager watchdog (register 0x0420). If
set to zero, the value is not written,
so the default is used. */
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \see ecrt_slave_config_pdos()
* \return zero on success, else non-zero
*/
EC_PUBLIC_API int ecrt_slave_config_pdo_assign_add(
ec_slave_config_t *sc,
uint8_t sync_index,
than #EC_MAX_SYNC_MANAGERS. */
uint16_t index
);
*
* This can be called before assigning PDOs via
* ecrt_slave_config_pdo_assign_add(), to clear the default assignment of a
* sync manager.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \see ecrt_slave_config_pdos()
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_slave_config_pdo_assign_clear(
ec_slave_config_t *sc,
uint8_t sync_index
than #EC_MAX_SYNC_MANAGERS. */
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \see ecrt_slave_config_pdos()
* \return zero on success, else non-zero
*/
EC_PUBLIC_API int ecrt_slave_config_pdo_mapping_add(
ec_slave_config_t *sc,
uint16_t pdo_index,
uint16_t entry_index,
mapping. */
uint8_t entry_subindex,
PDO's mapping. */
uint8_t entry_bit_length
);
*
* This can be called before mapping PDO entries via
* ecrt_slave_config_pdo_mapping_add(), to clear the default mapping.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \see ecrt_slave_config_pdos()
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_slave_config_pdo_mapping_clear(
ec_slave_config_t *sc,
uint16_t pdo_index
);
*
* This function is a convenience wrapper for the functions
* ecrt_slave_config_sync_manager(), ecrt_slave_config_pdo_assign_clear(),
* ecrt_slave_config_pdo_assign_add(), ecrt_slave_config_pdo_mapping_clear()
* and ecrt_slave_config_pdo_mapping_add(), that are better suitable for
* automatic code generation.
*
* The following example shows, how to specify a complete configuration,
* including the PDO mappings. With this information, the master is able to
* reserve the complete process data, even if the slave is not present at
* configuration time:
*
* \code
* ec_pdo_entry_info_t el3162_channel1[] = {
* {0x3101, 1, 8}, // status
* {0x3101, 2, 16} // value
* };
*
* ec_pdo_entry_info_t el3162_channel2[] = {
* {0x3102, 1, 8}, // status
* {0x3102, 2, 16} // value
* };
*
* ec_pdo_info_t el3162_pdos[] = {
* {0x1A00, 2, el3162_channel1},
* {0x1A01, 2, el3162_channel2}
* };
*
* ec_sync_info_t el3162_syncs[] = {
* {2, EC_DIR_OUTPUT},
* {3, EC_DIR_INPUT, 2, el3162_pdos},
* {0xff}
* };
*
* if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_syncs)) {
* // handle error
* }
* \endcode
*
* The next example shows, how to configure the PDO assignment only. The
* entries for each assigned PDO are taken from the PDO's default mapping.
* Please note, that PDO entry registration will fail, if the PDO
* configuration is left empty and the slave is offline.
*
* \code
* ec_pdo_info_t pdos[] = {
* {0x1600}, // Channel 1
* {0x1601} // Channel 2
* };
*
* ec_sync_info_t syncs[] = {
* {3, EC_DIR_INPUT, 2, pdos},
* };
*
* if (ecrt_slave_config_pdos(slave_config_ana_in, 1, syncs)) {
* // handle error
* }
* \endcode
*
* Processing of \a syncs will stop, if
* - the number of processed items reaches \a n_syncs, or
* - the \a index member of an ec_sync_info_t item is 0xff. In this case,
* \a n_syncs should set to a number greater than the number of list items;
* using EC_END is recommended.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return zero on success, else non-zero
*/
EC_PUBLIC_API int ecrt_slave_config_pdos(
ec_slave_config_t *sc,
unsigned int n_syncs,
\a syncs. */
const ec_sync_info_t syncs[]
configurations. */
);
*
* Searches the assigned PDOs for the given PDO entry. An error is raised, if
* the given entry is not mapped. Otherwise, the corresponding sync manager
* and FMMU configurations are provided for slave configuration and the
* respective sync manager's assigned PDOs are appended to the given domain,
* if not already done. The offset of the requested PDO entry's data inside
* the domain's process data is returned. Optionally, the PDO entry bit
* position (0-7) can be retrieved via the \a bit_position output parameter.
* This pointer may be \a NULL, in this case an error is raised if the PDO
* entry does not byte-align.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \retval >=0 Success: Offset of the PDO entry's process data.
* \retval <0 Error code.
*/
EC_PUBLIC_API 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
is desired */
);
*
* Similar to ecrt_slave_config_reg_pdo_entry(), but not using PDO indices but
* offsets in the PDO mapping, because PDO entry indices may not be unique
* inside a slave's PDO mapping. An error is raised, if
* one of the given positions is out of range.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \retval >=0 Success: Offset of the PDO entry's process data.
* \retval <0 Error code.
*/
EC_PUBLIC_API 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
is desired */
);
*
* Sets the AssignActivate word and the cycle and shift times for the sync
* signals.
*
* The AssignActivate word is vendor-specific and can be taken from the XML
* device description file (Device -> Dc -> AssignActivate). Set this to zero,
* if the slave shall be operated without distributed clocks (default).
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \attention The \a sync1_shift time is ignored.
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int 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
);
*
* An SDO configuration is stored in the slave configuration object and is
* downloaded to the slave whenever the slave is being configured by the
* master. This usually happens once on master activation, but can be repeated
* subsequently, for example after the slave's power supply failed.
*
* \attention The SDOs for PDO assignment (\p 0x1C10 - \p 0x1C2F) and PDO
* mapping (\p 0x1600 - \p 0x17FF and \p 0x1A00 - \p 0x1BFF) should not be
* configured with this function, because they are part of the slave
* configuration done by the master. Please use ecrt_slave_config_pdos() and
* friends instead.
*
* This is the generic function for adding an SDO configuration. Please note
* that the this function does not do any endianness correction. If
* datatype-specific functions are needed (that automatically correct the
* endianness), have a look at ecrt_slave_config_sdo8(),
* ecrt_slave_config_sdo16() and ecrt_slave_config_sdo32().
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_sdo(
ec_slave_config_t *sc,
uint16_t index,
uint8_t subindex,
const uint8_t *data,
size_t size
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \see ecrt_slave_config_sdo().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_sdo8(
ec_slave_config_t *sc,
uint16_t sdo_index,
uint8_t sdo_subindex,
uint8_t value
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \see ecrt_slave_config_sdo().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_sdo16(
ec_slave_config_t *sc,
uint16_t sdo_index,
uint8_t sdo_subindex,
uint16_t value
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \see ecrt_slave_config_sdo().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_sdo32(
ec_slave_config_t *sc,
uint16_t sdo_index,
uint8_t sdo_subindex,
uint32_t value
);
*
* The SDO data are transferred via CompleteAccess. Data for the first
* subindex (0) have to be included.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \see ecrt_slave_config_sdo().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_complete_sdo(
ec_slave_config_t *sc,
uint16_t index,
const uint8_t *data,
size_t size
);
*
* The initial size is zero, so all messages will be dropped. This method can
* be called even after master activation, but it will clear the ring buffer!
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return 0 on success, or negative error code.
*/
EC_PUBLIC_API int ecrt_slave_config_emerg_size(
ec_slave_config_t *sc,
size_t elements
);
*
* A record consists of 8 bytes:
*
* Byte 0-1: Error code (little endian)
* Byte 2: Error register
* Byte 3-7: Data
*
* Calling this method makes only sense in realtime context (after master
* activation).
*
* \return 0 on success (record popped), or negative error code (i. e.
* -ENOENT, if ring is empty).
*
* \apiusage{master_op,any_context}
*/
EC_PUBLIC_API int ecrt_slave_config_emerg_pop(
ec_slave_config_t *sc,
uint8_t *target
EC_COE_EMERGENCY_MSG_SIZE bytes). */
);
*
* Calling this method makes only sense in realtime context (after master
* activation).
*
* \apiusage{master_op,any_context}
*
* \return 0 on success, or negative error code.
*
*/
EC_PUBLIC_API int ecrt_slave_config_emerg_clear(
ec_slave_config_t *sc
);
*
* The overrun counter will be incremented when a CoE emergency message could
* not be stored in the ring buffer and had to be dropped. Call
* ecrt_slave_config_emerg_clear() to reset the counter.
*
* Calling this method makes only sense in realtime context (after master
* activation).
*
* \apiusage{master_op,any_context}
*
* \return Number of overruns since last clear, or negative error code.
*
*/
EC_PUBLIC_API int ecrt_slave_config_emerg_overruns(
const ec_slave_config_t *sc
);
*
* The created SDO request object is freed automatically when the master is
* released.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return New SDO request, or NULL on error.
*/
EC_PUBLIC_API ec_sdo_request_t *ecrt_slave_config_create_sdo_request(
ec_slave_config_t *sc,
uint16_t index,
uint8_t subindex,
size_t size
);
*
* The created SoE request object is freed automatically when the master is
* released.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return New SoE request, or NULL on error.
*/
EC_PUBLIC_API 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
);
* operation.
*
* The number of VoE handlers per slave configuration is not limited, but
* usually it is enough to create one for sending and one for receiving, if
* both can be done simultaneously.
*
* The created VoE handler object is freed automatically when the master is
* released.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return New VoE handler, or NULL on error.
*/
EC_PUBLIC_API ec_voe_handler_t *ecrt_slave_config_create_voe_handler(
ec_slave_config_t *sc,
size_t size
);
* realtime operation.
*
* This interface should not be used to take over master functionality,
* instead it is intended for debugging and monitoring reasons.
*
* The created register request object is freed automatically when the master
* is released.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \return New register request, or NULL on error.
*/
EC_PUBLIC_API ec_reg_request_t *ecrt_slave_config_create_reg_request(
ec_slave_config_t *sc,
size_t size
);
*
* Stores the state information in the given \a state structure. The state
* information is updated by the master state machine, so it may take a few
* cycles, until it changes.
*
* \attention If the state of process data exchange shall be monitored in
* realtime, ecrt_domain_state() should be used.
*
* \apiusage{master_op,rt_safe}
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_state(
const ec_slave_config_t *sc,
ec_slave_config_state_t *state
);
*
* A configuration for a Sercos-over-EtherCAT IDN is stored in the slave
* configuration object and is written to the slave whenever the slave is
* being configured by the master. This usually happens once on master
* activation, but can be repeated subsequently, for example after the slave's
* power supply failed.
*
* The \a idn parameter can be separated into several sections:
* - Bit 15: Standard data (0) or Product data (1)
* - Bit 14 - 12: Parameter set (0 - 7)
* - Bit 11 - 0: Data block number (0 - 4095)
*
* Please note that the this function does not do any endianness correction.
* Multi-byte data have to be passed in EtherCAT endianness (little-endian).
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_idn(
ec_slave_config_t *sc,
uint8_t drive_no,
uint16_t idn,
ec_al_state_t state,
SAFEOP). */
const uint8_t *data,
size_t size
);
*
* Feature flags are a generic way to configure slave-specific behavior.
*
* Multiple calls with the same slave configuration and key will overwrite the
* configuration.
*
* The following flags may be available:
* - AssignToPdi: Zero (default) keeps the slave information interface (SII)
* assigned to EtherCAT (except during transition to PREOP). Non-zero
* assigns the SII to the slave controller side before going to PREOP and
* leaves it there until a write command happens.
* - WaitBeforeSAFEOPms: Number of milliseconds to wait before commanding the
* transition from PREOP to SAFEOP. This can be used as a workaround for
* slaves that need a little time to initialize.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_flag(
ec_slave_config_t *sc,
const char *key,
int32_t value
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* The MAC address is stored in the slave configuration object and will be
* written to the slave during the configuration process.
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_eoe_mac_address(
ec_slave_config_t *sc,
const unsigned char *mac_address
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* The IP address is stored in the slave configuration object and will be
* written to the slave during the configuration process.
*
* The IP address is passed by-value as a `struct in_addr`. This structure
* contains the 32-bit IPv4 address in network byte order (big endian).
*
* A string-represented IPv4 address can be converted to a `struct in_addr`
* for example via the POSIX function `inet_pton()` (see man 3 inet_pton):
*
* \code{.c}
* #include <arpa/inet.h>
* struct in_addr addr;
* if (inet_aton("192.168.0.1", &addr) == 0) {
* fprintf(stderr, "Failed to convert IP address.\n");
* return -1;
* }
* if (ecrt_slave_config_eoe_ip_address(sc, addr)) {
* fprintf(stderr, "Failed to set IP address.\n");
* return -1;
* }
* \endcode
*
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_eoe_ip_address(
ec_slave_config_t *sc,
struct in_addr ip_address
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* The subnet mask is stored in the slave configuration object and will be
* written to the slave during the configuration process.
*
* The subnet mask is passed by-value as a `struct in_addr`. This structure
* contains the 32-bit mask in network byte order (big endian).
*
* See ecrt_slave_config_eoe_ip_address() on how to convert string-coded masks
* to `struct in_addr`.
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_eoe_subnet_mask(
ec_slave_config_t *sc,
struct in_addr subnet_mask
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* The gateway address is stored in the slave configuration object and will be
* written to the slave during the configuration process.
*
* The address is passed by-value as a `struct in_addr`. This structure
* contains the 32-bit IPv4 address in network byte order (big endian).
*
* See ecrt_slave_config_eoe_ip_address() on how to convert string-coded IPv4
* addresses to `struct in_addr`.
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_eoe_default_gateway(
ec_slave_config_t *sc,
struct in_addr gateway_address
);
* operation.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* The DNS server address is stored in the slave configuration object and will
* be written to the slave during the configuration process.
*
* The address is passed by-value as a `struct in_addr`. This structure
* contains the 32-bit IPv4 address in network byte order (big endian).
*
* See ecrt_slave_config_eoe_ip_address() on how to convert string-coded IPv4
* addresses to `struct in_addr`.
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_eoe_dns_address(
ec_slave_config_t *sc,
struct in_addr dns_address
);
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* The host name is stored in the slave configuration object and will
* be written to the slave during the configuration process.
*
* The maximum size of the host name is 32 bytes (including the zero
* terminator).
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_eoe_hostname(
ec_slave_config_t *sc,
const char *name
);
*
* Change the maximum allowed time for a slave to make an application-layer
* state transition for the given state transition (for example from PREOP to
* SAFEOP). The default values are defined in ETG.2000.
*
* A timeout value of zero ms will restore the default value.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*
* \retval 0 Success.
* \retval <0 Error code.
*/
EC_PUBLIC_API int ecrt_slave_config_state_timeout(
ec_slave_config_t *sc,
ec_al_state_t from_state,
ec_al_state_t to_state,
unsigned int timeout_ms
);
* Domain methods
****************************************************************************/
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \see ecrt_slave_config_reg_pdo_entry()
*
* \attention The registration array has to be terminated with an empty
* structure, or one with the \a index field set to zero!
*
* \apiusage{master_idle,blocking}
*
* \return 0 on success, else non-zero.
*/
EC_PUBLIC_API int ecrt_domain_reg_pdo_entry_list(
ec_domain_t *domain,
const ec_pdo_entry_reg_t *pdo_entry_regs
registrations. */
);
*
* The domain size is calculated after master activation.
*
* \apiusage{master_op,rt_safe}
*
* \return Size of the process data image, or a negative error code.
*/
EC_PUBLIC_API size_t ecrt_domain_size(
const ec_domain_t *domain
);
#ifdef __KERNEL__
*
* Call this after all PDO entries have been registered and before activating
* the master.
*
* The size of the allocated memory must be at least ecrt_domain_size(), after
* all PDO entries have been registered.
*
* This method has to be called in non-realtime context before
* ecrt_master_activate().
*
* \apiusage{master_idle,blocking}
*/
void ecrt_domain_external_memory(
ec_domain_t *domain,
uint8_t *memory
data in. */
);
#endif
*
* - In kernel context: If external memory was provided with
* ecrt_domain_external_memory(), the returned pointer will contain the
* address of that memory. Otherwise it will point to the internally allocated
* memory. In the latter case, this method may not be called before
* ecrt_master_activate().
*
* - In userspace context: This method has to be called after
* ecrt_master_activate() to get the mapped domain process data memory.
*
* \apiusage{master_op,rt_safe}
*
* \return Pointer to the process data memory.
*/
EC_PUBLIC_API uint8_t *ecrt_domain_data(
const ec_domain_t *domain
);
*
* Evaluates the working counters of the received datagrams and outputs
* statistics, if necessary. This must be called after ecrt_master_receive()
* is expected to receive the domain datagrams in order to make
* ecrt_domain_state() return the result of the last process data exchange.
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_domain_process(
ec_domain_t *domain
);
*
* Call this function to mark the domain's datagrams for exchanging at the
* next call of ecrt_master_send().
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_domain_queue(
ec_domain_t *domain
);
*
* Stores the domain state in the given \a state structure.
*
* Using this method, the process data exchange can be monitored in realtime.
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_domain_state(
const ec_domain_t *domain,
ec_domain_state_t *state
information. */
);
* SDO request methods.
****************************************************************************/
*
* \attention If the SDO index and/or subindex is changed while
* ecrt_sdo_request_state() returns EC_REQUEST_BUSY, this may lead to
* unexpected results.
*
* This method is meant to be called in realtime context (after master
* activation). To initialize the SDO request, the index and subindex can be
* set via ecrt_slave_config_create_sdo_request().
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_sdo_request_index(
ec_sdo_request_t *req,
uint16_t index,
uint8_t subindex
);
*
* If the request cannot be processed in the specified time, if will be marked
* as failed.
*
* The timeout is permanently stored in the request object and is valid until
* the next call of this method.
*
* The timeout should be defined in non-realtime context, but can also be
* changed afterwards.
*
* \apiusage{master_any,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_sdo_request_timeout(
ec_sdo_request_t *req,
uint32_t timeout
timeout. */
);
*
* This function returns a pointer to the request's internal SDO data memory.
*
* - After a read operation was successful, integer data can be evaluated
* using the EC_READ_*() macros as usual. Example:
* \code
* uint16_t value = EC_READ_U16(ecrt_sdo_request_data(sdo)));
* \endcode
* - If a write operation shall be triggered, the data have to be written to
* the internal memory. Use the EC_WRITE_*() macros, if you are writing
* integer data. Be sure, that the data fit into the memory. The memory size
* is a parameter of ecrt_slave_config_create_sdo_request().
* \code
* EC_WRITE_U16(ecrt_sdo_request_data(sdo), 0xFFFF);
* \endcode
*
* \attention The return value can be invalid during a read operation, because
* the internal SDO data memory could be re-allocated if the read SDO data do
* not fit inside.
*
* This method is meant to be called in realtime context (after master
* activation), but can also be used to initialize data before.
*
* \apiusage{master_any,rt_safe}
*
* \return Pointer to the internal SDO data memory.
*
*/
EC_PUBLIC_API uint8_t *ecrt_sdo_request_data(
const ec_sdo_request_t *req
);
*
* When the SDO request is created, the data size is set to the size of the
* reserved memory. After a read operation the size is set to the size of the
* read data. The size is not modified in any other situation.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_any,rt_safe}
*
* \return SDO data size in bytes.
*
*/
EC_PUBLIC_API size_t ecrt_sdo_request_data_size(
const ec_sdo_request_t *req
);
*
* The user-space implementation fetches incoming data and stores the received
* data size in the request object, so the request is not const.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return Request state.
*
*/
EC_PUBLIC_API ec_request_state_t ecrt_sdo_request_state(
#ifdef __KERNEL__
const
#endif
ec_sdo_request_t *req
);
*
* \attention This method may not be called while ecrt_sdo_request_state()
* returns EC_REQUEST_BUSY.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
* \retval -EINVAL Invalid input data, e.g. data size == 0.
* \retval -ENOBUFS Reserved memory in ecrt_slave_config_create_sdo_request()
* too small.
*/
EC_PUBLIC_API int ecrt_sdo_request_write(
ec_sdo_request_t *req
);
*
* \attention This method may not be called while ecrt_sdo_request_state()
* returns EC_REQUEST_BUSY.
*
* \attention After calling this function, the return value of
* ecrt_sdo_request_data() must be considered as invalid while
* ecrt_sdo_request_state() returns EC_REQUEST_BUSY.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_sdo_request_read(
ec_sdo_request_t *req
);
* SoE request methods.
****************************************************************************/
*
* \attention If the drive number and/or IDN is changed while
* ecrt_soe_request_state() returns EC_REQUEST_BUSY, this may lead to
* unexpected results.
*
* This method is meant to be called in realtime context (after master
* activation). To initialize the SoE request, the drive_no and IDN can be
* set via ecrt_slave_config_create_soe_request().
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_soe_request_idn(
ec_soe_request_t *req,
uint8_t drive_no,
uint16_t idn
);
*
* If the request cannot be processed in the specified time, if will be marked
* as failed.
*
* The timeout is permanently stored in the request object and is valid until
* the next call of this method.
*
* The timeout should be defined in non-realtime context, but can also be
* changed afterwards.
*
* \apiusage{master_any,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_soe_request_timeout(
ec_soe_request_t *req,
uint32_t timeout
timeout. */
);
*
* This function returns a pointer to the request's internal IDN data memory.
*
* - After a read operation was successful, integer data can be evaluated
* using the EC_READ_*() macros as usual. Example:
* \code
* uint16_t value = EC_READ_U16(ecrt_soe_request_data(idn_req)));
* \endcode
* - If a write operation shall be triggered, the data have to be written to
* the internal memory. Use the EC_WRITE_*() macros, if you are writing
* integer data. Be sure, that the data fit into the memory. The memory size
* is a parameter of ecrt_slave_config_create_soe_request().
* \code
* EC_WRITE_U16(ecrt_soe_request_data(idn_req), 0xFFFF);
* \endcode
*
* \attention The return value can be invalidated during a read operation,
* because the internal IDN data memory could be re-allocated if the read IDN
* data do not fit inside.
*
* This method is meant to be called in realtime context (after master
* activation), but can also be used to initialize data before.
*
* \apiusage{master_any,rt_safe}
*
* \return Pointer to the internal IDN data memory.
*
*/
EC_PUBLIC_API uint8_t *ecrt_soe_request_data(
const ec_soe_request_t *req
);
*
* When the SoE request is created, the data size is set to the size of the
* reserved memory. After a read operation the size is set to the size of the
* read data. The size is not modified in any other situation.
*
* \apiusage{master_any,rt_safe}
*
* \return IDN data size in bytes.
*/
EC_PUBLIC_API size_t ecrt_soe_request_data_size(
const ec_soe_request_t *req
);
*
* \return Request state.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* In the user-space implementation, the method fetches the size of the
* incoming data, so the request object is not const.
*
* \apiusage{master_op,rt_safe}
*/
EC_PUBLIC_API ec_request_state_t ecrt_soe_request_state(
#ifdef __KERNEL__
const
#endif
ec_soe_request_t *req
);
*
* \attention This method may not be called while ecrt_soe_request_state()
* returns EC_REQUEST_BUSY.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
* \retval -EINVAL Invalid input data, e.g. data size == 0.
* \retval -ENOBUFS Reserved memory in ecrt_slave_config_create_soe_request()
* too small.
*/
EC_PUBLIC_API int ecrt_soe_request_write(
ec_soe_request_t *req
);
*
* \attention This method may not be called while ecrt_soe_request_state()
* returns EC_REQUEST_BUSY.
*
* \attention After calling this function, the return value of
* ecrt_soe_request_data() must be considered as invalid while
* ecrt_soe_request_state() returns EC_REQUEST_BUSY.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_soe_request_read(
ec_soe_request_t *req
);
* VoE handler methods.
****************************************************************************/
*
* A VoE message shall contain a 4-byte vendor ID, followed by a 2-byte vendor
* type at as header. These numbers can be set with this function. The values
* are valid and will be used for future send operations until the next call
* of this method.
*
* This method is meant to be called in non-realtime context (before master
* activation) to initialize the header data, but it is also safe to
* change the header later on in realtime context.
*
* \apiusage{master_any,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_voe_handler_send_header(
ec_voe_handler_t *voe,
uint32_t vendor_id,
uint16_t vendor_type
);
*
* This method can be used to get the received VoE header information after a
* read operation has succeeded.
*
* The header information is stored at the memory given by the pointer
* parameters.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_voe_handler_received_header(
const ec_voe_handler_t *voe,
uint32_t *vendor_id,
uint16_t *vendor_type
);
*
* This function returns a pointer to the VoE handler's internal memory, that
* points to the actual VoE data right after the VoE header (see
* ecrt_voe_handler_send_header()).
*
* - After a read operation was successful, the memory contains the received
* data. The size of the received data can be determined via
* ecrt_voe_handler_data_size().
* - Before a write operation is triggered, the data have to be written to the
* internal memory. Be sure, that the data fit into the memory. The reserved
* memory size is a parameter of ecrt_slave_config_create_voe_handler().
*
* \attention The returned pointer is not necessarily persistent: After a read
* operation, the internal memory may have been reallocated. This can be
* avoided by reserving enough memory via the \a size parameter of
* ecrt_slave_config_create_voe_handler().
*
* \apiusage{master_any,rt_safe}
*
* \return Pointer to the internal memory.
*/
EC_PUBLIC_API uint8_t *ecrt_voe_handler_data(
const ec_voe_handler_t *voe
);
*
* The data size is the size of the VoE data without the header (see
* ecrt_voe_handler_send_header()).
*
* When the VoE handler is created, the data size is set to the size of the
* reserved memory. At a write operation, the data size is set to the number
* of bytes to write. After a read operation the size is set to the size of
* the read data. The size is not modified in any other situation.
*
* \apiusage{master_any,rt_safe}
*
* \return Data size in bytes.
*/
EC_PUBLIC_API size_t ecrt_voe_handler_data_size(
const ec_voe_handler_t *voe
);
*
* After this function has been called, the ecrt_voe_handler_execute() method
* must be called in every realtime cycle as long as it returns
* EC_REQUEST_BUSY. No other operation may be started while the handler is
* busy.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
* \retval -ENOBUFS Reserved memory in ecrt_slave_config_create_voe_handler
* too small.
*/
EC_PUBLIC_API int ecrt_voe_handler_write(
ec_voe_handler_t *voe,
size_t size
);
*
* After this function has been called, the ecrt_voe_handler_execute() method
* must be called in every realtime cycle as long as it returns
* EC_REQUEST_BUSY. No other operation may be started while the handler is
* busy.
*
* The state machine queries the slave's send mailbox for new data to be send
* to the master. If no data appear within the EC_VOE_RESPONSE_TIMEOUT
* (defined in master/voe_handler.c), the operation fails.
*
* On success, the size of the read data can be determined via
* ecrt_voe_handler_data_size(), while the VoE header of the received data
* can be retrieved with ecrt_voe_handler_received_header().
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_voe_handler_read(
ec_voe_handler_t *voe
);
*
* After this function has been called, the ecrt_voe_handler_execute() method
* must be called in every realtime cycle as long as it returns
* EC_REQUEST_BUSY. No other operation may be started while the handler is
* busy.
*
* The state machine queries the slave by sending an empty mailbox. The slave
* fills its data to the master in this mailbox. If no data appear within the
* EC_VOE_RESPONSE_TIMEOUT (defined in master/voe_handler.c), the operation
* fails.
*
* On success, the size of the read data can be determined via
* ecrt_voe_handler_data_size(), while the VoE header of the received data
* can be retrieved with ecrt_voe_handler_received_header().
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
*/
EC_PUBLIC_API int ecrt_voe_handler_read_nosync(
ec_voe_handler_t *voe
);
*
* This method executes the VoE handler. It has to be called in every realtime
* cycle as long as it returns EC_REQUEST_BUSY.
*
* \return Handler state.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
*/
EC_PUBLIC_API ec_request_state_t ecrt_voe_handler_execute(
ec_voe_handler_t *voe
);
* Register request methods.
****************************************************************************/
*
* This function returns a pointer to the request's internal memory.
*
* - After a read operation was successful, integer data can be evaluated
* using the EC_READ_*() macros as usual. Example:
* \code
* uint16_t value = EC_READ_U16(ecrt_reg_request_data(reg_request)));
* \endcode
* - If a write operation shall be triggered, the data have to be written to
* the internal memory. Use the EC_WRITE_*() macros, if you are writing
* integer data. Be sure, that the data fit into the memory. The memory size
* is a parameter of ecrt_slave_config_create_reg_request().
* \code
* EC_WRITE_U16(ecrt_reg_request_data(reg_request), 0xFFFF);
* \endcode
*
* This method is meant to be called in realtime context (after master
* activation), but can also be used to initialize data before.
*
* \apiusage{master_any,rt_safe}
*
* \return Pointer to the internal memory.
*
*/
EC_PUBLIC_API uint8_t *ecrt_reg_request_data(
const ec_reg_request_t *req
);
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return Request state.
*
*/
EC_PUBLIC_API ec_request_state_t ecrt_reg_request_state(
const ec_reg_request_t *req
);
*
* \attention This method may not be called while ecrt_reg_request_state()
* returns EC_REQUEST_BUSY.
*
* \attention The \a size parameter is truncated to the size given at request
* creation.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
* \retval -ENOBUFS Reserved memory in ecrt_slave_config_create_reg_request
* too small.
*/
EC_PUBLIC_API int ecrt_reg_request_write(
ec_reg_request_t *req,
uint16_t address,
size_t size
);
*
* \attention This method may not be called while ecrt_reg_request_state()
* returns EC_REQUEST_BUSY.
*
* \attention The \a size parameter is truncated to the size given at request
* creation.
*
* This method is meant to be called in realtime context (after master
* activation).
*
* \apiusage{master_op,rt_safe}
*
* \return 0 on success, otherwise negative error code.
* \retval -ENOBUFS Reserved memory in ecrt_slave_config_create_reg_request
* too small.
*/
EC_PUBLIC_API int ecrt_reg_request_read(
ec_reg_request_t *req,
uint16_t address,
size_t size
);
* Bitwise read/write macros
****************************************************************************/
*
* \param DATA EtherCAT data pointer
* \param POS bit position
*/
#define EC_READ_BIT(DATA, POS) ((*((uint8_t *) (DATA)) >> (POS)) & 0x01)
*
* \param DATA EtherCAT data pointer
* \param POS bit position
* \param VAL new bit value
*/
#define EC_WRITE_BIT(DATA, POS, VAL) \
do { \
if (VAL) *((uint8_t *) (DATA)) |= (1 << (POS)); \
else *((uint8_t *) (DATA)) &= ~(1 << (POS)); \
} while (0)
* Byte-swapping functions for user space
****************************************************************************/
#ifndef __KERNEL__
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define le16_to_cpu(x) x
#define le32_to_cpu(x) x
#define le64_to_cpu(x) x
#define cpu_to_le16(x) x
#define cpu_to_le32(x) x
#define cpu_to_le64(x) x
#elif __BYTE_ORDER == __BIG_ENDIAN
#define swap16(x) \
((uint16_t)( \
(((uint16_t)(x) & 0x00ffU) << 8) | \
(((uint16_t)(x) & 0xff00U) >> 8) ))
#define swap32(x) \
((uint32_t)( \
(((uint32_t)(x) & 0x000000ffUL) << 24) | \
(((uint32_t)(x) & 0x0000ff00UL) << 8) | \
(((uint32_t)(x) & 0x00ff0000UL) >> 8) | \
(((uint32_t)(x) & 0xff000000UL) >> 24) ))
#define swap64(x) \
((uint64_t)( \
(((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
(((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
(((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
(((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
(((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x) & 0xff00000000000000ULL) >> 56) ))
#define le16_to_cpu(x) swap16(x)
#define le32_to_cpu(x) swap32(x)
#define le64_to_cpu(x) swap64(x)
#define cpu_to_le16(x) swap16(x)
#define cpu_to_le32(x) swap32(x)
#define cpu_to_le64(x) swap64(x)
#endif
#define le16_to_cpup(x) le16_to_cpu(*((uint16_t *)(x)))
#define le32_to_cpup(x) le32_to_cpu(*((uint32_t *)(x)))
#define le64_to_cpup(x) le64_to_cpu(*((uint64_t *)(x)))
#endif
* Read macros
****************************************************************************/
*
* \return EtherCAT data value
*/
#define EC_READ_U8(DATA) \
((uint8_t) *((uint8_t *) (DATA)))
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_S8(DATA) \
((int8_t) *((uint8_t *) (DATA)))
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_U16(DATA) \
((uint16_t) le16_to_cpup((void *) (DATA)))
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_S16(DATA) \
((int16_t) le16_to_cpup((void *) (DATA)))
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_U32(DATA) \
((uint32_t) le32_to_cpup((void *) (DATA)))
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_S32(DATA) \
((int32_t) le32_to_cpup((void *) (DATA)))
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_U64(DATA) \
((uint64_t) le64_to_cpup((void *) (DATA)))
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_S64(DATA) \
((int64_t) le64_to_cpup((void *) (DATA)))
* Floating-point read functions and macros (userspace only)
****************************************************************************/
#ifndef __KERNEL__
*
* \apiusage{master_any,rt_safe}
*
* \param data EtherCAT data pointer
* \return EtherCAT data value
*/
EC_PUBLIC_API float ecrt_read_real(const void *data);
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_REAL(DATA) ecrt_read_real(DATA)
*
* \apiusage{master_any,rt_safe}
*
* \param data EtherCAT data pointer
* \return EtherCAT data value
*/
EC_PUBLIC_API double ecrt_read_lreal(const void *data);
*
* \param DATA EtherCAT data pointer
* \return EtherCAT data value
*/
#define EC_READ_LREAL(DATA) ecrt_read_lreal(DATA)
#endif
* Write macros
****************************************************************************/
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_U8(DATA, VAL) \
do { \
*((uint8_t *)(DATA)) = ((uint8_t) (VAL)); \
} while (0)
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_S8(DATA, VAL) EC_WRITE_U8(DATA, VAL)
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_U16(DATA, VAL) \
do { \
*((uint16_t *) (DATA)) = cpu_to_le16((uint16_t) (VAL)); \
} while (0)
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_S16(DATA, VAL) EC_WRITE_U16(DATA, VAL)
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_U32(DATA, VAL) \
do { \
*((uint32_t *) (DATA)) = cpu_to_le32((uint32_t) (VAL)); \
} while (0)
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_S32(DATA, VAL) EC_WRITE_U32(DATA, VAL)
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_U64(DATA, VAL) \
do { \
*((uint64_t *) (DATA)) = cpu_to_le64((uint64_t) (VAL)); \
} while (0)
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_S64(DATA, VAL) EC_WRITE_U64(DATA, VAL)
* Floating-point write functions and macros (userspace only)
****************************************************************************/
#ifndef __KERNEL__
*
* \apiusage{master_any,rt_safe}
*
* \param data EtherCAT data pointer
* \param value new value
*/
EC_PUBLIC_API void ecrt_write_real(void *data, float value);
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_REAL(DATA, VAL) ecrt_write_real(DATA, VAL)
*
* \apiusage{master_any,rt_safe}
*
* \param data EtherCAT data pointer
* \param value new value
*/
EC_PUBLIC_API void ecrt_write_lreal(void *data, double value);
*
* \param DATA EtherCAT data pointer
* \param VAL new value
*/
#define EC_WRITE_LREAL(DATA, VAL) ecrt_write_lreal(DATA, VAL)
#endif
#ifdef __cplusplus
}
#endif
#endif