从内核空间配置串行端口 [英] configuring serial port from kernel space

查看:116
本文介绍了从内核空间配置串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在内核模块中配置串行端口.我正在初始化模块功能中执行此操作.相同的配置在userpsace中起作用.我正在使用以下代码配置串行端口.

How to configure the serial port in kernel module. I am doing this in init module function. same configuration is working in userpsace. I am using the below code to configure the serial port.

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);

推荐答案

几乎所有串行端口操作的功能都由drivers/tty/serial/serial_core.c实现.如果您想以其他方式进行操作,请为include/linux/serial_core.h

Almost all functions of serial port operations are implemented by drivers/tty/serial/serial_core.c. If you want to do it differently then provide your own functions for uart_ops from 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()以了解如何设置波特率.

In your case, you need to implement set_termios function. Also, look at uart_get_divisor() to know how to set baud rate.

这篇关于从内核空间配置串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