linux UART串口驱动开发文档

时间:2012-09-06来源:网络

串口要能够成为终端,必须客外加入终端注册及初始化的代码,这部分很简单,基本上所有的串口驱动都是固定的模式,并无什么修改,主要包括如下结构:

static struct console cs_amba_console = {

.name = ttyBM,

.write = w83697uart_console_write,

.device = w83697uart_console_device,

.setup = w83697uart_console_setup,

.flags = CON_PRINTBUFFER,

.index = -1,

};

串口终端的注册通过下面的函数,将cs_amba_console注册成为终端, 这个函数调用路径是:

start_kernel()→console_init()→ep93xxuart_w83697_console_init()

void __init ep93xxuart_w83697_console_init(void)

终端会对应一种具体设备的driver, 相对于串口这个结构是uart_driver, 在驱动中我们已经提供了一个这样的结构. static struct uart_driver amba_reg, uart_register_driver会将它注册成为终端对应的driver, 因此真正串口与终端的关联就在此处建立.

函数: static int __init w83697uart_init(void)

描述: 调用uart_register_driver()完成串口与终端的关联,将串口注册成为一种TTY设备,在uart_register_driver()当中调用tty_register_driver()完成TTY设备注册; 其次是完成串口port口的注册,将静态描述的所有串口port(结构为struct uart_port)注册到uart_driver当中.

特别说明: 注册串口TTY设备时,由于历史的原因会注册两个TTY设备,一个是normal, 另一个是callout, 是两个设备来的, 在我们这里两者没有什么差别,请看源码中的注解:

.normal_name = ttyBM,

.callout_name = cuaam,

/*

* The callout device is just like the normal device except for

* the major number and the subtype code.

*/

函数: static void __exit w83697uart_exit(void)

描述: 卸截设备,卸截port口,因为我编译的驱动是与内核绑定在一起的,因此实际上根本不会调用此函数.

1 2 3 4 5 6

关键词: 开发 文档 驱动 串口 UART linux

加入微信
获取电子行业最新资讯
搜索微信公众号:EEPW

或用微信扫描左侧二维码

相关文章

查看电脑版