fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * fp@1326: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@1326: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1326: * modify it under the terms of the GNU General Public License version 2, as fp@1326: * published by the Free Software Foundation. fp@1326: * fp@1326: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1326: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1326: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1326: * Public License for more details. fp@1326: * fp@1326: * You should have received a copy of the GNU General Public License along fp@1326: * with the IgH EtherCAT Master; if not, write to the Free Software fp@197: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@197: * fp@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@246: * fp@39: *****************************************************************************/ fp@0: fp@792: /** \file fp@792: * Global definitions and macros. fp@792: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@883: #ifndef __EC_MASTER_GLOBALS_H__ fp@883: #define __EC_MASTER_GLOBALS_H__ fp@0: fp@152: #include fp@152: fp@444: #include "../globals.h" fp@1209: #include "../include/ecrt.h" fp@392: fp@196: /****************************************************************************** fp@792: * EtherCAT master fp@196: *****************************************************************************/ fp@41: fp@792: /** Clock frequency for the EoE state machines. */ fp@228: #define EC_EOE_FREQUENCY 1000 fp@228: fp@792: /** Datagram timeout in microseconds. */ fp@325: #define EC_IO_TIMEOUT 500 fp@325: fp@792: /** Number of state machine retries on datagram timeout. */ fp@505: #define EC_FSM_RETRIES 3 fp@505: fp@1327: /** Seconds to wait before fetching SDO dictionary fp@427: after slave entered PREOP state. */ fp@427: #define EC_WAIT_SDO_DICT 3 fp@427: fp@792: /** Minimum size of a buffer used with ec_state_string(). */ fp@453: #define EC_STATE_STRING_SIZE 32 fp@403: fp@872: /** Maximum SII size in words, to avoid infinite reading. */ fp@872: #define EC_MAX_SII_SIZE 1024 fp@696: fp@196: /****************************************************************************** fp@792: * EtherCAT protocol fp@196: *****************************************************************************/ fp@196: fp@792: /** Size of an EtherCAT frame header. */ fp@196: #define EC_FRAME_HEADER_SIZE 2 fp@196: fp@792: /** Size of an EtherCAT datagram header. */ fp@293: #define EC_DATAGRAM_HEADER_SIZE 10 fp@196: fp@792: /** Size of an EtherCAT datagram footer. */ fp@293: #define EC_DATAGRAM_FOOTER_SIZE 2 fp@196: fp@792: /** Size of the EtherCAT address field. */ fp@708: #define EC_ADDR_LEN 4 fp@708: fp@792: /** Resulting maximum data size of a single datagram in a frame. */ fp@211: #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \ fp@293: - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE) fp@0: fp@1217: /** Mailbox header size. */ fp@1217: #define EC_MBOX_HEADER_SIZE 6 fp@1217: fp@872: /** Word offset of first SII category. */ fp@872: #define EC_FIRST_SII_CATEGORY_OFFSET 0x40 fp@696: fp@1055: /** Maximum number of slave ports. */ fp@1055: #define EC_MAX_PORTS 4 fp@1055: fp@792: /** Size of a sync manager configuration page. */ fp@792: #define EC_SYNC_PAGE_SIZE 8 fp@792: fp@792: /** Maximum number of FMMUs per slave. */ fp@792: #define EC_MAX_FMMUS 16 fp@792: fp@792: /** Size of an FMMU configuration page. */ fp@792: #define EC_FMMU_PAGE_SIZE 16 fp@792: fp@1438: /** Number of DC sync signals. */ fp@1438: #define EC_SYNC_SIGNAL_COUNT 2 fp@1438: fp@989: /** Slave state mask. fp@989: * fp@989: * Apply this mask to a slave state byte to get the slave state without fp@989: * the error flag. fp@989: */ fp@989: #define EC_SLAVE_STATE_MASK 0x0F fp@989: fp@989: /** State of an EtherCAT slave. fp@989: */ fp@989: typedef enum { fp@989: EC_SLAVE_STATE_UNKNOWN = 0x00, fp@989: /**< unknown state */ fp@989: EC_SLAVE_STATE_INIT = 0x01, fp@989: /**< INIT state (no mailbox communication, no IO) */ fp@989: EC_SLAVE_STATE_PREOP = 0x02, fp@989: /**< PREOP state (mailbox communication, no IO) */ fp@1337: EC_SLAVE_STATE_BOOT = 0x03, fp@1337: /**< Bootstrap state (mailbox communication, firmware update) */ fp@989: EC_SLAVE_STATE_SAFEOP = 0x04, fp@989: /**< SAFEOP (mailbox communication and input update) */ fp@989: EC_SLAVE_STATE_OP = 0x08, fp@989: /**< OP (mailbox communication and input/output update) */ fp@989: EC_SLAVE_STATE_ACK_ERR = 0x10 fp@989: /**< Acknowledge/Error bit (no actual state) */ fp@989: } ec_slave_state_t; fp@989: fp@989: /** Supported mailbox protocols. fp@989: */ fp@989: enum { fp@1327: EC_MBOX_AOE = 0x01, /**< ADS over EtherCAT */ fp@1327: EC_MBOX_EOE = 0x02, /**< Ethernet over EtherCAT */ fp@1327: EC_MBOX_COE = 0x04, /**< CANopen over EtherCAT */ fp@1327: EC_MBOX_FOE = 0x08, /**< File-Access over EtherCAT */ fp@1327: EC_MBOX_SOE = 0x10, /**< Servo-Profile over EtherCAT */ fp@989: EC_MBOX_VOE = 0x20 /**< Vendor specific */ fp@989: }; fp@989: fp@1327: /** Slave information interface CANopen over EtherCAT details flags. fp@989: */ fp@989: typedef struct { fp@1327: uint8_t enable_sdo : 1; /**< Enable SDO access. */ fp@989: uint8_t enable_sdo_info : 1; /**< SDO information service available. */ fp@1327: uint8_t enable_pdo_assign : 1; /**< PDO mapping configurable. */ fp@1327: uint8_t enable_pdo_configuration : 1; /**< PDO configuration possible. */ fp@989: uint8_t enable_upload_at_startup : 1; /**< ?. */ fp@989: uint8_t enable_sdo_complete_access : 1; /**< Complete access possible. */ fp@989: } ec_sii_coe_details_t; fp@989: fp@989: /** Slave information interface general flags. fp@989: */ fp@989: typedef struct { fp@989: uint8_t enable_safeop : 1; /**< ?. */ fp@989: uint8_t enable_not_lrw : 1; /**< Slave does not support LRW. */ fp@989: } ec_sii_general_flags_t; fp@989: fp@1379: /** EtherCAT slave port descriptor. fp@1379: */ fp@1379: typedef enum { fp@1379: EC_PORT_NOT_IMPLEMENTED, fp@1379: EC_PORT_NOT_CONFIGURED, fp@1379: EC_PORT_EBUS, fp@1379: EC_PORT_MII fp@1379: } ec_slave_port_desc_t; fp@1379: fp@1420: /** EtherCAT slave port information. fp@1420: */ fp@1420: typedef struct { fp@1425: uint8_t link_up; /**< Link detected. */ fp@1425: uint8_t loop_closed; /**< Loop closed. */ fp@1425: uint8_t signal_detected; /**< Detected signal on RX port. */ fp@1425: } ec_slave_port_link_t; fp@1420: fp@1379: /** EtherCAT slave distributed clocks range. fp@1379: */ fp@1379: typedef enum { fp@1379: EC_DC_32, /**< 32 bit. */ fp@1379: EC_DC_64 /*< 64 bit for system time, system time offset and fp@1379: port 0 receive time. */ fp@1379: } ec_slave_dc_range_t; fp@1379: fp@1438: /** EtherCAT slave sync signal configuration. fp@1438: */ fp@1438: typedef struct { fp@1438: uint32_t cycle_time; /**< Cycle time [ns]. */ fp@1438: uint32_t shift_time; /**< Shift time [ns]. */ fp@1438: } ec_sync_signal_t; fp@1438: fp@1382: /** Access states for SDO entries. fp@1382: * fp@1382: * The access rights are managed per AL state. fp@1382: */ fp@1382: enum { fp@1382: EC_SDO_ENTRY_ACCESS_PREOP, /**< Access rights in PREOP. */ fp@1382: EC_SDO_ENTRY_ACCESS_SAFEOP, /**< Access rights in SAFEOP. */ fp@1382: EC_SDO_ENTRY_ACCESS_OP, /**< Access rights in OP. */ fp@1382: EC_SDO_ENTRY_ACCESS_COUNT /**< Number of states. */ fp@1382: }; fp@1382: fp@792: /*****************************************************************************/ fp@792: fp@792: /** Convenience macro for printing EtherCAT-specific information to syslog. fp@792: * fp@792: * This will print the message in \a fmt with a prefixed "EtherCAT: ". fp@792: * fp@792: * \param fmt format string (like in printf()) fp@792: * \param args arguments (optional) fp@792: */ fp@84: #define EC_INFO(fmt, args...) \ fp@84: printk(KERN_INFO "EtherCAT: " fmt, ##args) fp@259: fp@792: /** Convenience macro for printing EtherCAT-specific errors to syslog. fp@792: * fp@792: * This will print the message in \a fmt with a prefixed "EtherCAT ERROR: ". fp@792: * fp@792: * \param fmt format string (like in printf()) fp@792: * \param args arguments (optional) fp@792: */ fp@84: #define EC_ERR(fmt, args...) \ fp@84: printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args) fp@259: fp@792: /** Convenience macro for printing EtherCAT-specific warnings to syslog. fp@792: * fp@792: * This will print the message in \a fmt with a prefixed "EtherCAT WARNING: ". fp@792: * fp@792: * \param fmt format string (like in printf()) fp@792: * \param args arguments (optional) fp@792: */ fp@84: #define EC_WARN(fmt, args...) \ fp@84: printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args) fp@259: fp@792: /** Convenience macro for printing EtherCAT debug messages to syslog. fp@792: * fp@792: * This will print the message in \a fmt with a prefixed "EtherCAT DEBUG: ". fp@792: * fp@792: * \param fmt format string (like in printf()) fp@792: * \param args arguments (optional) fp@792: */ fp@84: #define EC_DBG(fmt, args...) \ fp@84: printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args) fp@84: fp@792: /** Convenience macro for defining read-only SysFS attributes. fp@792: * fp@792: * This results in creating a static variable called attr_\a NAME. The SysFS fp@792: * file will be world-readable. fp@792: * fp@792: * \param NAME name of the attribute to create. fp@792: */ fp@184: #define EC_SYSFS_READ_ATTR(NAME) \ fp@184: static struct attribute attr_##NAME = { \ fp@184: .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO \ fp@184: } fp@184: fp@792: /** Convenience macro for defining read-write SysFS attributes. fp@792: * fp@792: * This results in creating a static variable called attr_\a NAME. The SysFS fp@792: * file will be word-readable plus owner-writable. fp@792: * fp@792: * \param NAME name of the attribute to create. fp@792: */ fp@256: #define EC_SYSFS_READ_WRITE_ATTR(NAME) \ fp@256: static struct attribute attr_##NAME = { \ fp@256: .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO | S_IWUSR \ fp@256: } fp@256: fp@41: /*****************************************************************************/ fp@41: fp@444: extern char *ec_master_version_str; fp@444: fp@444: /*****************************************************************************/ fp@444: fp@325: void ec_print_data(const uint8_t *, size_t); fp@325: void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t); fp@1337: size_t ec_state_string(uint8_t, char *, uint8_t); fp@639: ssize_t ec_mac_print(const uint8_t *, char *); fp@639: int ec_mac_is_zero(const uint8_t *); fp@152: fp@1312: ec_master_t *ecrt_request_master_err(unsigned int); fp@1312: fp@152: /*****************************************************************************/ fp@152: fp@809: /** Code/Message pair. fp@792: * fp@792: * Some EtherCAT datagrams support reading a status code to display a certain fp@792: * message. This type allows to map a code to a message string. fp@792: */ fp@792: typedef struct { fp@792: uint32_t code; /**< Code. */ fp@792: const char *message; /**< Message belonging to \a code. */ fp@809: } ec_code_msg_t; fp@164: fp@164: /*****************************************************************************/ fp@164: fp@861: /** Generic request state. fp@861: * fp@861: * \attention If ever changing this, please be sure to adjust the \a fp@861: * state_table in master/sdo_request.c. fp@861: */ fp@861: typedef enum { fp@1209: EC_INT_REQUEST_INIT, fp@1209: EC_INT_REQUEST_QUEUED, fp@1209: EC_INT_REQUEST_BUSY, fp@1209: EC_INT_REQUEST_SUCCESS, fp@1209: EC_INT_REQUEST_FAILURE fp@1209: } ec_internal_request_state_t; fp@1209: fp@1209: /*****************************************************************************/ fp@1209: fp@1209: extern const ec_request_state_t ec_request_state_translation_table[]; fp@861: fp@861: /*****************************************************************************/ fp@861: fp@809: /** Origin type. fp@809: */ fp@809: typedef enum { fp@809: EC_ORIG_INTERNAL, /**< Internal. */ fp@809: EC_ORIG_EXTERNAL /**< External. */ fp@809: } ec_origin_t; fp@809: fp@809: /*****************************************************************************/ fp@809: fp@792: typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */ fp@740: fp@740: /*****************************************************************************/ fp@740: fp@0: #endif