实现一个简单的UART驱动程序

在DragonOS中,为了方便调试,实现了一个简单的UART驱动程序。

https://github.com/fslongjin/DragonOS/tree/master/kernel/driver/uarticon-default.png?t=M3K6https://github.com/fslongjin/DragonOS/tree/master/kernel/driver/uart

原理不难,就简单讲讲吧。

uart驱动程序工作的原理就是往指定的io端口写入数据,每次传送8个bit。

其中,io端口与com口的对应关系如下:

COM端口号IO端口基地址
10x3f8
20x2f8
30x3e8
40x2e8
50x5f8
60x4f8
70x5e8
80x4e8

每个COM口有8个寄存器,功能如下:

UART Registers
Base AddressDLABI/O AccessAbbrv.Register Name
+00WriteTHRTransmitter Holding Buffer
+00ReadRBRReceiver Buffer
+01Read/WriteDLLDivisor Latch Low Byte
+10Read/WriteIERInterrupt Enable Register
+11Read/WriteDLHDivisor Latch High Byte
+2xReadIIRInterrupt Identification Register
+2xWriteFCRFIFO Control Register
+3xRead/WriteLCRLine Control Register
+4xRead/WriteMCRModem Control Register
+5xReadLSRLine Status Register
+6xReadMSRModem Status Register
+7xRead/WriteSRScratch 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

转载请注明来源:实现一个简单的UART驱动程序 | | 龙进的博客

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值