IgH EtherCAT Master  1.7.0
slave.c File Reference

EtherCAT slave methods. More...

Go to the source code of this file.

Functions

char * ec_slave_sii_string (const ec_slave_t *slave, unsigned int index)
 Searches the string list for an index.
void ec_slave_find_names_for_pdo (ec_slave_t *slave, ec_pdo_t *pdo)
 Find name for a PDO and its entries.
unsigned int ec_slave_get_previous_port (const ec_slave_t *slave, unsigned int port_index)
 Returns the previous connected port of a given port.
unsigned int ec_slave_get_next_port (const ec_slave_t *slave, unsigned int port_index)
 Returns the next connected port of a given port.
uint32_t ec_slave_calc_rtt_sum (const ec_slave_t *slave)
 Calculates the sum of round-trip-times of connected ports 1-3.
ec_slave_t * ec_slave_find_next_dc_slave (ec_slave_t *slave)
 Finds the next slave supporting DC delay measurement.
int ec_slave_fetch_sii_strings (ec_slave_t *slave, const uint8_t *data, size_t data_size)
 Fetches data from a STRING category.
int ec_slave_fetch_sii_general (ec_slave_t *slave, const uint8_t *data, size_t data_size)
 Fetches data from a GENERAL category.
int ec_slave_fetch_sii_syncs (ec_slave_t *slave, const uint8_t *data, size_t data_size)
 Fetches data from a SYNC MANAGER category.
int ec_slave_fetch_sii_pdos (ec_slave_t *slave, const uint8_t *data, size_t data_size, ec_direction_t dir)
 Fetches data from a [RT]xPDO category.
void ec_slave_init (ec_slave_t *slave, ec_master_t *master, ec_device_index_t dev_idx, uint16_t ring_position, uint16_t station_address)
 Slave constructor.
void ec_read_mbox_lock_clear (ec_slave_t *slave)
 Clears the mailbox lock.
int ec_read_mbox_locked (ec_slave_t *slave)
 Return the current mailbox lock status and lock it if not locked.
void ec_slave_clear (ec_slave_t *slave)
 Slave destructor.
void ec_slave_clear_sync_managers (ec_slave_t *slave)
 Clear the sync manager array.
void ec_slave_set_state (ec_slave_t *slave, ec_slave_state_t new_state)
 Sets the application state of a slave.
void ec_slave_request_state (ec_slave_t *slave, ec_slave_state_t state)
 Request a slave state and resets the error flag.
int ec_slave_analyze_sii_data (ec_slave_t *slave)
 Analyzes SII data.
ec_sync_t * ec_slave_get_sync (ec_slave_t *slave, uint8_t sync_index)
 Get the sync manager given an index.
void ec_slave_sdo_dict_info (const ec_slave_t *slave, unsigned int *sdo_count, unsigned int *entry_count)
 Counts the total number of SDOs and entries in the dictionary.
ec_sdo_t * ec_slave_get_sdo (ec_slave_t *slave, uint16_t index)
 Get an SDO from the dictionary.
const ec_sdo_t * ec_slave_get_sdo_const (const ec_slave_t *slave, uint16_t index)
 Get an SDO from the dictionary.
const ec_sdo_t * ec_slave_get_sdo_by_pos_const (const ec_slave_t *slave, uint16_t sdo_position)
 Get an SDO from the dictionary, given its position in the list.
uint16_t ec_slave_sdo_count (const ec_slave_t *slave)
 Get the number of SDOs in the dictionary.
const ec_pdo_t * ec_slave_find_pdo (const ec_slave_t *slave, uint16_t index)
 Finds a mapped PDO.
void ec_slave_attach_pdo_names (ec_slave_t *slave)
 Attach PDO names.
void ec_slave_calc_port_delays (ec_slave_t *slave)
 Calculates the port transmission delays.
void ec_slave_calc_transmission_delays_rec (ec_slave_t *slave, ec_slave_t *came_from, uint32_t *delay)
 Recursively calculates transmission delays.

Variables

const ec_code_msg_t al_status_messages []
 Application layer status messages.

Detailed Description

EtherCAT slave methods.

Definition in file slave.c.

Function Documentation

◆ ec_slave_sii_string()

char * ec_slave_sii_string ( const ec_slave_t * slave,
unsigned int index )

Searches the string list for an index.

Returns
0 in case of success, else < 0
Parameters
slaveEtherCAT slave
indexstring index

Definition at line 842 of file slave.c.

