diff -r f98f89d0d778 -r c9308eb34c0e include/ecrt.h --- a/include/ecrt.h Fri Jul 10 09:38:37 2009 +0000 +++ b/include/ecrt.h Fri Jul 10 10:07:48 2009 +0000 @@ -47,6 +47,10 @@ * ecrt_master_sync_reference_clock() and ecrt_master_sync_slave_clocks() * for offset and drift compensation. The EC_TIMEVAL2NANO() macro can be * used for epoch time conversion. + * - Added ecrt_open_master() and ecrt_master_reserve() separation for + * userspace. + * - Added ecrt_master() userspace interface, to get information about a + * master. * - Changed the meaning of the negative return values of * ecrt_slave_config_reg_pdo_entry() and ecrt_slave_config_sdo*(). * - Imlemented the Vendor-specific over EtherCAT mailbox protocol. See @@ -192,6 +196,22 @@ /*****************************************************************************/ +#ifndef __KERNEL__ + +/** Master information. + * + * This is used as an output parameter of ecrt_master(). + * + * \see ecrt_master(). + */ +typedef struct { + unsigned int slave_count; /**< Number of slaves in the bus. */ + unsigned int link_up : 1; /**< \a true, if the network link is up. */ + uint64_t app_time; /**< Application time. */ +} ec_master_info_t; + +/*****************************************************************************/ + /** Slave information. * * This is used as an output parameter of ecrt_master_slave(). @@ -213,6 +233,8 @@ char name[EC_MAX_STRING_LENGTH]; /**< Name of the slave. */ } ec_slave_info_t; +#endif // #ifndef __KERNEL__ + /*****************************************************************************/ /** Domain working counter interpretation. @@ -354,6 +376,9 @@ * Before an application can access an EtherCAT master, it has to reserve one * for exclusive use. * + * In userspace, this is a convenience function for ecrt_open_master() and + * ecrt_master_reserve(). + * * This function has to be the first function an application has to call to * use EtherCAT. The function takes the index of the master as its argument. * The first master has index 0, the n-th master has index n - 1. The number @@ -365,6 +390,25 @@ unsigned int master_index /**< Index of the master to request. */ ); +#ifndef __KERNEL__ + +/** Opens an EtherCAT master for userspace access. + * + * This function has to be the first function an application has to call to + * use EtherCAT. The function takes the index of the master as its argument. + * The first master has index 0, the n-th master has index n - 1. The number + * of masters has to be specified when loading the master module. + * + * For convenience, the function ecrt_request_master() can be used. + * + * \return Pointer to the opened master, otherwise \a NULL. + */ +ec_master_t *ecrt_open_master( + unsigned int master_index /**< Index of the master to request. */ + ); + +#endif // #ifndef __KERNEL__ + /** Releases a requested EtherCAT master. * * After use, a master it has to be released to make it available for other @@ -378,6 +422,22 @@ * Master methods *****************************************************************************/ +#ifndef __KERNEL__ + +/** Reserves an EtherCAT master for realtime operation. + * + * Before an application can use PDO/domain registration functions or SDO + * request functions on the master, it has to reserve one for exclusive use. + * + * \return 0 in case of success, else < 0 + * + */ +int ecrt_master_reserve( + ec_master_t *master /**< EtherCAT master */ + ); + +#endif // #ifndef __KERNEL__ + #ifdef __KERNEL__ /** Sets the locking callbacks. @@ -451,6 +511,21 @@ #ifndef __KERNEL__ +/** Obtains master information. + * + * No memory is allocated on the heap in + * this function. + * + * \attention The pointer to this structure must point to a valid variable. + * + * \return 0 in case of success, else < 0 + */ +int ecrt_master( + ec_master_t *master, /**< EtherCAT master */ + ec_master_info_t *master_info /**< Structure that will output the + information */ + ); + /** Obtains slave information. * * Tries to find the slave with the given ring position. The obtained @@ -468,7 +543,7 @@ information */ ); -#endif /* ifndef __KERNEL__ */ +#endif /* #ifndef __KERNEL__ */ /** Finishes the configuration phase and prepares for cyclic operation. * @@ -603,7 +678,7 @@ uint32_t *abort_code /**< Abort code of the SDO upload. */ ); -#endif /* ifndef __KERNEL__ */ +#endif /* #ifndef __KERNEL__ */ /****************************************************************************** * Slave configuration methods