From: bernie Date: Tue, 20 Jul 2004 16:26:15 +0000 (+0000) Subject: Import byte-order macros into DevLib. X-Git-Tag: 1.0.0~1179 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=aaed3ed803ffbd77b476d71055388cf00232469a;p=bertos.git Import byte-order macros into DevLib. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@62 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/mware/byteorder.h b/mware/byteorder.h new file mode 100755 index 00000000..cf7d1374 --- /dev/null +++ b/mware/byteorder.h @@ -0,0 +1,47 @@ +/*! + * \file + * + * + * \brief Functions to convert integers to/from host byte-order. + * + * \version $Id$ + * + * \author Bernardo Innocenti + * \author Stefano Fedrigo + */ + +/* + * $Log$ + * Revision 1.1 2004/07/20 16:26:15 bernie + * Import byte-order macros into DevLib. + * + */ + +#ifndef MWARE_BYTEORDER_H +#define MWARE_BYTEORDER_H + +#include +#include + +INLINE uint16_t cpu_to_be16(uint16_t n); +INLINE uint16_t cpu_to_be16(uint16_t n) +{ + if (CPU_BYTE_ORDER == CPU_LITTLE_ENDIAN) + n = n << 8 | n >> 8; + + return n; +} + +INLINE uint16_t cpu_to_le16(uint16_t n); +INLINE uint16_t cpu_to_le16(uint16_t n) +{ + if (CPU_BYTE_ORDER == CPU_BIG_ENDIAN) + n = n << 8 | n >> 8; + + return n; +} + +#endif /* MWARE_BYTEORDER_H */