Skip to content

Commit

Permalink
Bluetooth: byteorder.h: Add big-endian macros
Browse files Browse the repository at this point in the history
This patch contains big-endian version of the macros present in that
file. The new code is formatted by clang-format, which is why the
formatting is different.

(cherry picked from commit a8a000d)

Original-Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
GitOrigin-RevId: a8a000d
Cr-Build-Id: 8739091610579900001
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8739091610579900001
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I00561c2fccfdc5397a6e0488c8822f10394b8101
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5800147
Reviewed-by: Eric Yilun Lin <yllin@google.com>
Commit-Queue: Eric Yilun Lin <yllin@google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
  • Loading branch information
alwa-nordic authored and Chromeos LUCI committed Aug 21, 2024
1 parent 4363e5f commit aa363d0
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions include/zephyr/bluetooth/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,78 @@ extern "C" {
BT_BYTES_LIST_LE32(_v), \
BT_BYTES_LIST_LE32((_v) >> 32) \

/** @brief Encode 16-bit value into array values in big-endian format.
*
* Helper macro to encode 16-bit values into comma separated values.
*
* @note @p _v is evaluated 2 times.
*
* @param _v 16-bit integer in host endianness.
*
* @return The comma separated values for the 16-bit value.
*/
#define BT_BYTES_LIST_BE16(_v) (((_v) >> 8) & 0xFFU), (((_v) >> 0) & 0xFFU)

/** @brief Encode 24-bit value into array values in big-endian format.
*
* Helper macro to encode 24-bit values into comma separated values.
*
* @note @p _v is evaluated 3 times.
*
* @param _v 24-bit integer in host endianness.
*
* @return The comma separated values for the 24-bit value.
*/
#define BT_BYTES_LIST_BE24(_v) (((_v) >> 16) & 0xFFU), BT_BYTES_LIST_BE16(_v)

/** @brief Encode 32-bit value into array values in big-endian format.
*
* Helper macro to encode 32-bit values into comma separated values.
*
* @note @p _v is evaluated 4 times.
*
* @param _v 32-bit integer in host endianness.
*
* @return The comma separated values for the 32-bit value.
*/
#define BT_BYTES_LIST_BE32(_v) (((_v) >> 24) & 0xFFU), BT_BYTES_LIST_BE24(_v)

/** @brief Encode 40-bit value into array values in big-endian format.
*
* Helper macro to encode 40-bit values into comma separated values.
*
* @note @p _v is evaluated 5 times.
*
* @param _v 40-bit integer in host endianness.
*
* @return The comma separated values for the 40-bit value.
*/
#define BT_BYTES_LIST_BE40(_v) BT_BYTES_LIST_BE16((_v) >> 24), BT_BYTES_LIST_BE24(_v)

/** @brief Encode 48-bit value into array values in big-endian format.
*
* Helper macro to encode 48-bit values into comma separated values.
*
* @note @p _v is evaluated 6 times.
*
* @param _v 48-bit integer in host endianness.
*
* @return The comma separated values for the 48-bit value.
*/
#define BT_BYTES_LIST_BE48(_v) BT_BYTES_LIST_BE16((_v) >> 32), BT_BYTES_LIST_BE32(_v)

/** @brief Encode 64-bit value into array values in big-endian format.
*
* Helper macro to encode 64-bit values into comma separated values.
*
* @note @p _v is evaluated 8 times.
*
* @param _v 64-bit integer in host endianness.
*
* @return The comma separated values for the 64-bit value.
*/
#define BT_BYTES_LIST_BE64(_v) BT_BYTES_LIST_BE32((_v) >> 32), BT_BYTES_LIST_BE32(_v)

/**
* @}
*/
Expand Down

0 comments on commit aa363d0

Please sign in to comment.