libethercat - an embeddable realtime EtherCAT-master library
Communicate with EtherCAT slaves attached to a Network interface.
Loading...
Searching...
No Matches
slave.h
Go to the documentation of this file.
1
13/*
14 * This file is part of libethercat.
15 *
16 * libethercat is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 3 of the License, or (at your option) any later version.
20 *
21 * libethercat is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with libethercat (LICENSE.LGPL-V3); if not, write
28 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
29 * Floor, Boston, MA 02110-1301, USA.
30 *
31 * Please note that the use of the EtherCAT technology, the EtherCAT
32 * brand name and the EtherCAT logo is only permitted if the property
33 * rights of Beckhoff Automation GmbH are observed. For further
34 * information please contact Beckhoff Automation GmbH & Co. KG,
35 * Hülshorstweg 20, D-33415 Verl, Germany (www.beckhoff.com) or the
36 * EtherCAT Technology Group, Ostendstraße 196, D-90482 Nuremberg,
37 * Germany (ETG, www.ethercat.org).
38 *
39 */
40
41#ifndef LIBETHERCAT_SLAVE_H
42#define LIBETHERCAT_SLAVE_H
43
44#include <libosal/types.h>
45
46#include <assert.h>
47
48#include "libethercat/common.h"
49#include "libethercat/eeprom.h"
50#include "libethercat/dc.h"
51#include "libethercat/mbx.h"
52
61#define BOOT_2_BOOT 0x0303u
62#define BOOT_2_INIT 0x0301u
63#define BOOT_2_PREOP 0x0302u
64#define BOOT_2_SAFEOP 0x0304u
65#define BOOT_2_OP 0x0308u
66#define UNKNOWN_2_BOOT 0x0003u
67#define UNKNOWN_2_INIT 0x0001u
68#define UNKNOWN_2_PREOP 0x0002u
69#define UNKNOWN_2_SAFEOP 0x0004u
70#define UNKNOWN_2_OP 0x0008u
71#define INIT_2_BOOT 0x0103u
72#define INIT_2_INIT 0x0101u
73#define INIT_2_PREOP 0x0102u
74#define INIT_2_SAFEOP 0x0104u
75#define INIT_2_OP 0x0108u
76#define PREOP_2_BOOT 0x0203u
77#define PREOP_2_INIT 0x0201u
78#define PREOP_2_PREOP 0x0202u
79#define PREOP_2_SAFEOP 0x0204u
80#define PREOP_2_OP 0x0208u
81#define SAFEOP_2_BOOT 0x0403u
82#define SAFEOP_2_INIT 0x0401u
83#define SAFEOP_2_PREOP 0x0402u
84#define SAFEOP_2_SAFEOP 0x0404u
85#define SAFEOP_2_OP 0x0408u
86#define OP_2_BOOT 0x0803u
87#define OP_2_INIT 0x0801u
88#define OP_2_PREOP 0x0802u
89#define OP_2_SAFEOP 0x0804u
90#define OP_2_OP 0x0808u
91
92typedef osal_uint16_t ec_state_transition_t;
93
95typedef struct PACKED ec_slave_sm {
96 osal_uint16_t adr;
102 osal_uint16_t len;
108 osal_uint32_t flags;
114
116typedef struct PACKED ec_slave_fmmu {
117 osal_uint32_t log;
126 osal_uint16_t log_len;
133 osal_uint8_t log_bit_start;
138 osal_uint8_t log_bit_stop;
143 osal_uint16_t phys;
150 osal_uint8_t phys_bit_start;
156 osal_uint8_t type;
160 osal_uint8_t active;
164 osal_uint8_t reserverd[3];
166
172
219
220#define INIT_CMD_SIZE (sizeof(ec_init_cmd_t))
221
222LIST_HEAD(ec_init_cmds, ec_init_cmd);
223
224typedef struct worker_arg {
225 struct ec *pec;
226 int slave;
227 ec_state_t state;
229
230typedef struct ec_slave {
231 osal_uint32_t slave;
232
233 osal_int16_t auto_inc_address;
234 osal_uint16_t fixed_address;
235
236 osal_uint16_t type;
237 osal_uint8_t sm_ch;
238 osal_uint8_t fmmu_ch;
239 osal_uint32_t ram_size;
240 osal_uint16_t features;
241 osal_uint16_t pdi_ctrl;
242 osal_uint8_t link_cnt;
243 osal_uint8_t active_ports;
244 osal_uint16_t ptype;
245 osal_int32_t pdelay;
246
248 int parent;
250
296 osal_size_t subdev_cnt;
313
316
317#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
319#endif
320
321 ec_state_t expected_state;
322 ec_state_t act_state;
323
324 osal_mutex_t transition_mutex;
325 osal_bool_t transition_active;
326
327 struct ec_init_cmds init_cmds;
329
343 osal_task_t worker_tid;
348} ec_slave_t;
349
350
351#define ec_slave_ptr(ptr, pec, slave) \
352 ec_slave_t *(ptr) = (ec_slave_t *)&pec->slaves[slave]; \
353 assert((ptr) != NULL);
354
355#ifdef __cplusplus
356extern "C" {
357#endif
358#if 0
359}
360#endif
361
362// init slave resources
370void ec_slave_init(struct ec *pec, osal_uint16_t slave);
371
372// free slave resources
380void ec_slave_free(struct ec *pec, osal_uint16_t slave);
381
383
390void ec_slave_reset(ec_t *pec, osal_uint16_t slave);
391
393
406int ec_slave_set_state(struct ec *pec, osal_uint16_t slave, ec_state_t state);
407
409
425int ec_slave_get_state(struct ec *pec, osal_uint16_t slave,
426 ec_state_t *state, osal_uint16_t *alstatcode);
427
429
442int ec_slave_generate_mapping(struct ec *pec, osal_uint16_t slave);
443
445
460int ec_slave_prepare_state_transition(struct ec *pec, osal_uint16_t slave,
461 ec_state_t state);
462
464
477int ec_slave_state_transition(struct ec *pec, osal_uint16_t slave,
478 ec_state_t state);
479
481
496 int transition, int id, int si_el, int ca_atn,
497 osal_char_t *data, osal_size_t datalen);
498
499#if LIBETHERCAT_MBX_SUPPORT_SOE == 1
501
515void ec_slave_mailbox_soe_init_cmd_init(ec_init_cmd_t *cmd,
516 int transition, int id, int si_el, int ca_atn,
517 osal_char_t *data, osal_size_t datalen);
518#endif
519
521
531void ec_slave_add_init_cmd(ec_t *pec, osal_uint16_t slave, ec_init_cmd_t *cmd);
532
534
550void ec_slave_set_dc_config(struct ec *pec, osal_uint16_t slave,
551 int use_dc, int type, osal_uint32_t cycle_time_0,
552 osal_uint32_t cycle_time_1, osal_int32_t cycle_shift);
553
554#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
556
569void ec_slave_set_eoe_settings(struct ec *pec, osal_uint16_t slave,
570 osal_uint8_t *mac, osal_uint8_t *ip_address, osal_uint8_t *subnet, osal_uint8_t *gateway,
571 osal_uint8_t *dns, osal_char_t *dns_name);
572#endif
573
574const osal_char_t *al_status_code_2_string(int code);
575
576#if 0
577{
578#endif
579#ifdef __cplusplus
580}
581#endif
582
585#endif // LIBETHERCAT_SLAVE_H
586
ethercat master common stuff
#define LEC_MAX_SLAVE_FMMU
Maximum number of slave FMMUs.
Definition common.h:95
#define LEC_MAX_SLAVE_SM
Maximum number of slave sync managers.
Definition common.h:103
#define LEC_MAX_INIT_CMD_DATA
Maximum size of init command data.
Definition common.h:87
#define LEC_MAX_DS402_SUBDEVS
Maximum DS420 sub devices.
Definition common.h:183
ethercat distributed clocks support.
EtherCAT eeprom access fuctions.
void ec_slave_init(struct ec *pec, osal_uint16_t slave)
void ec_slave_reset(ec_t *pec, osal_uint16_t slave)
issue hardware reset of slave
struct ec_slave_subdev ec_slave_subdev_t
EtherCAT sub device.
struct worker_arg worker_arg_t
Worker thread argument structure.
void ec_slave_set_dc_config(struct ec *pec, osal_uint16_t slave, int use_dc, int type, osal_uint32_t cycle_time_0, osal_uint32_t cycle_time_1, osal_int32_t cycle_shift)
Set Distributed Clocks config to slave.
void ec_slave_add_init_cmd(ec_t *pec, osal_uint16_t slave, ec_init_cmd_t *cmd)
Add master init command.
struct ec_init_cmd ec_init_cmd_t
slave mailbox init commands
struct PACKED ec_slave_sm ec_slave_sm_t
slave sync manager settings
struct PACKED ec_slave_fmmu ec_slave_fmmu_t
slave fielbus memory management unit (fmmu) settings
void ec_slave_free(struct ec *pec, osal_uint16_t slave)
int ec_slave_generate_mapping(struct ec *pec, osal_uint16_t slave)
Generate process data mapping.
int ec_slave_state_transition(struct ec *pec, osal_uint16_t slave, ec_state_t state)
Execute state transition on EtherCAT slave.
int ec_slave_set_state(struct ec *pec, osal_uint16_t slave, ec_state_t state)
Set EtherCAT state on slave.
int ec_slave_prepare_state_transition(struct ec *pec, osal_uint16_t slave, ec_state_t state)
Prepare state transition on EtherCAT slave.
void ec_slave_mailbox_coe_init_cmd_init(ec_init_cmd_t *cmd, int transition, int id, int si_el, int ca_atn, osal_char_t *data, osal_size_t datalen)
Initialize CoE init command.
int ec_slave_get_state(struct ec *pec, osal_uint16_t slave, ec_state_t *state, osal_uint16_t *alstatcode)
Get EtherCAT state from slave.
ethercat mailbox common access functions
Definition dc.h:66
Definition eoe.h:64
slave mailbox init commands
Definition slave.h:174
osal_char_t data[LEC_MAX_INIT_CMD_DATA]
new id data
Definition slave.h:216
int transition
ECat transition.
Definition slave.h:183
int ca_atn
flags
Definition slave.h:209
osal_size_t datalen
new id data length
Definition slave.h:217
int type
Mailbox type.
Definition slave.h:175
LIST_ENTRY(ec_init_cmd) le
List entry handle.
int id
index
Definition slave.h:194
int si_el
sub index
Definition slave.h:202
Definition mbx.h:118
process data structure
Definition common.h:211
slave fielbus memory management unit (fmmu) settings
Definition slave.h:116
osal_uint8_t active
activation flag
Definition slave.h:160
osal_uint8_t phys_bit_start
physical start bit at physical address
Definition slave.h:150
osal_uint8_t log_bit_start
start bit at logical bus address
Definition slave.h:133
osal_uint16_t phys
physical (local) address in slave
Definition slave.h:143
osal_uint32_t log
logical bus address
Definition slave.h:117
osal_uint16_t log_len
length of logical address area
Definition slave.h:126
osal_uint8_t log_bit_stop
stop bit at logical address plus length
Definition slave.h:138
osal_uint8_t type
type, read or write
Definition slave.h:156
slave sync manager settings
Definition slave.h:95
osal_uint16_t adr
sync manager address
Definition slave.h:96
osal_uint16_t len
sync manager length
Definition slave.h:102
osal_uint32_t flags
sync manager flags
Definition slave.h:108
EtherCAT sub device.
Definition slave.h:168
ec_pd_t pdout
process data outputs
Definition slave.h:170
ec_pd_t pdin
process data inputs
Definition slave.h:169
Definition slave.h:230
ec_dc_info_slave_t dc
Distributed Clock settings.
Definition slave.h:315
int port_on_parent
port attached on parent slave
Definition slave.h:249
osal_uint16_t pdi_ctrl
configuration of process data interface
Definition slave.h:241
osal_int16_t auto_inc_address
physical bus address
Definition slave.h:233
struct ec_init_cmds init_cmds
EtherCAT slave init commands.
Definition slave.h:327
ec_slave_fmmu_t fmmu[LEC_MAX_SLAVE_FMMU]
array of fmmu settings
Definition slave.h:269
ec_mbx_t mbx
EtherCAT mailbox structure.
Definition slave.h:312
int assigned_pd_group
Process data group this slave is assigned to.
Definition slave.h:277
osal_uint32_t ram_size
ram size in bytes
Definition slave.h:239
osal_int32_t pdelay
propagation delay of the slave
Definition slave.h:245
osal_task_t worker_tid
Set state worker thread handle.
Definition slave.h:343
ec_pd_t pdin
input process data
Definition slave.h:278
ec_state_t expected_state
Master expected slave state.
Definition slave.h:321
osal_bool_t transition_active
Flag is state transition is currently active.
Definition slave.h:325
ec_slave_sm_t sm[LEC_MAX_SLAVE_SM]
array of sm settings
Definition slave.h:261
ec_slave_subdev_t subdevs[LEC_MAX_DS402_SUBDEVS]
array of sub devices
Definition slave.h:304
osal_uint8_t link_cnt
link count
Definition slave.h:242
int entry_port
entry port from parent slave
Definition slave.h:247
osal_uint16_t ptype
ptype
Definition slave.h:244
osal_uint8_t sm_ch
number of sync manager channels
Definition slave.h:237
osal_uint16_t features
fmmu operation, dc available
Definition slave.h:240
ec_state_t act_state
Actual/Last read slave state.
Definition slave.h:322
osal_uint8_t active_ports
active ports with link
Definition slave.h:243
osal_uint8_t fmmu_ch
number of fmmu channels
Definition slave.h:238
osal_uint32_t slave
Slave index in EtherCAT master array.
Definition slave.h:231
osal_size_t subdev_cnt
count of sub devices
Definition slave.h:296
osal_mutex_t transition_mutex
Lock for state transition pending.
Definition slave.h:324
osal_uint16_t type
value of EC_REG_TYPE
Definition slave.h:236
int parent
parent slave number
Definition slave.h:248
ec_pd_t pdout
output process data
Definition slave.h:287
worker_arg_t worker_arg
Set state worker thread arguments.
Definition slave.h:338
eeprom_info_t eeprom
EtherCAT slave EEPROM data.
Definition slave.h:314
osal_uint16_t fixed_address
virtual bus address, programmed on start
Definition slave.h:234
int sm_set_by_user
sm set by user
Definition slave.h:251
ethercat master structure
Definition ec.h:192
Definition eeprom.h:143
Definition slave.h:224
ec_state_t state
State of EtherCAT slave.
Definition slave.h:227
int slave
Slave number this worker is doing things for.
Definition slave.h:226
struct ec * pec
Pointer to EtherCAT master struct.
Definition slave.h:225