From aaed3ed803ffbd77b476d71055388cf00232469a Mon Sep 17 00:00:00 2001 From: bernie Date: Tue, 20 Jul 2004 16:26:15 +0000 Subject: [PATCH] Import byte-order macros into DevLib. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@62 38d2e660-2303-0410-9eaa-f027e97ec537 --- mware/byteorder.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 mware/byteorder.h 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 */ -- 2.25.1