29 #ifndef __EC_MASTER_H__ 30 #define __EC_MASTER_H__ 32 #include <linux/version.h> 33 #include <linux/irq_work.h> 34 #include <linux/list.h> 35 #include <linux/timer.h> 36 #include <linux/wait.h> 37 #include <linux/kthread.h> 38 #include <linux/rtmutex.h> 39 #include <linux/workqueue.h> 62 #define EC_MASTER_INFO(master, fmt, args...) \ 63 printk(KERN_INFO "EtherCAT %u: " fmt, master->index, ##args) 74 #define EC_MASTER_ERR(master, fmt, args...) \ 75 printk(KERN_ERR "EtherCAT ERROR %u: " fmt, master->index, ##args) 86 #define EC_MASTER_WARN(master, fmt, args...) \ 87 printk(KERN_WARNING "EtherCAT WARNING %u: " fmt, master->index, ##args) 100 #define EC_MASTER_DBG(master, level, fmt, args...) \ 102 if (master->debug_level >= level) { \ 103 printk(KERN_DEBUG "EtherCAT DEBUG %u: " fmt, \ 104 master->index, ##args); \ 113 #define EC_EXT_RING_SIZE 32 117 #define EC_MAX_MASTERS 32 177 #if EC_MAX_NUM_DEVICES < 1 178 #error Invalid number of devices 201 const uint8_t *
macs[EC_MAX_NUM_DEVICES];
202 #if EC_MAX_NUM_DEVICES > 1 315 const uint8_t *, dev_t,
struct class *,
unsigned int,
unsigned int);
320 #if EC_MAX_NUM_DEVICES > 1 321 #define ec_master_num_devices(MASTER) ((MASTER)->num_devices) 323 #define ec_master_num_devices(MASTER) 1 340 const uint8_t *,
size_t);
374 uint16_t, uint32_t, uint32_t);
unsigned int injection_seq_fsm
Datagram injection sequence number for the FSM side.
void ec_master_clear_slaves(ec_master_t *)
Clear all slaves.
unsigned int reserved
True, if the master is in use.
struct list_head ext_datagram_queue
Queue for non-application datagrams.
void ec_master_eoe_stop(ec_master_t *)
Stops the Ethernet over EtherCAT processing.
struct semaphore config_sem
Semaphore protecting the config_busy variable and the allow_config flag.
void ec_master_internal_receive_cb(void *)
Internal receiving callback.
unsigned int fsm_exec_count
Number of entries in execution list.
unsigned int num_devices
Number of devices.
u64 last_loss
Tx/Rx difference of last statistics cycle.
u64 tx_count
Number of frames sent.
ec_domain_t * ecrt_master_create_domain_err(ec_master_t *)
Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
struct list_head sii_requests
SII write requests.
Finite state machine of an EtherCAT master.
const ec_eoe_t * ec_master_get_eoe_handler_const(const ec_master_t *, uint16_t)
Get an EoE handler via its position in the list.
#define EC_RATE_COUNT
Number of statistic rate intervals to maintain.
ec_datagram_t sync_mon_datagram
Datagram used for DC synchronisation monitoring.
struct list_head eoe_handlers
Ethernet over EtherCAT handlers.
const ec_slave_t * ec_master_find_slave_const(const ec_master_t *, uint16_t, uint16_t)
Finds a slave in the bus, given the alias and position.
unsigned int allow_scan
True, if slave scanning is allowed.
size_t max_queue_size
Maximum size of datagram queue.
void ec_master_request_op(ec_master_t *)
Request OP state for configured slaves.
struct list_head fsm_exec_list
Slave FSM execution list.
unsigned int scan_index
Index of slave currently scanned.
u64 dc_ref_time
Common reference timestamp for DC start times.
struct list_head emerg_reg_requests
Emergency register access requests.
int ec_master_enter_idle_phase(ec_master_t *)
Transition function from ORPHANED to IDLE phase.
struct list_head domains
List of domains.
ec_slave_config_t * ec_master_get_config(const ec_master_t *, unsigned int)
Get a slave configuration via its position in the list.
unsigned long jiffies
Jiffies of last statistic cycle.
const unsigned int rate_intervals[EC_RATE_COUNT]
List of intervals for statistics [s].
u64 last_rx_count
Number of frames received of last statistics cycle.
const uint8_t * macs[EC_MAX_NUM_DEVICES]
Device MAC addresses.
wait_queue_head_t request_queue
Wait queue for external requests from user space.
EtherCAT master state machine.
unsigned int run_on_cpu
bind kernel threads to this cpu
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.
void * cb_data
Current callback data.
ec_slave_t * fsm_slave
Slave that is queried next for FSM exec.
unsigned int send_interval
Interval between two calls to ecrt_master_send().
struct semaphore master_sem
Master semaphore.
uint8_t datagram_index
Current datagram index.
struct list_head datagram_queue
Datagram queue.
struct irq_work sc_reset_work_kicker
NMI-Safe kicker to trigger reset task above.
struct task_struct * eoe_thread
EoE thread.
unsigned int unmatched
unmatched datagrams (received, but not queued any longer)
unsigned int ext_ring_idx_fsm
Index in external datagram ring for FSM side.
Ethernet over EtherCAT (EoE)
ec_device_stats_t device_stats
Device statistics.
ec_datagram_t fsm_datagram
Datagram used for state machines.
ec_master_phase_t phase
Master phase.
ec_slave_t * slaves
Array of slaves on the bus.
unsigned int ec_master_domain_count(const ec_master_t *)
Get the number of domains.
struct semaphore device_sem
Device semaphore.
void ec_master_output_stats(ec_master_t *)
Output master statistics.
ec_domain_t * ec_master_find_domain(ec_master_t *, unsigned int)
Get a domain via its position in the list.
unsigned int timeouts
datagram timeouts
unsigned int debug_level
Master debug level.
ec_slave_t * ec_master_find_slave(ec_master_t *, uint16_t, uint16_t)
Finds a slave in the bus, given the alias and position.
unsigned int corrupted
corrupted frames
u64 last_tx_count
Number of frames sent of last statistics cycle.
void ec_master_receive_datagrams(ec_master_t *, ec_device_t *, const uint8_t *, size_t)
Processes a received frame.
unsigned int ext_ring_idx_rt
Index in external datagram ring for RT side.
struct rt_mutex io_mutex
Mutex used in IDLE and OP phase.
unsigned int slave_count
Number of slaves on the bus.
unsigned int scan_busy
Current scan state.
void(* receive_cb)(void *)
Current receive datagrams callback.
void ec_master_clear(ec_master_t *)
Destructor.
void ec_master_calc_dc(ec_master_t *)
Distributed-clocks calculations.
unsigned int active
Master has been activated.
wait_queue_head_t scan_queue
Queue for processes that wait for slave scanning.
int ec_master_debug_level(ec_master_t *, unsigned int)
Set the debug level.
ec_datagram_t sync_datagram
Datagram used for DC drift compensation.
struct device * class_device
Master class device.
void ec_master_internal_send_cb(void *)
Internal sending callback.
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 dat...
struct list_head configs
List of slave configurations.
ec_slave_config_t * dc_ref_config
Application-selected DC reference clock slave config.
uint16_t ec_master_eoe_handler_count(const ec_master_t *)
Get the number of EoE handlers.
u64 last_rx_bytes
Number of bytes received of last statistics cycle.
unsigned long output_jiffies
time of last output
ec_stats_t stats
Cyclic statistics.
struct semaphore scan_sem
Semaphore protecting the scan_busy variable and the allow_scan flag.
void ec_master_queue_datagram_ext(ec_master_t *, ec_datagram_t *)
Places a datagram in the non-application datagram queue.
void ec_master_leave_operation_phase(ec_master_t *)
Transition function from OPERATION to IDLE phase.
u64 tx_bytes
Number of bytes sent.
void(* app_send_cb)(void *)
Application's send datagrams callback.
void * app_cb_data
Application callback data.
void ec_master_eoe_start(ec_master_t *)
Starts Ethernet over EtherCAT processing on demand.
ec_datagram_t ext_datagram_ring[EC_EXT_RING_SIZE]
External datagram ring.
wait_queue_head_t config_queue
Queue for processes that wait for slave configuration.
#define EC_EXT_RING_SIZE
Size of the external datagram ring.
EtherCAT domain structure.
unsigned int ec_master_config_count(const ec_master_t *)
Get the number of slave configurations provided by the application.
u64 app_time
Time of the last ecrt_master_sync() call.
ec_datagram_t ref_sync_datagram
Datagram used for synchronizing the reference clock to the master clock.
u64 rx_count
Number of frames received.
void ec_master_leave_idle_phase(ec_master_t *)
Transition function from IDLE to ORPHANED phase.
struct work_struct sc_reset_work
Task to reset slave configuration.
ec_slave_config_t * ecrt_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.
EtherCAT master character device.
struct semaphore ext_queue_sem
Semaphore protecting the ext_datagram_queue.
EtherCAT slave configuration.
EtherCAT device structure.
void(* app_receive_cb)(void *)
Application's receive datagrams callback.
ec_master_phase_t
EtherCAT master phase.
void ec_master_attach_slave_configs(ec_master_t *)
Attaches the slave configurations to the slaves.
void ec_master_init_static(void)
Static variables initializer.
void ec_master_clear_eoe_handlers(ec_master_t *)
Clear and free all EoE handlers.
u64 last_tx_bytes
Number of bytes sent of last statistics cycle.
Ethernet over EtherCAT (EoE) handler.
ec_fsm_master_t fsm
Master state machine.
ec_cdev_t cdev
Master character device.
const ec_domain_t * ec_master_find_domain_const(const ec_master_t *, unsigned int)
Get a domain via its position in the list.
u64 rx_bytes
Number of bytes received.
const ec_slave_config_t * ec_master_get_config_const(const ec_master_t *, unsigned int)
Get a slave configuration via its position in the list.
unsigned int config_changed
The configuration changed.
unsigned int injection_seq_rt
Datagram injection sequence number for the realtime side.
ec_device_t devices[EC_MAX_NUM_DEVICES]
EtherCAT devices.
unsigned int config_busy
State of slave configuration.
EtherCAT master character device.
int ec_master_enter_operation_phase(ec_master_t *)
Transition function from IDLE to OPERATION phase.
void(* send_cb)(void *)
Current send datagrams callback.
struct task_struct * thread
Master thread.
ec_slave_t * dc_ref_clock
DC reference clock slave.
void ec_master_queue_datagram(ec_master_t *, ec_datagram_t *)
Places a datagram in the datagram queue.