fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * fp@197: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@197: * The IgH EtherCAT Master is free software; you can redistribute it fp@197: * and/or modify it under the terms of the GNU General Public License fp@246: * as published by the Free Software Foundation; either version 2 of the fp@246: * License, or (at your option) any later version. fp@197: * fp@197: * The IgH EtherCAT Master is distributed in the hope that it will be fp@197: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@197: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@197: * GNU General Public License for more details. fp@197: * fp@197: * You should have received a copy of the GNU General Public License fp@197: * along 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@246: * The right to use EtherCAT Technology is granted and comes free of fp@246: * charge under condition of compatibility of product made by fp@246: * Licensee. People intending to distribute/sell products based on the fp@246: * code, have to sign an agreement to guarantee that products using fp@246: * software based on IgH EtherCAT master stay compatible with the actual fp@246: * EtherCAT specification (which are released themselves as an open fp@246: * standard) as the (only) precondition to have the right to use EtherCAT fp@246: * Technology, IP and trade marks. fp@246: * fp@39: *****************************************************************************/ fp@0: fp@199: /** fp@199: \file fp@199: Global definitions and macros. fp@199: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@1732: #ifndef _EC_MASTER_GLOBALS_ fp@1732: #define _EC_MASTER_GLOBALS_ fp@0: fp@152: #include fp@152: fp@1732: #include "../globals.h" fp@1731: fp@196: /****************************************************************************** fp@196: * EtherCAT master fp@196: *****************************************************************************/ fp@41: fp@228: /** clock frequency for the EoE state machines */ fp@228: #define EC_EOE_FREQUENCY 1000 fp@228: fp@1715: /** datagram timeout in microseconds */ fp@1715: #define EC_IO_TIMEOUT 500 fp@1715: fp@1739: /** number of state machine retries on datagram timeout */ fp@1739: #define EC_FSM_RETRIES 3 fp@1739: fp@1732: /** Seconds to wait before fetching SDO dictionary fp@1732: after slave entered PREOP state. */ fp@1732: #define EC_WAIT_SDO_DICT 3 fp@1732: fp@1732: /** minimum size of a buffer used with ec_state_string() */ fp@1732: #define EC_STATE_STRING_SIZE 32 fp@1732: fp@1744: /** maximum EEPROM size in words, to avoid infinite reading. */ fp@1744: #define EC_MAX_EEPROM_SIZE 512 fp@1744: fp@196: /****************************************************************************** fp@196: * EtherCAT protocol fp@196: *****************************************************************************/ fp@196: fp@196: /** size of an EtherCAT frame header */ fp@196: #define EC_FRAME_HEADER_SIZE 2 fp@196: fp@293: /** size of an EtherCAT datagram header */ fp@293: #define EC_DATAGRAM_HEADER_SIZE 10 fp@196: fp@293: /** size of an EtherCAT datagram footer */ fp@293: #define EC_DATAGRAM_FOOTER_SIZE 2 fp@196: fp@1745: /** size of the EtherCAT address field */ fp@1745: #define EC_ADDR_LEN 4 fp@1745: fp@293: /** 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@1744: /** word offset of first EEPROM category. */ fp@1744: #define EC_FIRST_EEPROM_CATEGORY_OFFSET 0x40 fp@1744: fp@152: /*****************************************************************************/ fp@152: fp@259: /** fp@259: Convenience macro for printing EtherCAT-specific information to syslog. fp@259: This will print the message in \a fmt with a prefixed "EtherCAT: ". fp@259: \param fmt format string (like in printf()) fp@259: \param args arguments (optional) fp@259: */ fp@259: fp@84: #define EC_INFO(fmt, args...) \ fp@84: printk(KERN_INFO "EtherCAT: " fmt, ##args) fp@259: fp@259: /** fp@259: Convenience macro for printing EtherCAT-specific errors to syslog. fp@259: This will print the message in \a fmt with a prefixed "EtherCAT ERROR: ". fp@259: \param fmt format string (like in printf()) fp@259: \param args arguments (optional) fp@259: */ fp@259: fp@84: #define EC_ERR(fmt, args...) \ fp@84: printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args) fp@259: fp@259: /** fp@259: Convenience macro for printing EtherCAT-specific warnings to syslog. fp@259: This will print the message in \a fmt with a prefixed "EtherCAT WARNING: ". fp@259: \param fmt format string (like in printf()) fp@259: \param args arguments (optional) fp@259: */ fp@259: fp@84: #define EC_WARN(fmt, args...) \ fp@84: printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args) fp@259: fp@259: /** fp@259: Convenience macro for printing EtherCAT debug messages to syslog. fp@259: This will print the message in \a fmt with a prefixed "EtherCAT DEBUG: ". fp@259: \param fmt format string (like in printf()) fp@259: \param args arguments (optional) fp@259: */ fp@259: fp@84: #define EC_DBG(fmt, args...) \ fp@84: printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args) fp@84: fp@259: /** fp@259: Convenience macro for defining read-only SysFS attributes. fp@259: This results in creating a static variable called attr_\a NAME. The SysFS fp@259: file will be world-readable. fp@259: \param NAME name of the attribute to create. fp@199: */ fp@199: 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@259: /** fp@259: Convenience macro for defining read-write SysFS attributes. fp@259: This results in creating a static variable called attr_\a NAME. The SysFS fp@259: file will be word-readable plus owner-writable. fp@259: \param NAME name of the attribute to create. fp@259: */ fp@259: 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@1732: extern char *ec_master_version_str; fp@1732: fp@1732: /*****************************************************************************/ fp@1732: fp@1715: void ec_print_data(const uint8_t *, size_t); fp@1715: void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t); fp@1715: size_t ec_state_string(uint8_t, char *); fp@1744: ssize_t ec_mac_print(const uint8_t *, char *); fp@1744: int ec_mac_is_zero(const uint8_t *); fp@152: fp@152: /*****************************************************************************/ fp@152: fp@164: /** fp@195: Code - Message pair. fp@293: Some EtherCAT datagrams support reading a status code to display a certain fp@164: message. This type allows to map a code to a message string. fp@164: */ fp@164: fp@164: typedef struct fp@164: { fp@195: uint32_t code; /**< code */ fp@195: const char *message; /**< message belonging to \a code */ fp@164: } fp@164: ec_code_msg_t; fp@164: fp@164: /*****************************************************************************/ fp@164: fp@1744: /** fp@1744: * Master request state. fp@1744: */ fp@1744: fp@1744: typedef enum fp@1744: { fp@1744: EC_REQUEST_QUEUED, fp@1744: EC_REQUEST_IN_PROGRESS, fp@1744: EC_REQUEST_COMPLETE, fp@1744: EC_REQUEST_FAILURE fp@1744: } fp@1744: ec_request_state_t; fp@1744: fp@1744: /*****************************************************************************/ fp@1744: fp@1746: typedef struct ec_sdo ec_sdo_t; /**< \see ec_sdo */ fp@1746: fp@1746: /*****************************************************************************/ fp@1746: fp@0: #endif