byteorder: Add macros for 32bits values

As for 16 bits integers, let's add utility byteordering macros for 32
bits integers.

Change-Id: I3113b9890992e4335d300a17738e5bb772b719ae
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2015-04-29 11:54:43 +03:00 committed by Anas Nashif
commit 03d4fc2e2f

View file

@ -33,10 +33,16 @@
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define sys_le16_to_cpu(val) (val)
#define sys_cpu_to_le16(val) (val)
#define sys_le32_to_cpu(val) (val)
#define sys_cpu_to_le32(val) (val)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define bswap_16(x) ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
#define sys_le16_to_cpu(val) bswap_16(val)
#define sys_cpu_to_le16(val) bswap_16(val)
#define bswap_32(x) ((uint32_t) ((((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) \
| (((x) & 0xff00) << 8) | (((x) & 0xff) << 24)))
#define sys_le32_to_cpu(val) bswap_32(val)
#define sys_cpu_to_le32(val) bswap_32(val)
#else
#error "Unknown byte order"
#endif