Skip to content

Commit

Permalink
sys: byteorder: Add support for sys_get_be64()
Browse files Browse the repository at this point in the history
There is sys_get_le64() already but nothing for 64-bit
big-endian version.

Fixes zephyrproject-rtos#18258

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information
jukkar committed Aug 14, 2019
1 parent f77ede8 commit 62e15f3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/sys/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ static inline u32_t sys_get_be32(const u8_t src[4])
return ((u32_t)sys_get_be16(&src[0]) << 16) | sys_get_be16(&src[2]);
}

/**
* @brief Get a 64-bit integer stored in big-endian format.
*
* Get a 64-bit integer, stored in big-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the big-endian 64-bit integer to get.
*
* @return 64-bit integer in host endianness.
*/
static inline u64_t sys_get_be64(const u8_t src[8])
{
return ((u64_t)sys_get_be32(&src[0]) << 32) | sys_get_be32(&src[4]);
}

/**
* @brief Get a 16-bit integer stored in little-endian format.
*
Expand Down

0 comments on commit 62e15f3

Please sign in to comment.