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 
11 /*-
12  * SPDX-License-Identifier: BSD-2-Clause
13  *
14  * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
15  * All rights reserved.
16  *
17  * Portions of this software were developed under sponsorship from Snow
18  * B.V., the Netherlands.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  * 1. Redistributions of source code must retain the above copyright
24  *    notice, this list of conditions and the following disclaimer.
25  * 2. Redistributions in binary form must reproduce the above copyright
26  *    notice, this list of conditions and the following disclaimer in the
27  *    documentation and/or other materials provided with the distribution.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  */
41 
42 #ifndef _SYS_TTYDISC_H_
43 #define _SYS_TTYDISC_H_
44 
45 #ifndef __LWP_TERMINAL_H__
46 #error "can only be included through <terminal.h>"
47 #endif /* !__LWP_TERMINAL_H__ */
48 
49 #include <rtdef.h>
50 
51 struct rt_wqueue;
52 struct rt_thread;
53 struct lwp_tty;
54 struct uio;
55 
56 /* Top half routines. */
57 void ttydisc_open(struct lwp_tty *tp);
58 void ttydisc_close(struct lwp_tty *tp);
59 int ttydisc_read(struct lwp_tty *tp, struct uio *uio, int ioflag);
60 int ttydisc_write(struct lwp_tty *tp, struct uio *uio, int ioflag);
61 void ttydisc_optimize(struct lwp_tty *tp);
62 
63 /* Bottom half routines. */
64 void ttydisc_modem(struct lwp_tty *tp, int open);
65 #define ttydisc_can_bypass(tp) ((tp)->t_flags & TF_BYPASS)
66 int ttydisc_rint(struct lwp_tty *tp, char c, int flags);
67 size_t ttydisc_rint_simple(struct lwp_tty *tp, const void *buf, size_t len);
68 size_t ttydisc_rint_bypass(struct lwp_tty *tp, const void *buf, size_t len);
69 void ttydisc_rint_done(struct lwp_tty *tp);
70 size_t ttydisc_rint_poll(struct lwp_tty *tp);
71 size_t ttydisc_getc(struct lwp_tty *tp, void *buf, size_t len);
72 int ttydisc_getc_uio(struct lwp_tty *tp, struct uio *uio);
73 size_t ttydisc_getc_poll(struct lwp_tty *tp);
74 
75 /* Error codes for ttydisc_rint(). */
76 #define TRE_FRAMING 0x01
77 #define TRE_PARITY  0x02
78 #define TRE_OVERRUN 0x04
79 #define TRE_BREAK   0x08
80 
81 #endif /* !_SYS_TTYDISC_H_ */
82