summaryrefslogtreecommitdiff
path: root/components/drivers/include
diff options
context:
space:
mode:
authorShell <[email protected]>2024-04-09 21:36:16 +0800
committerGitHub <[email protected]>2024-04-09 21:36:16 +0800
commit4b0f42c24aad9c824fb98a3bb4c7cc2fd29b632a (patch)
treeacbfb3c1ef799a4e1d48947d435f44e11fa4cbdd /components/drivers/include
parent38204386b3c5db7412572adb75038badc4cef6d2 (diff)
[drivers/serial] Introduce hooker for TTY (#8733)
In this patch, a hook list has been introduced to address the concerns regarding coupling issues arising from modifications to the serial code for integrating TTY logic. Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'components/drivers/include')
-rw-r--r--components/drivers/include/drivers/serial.h9
-rw-r--r--components/drivers/include/drivers/serial_dm.h29
-rw-r--r--components/drivers/include/drivers/serial_v2.h8
3 files changed, 46 insertions, 0 deletions
diff --git a/components/drivers/include/drivers/serial.h b/components/drivers/include/drivers/serial.h
index b13c268a00..9438ed43f9 100644
--- a/components/drivers/include/drivers/serial.h
+++ b/components/drivers/include/drivers/serial.h
@@ -102,6 +102,14 @@
0 \
}
+/**
+ * @brief Sets a hook function when RX indicate is called
+ *
+ * @param thread is the target thread that initializing
+ */
+typedef void (*rt_hw_serial_rxind_hookproto_t)(rt_device_t dev, rt_size_t size);
+RT_OBJECT_HOOKLIST_DECLARE(rt_hw_serial_rxind_hookproto_t, rt_hw_serial_rxind);
+
struct serial_configure
{
rt_uint32_t baud_rate;
@@ -186,4 +194,5 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
void *data);
rt_err_t rt_hw_serial_register_tty(struct rt_serial_device *serial);
+
#endif
diff --git a/components/drivers/include/drivers/serial_dm.h b/components/drivers/include/drivers/serial_dm.h
new file mode 100644
index 0000000000..20792fc9eb
--- /dev/null
+++ b/components/drivers/include/drivers/serial_dm.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-11-16 GuEe-GUI first version
+ */
+
+#ifndef __SERIAL_DM_H__
+#define __SERIAL_DM_H__
+
+#include <rtthread.h>
+#include <rtdevice.h>
+#include <string.h>
+
+int serial_dev_set_name(struct rt_serial_device *sdev);
+
+void *serial_base_from_args(char *str);
+struct serial_configure serial_cfg_from_args(char *str);
+
+#define serial_for_each_args(arg, args) \
+ for (char *context = (arg = (typeof(arg))args, (void *)RT_NULL), \
+ *context_end = rt_strchrnul((char *)args, ' '); \
+ (arg = strtok_r(arg, ",", &context)) && arg < context_end; \
+ arg = RT_NULL)
+
+#endif /* __SERIAL_DM_H__ */
diff --git a/components/drivers/include/drivers/serial_v2.h b/components/drivers/include/drivers/serial_v2.h
index 399b3d0a59..d0dcf37813 100644
--- a/components/drivers/include/drivers/serial_v2.h
+++ b/components/drivers/include/drivers/serial_v2.h
@@ -103,6 +103,14 @@
0 \
}
+/**
+ * @brief Sets a hook function when RX indicate is called
+ *
+ * @param thread is the target thread that initializing
+ */
+typedef void (*rt_hw_serial_rxind_hookproto_t)(rt_device_t dev, rt_size_t size);
+RT_OBJECT_HOOKLIST_DECLARE(rt_hw_serial_rxind_hookproto_t, rt_hw_serial_rxind);
+
struct serial_configure
{
rt_uint32_t baud_rate;