master.c File Reference

EtherCAT master methods. More...

Go to the source code of this file.

Defines

#define DEBUG_INJECT   0
 Set to 1 to enable external datagram injection debugging.
#define FORCE_OUTPUT_CORRUPTED   0
 Always output corrupted frames.
#define EC_FIND_SLAVE
 Common implementation for ec_master_find_slave() and ec_master_find_slave_const().
#define EC_FIND_CONFIG
 Common implementation for ec_master_get_config() and ec_master_get_config_const().
#define EC_FIND_DOMAIN
 Common implementation for ec_master_find_domain() and ec_master_find_domain_const().

Functions

void ec_master_clear_slave_configs (ec_master_t *master)
 Clear all slave configurations.
void ec_master_clear_domains (ec_master_t *master)
 Clear all domains.
static int ec_master_idle_thread (void *priv_data)
 Master kernel thread function for IDLE phase.
static int ec_master_operation_thread (void *priv_data)
 Master kernel thread function for OPERATION phase.
static int ec_master_eoe_thread (void *priv_data)
 Does the Ethernet over EtherCAT processing.
void ec_master_find_dc_ref_clock (ec_master_t *master)
 Finds the DC reference clock.
void ec_master_clear_device_stats (ec_master_t *master)
 Clears the common device statistics.
void ec_master_update_device_stats (ec_master_t *master)
 Updates the common device statistics.
void ec_master_init_static (void)
 Static variables initializer.
int ec_master_init (ec_master_t *master, unsigned int index, const uint8_t *main_mac, const uint8_t *backup_mac, dev_t device_number, struct class *class, unsigned int debug_level)
 Master constructor.
void ec_master_clear (ec_master_t *master)
 Destructor.
void ec_master_clear_eoe_handlers (ec_master_t *master)
 Clear and free all EoE handlers.
void ec_master_clear_slaves (ec_master_t *master)
 Clear all slaves.
void ec_master_clear_config (ec_master_t *master)
 Clear the configuration applied by the application.
void ec_master_internal_send_cb (void *cb_data)
 Internal sending callback.
void ec_master_internal_receive_cb (void *cb_data)
 Internal receiving callback.
int ec_master_thread_start (ec_master_t *master, int(*thread_func)(void *), const char *name)
 Starts the master thread.
void ec_master_thread_stop (ec_master_t *master)
 Stops the master thread.
int ec_master_enter_idle_phase (ec_master_t *master)
 Transition function from ORPHANED to IDLE phase.
void ec_master_leave_idle_phase (ec_master_t *master)
 Transition function from IDLE to ORPHANED phase.
int ec_master_enter_operation_phase (ec_master_t *master)
 Transition function from IDLE to OPERATION phase.
void ec_master_leave_operation_phase (ec_master_t *master)
 Transition function from OPERATION to IDLE phase.
void ec_master_inject_external_datagrams (ec_master_t *master)
 Injects external datagrams that fit into the datagram queue.
void ec_master_set_send_interval (ec_master_t *master, unsigned int send_interval)
 Sets the expected interval between calls to ecrt_master_send and calculates the maximum amount of data to queue.
ec_datagram_tec_master_get_external_datagram (ec_master_t *master)
 Searches for a free datagram in the external datagram ring.
void ec_master_queue_datagram (ec_master_t *master, ec_datagram_t *datagram)
 Places a datagram in the datagram queue.
void ec_master_queue_datagram_ext (ec_master_t *master, ec_datagram_t *datagram)
 Places a datagram in the non-application datagram queue.
void ec_master_send_datagrams (ec_master_t *master, ec_device_index_t device_index)
 Sends the datagrams in the queue for a certain device.
void ec_master_receive_datagrams (ec_master_t *master, ec_device_t *device, const uint8_t *frame_data, size_t size)
 Processes a received frame.
void ec_master_output_stats (ec_master_t *master)
 Output master statistics.
void ec_master_exec_slave_fsms (ec_master_t *master)
 Execute slave FSMs.
void ec_master_eoe_start (ec_master_t *master)
 Starts Ethernet over EtherCAT processing on demand.
void ec_master_eoe_stop (ec_master_t *master)
 Stops the Ethernet over EtherCAT processing.
void ec_master_attach_slave_configs (ec_master_t *master)
 Attaches the slave configurations to the slaves.
ec_slave_tec_master_find_slave (ec_master_t *master, uint16_t alias, uint16_t position)
 Finds a slave in the bus, given the alias and position.
