Skip to content

Commit a79176b

Browse files
polarvidRbb666
authored andcommitted
[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]>
1 parent 0655742 commit a79176b

File tree

11 files changed

+90
-35
lines changed

11 files changed

+90
-35
lines changed

components/drivers/include/drivers/serial.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@
102102
0 \
103103
}
104104

105+
/**
106+
* @brief Sets a hook function when RX indicate is called
107+
*
108+
* @param thread is the target thread that initializing
109+
*/
110+
typedef void (*rt_hw_serial_rxind_hookproto_t)(rt_device_t dev, rt_size_t size);
111+
RT_OBJECT_HOOKLIST_DECLARE(rt_hw_serial_rxind_hookproto_t, rt_hw_serial_rxind);
112+
105113
struct serial_configure
106114
{
107115
rt_uint32_t baud_rate;
@@ -186,4 +194,5 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
186194
void *data);
187195

188196
rt_err_t rt_hw_serial_register_tty(struct rt_serial_device *serial);
197+
189198
#endif
File renamed without changes.

components/drivers/include/drivers/serial_v2.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@
103103
0 \
104104
}
105105

106+
/**
107+
* @brief Sets a hook function when RX indicate is called
108+
*
109+
* @param thread is the target thread that initializing
110+
*/
111+
typedef void (*rt_hw_serial_rxind_hookproto_t)(rt_device_t dev, rt_size_t size);
112+
RT_OBJECT_HOOKLIST_DECLARE(rt_hw_serial_rxind_hookproto_t, rt_hw_serial_rxind);
113+
106114
struct serial_configure
107115
{
108116
rt_uint32_t baud_rate;

components/drivers/ofw/ofw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <rtdevice.h>
1313
#include <drivers/platform.h>
1414
#include <drivers/core/bus.h>
15-
#include "../serial/serial_dm.h"
15+
#include <drivers/serial_dm.h>
1616

1717
#define DBG_TAG "rtdm.ofw"
1818
#define DBG_LVL DBG_INFO

components/drivers/serial/serial.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@
5757
#undef putc
5858
#endif
5959

60+
RT_OBJECT_HOOKLIST_DEFINE(rt_hw_serial_rxind);
61+
6062
static rt_err_t serial_fops_rx_ind(rt_device_t dev, rt_size_t size)
6163
{
6264
rt_wqueue_wakeup(&(dev->wait_queue), (void*)POLLIN);
6365

66+
RT_OBJECT_HOOKLIST_CALL(rt_hw_serial_rxind, (dev, size));
67+
6468
return RT_EOK;
6569
}
6670

@@ -1390,14 +1394,6 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
13901394
return ret;
13911395
}
13921396

1393-
#if defined(RT_USING_SMART) && defined(LWP_DEBUG)
1394-
static volatile int _early_input = 0;
1395-
int lwp_startup_debug_request(void)
1396-
{
1397-
return _early_input;
1398-
}
1399-
#endif
1400-
14011397
/* ISR for serial interrupt */
14021398
void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
14031399
{
@@ -1443,7 +1439,7 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
14431439
/**
14441440
* Invoke callback.
14451441
* First try notify if any, and if notify is existed, rx_indicate()
1446-
* is not callback. This seperate the priority and makes the reuse
1442+
* is not callback. This separate the priority and makes the reuse
14471443
* of same serial device reasonable for RT console.
14481444
*/
14491445
if (serial->rx_notify.notify)
@@ -1465,9 +1461,6 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
14651461
serial->parent.rx_indicate(&serial->parent, rx_length);
14661462
}
14671463
}
1468-
#if defined(RT_USING_SMART) && defined(LWP_DEBUG)
1469-
_early_input = 1;
1470-
#endif
14711464
break;
14721465
}
14731466
case RT_SERIAL_EVENT_TX_DONE:

components/drivers/serial/serial_dm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
#include <rtatomic.h>
12-
#include "serial_dm.h"
12+
#include <drivers/serial_dm.h>
1313

1414
int serial_dev_set_name(struct rt_serial_device *sdev)
1515
{
@@ -82,8 +82,9 @@ void *serial_base_from_args(char *str)
8282
return (void *)base;
8383
}
8484

