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 "libethercat/config.h"
47#include "libethercat/common.h"
48#include "libethercat/eeprom.h"
49#include "libethercat/dc.h"
50#include "libethercat/mbx.h"
51
60#define BOOT_2_BOOT 0x0303u
61#define BOOT_2_INIT 0x0301u
62#define BOOT_2_PREOP 0x0302u
63#define BOOT_2_SAFEOP 0x0304u
64#define BOOT_2_OP 0x0308u
65#define UNKNOWN_2_BOOT 0x0003u
66#define UNKNOWN_2_INIT 0x0001u
67#define UNKNOWN_2_PREOP 0x0002u
68#define UNKNOWN_2_SAFEOP 0x0004u
69#define UNKNOWN_2_OP 0x0008u
70#define INIT_2_BOOT 0x0103u
71#define INIT_2_INIT 0x0101u
72#define INIT_2_PREOP 0x0102u
73#define INIT_2_SAFEOP 0x0104u
74#define INIT_2_OP 0x0108u
75#define PREOP_2_BOOT 0x0203u
76#define PREOP_2_INIT 0x0201u
77#define PREOP_2_PREOP 0x0202u
78#define PREOP_2_SAFEOP 0x0204u
79#define PREOP_2_OP 0x0208u
80#define SAFEOP_2_BOOT 0x0403u
81#define SAFEOP_2_INIT 0x0401u
82#define SAFEOP_2_PREOP 0x0402u
83#define SAFEOP_2_SAFEOP 0x0404u
84#define SAFEOP_2_OP 0x0408u
85#define OP_2_BOOT 0x0803u
86#define OP_2_INIT 0x0801u
87#define OP_2_PREOP 0x0802u
88#define OP_2_SAFEOP 0x0804u
89#define OP_2_OP 0x0808u
90
91typedef osal_uint16_t ec_state_transition_t;
92
94typedef struct PACKED ec_slave_sm {
95 osal_uint16_t adr;
101 osal_uint16_t len;
107 osal_uint32_t flags;
113
115typedef struct PACKED ec_slave_fmmu {
116 osal_uint32_t log;
125 osal_uint16_t log_len;
132 osal_uint8_t log_bit_start;
137 osal_uint8_t log_bit_stop;
142 osal_uint16_t phys;
149 osal_uint8_t phys_bit_start;
155 osal_uint8_t type;
159 osal_uint8_t active;
163 osal_uint8_t reserverd[3];
165
171
218
219#define INIT_CMD_SIZE (sizeof(ec_init_cmd_t))
220
221LIST_HEAD(ec_init_cmds, ec_init_cmd);
222
223typedef struct worker_arg {
224 struct ec *pec;
225 int slave;
226 ec_state_t state;
228
229typedef struct ec_slave {
230 osal_uint32_t slave;
231
232 osal_int16_t auto_inc_address;
233 osal_uint16_t fixed_address;
234
235 osal_uint16_t type;
236 osal_uint8_t sm_ch;
237 osal_uint8_t fmmu_ch;
238 osal_uint32_t ram_size;
239 osal_uint16_t features;
240 osal_uint16_t pdi_ctrl;
241 osal_uint8_t link_cnt;
242 osal_uint8_t active_ports;
243 osal_uint16_t ptype;
244 osal_int32_t pdelay;
245
247 int parent;
249
295 osal_size_t subdev_cnt;
312
315
316#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
318#endif
319
320 ec_state_t expected_state;
321 ec_state_t act_state;
322
323 osal_mutex_t transition_mutex;
324 osal_bool_t transition_active;
325
326 struct ec_init_cmds init_cmds;
328
342 osal_task_t worker_tid;
347} ec_slave_t;
348
349
350#define ec_slave_ptr(ptr, pec, slave) \
351 ec_slave_t *(ptr) = (ec_slave_t *)&pec->slaves[slave]; \
352 assert((ptr) != NULL);
353
354#ifdef __cplusplus
355extern "C" {
356#endif
357#if 0
358}
359#endif
360
361// init slave resources
369void ec_slave_init(struct ec *pec, osal_uint16_t slave);
370
371// free slave resources
379void ec_slave_free(struct ec *pec, osal_uint16_t slave);
380
382
389void ec_slave_reset(ec_t *pec, osal_uint16_t slave);
390
392
405int ec_slave_set_state(struct ec *pec, osal_uint16_t slave, ec_state_t state);
406
408
424int ec_slave_get_state(struct ec *pec, osal_uint16_t slave,
425 ec_state_t *state, osal_uint16_t *alstatcode);
426
428
441int ec_slave_generate_mapping(struct ec *pec, osal_uint16_t slave);
442
444
459int ec_slave_prepare_state_transition(struct ec *pec, osal_uint16_t slave,
460 ec_state_t state);
461
463
476int ec_slave_state_transition(struct ec *pec, osal_uint16_t slave,
477 ec_state_t state);
478
480
495 int transition, int id, int si_el, int ca_atn,
496 osal_char_t *data, osal_size_t datalen);
497
498#if LIBETHERCAT_MBX_SUPPORT_SOE == 1
500
514void ec_slave_mailbox_soe_init_cmd_init(ec_init_cmd_t *cmd,
515 int transition, int id, int si_el, int ca_atn,
516 osal_char_t *data, osal_size_t datalen);
517#endif
518
520
530void ec_slave_add_init_cmd(ec_t *pec, osal_uint16_t slave, ec_init_cmd_t *cmd);
531
533
549void ec_slave_set_dc_config(struct ec *pec, osal_uint16_t slave,
550 int use_dc, int type, osal_uint32_t cycle_time_0,
551 osal_uint32_t cycle_time_1, osal_int32_t cycle_shift);
552
553#if LIBETHERCAT_MBX_SUPPORT_EOE == 1
555
568void ec_slave_set_eoe_settings(struct ec *pec, osal_uint16_t slave,
569 osal_uint8_t *mac, osal_uint8_t *ip_address, osal_uint8_t *subnet, osal_uint8_t *gateway,
570 osal_uint8_t *dns, osal_char_t *dns_name);
571#endif
572
573const osal_char_t *al_status_code_2_string(int code);
574
575#if 0
576{
577#endif
578#ifdef __cplusplus
579}
580#endif
581
584#endif // LIBETHERCAT_SLAVE_H
585
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:67
Definition eoe.h:63
slave mailbox init commands
Definition slave.h:173
osal_char_t data[LEC_MAX_INIT_CMD_DATA]
new id data
Definition slave.h:215
int transition
ECat transition.
Definition slave.h:182
int ca_atn
flags
Definition slave.h:208
osal_size_t datalen
new id data length
Definition slave.h:216
int type
Mailbox type.
Definition slave.h:174
LIST_ENTRY(ec_init_cmd) le
List entry handle.
int id
index
Definition slave.h:193
int si_el
sub index
Definition slave.h:201
Definition mbx.h:117
process data structure
Definition common.h:211
slave fielbus memory management unit (fmmu) settings
Definition slave.h:115
osal_uint8_t active
activation flag
Definition slave.h:159
osal_uint8_t phys_bit_start
physical start bit at physical address
Definition slave.h:149
osal_uint8_t log_bit_start
start bit at logical bus address
Definition slave.h:132
osal_uint16_t phys
physical (local) address in slave
Definition slave.h:142
osal_uint32_t log
logical bus address
Definition slave.h:116
osal_uint16_t log_len
length of logical address area
Definition slave.h:125
osal_uint8_t log_bit_stop
stop bit at logical address plus length
Definition slave.h:137
osal_uint8_t type
type, read or write
Definition slave.h:155
slave sync manager settings
Definition slave.h:94
osal_uint16_t adr
sync manager address
Definition slave.h:95
osal_uint16_t len
sync manager length
Definition slave.h:101
osal_uint32_t flags
sync manager flags
Definition slave.h:107
EtherCAT sub device.
Definition slave.h:167
ec_pd_t pdout
process data outputs
Definition slave.h:169
ec_pd_t pdin
process data inputs
Definition slave.h:168
Definition slave.h:229
ec_dc_info_slave_t dc
Distributed Clock settings.
Definition slave.h:314
int port_on_parent
port attached on parent slave
Definition slave.h:248
osal_uint16_t pdi_ctrl
configuration of process data interface
Definition slave.h:240
osal_int16_t auto_inc_address
physical bus address
Definition slave.h:232
struct ec_init_cmds init_cmds
EtherCAT slave init commands.
Definition slave.h:326
ec_slave_fmmu_t fmmu[LEC_MAX_SLAVE_FMMU]
array of fmmu settings
Definition slave.h:268
ec_mbx_t mbx
EtherCAT mailbox structure.
Definition slave.h:311
int assigned_pd_group
Process data group this slave is assigned to.
Definition slave.h:276
osal_uint32_t ram_size
ram size in bytes
Definition slave.h:238
osal_int32_t pdelay
propagation delay of the slave
Definition slave.h:244
osal_task_t worker_tid
Set state worker thread handle.
Definition slave.h:342
ec_pd_t pdin
input process data
Definition slave.h:277
ec_state_t expected_state
Master expected slave state.
Definition slave.h:320
osal_bool_t transition_active
Flag is state transition is currently active.
Definition slave.h:324
ec_slave_sm_t sm[LEC_MAX_SLAVE_SM]
array of sm settings
Definition slave.h:260
ec_slave_subdev_t subdevs[LEC_MAX_DS402_SUBDEVS]
array of sub devices
Definition slave.h:303
osal_uint8_t link_cnt
link count
Definition slave.h:241
int entry_port
entry port from parent slave
Definition slave.h:246
osal_uint16_t ptype
ptype
Definition slave.h:243
osal_uint8_t sm_ch
number of sync manager channels
Definition slave.h:236
osal_uint16_t features
fmmu operation, dc available
Definition slave.h:239
ec_state_t act_state
Actual/Last read slave state.
Definition slave.h:321
osal_uint8_t active_ports
active ports with link
Definition slave.h:242
osal_uint8_t fmmu_ch
number of fmmu channels
Definition slave.h:237
osal_uint32_t slave
Slave index in EtherCAT master array.
Definition slave.h:230
osal_size_t subdev_cnt
count of sub devices
Definition slave.h:295
osal_mutex_t transition_mutex
Lock for state transition pending.
Definition slave.h:323
osal_uint16_t type
value of EC_REG_TYPE
Definition slave.h:235
int parent
parent slave number
Definition slave.h:247
ec_pd_t pdout
output process data
Definition slave.h:286
worker_arg_t worker_arg
Set state worker thread arguments.
Definition slave.h:337
eeprom_info_t eeprom
EtherCAT slave EEPROM data.
Definition slave.h:313
osal_uint16_t fixed_address
virtual bus address, programmed on start
Definition slave.h:233
int sm_set_by_user
sm set by user
Definition slave.h:250
ethercat master structure
Definition ec.h:188
Definition eeprom.h:143
Definition slave.h:223
ec_state_t state
State of EtherCAT slave.
Definition slave.h:226
int slave
Slave number this worker is doing things for.
Definition slave.h:225
struct ec * pec
Pointer to EtherCAT master struct.
Definition slave.h:224