summaryrefslogtreecommitdiff
path: root/components/drivers/include
diff options
context:
space:
mode:
Diffstat (limited to 'components/drivers/include')
-rw-r--r--components/drivers/include/drivers/byteorder.h58
-rwxr-xr-xcomponents/drivers/include/drivers/core/rtdm.h50
-rw-r--r--components/drivers/include/drivers/misc.h86
-rw-r--r--components/drivers/include/rtdevice.h4
4 files changed, 198 insertions, 0 deletions
diff --git a/components/drivers/include/drivers/byteorder.h b/components/drivers/include/drivers/byteorder.h
new file mode 100644
index 0000000000..30decb5440
--- /dev/null
+++ b/components/drivers/include/drivers/byteorder.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-02-25 GuEe-GUI the first version
+ */
+
+#ifndef __BYTEORDER__
+#define __BYTEORDER__
+
+#ifdef __CHECKER__
+#define __bitwise __attribute__((bitwise))
+#else
+#define __bitwise
+#endif
+
+typedef rt_uint16_t __bitwise rt_le16_t;
+typedef rt_uint32_t __bitwise rt_le32_t;
+typedef rt_uint64_t __bitwise rt_le64_t;
+typedef rt_uint16_t __bitwise rt_be16_t;
+typedef rt_uint32_t __bitwise rt_be32_t;
+typedef rt_uint64_t __bitwise rt_be64_t;
+
+/* gcc defines __BIG_ENDIAN__ on big endian targets */
+#if defined(__BIG_ENDIAN__) || defined(ARCH_CPU_BIG_ENDIAN)
+#define rt_cpu_to_be16(x) (x)
+#define rt_cpu_to_be32(x) (x)
+#define rt_cpu_to_be64(x) (x)
+#define rt_be16_to_cpu(x) (x)
+#define rt_be32_to_cpu(x) (x)
+#define rt_be64_to_cpu(x) (x)
+#define rt_le16_to_cpu(x) __builtin_bswap16(x)
+#define rt_le32_to_cpu(x) __builtin_bswap32(x)
+#define rt_le64_to_cpu(x) __builtin_bswap64(x)
+#define rt_cpu_to_le16(x) __builtin_bswap16(x)
+#define rt_cpu_to_le32(x) __builtin_bswap32(x)
+#define rt_cpu_to_le64(x) __builtin_bswap64(x)
+#else
+#define rt_cpu_to_be16(x) __builtin_bswap16(x)
+#define rt_cpu_to_be32(x) __builtin_bswap32(x)
+#define rt_cpu_to_be64(x) __builtin_bswap64(x)
+#define rt_be16_to_cpu(x) __builtin_bswap16(x)
+#define rt_be32_to_cpu(x) __builtin_bswap32(x)
+#define rt_be64_to_cpu(x) __builtin_bswap64(x)
+#define rt_le16_to_cpu(x) (x)
+#define rt_le32_to_cpu(x) (x)
+#define rt_le64_to_cpu(x) (x)
+#define rt_cpu_to_le16(x) (x)
+#define rt_cpu_to_le32(x) (x)
+#define rt_cpu_to_le64(x) (x)
+#endif /* __BIG_ENDIAN__ || ARCH_CPU_BIG_ENDIAN */
+
+#undef __bitwise
+
+#endif /* __BYTEORDER__ */
diff --git a/components/drivers/include/drivers/core/rtdm.h b/components/drivers/include/drivers/core/rtdm.h
new file mode 100755
index 0000000000..95d3c259b8
--- /dev/null
+++ b/components/drivers/include/drivers/core/rtdm.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-04-20 ErikChan the first version
+ */
+
+#ifndef __RT_DM_H__
+#define __RT_DM_H__
+
+#include <rthw.h>
+#include <rtdef.h>
+#include <drivers/misc.h>
+#include <drivers/byteorder.h>
+
+#ifndef RT_CPUS_NR
+#define RT_CPUS_NR 1
+#endif
+
+#ifndef RT_USING_SMP
+extern int rt_hw_cpu_id(void);
+#endif
+
+void rt_dm_secondary_cpu_init(void);
+
+int rt_dm_set_dev_name_auto(rt_device_t dev, const char *prefix);
+int rt_dm_get_dev_name_id(rt_device_t dev);
+
+int rt_dm_set_dev_name(rt_device_t dev, const char *format, ...);
+const char *rt_dm_get_dev_name(rt_device_t dev);
+
+/* init cpu, memory, interrupt-controller, bus... */
+#define INIT_CORE_EXPORT(fn) INIT_EXPORT(fn, "1.0")
+/* init pci/pcie, usb platform driver... */
+#define INIT_FRAMEWORK_EXPORT(fn) INIT_EXPORT(fn, "1.1")
+/* init platform, user code... */
+#define INIT_PLATFORM_EXPORT(fn) INIT_EXPORT(fn, "1.2")
+/* init sys-timer, clk, pinctrl... */
+#define INIT_SUBSYS_EXPORT(fn) INIT_EXPORT(fn, "1.3")
+/* init early drivers */
+#define INIT_DRIVER_EARLY_EXPORT(fn) INIT_EXPORT(fn, "1.4")
+/* init in secondary_cpu_c_start */
+#define INIT_SECONDARY_CPU_EXPORT(fn) INIT_EXPORT(fn, "7")
+/* init after mount fs */
+#define INIT_FS_EXPORT(fn) INIT_EXPORT(fn, "6.0")
+
+#endif /* __RT_DM_H__ */
diff --git a/components/drivers/include/drivers/misc.h b/components/drivers/include/drivers/misc.h
new file mode 100644
index 0000000000..aa2b715512
--- /dev/null
+++ b/components/drivers/include/drivers/misc.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-02-25 GuEe-GUI the first version
+ */
+
+#ifndef __MISC_H__
+#define __MISC_H__
+
+#include <rtdef.h>
+
+#ifdef ARCH_CPU_64BIT
+#define RT_BITS_PER_LONG 64
+#else
+#define RT_BITS_PER_LONG 32
+#endif
+#define RT_BITS_PER_LONG_LONG 64
+
+#define RT_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#define RT_DIV_ROUND_CLOSEST(x, divisor) \
+({ \
+ typeof(x) __x = x; \
+ typeof(divisor) __d = divisor; \
+ (((typeof(x))-1) > 0 || \
+ ((typeof(divisor))-1) > 0 || \
+ (((__x) > 0) == ((__d) > 0))) ? \
+ (((__x) + ((__d) / 2)) / (__d)) : \
+ (((__x) - ((__d) / 2)) / (__d)); \
+})
+
+#define RT_BIT(n) (1UL << (n))
+#define RT_BIT_ULL(n) (1ULL << (n))
+#define RT_BIT_MASK(nr) (1UL << ((nr) % RT_BITS_PER_LONG))
+#define RT_BIT_WORD(nr) ((nr) / RT_BITS_PER_LONG)
+
+#define RT_BITS_PER_BYTE 8
+#define RT_BITS_PER_TYPE(type) (sizeof(type) * RT_BITS_PER_BYTE)
+#define RT_BITS_TO_BYTES(nr) RT_DIV_ROUND_UP(nr, RT_BITS_PER_TYPE(char))
+#define RT_BITS_TO_LONGS(nr) RT_DIV_ROUND_UP(nr, RT_BITS_PER_TYPE(long))
+
+#define RT_GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (RT_BITS_PER_LONG - 1 - (h))))
+#define RT_GENMASK_ULL(h, l) (((~0ULL) << (l)) & (~0ULL >> (RT_BITS_PER_LONG_LONG - 1 - (h))))
+
+#define RT_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+
+#define rt_min(x, y) \
+({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x < _y ? _x : _y; \
+})
+
+#define rt_max(x, y) \
+({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x > _y ? _x : _y; \
+})
+
+#define rt_min_t(type, x, y) \
+({ \
+ type _x = (x); \
+ type _y = (y); \
+ _x < _y ? _x: _y; \
+})
+
+#define rt_clamp(val, lo, hi) rt_min((typeof(val))rt_max(val, lo), hi)
+
+#define rt_do_div(n, base) \
+({ \
+ rt_uint32_t _base = (base), _rem; \
+ _rem = ((rt_uint64_t)(n)) % _base; \
+ (n) = ((rt_uint64_t)(n)) / _base; \
+ if (_rem > _base / 2) \
+ ++(n); \
+ _rem; \
+})
+
+#endif /* __MISC_H__ */
diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h
index afce028b0e..60da08f8b1 100644
--- a/components/drivers/include/rtdevice.h
+++ b/components/drivers/include/rtdevice.h
@@ -169,6 +169,10 @@ extern "C" {
#include "drivers/lcd.h"
#endif
+#ifdef RT_USING_DM
+#include "drivers/core/rtdm.h"
+#endif /* RT_USING_DM */
+
#ifdef __cplusplus
}
#endif