85-
struct serial_configure serial_cfg_from_args(char *str)
85+
struct serial_configure serial_cfg_from_args(char *_str)
8686
{
87+
char *str = _str;
8788
struct serial_configure cfg = RT_SERIAL_CONFIG_DEFAULT;
8889

8990
/* Format baudrate/parity/bits/flow (BBBBPNF), Default is 115200n8 */

components/drivers/serial/serial_tty.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ static char *alloc_device_name(void)
6363
return tty_dev_name;
6464
}
6565

66+
#ifdef LWP_DEBUG_INIT
67+
static volatile int _early_input = 0;
68+
69+
static void _set_debug(rt_device_t dev, rt_size_t size);
70+
RT_OBJECT_HOOKLIST_DEFINE_NODE(rt_hw_serial_rxind, _set_debug_node, _set_debug);
71+
72+
static void _set_debug(rt_device_t dev, rt_size_t size)
73+
{
74+
rt_list_remove(&_set_debug_node.list_node);
75+
_early_input = 1;
76+
}
77+
78+
static void _setup_debug_rxind_hook(void)
79+
{
80+
rt_hw_serial_rxind_sethook(&_set_debug_node);
81+
}
82+
83+
int lwp_startup_debug_request(void)
84+
{
85+
return _early_input;
86+
}
87+
88+
#else /* !LWP_DEBUG_INIT */
89+
90+
static void _setup_debug_rxind_hook(void)
91+
{
92+
return ;
93+
}
94+
95+
#endif /* LWP_DEBUG_INIT */
96+
6697
static void _tty_rx_notify(struct rt_device *device)
6798
{
6899
lwp_tty_t tp;
@@ -325,6 +356,8 @@ static int _tty_workqueue_init(void)
325356
LWP_TTY_WORKQUEUE_PRIORITY);
326357
RT_ASSERT(_ttyworkq != RT_NULL);
327358

359+
_setup_debug_rxind_hook();
360+
328361
return RT_EOK;
329362
}
330363
INIT_PREV_EXPORT(_tty_workqueue_init);

components/drivers/serial/serial_v2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@
3535
#undef putc
3636
#endif
3737

38+
RT_OBJECT_HOOKLIST_DEFINE(rt_hw_serial_rxind);
39+
3840
static rt_err_t serial_fops_rx_ind(rt_device_t dev, rt_size_t size)
3941
{
4042
rt_wqueue_wakeup(&(dev->wait_queue), (void*)POLLIN);
4143

44+
RT_OBJECT_HOOKLIST_CALL(rt_hw_serial_rxind, (dev, size));
45+
4246
return RT_EOK;
4347
}
4448

components/lwp/Kconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ menuconfig RT_USING_LWP
66
The lwP is a light weight process running in user mode.
77

88
if RT_USING_LWP
9-
config LWP_DEBUG
9+
menuconfig LWP_DEBUG
1010
bool "Enable debugging features of LwP"
1111
default y
1212

13+
if LWP_DEBUG
14+
config LWP_DEBUG_INIT
15+
select RT_USING_HOOKLIST
16+
bool "Enable debug mode of init process"
17+
default n
18+
endif
19+
1320
config RT_LWP_MAX_NR
1421
int "The max number of light-weight process"
1522
default 30

components/lwp/lwp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int lwp_startup(void)
137137
char *argv[] = {0, "&"};
138138
char *envp[] = {LWP_CONSOLE_PATH, 0};
139139

140-
#ifdef LWP_DEBUG
140+
#ifdef LWP_DEBUG_INIT
141141
int command;
142142
int countdown = LATENCY_TIMES;
143143
while (countdown)
@@ -152,7 +152,7 @@ static int lwp_startup(void)
152152
rt_thread_mdelay(LATENCY_IN_MSEC);
153153
}
154154
rt_kprintf("Starting init ...\n");
155-
#endif
155+
#endif /* LWP_DEBUG_INIT */
156156

157157
for (size_t i = 0; i < sizeof(init_search_path)/sizeof(init_search_path[0]); i++)
158158
{

0 commit comments

Comments
 (0)