summaryrefslogtreecommitdiff
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
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]>
-rw-r--r--components/drivers/include/drivers/serial.h9
-rw-r--r--components/drivers/include/drivers/serial_dm.h (renamed from components/drivers/serial/serial_dm.h)0
-rw-r--r--components/drivers/include/drivers/serial_v2.h8
-rw-r--r--components/drivers/ofw/ofw.c2
-rw-r--r--components/drivers/serial/serial.c17
-rw-r--r--components/drivers/serial/serial_dm.c5
-rw-r--r--components/drivers/serial/serial_tty.c33
-rw-r--r--components/drivers/serial/serial_v2.c4
-rw-r--r--components/lwp/Kconfig9
-rw-r--r--components/lwp/lwp.c4
-rw-r--r--include/rtdef.h34
11 files changed, 90 insertions, 35 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/serial/serial_dm.h b/components/drivers/include/drivers/serial_dm.h
index 20792fc9eb..20792fc9eb 100644
--- a/components/drivers/serial/serial_dm.h
+++ b/components/drivers/include/drivers/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;
diff --git a/components/drivers/ofw/ofw.c b/components/drivers/ofw/ofw.c
index 23e03072e9..1f30bd98f9 100644
--- a/components/drivers/ofw/ofw.c
+++ b/components/drivers/ofw/ofw.c
@@ -12,7 +12,7 @@
#include <rtdevice.h>
#include <drivers/platform.h>
#include <drivers/core/bus.h>
-#include "../serial/serial_dm.h"
+#include <drivers/serial_dm.h>
#define DBG_TAG "rtdm.ofw"
#define DBG_LVL DBG_INFO
diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c
index 8c554d303f..fef049ae03 100644
--- a/components/drivers/serial/serial.c
+++ b/components/drivers/serial/serial.c
@@ -57,10 +57,14 @@
#undef putc
#endif
+RT_OBJECT_HOOKLIST_DEFINE(rt_hw_serial_rxind);
+
static rt_err_t serial_fops_rx_ind(rt_device_t dev, rt_size_t size)
{
rt_wqueue_wakeup(&(dev->wait_queue), (void*)POLLIN);
+ RT_OBJECT_HOOKLIST_CALL(rt_hw_serial_rxind, (dev, size));
+
return RT_EOK;
}
@@ -1388,14 +1392,6 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
return ret;
}
-#if defined(RT_USING_SMART) && defined(LWP_DEBUG)
-static volatile int _early_input = 0;
-int lwp_startup_debug_request(void)
-{
- return _early_input;
-}
-#endif
-
/* ISR for serial interrupt */
void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
{
@@ -1441,7 +1437,7 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
/**
* Invoke callback.
* First try notify if any, and if notify is existed, rx_indicate()
- * is not callback. This seperate the priority and makes the reuse
+ * is not callback. This separate the priority and makes the reuse
* of same serial device reasonable for RT console.
*/
if (serial->rx_notify.notify)
@@ -1463,9 +1459,6 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
serial->parent.rx_indicate(&serial->parent, rx_length);
}
}
- #if defined(RT_USING_SMART) && defined(LWP_DEBUG)
- _early_input = 1;
- #endif
break;
}
case RT_SERIAL_EVENT_TX_DONE:
diff --git a/components/drivers/serial/serial_dm.c b/components/drivers/serial/serial_dm.c
index f3847e17e8..c41a1fec16 100644
--- a/components/drivers/serial/serial_dm.c
+++ b/components/drivers/serial/serial_dm.c
@@ -9,7 +9,7 @@
*/
#include <rtatomic.h>
-#include "serial_dm.h"
+#include <drivers/serial_dm.h>
int serial_dev_set_name(struct rt_serial_device *sdev)
{
@@ -82,8 +82,9 @@ void *serial_base_from_args(char *str)
return (void *)base;
}
-struct serial_configure serial_cfg_from_args(char *str)
+struct serial_configure serial_cfg_from_args(char *_str)
{
+ char *str = _str;
struct serial_configure cfg = RT_SERIAL_CONFIG_DEFAULT;
/* Format baudrate/parity/bits/flow (BBBBPNF), Default is 115200n8 */
diff --git a/components/drivers/serial/serial_tty.c b/components/drivers/serial/serial_tty.c
index f7b0a1f80f..85c30dbfeb 100644
--- a/components/drivers/serial/serial_tty.c
+++ b/components/drivers/serial/serial_tty.c
@@ -63,6 +63,37 @@ static char *alloc_device_name(void)
return tty_dev_name;
}
+#ifdef LWP_DEBUG_INIT
+static volatile int _early_input = 0;
+
+static void _set_debug(rt_device_t dev, rt_size_t size);
+RT_OBJECT_HOOKLIST_DEFINE_NODE(rt_hw_serial_rxind, _set_debug_node, _set_debug);
+
+static void _set_debug(rt_device_t dev, rt_size_t size)
+{
+ rt_list_remove(&_set_debug_node.list_node);
+ _early_input = 1;
+}
+
+static void _setup_debug_rxind_hook(void)
+{
+ rt_hw_serial_rxind_sethook(&_set_debug_node);
+}
+
+int lwp_startup_debug_request(void)
+{
+ return _early_input;
+}
+
+#else /* !LWP_DEBUG_INIT */
+
+static void _setup_debug_rxind_hook(void)
+{
+ return ;
+}
+
+#endif /* LWP_DEBUG_INIT */
+
static void _tty_rx_notify(struct rt_device *device)
{
lwp_tty_t tp;
@@ -325,6 +356,8 @@ static int _tty_workqueue_init(void)
LWP_TTY_WORKQUEUE_PRIORITY);
RT_ASSERT(_ttyworkq != RT_NULL);
+ _setup_debug_rxind_hook();
+
return RT_EOK;
}
INIT_PREV_EXPORT(_tty_workqueue_init);
diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c
index ce657e55f6..d7576dbed8 100644
--- a/components/drivers/serial/serial_v2.c
+++ b/components/drivers/serial/serial_v2.c
@@ -35,10 +35,14 @@
#undef putc
#endif
+RT_OBJECT_HOOKLIST_DEFINE(rt_hw_serial_rxind);
+
static rt_err_t serial_fops_rx_ind(rt_device_t dev, rt_size_t size)
{
rt_wqueue_wakeup(&(dev->wait_queue), (void*)POLLIN);
+ RT_OBJECT_HOOKLIST_CALL(rt_hw_serial_rxind, (dev, size));
+
return RT_EOK;
}
diff --git a/components/lwp/Kconfig b/components/lwp/Kconfig
index 9b79e51207..16b23c4dd7 100644
--- a/components/lwp/Kconfig
+++ b/components/lwp/Kconfig
@@ -6,10 +6,17 @@ menuconfig RT_USING_LWP
The lwP is a light weight process running in user mode.
if RT_USING_LWP
- config LWP_DEBUG
+ menuconfig LWP_DEBUG
bool "Enable debugging features of LwP"
default y
+ if LWP_DEBUG
+ config LWP_DEBUG_INIT
+ select RT_USING_HOOKLIST
+ bool "Enable debug mode of init process"
+ default n
+ endif
+
config RT_LWP_MAX_NR
int "The max number of light-weight process"
default 30
diff --git a/components/lwp/lwp.c b/components/lwp/lwp.c
index 27d9f2f234..f923c91817 100644
--- a/components/lwp/lwp.c
+++ b/components/lwp/lwp.c
@@ -137,7 +137,7 @@ static int lwp_startup(void)
char *argv[] = {0, "&"};
char *envp[] = {LWP_CONSOLE_PATH, 0};
-#ifdef LWP_DEBUG
+#ifdef LWP_DEBUG_INIT
int command;
int countdown = LATENCY_TIMES;
while (countdown)
@@ -152,7 +152,7 @@ static int lwp_startup(void)
rt_thread_mdelay(LATENCY_IN_MSEC);
}
rt_kprintf("Starting init ...\n");
-#endif
+#endif /* LWP_DEBUG_INIT */
for (size_t i = 0; i < sizeof(init_search_path)/sizeof(init_search_path[0]); i++)
{
diff --git a/include/rtdef.h b/include/rtdef.h
index 085600433e..e3daa03828 100644
--- a/include/rtdef.h
+++ b/include/rtdef.h
@@ -525,23 +525,23 @@ struct rt_object_information
* do_other_things();
* }
*/
-#define _RT_OBJECT_HOOKLIST_CALL(nodetype, nested, list, lock, argv) \
- do \
- { \
- nodetype iter; \
- rt_ubase_t level = rt_spin_lock_irqsave(&lock); \
- nested += 1; \
- rt_spin_unlock_irqrestore(&lock, level); \
- if (!rt_list_isempty(&list)) \
- { \
- rt_list_for_each_entry(iter, &list, list_node) \
- { \
- iter->handler argv; \
- } \
- } \
- level = rt_spin_lock_irqsave(&lock); \
- nested -= 1; \
- rt_spin_unlock_irqrestore(&lock, level); \
+#define _RT_OBJECT_HOOKLIST_CALL(nodetype, nested, list, lock, argv) \
+ do \
+ { \
+ nodetype iter, next; \
+ rt_ubase_t level = rt_spin_lock_irqsave(&lock); \
+ nested += 1; \
+ rt_spin_unlock_irqrestore(&lock, level); \
+ if (!rt_list_isempty(&list)) \
+ { \
+ rt_list_for_each_entry_safe(iter, next, &list, list_node) \
+ { \
+ iter->handler argv; \
+ } \
+ } \
+ level = rt_spin_lock_irqsave(&lock); \
+ nested -= 1; \
+ rt_spin_unlock_irqrestore(&lock, level); \
} while (0)
#define RT_OBJECT_HOOKLIST_CALL(name, argv) \
_RT_OBJECT_HOOKLIST_CALL(name##_hooklistnode_t, name##_nested, \