From: Nathael Pajani Date: Wed, 24 May 2017 12:37:55 +0000 (+0200) Subject: Add the ntoh* and hton* functions to the utils lib. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=d5e3a4bb2d23cd9a09ec3bc1c4bb18529d599b9e;p=soft%2Flpc82x%2Fcore Add the ntoh* and hton* functions to the utils lib. --- diff --git a/include/lib/utils.h b/include/lib/utils.h index e8ffac2..b4406a3 100644 --- a/include/lib/utils.h +++ b/include/lib/utils.h @@ -54,5 +54,22 @@ uint8_t ctz(uint32_t x); 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"))); + + +/* MIN and MAX */ +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + + + #endif /* LIB_UTILS_H */