master/globals.h
changeset 2068 3001f6523e63
parent 2037 ea0319750e13
child 2106 505871ced767
equal deleted inserted replaced
2067:19732da2cf86 2068:3001f6523e63
    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 
    41 
       
    42 #ifdef __KERNEL__
       
    43 #include <linux/version.h>
       
    44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
       
    45 #include <linux/rtmutex.h>
       
    46 #endif  // KERNEL_VERSION(2,6,24)
       
    47 #endif // __KERNEL__
       
    48 
       
    49 #ifdef CONFIG_TRACING
       
    50 //#define USE_TRACE_PRINTK
       
    51 #endif
       
    52 
    42 /******************************************************************************
    53 /******************************************************************************
    43  * EtherCAT master
    54  * EtherCAT master
    44  *****************************************************************************/
    55  *****************************************************************************/
    45 
    56 
    46 /** Datagram timeout in microseconds. */
    57 /** Datagram timeout in microseconds. */
    47 #define EC_IO_TIMEOUT 500
    58 #define EC_IO_TIMEOUT 500
    48 
    59 
    49 /** SDO injection timeout in microseconds. */
    60 /** FSM injection timeout in microseconds. */
    50 #define EC_SDO_INJECTION_TIMEOUT 10000
    61 #define EC_FSM_INJECTION_TIMEOUT 10000
    51 
    62 
    52 /** Time to send a byte in nanoseconds.
    63 /** Time to send a byte in nanoseconds.
    53  *
    64  *
    54  * t_ns = 1 / (100 MBit/s / 8 bit/byte) = 80 ns/byte
    65  * t_ns = 1 / (100 MBit/s / 8 bit/byte) = 80 ns/byte
    55  */
    66  */
    94 /** Mailbox header size.  */
   105 /** Mailbox header size.  */
    95 #define EC_MBOX_HEADER_SIZE 6
   106 #define EC_MBOX_HEADER_SIZE 6
    96 
   107 
    97 /** Word offset of first SII category. */
   108 /** Word offset of first SII category. */
    98 #define EC_FIRST_SII_CATEGORY_OFFSET 0x40
   109 #define EC_FIRST_SII_CATEGORY_OFFSET 0x40
    99 
       
   100 /** Maximum number of slave ports. */
       
   101 #define EC_MAX_PORTS 4
       
   102 
   110 
   103 /** Size of a sync manager configuration page. */
   111 /** Size of a sync manager configuration page. */
   104 #define EC_SYNC_PAGE_SIZE 8
   112 #define EC_SYNC_PAGE_SIZE 8
   105 
   113 
   106 /** Maximum number of FMMUs per slave. */
   114 /** Maximum number of FMMUs per slave. */
   171 typedef struct {
   179 typedef struct {
   172     uint8_t enable_safeop : 1; /**< ?. */
   180     uint8_t enable_safeop : 1; /**< ?. */
   173     uint8_t enable_not_lrw : 1; /**< Slave does not support LRW. */
   181     uint8_t enable_not_lrw : 1; /**< Slave does not support LRW. */
   174 } ec_sii_general_flags_t;
   182 } ec_sii_general_flags_t;
   175 
   183 
   176 /** EtherCAT slave port descriptor.
       
   177  */
       
   178 typedef enum {
       
   179     EC_PORT_NOT_IMPLEMENTED,
       
   180     EC_PORT_NOT_CONFIGURED,
       
   181     EC_PORT_EBUS,
       
   182     EC_PORT_MII
       
   183 } ec_slave_port_desc_t;
       
   184 
       
   185 /** EtherCAT slave port information.
       
   186  */
       
   187 typedef struct {
       
   188     uint8_t link_up; /**< Link detected. */
       
   189     uint8_t loop_closed; /**< Loop closed. */
       
   190     uint8_t signal_detected; /**< Detected signal on RX port. */
       
   191 } ec_slave_port_link_t;
       
   192 
       
   193 /** EtherCAT slave distributed clocks range.
   184 /** EtherCAT slave distributed clocks range.
   194  */
   185  */
   195 typedef enum {
   186 typedef enum {
   196     EC_DC_32, /**< 32 bit. */
   187     EC_DC_32, /**< 32 bit. */
   197     EC_DC_64 /*< 64 bit for system time, system time offset and
   188     EC_DC_64 /*< 64 bit for system time, system time offset and
   323 
   314 
   324 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */
   315 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */
   325 
   316 
   326 /*****************************************************************************/
   317 /*****************************************************************************/
   327 
   318 
       
   319 /*****************************************************************************/
       
   320 
       
   321 #ifdef __KERNEL__
       
   322 
       
   323 /** Mutual exclusion helpers.
       
   324  *
       
   325  */
       
   326 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
       
   327 #define ec_mutex_t rt_mutex
       
   328 static inline void ec_mutex_init(struct ec_mutex_t *mutex)
       
   329 {
       
   330     rt_mutex_init(mutex);
       
   331 }
       
   332 static inline void ec_mutex_lock(struct ec_mutex_t *mutex)
       
   333 {
       
   334     rt_mutex_lock(mutex);
       
   335 }
       
   336 static inline int ec_mutex_trylock(struct ec_mutex_t *mutex)
       
   337 {
       
   338     return rt_mutex_trylock(mutex);
       
   339 }
       
   340 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *mutex)
       
   341 {
       
   342     return rt_mutex_lock_interruptible(mutex,0);
       
   343 }
       
   344 static inline void ec_mutex_unlock(struct ec_mutex_t *mutex)
       
   345 {
       
   346     rt_mutex_unlock(mutex);
       
   347 }
       
   348 #else   // < KERNEL_VERSION(2,6,24)
       
   349 #define ec_mutex_t semaphore
       
   350 static inline void ec_mutex_init(struct ec_mutex_t *sem)
       
   351 {
       
   352     sema_init(sem, 1);
       
   353 }
       
   354 static inline void ec_mutex_lock(struct ec_mutex_t *sem)
       
   355 {
       
   356     down(sem);
       
   357 }
       
   358 static inline int ec_mutex_trylock(struct ec_mutex_t *sem)
       
   359 {
       
   360     down(sem);
       
   361     return 1;
       
   362 }
       
   363 static inline int ec_mutex_lock_interruptible(struct ec_mutex_t *sem)
       
   364 {
       
   365     return down_interruptible(sem);
       
   366 }
       
   367 static inline void ec_mutex_unlock(struct ec_mutex_t *sem)
       
   368 {
       
   369     up(sem);
       
   370 }
       
   371 
       
   372 #endif // KERNEL_VERSION(2,6,24)
       
   373 #endif // __KERNEL__
       
   374 
   328 #endif
   375 #endif