fp@104: /****************************************************************************** fp@104: * fp@125: * $Id$ fp@104: * fp@1618: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@1618: * fp@1618: * This file is part of the IgH EtherCAT Master. fp@1618: * fp@1618: * The IgH EtherCAT Master is free software; you can redistribute it fp@1618: * and/or modify it under the terms of the GNU General Public License fp@1619: * as published by the Free Software Foundation; either version 2 of the fp@1619: * License, or (at your option) any later version. fp@1618: * fp@1618: * The IgH EtherCAT Master is distributed in the hope that it will be fp@1618: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1618: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@1618: * GNU General Public License for more details. fp@1618: * fp@1618: * You should have received a copy of the GNU General Public License fp@1618: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@1618: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1618: * fp@1619: * The right to use EtherCAT Technology is granted and comes free of fp@1619: * charge under condition of compatibility of product made by fp@1619: * Licensee. People intending to distribute/sell products based on the fp@1619: * code, have to sign an agreement to guarantee that products using fp@1619: * software based on IgH EtherCAT master stay compatible with the actual fp@1619: * EtherCAT specification (which are released themselves as an open fp@1619: * standard) as the (only) precondition to have the right to use EtherCAT fp@1619: * Technology, IP and trade marks. fp@1619: * fp@1618: *****************************************************************************/ fp@1618: fp@1618: /** fp@1618: \file fp@1618: EtherCAT realtime interface. fp@1618: */ fp@1618: fp@1618: /** fp@1618: \defgroup RealtimeInterface EtherCAT realtime interface fp@1618: EtherCAT interface for realtime modules. fp@1618: This interface is designed for realtime modules that want to use EtherCAT. fp@1618: There are functions to request a master, to map process data, to communicate fp@1618: with slaves via CoE and to configure and activate the bus. fp@1618: */ fp@1618: fp@1618: /*****************************************************************************/ fp@104: fp@125: #ifndef __ECRT_H__ fp@125: #define __ECRT_H__ fp@104: fp@104: #include fp@104: fp@110: #ifdef __KERNEL__ fp@110: #include fp@110: #else fp@110: #include fp@110: #endif fp@110: fp@104: /*****************************************************************************/ fp@104: fp@104: struct ec_master; fp@104: typedef struct ec_master ec_master_t; fp@104: fp@104: struct ec_domain; fp@104: typedef struct ec_domain ec_domain_t; fp@104: fp@104: struct ec_slave; fp@104: typedef struct ec_slave ec_slave_t; fp@104: fp@1618: /** fp@1618: Initialization type for field registrations. fp@1618: This type is used as a parameter for the ec_domain_register_field_list() fp@1618: function. fp@1618: */ fp@1618: fp@104: typedef struct fp@104: { fp@1618: void **data_ptr; /**< address of the process data pointer */ fp@1618: const char *slave_address; /**< slave address string (see fp@1618: ecrt_master_get_slave()) */ fp@1618: const char *vendor_name; /**< vendor name */ fp@1618: const char *product_name; /**< product name */ fp@1618: const char *field_name; /**< data field name */ fp@1618: unsigned int field_index; /**< index in data fields with same name */ fp@1618: unsigned int field_count; /**< number of data fields with same name */ fp@104: } fp@104: ec_field_init_t; fp@104: fp@1618: /****************************************************************************** fp@1618: * Master request functions fp@1618: *****************************************************************************/ fp@104: fp@104: ec_master_t *ecrt_request_master(unsigned int master_index); fp@104: void ecrt_release_master(ec_master_t *master); fp@104: fp@1618: /****************************************************************************** fp@1618: * Master methods fp@1618: *****************************************************************************/ fp@104: fp@1619: void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *), fp@1619: void (*release_cb)(void *), void *cb_data); fp@1619: fp@104: ec_domain_t *ecrt_master_create_domain(ec_master_t *master); fp@138: fp@104: int ecrt_master_activate(ec_master_t *master); fp@104: void ecrt_master_deactivate(ec_master_t *master); fp@138: fp@135: int ecrt_master_fetch_sdo_lists(ec_master_t *master); fp@138: fp@104: void ecrt_master_sync_io(ec_master_t *master); fp@104: void ecrt_master_async_send(ec_master_t *master); fp@104: void ecrt_master_async_receive(ec_master_t *master); fp@106: void ecrt_master_prepare_async_io(ec_master_t *master); fp@138: fp@144: void ecrt_master_run(ec_master_t *master); fp@144: fp@1619: int ecrt_master_start_eoe(ec_master_t *master); fp@1619: fp@104: void ecrt_master_debug(ec_master_t *master, int level); fp@140: void ecrt_master_print(const ec_master_t *master, unsigned int verbosity); fp@138: fp@138: ec_slave_t *ecrt_master_get_slave(const ec_master_t *, const char *); fp@104: fp@1618: /****************************************************************************** fp@1618: * Domain Methods fp@1618: *****************************************************************************/ fp@104: fp@104: ec_slave_t *ecrt_domain_register_field(ec_domain_t *domain, fp@104: const char *address, fp@104: const char *vendor_name, fp@104: const char *product_name, fp@138: void **data_ptr, const char *field_name, fp@104: unsigned int field_index, fp@104: unsigned int field_count); fp@104: int ecrt_domain_register_field_list(ec_domain_t *domain, fp@150: const ec_field_init_t *fields); fp@138: fp@104: void ecrt_domain_queue(ec_domain_t *domain); fp@104: void ecrt_domain_process(ec_domain_t *domain); fp@141: fp@105: int ecrt_domain_state(ec_domain_t *domain); fp@104: fp@1618: /****************************************************************************** fp@1618: * Slave Methods fp@1618: *****************************************************************************/ fp@104: fp@138: int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, uint16_t sdo_index, fp@138: uint8_t sdo_subindex, uint8_t *value); fp@138: int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, uint16_t sdo_index, fp@138: uint8_t sdo_subindex, uint16_t *value); fp@138: int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, uint16_t sdo_index, fp@138: uint8_t sdo_subindex, uint32_t *value); fp@138: int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, uint16_t sdo_index, fp@138: uint8_t sdo_subindex, uint8_t value); fp@138: int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, uint16_t sdo_index, fp@138: uint8_t sdo_subindex, uint16_t value); fp@138: int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, uint16_t sdo_index, fp@138: uint8_t sdo_subindex, uint32_t value); fp@138: int ecrt_slave_sdo_read(ec_slave_t *slave, uint16_t sdo_index, fp@138: uint8_t sdo_subindex, uint8_t *data, size_t *size); fp@138: fp@138: int ecrt_slave_write_alias(ec_slave_t *slave, uint16_t alias); fp@104: fp@1618: /****************************************************************************** fp@1618: * Bitwise read/write macros fp@1618: *****************************************************************************/ fp@1618: fp@1618: /** fp@1618: Read a certain bit of an EtherCAT data byte. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param POS bit position fp@1618: */ fp@1618: fp@1618: #define EC_READ_BIT(DATA, POS) ((*((uint8_t *) (DATA)) >> (POS)) & 0x01) fp@1618: fp@1618: /** fp@1618: Write a certain bit of an EtherCAT data byte. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param POS bit position fp@1618: \param VAL new bit value fp@1618: */ fp@1618: fp@1618: #define EC_WRITE_BIT(DATA, POS, VAL) \ fp@1618: do { \ fp@1618: if (VAL) *((uint8_t *) (DATA)) |= (1 << (POS)); \ fp@1618: else *((uint8_t *) (DATA)) &= ~(1 << (POS)); \ fp@1618: } while (0) fp@1618: fp@1618: /****************************************************************************** fp@1618: * Read macros fp@1618: *****************************************************************************/ fp@1618: fp@1618: /** fp@1618: Read an 8-bit unsigned value from EtherCAT data. fp@1618: \return EtherCAT data value fp@1618: */ fp@1618: fp@1618: #define EC_READ_U8(DATA) \ fp@1618: ((uint8_t) *((uint8_t *) (DATA))) fp@1618: fp@1618: /** fp@1618: Read an 8-bit signed value from EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \return EtherCAT data value fp@1618: */ fp@1618: fp@1618: #define EC_READ_S8(DATA) \ fp@1618: ((int8_t) *((uint8_t *) (DATA))) fp@1618: fp@1618: /** fp@1618: Read a 16-bit unsigned value from EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \return EtherCAT data value fp@1618: */ fp@1618: fp@1618: #define EC_READ_U16(DATA) \ fp@1618: ((uint16_t) le16_to_cpup((void *) (DATA))) fp@1618: fp@1618: /** fp@1618: Read a 16-bit signed value from EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \return EtherCAT data value fp@1618: */ fp@1618: fp@1618: #define EC_READ_S16(DATA) \ fp@1618: ((int16_t) le16_to_cpup((void *) (DATA))) fp@1618: fp@1618: /** fp@1618: Read a 32-bit unsigned value from EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \return EtherCAT data value fp@1618: */ fp@1618: fp@1618: #define EC_READ_U32(DATA) \ fp@1618: ((uint32_t) le32_to_cpup((void *) (DATA))) fp@1618: fp@1618: /** fp@1618: Read a 32-bit signed value from EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \return EtherCAT data value fp@1618: */ fp@1618: fp@1618: #define EC_READ_S32(DATA) \ fp@1618: ((int32_t) le32_to_cpup((void *) (DATA))) fp@1618: fp@1618: fp@1618: /****************************************************************************** fp@1618: * Write macros fp@1618: *****************************************************************************/ fp@1618: fp@1618: /** fp@1618: Write an 8-bit unsigned value to EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param VAL new value fp@1618: */ fp@1618: fp@1618: #define EC_WRITE_U8(DATA, VAL) \ fp@1618: do { \ fp@1618: *((uint8_t *)(DATA)) = ((uint8_t) (VAL)); \ fp@1618: } while (0) fp@1618: fp@1618: /** fp@1618: Write an 8-bit signed value to EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param VAL new value fp@1618: */ fp@1618: fp@1618: #define EC_WRITE_S8(DATA, VAL) EC_WRITE_U8(DATA, VAL) fp@1618: fp@1618: /** fp@1618: Write a 16-bit unsigned value to EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param VAL new value fp@1618: */ fp@1618: fp@1618: #define EC_WRITE_U16(DATA, VAL) \ fp@1618: do { \ fp@1618: *((uint16_t *) (DATA)) = (uint16_t) (VAL); \ fp@1618: cpu_to_le16s(DATA); \ fp@1618: } while (0) fp@1618: fp@1618: /** fp@1618: Write a 16-bit signed value to EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param VAL new value fp@1618: */ fp@1618: fp@1618: #define EC_WRITE_S16(DATA, VAL) EC_WRITE_U16(DATA, VAL) fp@1618: fp@1618: /** fp@1618: Write a 32-bit unsigned value to EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param VAL new value fp@1618: */ fp@1618: fp@1618: #define EC_WRITE_U32(DATA, VAL) \ fp@1618: do { \ fp@1618: *((uint32_t *) (DATA)) = (uint32_t) (VAL); \ fp@1618: cpu_to_le16s(DATA); \ fp@1618: } while (0) fp@1618: fp@1618: /** fp@1618: Write a 32-bit signed value to EtherCAT data. fp@1618: \param DATA EtherCAT data pointer fp@1618: \param VAL new value fp@1618: */ fp@1618: fp@1618: #define EC_WRITE_S32(DATA, VAL) EC_WRITE_U32(DATA, VAL) fp@1618: fp@104: /*****************************************************************************/ fp@104: fp@104: #endif