const ec_slave_tec_master_find_slave_const (const ec_master_t *master, uint16_t alias, uint16_t position)
 Finds a slave in the bus, given the alias and position.
unsigned int ec_master_config_count (const ec_master_t *master)
 Get the number of slave configurations provided by the application.
ec_slave_config_tec_master_get_config (const ec_master_t *master, unsigned int pos)
 Get a slave configuration via its position in the list.
const ec_slave_config_tec_master_get_config_const (const ec_master_t *master, unsigned int pos)
 Get a slave configuration via its position in the list.
unsigned int ec_master_domain_count (const ec_master_t *master)
 Get the number of domains.
ec_domain_tec_master_find_domain (ec_master_t *master, unsigned int index)
 Get a domain via its position in the list.
const ec_domain_tec_master_find_domain_const (const ec_master_t *master, unsigned int index)
 Get a domain via its position in the list.
uint16_t ec_master_eoe_handler_count (const ec_master_t *master)
 Get the number of EoE handlers.
const ec_eoe_tec_master_get_eoe_handler_const (const ec_master_t *master, uint16_t index)
 Get an EoE handler via its position in the list.
int ec_master_debug_level (ec_master_t *master, unsigned int level)
 Set the debug level.
int ec_master_calc_topology_rec (ec_master_t *master, ec_slave_t *port0_slave, unsigned int *slave_position)
 Calculates the bus topology; recursion function.
void ec_master_calc_topology (ec_master_t *master)
 Calculates the bus topology.
void ec_master_calc_transmission_delays (ec_master_t *master)
 Calculates the bus transmission delays.
void ec_master_calc_dc (ec_master_t *master)
 Distributed-clocks calculations.
void ec_master_request_op (ec_master_t *master)
 Request OP state for configured slaves.
ec_domain_tecrt_master_create_domain_err (ec_master_t *master)
 Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
ec_domain_tecrt_master_create_domain (ec_master_t *master)
 Creates a new process data domain.
int ecrt_master_activate (ec_master_t *master)
 Finishes the configuration phase and prepares for cyclic operation.
void ecrt_master_deactivate (ec_master_t *master)
 Deactivates the master.
void ecrt_master_send (ec_master_t *master)
 Sends all datagrams in the queue.
void ecrt_master_receive (ec_master_t *master)
 Fetches received frames from the hardware and processes the datagrams.
void ecrt_master_send_ext (ec_master_t *master)
 Sends non-application datagrams.
