From: Aurelien Jacobs Date: Sun, 22 Feb 2015 23:26:16 +0000 (+0100) Subject: libsigrok-internal.h: add helper macro to read floats from unaligend memory. X-Git-Tag: libsigrok-0.4.0~501 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=a2632bcafcba2c3d3ea08db44a497ad6d05f1c5f libsigrok-internal.h: add helper macro to read floats from unaligend memory. --- diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index b4b32f23..aff0fea6 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -113,6 +113,20 @@ ((unsigned)((const uint8_t*)(x))[1] << 8) | \ (unsigned)((const uint8_t*)(x))[0])) +/** + * Read a 32 bits big endian float out of memory. + * @param x a pointer to the input memory + * @return the corresponding float + */ +#define RBFL(x) ((union { uint32_t u; float f; }) { .u = RB32(x) }.f) + +/** + * Read a 32 bits little endian float out of memory. + * @param x a pointer to the input memory + * @return the corresponding float + */ +#define RLFL(x) ((union { uint32_t u; float f; }) { .u = RL32(x) }.f) + /** * Write a 8 bits unsigned integer to memory. * @param p a pointer to the output memory @@ -156,6 +170,20 @@ ((uint8_t*)(p))[2] = (uint8_t)((x)>>16); \ ((uint8_t*)(p))[3] = (uint8_t)((x)>>24); } while (0) +/** + * Write a 32 bits float to memory stored as big endian. + * @param p a pointer to the output memory + * @param x the input float + */ +#define WBFL(p, x) WB32(p, (union { uint32_t u; float f; }) { .f = x }.u) + +/** + * Write a 32 bits float to memory stored as little endian. + * @param p a pointer to the output memory + * @param x the input float + */ +#define WLFL(p, x) WL32(p, (union { uint32_t u; float f; }) { .f = x }.u) + /* Portability fixes for FreeBSD. */ #ifdef __FreeBSD__ #define LIBUSB_CLASS_APPLICATION 0xfe