◆ ec_slave_find_names_for_pdo()

void ec_slave_find_names_for_pdo ( ec_slave_t * slave,
ec_pdo_t * pdo )

Find name for a PDO and its entries.

Definition at line 1024 of file slave.c.

◆ ec_slave_get_previous_port()

unsigned int ec_slave_get_previous_port ( const ec_slave_t * slave,
unsigned int port_index )

Returns the previous connected port of a given port.

Returns
Port index.
Parameters
slaveEtherCAT slave.
port_indexPort index.

Definition at line 1077 of file slave.c.

◆ ec_slave_get_next_port()

unsigned int ec_slave_get_next_port ( const ec_slave_t * slave,
unsigned int port_index )

Returns the next connected port of a given port.

Returns
Port index.
Parameters
slaveEtherCAT slave.
port_indexPort index.

Definition at line 1107 of file slave.c.

◆ ec_slave_calc_rtt_sum()

uint32_t ec_slave_calc_rtt_sum ( const ec_slave_t * slave)

Calculates the sum of round-trip-times of connected ports 1-3.

Returns
Round-trip-time in ns.
Parameters
slaveEtherCAT slave.

Definition at line 1137 of file slave.c.

◆ ec_slave_find_next_dc_slave()

ec_slave_t * ec_slave_find_next_dc_slave ( ec_slave_t * slave)

Finds the next slave supporting DC delay measurement.

Returns
Next DC slave, or NULL.
Parameters
slaveEtherCAT slave.

Definition at line 1163 of file slave.c.

◆ ec_slave_fetch_sii_strings()

int ec_slave_fetch_sii_strings ( ec_slave_t * slave,
const uint8_t * data,
size_t data_size )

Fetches data from a STRING category.

Todo
range checking
Returns
0 in case of success, else < 0
Parameters
slaveEtherCAT slave
datacategory data
data_sizenumber of bytes

Definition at line 586 of file slave.c.

◆ ec_slave_fetch_sii_general()

int ec_slave_fetch_sii_general ( ec_slave_t * slave,
const uint8_t * data,
size_t data_size )

Fetches data from a GENERAL category.

Returns
0 in case of success, else < 0
Parameters
slaveEtherCAT slave
datacategory data
data_sizesize in bytes

Definition at line 642 of file slave.c.

◆ ec_slave_fetch_sii_syncs()

int ec_slave_fetch_sii_syncs ( ec_slave_t * slave,
const uint8_t * data,
size_t data_size )

Fetches data from a SYNC MANAGER category.

Appends the sync managers described in the category to the existing ones.

Returns
0 in case of success, else < 0
Parameters
slaveEtherCAT slave.
dataCategory data.
data_sizeNumber of bytes.

Definition at line 693 of file slave.c.

◆ ec_slave_fetch_sii_pdos()

int ec_slave_fetch_sii_pdos ( ec_slave_t * slave,
const uint8_t * data,
size_t data_size,
ec_direction_t dir )

Fetches data from a [RT]xPDO category.

Returns
0 in case of success, else < 0
Parameters
slaveEtherCAT slave
datacategory data
data_sizenumber of bytes
dirPDO direction.

Definition at line 759 of file slave.c.

◆ ec_slave_init()

void ec_slave_init ( ec_slave_t * slave,
ec_master_t * master,
ec_device_index_t dev_idx,
uint16_t ring_position,
uint16_t station_address )

Slave constructor.

Returns
0 in case of success, else < 0
Parameters
slaveEtherCAT slave
masterEtherCAT master
dev_idxDevice index.
ring_positionring position
station_addressstation address to configure

Definition at line 65 of file slave.c.

◆ ec_read_mbox_lock_clear()

void ec_read_mbox_lock_clear ( ec_slave_t * slave)

Clears the mailbox lock.

Lock-free, so that it can be called from any context (also from realtime context, e. g. via ecrt_voe_handler_execute()).

Definition at line 187 of file slave.c.

◆ ec_read_mbox_locked()

int ec_read_mbox_locked ( ec_slave_t * slave)

Return the current mailbox lock status and lock it if not locked.

Lock-free, see ec_read_mbox_lock_clear().

Returns
Non-zero, if the lock was already taken.

Definition at line 201 of file slave.c.

◆ ec_slave_clear()

void ec_slave_clear ( ec_slave_t * slave)

Slave destructor.

Clears and frees a slave object.

Parameters
slaveEtherCAT slave

Definition at line 213 of file slave.c.

