From 78825ed789baedb74de4ef80f567804bbef6a72a Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 27 Aug 2019 18:15:34 +0300 Subject: [PATCH] sys: byteorder: Add support for sys_put_be64() There is sys_get_be64() but nothing for storing a 64-bit big-endian version. Signed-off-by: Jukka Rissanen --- include/sys/byteorder.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/sys/byteorder.h b/include/sys/byteorder.h index 3f9a3a21498..d98c16bc4bc 100644 --- a/include/sys/byteorder.h +++ b/include/sys/byteorder.h @@ -154,6 +154,21 @@ static inline void sys_put_be32(u32_t val, u8_t dst[4]) sys_put_be16(val, &dst[2]); } +/** + * @brief Put a 64-bit integer as big-endian to arbitrary location. + * + * Put a 64-bit integer, originally in host endianness, to a + * potentially unaligned memory location in big-endian format. + * + * @param val 64-bit integer in host endianness. + * @param dst Destination memory address to store the result. + */ +static inline void sys_put_be64(u64_t val, u8_t dst[8]) +{ + sys_put_be32(val >> 32, dst); + sys_put_be32(val, &dst[4]); +} + /** * @brief Put a 16-bit integer as little-endian to arbitrary location. *