38 |
38 |
39 #include "../globals.h" |
39 #include "../globals.h" |
40 #include "../include/ecrt.h" |
40 #include "../include/ecrt.h" |
41 |
41 |
42 #ifdef __KERNEL__ |
42 #ifdef __KERNEL__ |
|
43 |
43 #include <linux/version.h> |
44 #include <linux/version.h> |
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) |
45 |
|
46 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
45 #include <linux/rtmutex.h> |
47 #include <linux/rtmutex.h> |
46 #endif // KERNEL_VERSION(2,6,24) |
48 #endif // KERNEL_VERSION(2, 6, 24) |
|
49 |
47 #endif // __KERNEL__ |
50 #endif // __KERNEL__ |
48 |
51 |
|
52 #if 0 |
49 #ifdef CONFIG_TRACING |
53 #ifdef CONFIG_TRACING |
50 //#define USE_TRACE_PRINTK |
54 #define USE_TRACE_PRINTK |
|
55 #endif |
51 #endif |
56 #endif |
52 |
57 |
53 /****************************************************************************** |
58 /****************************************************************************** |
54 * EtherCAT master |
59 * EtherCAT master |
55 *****************************************************************************/ |
60 *****************************************************************************/ |
314 |
319 |
315 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */ |
320 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */ |
316 |
321 |
317 /*****************************************************************************/ |
322 /*****************************************************************************/ |
318 |
323 |
319 /*****************************************************************************/ |
|
320 |
|
321 #ifdef __KERNEL__ |
324 #ifdef __KERNEL__ |
322 |
325 |
323 /** Mutual exclusion helpers. |
326 /** Mutual exclusion helpers. |
324 * |
327 */ |
325 */ |
328 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
326 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) |
329 |
327 #define ec_mutex_t rt_mutex |
330 #define ec_mutex_t rt_mutex |
|
331 |
328 static inline void ec_mutex_init(struct ec_mutex_t *mutex) |
332 static inline void ec_mutex_init(struct ec_mutex_t *mutex) |
329 { |
333 { |
330 rt_mutex_init(mutex); |
334 rt_mutex_init(mutex); |
331 } |
335 } |
|
336 |
332 static inline void ec_mutex_lock(struct ec_mutex_t *mutex) |
337 static inline void ec_mutex_lock(struct ec_mutex_t *mutex) |
333 { |
338 { |
334 rt_mutex_lock(mutex); |
339 rt_mutex_lock(mutex); |
335 } |
340 } |
|
341 |
336 static inline int ec_mutex_trylock(struct ec_mutex_t *mutex) |
342 static inline int ec_mutex_trylock(struct ec_mutex_t *mutex) |
337 { |
343 { |
338 return rt_mutex_trylock(mutex); |
344 return rt_mutex_trylock(mutex); |
339 } |
345 } |
|
346 |
340 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *mutex) |
347 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *mutex) |
341 { |
348 { |
342 return rt_mutex_lock_interruptible(mutex,0); |
349 return rt_mutex_lock_interruptible(mutex, 0); |
343 } |
350 } |
|
351 |
344 static inline void ec_mutex_unlock(struct ec_mutex_t *mutex) |
352 static inline void ec_mutex_unlock(struct ec_mutex_t *mutex) |
345 { |
353 { |
346 rt_mutex_unlock(mutex); |
354 rt_mutex_unlock(mutex); |
347 } |
355 } |
348 #else // < KERNEL_VERSION(2,6,24) |
356 |
|
357 #else // < KERNEL_VERSION(2, 6, 24) |
|
358 |
349 #define ec_mutex_t semaphore |
359 #define ec_mutex_t semaphore |
|
360 |
350 static inline void ec_mutex_init(struct ec_mutex_t *sem) |
361 static inline void ec_mutex_init(struct ec_mutex_t *sem) |
351 { |
362 { |
352 sema_init(sem, 1); |
363 sema_init(sem, 1); |
353 } |
364 } |
|
365 |
354 static inline void ec_mutex_lock(struct ec_mutex_t *sem) |
366 static inline void ec_mutex_lock(struct ec_mutex_t *sem) |
355 { |
367 { |
356 down(sem); |
368 down(sem); |
357 } |
369 } |
|
370 |
358 static inline int ec_mutex_trylock(struct ec_mutex_t *sem) |
371 static inline int ec_mutex_trylock(struct ec_mutex_t *sem) |
359 { |
372 { |
360 down(sem); |
373 down(sem); |
361 return 1; |
374 return 1; |
362 } |
375 } |
|
376 |
363 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *sem) |
377 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *sem) |
364 { |
378 { |
365 return down_interruptible(sem); |
379 return down_interruptible(sem); |
366 } |
380 } |
|
381 |
367 static inline void ec_mutex_unlock(struct ec_mutex_t *sem) |
382 static inline void ec_mutex_unlock(struct ec_mutex_t *sem) |
368 { |
383 { |
369 up(sem); |
384 up(sem); |
370 } |
385 } |
371 |
386 |
372 #endif // KERNEL_VERSION(2,6,24) |
387 #endif // KERNEL_VERSION(2, 6, 24) |
|
388 |
373 #endif // __KERNEL__ |
389 #endif // __KERNEL__ |
374 |
390 |
|
391 /*****************************************************************************/ |
|
392 |
375 #endif |
393 #endif |