6 * |
6 * |
7 * This file is part of the IgH EtherCAT Master. |
7 * This file is part of the IgH EtherCAT Master. |
8 * |
8 * |
9 * The IgH EtherCAT Master is free software; you can redistribute it |
9 * The IgH EtherCAT Master is free software; you can redistribute it |
10 * and/or modify it under the terms of the GNU General Public License |
10 * and/or modify it under the terms of the GNU General Public License |
11 * as published by the Free Software Foundation; version 2 of the License. |
11 * as published by the Free Software Foundation; either version 2 of the |
|
12 * License, or (at your option) any later version. |
12 * |
13 * |
13 * The IgH EtherCAT Master is distributed in the hope that it will be |
14 * The IgH EtherCAT Master is distributed in the hope that it will be |
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 * GNU General Public License for more details. |
17 * GNU General Public License for more details. |
17 * |
18 * |
18 * You should have received a copy of the GNU General Public License |
19 * You should have received a copy of the GNU General Public License |
19 * along with the IgH EtherCAT Master; if not, write to the Free Software |
20 * along with the IgH EtherCAT Master; if not, write to the Free Software |
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 * |
|
23 * The right to use EtherCAT Technology is granted and comes free of |
|
24 * charge under condition of compatibility of product made by |
|
25 * Licensee. People intending to distribute/sell products based on the |
|
26 * code, have to sign an agreement to guarantee that products using |
|
27 * software based on IgH EtherCAT master stay compatible with the actual |
|
28 * EtherCAT specification (which are released themselves as an open |
|
29 * standard) as the (only) precondition to have the right to use EtherCAT |
|
30 * Technology, IP and trade marks. |
21 * |
31 * |
22 *****************************************************************************/ |
32 *****************************************************************************/ |
23 |
33 |
24 /** |
34 /** |
25 \file |
35 \file |
47 #define EC_MASTER_VERSION_EXTRA "stable" |
57 #define EC_MASTER_VERSION_EXTRA "stable" |
48 |
58 |
49 /** maximum number of FMMUs per slave */ |
59 /** maximum number of FMMUs per slave */ |
50 #define EC_MAX_FMMUS 16 |
60 #define EC_MAX_FMMUS 16 |
51 |
61 |
|
62 /** size of the EoE tx queue */ |
|
63 #define EC_EOE_TX_QUEUE_SIZE 100 |
|
64 |
|
65 /** clock frequency for the EoE state machines */ |
|
66 #define EC_EOE_FREQUENCY 1000 |
|
67 |
52 /****************************************************************************** |
68 /****************************************************************************** |
53 * EtherCAT protocol |
69 * EtherCAT protocol |
54 *****************************************************************************/ |
70 *****************************************************************************/ |
55 |
|
56 /** maximum size of an EtherCAT frame (without header and CRC) */ |
|
57 #define EC_MAX_FRAME_SIZE 1500 |
|
58 |
|
59 /** minimum size of an EtherCAT frame (without header and CRC) */ |
|
60 #define EC_MIN_FRAME_SIZE 46 |
|
61 |
71 |
62 /** size of an EtherCAT frame header */ |
72 /** size of an EtherCAT frame header */ |
63 #define EC_FRAME_HEADER_SIZE 2 |
73 #define EC_FRAME_HEADER_SIZE 2 |
64 |
74 |
65 /** size of an EtherCAT command header */ |
75 /** size of an EtherCAT command header */ |
73 |
83 |
74 /** size of an FMMU configuration page */ |
84 /** size of an FMMU configuration page */ |
75 #define EC_FMMU_SIZE 16 |
85 #define EC_FMMU_SIZE 16 |
76 |
86 |
77 /** resulting maximum data size of a single command in a frame */ |
87 /** resulting maximum data size of a single command in a frame */ |
78 #define EC_MAX_DATA_SIZE (EC_MAX_FRAME_SIZE - EC_FRAME_HEADER_SIZE \ |
88 #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \ |
79 - EC_COMMAND_HEADER_SIZE - EC_COMMAND_FOOTER_SIZE) |
89 - EC_COMMAND_HEADER_SIZE - EC_COMMAND_FOOTER_SIZE) |
80 |
90 |
81 /*****************************************************************************/ |
91 /*****************************************************************************/ |
82 |
92 |
|
93 /** |
|
94 Convenience macro for printing EtherCAT-specific information to syslog. |
|
95 This will print the message in \a fmt with a prefixed "EtherCAT: ". |
|
96 \param fmt format string (like in printf()) |
|
97 \param args arguments (optional) |
|
98 */ |
|
99 |
83 #define EC_INFO(fmt, args...) \ |
100 #define EC_INFO(fmt, args...) \ |
84 printk(KERN_INFO "EtherCAT: " fmt, ##args) |
101 printk(KERN_INFO "EtherCAT: " fmt, ##args) |
|
102 |
|
103 /** |
|
104 Convenience macro for printing EtherCAT-specific errors to syslog. |
|
105 This will print the message in \a fmt with a prefixed "EtherCAT ERROR: ". |
|
106 \param fmt format string (like in printf()) |
|
107 \param args arguments (optional) |
|
108 */ |
|
109 |
85 #define EC_ERR(fmt, args...) \ |
110 #define EC_ERR(fmt, args...) \ |
86 printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args) |
111 printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args) |
|
112 |
|
113 /** |
|
114 Convenience macro for printing EtherCAT-specific warnings to syslog. |
|
115 This will print the message in \a fmt with a prefixed "EtherCAT WARNING: ". |
|
116 \param fmt format string (like in printf()) |
|
117 \param args arguments (optional) |
|
118 */ |
|
119 |
87 #define EC_WARN(fmt, args...) \ |
120 #define EC_WARN(fmt, args...) \ |
88 printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args) |
121 printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args) |
|
122 |
|
123 /** |
|
124 Convenience macro for printing EtherCAT debug messages to syslog. |
|
125 This will print the message in \a fmt with a prefixed "EtherCAT DEBUG: ". |
|
126 \param fmt format string (like in printf()) |
|
127 \param args arguments (optional) |
|
128 */ |
|
129 |
89 #define EC_DBG(fmt, args...) \ |
130 #define EC_DBG(fmt, args...) \ |
90 printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args) |
131 printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args) |
91 |
132 |
|
133 /** |
|
134 Helper macro for EC_STR(), literates a macro argument. |
|
135 \param X argument to literate. |
|
136 */ |
|
137 |
92 #define EC_LIT(X) #X |
138 #define EC_LIT(X) #X |
|
139 |
|
140 /** |
|
141 Converts a macro argument to a string. |
|
142 \param X argument to stringify. |
|
143 */ |
|
144 |
93 #define EC_STR(X) EC_LIT(X) |
145 #define EC_STR(X) EC_LIT(X) |
94 |
146 |
95 /** |
147 /** |
96 Convenience macro for defining SysFS attributes. |
148 Convenience macro for defining read-only SysFS attributes. |
|
149 This results in creating a static variable called attr_\a NAME. The SysFS |
|
150 file will be world-readable. |
|
151 \param NAME name of the attribute to create. |
97 */ |
152 */ |
98 |
153 |
99 #define EC_SYSFS_READ_ATTR(NAME) \ |
154 #define EC_SYSFS_READ_ATTR(NAME) \ |
100 static struct attribute attr_##NAME = { \ |
155 static struct attribute attr_##NAME = { \ |
101 .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO \ |
156 .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO \ |
102 } |
157 } |
103 |
158 |
|
159 /** |
|
160 Convenience macro for defining read-write SysFS attributes. |
|
161 This results in creating a static variable called attr_\a NAME. The SysFS |
|
162 file will be word-readable plus owner-writable. |
|
163 \param NAME name of the attribute to create. |
|
164 */ |
|
165 |
|
166 #define EC_SYSFS_READ_WRITE_ATTR(NAME) \ |
|
167 static struct attribute attr_##NAME = { \ |
|
168 .name = EC_STR(NAME), .owner = THIS_MODULE, .mode = S_IRUGO | S_IWUSR \ |
|
169 } |
|
170 |
104 /*****************************************************************************/ |
171 /*****************************************************************************/ |
105 |
172 |
106 extern void ec_print_data(const uint8_t *, size_t); |
173 extern void ec_print_data(const uint8_t *, size_t); |
107 extern void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t); |
174 extern void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t); |
|
175 extern void ec_print_states(uint8_t); |
108 |
176 |
109 /*****************************************************************************/ |
177 /*****************************************************************************/ |
110 |
178 |
111 /** |
179 /** |
112 Code - Message pair. |
180 Code - Message pair. |