]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Add drv/endian.h
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 29 Aug 2015 11:02:37 +0000 (13:02 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 3 Sep 2015 08:22:11 +0000 (10:22 +0200)
rpp/include/drv/.gitattributes
rpp/include/drv/endian.h [new file with mode: 0644]

index 38f649a2cb2e9e62659ade90c994f0a273238205..401e4d60e6b27741b46868254e1385b7c8727b70 100644 (file)
@@ -1,7 +1,7 @@
-/adc.h eaton
 /Std_Types.h   eaton
 /adc.h eaton
 /drv.h eaton
+/endian.h      eaton
 /gio.h eaton
 /gio_def.h     eaton
 /gio_names.h   eaton
diff --git a/rpp/include/drv/endian.h b/rpp/include/drv/endian.h
new file mode 100644 (file)
index 0000000..0f6fbf5
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
+ *
+ */
+
+#ifndef _ENDIAN_H
+#define _ENDIAN_H
+
+#include "types.h"
+
+#if defined(__TI_COMPILER_VERSION__)
+#if defined(__big_endian__) && !defined(__little_endian__)
+#define RPP_BIG_ENDIAN 1
+#endif
+#if defined(__little_endian__) && !defined(__big_endian__)
+#define RPP_LITTLE_ENDIAN 1
+#endif
+#endif
+
+#if defined(__GNUC__) && !defined(__TI_COMPILER_VERSION__)
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define RPP_BIG_ENDIAN 1
+#endif
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define RPP_LITTLE_ENDIAN 1
+#endif
+#endif
+
+#if defined(RPP_BIG_ENDIAN) && !defined(RPP_LITTLE_ENDIAN)
+
+static inline uint16_t cpu_to_le16(uint16_t x) { return __rev16(x); }
+static inline uint16_t cpu_to_be16(uint16_t x) { return x; }
+static inline uint32_t cpu_to_le32(uint32_t x) { return __rev(x); }
+static inline uint32_t cpu_to_be32(uint32_t x) { return x; }
+
+static inline uint16_t le16_to_cpu(uint16_t x) { return __rev16(x); }
+static inline uint16_t be16_to_cpu(uint16_t x) { return x; }
+static inline uint32_t le32_to_cpu(uint32_t x) { return __rev(x); }
+static inline uint32_t be32_to_cpu(uint32_t x) { return x; }
+
+#elif defined(RPP_LITTLE_ENDIAN) && !defined(RPP_BIG_ENDIAN)
+
+static inline uint16_t cpu_to_be16(uint16_t x) { return __rev16(x); }
+static inline uint16_t cpu_to_le16(uint16_t x) { return x; }
+static inline uint32_t cpu_to_be32(uint32_t x) { return __rev(x); }
+static inline uint32_t cpu_to_le32(uint32_t x) { return x; }
+
+static inline uint16_t be16_to_cpu(uint16_t x) { return __rev16(x); }
+static inline uint16_t le16_to_cpu(uint16_t x) { return x; }
+static inline uint32_t be32_to_cpu(uint32_t x) { return __rev(x); }
+static inline uint32_t le32_to_cpu(uint32_t x) { return x; }
+
+#else
+#error Unknown endian
+#endif /* endian */
+
+#endif