实现一个简单的UART驱动程序
在DragonOS中,为了方便调试,实现了一个简单的UART驱动程序。
https://github.com/fslongjin/DragonOS/tree/master/kernel/driver/uart
原理不难,就简单讲讲吧。
uart驱动程序工作的原理就是往指定的io端口写入数据,每次传送8个bit。
其中,io端口与com口的对应关系如下:
COM端口号 | IO端口基地址 |
---|---|
1 | 0x3f8 |
2 | 0x2f8 |
3 | 0x3e8 |
4 | 0x2e8 |
5 | 0x5f8 |
6 | 0x4f8 |
7 | 0x5e8 |
8 | 0x4e8 |
每个COM口有8个寄存器,功能如下:
UART Registers | ||||
---|---|---|---|---|
Base Address | DLAB | I/O Access | Abbrv. | Register Name |
+0 | 0 | Write | THR | Transmitter Holding Buffer |
+0 | 0 | Read | RBR | Receiver Buffer |
+0 | 1 | Read/Write | DLL | Divisor Latch Low Byte |
+1 | 0 | Read/Write | IER | Interrupt Enable Register |
+1 | 1 | Read/Write | DLH | Divisor Latch High Byte |
+2 | x | Read | IIR | Interrupt Identification Register |
+2 | x | Write | FCR | FIFO Control Register |
+3 | x | Read/Write | LCR | Line Control Register |
+4 | x | Read/Write | MCR | Modem Control Register |
+5 | x | Read | LSR | Line Status Register |
+6 | x | Read | MSR | Modem Status Register |
+7 | x | Read/Write | SR | Scratch Register |
The “x” in the DLAB column means that the status of the DLAB has no effect on what register is going to be accessed for that offset range. Notice also that some registers are Read only. If you attempt to write data to them, you may end up with either some problems with the modem (worst case), or the data will simply be ignored (typically the result). As mentioned earlier, some registers share a Port I/O address where one register will be used when you write data to it and another register will be used to retrieve data from the same address.
1.1.1. 设置波特率
波特率的设置是通过设置divisor来实现的,
1.1.2. 发送与接收数据
操作就是先读取标志位,确认是否端口处于忙的状态,然后从DATA_REG读取数据。
在写UART驱动程序的过程中,参考了资料:https://github.com/fslongjin/DragonOS/tree/master/kernel/driver/uart
转载请注明来源:https://longjin666.cn/?p=1399
相关文章
- 实现一个简单版 Vue2 双向数据绑定
- SpringBoot+JPA+Thymeleaf实现简单的CRUD
- java 异或加密_使用异或实现一个简单的加密或解密
- 使用.NET简单实现一个Redis的高性能克隆版(四、五)
- 使用.NET简单实现一个Redis的高性能克隆版(六)
- 实现一个简单的Database10(译文)
- 实现一个简单的Database2(译文)
- 实现一个简单的Database3(译文)
- 实现一个简单的 Spring Bean 容器
- 简单三步轻松实现ORACLE字段自增
- Python实现简单的缓存和缓存decorator详解编程语言
- Apache commons exec 简介和简单ping命令方法调用实现详解编程语言
- JBPM工作流(一)——实现一个简单的工作流例子详解编程语言
- Java经典实例:实现一个简单堆栈详解编程语言
- 使用Linux开发:实现一个简单应用(linux开发应用实例)
- 实现MongoDB表数据导出的简单方法(mongodb导出表数据)
- 可视化Redis界面可视化: 实现简单易用的管理(redis界面)
- Linux用户查询:实现简单高效(linux用户查询)
- 一个简单的shell脚本—–实现虚拟机实验环境的简单配置
- Oracle主机改IP实现简单迅速的操作(oracle主机改ip)
- 导出Redis中所有Key一个简单的实现(导出redis所有key)
- Redis实现访问统计简单有效的实践方法(redis 访问统计)
- 一个简单的php实现的MySQL数据浏览器
- 一个简单的JavaScript数据缓存系统实现代码
- 基于C中一个行压缩图的简单实现代码
- PHP导航下拉菜单的实现如此简单
- jquery实现图片滚动效果的简单实例
- java实现八皇后问题示例分享
- 用jquery实现的一个超级简单的下拉菜单
- 使用Node.js实现一个简单的FastCGI服务器实例
- Go语言实现简单的一个静态WEB服务器