master/globals.h
changeset 792 3778920f61e4
parent 773 6c4646a03d68
child 809 ec4ef8911824
equal deleted inserted replaced
791:3b81d074735c 792:3778920f61e4
    29  *  standard) as the (only) precondition to have the right to use EtherCAT
    29  *  standard) as the (only) precondition to have the right to use EtherCAT
    30  *  Technology, IP and trade marks.
    30  *  Technology, IP and trade marks.
    31  *
    31  *
    32  *****************************************************************************/
    32  *****************************************************************************/
    33 
    33 
    34 /**
    34 /** \file
    35    \file
    35  * Global definitions and macros.
    36    Global definitions and macros.
    36  */
    37 */
       
    38 
    37 
    39 /*****************************************************************************/
    38 /*****************************************************************************/
    40 
    39 
    41 #ifndef _EC_MASTER_GLOBALS_
    40 #ifndef _EC_MASTER_GLOBALS_
    42 #define _EC_MASTER_GLOBALS_
    41 #define _EC_MASTER_GLOBALS_
    44 #include <linux/types.h>
    43 #include <linux/types.h>
    45 
    44 
    46 #include "../globals.h"
    45 #include "../globals.h"
    47 
    46 
    48 /******************************************************************************
    47 /******************************************************************************
    49  *  EtherCAT master
    48  * EtherCAT master
    50  *****************************************************************************/
    49  *****************************************************************************/
    51 
    50 
    52 /** clock frequency for the EoE state machines */
    51 /** Clock frequency for the EoE state machines. */
    53 #define EC_EOE_FREQUENCY 1000
    52 #define EC_EOE_FREQUENCY 1000
    54 
    53 
    55 /** datagram timeout in microseconds */
    54 /** Datagram timeout in microseconds. */
    56 #define EC_IO_TIMEOUT 500
    55 #define EC_IO_TIMEOUT 500
    57 
    56 
    58 /** number of state machine retries on datagram timeout */
    57 /** Number of state machine retries on datagram timeout. */
    59 #define EC_FSM_RETRIES 3
    58 #define EC_FSM_RETRIES 3
    60 
    59 
    61 /** Seconds to wait before fetching SDO dictionary
    60 /** Seconds to wait before fetching SDO dictionary
    62     after slave entered PREOP state. */
    61     after slave entered PREOP state. */
    63 #define EC_WAIT_SDO_DICT 3
    62 #define EC_WAIT_SDO_DICT 3
    64 
    63 
    65 /** minimum size of a buffer used with ec_state_string() */
    64 /** Minimum size of a buffer used with ec_state_string(). */
    66 #define EC_STATE_STRING_SIZE 32
    65 #define EC_STATE_STRING_SIZE 32
    67 
    66 
    68 /** maximum EEPROM size in words, to avoid infinite reading. */
    67 /** Maximum EEPROM size in words, to avoid infinite reading. */
    69 #define EC_MAX_EEPROM_SIZE 1024
    68 #define EC_MAX_EEPROM_SIZE 1024
    70 
    69 
    71 /******************************************************************************
    70 /******************************************************************************
    72  *  EtherCAT protocol
    71  * EtherCAT protocol
    73  *****************************************************************************/
    72  *****************************************************************************/
    74 
    73 
    75 /** size of an EtherCAT frame header */
    74 /** Size of an EtherCAT frame header. */
    76 #define EC_FRAME_HEADER_SIZE 2
    75 #define EC_FRAME_HEADER_SIZE 2
    77 
    76 
    78 /** size of an EtherCAT datagram header */
    77 /** Size of an EtherCAT datagram header. */
    79 #define EC_DATAGRAM_HEADER_SIZE 10
    78 #define EC_DATAGRAM_HEADER_SIZE 10
    80 
    79 
    81 /** size of an EtherCAT datagram footer */
    80 /** Size of an EtherCAT datagram footer. */
    82 #define EC_DATAGRAM_FOOTER_SIZE 2
    81 #define EC_DATAGRAM_FOOTER_SIZE 2
    83 
    82 
    84 /** size of the EtherCAT address field */
    83 /** Size of the EtherCAT address field. */
    85 #define EC_ADDR_LEN 4
    84 #define EC_ADDR_LEN 4
    86 
    85 
    87 /** resulting maximum data size of a single datagram in a frame */
    86 /** Resulting maximum data size of a single datagram in a frame. */
    88 #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \
    87 #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \
    89                           - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE)
    88                           - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE)
    90 
    89 
    91 /** word offset of first EEPROM category. */
    90 /** Word offset of first EEPROM category. */
    92 #define EC_FIRST_EEPROM_CATEGORY_OFFSET 0x40
    91 #define EC_FIRST_EEPROM_CATEGORY_OFFSET 0x40
    93 
    92 
    94 /*****************************************************************************/
    93 /** Size of a sync manager configuration page. */
    95 
    94 #define EC_SYNC_PAGE_SIZE 8
    96 /**
    95 
    97    Convenience macro for printing EtherCAT-specific information to syslog.
    96 /** Maximum number of FMMUs per slave. */
    98    This will print the message in \a fmt with a prefixed "EtherCAT: ".
    97 #define EC_MAX_FMMUS 16
    99    \param fmt format string (like in printf())
    98 
   100    \param args arguments (optional)
    99 /** Size of an FMMU configuration page. */
   101 */
   100 #define EC_FMMU_PAGE_SIZE 16
   102 
   101 
       
   102 /*****************************************************************************/
       
   103 
       
   104 /** Convenience macro for printing EtherCAT-specific information to syslog.
       
   105  *
       
   106  * This will print the message in \a fmt with a prefixed "EtherCAT: ".
       
   107  *
       
   108  * \param fmt format string (like in printf())
       
   109  * \param args arguments (optional)
       
   110  */
   103 #define EC_INFO(fmt, args...) \
   111 #define EC_INFO(fmt, args...) \
   104     printk(KERN_INFO "EtherCAT: " fmt, ##args)
   112     printk(KERN_INFO "EtherCAT: " fmt, ##args)
   105 
   113 
   106 /**
   114 /** Convenience macro for printing EtherCAT-specific errors to syslog.
   107    Convenience macro for printing EtherCAT-specific errors to syslog.
   115  *
   108    This will print the message in \a fmt with a prefixed "EtherCAT ERROR: ".
   116  * This will print the message in \a fmt with a prefixed "EtherCAT ERROR: ".
   109    \param fmt format string (like in printf())
   117  *
   110    \param args arguments (optional)
   118  * \param fmt format string (like in printf())
   111 */
   119  * \param args arguments (optional)
   112 
   120  */
   113 #define EC_ERR(fmt, args...) \
   121 #define EC_ERR(fmt, args...) \
   114     printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args)
   122     printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args)
   115 
   123 
   116 /**
   124 /** Convenience macro for printing EtherCAT-specific warnings to syslog.
   117    Convenience macro for printing EtherCAT-specific warnings to syslog.
   125  *
   118    This will print the message in \a fmt with a prefixed "EtherCAT WARNING: ".
   126  * This will print the message in \a fmt with a prefixed "EtherCAT WARNING: ".
   119    \param fmt format string (like in printf())
   127  *
   120    \param args arguments (optional)
   128  * \param fmt format string (like in printf())
   121 */
   129  * \param args arguments (optional)
   122 
   130  */
   123 #define EC_WARN(fmt, args...) \
   131 #define EC_WARN(fmt, args...) \
   124     printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args)
   132     printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args)
   125 
   133 
   126 /**
   134 /** Convenience macro for printing EtherCAT debug messages to syslog.
   127    Convenience macro for printing EtherCAT debug messages to syslog.
   135  *
   128    This will print the message in \a fmt with a prefixed "EtherCAT DEBUG: ".
   136  * This will print the message in \a fmt with a prefixed "EtherCAT DEBUG: ".
   129    \param fmt format string (like in printf())
   137  *
   130    \param args arguments (optional)
   138  * \param fmt format string (like in printf())
   131 */
   139  * \param args arguments (optional)
   132 
   140  */
   133 #define EC_DBG(fmt, args...) \
   141 #define EC_DBG(fmt, args...) \
   134     printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args)
   142     printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args)
   135 
   143 
   136 /**
   144 /** Convenience macro for defining read-only SysFS attributes.
   137    Convenience macro for defining read-only SysFS attributes.
   145  *
   138    This results in creating a static variable called attr_\a NAME. The SysFS
   146  * This results in creating a static variable called attr_\a NAME. The SysFS
   139    file will be world-readable.
   147  * file will be world-readable.
   140    \param NAME name of the attribute to create.
   148  *
   141 */
   149  * \param NAME name of the attribute to create.
   142 
   150  */
   143 #define EC_SYSFS_READ_ATTR(NAME) \
   151 #define EC_SYSFS_READ_ATTR(NAME) \
   144     static struct attribute attr_##NAME = { \
   152     static struct attribute attr_##NAME = { \
   145         .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO \
   153         .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO \
   146     }
   154     }
   147 
   155 
   148 /**
   156 /** Convenience macro for defining read-write SysFS attributes.
   149    Convenience macro for defining read-write SysFS attributes.
   157  *
   150    This results in creating a static variable called attr_\a NAME. The SysFS
   158  * This results in creating a static variable called attr_\a NAME. The SysFS
   151    file will be word-readable plus owner-writable.
   159  * file will be word-readable plus owner-writable.
   152    \param NAME name of the attribute to create.
   160  *
   153 */
   161  * \param NAME name of the attribute to create.
   154 
   162  */
   155 #define EC_SYSFS_READ_WRITE_ATTR(NAME) \
   163 #define EC_SYSFS_READ_WRITE_ATTR(NAME) \
   156     static struct attribute attr_##NAME = { \
   164     static struct attribute attr_##NAME = { \
   157         .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO | S_IWUSR \
   165         .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO | S_IWUSR \
   158     }
   166     }
   159 
   167 
   169 ssize_t ec_mac_print(const uint8_t *, char *);
   177 ssize_t ec_mac_print(const uint8_t *, char *);
   170 int ec_mac_is_zero(const uint8_t *);
   178 int ec_mac_is_zero(const uint8_t *);
   171 
   179 
   172 /*****************************************************************************/
   180 /*****************************************************************************/
   173 
   181 
   174 /**
   182 /** Code - Message pair.
   175    Code - Message pair.
   183  *
   176    Some EtherCAT datagrams support reading a status code to display a certain
   184  * Some EtherCAT datagrams support reading a status code to display a certain
   177    message. This type allows to map a code to a message string.
   185  * message. This type allows to map a code to a message string.
   178 */
   186  */
   179 
   187 typedef struct {
   180 typedef struct
   188     uint32_t code; /**< Code. */
   181 {
   189     const char *message; /**< Message belonging to \a code. */
   182     uint32_t code; /**< code */
       
   183     const char *message; /**< message belonging to \a code */
       
   184 }
   190 }
   185 ec_code_msg_t;
   191 ec_code_msg_t;
   186 
   192 
   187 /*****************************************************************************/
   193 /*****************************************************************************/
   188 
   194 
   189 /**
   195 /** Master request state.
   190  * Master request state.
   196  */
   191  */
   197 typedef enum {
   192 
       
   193 typedef enum
       
   194 {
       
   195     EC_REQUEST_QUEUED,
   198     EC_REQUEST_QUEUED,
   196     EC_REQUEST_IN_PROGRESS,
   199     EC_REQUEST_IN_PROGRESS,
   197     EC_REQUEST_COMPLETE,
   200     EC_REQUEST_COMPLETE,
   198     EC_REQUEST_FAILURE
   201     EC_REQUEST_FAILURE
   199 }
   202 }
   200 ec_request_state_t;
   203 ec_request_state_t;
   201 
   204 
   202 /*****************************************************************************/
   205 /*****************************************************************************/
   203 
   206 
       
   207 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */
   204 typedef struct ec_sdo ec_sdo_t; /**< \see ec_sdo */
   208 typedef struct ec_sdo ec_sdo_t; /**< \see ec_sdo */
   205 
   209 
   206 /*****************************************************************************/
   210 /*****************************************************************************/
   207 
   211 
   208 #endif
   212 #endif