From efce57da322cbe3d8c65332122ab3fb76e02089a Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Mon, 26 Oct 2020 19:48:22 +0100 Subject: [PATCH] libsigrok-internal.h: add u64be endianess writer Add endianess aware writer for uint64_t data in BE format. This is motivated by the Codethink Interrogizer. --- src/libsigrok-internal.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 9a672c7d..98d1631e 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -475,6 +475,23 @@ 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 64 bits unsigned integer to memory stored as big endian. + * @param p a pointer to the output memory + * @param x the input unsigned integer + */ +static inline void write_u64be(uint8_t *p, uint64_t x) +{ + p[7] = x & 0xff; x >>= 8; + p[6] = x & 0xff; x >>= 8; + p[5] = x & 0xff; x >>= 8; + p[4] = x & 0xff; x >>= 8; + p[3] = x & 0xff; x >>= 8; + p[2] = x & 0xff; x >>= 8; + p[1] = x & 0xff; x >>= 8; + p[0] = x & 0xff; x >>= 8; +} + /** * Write a 64 bits unsigned integer to memory stored as little endian. * @param p a pointer to the output memory -- 2.30.2