X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fcfg%2Fmacros.h;h=4af10246f2ad6e646a44f242259cf8d920b12b3e;hb=refs%2Fheads%2Fmaster;hp=6c9b63ef0001b0877a0086a162f83b312cc7f10d;hpb=12d76a7eda50f3ca970b39806ea68e207a1b4495;p=bertos.git diff --git a/bertos/cfg/macros.h b/bertos/cfg/macros.h index 6c9b63ef..4af10246 100644 --- a/bertos/cfg/macros.h +++ b/bertos/cfg/macros.h @@ -250,6 +250,9 @@ /** Check if \a x is an integer power of 2. */ #define IS_POW2(x) (!(bool)((x) & ((x)-1))) +/** Check if \a x is aligned to \a byte_count bytes */ +#define IS_ALIGNED(x, byte_count) ((uintptr_t)(const void *)(x) % (byte_count) == 0) + /** Calculate a compile-time log2 for a uint8_t */ #define UINT8_LOG2(x) \ ((x) < 2 ? 0 : \ @@ -443,5 +446,22 @@ INLINE bool is_aligned(const void *addr, size_t size) /** \} */ //defgroup macros + +/** + * Macro to unpack the ip addres from lwip format in 4 int + * \param addr is struct ip_addr ip_addr; + * \return for int variable separated from comma + * + * \code + * //Upack into 4 int the lwip ip address + * LOG_INFO("dhcp ok: ip = %d.%d.%d.%d\n", IP_ADDR_TO_INT_TUPLE(netif.ip_addr.addr)); + * \endcode + */ +#define IP_ADDR_TO_INT_TUPLE(addr) \ + (int)((addr) >> 0 & 0xff), \ + (int)((addr) >> 8 & 0xff), \ + (int)((addr) >> 16 & 0xff), \ + (int)((addr) >> 24 & 0xff) + #endif /* MACROS_H */