From d5e3a4bb2d23cd9a09ec3bc1c4bb18529d599b9e Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Wed, 24 May 2017 14:37:55 +0200 Subject: [PATCH] Add the ntoh* and hton* functions to the utils lib. --- include/lib/utils.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 */ -- 2.43.0