summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2015-11-12 13:00:14 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-11-15 11:23:22 -0800
commit684d25b41aa77f14aae48afb5968a8aa1643c629 (patch)
tree9b5d637025eb3b02cc30d7f512f4782e75db4d5b
parent96b65354878587df434becfbc5d707a687c85fa4 (diff)
downloadchrome-ec-684d25b41aa77f14aae48afb5968a8aa1643c629.tar.gz
common: byte order conversion functions
Support for various communications protocols requires the ability to convert between big and little endian representation of integers. This patch moves integer converting functions into the common scope and uses the built in functions available in ARM architecture. Since all today's ec platforms are running in little endian mode, the functions being added assume that the host is little endian. BRANCH=none BUG=chrome-os-partner:43025 TEST=none yet Change-Id: I55ad0c5c3fe9f30cb4ed8ae807b1f5e4a54b8b35 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/312584 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--include/byteorder.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/byteorder.h b/include/byteorder.h
new file mode 100644
index 0000000000..e2e305537d
--- /dev/null
+++ b/include/byteorder.h
@@ -0,0 +1,38 @@
+/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __EC_INCLUDE_BYTEORDER_H
+#define __EC_INCLUDE_BYTEORDER_H
+
+#include <stdint.h>
+
+/*
+ * Functions to convert byte order in various sized big endian integers to
+ * host byte order. Note that the code currently does not require functions
+ * for converting little endian integers.
+ */
+#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+
+static inline uint16_t be16toh(uint16_t in)
+{
+ return __builtin_bswap16(in);
+}
+static inline uint32_t be32toh(uint32_t in)
+{
+ return __builtin_bswap32(in);
+}
+static inline uint64_t be64toh(uint64_t in)
+{
+ return __builtin_bswap64(in);
+}
+
+#define htobe16 be16toh
+#define htobe32 be32toh
+#define htobe64 be64toh
+
+#endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */
+
+
+#endif /* __EC_INCLUDE_BYTEORDER_H */