41 #include <linux/list.h> |
41 #include <linux/list.h> |
42 #include <linux/timer.h> |
42 #include <linux/timer.h> |
43 #include <linux/wait.h> |
43 #include <linux/wait.h> |
44 #include <linux/kthread.h> |
44 #include <linux/kthread.h> |
45 |
45 |
46 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
|
47 #include <linux/semaphore.h> |
|
48 #else |
|
49 #include <asm/semaphore.h> |
|
50 #endif |
|
51 |
|
52 #include "device.h" |
46 #include "device.h" |
53 #include "domain.h" |
47 #include "domain.h" |
54 #include "ethernet.h" |
48 #include "ethernet.h" |
55 #include "fsm_master.h" |
49 #include "fsm_master.h" |
56 #include "cdev.h" |
50 #include "cdev.h" |
|
51 |
57 |
52 |
58 /*****************************************************************************/ |
53 /*****************************************************************************/ |
59 |
54 |
60 /** Convenience macro for printing master-specific information to syslog. |
55 /** Convenience macro for printing master-specific information to syslog. |
61 * |
56 * |
150 struct device *class_device; /**< Master class device. */ |
145 struct device *class_device; /**< Master class device. */ |
151 #else |
146 #else |
152 struct class_device *class_device; /**< Master class device. */ |
147 struct class_device *class_device; /**< Master class device. */ |
153 #endif |
148 #endif |
154 |
149 |
155 struct semaphore master_sem; /**< Master semaphore. */ |
150 struct ec_mutex_t master_mutex; /**< Master mutex. */ |
156 |
151 |
157 ec_device_t main_device; /**< EtherCAT main device. */ |
152 ec_device_t main_device; /**< EtherCAT main device. */ |
158 const uint8_t *main_mac; /**< MAC address of main device. */ |
153 const uint8_t *main_mac; /**< MAC address of main device. */ |
159 ec_device_t backup_device; /**< EtherCAT backup device. */ |
154 ec_device_t backup_device; /**< EtherCAT backup device. */ |
160 const uint8_t *backup_mac; /**< MAC address of backup device. */ |
155 const uint8_t *backup_mac; /**< MAC address of backup device. */ |
161 struct semaphore device_sem; /**< Device semaphore. */ |
156 struct ec_mutex_t device_mutex; /**< Device mutex. */ |
162 |
157 |
163 ec_fsm_master_t fsm; /**< Master state machine. */ |
158 ec_fsm_master_t fsm; /**< Master state machine. */ |
164 ec_datagram_t fsm_datagram; /**< Datagram used for state machines. */ |
159 ec_datagram_t fsm_datagram; /**< Datagram used for state machines. */ |
165 ec_master_phase_t phase; /**< Master phase. */ |
160 ec_master_phase_t phase; /**< Master phase. */ |
166 unsigned int active; /**< Master has been activated. */ |
161 unsigned int active; /**< Master has been activated. */ |
192 #endif |
187 #endif |
193 unsigned long dc_jiffies_app_start_time;/** jiffies at last |
188 unsigned long dc_jiffies_app_start_time;/** jiffies at last |
194 ecrt_master_sync() call.*/ |
189 ecrt_master_sync() call.*/ |
195 unsigned int scan_busy; /**< Current scan state. */ |
190 unsigned int scan_busy; /**< Current scan state. */ |
196 unsigned int allow_scan; /**< \a True, if slave scanning is allowed. */ |
191 unsigned int allow_scan; /**< \a True, if slave scanning is allowed. */ |
197 struct semaphore scan_sem; /**< Semaphore protecting the \a scan_busy |
192 struct ec_mutex_t scan_mutex; /**< Mutex protecting the \a scan_busy |
198 variable and the \a allow_scan flag. */ |
193 variable and the \a allow_scan flag. */ |
199 wait_queue_head_t scan_queue; /**< Queue for processes that wait for |
194 wait_queue_head_t scan_queue; /**< Queue for processes that wait for |
200 slave scanning. */ |
195 slave scanning. */ |
201 |
196 |
202 unsigned int config_busy; /**< State of slave configuration. */ |
197 unsigned int config_busy; /**< State of slave configuration. */ |
203 unsigned int allow_config; /**< \a True, if slave configuration is |
198 unsigned int allow_config; /**< \a True, if slave configuration is |
204 allowed. */ |
199 allowed. */ |
205 struct semaphore config_sem; /**< Semaphore protecting the \a config_busy |
200 struct ec_mutex_t config_mutex; /**< Mutex protecting the \a config_busy |
206 variable and the allow_config flag. */ |
201 variable and the allow_config flag. */ |
207 wait_queue_head_t config_queue; /**< Queue for processes that wait for |
202 wait_queue_head_t config_queue; /**< Queue for processes that wait for |
208 slave configuration. */ |
203 slave configuration. */ |
209 |
204 |
210 struct list_head datagram_queue; /**< Datagram queue. */ |
205 struct list_head datagram_queue; /**< Datagram queue. */ |
211 uint8_t datagram_index; /**< Current datagram index. */ |
206 uint8_t datagram_index; /**< Current datagram index. */ |
212 |
207 |
213 struct semaphore fsm_queue_sem; /**< Semaphore protecting the \a |
208 struct ec_mutex_t fsm_queue_mutex; /**< Mutex protecting the \a |
214 fsm_datagram_queue. */ |
209 fsm_datagram_queue. */ |
215 struct list_head fsm_datagram_queue; /**< External Datagram queue. */ |
210 struct list_head fsm_datagram_queue; /**< External Datagram queue. */ |
216 |
211 |
217 unsigned int send_interval; /**< Interval between calls to ecrt_master_send */ |
212 unsigned int send_interval; /**< Interval between calls to ecrt_master_send */ |
218 size_t max_queue_size; /**< Maximum size of datagram queue */ |
213 size_t max_queue_size; /**< Maximum size of datagram queue */ |
225 #ifdef EC_EOE |
220 #ifdef EC_EOE |
226 struct task_struct *eoe_thread; /**< EoE thread. */ |
221 struct task_struct *eoe_thread; /**< EoE thread. */ |
227 struct list_head eoe_handlers; /**< Ethernet over EtherCAT handlers. */ |
222 struct list_head eoe_handlers; /**< Ethernet over EtherCAT handlers. */ |
228 #endif |
223 #endif |
229 |
224 |
230 struct semaphore io_sem; /**< Semaphore used in \a IDLE phase. */ |
225 struct ec_mutex_t io_mutex; /**< Mutex used in \a IDLE phase. */ |
231 |
226 |
232 void (*fsm_queue_lock_cb)(void *); /**< FSM queue lock callback. */ |
227 void (*fsm_queue_lock_cb)(void *); /**< FSM queue lock callback. */ |
233 void (*fsm_queue_unlock_cb)(void *); /**< FSM queue unlock callback. */ |
228 void (*fsm_queue_unlock_cb)(void *); /**< FSM queue unlock callback. */ |
234 void *fsm_queue_locking_data; /**< Data parameter of fsm queue locking callbacks. */ |
229 void *fsm_queue_locking_data; /**< Data parameter of fsm queue locking callbacks. */ |
235 void (*app_fsm_queue_lock_cb)(void *); /**< App's FSM queue lock callback. */ |
230 void (*app_fsm_queue_lock_cb)(void *); /**< App's FSM queue lock callback. */ |