mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-02-06 03:41:52 +08:00
Added floating-point access functions and macros for user-space.
This commit is contained in:
@@ -2189,6 +2189,42 @@ void ecrt_reg_request_read(
|
||||
#define EC_READ_S64(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
|
||||
*****************************************************************************/
|
||||
@@ -2261,6 +2297,42 @@ void ecrt_reg_request_read(
|
||||
*/
|
||||
#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__
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** @} */
|
||||
|
||||
30
lib/common.c
30
lib/common.c
@@ -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