1 /*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2023-11-13 Shell init ver.
9 */
10 #ifndef __LWP_TTY_INTERNAL_H__
11 #define __LWP_TTY_INTERNAL_H__
12
13 #include "lwp.h"
14 #include "terminal.h"
15
16 extern struct cdevsw bsd_ttydev_methods;
17
18 extern struct bsd_fileops bsd_ptsdev_methods;
19
20 /* bsd devsw porting */
21 void bsd_devsw_init(struct lwp_ttydevsw *tsw);
22
23 /**
24 * Do not assert RTS or DTR automatically. If CNO_RTSDTR is set then the RTS and
25 * DTR lines will not be asserted when the device is opened. As a result, this
26 * flag is only useful on initial-state devices.
27 *
28 * Note: this feature is not using on smart system, so this flag is always 0.
29 */
30 #define CNO_RTSDTR 0
31
32 /* Waking up readers/writers. */
33 int tty_wait(struct lwp_tty *tp, struct rt_condvar *cv);
34 int tty_wait_background(struct lwp_tty *tp, struct rt_thread *td, int sig);
35 int tty_timedwait(struct lwp_tty *tp, struct rt_condvar *cv, rt_tick_t timeout);
36 void tty_wakeup(struct lwp_tty *tp, int flags);
37
38 void tty_info(struct lwp_tty *tp);
39
40 void pts_set_lock(lwp_tty_t pts, rt_bool_t is_lock);
41 rt_bool_t pts_is_locked(lwp_tty_t pts);
42 int pts_get_pktmode(lwp_tty_t pts);
43 int pts_alloc(int fflags, struct rt_thread *td, struct dfs_file *ptm_file);
44
45 int lwp_tty_ioctl_adapter(lwp_tty_t tp, int cmd, int oflags, void *args, rt_thread_t td);
46
47 int lwp_tty_set_ctrl_proc(lwp_tty_t tp, rt_thread_t td);
48 int lwp_tty_assign_foreground(lwp_tty_t tp, rt_thread_t td, int pgid);
49 int lwp_tty_bg_stop(struct lwp_tty *tp, struct rt_condvar *cv);
50
is_sess_leader(rt_lwp_t p)51 rt_inline rt_bool_t is_sess_leader(rt_lwp_t p)
52 {
53 /**
54 * Note: a pgrp leader is never lose its group, so once it's
55 * true then it's always true
56 */
57 return p->pid == p->sid;
58 }
59
tty_is_ctty(struct lwp_tty * tp,struct rt_lwp * p)60 rt_inline int tty_is_ctty(struct lwp_tty *tp, struct rt_lwp *p)
61 {
62 tty_assert_locked(tp);
63
64 return p->pgrp->session == tp->t_session && p->term_ctrlterm;
65 }
66
67 #endif /* __LWP_TTY_INTERNAL_H__ */
68