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#ifdef HAVE_CONFIG_H
47#include "libethercat/config.h"
48#endif
49
50#include <assert.h>
51
52#include "libethercat/common.h"
53#include "libethercat/eeprom.h"
54#include "libethercat/dc.h"
55#include "libethercat/mbx.h"
56
65#define BOOT_2_BOOT 0x0303u
66#define BOOT_2_INIT 0x0301u
67#define BOOT_2_PREOP 0x0302u
68#define BOOT_2_SAFEOP 0x0304u
69#define BOOT_2_OP 0x0308u
70#define UNKNOWN_2_BOOT 0x0003u
71#define UNKNOWN_2_INIT 0x0001u
72#define UNKNOWN_2_PREOP 0x0002u
73#define UNKNOWN_2_SAFEOP 0x0004u
74#define UNKNOWN_2_OP 0x0008u
75#define INIT_2_BOOT 0x0103u
76#define INIT_2_INIT 0x0101u
77#define INIT_2_PREOP 0x0102u
78#define INIT_2_SAFEOP 0x0104u
79#define INIT_2_OP 0x0108u
80#define PREOP_2_BOOT 0x0203u
81#define PREOP_2_INIT 0x0201u
82#define PREOP_2_PREOP 0x0202u
83#define PREOP_2_SAFEOP 0x0204u
84#define PREOP_2_OP 0x0208u
85#define SAFEOP_2_BOOT 0x0403u
86#define SAFEOP_2_INIT 0x0401u
87#define SAFEOP_2_PREOP 0x0402u
88#define SAFEOP_2_SAFEOP 0x0404u
89#define SAFEOP_2_OP 0x0408u
90#define OP_2_BOOT 0x0803u
91#define OP_2_INIT 0x0801u
92#define OP_2_PREOP 0x0802u
93#define OP_2_SAFEOP 0x0804u
94#define OP_2_OP 0x0808u
95
96typedef osal_uint16_t ec_state_transition_t;
97
99typedef struct PACKED ec_slave_sm {
100 osal_uint16_t adr;
106 osal_uint16_t len;
112 osal_uint32_t flags;
118
120typedef struct PACKED ec_slave_fmmu {
121 osal_uint32_t log;
130 osal_uint16_t log_len;
137 osal_uint8_t log_bit_start;
142 osal_uint8_t log_bit_stop;
147 osal_uint16_t phys;
154 osal_uint8_t phys_bit_start;
160 osal_uint8_t type;
164 osal_uint8_t active;
168 osal_uint8_t reserverd[3];
170
176
223
224#define INIT_CMD_SIZE (sizeof(ec_init_cmd_t))
225
226LIST_HEAD(ec_init_cmds, ec_init_cmd);
227
228typedef struct worker_arg {
229 struct ec *pec;
230 int slave;
231 ec_state_t state;
233
234typedef struct ec_slave {
235 osal_uint32_t slave;
236
237 osal_int16_t auto_inc_address;
238 osal_uint16_t fixed_address;
239
240 osal_uint16_t type;
241 osal_uint8_t sm_ch;
242 osal_uint8_t fmmu_ch;
243 osal_uint32_t ram_size;
244 osal_uint16_t features;
245 osal_uint16_t pdi_ctrl;
246 osal_uint8_t link_cnt;
247 osal_uint8_t active_ports;
248 osal_uint16_t ptype;
249 osal_int32_t pdelay;
250
252 int parent;
254
300 osal_size_t subdev_cnt;
317
320
321#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
323#endif
324
325 ec_state_t expected_state;
326 ec_state_t act_state;
327
328 osal_mutex_t transition_mutex;
329 osal_bool_t transition_active;
330
331 struct ec_init_cmds init_cmds;
333
347 osal_task_t worker_tid;
352} ec_slave_t;
353
354
355#define ec_slave_ptr(ptr, pec, slave) \
356 ec_slave_t *(ptr) = (ec_slave_t *)&pec->slaves[slave]; \
357 assert((ptr) != NULL);
358
359#ifdef __cplusplus
360extern "C" {
361#endif
362#if 0
363}
364#endif
365
366// init slave resources
374void ec_slave_init(struct ec *pec, osal_uint16_t slave);
375
376// free slave resources
384void ec_slave_free(struct ec *pec, osal_uint16_t slave);
385
387
394void ec_slave_reset(ec_t *pec, osal_uint16_t slave);
395
397
410int ec_slave_set_state(struct ec *pec, osal_uint16_t slave, ec_state_t state);
411
413
429int ec_slave_get_state(struct ec *pec, osal_uint16_t slave,
430 ec_state_t *state, osal_uint16_t *alstatcode);
431
433
446int ec_slave_generate_mapping(struct ec *pec, osal_uint16_t slave);
447
449
464int ec_slave_prepare_state_transition(struct ec *pec, osal_uint16_t slave,
465 ec_state_t state);
466
468
481int ec_slave_state_transition(struct ec *pec, osal_uint16_t slave,
482 ec_state_t state);
483
485
500 int transition, int id, int si_el, int ca_atn,
501 osal_char_t *data, osal_size_t datalen);
502
503#if LIBETHERCAT_MBX_SUPPORT_SOE == 1
505
519void ec_slave_mailbox_soe_init_cmd_init(ec_init_cmd_t *cmd,
520 int transition, int id, int si_el, int ca_atn,
521 osal_char_t *data, osal_size_t datalen);
522#endif
523
525
535void ec_slave_add_init_cmd(ec_t *pec, osal_uint16_t slave, ec_init_cmd_t *cmd);
536
538
554void ec_slave_set_dc_config(struct ec *pec, osal_uint16_t slave,
555 int use_dc, int type, osal_uint32_t cycle_time_0,
556 osal_uint32_t cycle_time_1, osal_int32_t cycle_shift);
557
558#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
560
573void ec_slave_set_eoe_settings(struct ec *pec, osal_uint16_t slave,
574 osal_uint8_t *mac, osal_uint8_t *ip_address, osal_uint8_t *subnet, osal_uint8_t *gateway,
575 osal_uint8_t *dns, osal_char_t *dns_name);
576#endif
577
578const osal_char_t *al_status_code_2_string(int code);
579
580#if 0
581{
582#endif
583#ifdef __cplusplus
584}
585#endif
586
589#endif // LIBETHERCAT_SLAVE_H
590
ethercat master common stuff
#define LEC_MAX_SLAVE_FMMU
Maximum number of slave FMMUs.
Definition common.h:97
#define LEC_MAX_SLAVE_SM
Maximum number of slave sync managers.
Definition common.h:105
#define LEC_MAX_INIT_CMD_DATA
Maximum size of init command data.
Definition common.h:89
#define LEC_MAX_DS402_SUBDEVS
Maximum DS420 sub devices.
Definition common.h:185
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:67
Definition eoe.h:63
slave mailbox init commands
Definition slave.h:178
osal_char_t data[LEC_MAX_INIT_CMD_DATA]
new id data
Definition slave.h:220
int transition
ECat transition.
Definition slave.h:187
int ca_atn
flags
Definition slave.h:213
osal_size_t datalen
new id data length
Definition slave.h:221
int type
Mailbox type.
Definition slave.h:179
LIST_ENTRY(ec_init_cmd) le
List entry handle.
int id
index
Definition slave.h:198
int si_el
sub index
Definition slave.h:206
Definition mbx.h:117
process data structure
Definition common.h:213
slave fielbus memory management unit (fmmu) settings
Definition slave.h:120
osal_uint8_t active
activation flag
Definition slave.h:164
osal_uint8_t phys_bit_start
physical start bit at physical address
Definition slave.h:154
osal_uint8_t log_bit_start
start bit at logical bus address
Definition slave.h:137
osal_uint16_t phys
physical (local) address in slave
Definition slave.h:147
osal_uint32_t log
logical bus address
Definition slave.h:121
osal_uint16_t log_len
length of logical address area
Definition slave.h:130
osal_uint8_t log_bit_stop
stop bit at logical address plus length
Definition slave.h:142
osal_uint8_t type
type, read or write
Definition slave.h:160
slave sync manager settings
Definition slave.h:99
osal_uint16_t adr
sync manager address
Definition slave.h:100
osal_uint16_t len
sync manager length
Definition slave.h:106
osal_uint32_t flags
sync manager flags
Definition slave.h:112
EtherCAT sub device.
Definition slave.h:172
ec_pd_t pdout
process data outputs
Definition slave.h:174
ec_pd_t pdin
process data inputs
Definition slave.h:173
Definition slave.h:234
ec_dc_info_slave_t dc
Distributed Clock settings.
Definition slave.h:319
int port_on_parent
port attached on parent slave
Definition slave.h:253
osal_uint16_t pdi_ctrl
configuration of process data interface
Definition slave.h:245
osal_int16_t auto_inc_address
physical bus address
Definition slave.h:237
struct ec_init_cmds init_cmds
EtherCAT slave init commands.
Definition slave.h:331
ec_slave_fmmu_t fmmu[LEC_MAX_SLAVE_FMMU]
array of fmmu settings
Definition slave.h:273
ec_mbx_t mbx
EtherCAT mailbox structure.
Definition slave.h:316
int assigned_pd_group
Process data group this slave is assigned to.
Definition slave.h:281
osal_uint32_t ram_size
ram size in bytes
Definition slave.h:243
osal_int32_t pdelay
propagation delay of the slave
Definition slave.h:249
osal_task_t worker_tid
Set state worker thread handle.
Definition slave.h:347
ec_pd_t pdin
input process data
Definition slave.h:282
ec_state_t expected_state
Master expected slave state.
Definition slave.h:325
osal_bool_t transition_active
Flag is state transition is currently active.
Definition slave.h:329
ec_slave_sm_t sm[LEC_MAX_SLAVE_SM]
array of sm settings
Definition slave.h:265
ec_slave_subdev_t subdevs[LEC_MAX_DS402_SUBDEVS]
array of sub devices
Definition slave.h:308
osal_uint8_t link_cnt
link count
Definition slave.h:246
int entry_port
entry port from parent slave
Definition slave.h:251
osal_uint16_t ptype
ptype
Definition slave.h:248
osal_uint8_t sm_ch
number of sync manager channels
Definition slave.h:241
osal_uint16_t features
fmmu operation, dc available
Definition slave.h:244
ec_state_t act_state
Actual/Last read slave state.
Definition slave.h:326
osal_uint8_t active_ports
active ports with link
Definition slave.h:247
osal_uint8_t fmmu_ch
number of fmmu channels
Definition slave.h:242
osal_uint32_t slave
Slave index in EtherCAT master array.
Definition slave.h:235
osal_size_t subdev_cnt
count of sub devices
Definition slave.h:300
osal_mutex_t transition_mutex
Lock for state transition pending.
Definition slave.h:328
osal_uint16_t type
value of EC_REG_TYPE
Definition slave.h:240
int parent
parent slave number
Definition slave.h:252
ec_pd_t pdout
output process data
Definition slave.h:291
worker_arg_t worker_arg
Set state worker thread arguments.
Definition slave.h:342
eeprom_info_t eeprom
EtherCAT slave EEPROM data.
Definition slave.h:318
osal_uint16_t fixed_address
virtual bus address, programmed on start
Definition slave.h:238
int sm_set_by_user
sm set by user
Definition slave.h:255
ethercat master structure
Definition ec.h:188
Definition eeprom.h:143
Definition slave.h:228
ec_state_t state
State of EtherCAT slave.
Definition slave.h:231
int slave
Slave number this worker is doing things for.
Definition slave.h:230
struct ec * pec
Pointer to EtherCAT master struct.
Definition slave.h:229