0

如何在内核模块中配置串口。我在初始化模块函数中这样做。相同的配置在用户空间中工作。我正在使用下面的代码来配置串口。

mm_segment_t oldfs;

oldfs = get_fs();
set_fs(KERNEL_DS);
fp = filp_open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY);
tty = (struct tty_struct *)fp->private_data;
setting the required configuration(tty->termios)
set_fs(oldfs);
4

1 回答 1

0

几乎所有串口操作的功能都是由drivers/tty/serial/serial_core.c. 如果您想以不同的方式进行操作,请为uart_opsfrom提供您自己的功能include/linux/serial_core.h

struct uart_ops {
        unsigned int    (*tx_empty)(struct uart_port *);
        void            (*set_mctrl)(struct uart_port *, unsigned int mctrl);
        unsigned int    (*get_mctrl)(struct uart_port *);
        void            (*stop_tx)(struct uart_port *);
        void            (*start_tx)(struct uart_port *);
        void            (*send_xchar)(struct uart_port *, char ch);
        void            (*stop_rx)(struct uart_port *);
        void            (*enable_ms)(struct uart_port *);
        void            (*break_ctl)(struct uart_port *, int ctl);
        int             (*startup)(struct uart_port *);
        void            (*shutdown)(struct uart_port *);
        void            (*flush_buffer)(struct uart_port *);
        void            (*set_termios)(struct uart_port *, struct ktermios *new,
                                       struct ktermios *old);
        void            (*set_ldisc)(struct uart_port *, int new);
        void            (*pm)(struct uart_port *, unsigned int state,
                              unsigned int oldstate);
        int             (*set_wake)(struct uart_port *, unsigned int state);
        const char *    (*type)(struct uart_port *);
        void            (*release_port)(struct uart_port *);
        int             (*request_port)(struct uart_port *);
        void            (*config_port)(struct uart_port *, int);
        int             (*verify_port)(struct uart_port *, struct serial_struct *);
        int             (*ioctl)(struct uart_port *, unsigned int, unsigned long);
#ifdef CONFIG_CONSOLE_POLL
        void    (*poll_put_char)(struct uart_port *, unsigned char);
        int             (*poll_get_char)(struct uart_port *);
#endif
};

在您的情况下,您需要实现 set_termios 功能。另外,看看uart_get_divisor()如何设置波特率。

于 2012-12-04T09:14:51.570 回答