5.S5PV210串口通信详解(三)

一、串口中断相关的知识:
INTERRUPT/DMA REQUEST GENERATION(中断/DMA 请求生成)

Each UART in S5PV210 comprises of seven status (Tx/Rx/Error) signals, namely, Overrun error, Parity error,Frame error, Break, Receive buffer data ready, Transmit buffer empty, and Transmit shifter empty. These conditions are indicated by the corresponding UART status register(UTRSTATn/UERSTATn).
在S5PV210每一个串口都由7个状态(Tx/Rx/Error)信号组成,即:溢出错误、奇偶校验错误、帧错误、中断、接收缓冲区数据准备完成、发送缓冲区为空和发送移位器为空。它们的状态都能通过相应的UART状态寄存器(UTRSTATn/UERSTATn)来表示。

The Overrun Error, Parity Error, Frame Error and Break Condition specify the receive error status. If receive-errorstatus-interrupt-enable bit is set to 1 in the control register (UCONn), the receive error status generates receiveerror-status-interrupt. If a receive-error-status-interrupt-request is detected, you can identify the source of interrupt by reading the value of UERSTATn.
溢出错误、奇偶校验错误、帧错误和中断状态指定为接收错误状态。如果UCONn寄存器中的receive-errorstatus-interrupt-enable位置1,那么接收错误状态就会产生一个异常中断,如果检测到了receive-error-status-interrupt-request,你可以通过读取UERSTATn寄存器的值来识别中断源。

If the receiver transfers data of the receive shifter to the receive FIFO register in FIFO mode, and the number of
received data is greater than or equal to the Rx FIFO Trigger Level, Rx interrupt is generated if Receive mode in
control register (UCONn) is set to 1 (Interrupt request or polling mode).
在FIFO模式下,如果接收方从接收移位器传输数据到接收方FIFO寄存器时,接收到的数据的数量大于或者等于Rx FIFO触发器的水平时且UCONn寄存器中的接收模式位被置1(以中断请求或者轮询模式读取串口接收缓冲区的数据),将会产生Rx中断。

In Non-FIFO mode, transferring the data of receive shifter to receive holding register causes Rx interrupt in theInterrupt request and polling modes.
在非FIFO模式下,当选择中断请求和轮询模式时,将接收移位器的数据传输到接收存储寄存器会导致Rx中断。

If the transmitter transfers data from its transmit FIFO register to transmit shifter and the number of data left in
transmit FIFO is less than or equal to the Tx FIFO Trigger Level, Tx interrupt is generated (provided Transmit
mode in control register is selected as Interrupt request or polling mode). 
在FIFO模式下,如果发送方从它的发送FIFO寄存器发送数据到发送移位器并且发送FIFO剩下的数据数量小于或等于发送FIFO触发器的水平,将会产生Tx中断(假设发送模式选择的是中断请求或者轮询模式)。

In Non-FIFO mode, transferring the data from transmit holding register to transmit shifter causes Tx interrupt in the Interrupt request and polling mode.
在非FIFO模式下,当在中断请求或轮询模式时,从transmit holding register发送数据到transmit shifter会产生Tx中断。

Remember that the Tx interrupt is always requested if the number of data in the transmit FIFO is smaller than the trigger level. This means that an interrupt is requested as soon as you enable the Tx interrupt, unless you fill the
Tx buffer. It is recommended to fill the Tx buffer first and then enable the Tx interrupt.
请记住,如果发送方FIFO里的数据小于触发器水平总是会请求Tx中断。这意味着除非你填满发送缓冲区,否则你一使能Tx中断就会产生一个中断请求。所以推荐先填满发送缓冲区再使能Tx中断。

The interrupt controllers of S5PV210 are of the level-triggered type. You must set the interrupt type as ‘Level’ if you program the UART control registers.
S5PV210的中断控制器是level-triggered类型,所以如果你编程串口控制器必须设置中断类型为“Level”。

If Receive and Transmit modes in control register are selected as DMAn request mode, then DMAn request
occurs instead of Rx or Tx interrupt in the above situation.
如果收发模式中控制寄存器选择的是DMA请求模式,那么上述情况中的Rx或Tx中断被DMA请求产生代替。


串口通信与中断的关系:

串口通信分为发送和接收两个部分,一般情况下,发送方不需要(也可以使用)中断即可完成发送,但是接收方(一般来说必须,使用轮询
模式也可以)使用中断来完成接收。

发送方使用中断的过程:

发送方先设置好中断并绑定一个中断处理程序,然后发送方丢一帧数据给transmitter,transmitter发送耗费一段时间来发送这一帧数据,这段时间内CPU可以去做别的事情,等transmitter发送完成后会产生一个Tx中断,然后CPU处理中断,该中断处理程序的内容是继续给transmitter填充数据,然后CPU继续做其它的事情,来回不断的这样循环发送数据。这样可以更大程度的利用CPU,不造成资源浪费。


发送方不使用中断的过程:

发送方事先禁止Tx中断,然后发送方丢一帧数据给transmitter,然后transmitter耗费一段时间来发送这帧数据,在这期间CPU要一直等着这帧数据发送完成,期间不能做其它的事情,直到发送完成后再继续填充数据给transmitter,然后不断循环这样的过程。在这期间CPU是通过不断的查询串口中的状态寄存器中的发送缓冲区位是否为空来判断这帧数据是否发送完成。

为什么接收方要使用中断:

因为串口通信是异步通信方式,也就是说双方各自使用自己的时钟,发送方占主导低位,它随时想发就发,如果接收方不使用中断,那么CPU就不用干其它的事情了,就得一直不断的查询状态寄存器中的接收缓冲区标志位才能确保发送的数据不会被丢失,显然这是不可取的,所以要使用中断来完成接收数据。


二、串口通信接口的时钟设计:
要想了解串口的时钟就需要参考串口的结构框图和S5PV210的时钟结构框图(这两个框图可以翻我之前的博客或者自己查询S5PV210数据手册),通过S5PV210的时钟结构框图我们可以查到提供给串口的时钟源,然后串口中的Buad-rate Generator(波特率发生器)会根据时钟源来产生接收器和发送器传输数据的时钟节拍。(具体是通过设置相关寄存器,在后面详细说明串口中寄存器的时候会详细解释)。



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值