From: Nathael Pajani Date: Fri, 28 Oct 2016 01:20:50 +0000 (+0200) Subject: Add ntohl, htonl, ntohs and htons to lib/utils.h X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=af7b17d60fb789b4160e8ce45d2b197b51f79350;p=soft%2Flpc122x%2Fcore Add ntohl, htonl, ntohs and htons to lib/utils.h --- diff --git a/include/lib/utils.h b/include/lib/utils.h index e8ffac2..5062d1c 100644 --- a/include/lib/utils.h +++ b/include/lib/utils.h @@ -26,6 +26,7 @@ /***************************************************************************** */ #include "lib/stdint.h" +#include "core/lpc_core.h" /***************************************************************************** */ @@ -48,11 +49,19 @@ uint8_t clz(uint32_t x); */ uint8_t ctz(uint32_t x); -/* - * Count bits set +/* Count bits set */ uint8_t bits_set(uint32_t x); + +/* Network to host and host to network. + * LPC1224 is a little endian platform, we need to change endianness (reverse byte order) + */ +static inline uint32_t ntohl(uint32_t val) __attribute__ ((alias ("byte_swap_32"))); +static inline uint32_t htonl(uint32_t val) __attribute__ ((alias ("byte_swap_32"))); +/* Short versions */ +static inline uint32_t ntohs(uint32_t val) __attribute__ ((alias ("byte_swap_16"))); +static inline uint32_t htons(uint32_t val) __attribute__ ((alias ("byte_swap_16"))); #endif /* LIB_UTILS_H */