IgH EtherCAT Master  1.5.3
master.h File Reference

EtherCAT master structure. More...

Go to the source code of this file.

Data Structures

struct  ec_stats_t
 Cyclic statistics. More...
 
struct  ec_device_stats_t
 Device statistics. More...
 
struct  ec_master
 EtherCAT master. More...
 

Macros

#define EC_MASTER_INFO(master, fmt, args...)   printk(KERN_INFO "EtherCAT %u: " fmt, master->index, ##args)
 Convenience macro for printing master-specific information to syslog. More...
 
#define EC_MASTER_ERR(master, fmt, args...)   printk(KERN_ERR "EtherCAT ERROR %u: " fmt, master->index, ##args)
 Convenience macro for printing master-specific errors to syslog. More...
 
#define EC_MASTER_WARN(master, fmt, args...)   printk(KERN_WARNING "EtherCAT WARNING %u: " fmt, master->index, ##args)
 Convenience macro for printing master-specific warnings to syslog. More...
 
#define EC_MASTER_DBG(master, level, fmt, args...)
 Convenience macro for printing master-specific debug messages to syslog. More...
 
#define EC_EXT_RING_SIZE   32
 Size of the external datagram ring. More...
 
#define ec_master_num_devices(MASTER)   ((MASTER)->num_devices)
 Number of Ethernet devices.
 

Enumerations

enum  ec_master_phase_t { EC_ORPHANED, EC_IDLE, EC_OPERATION }
 EtherCAT master phase. More...
 

Functions

void ec_master_init_static (void)
 Static variables initializer.
 
int ec_master_init (ec_master_t *, unsigned int, const uint8_t *, const uint8_t *, dev_t, struct class *, unsigned int, unsigned int)
 Master constructor. More...
 
void ec_master_clear (ec_master_t *)
 Destructor.
 
int ec_master_enter_idle_phase (ec_master_t *)
 Transition function from ORPHANED to IDLE phase. More...
 
void ec_master_leave_idle_phase (ec_master_t *)
 Transition function from IDLE to ORPHANED phase.
 
int ec_master_enter_operation_phase (ec_master_t *)
 Transition function from IDLE to OPERATION phase. More...
 
void ec_master_leave_operation_phase (ec_master_t *)
 Transition function from OPERATION to IDLE phase.
 
void ec_master_eoe_start (ec_master_t *)
 Starts Ethernet over EtherCAT processing on demand.
 
void ec_master_eoe_stop (ec_master_t *)
 Stops the Ethernet over EtherCAT processing.
 
void ec_master_receive_datagrams (ec_master_t *, ec_device_t *, const uint8_t *, size_t)
 Processes a received frame. More...
 
void ec_master_queue_datagram (ec_master_t *, ec_datagram_t *)
 Places a datagram in the datagram queue.
 
void ec_master_queue_datagram_ext (ec_master_t *, ec_datagram_t *)
 Places a datagram in the non-application datagram queue.
 
void ec_master_set_send_interval (ec_master_t *, unsigned int)
 Sets the expected interval between calls to ecrt_master_send and calculates the maximum amount of data to queue.
 
void ec_master_attach_slave_configs (ec_master_t *)
 Attaches the slave configurations to the slaves.
 
ec_slave_tec_master_find_slave (ec_master_t *, uint16_t, uint16_t)
 Finds a slave in the bus, given the alias and position. More...
 
const ec_slave_tec_master_find_slave_const (const ec_master_t *, uint16_t, uint16_t)
 Finds a slave in the bus, given the alias and position. More...
 
void ec_master_output_stats (ec_master_t *)
 Output master statistics. More...
 
void ec_master_clear_eoe_handlers (ec_master_t *)
 Clear and free all EoE handlers.
 
void ec_master_clear_slaves (ec_master_t *)
 Clear all slaves.
 
