mcu_base/inc/global.h
2013-10-29 11:01:19 -04:00

49 lines
1.2 KiB
C

#ifndef __GLOBAL_H
#define __GLOBAL_H
#include <stdarg.h>
#include <stdint.h>
#include <sys/types.h>
/* Misc definitions */
#define MAC_ADDR_LEN 6
/* Endianness */
#define swab16(x) \
({ \
uint16_t __x = (x); \
((uint16_t)( \
(((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
(((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
})
#define swab32(x) \
({ \
uint32_t __x = (x); \
((uint32_t)( \
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
})
#ifdef __ARMEB__
#define htonl(x) (x)
#define ntohl(x) (x)
#define ntohs(x) (x)
#define htons(x) (x)
#endif
#ifdef __ARMEL__
#define htonl(x) swab32(x)
#define ntohl(x) swab32(x)
#define htons(x) swab16(x)
#define ntohs(x) swab16(x)
#endif
/* snprintf() and friends */
uint32_t parse_int(const char *src, int b, int width);
int mcu_vsnprintf(char *str, size_t size, const char *format, va_list ap);
int mcu_snprintf(char *str, size_t size, const char *format, ...);
#endif /* __GLOBAL_H */