mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-09-27 20:44:00 +08:00
Added floating-point access functions and macros for user-space.
This commit is contained in:
@@ -2202,6 +2202,42 @@ void ecrt_reg_request_read(
|
|||||||
#define EC_READ_S64(DATA) \
|
#define EC_READ_S64(DATA) \
|
||||||
((int64_t) le64_to_cpup((void *) (DATA)))
|
((int64_t) le64_to_cpup((void *) (DATA)))
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Floating-point read functions and macros (userspace only)
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __KERNEL__
|
||||||
|
|
||||||
|
/** Read a 32-bit floating-point value from EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param data EtherCAT data pointer
|
||||||
|
* \return EtherCAT data value
|
||||||
|
*/
|
||||||
|
float ecrt_read_real(void *data);
|
||||||
|
|
||||||
|
/** Read a 32-bit floating-point value from EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param DATA EtherCAT data pointer
|
||||||
|
* \return EtherCAT data value
|
||||||
|
*/
|
||||||
|
#define EC_READ_REAL(DATA) ecrt_read_real(DATA)
|
||||||
|
|
||||||
|
/** Read a 64-bit floating-point value from EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param data EtherCAT data pointer
|
||||||
|
* \return EtherCAT data value
|
||||||
|
*/
|
||||||
|
double ecrt_read_lreal(void *data);
|
||||||
|
|
||||||
|
/** Read a 64-bit floating-point value from EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param DATA EtherCAT data pointer
|
||||||
|
* \return EtherCAT data value
|
||||||
|
*/
|
||||||
|
#define EC_READ_LREAL(DATA) ecrt_read_lreal(DATA)
|
||||||
|
|
||||||
|
#endif // ifndef __KERNEL__
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Write macros
|
* Write macros
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
@@ -2274,6 +2310,42 @@ void ecrt_reg_request_read(
|
|||||||
*/
|
*/
|
||||||
#define EC_WRITE_S64(DATA, VAL) EC_WRITE_U64(DATA, VAL)
|
#define EC_WRITE_S64(DATA, VAL) EC_WRITE_U64(DATA, VAL)
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Floating-point write functions and macros (userspace only)
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __KERNEL__
|
||||||
|
|
||||||
|
/** Write a 32-bit floating-point value to EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param data EtherCAT data pointer
|
||||||
|
* \param value new value
|
||||||
|
*/
|
||||||
|
void ecrt_write_real(void *data, float value);
|
||||||
|
|
||||||
|
/** Write a 32-bit floating-point value to EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param DATA EtherCAT data pointer
|
||||||
|
* \param VAL new value
|
||||||
|
*/
|
||||||
|
#define EC_WRITE_REAL(DATA, VAL) ecrt_write_real(DATA, VAL)
|
||||||
|
|
||||||
|
/** Write a 64-bit floating-point value to EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param data EtherCAT data pointer
|
||||||
|
* \param value new value
|
||||||
|
*/
|
||||||
|
void ecrt_write_lreal(void *data, double value);
|
||||||
|
|
||||||
|
/** Write a 64-bit floating-point value to EtherCAT data.
|
||||||
|
*
|
||||||
|
* \param DATA EtherCAT data pointer
|
||||||
|
* \param VAL new value
|
||||||
|
*/
|
||||||
|
#define EC_WRITE_LREAL(DATA, VAL) ecrt_write_lreal(DATA, VAL)
|
||||||
|
|
||||||
|
#endif // ifndef __KERNEL__
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
@@ -137,3 +137,33 @@ void ecrt_release_master(ec_master_t *master)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
float ecrt_read_real(void *data)
|
||||||
|
{
|
||||||
|
uint32_t raw = EC_READ_U32(data);
|
||||||
|
return *(float *) (const void *) &raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
double ecrt_read_lreal(void *data)
|
||||||
|
{
|
||||||
|
uint64_t raw = EC_READ_U64(data);
|
||||||
|
return *(double *) (const void *) &raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void ecrt_write_real(void *data, float value)
|
||||||
|
{
|
||||||
|
*(uint32_t *) data = cpu_to_le32(*(uint32_t *) (void *) &value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void ecrt_write_lreal(void *data, double value)
|
||||||
|
{
|
||||||
|
*(uint64_t *) data = cpu_to_le64(*(uint64_t *) (void *) &value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user