master/globals.h
changeset 2028 55854f070c4a
parent 2022 393e7aef6706
child 2035 72a4e043e67d
equal deleted inserted replaced
2027:ac35f4d38a31 2028:55854f070c4a
    36 #ifndef __EC_MASTER_GLOBALS_H__
    36 #ifndef __EC_MASTER_GLOBALS_H__
    37 #define __EC_MASTER_GLOBALS_H__
    37 #define __EC_MASTER_GLOBALS_H__
    38 
    38 
    39 #include "../globals.h"
    39 #include "../globals.h"
    40 #include "../include/ecrt.h"
    40 #include "../include/ecrt.h"
       
    41 
       
    42 #ifdef __KERNEL__
       
    43 #ifdef EC_USE_MUTEX
       
    44 #include <linux/rtmutex.h>
       
    45 #endif  // EC_USE_MUTEX
       
    46 #endif // __KERNEL__
    41 
    47 
    42 /******************************************************************************
    48 /******************************************************************************
    43  * EtherCAT master
    49  * EtherCAT master
    44  *****************************************************************************/
    50  *****************************************************************************/
    45 
    51 
   303 
   309 
   304 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */
   310 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */
   305 
   311 
   306 /*****************************************************************************/
   312 /*****************************************************************************/
   307 
   313 
       
   314 /*****************************************************************************/
       
   315 
       
   316 #ifdef __KERNEL__
       
   317 
       
   318 /** Mutual exclusion helpers.
       
   319  *
       
   320  */
       
   321 #ifdef EC_USE_MUTEX
       
   322 #define ec_mutex_t rt_mutex
       
   323 static inline void ec_mutex_init(struct ec_mutex_t *mutex)
       
   324 {
       
   325     rt_mutex_init(mutex);
       
   326 }
       
   327 static inline void ec_mutex_lock(struct ec_mutex_t *mutex)
       
   328 {
       
   329     rt_mutex_lock(mutex);
       
   330 }
       
   331 static inline int ec_mutex_trylock(struct ec_mutex_t *mutex)
       
   332 {
       
   333     return rt_mutex_trylock(mutex);
       
   334 }
       
   335 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *mutex)
       
   336 {
       
   337     return rt_mutex_lock_interruptible(mutex,0);
       
   338 }
       
   339 static inline void ec_mutex_unlock(struct ec_mutex_t *mutex)
       
   340 {
       
   341     rt_mutex_unlock(mutex);
       
   342 }
       
   343 #else   // EC_USE_MUTEX
       
   344 #define ec_mutex_t semaphore
       
   345 static inline void ec_mutex_init(struct ec_mutex_t *sem)
       
   346 {
       
   347     sema_init(sem, 1);
       
   348 }
       
   349 static inline void ec_mutex_lock(struct ec_mutex_t *sem)
       
   350 {
       
   351     down(sem);
       
   352 }
       
   353 static inline int ec_mutex_trylock(struct ec_mutex_t *sem)
       
   354 {
       
   355     down(sem);
       
   356     return 1;
       
   357 }
       
   358 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *sem)
       
   359 {
       
   360     return down_interruptible(sem);
       
   361 }
       
   362 static inline void ec_mutex_unlock(struct ec_mutex_t *sem)
       
   363 {
       
   364     up(sem);
       
   365 }
       
   366 
       
   367 #endif // EC_USE_MUTEX
       
   368 #endif // __KERNEL__
       
   369 
   308 #endif
   370 #endif