X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Flibsigrok-internal.h;h=1c37ee2752dec847768cbebeedc66f22c98d6459;hb=08f023fe97e402d68106299d04726f9094f00c45;hp=9111bc37cb07eeff729ef5b6271745e501599f64;hpb=4c29bba1f076dd70fc3b6ad2eb950a555b612c06;p=libsigrok.git diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 9111bc37..1c37ee27 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -475,6 +475,22 @@ 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 48 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_u48le(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; + p[5] = x & 0xff; x >>= 8; +} +#define WL48(p, x) write_u48le((uint8_t *)(p), (uint64_t)(x)) + /** * Write a 64 bits unsigned integer to memory stored as big endian. * @param p a pointer to the output memory @@ -905,6 +921,19 @@ static inline void write_u32le_inc(uint8_t **p, uint32_t x) *p += sizeof(x); } +/** + * Write unsigned 48bit 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_u48le_inc(uint8_t **p, uint64_t x) +{ + if (!p || !*p) + return; + write_u48le(*p, x); + *p += 48 / 8 * sizeof(uint8_t); +} + /** * Write unsigned 64bit little endian integer to raw memory, increment write position. * @param[in, out] p Pointer into byte stream.