libethercat - an embeddable realtime EtherCAT-master library
Communicate with EtherCAT slaves attached to a Network interface.
Loading...
Searching...
No Matches
Slave

Data Structures

struct  ec_slave_sm
 slave sync manager settings More...
 
struct  ec_slave_fmmu
 slave fielbus memory management unit (fmmu) settings More...
 
struct  ec_slave_subdev
 EtherCAT sub device. More...
 
struct  ec_init_cmd
 slave mailbox init commands More...
 
struct  worker_arg
 
struct  ec_slave
 

Macros

#define BOOT_2_BOOT   0x0303u
 EtherCAT slave state transitions.
 
#define BOOT_2_INIT   0x0301u
 BOOT to INIT state transition.
 
#define BOOT_2_PREOP   0x0302u
 BOOT to PREOP state transition,.
 
#define BOOT_2_SAFEOP   0x0304u
 BOOT to SAFEOP state transition,.
 
#define BOOT_2_OP   0x0308u
 BOOT to OP state transition,.
 
#define UNKNOWN_2_BOOT   0x0003u
 UNKNOWN to BOOT state transition.
 
#define UNKNOWN_2_INIT   0x0001u
 UNKNOWN to INIT state transition,.
 
#define UNKNOWN_2_PREOP   0x0002u
 UNKNOWN to PREOP state transition,.
 
#define UNKNOWN_2_SAFEOP   0x0004u
 UNKNOWN to SAFEOP state transition,.
 
#define UNKNOWN_2_OP   0x0008u
 UNKNOWN to OP state transition,.
 
#define INIT_2_BOOT   0x0103u
 INIT to BOOT state transition.
 
#define INIT_2_INIT   0x0101u
 INIT to INIT state transition,.
 
#define INIT_2_PREOP   0x0102u
 INIT to PREOP state transition,.
 
#define INIT_2_SAFEOP   0x0104u
 INIT to SAFEOP state transition,.
 
#define INIT_2_OP   0x0108u
 INIT to OP state transition,.
 
#define PREOP_2_BOOT   0x0203u
 PREOP to BOOT state transition,.
 
#define PREOP_2_INIT   0x0201u
 PREOP to INIT state transition,.
 
#define PREOP_2_PREOP   0x0202u
 PREOP to PREOP state transition,.
 
#define PREOP_2_SAFEOP   0x0204u
 PREOP to SAFEOP state transition,.
 
#define PREOP_2_OP   0x0208u
 PREOP to OP state transition,.
 
#define SAFEOP_2_BOOT   0x0403u
 SAFEOP to BOOT state transition,.
 
#define SAFEOP_2_INIT   0x0401u
 SAFEOP to INIT state transition,.
 
#define SAFEOP_2_PREOP   0x0402u
 SAFEOP to PREOP state transition,.
 
#define SAFEOP_2_SAFEOP   0x0404u
 SAFEOP to SAFEOP state transition,.
 
#define SAFEOP_2_OP   0x0408u
 SAFEOP to OP state transition,.
 
#define OP_2_BOOT   0x0803u
 OP to BOOT state transition,.
 
#define OP_2_INIT   0x0801u
 OP to INIT state transition,.
 
#define OP_2_PREOP   0x0802u
 OP to PREOP state transition,.
 
#define OP_2_SAFEOP   0x0804u
 OP to SAFEOP state transition,.
 
#define OP_2_OP   0x0808u
 OP to OP state transition,.
 
#define INIT_CMD_SIZE   (sizeof(ec_init_cmd_t))
 
#define ec_slave_ptr(ptr, pec, slave)
 

Typedefs

typedef osal_uint16_t ec_state_transition_t
 
typedef struct PACKED ec_slave_sm ec_slave_sm_t
 slave sync manager settings
 
typedef struct PACKED ec_slave_fmmu ec_slave_fmmu_t
 slave fielbus memory management unit (fmmu) settings
 
typedef struct ec_slave_subdev ec_slave_subdev_t
 EtherCAT sub device.
 
typedef struct ec_init_cmd ec_init_cmd_t
 slave mailbox init commands
 
typedef struct worker_arg worker_arg_t
 Worker thread argument structure.
 
typedef struct ec_slave ec_slave_t
 

Functions

 LIST_HEAD (ec_init_cmds, ec_init_cmd)
 
void ec_slave_init (struct ec *pec, osal_uint16_t slave)
 
void ec_slave_free (struct ec *pec, osal_uint16_t slave)
 
void ec_slave_reset (ec_t *pec, osal_uint16_t slave)
 issue hardware reset of 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_get_state (struct ec *pec, osal_uint16_t slave, ec_state_t *state, osal_uint16_t *alstatcode)
 Get EtherCAT state from slave.
 
int ec_slave_generate_mapping (struct ec *pec, osal_uint16_t slave)
 Generate process data mapping.
 
int ec_slave_prepare_state_transition (struct ec *pec, osal_uint16_t slave, ec_state_t state)
 Prepare state transition on EtherCAT slave.
 
