]> sigrok.org Git - libsigrok.git/blobdiff - src/libsigrok-internal.h
libsigrok-internal.h: add 48bit endianess aware byte stream helpers
[libsigrok.git] / src / libsigrok-internal.h
index 9111bc37cb07eeff729ef5b6271745e501599f64..1c37ee2752dec847768cbebeedc66f22c98d6459 100644 (file)
@@ -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.