summaryrefslogtreecommitdiff
path: root/components/drivers/tty/include/tty_ldisc.h
blob: 919805f64570dd88cdce6e1f887d86bb4a096108 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021.12.07     linzhenxing      first version
 */
#ifndef __TTY_LDISC_
#define __TTY_LDISC_
#include <rtthread.h>
#include <dfs.h>
#include <dfs_fs.h>
#include <tty.h>
#if defined(RT_USING_POSIX_TERMIOS)
#include <termios.h>
#endif
struct tty_struct;

struct tty_ldisc_ops
{
    char    *name;
    int num;

    int (*open)     (struct dfs_fd *fd);
    int (*close)    (struct tty_struct *tty);
    int (*ioctl)    (struct dfs_fd *fd, int cmd, void *args);
    int (*read)     (struct dfs_fd *fd, void *buf, size_t count);
    int (*write)    (struct dfs_fd *fd, const void *buf, size_t count);
    int (*flush)    (struct dfs_fd *fd);
    int (*lseek)    (struct dfs_fd *fd, off_t offset);
    int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count);

    int (*poll)     (struct dfs_fd *fd, struct rt_pollreq *req);
    void (*set_termios) (struct tty_struct *tty, struct termios *old);
    int (*receive_buf) (struct tty_struct *tty,char *cp, int count);

    int refcount;
};

struct tty_ldisc
{
    struct tty_ldisc_ops *ops;
    struct tty_struct *tty;
};

#define TTY_LDISC_MAGIC 0x5403

int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
void tty_ldisc_kill(struct tty_struct *tty);
void tty_ldisc_init(struct tty_struct *tty);
void tty_ldisc_release(struct tty_struct *tty);
void n_tty_init(void);

#endif // __TTY_LDISC_