int ec_slave_state_transition (struct ec *pec, osal_uint16_t slave, ec_state_t state)
 Execute 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.
 
void ec_slave_add_init_cmd (ec_t *pec, osal_uint16_t slave, ec_init_cmd_t *cmd)
 Add master init command.
 
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.
 
const osal_char_t * al_status_code_2_string (int code)
 

Detailed Description

This modules contains main EtherCAT slave functions.

Macro Definition Documentation

◆ BOOT_2_BOOT

#define BOOT_2_BOOT   0x0303u

EtherCAT slave state transitions.

BOOT to BOOT state transition

◆ ec_slave_ptr

#define ec_slave_ptr (   ptr,
  pec,
  slave 
)
Value:
ec_slave_t *(ptr) = (ec_slave_t *)&pec->slaves[slave]; \
assert((ptr) != NULL);
Definition slave.h:229

Function Documentation

◆ ec_slave_add_init_cmd()

void ec_slave_add_init_cmd ( ec_t pec,
osal_uint16_t  slave,
ec_init_cmd_t cmd 
)

Add master init command.

This adds an EtherCAT slave init command.

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).
[in]cmdInit command to add.

◆ ec_slave_free()

void ec_slave_free ( struct ec pec,
osal_uint16_t  slave 
)
Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).

◆ ec_slave_generate_mapping()

int ec_slave_generate_mapping ( struct ec pec,
osal_uint16_t  slave 
)

Generate process data mapping.

This tries to generate a mapping for the process data and figures out the settings for the sync managers. Therefor it either tries to use an available mailbox protocol or the information stored in the EEPROM.

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).
Returns
EC_OK on success, otherwise EC_ERROR_* code.

◆ ec_slave_get_state()

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.

This call tries to read the EtherCAT slave state. If successfull a working counter of 1 will be returned.

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).
[out]stateReturns current EtherCAT state.
[out]alstatcodeReturn current AL StatusCode of specified EtherCAT slave. (maybe NULL if you are not interested in)
Returns
EC_OK on success, otherwise EC_ERROR_* code.

◆ ec_slave_init()

void ec_slave_init ( struct ec pec,
osal_uint16_t  slave 
)
Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).

◆ ec_slave_mailbox_coe_init_cmd_init()

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.

This adds an EtherCAT slave init command.

Parameters
[in]cmdInit command to add.
[in]transitionEtherCAT state transition in form 0xab, where 'a' is the state we are coming from and 'b' is the state we want to get.
[in]idEither CoE Index number or the ServoDrive IDN.
[in]si_elEither CoE SubIndex or ServoDrive element number.
[in]ca_atnEither CoE complete access or ServoDrive ATN.
[in]dataPointer to memory buffer with data which should be transfered.
[in]datalenLength of data

◆ ec_slave_prepare_state_transition()

int ec_slave_prepare_state_transition ( struct ec pec,
osal_uint16_t  slave,
ec_state_t  state 
)

Prepare state transition on EtherCAT slave.

While prepare a state transition the master sends the init commands to the slaves. These are usually settings for the process data mapping (e.g. PDOs, ...) or some slave specific settings.

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).
[in]statePrepare the EtherCAT slave for a switch to the specified EtherCAT state.
Returns
Working counter of the used commands, should be 1 if it was successfull.

◆ ec_slave_reset()

void ec_slave_reset ( ec_t pec,
osal_uint16_t  slave 
)

issue hardware reset of slave

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).

◆ ec_slave_set_dc_config()

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.

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).
[in]use_dcWhether to en-/disable dc on slave.
[in]activation_regDC Sync Activation Register (0x981). Sets the type of DC sync:
  • 0x3 = Sync0
  • 0x5 = Sync1
  • 0x7 = Sync01
[in]cycle_time_0Cycle time of sync 0 [ns].
[in]cycle_time_1Cycle time of sync 1 [ns].
[in]cycle_shiftCycle shift time [ns].

◆ ec_slave_set_state()

int ec_slave_set_state ( struct ec pec,
osal_uint16_t  slave,
ec_state_t  state 
)

Set EtherCAT state on slave.

This call tries to set the EtherCAT slave to the requested state. If successfull a working counter of 1 will be returned.

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).
[in]stateNew EtherCAT state which will be set on specified slave.
Returns
EC_OK on success, otherwise EC_ERROR_* code.

◆ ec_slave_state_transition()

int ec_slave_state_transition ( struct ec pec,
osal_uint16_t  slave,
ec_state_t  state 
)

Execute state transition on EtherCAT slave.

This actually performs the state transition.

Parameters
[in]pecPointer to ethercat master structure, which you got from ec_open.
[in]slaveNumber of ethercat slave. this depends on the physical order of the ethercat slaves (usually the n'th slave attached).
[in]stateSwitch the EtherCAT slave to the specified EtherCAT state.
Returns
Working counter of the used commands, should be 1 if it was successfull.