78 /** EtherCAT master. |
81 /** EtherCAT master. |
79 * |
82 * |
80 * Manages slaves, domains and IO. |
83 * Manages slaves, domains and IO. |
81 */ |
84 */ |
82 struct ec_master { |
85 struct ec_master { |
83 unsigned int index; /**< master index */ |
86 unsigned int index; /**< Index. */ |
84 unsigned int reserved; /**< non-zero, if the master is reserved for RT */ |
87 unsigned int reserved; /**< \a True, if the master is in use. */ |
85 |
88 |
86 ec_cdev_t cdev; /**< Master character device. */ |
89 ec_cdev_t cdev; /**< Master character device. */ |
87 struct class_device *class_device; /**< Master class device. */ |
90 struct class_device *class_device; /**< Master class device. */ |
88 |
91 |
89 ec_device_t main_device; /**< EtherCAT device */ |
92 ec_device_t main_device; /**< EtherCAT main device. */ |
90 const uint8_t *main_mac; /**< MAC address of main device */ |
93 const uint8_t *main_mac; /**< MAC address of main device. */ |
91 ec_device_t backup_device; /**< EtherCAT backup device */ |
94 ec_device_t backup_device; /**< EtherCAT backup device. */ |
92 const uint8_t *backup_mac; /**< MAC address of backup device */ |
95 const uint8_t *backup_mac; /**< MAC address of backup device. */ |
93 struct semaphore device_sem; /**< device semaphore */ |
96 struct semaphore device_sem; /**< Device semaphore. */ |
94 |
97 |
95 ec_fsm_master_t fsm; /**< master state machine */ |
98 ec_fsm_master_t fsm; /**< Master state machine. */ |
96 ec_datagram_t fsm_datagram; /**< datagram used for state machines */ |
99 ec_datagram_t fsm_datagram; /**< Datagram used for state machines. */ |
97 ec_master_mode_t mode; /**< master mode */ |
100 ec_master_phase_t phase; /**< Master phase. */ |
98 unsigned int injection_seq_fsm; /**< datagram injection sequence number |
101 unsigned int injection_seq_fsm; /**< Datagram injection sequence number |
99 for the FSM side */ |
102 for the FSM side. */ |
100 unsigned int injection_seq_rt; /**< datagram injection sequence number |
103 unsigned int injection_seq_rt; /**< Datagram injection sequence number |
101 for the realtime side */ |
104 for the realtime side. */ |
102 |
105 |
103 ec_slave_t *slaves; /**< Array of slaves on the bus. */ |
106 ec_slave_t *slaves; /**< Array of slaves on the bus. */ |
104 unsigned int slave_count; /**< Number of slaves on the bus. */ |
107 unsigned int slave_count; /**< Number of slaves on the bus. */ |
105 |
108 |
106 struct list_head configs; /**< List of slave configurations. */ |
109 struct list_head configs; /**< List of slave configurations. */ |
107 |
110 |
108 unsigned int scan_busy; /**< Current scan state. */ |
111 unsigned int scan_busy; /**< Current scan state. */ |
109 unsigned int allow_scan; /**< non-zero, if slave scanning is allowed */ |
112 unsigned int allow_scan; /**< \a True, if slave scanning is allowed. */ |
110 struct semaphore scan_sem; /**< semaphore protecting the scan_state |
113 struct semaphore scan_sem; /**< Semaphore protecting the \a scan_busy |
111 variable and the allow_scan flag */ |
114 variable and the \a allow_scan flag. */ |
112 wait_queue_head_t scan_queue; /**< queue for processes that wait for |
115 wait_queue_head_t scan_queue; /**< Queue for processes that wait for |
113 slave scanning */ |
116 slave scanning. */ |
114 |
117 |
115 unsigned int config_busy; /**< State of slave configuration. */ |
118 unsigned int config_busy; /**< State of slave configuration. */ |
116 unsigned int allow_config; /**< non-zero, if slave scanning is allowed */ |
119 unsigned int allow_config; /**< \a True, if slave configuration is |
117 struct semaphore config_sem; /**< semaphore protecting the config_state |
120 allowed. */ |
118 variable and the allow_config flag */ |
121 struct semaphore config_sem; /**< Semaphore protecting the \a config_busy |
119 wait_queue_head_t config_queue; /**< queue for processes that wait for |
122 variable and the allow_config flag. */ |
120 slave configuration */ |
123 wait_queue_head_t config_queue; /**< Queue for processes that wait for |
121 |
124 slave configuration. */ |
122 struct list_head datagram_queue; /**< datagram queue */ |
125 |
123 uint8_t datagram_index; /**< current datagram index */ |
126 struct list_head datagram_queue; /**< Datagram queue. */ |
124 |
127 uint8_t datagram_index; /**< Current datagram index. */ |
125 struct list_head domains; /**< list of domains */ |
128 |
|
129 struct list_head domains; /**< List of domains. */ |
126 |
130 |
127 int debug_level; /**< Master debug level. */ |
131 int debug_level; /**< Master debug level. */ |
128 ec_stats_t stats; /**< cyclic statistics */ |
132 ec_stats_t stats; /**< Cyclic statistics. */ |
129 unsigned int frames_timed_out; /**< there were frame timeouts in the last |
133 unsigned int frames_timed_out; /**< There were frame timeouts in the last |
130 call to ecrt_master_receive() */ |
134 call to ecrt_master_receive(). */ |
131 |
135 |
132 int thread_id; /**< master thread PID */ |
136 int thread_id; /**< Master thread PID. */ |
133 struct completion thread_exit; /**< thread completion object */ |
137 struct completion thread_exit; /**< Thread completion object. */ |
134 uint32_t idle_cycle_times[HZ]; /**< Idle cycle times ring */ |
138 uint32_t idle_cycle_times[HZ]; /**< Idle cycle times ring. */ |
135 unsigned int idle_cycle_time_pos; /**< time ring buffer position */ |
139 unsigned int idle_cycle_time_pos; /**< time ring buffer position */ |
136 |
140 |
137 #ifdef EC_EOE |
141 #ifdef EC_EOE |
138 struct timer_list eoe_timer; /**< EoE timer object */ |
142 struct timer_list eoe_timer; /**< EoE timer object. */ |
139 unsigned int eoe_running; /**< non-zero, if EoE processing is active. */ |
143 unsigned int eoe_running; /**< \a True, if EoE processing is active. */ |
140 struct list_head eoe_handlers; /**< Ethernet-over-EtherCAT handlers */ |
144 struct list_head eoe_handlers; /**< Ethernet-over-EtherCAT handlers. */ |
141 uint32_t eoe_cycle_times[HZ]; /**< EoE cycle times ring */ |
145 uint32_t eoe_cycle_times[HZ]; /**< EoE cycle times ring. */ |
142 unsigned int eoe_cycle_time_pos; /**< time ring buffer position */ |
146 unsigned int eoe_cycle_time_pos; /**< Time ring buffer position. */ |
143 #endif |
147 #endif |
144 |
148 |
145 spinlock_t internal_lock; /**< spinlock used in idle mode */ |
149 spinlock_t internal_lock; /**< Spinlock used in \a IDLE phase. */ |
146 int (*request_cb)(void *); /**< lock request callback */ |
150 int (*request_cb)(void *); /**< Lock request callback. */ |
147 void (*release_cb)(void *); /**< lock release callback */ |
151 void (*release_cb)(void *); /**< Lock release callback. */ |
148 void *cb_data; /**< data parameter of locking callbacks */ |
152 void *cb_data; /**< Data parameter of locking callbacks. */ |
149 int (*ext_request_cb)(void *); /**< external lock request callback */ |
153 int (*ext_request_cb)(void *); /**< External lock request callback. */ |
150 void (*ext_release_cb)(void *); /**< externam lock release callback */ |
154 void (*ext_release_cb)(void *); /**< External lock release callback. */ |
151 void *ext_cb_data; /**< data parameter of external locking callbacks */ |
155 void *ext_cb_data; /**< Data parameter of external locking callbacks. */ |
152 |
156 |
153 struct list_head sii_requests; /**< SII write requests */ |
157 struct list_head sii_requests; /**< SII write requests. */ |
154 struct semaphore sii_sem; /**< semaphore protecting the list of |
158 struct semaphore sii_sem; /**< Semaphore protecting the list of |
155 SII write requests */ |
159 SII write requests. */ |
156 wait_queue_head_t sii_queue; /**< wait queue for SII |
160 wait_queue_head_t sii_queue; /**< Wait queue for SII |
157 write requests from user space */ |
161 write requests from user space. */ |
158 |
162 |
159 struct list_head slave_sdo_requests; /**< Sdo access requests. */ |
163 struct list_head slave_sdo_requests; /**< Sdo access requests. */ |
160 struct semaphore sdo_sem; /**< semaphore protecting the list of |
164 struct semaphore sdo_sem; /**< Semaphore protecting the list of |
161 Sdo access requests */ |
165 Sdo access requests. */ |
162 wait_queue_head_t sdo_queue; /**< wait queue for Sdo access requests |
166 wait_queue_head_t sdo_queue; /**< Wait queue for Sdo access requests |
163 from user space */ |
167 from user space. */ |
164 }; |
168 }; |
165 |
169 |
166 /*****************************************************************************/ |
170 /*****************************************************************************/ |
167 |
171 |
168 // master creation/deletion |
172 // master creation/deletion |
169 int ec_master_init(ec_master_t *, unsigned int, const uint8_t *, |
173 int ec_master_init(ec_master_t *, unsigned int, const uint8_t *, |
170 const uint8_t *, dev_t, struct class *); |
174 const uint8_t *, dev_t, struct class *); |
171 void ec_master_clear(ec_master_t *); |
175 void ec_master_clear(ec_master_t *); |
172 |
176 |
173 // mode transitions |
177 // phase transitions |
174 int ec_master_enter_idle_mode(ec_master_t *); |
178 int ec_master_enter_idle_phase(ec_master_t *); |
175 void ec_master_leave_idle_mode(ec_master_t *); |
179 void ec_master_leave_idle_phase(ec_master_t *); |
176 int ec_master_enter_operation_mode(ec_master_t *); |
180 int ec_master_enter_operation_phase(ec_master_t *); |
177 void ec_master_leave_operation_mode(ec_master_t *); |
181 void ec_master_leave_operation_phase(ec_master_t *); |
178 |
182 |
179 #ifdef EC_EOE |
183 #ifdef EC_EOE |
180 // EoE |
184 // EoE |
181 void ec_master_eoe_start(ec_master_t *); |
185 void ec_master_eoe_start(ec_master_t *); |
182 void ec_master_eoe_stop(ec_master_t *); |
186 void ec_master_eoe_stop(ec_master_t *); |