libsigrok-internal.h: add helper macro to read floats from unaligend memory.

This commit is contained in:
Aurelien Jacobs 2015-02-23 00:26:16 +01:00 committed by Uwe Hermann
parent 7a0b98b544
commit a2632bcafc
1 changed files with 28 additions and 0 deletions

View File

@ -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