IgH EtherCAT Master  1.6.0-rc1
globals.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2006-2021 Florian Pose, Ingenieurgemeinschaft IgH
4  *
5  * This file is part of the IgH EtherCAT master.
6  *
7  * The file is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; version 2.1 of the License.
10  *
11  * This file is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this file. If not, see <http://www.gnu.org/licenses/>.
18  *
19  *****************************************************************************/
20 
25 /*****************************************************************************/
26 
27 #ifndef __EC_MASTER_GLOBALS_H__
28 #define __EC_MASTER_GLOBALS_H__
29 
30 #include "../globals.h"
31 #include "../include/ecrt.h"
32 
33 /******************************************************************************
34  * EtherCAT master
35  *****************************************************************************/
36 
38 #define EC_IO_TIMEOUT 500
39 
44 #define EC_BYTE_TRANSMISSION_TIME_NS 80
45 
47 #define EC_FSM_RETRIES 3
48 
51 #define EC_WAIT_SDO_DICT 3
52 
54 #define EC_STATE_STRING_SIZE 32
55 
57 #define EC_MAX_SII_SIZE 4096
58 
60 #define EC_RATE_COUNT 3
61 
62 /******************************************************************************
63  * EtherCAT protocol
64  *****************************************************************************/
65 
67 #define EC_FRAME_HEADER_SIZE 2
68 
70 #define EC_DATAGRAM_HEADER_SIZE 10
71 
73 #define EC_DATAGRAM_FOOTER_SIZE 2
74 
76 #define EC_ADDR_LEN 4
77 
79 #ifdef DEBUG_DATAGRAM_OVERFLOW
80 // Define a runt datagram which can be easily overflowed on
81 // available hardware for use when testing ec_domain_finish()
82 #define EC_MAX_DATA_SIZE (128)
83 #else
84 #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \
85  - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE)
86 #endif // DEBUG_DATAGRAM_OVERFLOW
87 
89 #define EC_MBOX_HEADER_SIZE 6
90 
92 #define EC_FIRST_SII_CATEGORY_OFFSET 0x40
93 
95 #define EC_SYNC_PAGE_SIZE 8
96 
98 #define EC_MAX_FMMUS 16
99 
101 #define EC_FMMU_PAGE_SIZE 16
102 
104 #define EC_SYNC_SIGNAL_COUNT 2
105 
110 #define EC_DATAGRAM_NAME_SIZE 20
111 
116 #define EC_MAX_HOSTNAME_SIZE 32
117 
123 #define EC_SLAVE_STATE_MASK 0x0F
124 
127 typedef enum {
143 
149 enum {
150  EC_MBOX_AOE = 0x01,
151  EC_MBOX_EOE = 0x02,
152  EC_MBOX_COE = 0x04,
153  EC_MBOX_FOE = 0x08,
154  EC_MBOX_SOE = 0x10,
155  EC_MBOX_VOE = 0x20
156 };
157 
160 typedef struct {
161  uint8_t enable_sdo : 1;
162  uint8_t enable_sdo_info : 1;
163  uint8_t enable_pdo_assign : 1;
164  uint8_t enable_pdo_configuration : 1;
165  uint8_t enable_upload_at_startup : 1;
166  uint8_t enable_sdo_complete_access : 1;
168 
171 typedef struct {
172  uint8_t enable_safeop : 1;
173  uint8_t enable_not_lrw : 1;
175 
178 typedef enum {
180  EC_DC_64 /*< 64 bit for system time, system time offset and
181  port 0 receive time. */
183 
186 typedef struct {
187  uint32_t cycle_time;
188  int32_t shift_time;
190 
195 enum {
200 };
201 
204 typedef enum {
208 
209 extern const char *ec_device_names[2]; // only main and backup!
210 
211 /*****************************************************************************/
212 
220 #define EC_INFO(fmt, args...) \
221  printk(KERN_INFO "EtherCAT: " fmt, ##args)
222 
230 #define EC_ERR(fmt, args...) \
231  printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args)
232 
240 #define EC_WARN(fmt, args...) \
241  printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args)
242 
250 #define EC_DBG(fmt, args...) \
251  printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args)
252 
253 /*****************************************************************************/
254 
257 #define EC_ABS(X) ((X) >= 0 ? (X) : -(X))
258 
259 /*****************************************************************************/
260 
261 extern char *ec_master_version_str;
262 
263 /*****************************************************************************/
264 
265 unsigned int ec_master_count(void);
266 void ec_print_data(const uint8_t *, size_t);
267 void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t);
268 size_t ec_state_string(uint8_t, char *, uint8_t);
269 size_t ec_mac_print(const uint8_t *, char *);
270 int ec_mac_is_zero(const uint8_t *);
271 
272 ec_master_t *ecrt_request_master_err(unsigned int);
273 
274 /*****************************************************************************/
275 
281 typedef struct {
282  uint32_t code;
283  const char *message;
284 } ec_code_msg_t;
285 
286 /*****************************************************************************/
287 
293 typedef enum {
294  EC_INT_REQUEST_INIT,
295  EC_INT_REQUEST_QUEUED,
296  EC_INT_REQUEST_BUSY,
297  EC_INT_REQUEST_SUCCESS,
298  EC_INT_REQUEST_FAILURE
300 
301 /*****************************************************************************/
302 
304 
305 /*****************************************************************************/
306 
309 typedef enum {
312 } ec_origin_t;
313 
314 /*****************************************************************************/
315 
316 typedef struct ec_slave ec_slave_t;
318 /*****************************************************************************/
319 
320 #endif
Slave information interface general flags.
Definition: globals.h:171
Vendor specific.
Definition: globals.h:155
int ec_mac_is_zero(const uint8_t *)
Definition: module.c:267
void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t)
Outputs frame contents and differences for debugging purposes.
Definition: module.c:373
Servo-Profile over EtherCAT.
Definition: globals.h:154
int32_t shift_time
Shift time [ns].
Definition: globals.h:188
OP (mailbox communication and input/output update)
Definition: globals.h:138
size_t ec_state_string(uint8_t, char *, uint8_t)
Prints slave states in clear text.
Definition: module.c:402
uint32_t code
Code.
Definition: globals.h:282
Bootstrap state (mailbox communication, firmware update)
Definition: globals.h:134
uint32_t cycle_time
Cycle time [ns].
Definition: globals.h:187
Acknowledge/Error bit (no actual state)
Definition: globals.h:140
ec_master_t * ecrt_request_master_err(unsigned int)
Request a master.
Definition: module.c:538
const char * message
Message belonging to code.
Definition: globals.h:283
const char * ec_device_names[2]
Device names.
Definition: module.c:466
size_t ec_mac_print(const uint8_t *, char *)
Print a MAC address to a buffer.
Definition: module.c:246
SAFEOP (mailbox communication and input update)
Definition: globals.h:136
Internal.
Definition: globals.h:310
ec_internal_request_state_t
Generic request state.
Definition: globals.h:293
EtherCAT slave.
Definition: slave.h:199
Code/Message pair.
Definition: globals.h:281
Slave information interface CANopen over EtherCAT details flags.
Definition: globals.h:160
CANopen over EtherCAT.
Definition: globals.h:152
Access rights in OP.
Definition: globals.h:198
ec_device_index_t
Master devices.
Definition: globals.h:204
Number of states.
Definition: globals.h:199
External.
Definition: globals.h:311
Main device.
Definition: globals.h:205
Ethernet over EtherCAT.
Definition: globals.h:151
ec_slave_dc_range_t
EtherCAT slave distributed clocks range.
Definition: globals.h:178
ec_slave_state_t
State of an EtherCAT slave.
Definition: globals.h:127
Access rights in SAFEOP.
Definition: globals.h:197
32 bit.
Definition: globals.h:179
void ec_print_data(const uint8_t *, size_t)
Outputs frame contents for debugging purposes.
Definition: module.c:345
char * ec_master_version_str
Version string.
Definition: module.c:71
INIT state (no mailbox communication, no IO)
Definition: globals.h:130
EtherCAT slave sync signal configuration.
Definition: globals.h:186
ec_origin_t
Origin type.
Definition: globals.h:309
unsigned int ec_master_count(void)
Get the number of masters.
Definition: module.c:208
ec_request_state_t
Request state.
Definition: ecrt.h:535
PREOP state (mailbox communication, no IO)
Definition: globals.h:132
Backup device.
Definition: globals.h:206
Access rights in PREOP.
Definition: globals.h:196
const ec_request_state_t ec_request_state_translation_table[]
Global request state type translation table.
Definition: module.c:659
EtherCAT master.
Definition: master.h:189
ADS over EtherCAT.
Definition: globals.h:150
File-Access over EtherCAT.
Definition: globals.h:153
unknown state
Definition: globals.h:128