unsigned int ec_master_config_count (const ec_master_t *)
 Get the number of slave configurations provided by the application. More...
 
ec_slave_config_tec_master_get_config (const ec_master_t *, unsigned int)
 Get a slave configuration via its position in the list. More...
 
const ec_slave_config_tec_master_get_config_const (const ec_master_t *, unsigned int)
 Get a slave configuration via its position in the list. More...
 
unsigned int ec_master_domain_count (const ec_master_t *)
 Get the number of domains. More...
 
ec_domain_tec_master_find_domain (ec_master_t *, unsigned int)
 Get a domain via its position in the list. More...
 
const ec_domain_tec_master_find_domain_const (const ec_master_t *, unsigned int)
 Get a domain via its position in the list. More...
 
uint16_t ec_master_eoe_handler_count (const ec_master_t *)
 Get the number of EoE handlers. More...
 
const ec_eoe_tec_master_get_eoe_handler_const (const ec_master_t *, uint16_t)
 Get an EoE handler via its position in the list. More...
 
int ec_master_debug_level (ec_master_t *, unsigned int)
 Set the debug level. More...
 
ec_domain_tecrt_master_create_domain_err (ec_master_t *)
 Same as ecrt_master_create_domain(), but with ERR_PTR() return value. More...
 
ec_slave_config_tecrt_master_slave_config_err (ec_master_t *, uint16_t, uint16_t, uint32_t, uint32_t)
 Same as ecrt_master_slave_config(), but with ERR_PTR() return value.
 
void ec_master_calc_dc (ec_master_t *)
 Distributed-clocks calculations.
 
void ec_master_request_op (ec_master_t *)
 Request OP state for configured slaves.
 
void ec_master_internal_send_cb (void *)
 Internal sending callback.
 
void ec_master_internal_receive_cb (void *)
 Internal receiving callback.
 

Variables

const unsigned int rate_intervals [EC_RATE_COUNT]
 List of intervals for statistics [s].
 

Detailed Description

EtherCAT master structure.

Definition in file master.h.

Macro Definition Documentation

◆ EC_MASTER_INFO

#define EC_MASTER_INFO (   master,
  fmt,
  args... 
)    printk(KERN_INFO "EtherCAT %u: " fmt, master->index, ##args)

Convenience macro for printing master-specific information to syslog.

This will print the message in fmt with a prefixed "EtherCAT <INDEX>: ", where INDEX is the master index.

Parameters
masterEtherCAT master
fmtformat string (like in printf())
argsarguments (optional)

Definition at line 73 of file master.h.

◆ EC_MASTER_ERR

#define EC_MASTER_ERR (   master,
  fmt,
  args... 
)    printk(KERN_ERR "EtherCAT ERROR %u: " fmt, master->index, ##args)

Convenience macro for printing master-specific errors to syslog.

This will print the message in fmt with a prefixed "EtherCAT <INDEX>: ", where INDEX is the master index.

Parameters
masterEtherCAT master
fmtformat string (like in printf())
argsarguments (optional)

Definition at line 85 of file master.h.

◆ EC_MASTER_WARN

#define EC_MASTER_WARN (   master,
  fmt,
  args... 
)    printk(KERN_WARNING "EtherCAT WARNING %u: " fmt, master->index, ##args)

Convenience macro for printing master-specific warnings to syslog.

This will print the message in fmt with a prefixed "EtherCAT <INDEX>: ", where INDEX is the master index.

Parameters
masterEtherCAT master
fmtformat string (like in printf())
argsarguments (optional)

Definition at line 97 of file master.h.

◆ EC_MASTER_DBG

#define EC_MASTER_DBG (   master,
  level,
  fmt,
  args... 
)
Value:
do { \
if (master->debug_level >= level) { \
printk(KERN_DEBUG "EtherCAT DEBUG %u: " fmt, \
master->index, ##args); \
} \
} while (0)

Convenience macro for printing master-specific debug messages to syslog.

This will print the message in fmt with a prefixed "EtherCAT <INDEX>: ", where INDEX is the master index.

Parameters
masterEtherCAT master
levelDebug level. Master's debug level must be >= level for output.
fmtformat string (like in printf())
argsarguments (optional)

Definition at line 111 of file master.h.

◆ EC_EXT_RING_SIZE

#define EC_EXT_RING_SIZE   32

Size of the external datagram ring.

The external datagram ring is used for slave FSMs.

Definition at line 124 of file master.h.

Enumeration Type Documentation

◆ ec_master_phase_t

EtherCAT master phase.

Enumerator
EC_ORPHANED 

Orphaned phase.

The master has no Ethernet device attached.

EC_IDLE 

Idle phase.

An Ethernet device is attached, but the master is not in use, yet.

EC_OPERATION 

Operation phase.

The master was requested by a realtime application.

Definition at line 130 of file master.h.

Function Documentation

◆ ec_master_init()

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,
unsigned int  run_on_cpu 
)

