fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * 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@39: *****************************************************************************/ fp@0: fp@1618: /** fp@1618: \file fp@1618: Global definitions and macros. fp@1618: */ fp@1618: fp@1618: /*****************************************************************************/ fp@1618: fp@0: #ifndef _EC_GLOBALS_ fp@0: #define _EC_GLOBALS_ fp@0: fp@152: #include fp@152: fp@1617: /****************************************************************************** fp@1617: * EtherCAT master fp@1617: *****************************************************************************/ fp@41: fp@1618: /** master main version */ fp@1617: #define EC_MASTER_VERSION_MAIN 1 fp@1618: fp@1618: /** master sub version (after the dot) */ fp@1617: #define EC_MASTER_VERSION_SUB 0 fp@1618: fp@1618: /** master extra version (just a string) */ fp@1617: #define EC_MASTER_VERSION_EXTRA "stable" fp@1617: fp@1617: /** maximum number of FMMUs per slave */ fp@1617: #define EC_MAX_FMMUS 16 fp@1617: fp@1619: /** size of the EoE tx queue */ fp@1619: #define EC_EOE_TX_QUEUE_SIZE 100 fp@1619: fp@1619: /** clock frequency for the EoE state machines */ fp@1619: #define EC_EOE_FREQUENCY 1000 fp@1619: fp@1617: /****************************************************************************** fp@1617: * EtherCAT protocol fp@1617: *****************************************************************************/ fp@1617: fp@1617: /** size of an EtherCAT frame header */ fp@1617: #define EC_FRAME_HEADER_SIZE 2 fp@1617: fp@1624: /** size of an EtherCAT datagram header */ fp@1624: #define EC_DATAGRAM_HEADER_SIZE 10 fp@1617: fp@1624: /** size of an EtherCAT datagram footer */ fp@1624: #define EC_DATAGRAM_FOOTER_SIZE 2 fp@1617: fp@1617: /** size of a sync manager configuration page */ fp@1617: #define EC_SYNC_SIZE 8 fp@1617: fp@1617: /** size of an FMMU configuration page */ fp@1617: #define EC_FMMU_SIZE 16 fp@1617: fp@1624: /** resulting maximum data size of a single datagram in a frame */ fp@1619: #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \ fp@1624: - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE) fp@0: fp@152: /*****************************************************************************/ fp@152: fp@1619: /** fp@1619: Convenience macro for printing EtherCAT-specific information to syslog. fp@1619: This will print the message in \a fmt with a prefixed "EtherCAT: ". fp@1619: \param fmt format string (like in printf()) fp@1619: \param args arguments (optional) fp@1619: */ fp@1619: fp@84: #define EC_INFO(fmt, args...) \ fp@84: printk(KERN_INFO "EtherCAT: " fmt, ##args) fp@1619: fp@1619: /** fp@1619: Convenience macro for printing EtherCAT-specific errors to syslog. fp@1619: This will print the message in \a fmt with a prefixed "EtherCAT ERROR: ". fp@1619: \param fmt format string (like in printf()) fp@1619: \param args arguments (optional) fp@1619: */ fp@1619: fp@84: #define EC_ERR(fmt, args...) \ fp@84: printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args) fp@1619: fp@1619: /** fp@1619: Convenience macro for printing EtherCAT-specific warnings to syslog. fp@1619: This will print the message in \a fmt with a prefixed "EtherCAT WARNING: ". fp@1619: \param fmt format string (like in printf()) fp@1619: \param args arguments (optional) fp@1619: */ fp@1619: fp@84: #define EC_WARN(fmt, args...) \ fp@84: printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args) fp@1619: fp@1619: /** fp@1619: Convenience macro for printing EtherCAT debug messages to syslog. fp@1619: This will print the message in \a fmt with a prefixed "EtherCAT DEBUG: ". fp@1619: \param fmt format string (like in printf()) fp@1619: \param args arguments (optional) fp@1619: */ fp@1619: fp@84: #define EC_DBG(fmt, args...) \ fp@84: printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args) fp@84: fp@1619: /** fp@1619: Helper macro for EC_STR(), literates a macro argument. fp@1619: \param X argument to literate. fp@1619: */ fp@1619: fp@184: #define EC_LIT(X) #X fp@1619: fp@1619: /** fp@1619: Converts a macro argument to a string. fp@1619: \param X argument to stringify. fp@1619: */ fp@1619: fp@184: #define EC_STR(X) EC_LIT(X) fp@184: fp@1618: /** fp@1619: Convenience macro for defining read-only SysFS attributes. fp@1619: This results in creating a static variable called attr_\a NAME. The SysFS fp@1619: file will be world-readable. fp@1619: \param NAME name of the attribute to create. fp@1618: */ fp@1618: 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@1619: /** fp@1619: Convenience macro for defining read-write SysFS attributes. fp@1619: This results in creating a static variable called attr_\a NAME. The SysFS fp@1619: file will be word-readable plus owner-writable. fp@1619: \param NAME name of the attribute to create. fp@1619: */ fp@1619: fp@1619: #define EC_SYSFS_READ_WRITE_ATTR(NAME) \ fp@1619: static struct attribute attr_##NAME = { \ fp@1619: .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO | S_IWUSR \ fp@1619: } fp@1619: fp@41: /*****************************************************************************/ fp@41: fp@152: extern void ec_print_data(const uint8_t *, size_t); fp@152: extern void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t); fp@1619: extern void ec_print_states(uint8_t); fp@152: fp@152: /*****************************************************************************/ fp@152: fp@164: /** fp@195: Code - Message pair. fp@1624: 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@0: #endif fp@73: