zephyr: Make Zephyr int types deprecated by default
As the int types defined in include/zephyr/types.h are typdef's we
utilize a Kconfig option (LEGACY_ZEPHYR_INT_TYPES) to enable/disable
the support for them. By default to LEGACY_ZEPHYR_INT_TYPES not
being enabled and add an explicit test to ensure the types continue to
function until removed in the future.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
diff --git a/Kconfig.zephyr b/Kconfig.zephyr
index 4043e77..9821e20 100644
--- a/Kconfig.zephyr
+++ b/Kconfig.zephyr
@@ -363,6 +363,12 @@
Zephyr 2.2 and previous versions, rather than the devicetree.h
API introduced during the Zephyr 2.3 development cycle.
+config LEGACY_ZEPHYR_INT_TYPES
+ bool "Allow the use of the legacy zephyr integer types"
+ help
+ Allows the use of the legacy Zephyr integer typedefs defined in
+ Zephyr 2.3 and previous versions.
+
endmenu
endmenu
diff --git a/include/zephyr/types.h b/include/zephyr/types.h
index e875a35..bd97c8e 100644
--- a/include/zephyr/types.h
+++ b/include/zephyr/types.h
@@ -13,6 +13,8 @@
extern "C" {
#endif
+#ifdef CONFIG_LEGACY_ZEPHYR_INT_TYPES
+
typedef signed char s8_t;
typedef signed short s16_t;
typedef signed int s32_t;
@@ -23,6 +25,8 @@
typedef unsigned int u32_t;
typedef unsigned long long u64_t;
+#endif
+
/* 32 bits on ILP32 builds, 64 bits on LP64 builts */
typedef unsigned long ulong_t;
diff --git a/tests/deprecated/inttype/CMakeLists.txt b/tests/deprecated/inttype/CMakeLists.txt
new file mode 100644
index 0000000..30b8735
--- /dev/null
+++ b/tests/deprecated/inttype/CMakeLists.txt
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: Apache-2.0
+
+cmake_minimum_required(VERSION 3.13.1)
+
+find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
+project(test_inttypes)
+
+target_sources(app PRIVATE src/main.c)
diff --git a/tests/deprecated/inttype/prj.conf b/tests/deprecated/inttype/prj.conf
new file mode 100644
index 0000000..b230bb0
--- /dev/null
+++ b/tests/deprecated/inttype/prj.conf
@@ -0,0 +1 @@
+CONFIG_LEGACY_ZEPHYR_INT_TYPES=y
diff --git a/tests/deprecated/inttype/src/main.c b/tests/deprecated/inttype/src/main.c
new file mode 100644
index 0000000..74bc769
--- /dev/null
+++ b/tests/deprecated/inttype/src/main.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2020 Linaro
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr.h>
+
+void main(void)
+{
+ BUILD_ASSERT(sizeof(u8_t) == 1, "sizeof u8_t mismatch");
+ BUILD_ASSERT(sizeof(u16_t) == 2, "sizeof u16_t mismatch");
+ BUILD_ASSERT(sizeof(u32_t) == 4, "sizeof u32_t mismatch");
+ BUILD_ASSERT(sizeof(u64_t) == 8, "sizeof u64_t mismatch");
+
+ BUILD_ASSERT(sizeof(s8_t) == 1, "sizeof s8_t mismatch");
+ BUILD_ASSERT(sizeof(s16_t) == 2, "sizeof s16_t mismatch");
+ BUILD_ASSERT(sizeof(s32_t) == 4, "sizeof s32_t mismatch");
+ BUILD_ASSERT(sizeof(s64_t) == 8, "sizeof s64_t mismatch");
+}
diff --git a/tests/deprecated/inttype/testcase.yaml b/tests/deprecated/inttype/testcase.yaml
new file mode 100644
index 0000000..707f791
--- /dev/null
+++ b/tests/deprecated/inttype/testcase.yaml
@@ -0,0 +1,4 @@
+tests:
+ deprecated.inttypes:
+ build_only: true
+ tags: deprecated