Master constructor.

Returns
0 in case of success, else < 0
Parameters
masterEtherCAT master
indexmaster index
main_macMAC address of main device
backup_macMAC address of backup device
device_numberCharacter device number.
classDevice class.
debug_levelDebug level (module parameter).
run_on_cpubind created kernel threads to a cpu

Definition at line 142 of file master.c.

◆ ec_master_enter_idle_phase()

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
masterEtherCAT master

Definition at line 641 of file master.c.

◆ ec_master_enter_operation_phase()

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
masterEtherCAT master

Definition at line 698 of file master.c.

◆ ec_master_receive_datagrams()

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
masterEtherCAT master
deviceEtherCAT device
frame_dataframe data
sizesize of the received data

Definition at line 1137 of file master.c.

◆ ec_master_find_slave()

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
masterEtherCAT master.
aliasSlave alias.
positionSlave position.

Definition at line 1848 of file master.c.

◆ ec_master_find_slave_const()

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
masterEtherCAT master.
aliasSlave alias.
positionSlave position.

Definition at line 1864 of file master.c.

◆ ec_master_output_stats()

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
masterEtherCAT master

Definition at line 1275 of file master.c.

◆ ec_master_config_count()

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
masterEtherCAT master.

Definition at line 1880 of file master.c.

◆ ec_master_get_config()

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
masterEtherCAT master.
posList position.

Definition at line 1913 of file master.c.

◆ ec_master_get_config_const()

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
masterEtherCAT master.
posList position.

Definition at line 1928 of file master.c.

◆ ec_master_domain_count()

unsigned int ec_master_domain_count ( const ec_master_t master)

Get the number of domains.

Returns
Number of domains.
Parameters
masterEtherCAT master.

Definition at line 1943 of file master.c.

◆ ec_master_find_domain()

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
masterEtherCAT master.
indexDomain index.

Definition at line 1977 of file master.c.

◆ ec_master_find_domain_const()

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
masterEtherCAT master.
indexDomain index.

Definition at line 1992 of file master.c.

◆ ec_master_eoe_handler_count()

uint16_t ec_master_eoe_handler_count ( const ec_master_t master)

Get the number of EoE handlers.

Returns
Number of EoE handlers.
Parameters
masterEtherCAT master.

Definition at line 2009 of file master.c.

◆ ec_master_get_eoe_handler_const()

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
masterEtherCAT master.
indexEoE handler index.

Definition at line 2031 of file master.c.

◆ ec_master_debug_level()

int ec_master_debug_level ( ec_master_t master,
unsigned int  level 
)

Set the debug level.

Return values
0Success.
-EINVALInvalid debug level.
Parameters
masterEtherCAT master.
levelDebug level. May be 0, 1 or 2.

Definition at line 2056 of file master.c.

◆ ecrt_master_create_domain_err()

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
mastermaster

Definition at line 2274 of file master.c.