◆ ec_slave_clear_sync_managers()

void ec_slave_clear_sync_managers ( ec_slave_t * slave)

Clear the sync manager array.

Parameters
slaveEtherCAT slave.

Definition at line 316 of file slave.c.

◆ ec_slave_set_state()

void ec_slave_set_state ( ec_slave_t * slave,
ec_slave_state_t new_state )

Sets the application state of a slave.

Parameters
slaveEtherCAT slave
new_statenew application state

Definition at line 335 of file slave.c.

◆ ec_slave_request_state()

void ec_slave_request_state ( ec_slave_t * slave,
ec_slave_state_t state )

Request a slave state and resets the error flag.

Parameters
slaveEtherCAT slave
statenew state

Definition at line 357 of file slave.c.

◆ ec_slave_analyze_sii_data()

int ec_slave_analyze_sii_data ( ec_slave_t * slave)

Analyzes SII data.

Returns
0 in case of success, else < 0
Parameters
slaveSlave.

Definition at line 372 of file slave.c.

◆ ec_slave_get_sync()

ec_sync_t * ec_slave_get_sync ( ec_slave_t * slave,
uint8_t sync_index )

Get the sync manager given an index.

Returns
pointer to sync manager, or NULL.
Parameters
slaveEtherCAT slave.
sync_indexSync manager index.

Definition at line 864 of file slave.c.

◆ ec_slave_sdo_dict_info()

void ec_slave_sdo_dict_info ( const ec_slave_t * slave,
unsigned int * sdo_count,
unsigned int * entry_count )

Counts the total number of SDOs and entries in the dictionary.

Parameters
slaveEtherCAT slave
sdo_countnumber of SDOs
entry_counttotal number of entries

Definition at line 882 of file slave.c.

◆ ec_slave_get_sdo()

ec_sdo_t * ec_slave_get_sdo ( ec_slave_t * slave,
uint16_t index )

Get an SDO from the dictionary.

Returns
The desired SDO, or NULL.
Parameters
slaveEtherCAT slave
indexSDO index

Definition at line 910 of file slave.c.

◆ ec_slave_get_sdo_const()

const ec_sdo_t * ec_slave_get_sdo_const ( const ec_slave_t * slave,
uint16_t index )

Get an SDO from the dictionary.

const version.

Returns
The desired SDO, or NULL.
Parameters
slaveEtherCAT slave
indexSDO index

Definition at line 936 of file slave.c.

◆ ec_slave_get_sdo_by_pos_const()

const ec_sdo_t * ec_slave_get_sdo_by_pos_const ( const ec_slave_t * slave,
uint16_t sdo_position )

Get an SDO from the dictionary, given its position in the list.

Returns
The desired SDO, or NULL.
Parameters
slaveEtherCAT slave.
sdo_positionSDO list position.

Definition at line 958 of file slave.c.

◆ ec_slave_sdo_count()

uint16_t ec_slave_sdo_count ( const ec_slave_t * slave)

Get the number of SDOs in the dictionary.

Returns
SDO count.
Parameters
slaveEtherCAT slave.

Definition at line 980 of file slave.c.

◆ ec_slave_find_pdo()

const ec_pdo_t * ec_slave_find_pdo ( const ec_slave_t * slave,
uint16_t index )

Finds a mapped PDO.

Returns
The desired PDO object, or NULL.
Parameters
slaveSlave.
indexPDO index to find.

Definition at line 999 of file slave.c.

◆ ec_slave_attach_pdo_names()

void ec_slave_attach_pdo_names ( ec_slave_t * slave)

Attach PDO names.

Definition at line 1055 of file slave.c.

◆ ec_slave_calc_port_delays()

void ec_slave_calc_port_delays ( ec_slave_t * slave)

Calculates the port transmission delays.

Parameters
slaveEtherCAT slave.

Definition at line 1196 of file slave.c.

◆ ec_slave_calc_transmission_delays_rec()

void ec_slave_calc_transmission_delays_rec ( ec_slave_t * slave,
ec_slave_t * came_from,
uint32_t * delay )

Recursively calculates transmission delays.

Parameters
slaveCurrent slave.
came_fromDC slave we recursed in from (NULL at the reference clock).
delaySum of delays.

Definition at line 1242 of file slave.c.

Variable Documentation

◆ al_status_messages

const ec_code_msg_t al_status_messages[]
extern

Application layer status messages.

Definition at line 382 of file fsm_change.c.