1 /*
2  * Copyright (C) 2020-2021 Alibaba Group Holding Limited
3  */
4 
5 #ifndef AOS_TTY_H
6 #define AOS_TTY_H
7 
8 #include <termios.h>
9 #include <aos/device.h>
10 
11 typedef aos_dev_ref_t aos_tty_ref_t;
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * @brief   Get a TTY device.
19  * @param   ref TTY ref to operate.
20  * @param   id  TTY device ID.
21  * @return  0: on success; < 0: on failure.
22  */
23 aos_status_t aos_tty_get(aos_tty_ref_t *ref, uint32_t id);
24 /**
25  * @brief   Release a TTY device.
26  * @param   ref TTY ref to operate.
27  * @return  None.
28  */
29 void aos_tty_put(aos_tty_ref_t *ref);
30 /**
31  * @brief   Get the parameters associated with a TTY device.
32  * @param   ref     TTY ref to operate.
33  * @param   termios POSIX-compliant termios structure.
34  * @return  0: on success; < 0: on failure.
35  */
36 aos_status_t aos_tty_get_attr(aos_tty_ref_t *ref, struct termios *termios);
37 /**
38  * @brief   Set the parameters associated with a TTY device.
39  * @param   ref                 TTY ref to operate.
40  * @param   optional_actions    Specifie when the changes take effect.
41  * @param   termios             POSIX-compliant termios structure.
42  * @return  0: on success; < 0: on failure.
43  */
44 aos_status_t aos_tty_set_attr(aos_tty_ref_t *ref, int optional_actions, const struct termios *termios);
45 /**
46  * @brief   Read data from a TTY device.
47  * @param   ref     TTY ref to operate.
48  * @param   buf     Data buffer.
49  * @param   count   Attempt to read up to count bytes.
50  * @param   timeout Timeout in milliseconds.
51  * @return  > 0: the number of bytes read; < 0: on failure.
52  */
53 ssize_t aos_tty_read(aos_tty_ref_t *ref, void *buf, size_t count, uint32_t timeout);
54 /**
55  * @brief   Write data to a TTY device.
56  * @param   ref     TTY ref to operate.
57  * @param   buf     Data buffer.
58  * @param   count   Attempt to write up to count bytes.
59  * @param   timeout Timeout in milliseconds.
60  * @return  > 0: the number of bytes written; < 0: on failure.
61  */
62 ssize_t aos_tty_write(aos_tty_ref_t *ref, const void *buf, size_t count, uint32_t timeout);
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif /* AOS_TTY_H */
69