IgH EtherCAT Master  1.5.2
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#define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \
80 - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE)
81
83#define EC_MBOX_HEADER_SIZE 6
84
86#define EC_FIRST_SII_CATEGORY_OFFSET 0x40
87
89#define EC_SYNC_PAGE_SIZE 8
90
92#define EC_MAX_FMMUS 16
93
95#define EC_FMMU_PAGE_SIZE 16
96
98#define EC_SYNC_SIGNAL_COUNT 2
99
104#define EC_DATAGRAM_NAME_SIZE 20
105
111#define EC_SLAVE_STATE_MASK 0x0F
112
115typedef enum {
118 EC_SLAVE_STATE_INIT = 0x01,
122 EC_SLAVE_STATE_BOOT = 0x03,
126 EC_SLAVE_STATE_OP = 0x08,
131
134enum {
135 EC_MBOX_AOE = 0x01,
136 EC_MBOX_EOE = 0x02,
137 EC_MBOX_COE = 0x04,
138 EC_MBOX_FOE = 0x08,
139 EC_MBOX_SOE = 0x10,
140 EC_MBOX_VOE = 0x20
142
145typedef struct {
146 uint8_t enable_sdo : 1;
147 uint8_t enable_sdo_info : 1;
148 uint8_t enable_pdo_assign : 1;
153
156typedef struct {
157 uint8_t enable_safeop : 1;
158 uint8_t enable_not_lrw : 1;
160
163typedef enum {
165 EC_DC_64 /*< 64 bit for system time, system time offset and
166 port 0 receive time. */
168
171typedef struct {
172 uint32_t cycle_time;
173 int32_t shift_time;
175
180enum {
186
189typedef enum {
193
194extern const char *ec_device_names[2]; // only main and backup!
195
196/*****************************************************************************/
197
205#define EC_INFO(fmt, args...) \
206 printk(KERN_INFO "EtherCAT: " fmt, ##args)
207
215#define EC_ERR(fmt, args...) \
216 printk(KERN_ERR "EtherCAT ERROR: " fmt, ##args)
217
225#define EC_WARN(fmt, args...) \
226 printk(KERN_WARNING "EtherCAT WARNING: " fmt, ##args)
227
235#define EC_DBG(fmt, args...) \
236 printk(KERN_DEBUG "EtherCAT DEBUG: " fmt, ##args)
237
238/*****************************************************************************/
239
242#define EC_ABS(X) ((X) >= 0 ? (X) : -(X))
243
244/*****************************************************************************/
245
246extern char *ec_master_version_str;
247
248/*****************************************************************************/
249
250unsigned int ec_master_count(void);
251void ec_print_data(const uint8_t *, size_t);
252void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t);
253size_t ec_state_string(uint8_t, char *, uint8_t);
254ssize_t ec_mac_print(const uint8_t *, char *);
255int ec_mac_is_zero(const uint8_t *);
256
258
259/*****************************************************************************/
260
266typedef struct {
267 uint32_t code;
268 const char *message;
270
271/*****************************************************************************/
272
278typedef enum {
279 EC_INT_REQUEST_INIT,
280 EC_INT_REQUEST_QUEUED,
281 EC_INT_REQUEST_BUSY,
282 EC_INT_REQUEST_SUCCESS,
283 EC_INT_REQUEST_FAILURE
285
286/*****************************************************************************/
287
289
290/*****************************************************************************/
291
294typedef enum {
298
299/*****************************************************************************/
300
301typedef struct ec_slave ec_slave_t;
303/*****************************************************************************/
304
305#endif
ec_slave_state_t
State of an EtherCAT slave.
Definition: globals.h:115
@ EC_SLAVE_STATE_BOOT
Bootstrap state (mailbox communication, firmware update)
Definition: globals.h:122
@ EC_SLAVE_STATE_PREOP
PREOP state (mailbox communication, no IO)
Definition: globals.h:120
@ EC_SLAVE_STATE_OP
OP (mailbox communication and input/output update)
Definition: globals.h:126
@ EC_SLAVE_STATE_SAFEOP
SAFEOP (mailbox communication and input update)
Definition: globals.h:124
@ EC_SLAVE_STATE_UNKNOWN
unknown state
Definition: globals.h:116
@ EC_SLAVE_STATE_INIT
INIT state (no mailbox communication, no IO)
Definition: globals.h:118
@ EC_SLAVE_STATE_ACK_ERR
Acknowledge/Error bit (no actual state)
Definition: globals.h:128
void ec_print_data_diff(const uint8_t *, const uint8_t *, size_t)
Outputs frame contents and differences for debugging purposes.
Definition: module.c:376
const ec_request_state_t ec_request_state_translation_table[]
Global request state type translation table.
Definition: module.c:662
int ec_mac_is_zero(const uint8_t *)
Definition: module.c:270
unsigned int ec_master_count(void)
Get the number of masters.
Definition: module.c:211
ssize_t ec_mac_print(const uint8_t *, char *)
Print a MAC address to a buffer.
Definition: module.c:249
size_t ec_state_string(uint8_t, char *, uint8_t)
Prints slave states in clear text.
Definition: module.c:405
ec_slave_dc_range_t
EtherCAT slave distributed clocks range.
Definition: globals.h:163
@ EC_DC_32
32 bit.
Definition: globals.h:164
ec_master_t * ecrt_request_master_err(unsigned int)
Request a master.
Definition: module.c:541
@ EC_SDO_ENTRY_ACCESS_PREOP
Access rights in PREOP.
Definition: globals.h:181
@ EC_SDO_ENTRY_ACCESS_COUNT
Number of states.
Definition: globals.h:184
@ EC_SDO_ENTRY_ACCESS_OP
Access rights in OP.
Definition: globals.h:183
@ EC_SDO_ENTRY_ACCESS_SAFEOP
Access rights in SAFEOP.
Definition: globals.h:182
char * ec_master_version_str
Version string.
Definition: module.c:72
const char * ec_device_names[2]
Device names.
Definition: module.c:469
ec_origin_t
Origin type.
Definition: globals.h:294
@ EC_ORIG_EXTERNAL
External.
Definition: globals.h:296
@ EC_ORIG_INTERNAL
Internal.
Definition: globals.h:295
ec_device_index_t
Master devices.
Definition: globals.h:189
@ EC_DEVICE_MAIN
Main device.
Definition: globals.h:190
@ EC_DEVICE_BACKUP
Backup device.
Definition: globals.h:191
@ EC_MBOX_FOE
File-Access over EtherCAT.
Definition: globals.h:138
@ EC_MBOX_COE
CANopen over EtherCAT.
Definition: globals.h:137
@ EC_MBOX_EOE
Ethernet over EtherCAT.
Definition: globals.h:136
@ EC_MBOX_VOE
Vendor specific.
Definition: globals.h:140
@ EC_MBOX_SOE
Servo-Profile over EtherCAT.
Definition: globals.h:139
@ EC_MBOX_AOE
ADS over EtherCAT.
Definition: globals.h:135
ec_internal_request_state_t
Generic request state.
Definition: globals.h:278
void ec_print_data(const uint8_t *, size_t)
Outputs frame contents for debugging purposes.
Definition: module.c:348
ec_request_state_t
Request state.
Definition: ecrt.h:530
Code/Message pair.
Definition: globals.h:266
uint32_t code
Code.
Definition: globals.h:267
const char * message
Message belonging to code.
Definition: globals.h:268
EtherCAT master.
Definition: master.h:194
Slave information interface CANopen over EtherCAT details flags.
Definition: globals.h:145
uint8_t enable_sdo
Enable SDO access.
Definition: globals.h:146
uint8_t enable_upload_at_startup
?.
Definition: globals.h:150
uint8_t enable_pdo_assign
PDO mapping configurable.
Definition: globals.h:148
uint8_t enable_sdo_complete_access
Complete access possible.
Definition: globals.h:151
uint8_t enable_pdo_configuration
PDO configuration possible.
Definition: globals.h:149
uint8_t enable_sdo_info
SDO information service available.
Definition: globals.h:147
Slave information interface general flags.
Definition: globals.h:156
uint8_t enable_safeop
?.
Definition: globals.h:157
uint8_t enable_not_lrw
Slave does not support LRW.
Definition: globals.h:158
EtherCAT slave.
Definition: slave.h:177
EtherCAT slave sync signal configuration.
Definition: globals.h:171
uint32_t cycle_time
Cycle time [ns].
Definition: globals.h:172
int32_t shift_time
Shift time [ns].
Definition: globals.h:173