Import byte-order macros into DevLib.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 20 Jul 2004 16:26:15 +0000 (16:26 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 20 Jul 2004 16:26:15 +0000 (16:26 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@62 38d2e660-2303-0410-9eaa-f027e97ec537

mware/byteorder.h [new file with mode: 0755]

diff --git a/mware/byteorder.h b/mware/byteorder.h
new file mode 100755 (executable)
index 0000000..cf7d137
--- /dev/null
@@ -0,0 +1,47 @@
+/*!
+ * \file
+ * <!--
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * This file is part of DevLib - See devlib/README for information.
+ * -->
+ *
+ * \brief Functions to convert integers to/from host byte-order.
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ * \author Stefano Fedrigo <aleph@develer.com>
+ */
+
+/*
+ * $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 <compiler.h>
+#include <cpu.h>
+
+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 */