fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * fp@1685: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@1685: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1685: * modify it under the terms of the GNU General Public License version 2, as fp@1685: * published by the Free Software Foundation. fp@1685: * fp@1685: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1685: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1685: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1685: * Public License for more details. fp@1685: * fp@1685: * You should have received a copy of the GNU General Public License along fp@1685: * 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@1685: * Using the EtherCAT technology and brand is permitted in compliance with fp@1685: * the 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@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@814: /** 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@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@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@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@989: EC_MBOX_AOE = 0x01, /**< ADS-over-EtherCAT */ fp@989: EC_MBOX_EOE = 0x02, /**< Ethernet-over-EtherCAT */ fp@989: EC_MBOX_COE = 0x04, /**< CANopen-over-EtherCAT */ fp@989: EC_MBOX_FOE = 0x08, /**< File-Access-over-EtherCAT */ fp@989: EC_MBOX_SOE = 0x10, /**< Servo-Profile-over-EtherCAT */ fp@989: EC_MBOX_VOE = 0x20 /**< Vendor specific */ fp@989: }; fp@989: fp@989: /** Slave information interface CANopen-over-EtherCAT details flags. fp@989: */ fp@989: typedef struct { fp@989: uint8_t enable_sdo : 1; /**< Enable Sdo access. */ fp@989: uint8_t enable_sdo_info : 1; /**< SDO information service available. */ fp@989: uint8_t enable_pdo_assign : 1; /**< Pdo mapping configurable. */ fp@989: 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@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@325: size_t ec_state_string(uint8_t, char *); fp@639: ssize_t ec_mac_print(const uint8_t *, char *); fp@639: int ec_mac_is_zero(const uint8_t *); fp@152: 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@861: EC_REQUEST_INIT, fp@861: EC_REQUEST_QUEUED, fp@861: EC_REQUEST_BUSY, fp@861: EC_REQUEST_SUCCESS, fp@861: EC_REQUEST_FAILURE fp@861: } ec_request_state_t; 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