ec_slave_config_tecrt_master_slave_config_err (ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
 Same as ecrt_master_slave_config(), but with ERR_PTR() return value.
ec_slave_config_tecrt_master_slave_config (ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
 Obtains a slave configuration.
int ecrt_master_select_reference_clock (ec_master_t *master, ec_slave_config_t *sc)
 Selects the reference clock for distributed clocks.
int ecrt_master (ec_master_t *master, ec_master_info_t *master_info)
 Obtains master information.
int ecrt_master_get_slave (ec_master_t *master, uint16_t slave_position, ec_slave_info_t *slave_info)
 Obtains slave information.
void ecrt_master_callbacks (ec_master_t *master, void(*send_cb)(void *), void(*receive_cb)(void *), void *cb_data)
 Sets the locking callbacks.
void ecrt_master_state (const ec_master_t *master, ec_master_state_t *state)
 Reads the current master state.
int ecrt_master_link_state (const ec_master_t *master, unsigned int dev_idx, ec_master_link_state_t *state)
 Reads the current state of a redundant link.
void ecrt_master_application_time (ec_master_t *master, uint64_t app_time)
 Sets the application time.
int ecrt_master_reference_clock_time (ec_master_t *master, uint32_t *time)
 Get the lower 32 bit of the reference clock system time.
void ecrt_master_sync_reference_clock (ec_master_t *master)
 Queues the DC reference clock drift compensation datagram for sending.
void ecrt_master_sync_slave_clocks (ec_master_t *master)
 Queues the DC clock drift compensation datagram for sending.
void ecrt_master_sync_monitor_queue (ec_master_t *master)
 Queues the DC synchrony monitoring datagram for sending.
uint32_t ecrt_master_sync_monitor_process (ec_master_t *master)
 Processes the DC synchrony monitoring datagram.
int ecrt_master_sdo_download (ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t subindex, uint8_t *data, size_t data_size, uint32_t *abort_code)
 Executes an SDO download request to write data to a slave.
int ecrt_master_sdo_download_complete (ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t *data, size_t data_size, uint32_t *abort_code)
 Executes an SDO download request to write data to a slave via complete access.
int ecrt_master_sdo_upload (ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t subindex, uint8_t *target, size_t target_size, size_t *result_size, uint32_t *abort_code)
 Executes an SDO upload request to read data from a slave.
int ecrt_master_write_idn (ec_master_t *master, uint16_t slave_position, uint8_t drive_no, uint16_t idn, uint8_t *data, size_t data_size, uint16_t *error_code)
 Executes an SoE write request.
int ecrt_master_read_idn (ec_master_t *master, uint16_t slave_position, uint8_t drive_no, uint16_t idn, uint8_t *target, size_t target_size, size_t *result_size, uint16_t *error_code)
 Executes an SoE read request.
void ecrt_master_reset (ec_master_t *master)
 Retry configuring slaves.

Variables

static unsigned long timeout_jiffies
 Frame timeout in jiffies.
static unsigned long ext_injection_timeout_jiffies
 Timeout for external datagram injection [jiffies].
const unsigned int rate_intervals []
 List of intervals for statistics [s].


Detailed Description

EtherCAT master methods.

Definition in file master.c.


Define Documentation

#define EC_FIND_SLAVE

Value:

do { \
        if (alias) { \
            for (; slave < master->slaves + master->slave_count; \
                    slave++) { \
                if (slave->effective_alias == alias) \
                break; \
            } \
            if (slave == master->slaves + master->slave_count) \
            return NULL; \
        } \
        \
        slave += position; \
        if (slave < master->slaves + master->slave_count) { \
            return slave; \
        } else { \
            return NULL; \
        } \
    } while (0)
Common implementation for ec_master_find_slave() and ec_master_find_slave_const().

Definition at line 1791 of file master.c.

#define EC_FIND_CONFIG

Value:

do { \
        list_for_each_entry(sc, &master->configs, list) { \
            if (pos--) \
                continue; \
            return sc; \
        } \
        return NULL; \
    } while (0)
Common implementation for ec_master_get_config() and ec_master_get_config_const().

Definition at line 1866 of file master.c.

#define EC_FIND_DOMAIN

Value:

do { \
        list_for_each_entry(domain, &master->domains, list) { \
            if (index--) \
                continue; \
            return domain; \
        } \
        \
        return NULL; \
    } while (0)
Common implementation for ec_master_find_domain() and ec_master_find_domain_const().

Definition at line 1929 of file master.c.


Function Documentation

void ec_master_find_dc_ref_clock ( ec_master_t master  ) 

Finds the DC reference clock.

Parameters:
master  EtherCAT master.

Definition at line 2046 of file master.c.

void ec_master_clear_device_stats ( ec_master_t master  ) 

Clears the common device statistics.

Parameters:
master  EtherCAT master

Definition at line 1289 of file master.c.

void ec_master_update_device_stats ( ec_master_t master  ) 

Updates the common device statistics.

Parameters:
master  EtherCAT master

Definition at line 1317 of file master.c.

int ec_master_init ( ec_master_t master,
unsigned int  index,
const uint8_t *  main_mac,
const uint8_t *  backup_mac,
dev_t  device_number,
struct class class,
unsigned int  debug_level 
)

Master constructor.

Returns:
0 in case of success, else < 0
Parameters:
master  EtherCAT master
index  master index
main_mac  MAC address of main device
backup_mac  MAC address of backup device
device_number  Character device number.
class  Device class.
debug_level  Debug level (module parameter).

Definition at line 133 of file master.c.

void ec_master_clear ( ec_master_t master  ) 

Destructor.

Parameters:
master  EtherCAT master

Definition at line 385 of file master.c.

void ec_master_clear_eoe_handlers ( ec_master_t master  ) 

Clear and free all EoE handlers.

Parameters:
master  EtherCAT master

Definition at line 432 of file master.c.

void ec_master_clear_config ( ec_master_t master  ) 

Clear the configuration applied by the application.

Parameters:
master  EtherCAT master.

Definition at line 525 of file master.c.

void ec_master_internal_send_cb ( void *  cb_data  ) 

Internal sending callback.

Parameters:
cb_data  Callback data.

Definition at line 539 of file master.c.

void ec_master_internal_receive_cb ( void *  cb_data  ) 

Internal receiving callback.

Parameters:
cb_data  Callback data.

Definition at line 553 of file master.c.

int ec_master_thread_start ( ec_master_t master,
int(*)(void *)  thread_func,
const char *  name 
)

Starts the master thread.

Return values:
0 Success.
<0 Error code.
Parameters:
master  EtherCAT master
thread_func  thread function to start
name  Thread name.

Definition at line 570 of file master.c.

void ec_master_thread_stop ( ec_master_t master  ) 

Stops the master thread.

Parameters:
master  EtherCAT master

Definition at line 593 of file master.c.

int ec_master_enter_idle_phase ( ec_master_t master  ) 

Transition function from ORPHANED to IDLE phase.

Returns:
Zero on success, otherwise a negative error code.
Parameters:
master  EtherCAT master

Definition at line 625 of file master.c.

void ec_master_leave_idle_phase ( ec_master_t master  ) 

Transition function from IDLE to ORPHANED phase.

Parameters:
master  EtherCAT master

Definition at line 658 of file master.c.

int ec_master_enter_operation_phase ( ec_master_t master  ) 

Transition function from IDLE to OPERATION phase.

Returns:
Zero on success, otherwise a negative error code.
Parameters:
master  EtherCAT master

Definition at line 682 of file master.c.

void ec_master_leave_operation_phase ( ec_master_t master  ) 

Transition function from OPERATION to IDLE phase.

Parameters:
master  EtherCAT master

Definition at line 764 of file master.c.

void ec_master_inject_external_datagrams ( ec_master_t master  ) 

Injects external datagrams that fit into the datagram queue.

Parameters:
master  EtherCAT master

Definition at line 786 of file master.c.

void ec_master_set_send_interval ( ec_master_t master,
unsigned int  send_interval 
)

Sets the expected interval between calls to ecrt_master_send and calculates the maximum amount of data to queue.

Parameters:
master  EtherCAT master
send_interval  Send interval

Definition at line 900 of file master.c.

ec_datagram_t* ec_master_get_external_datagram ( ec_master_t master  ) 

Searches for a free datagram in the external datagram ring.

Returns:
Next free datagram, or NULL.
Parameters:
master  EtherCAT master

Definition at line 917 of file master.c.

void ec_master_queue_datagram ( ec_master_t master,
ec_datagram_t datagram 
)

Places a datagram in the datagram queue.

Parameters:
master  EtherCAT master
datagram  datagram

Definition at line 936 of file master.c.

void ec_master_queue_datagram_ext ( ec_master_t master,
ec_datagram_t datagram 
)

Places a datagram in the non-application datagram queue.

Parameters:
master  EtherCAT master
datagram  datagram

Definition at line 969 of file master.c.

void ec_master_send_datagrams ( ec_master_t master,
ec_device_index_t  device_index 
)

Sends the datagrams in the queue for a certain device.

Parameters:
master  EtherCAT master
device_index  Device index.

Definition at line 984 of file master.c.

void ec_master_receive_datagrams ( ec_master_t master,
ec_device_t device,
const uint8_t *  frame_data,
size_t  size 
)

Processes a received frame.

This function is called by the network driver for every received frame.

Returns:
0 in case of success, else < 0
Parameters:
master  EtherCAT master
device  EtherCAT device
frame_data  frame data
size  size of the received data

Definition at line 1121 of file master.c.

void ec_master_output_stats ( ec_master_t master  ) 

Output master statistics.

This function outputs statistical data on demand, but not more often than necessary. The output happens at most once a second.

Parameters:
master  EtherCAT master

Definition at line 1259 of file master.c.

void ec_master_exec_slave_fsms ( ec_master_t master  ) 

Execute slave FSMs.

Parameters:
master  EtherCAT master.

Definition at line 1444 of file master.c.

void ec_master_eoe_start ( ec_master_t master  ) 

Starts Ethernet over EtherCAT processing on demand.

Parameters:
master  EtherCAT master

Definition at line 1659 of file master.c.

void ec_master_eoe_stop ( ec_master_t master  ) 

Stops the Ethernet over EtherCAT processing.

Parameters:
master  EtherCAT master

Definition at line 1696 of file master.c.

void ec_master_attach_slave_configs ( ec_master_t master  ) 

Attaches the slave configurations to the slaves.

Parameters:
master  EtherCAT master.

Definition at line 1775 of file master.c.

ec_slave_t* ec_master_find_slave ( ec_master_t master,
uint16_t  alias,
uint16_t  position 
)

Finds a slave in the bus, given the alias and position.

Returns:
Search result, or NULL.
Parameters:
master  EtherCAT master.
alias  Slave alias.
position  Slave position.

Definition at line 1815 of file master.c.

const ec_slave_t* ec_master_find_slave_const ( const ec_master_t master,
uint16_t  alias,
uint16_t  position 
)

Finds a slave in the bus, given the alias and position.

Const version.

Returns:
Search result, or NULL.
Parameters:
master  EtherCAT master.
alias  Slave alias.
position  Slave position.

Definition at line 1831 of file master.c.

unsigned int ec_master_config_count ( const ec_master_t master  ) 

Get the number of slave configurations provided by the application.

Returns:
Number of configurations.
Parameters:
master  EtherCAT master.

Definition at line 1847 of file master.c.

ec_slave_config_t* ec_master_get_config ( const ec_master_t master,
unsigned int  pos 
)

Get a slave configuration via its position in the list.

Returns:
Slave configuration or NULL.
Parameters:
master  EtherCAT master.
pos  List position.

Definition at line 1880 of file master.c.

const ec_slave_config_t* ec_master_get_config_const ( const ec_master_t master,
unsigned int  pos 
)

Get a slave configuration via its position in the list.

Const version.

Returns:
Slave configuration or NULL.
Parameters:
master  EtherCAT master.
pos  List position.

Definition at line 1895 of file master.c.

unsigned int ec_master_domain_count ( const ec_master_t master  ) 

Get the number of domains.

Returns:
Number of domains.
Parameters:
master  EtherCAT master.

Definition at line 1910 of file master.c.

ec_domain_t* ec_master_find_domain ( ec_master_t master,
unsigned int  index 
)

Get a domain via its position in the list.

Returns:
Domain pointer, or NULL if not found.
Parameters:
master  EtherCAT master.
index  Domain index.

Definition at line 1944 of file master.c.

const ec_domain_t* ec_master_find_domain_const ( const ec_master_t master,
unsigned int  index 
)

Get a domain via its position in the list.

Const version.

Returns:
Domain pointer, or NULL if not found.
Parameters:
master  EtherCAT master.
index  Domain index.

Definition at line 1959 of file master.c.

uint16_t ec_master_eoe_handler_count ( const ec_master_t master  ) 

Get the number of EoE handlers.

Returns:
Number of EoE handlers.
Parameters:
master  EtherCAT master.

Definition at line 1976 of file master.c.

const ec_eoe_t* ec_master_get_eoe_handler_const ( const ec_master_t master,
uint16_t  index 
)

Get an EoE handler via its position in the list.

Const version.

Returns:
EoE handler pointer, or NULL if not found.
Parameters:
master  EtherCAT master.
index  EoE handler index.

Definition at line 1998 of file master.c.

int ec_master_debug_level ( ec_master_t master,
unsigned int  level 
)

Set the debug level.

Return values:
0 Success.
-EINVAL Invalid debug level.
Parameters:
master  EtherCAT master.
level  Debug level. May be 0, 1 or 2.

Definition at line 2023 of file master.c.

int ec_master_calc_topology_rec ( ec_master_t master,
ec_slave_t port0_slave,
unsigned int *  slave_position 
)

Calculates the bus topology; recursion function.

Returns:
Zero on success, otherwise a negative error code.
Parameters:
master  EtherCAT master.
port0_slave  Slave at port 0.
slave_position  Slave position.

Definition at line 2108 of file master.c.

void ec_master_calc_topology ( ec_master_t master  ) 

Calculates the bus topology.

Parameters:
master  EtherCAT master.

Definition at line 2151 of file master.c.

void ec_master_calc_transmission_delays ( ec_master_t master  ) 

Calculates the bus transmission delays.

Parameters:
master  EtherCAT master.

Definition at line 2168 of file master.c.

void ec_master_calc_dc ( ec_master_t master  ) 

Distributed-clocks calculations.

Parameters:
master  EtherCAT master.

Definition at line 2190 of file master.c.

void ec_master_request_op ( ec_master_t master  ) 

Request OP state for configured slaves.

Parameters:
master  EtherCAT master.

Definition at line 2207 of file master.c.

ec_domain_t* ecrt_master_create_domain_err ( ec_master_t master  ) 

Same as ecrt_master_create_domain(), but with ERR_PTR() return value.

Returns:
New domain, or ERR_PTR() return value.
Parameters:
master  master

Definition at line 2241 of file master.c.


Variable Documentation

const unsigned int rate_intervals[]

Initial value:

 {
    1, 10, 60
}
List of intervals for statistics [s].

Definition at line 91 of file master.c.


Generated on Mon Jun 20 09:31:31 2016 for IgH EtherCAT Master by  doxygen 1.5.6