X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Flibsigrok-internal.h;h=6a70e8b14f4fbc5c7974e22e2a0ec91057384525;hb=084d6b927163fb0881941ad13014e07a6a5e7a77;hp=a2350e02ddf3aed2c48c89bcab2ac8eb8f59dfae;hpb=e1a712ca268df9c179377cf5c48ece8b87ed0ed7;p=libsigrok.git diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index a2350e02..6a70e8b1 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -450,6 +450,19 @@ static inline void write_u16le(uint8_t *p, uint16_t x) } #define WL16(p, x) write_u16le((uint8_t *)(p), (uint16_t)(x)) +/** + * Write a 24 bits unsigned integer to memory stored as little endian. + * @param p a pointer to the output memory + * @param x the input unsigned integer + */ +static inline void write_u24le(uint8_t *p, uint32_t x) +{ + p[0] = x & 0xff; x >>= 8; + p[1] = x & 0xff; x >>= 8; + p[2] = x & 0xff; x >>= 8; +} +#define WL24(p, x) write_u24le((uint8_t *)(p), (uint32_t)(x)) + /** * Write a 32 bits unsigned integer to memory stored as big endian. * @param p a pointer to the output memory @@ -478,6 +491,21 @@ static inline void write_u32le(uint8_t *p, uint32_t x) } #define WL32(p, x) write_u32le((uint8_t *)(p), (uint32_t)(x)) +/** + * Write a 40 bits unsigned integer to memory stored as little endian. + * @param p a pointer to the output memory + * @param x the input unsigned integer + */ +static inline void write_u40le(uint8_t *p, uint64_t x) +{ + p[0] = x & 0xff; x >>= 8; + p[1] = x & 0xff; x >>= 8; + p[2] = x & 0xff; x >>= 8; + p[3] = x & 0xff; x >>= 8; + p[4] = x & 0xff; x >>= 8; +} +#define WL40(p, x) write_u40le((uint8_t *)(p), (uint64_t)(x)) + /** * Write a 48 bits unsigned integer to memory stored as little endian. * @param p a pointer to the output memory @@ -898,6 +926,19 @@ static inline void write_u16le_inc(uint8_t **p, uint16_t x) *p += sizeof(x); } +/** + * Write unsigned 24bit liggle endian integer to raw memory, increment write position. + * @param[in, out] p Pointer into byte stream. + * @param[in] x Value to write. + */ +static inline void write_u24le_inc(uint8_t **p, uint32_t x) +{ + if (!p || !*p) + return; + write_u24le(*p, x); + *p += 3 * sizeof(uint8_t); +} + /** * Write unsigned 32bit big endian integer to raw memory, increment write position. * @param[in, out] p Pointer into byte stream. @@ -924,6 +965,19 @@ static inline void write_u32le_inc(uint8_t **p, uint32_t x) *p += sizeof(x); } +/** + * Write unsigned 40bit little endian integer to raw memory, increment write position. + * @param[in, out] p Pointer into byte stream. + * @param[in] x Value to write. + */ +static inline void write_u40le_inc(uint8_t **p, uint64_t x) +{ + if (!p || !*p) + return; + write_u40le(*p, x); + *p += 5 * sizeof(uint8_t); +} + /** * Write unsigned 48bit little endian integer to raw memory, increment write position. * @param[in, out] p Pointer into byte stream.