Skip to content

Commit

Permalink
libsigrok-internal.h: add u64be endianess writer
Browse files Browse the repository at this point in the history
Add endianess aware writer for uint64_t data in BE format. This is
motivated by the Codethink Interrogizer.
  • Loading branch information
gsigh committed Oct 26, 2020
1 parent 6bee394 commit efce57d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libsigrok-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit efce57d

Please sign in to comment.