IgH EtherCAT Master  1.5.2
slave.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * 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  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
35 /*****************************************************************************/
36 
37 #ifndef __EC_SLAVE_H__
38 #define __EC_SLAVE_H__
39 
40 #include <linux/list.h>
41 #include <linux/kobject.h>
42 #include <linux/rtmutex.h>
43 
44 #include "globals.h"
45 #include "datagram.h"
46 #include "pdo.h"
47 #include "sync.h"
48 #include "sdo.h"
49 #include "fsm_slave.h"
50 
51 /*****************************************************************************/
52 
63 #define EC_SLAVE_INFO(slave, fmt, args...) \
64  printk(KERN_INFO "EtherCAT %u-%s-%u: " fmt, slave->master->index, \
65  ec_device_names[slave->device_index!=0], slave->ring_position, ##args)
66 
77 #define EC_SLAVE_ERR(slave, fmt, args...) \
78  printk(KERN_ERR "EtherCAT ERROR %u-%s-%u: " fmt, slave->master->index, \
79  ec_device_names[slave->device_index!=0], slave->ring_position, ##args)
80 
91 #define EC_SLAVE_WARN(slave, fmt, args...) \
92  printk(KERN_WARNING "EtherCAT WARNING %u-%s-%u: " fmt, \
93  slave->master->index, ec_device_names[slave->device_index!=0], \
94  slave->ring_position, ##args)
95 
108 #define EC_SLAVE_DBG(slave, level, fmt, args...) \
109  do { \
110  if (slave->master->debug_level >= level) { \
111  printk(KERN_DEBUG "EtherCAT DEBUG %u-%s-%u: " fmt, \
112  slave->master->index, ec_device_names[slave->device_index!=0], \
113  slave->ring_position, ##args); \
114  } \
115  } while (0)
116 
117 /*****************************************************************************/
118 
119 #ifdef EC_LOOP_CONTROL
120 
123 typedef enum {
124  EC_SLAVE_PORT_DOWN,
125  EC_SLAVE_PORT_WAIT,
126  EC_SLAVE_PORT_UP
127 } ec_slave_port_state_t;
128 
131 #define EC_PORT_WAIT_MS 2000
132 
133 #endif
134 
135 /*****************************************************************************/
136 
139 typedef struct {
143  uint32_t receive_time;
145  uint32_t delay_to_next_dc;
147 #ifdef EC_LOOP_CONTROL
148  ec_slave_port_state_t state;
149  unsigned long link_detection_jiffies;
150 #endif
152 
153 /*****************************************************************************/
154 
157 typedef struct {
158  // Non-category data
159  uint16_t alias;
160  uint32_t vendor_id;
161  uint32_t product_code;
162  uint32_t revision_number;
163  uint32_t serial_number;
172  uint16_t mailbox_protocols;
174  // Strings
175  char **strings;
176  unsigned int string_count;
178  // General
179  unsigned int has_general;
180  char *group;
181  char *image;
182  char *order;
183  char *name;
184  uint8_t physical_layer[EC_MAX_PORTS];
187  int16_t current_on_ebus;
189  // SyncM
191  unsigned int sync_count;
193  // [RT]XPDO
194  struct list_head pdos;
195 } ec_sii_t;
196 
197 /*****************************************************************************/
198 
201 typedef struct {
202  struct list_head list;
204  uint16_t *words;
205  size_t nwords;
209 
210 /*****************************************************************************/
211 
214 struct ec_slave
215 {
220  // addresses
221  uint16_t ring_position;
222  uint16_t station_address;
223  uint16_t effective_alias;
224  // identification
225 #ifdef EC_SII_CACHE
230 #endif
232  uint8_t upstream_port;
234  // configuration
238  uint16_t last_al_error;
239  unsigned int error_flag;
240  unsigned int force_config;
241  unsigned int reboot;
250  // base data
251  uint8_t base_type;
252  uint8_t base_revision;
253  uint16_t base_build;
254  uint8_t base_fmmu_count;
255  uint8_t base_sync_count;
265  // Slave information interface
266  uint16_t *vendor_words;
269  struct list_head sdo_dictionary;
270  uint8_t scan_required;
272  unsigned long jiffies_preop;
274  struct list_head sdo_requests;
275  struct list_head reg_requests;
276  struct list_head foe_requests;
277  struct list_head soe_requests;
278  struct list_head eoe_requests;
279  struct list_head mbg_requests;
280  struct list_head dict_requests;
284  uint8_t read_mbox_busy;
285  struct rt_mutex mbox_sem;
287 #ifdef EC_EOE
290 #endif
297  uint8_t valid_mbox_data;
298 };
299 
300 /*****************************************************************************/
301 
302 // slave construction/destruction
304  uint16_t, uint16_t);
305 
307 
308 void ec_slave_clear(ec_slave_t *);
309 
311 
313 void ec_slave_set_dl_status(ec_slave_t *, uint16_t);
316 
317 // SII categories
318 int ec_slave_fetch_sii_strings(ec_slave_t *, const uint8_t *, size_t);
319 int ec_slave_fetch_sii_general(ec_slave_t *, const uint8_t *, size_t);
320 int ec_slave_fetch_sii_syncs(ec_slave_t *, const uint8_t *, size_t);
321 int ec_slave_fetch_sii_pdos(ec_slave_t *, const uint8_t *, size_t,
323 
324 // misc.
326 
328  unsigned int *, unsigned int *);
329 ec_sdo_t *ec_slave_get_sdo(ec_slave_t *, uint16_t);
330 const ec_sdo_t *ec_slave_get_sdo_const(const ec_slave_t *, uint16_t);
331 const ec_sdo_t *ec_slave_get_sdo_by_pos_const(const ec_slave_t *, uint16_t);
332 uint16_t ec_slave_sdo_count(const ec_slave_t *);
333 const ec_pdo_t *ec_slave_find_pdo(const ec_slave_t *, uint16_t);
335 
339 
342 
343 /*****************************************************************************/
344 
345 #endif
ec_sii_general_flags_t general_flags
General flags.
Definition: slave.h:186
ec_mbox_data_t mbox_eoe_frag_data
Received mailbox data for EoE, type frame fragment.
Definition: slave.h:288
Slave information interface general flags.
Definition: globals.h:203
uint16_t ring_position
Ring position.
Definition: slave.h:221
uint32_t revision_number
Revision number.
Definition: slave.h:162
uint8_t upstream_port
Index of master-facing port.
Definition: slave.h:232
uint16_t boot_rx_mailbox_offset
Bootstrap receive mailbox address.
Definition: slave.h:164
int ec_slave_fetch_sii_syncs(ec_slave_t *, const uint8_t *, size_t)
Fetches data from a SYNC MANAGER category.
Definition: slave.c:581
uint16_t configured_tx_mailbox_size
Configured send mailbox size.
Definition: slave.h:248
uint16_t base_build
Build number.
Definition: slave.h:253
ec_slave_port_desc_t
EtherCAT slave port descriptor.
Definition: ecrt.h:354
unsigned int reboot
Request reboot.
Definition: slave.h:241
ec_mbox_data_t mbox_eoe_init_data
Received mailbox data for EoE, type eoe init reponse.
Definition: slave.h:289
void ec_slave_request_state(ec_slave_t *, ec_slave_state_t)
Request a slave state and resets the error flag.
Definition: slave.c:436
void ec_slave_calc_upstream_port(ec_slave_t *)
Calculates which of ports 0-3 appears to be the upstream one.
Definition: slave.c:1085
uint16_t configured_tx_mailbox_offset
Configured send mailbox offset.
Definition: slave.h:246
ec_slave_state_t current_state
Current application state.
Definition: slave.h:237
Complete slave information interface data image.
Definition: slave.h:201
ec_mbox_data_t mbox_mbg_data
Received mailbox data for MBox Gateway.
Definition: slave.h:295
ec_mbox_data_t mbox_foe_data
Received mailbox data for FoE.
Definition: slave.h:292
ec_sync_t * ec_slave_get_sync(ec_slave_t *, uint8_t)
Get the sync manager given an index.
Definition: slave.c:767
ec_slave_port_link_t link
Port link status.
Definition: slave.h:141
EtherCAT mailbox response data.
Definition: datagram.h:122
uint32_t serial_number
Serial number.
Definition: slave.h:163
const ec_pdo_t * ec_slave_find_pdo(const ec_slave_t *, uint16_t)
Finds a mapped PDO.
Definition: slave.c:908
ec_sii_coe_details_t coe_details
CoE detail flags.
Definition: slave.h:185
char * order
Order number.
Definition: slave.h:182
int ec_slave_fetch_sii_general(ec_slave_t *, const uint8_t *, size_t)
Fetches data from a GENERAL category.
Definition: slave.c:525
Finite state machine of an EtherCAT slave.
Definition: fsm_slave.h:63
ec_fsm_slave_t fsm
Slave state machine.
Definition: slave.h:282
CANopen SDO.
Definition: sdo.h:49
int16_t current_on_ebus
Power consumption in mA.
Definition: slave.h:187
uint16_t boot_tx_mailbox_size
Bootstrap transmit mailbox size.
Definition: slave.h:167
void ec_read_mbox_lock_clear(ec_slave_t *)
Clears the mailbox lock.
Definition: slave.c:216
int ec_read_mbox_locked(ec_slave_t *)
Return the current mailbox lock status and lock it if not locked.
Definition: slave.c:229
uint16_t station_address
Configured station address.
Definition: slave.h:222
unsigned int sync_count
Number of sync managers.
Definition: slave.h:191
uint16_t std_rx_mailbox_size
Standard receive mailbox size.
Definition: slave.h:169
uint8_t base_type
Slave type.
Definition: slave.h:251
const ec_sdo_t * ec_slave_get_sdo_const(const ec_slave_t *, uint16_t)
Get an SDO from the dictionary.
Definition: slave.c:845
int ec_slave_fetch_sii_pdos(ec_slave_t *, const uint8_t *, size_t, ec_direction_t)
Fetches data from a [RT]xPDO category.
Definition: slave.c:652
Global definitions and macros.
uint16_t std_tx_mailbox_offset
Standard transmit mailbox address.
Definition: slave.h:170
uint16_t boot_tx_mailbox_offset
Bootstrap transmit mailbox address.
Definition: slave.h:166
void ec_slave_init(ec_slave_t *, ec_master_t *, ec_device_index_t, uint16_t, uint16_t)
Slave constructor.
Definition: slave.c:62
EtherCAT slave.
Definition: slave.h:214
uint16_t ec_slave_sdo_count(const ec_slave_t *)
Get the number of SDOs in the dictionary.
Definition: slave.c:889
ec_sii_image_t * sii_image
Current complete SII image.
Definition: slave.h:267
Slave information interface CANopen over EtherCAT details flags.
Definition: globals.h:192
ec_slave_config_t * config
Current configuration.
Definition: slave.h:235
void ec_slave_sii_image_init(ec_sii_image_t *sii_image)
Definition: slave.c:166
PDO description.
Definition: pdo.h:49
uint8_t sdo_dictionary_fetched
Dictionary has been fetched.
Definition: slave.h:271
uint16_t mailbox_protocols
Supported mailbox protocols.
Definition: slave.h:172
ec_slave_dc_range_t base_dc_range
DC range.
Definition: slave.h:258
Sync manager.
Definition: sync.h:47
uint16_t std_rx_mailbox_offset
Standard receive mailbox address.
Definition: slave.h:168
uint8_t base_fmmu_bit_operation
FMMU bit operation is supported.
Definition: slave.h:256
uint32_t transmission_delay
DC system time transmission delay (offset from reference clock).
Definition: slave.h:262
ec_device_index_t
Master devices.
Definition: globals.h:236
void ec_slave_calc_port_delays(ec_slave_t *)
Calculates the port transmission delays.
Definition: slave.c:1184
uint16_t alias
Configured station alias.
Definition: slave.h:159
ec_direction_t
Direction type for PDO assignment functions.
Definition: ecrt.h:436
uint8_t base_fmmu_count
Number of supported FMMUs.
Definition: slave.h:254
uint16_t configured_rx_mailbox_offset
Configured receive mailbox offset.
Definition: slave.h:242
void ec_slave_clear_sync_managers(ec_slave_t *)
Clear the sync manager array.
Definition: slave.c:355
uint32_t effective_product_code
Effective product code.
Definition: slave.h:227
ec_slave_dc_range_t
EtherCAT slave distributed clocks range.
Definition: globals.h:210
ec_slave_port_desc_t desc
Port descriptors.
Definition: slave.h:140
unsigned int string_count
Number of SII strings.
Definition: slave.h:176
ec_master_t * master
Master owning the slave.
Definition: slave.h:216
uint8_t has_dc_system_time
The slave supports the DC system time register.
Definition: slave.h:259
char ** strings
Strings in SII categories.
Definition: slave.h:175
ec_slave_state_t
State of an EtherCAT slave.
Definition: globals.h:159
void ec_slave_clear(ec_slave_t *)
Slave destructor.
Definition: slave.c:250
void ec_slave_set_dl_status(ec_slave_t *, uint16_t)
Sets the data-link state of a slave.
Definition: slave.c:374
EtherCAT datagram structure.
void ec_slave_set_al_status(ec_slave_t *, ec_slave_state_t)
Sets the application state of a slave.
Definition: slave.c:414
void ec_slave_calc_transmission_delays_rec(ec_slave_t *, uint32_t *)
Recursively calculates transmission delays.
Definition: slave.c:1234
void ec_slave_sdo_dict_info(const ec_slave_t *, unsigned int *, unsigned int *)
Counts the total number of SDOs and entries in the dictionary.
Definition: slave.c:791
uint8_t base_revision
Revision.
Definition: slave.h:252
uint32_t effective_vendor_id
Effective vendor ID.
Definition: slave.h:226
uint16_t * vendor_words
First 16 words of SII image.
Definition: slave.h:266
uint8_t valid_mbox_data
Received mailbox data is valid.
Definition: slave.h:297
uint16_t effective_alias
Effective alias address.
Definition: slave.h:223
uint16_t boot_rx_mailbox_size
Bootstrap receive mailbox size.
Definition: slave.h:165
#define EC_MAX_PORTS
Maximum number of slave ports.
Definition: ecrt.h:217
uint32_t effective_serial_number
Effective serial number.
Definition: slave.h:229
uint8_t read_mbox_busy
Flag set during a mailbox read request.
Definition: slave.h:284
EtherCAT slave request state machine.
ec_slave_t * next_slave
Connected slaves.
Definition: slave.h:142
uint32_t receive_time
Port receive times for delay measurement.
Definition: slave.h:143
EtherCAT sync manager.
Slave port.
Definition: slave.h:139
char * image
Image name.
Definition: slave.h:181
ec_mbox_data_t mbox_voe_data
Received mailbox data for VoE.
Definition: slave.h:294
unsigned long jiffies_preop
Time, the slave went to PREOP.
Definition: slave.h:272
uint16_t configured_rx_mailbox_size
Configured receive mailbox size.
Definition: slave.h:244
uint8_t base_dc_supported
Distributed clocks are supported.
Definition: slave.h:257
Extracted slave information interface data.
Definition: slave.h:157
char * group
Group name.
Definition: slave.h:180
void ec_slave_attach_pdo_names(ec_slave_t *)
Attach PDO names.
Definition: slave.c:969
uint8_t base_sync_count
Number of supported sync managers.
Definition: slave.h:255
EtherCAT slave configuration.
Definition: slave_config.h:118
ec_sii_t sii
Extracted SII data.
Definition: slave.h:207
ec_device_index_t device_index
Index of device the slave responds on.
Definition: slave.h:217
uint32_t product_code
Vendor-specific product code.
Definition: slave.h:161
const ec_sdo_t * ec_slave_get_sdo_by_pos_const(const ec_slave_t *, uint16_t)
Get an SDO from the dictionary, given its position in the list.
Definition: slave.c:867
size_t nwords
Size of the SII contents in words.
Definition: slave.h:205
uint8_t scan_required
Scan required.
Definition: slave.h:270
unsigned int error_flag
Stop processing after an error.
Definition: slave.h:239
ec_sync_t * syncs
SYNC MANAGER categories.
Definition: slave.h:190
uint16_t std_tx_mailbox_size
Standard transmit mailbox size.
Definition: slave.h:171
EtherCAT master.
Definition: master.h:202
ec_slave_state_t requested_state
Requested application state.
Definition: slave.h:236
uint32_t effective_revision_number
Effective revision number.
Definition: slave.h:228
int ec_slave_fetch_sii_strings(ec_slave_t *, const uint8_t *, size_t)
Fetches data from a STRING category.
Definition: slave.c:464
uint16_t last_al_error
Last AL state error code.
Definition: slave.h:238
EtherCAT CANopen SDO structure.
char * name
Slave name.
Definition: slave.h:183
ec_mbox_data_t mbox_coe_data
Received mailbox data for CoE.
Definition: slave.h:291
ec_mbox_data_t mbox_soe_data
Received mailbox data for SoE.
Definition: slave.h:293
uint32_t vendor_id
Vendor ID.
Definition: slave.h:160
uint32_t delay_to_next_dc
Delay to next slave with DC support behind this port [ns].
Definition: slave.h:145
void ec_slave_request_reboot(ec_slave_t *)
Request a slave reboot (some slaves will ignore this).
Definition: slave.c:450
unsigned int force_config
Force (re-)configuration.
Definition: slave.h:240
unsigned int has_general
General category present.
Definition: slave.h:179
ec_sdo_t * ec_slave_get_sdo(ec_slave_t *, uint16_t)
Get an SDO from the dictionary.
Definition: slave.c:819
EtherCAT Process data object structure.