资源描述
译文基于FPGA的串行控制器设计Thomas Oelsner QuickLogic Europe 应用注释:QAN20简介目前设计开发和验证FPGA系统时,硬件描述语言HDL的使用变得越来越主流。采用行为级描述不仅提高了产品的设计效率,而且在设计验证中显示出其独特的优势。目前最流行的HDL语言是Verilog和VHDL语言。本文介绍了采用verilog语言对数字异步串行收发器进行设计和验证。UART 通用异步串行收发器(UART)由二个独立的HDL模块组成。一个模块实现发射功能,而另一个模块则实现接收功能。发射和接收功能模块在顶层设计时组合到一起,这种接收和发射的组合是通信所必需的。数据写入发射器,从接收器读出,所有的数据是以二进制8字节的形式通过一个双向CPU接口。由地址映射的发射机和接收机通道可以很容易地建立接口。两个模块共用一个主控时钟,该时钟为mclkx16,在每个模块里,主控时钟mclkx16被分频成独立的波特率时钟。所有英文的图和表的标题要翻译成中文图1 通用异步串行收发器通用异步串行收发器的特点是否具有全双工操作标准UART数据帧格式偶校验或奇校验模式奇偶错误校验帧错误校验溢出错误校验数据接收准备中断数据发送准备中断是是是是是是是是表 UART功能概述UART的功能概况注意下面所有图标的格式,统一是居中,字体要一样。UART的基本功能概况见下图。左边为“发送寄存器”、“发送移位寄存器”以及“发送控制逻辑模块”,这些模块包含在发送模块”txmix”中。右边为“接收移位寄存器”、“接收寄存器”和“接收控制逻辑模块”,这些模块包含在发送模块”rxmix”中。这两个模块有单独的输入和输出的控制线路,只有双向的数据总线、主时钟和复位线是共享的是共享的。图的标题翻译图2 UART框图顶层UART系统的I/O功能描述符 号类型描 述mclkx16输入用于主控时钟波特率的生产。reset输入主复位输入信号。parityerr输出表明被检测的数据帧有无奇偶校验错误。校验编码可以基于偶数或奇数模式。framingerr输出表明从rx输入的数据串是否符合如图2所示的UART数据帧格式。overrun输出表明接收模块准备接收新数据是,模块中仍然有数据未读取。rxrdy输出表明接收模块已经接收新数据,并准备读取。txrdy输出表明数据已准备好加载到发送模块。read输入低电平有效的读选通信号,用于从接收模块中读取数据。write输入低电平有效的写选通信号,用于将数据写入发送模块。data7:0输入双向数据总线。数据通过该总线进行发送或接收。tx输出发送模块串行输出。复位或闲置时为高电平。rx输入接收模块串行输入。复位或闲置时为高电平。表 2 UART的IO接口UART的标准数据格式图3 UART数据帧格式图的标题要翻译图3为UART的串行数据格式,在串行数据帧中包含8位数据位以及编码比特的信息。在连续传输线路之间,传输线路处于高电平。传输从低位的起始比特开始,接下来的是8比特的数据信息,低位对于后边高位有重要的作用。然后是1比特的奇偶校验位,对之前的8比特的数据位进行奇偶校验。奇偶校验位由奇校验或偶校验的形式进行编码。奇偶校验位之后是高位停止比特,标志数据帧的结束。UART时序图下面显示了数据是如何写入“发送寄存器”并如何加载给“发送移位寄存器”,及在波特率时钟上升沿时如何传输到tx端进行输出的。图的标题要翻译图4 发送时序图下图显示了数据如何从rx端输入写入“接收移位寄存器”并加载到“接收寄存器”。最后接收模块发出rxrdty标志位。同上图5 接收时序图发送模块主控时钟称为mclkx16,被分频成等于mclkx16/16的称为txclk的时钟频率。数据以并行的形式写入模块,而按照波特率时钟的频率以串行的形式从tx端输出。从tx端输出的数据按照图3所示的UART数据帧格式发送。同上图6 发送模块表的标题和内容要翻译。符号类型描 述mclkx16输入用于生成主控时钟波特率。reset输入主复位输入信号write输入低电平有效的写选通信号,将数据写入发送模块。data7:0输入数据传输是通过数据总线写入发送模块。在写选通脉冲的上升沿,数据总线的内容锁定在一个内部的“发送寄存器”。tx输出串行数据输出。串行数据帧通过这个端口发送,当复位或闲置时,tx保持高电平。txrdy输出表明数据锁存到“发送寄存器”,同时加载到“发送移位寄存器”,“发送寄存器”准备好接收新数据。表 2 发送模块IO接口功能同上符号类型内部标志或信号的描述thrreg7:08位“发送寄存器”,用于锁存发送模块接收到的数据。tsrreg7:08位“发送移位寄存器”,发送模块的数据通过此输出。paritymodewire奇偶校验模式位表明了发送模块进行奇偶校验的模式。值为“1”时,为奇校验,为“0”时,偶校验。txparityreg输出tx奇偶校验的结果。tag1,tag2reg此标志位表明发送模块的状态。txclkreg波特率时钟,根据时钟频率将数据通过tx输出。txdonewire表明一个数据串发送完成。txdatardyreg表明“发送寄存器”已锁存新数据,准备好进行发送。paritycyclewire表明tx输出端接收到txparity的值时,发送模块的状态。cntreg3:0暂存器,用于将clkx16时钟分频为txclk时钟。表3 发送模块的内部信号发送模块的行为描述发送模块等待新的数据来写入模块,新的数据在发送模块初始化后发送。以并行形式写入模块的数据转换成串行的形式并由tx端输出。当没有传输序列的时候, tx端输出高电平。图的标题要翻译图 7发送的流程发送模块的实现用Verilog语言声明模块端口,这里定义的信号,是来自于模块并在这里输出的。在这里并没有详细地说明方向。module txmit(mclkx16,write,reset,tx,txrdy,data);图8 发送模块的声明同上端口定义之后是端口的方向,方向为输入、输出或输入(双向) ,这在表1中已说明。描述端口方向之后是声明内部信号,内部信号在Verilog语言中内部信号声明为“wire”或“reg”数据类型,wire类型用于连续的赋值,也叫做组合声明。reg类型在Verilog语言中用于“always”块,常常用于时序逻辑的赋值,但有时并不是这样,进一步解释见Verilog参考书。模块内部信号的数据类型说明见表3 。我们现在已经进行所有必要的声明,并作好准备看看实际的执行情况。硬件描述语言使我们可以用更多的行为模式来描述发送模块的功能,而不是把重点放在门一级的实际实现上。软件编程语言,函数和过程将庞杂的程序变得更具可读性和易于维护。Verilog语言提供类似的函数和任务结构类似于软件编程语言的函数和过程。一个Verilog语言的函数和任务相当于几行Verilog代码,这些代码使得输入信号影响输出信号或变量。函数和任务通常用在多行代码都是重复出现的地方, 从而使得设计易于阅读和维护。一个Verilog的函数可以有多个输入,但始终只有一个输出,而Verilog的任务在某些情况下可以同时有多个输入和多个输出。下图显示了Verilog的任务格式,保留了所有必要的语句,用来描述发送模块的传输模式。图的标题要翻译图9 发送传输模式我们可以看到在移位寄存器有2个标志位tag1和tag2,创建类似的任务来描述发送模块的“闲置”和“负载”模式。使用Verilog语言,现在我们可以创建一个“容易阅读”的行为模型的空穴传输过程。如在波特率时钟的上升沿,tsr中的内容传输到tx端输出。在tsr传输的同时,奇偶校验位也产生了,如图10所示。重要的一点,就是在传输过程中tsr会进行补零。不同的后置标志位tag 和tsr补零位的组合表示不同的传输模式。如果奇偶校验循环周期的第二个周期是高电平,这意味着以标志位tg2的值对tsr1赋值。这是图还是表?当传输结束时,Txdone置高电平,这意味着以标志位tg2的置对tx赋值。基于所述传输序列中的不同状态,“数据位”,“奇偶校验位”或“停止位”被多路复用到tx输出。图的标题要翻译图10 发送传输过程传输序列模拟在写操作信号上升沿时数据总线被锁存,在txclk的下一个上升沿,thr的内容加载到tsr,tx端输出低电平的起始位,同时txrdy标志位表明,该thr再次准备好要写入新的数据。在txclk的每个上升沿,tsr的内容被转移到totx。在数据传输的同时,奇偶校验位也随之产生。在第一个奇偶校验周期,tx持续为高电平,在第二个周期,tx端获得奇偶校验的结果。传输结束时内部的txdone信号为高电平,tx端也持续高电平。同上图11 波特率为2Mhz时的发送时序图接收模块主控时钟mclkx16分频到合适的波特率时钟频率,即rxclk时钟,它等于mclkx16/16。串行数据在rx端接收输入模块,其中串行数据以如图3所示的UART数据帧格式传输,收到的数据通过8位数据总线以并行的形式输出。同上图13 接收模块符号类型IO接口描述mclkx16输入用于输入主控时钟波特率的生成。reset输入主复位输入信号。read输入低电平有效的读选通信号,用于从接收模块中读取数据。data7:0输出数据总线,数据以并行的形式从总线中读取。在读选通信号的下降沿,数据加载到数据总线。rx输入接收信号,处于闲置状态时,保持为高电平。rxrdy输出表明已接收新数据,并准备将其读取。parityerr输出表明无论是否发生奇偶校验错误,都可以进行奇偶校验编码。framingerr输出表明发送到rx的串行信号的数据格式是否符合如图3所示的UART数据帧格式。overrun输出表明新数据准备传输到接收模块时,接收模块仍然有数据未读取。表4 接收模块IO接口信号符号类型内部标志或信号的描述rhrreg7:08位“接收寄存器”,用于锁存接收模块接收到的数据。rsrreg7:08位“接收移位寄存器”,接收模块的数据通过此输入。paritymodewire奇偶校验模式位表明了发送模块进行奇偶校验的模式。值为“1”时,为奇校验,为“0”时,偶校验。rxparityreg输出rsr奇偶校验的结果。paritygenreg表明数据帧奇偶校验后,发生错误。rxclkreg波特率时钟,根据时钟频率进行数据传输。rxstopwire获取从rx接收到的数据帧的结束位。idlereg接收模块的状态位。huntreg接收模块的状态位。rxdatardyreg表明新数据以接收,并准备读取。rxcntreg3:0暂存器,用于将clkx16时钟分频为rxclk时钟。表5 接收模块的内部信号接收模块行为描述在连续发送时,传输线保持高电平,根据异步串行UART标准,接收模块在等待“闲置”模式的rx端变为低电平。在rx的下降沿时,接收模块进入“捕获”模式,因为现在正在寻找一个新的数据帧的有效起始位。当有效的开始位被检测到时,接收器进入“数据传输”模式。如果检测到无效的起始位,接收模块则进入“闲置”模式。当接收到一个数据帧时,各种校验和检查同时进行。接收模块接收到一个完整的数据帧时,接收端返回待机模式,接收模块基本运作如下所示。图13接收的流程图的标题要翻译表的标题和内容要翻译接收频率为mclkx16,和第一上升沿的rxclk常常发生在中心点开始位,如下图显示,对于中心点的起始位及后边的数据字节,波特率时钟是同步。图的标题要翻译图14 同步时钟rxclk起始位的中心点接收器模块的实现为了创建一个易读易操作的接收模块,用两个Verilog任务来描述不同的接收方式,当接收在空闲状态时,其中一个Verilog称为“空闲复位”,下图中有用来描述该接收机复位条件的必要的语句。同上图15 复位条件和闲置模式下的接收模块当接收模块不在复位状态,也不在空闲状态下,接收模块在rx输入端采样数据,传输到移位寄存器中,同时根据输入的数据产生奇偶校验位。这个Verilog任务称为“数据传输”,下图包括所有以描述上述行为的必要语句。图的标题要翻译图16 接收模块数据的传输利用两个Verilog任务实现上述功能,现我们可以在接收模块的复位状态、空闲状态或者数据传输状态对接收模块进行行为级的描述,所有上述行为是和一个叫做rxclk的波特率时钟同步的,它们的实现如下所示。同上图17 接收模块进程当低电平起始位到达rsr0时,一个完整的数据帧将会被接收,在下一个接收时钟上升沿到来时,接收模块又回到空闲状态。当返回空闲状态时,接收模块发出“数据接收准备”中断,表明新的数据可以以并行的方式读取。返回空闲状态时,对错误的标志位进行更新,并清除已经读取的数据。在读信号的下降沿,rhr的内容被锁存到数据总线。在表8中列举接收模块进行的各种错误检查。错误类型描 述奇偶校验错误检查接收数据时,奇偶校验即已经开始。奇偶校验寄存器预先设置为空闲模式(1=奇校验,0=偶校验)。经过一次完整的传输过程,奇偶校验寄存器的值表明是否在传输过程中发生奇偶校验错误。帧传输错误如果接收到的数据帧的结束位不为1,可以认为发生了帧传输错误。数据的格式不符合如图2所示的UART数据帧格式。溢出新数据通过rsr接收时,之前接收的数据仍未读取,可以认为发生了溢出错误。Rsr的内容无法加载到rhr中。表8 接收模块支持的错误检查接收序列的模拟在连续传输时线路保持高电平,在rx输入的下降沿,内部信号rxcnt开始计数,保持和mclkx16同步。如果rx输入在mclkx16的8个循环周期内保持低电平,内部空闲标志位复位,这由 rxclk信号进行。这时,Rxclk信号与低位的起始位中心点同步,在接受时钟上升沿,数据从rx传输到rsr。当低位起始位到达rsr0时,在下一个接收时钟上升沿时,空闲标志位被强行置为高电平。在接收序列时,产生rxclk的11个周期,主要是为了采样1位低位起始位,8位数据位,1位奇偶位,1位高位停止位。在返回空闲状态,rsr的内容加载至rhr,内部标志位更新,“rxrdy”标志位表明,rhr的内容可以读出,在读信号的下降沿,rhr的内容锁存到数据总线。图的要求同上图18 波特率为2Mhz时接收模块的时序仿真硬件描述语言仿真在这里,我们研究如何将HDL用于行为级设计,实现数字UART设计。利用HDL进行设计可以使设计更容易阅读,更容易理解,它还提供了能够方便地描述在一个复杂的事件系统中相互紧密结合的各种过程,例如UART。我们将了解到这种依靠各种进程来描述复杂系统的能力对于仿真而言是必需的。在Verilog语言中仿真激励叫做“测试工具”。测试工具是Verilog的一个模块,拥有要生成仿真激励所需的所有HDL代码。进行仿真时,模块端口将会把信号映射到进行仿真的设计中。端口映射是由将UART顶层模块的模块分层实例化应用到“测试工具”中实现的,如下所示。同上图19 顶层UART模块实例化这使得仿真激励可以用来表示设计的输入,并同时检测该输入条件下设计的输出情况。可以有条件地通过输出激励对输入激励的响应对设计进行调试,图19显示说明测试工具端口如何映射到UART的顶层。同上图20 UART模型和测试工具通过测试工具,发送模块输出端返回到接收模块输入端,这使得发送模块的信号可以用来作为接收模块的测试信号。数据以并行的方式从发送模块发送,同时以串行的形式回送到接收模块的输入端,收到的数据最终从接收模块以并行形式读出。为了尽可能实现UART的自动化测试, Verilog任务树如下,“写入发送”任务提供了将并行数据写入发送模块的一切必要的声明和语句,以完成“写入发送”功能,并将数据锁存到内部,供测试工具进行分析。“读取接收”任务提供了将并行的数据从接收模块读取出来的一切必要的声明和语句,“读取接收”任务来完成读出功能,并得到锁存在内部的数据并供测试工具进行分析。“数据比较”任务提供了一切必要的声明来比较写入到发送模块的数据和接收到的相应的数据。接收到的数据和接收模块读出的数据进行比较,如果发生任何误差,数据比较标志将发送数据错误标志。当误差发生时,“比较数据”任务将立即停止仿真。除了上面提到的Verilog任务树,测试工具还提供程序语句生成mclkx16、主复位信号、以及“tx to rx”环回功能。该语句不是很重要,并且这里将不加以说明,但可在测试工具本身内作参考。测试工具的核心是一个“for循环”。通过这个“for循环”,执行上述任务的Verilog树才能将所有可能的数据组合写入发送模块,并确保相同的数据被正确接收。For循环如图21所示。同上图21 测试工具的核心代码上图所示for循环使用了Verilog“等待”声明。“等待”声明是一个并发进程声明。在它的条件表达式变为真时,声明开始执行。这种情况下,该循环等待接收模块完成序列的接收后,以“rxrdy”标志位变高电平来表示完成数据序列的接收。For循环的停止,是以 “rxrdy”标志位变为高电平作为标志。当“rxrdy”变为高电平,for循环立即执行“读取接收”任务,其次是“比较数据”的任务。根据如图3所示的UART数据帧格式显示,测试工具必须测试多种不同的数据组合,以测试所有可能的数据组合格式。当for循环处理完所有的数据组合,“数据比较”任务没有反馈任何错误标志时,测试工具成功完成测试,并停止运行。同上图22 顶层UART时序仿真图22表示使用2Mhz波特率的仿真序列,其执行了如图21所示的for循环。测试的流程1、发送模块执行“写入发送”任务,数据写入发送模块。2、在“写”信号的上升沿,写入的数据被自动地加载到 “data_written7:0”的信号中。 3、txrdy标志位表示发送模块已经准备好要写入新的数据。4、根据所选择的波特率,数据以并行的形式写入发送模块,并以串行的形式通过tx输出。5、tx的输出反馈到接收模块的rx的输入。6、Rxrdy标志位表示接收模块已接收新数据。7、在rxrdy标志位信号的上升沿,“for循环”执行“读取接收”任务。在读信号的下降沿,接收到的数据被自动锁存到 “data_received7:0”的信号中。8、Data_received7:0信号与 data_writen7:0信号进行比较。测试工具的不同我们已经简要地讨论了UART测试工具以及Verilog语言的仿真方式。上述的UART测试工具采用由设计者选择的信号序列来进行读写测试,但对于更具体的系统级集成的UART仿真,“写入发送”任务和“读取接收”任务可以很容易地通过任何给定的CPU的读写周期信号进行调试修改。如果在实际应用中,本文提到的仿真功能无法完成实际需要,你可以修改测试工具,来实现需要的仿真功能。这是一个锻炼自己的好机会。综合HDL作为设计方法比传统的FPGA设计方式(如原理图设计)有若干优势,它同时需要拥有极大的灵活性以及高性能的实现综合流程的装置,UART综合流程专门将两个灵活的和高性能的可编程逻辑器件FPGA系列作为服务对象,如pASIC-1和pASIC-2家族。UART设计和仿真的文件通过Saros公司的Turbo Writer 技术加载到HDL语言编辑器,其中HDL语言编辑器集成了Synplicity公司的快速高效的综合工具。综合以后,设计布局仿真使用QuickLogic公司的SpDE布局布线工具。经过布局布线,UART设计采用“back-annotated”的时序模型进行模拟布局。QuickLogic公司的QuickWorks工具套件提供了仿真需要的所有工具,布线仿真也可以使用Simucad公司的Silos III快速Verilog仿真工具。同上图24 QuickWorks工具套件The serial controller design based on FPGAIntroductionThe use of hardware description language (HDL) is becoming a more dominant factor, when designing and verifying FPGA designs. The use of behavior level description not only increases the design productivity, but also provides unique advantages in the design verification. The most dominant HDL stoday are called Verilog and VHDL. This application note will illustrate the use of Verilog in design and verification of a digital UART (Universal Asynchronous Receiver & Transmitter).Defining the UART.The UART consists of two independent HDL modules. One module implements thetransmitter, while the other module implements the receiver. The transmitter and receivermodules can be combined at the top level of the design, for any combinations of transmitter and receiver channels required. Data can be written to the transmitter and read out from the receiver, all through a single 8 bit bi-directional CPU interface. Address mapping for the transmitter and receiver channels can easily be build intothe interface at the top level of the design. Both modules share a common master clock called mclkx16. Within each module mclkx16 are divided down to independent baud rate clocks.UART functional overview.A basic overview of the UART is shown below. At the left hand side is shown “transmit hold register”, “transmit shift register” and the transmitter “control logic” block, all contained within the transmitter module called “txmit”. At the right hand side is shown the “receive shift register”, “receive hold register” and the receiver “control logic” block, all contained within the receiver module called “rxcver”. The two modules have separate inputs and outputs for most of their control lines, only the bi-directional data bus, master clock and reset lines are shared by both modules.The UART standard data format.In figure 3 is shown the UART serial data format. Serial data are contained within frames of 8 data bits, as well as coded information bits. Between successive transmissions, the transmission line is held high. A transmission is initialized by a leading low start bit. Next to the leading low start bit comes 8 bits of data information, beginning with the LSB and afterwards represented at increasing significance order up to the MSB. Next to the 8 data bits comes the parity bit, representing the parity result of the 8 data bits. The parity bit can be encoded true based on even parity or odd parity mode. Next to the parity bit comes atrailing high stop bit indicating the end of a data frame.UART timing diagrams.Below is shown, how data written to the “transmit hold register” gets loaded into the “transmit shift register”, and at the rising edge of the baud rate clock, shifted to tx output.Below is shown, how data gets shifted from rx input to the “receive shift register”, and afterwards loaded into the “receive hold register”. Finally the receiver raises “rxrdy” flag.The Transmitter module.The master clock called mclkx16 are divided down to the proper baud rate called txclk and equals to mclkx16/16. Data written in parallel format to the module are latched internally, and shifted in serial format to the tx output at the frequency of the baud rate clock. Data shifted to the tx output follows the UART data format shown in fig. 3.Behavioral description of the transmitter.The transmitter waits for new data to be written to the module. When new data are written a transmit sequence is initialized. Data that was written in parallel to the module gets transmitted as serial data frames at the tx output. When no transmit sequence are in place, the tx output is held high.Implementation of the transmitter module.Creating logic in Verilog starts with the module port declaration. Here defines signals, that are ported to and from the module. No direction are specified at this point.Next to port definitions comes port directions. Directions are specified as input, output or inout (bidirectional), and can be referred to in table 1. Next to the specification of port directions comes declaration of internal signals. Internal signals in Verilog are declared as “wire” or “reg” data types. Signals of the “wire” type are used for continuos assignments, also called combinatorial statements. Signals of the “reg” type are used for assignments within the Verilog “always” block, often use forsequential logic assignments, but not necessarily. For further explanation see aVerilog reference book. Data types of the internal signals of the module can be referred to in table 3.We have now passed by all necessary declarations, and are now ready to look at the actual implementation. Using hardware description language allows us to describe the function of the transmitter in a more behavioral manner, rather than focus on its actual implementation at gate level In software programming language, functions and procedures breaks larger programs into more readable, manageable and certainly maintainable pieces. The Verilog language provides functions and tasks asconstructs, analogous to software functions and procedures. A Verilog function and task are used as the equivalent to multiple lines of Verilog code, where certain inputs or signals affects certain outputs or variables. The use of functions and tasks usually takes place where multiple lines of code are repeatedly used in a design, and hence makes the design easier to read and certainly maintain. A Verilog functioncan have multiple inputs, but always have only one output, while the Verilog task can have both multiple inputs, and multiple outputs and even in some cases, non of each. Below is shown the Verilog task, that hold all necessary sequential statements, to describe the transmitter in the “shift” mode.We here see the two tag bits called tag1 and tag2 concatenated to the “transmit shift register. Similar tasks were created to describe the transmitter in “idle” and “load”modes. By using these Verilog tasks, we can now create a very“ easy to read” behavioral model of the hole transmit process.If txdone and tx datardy both are true, the transmitter enter load mode. Next to the load mode, the transmitter enters shift mode. At the rising edge of the baud rate clock, the contents of tsr are shifted to the tx output. Parity generation takes place during shifting of the tsr, as shown below.Its important to note, that the tsr are zero filled during transmission. The combination of the two trailing tag bits and the zero filled tsr indicates the different states during shifting. Paritycycle is high on cycle next to last cycle, that means when tsr1 gets tag2.Txdone is high when shifting is over, this means when tx gets tag2.Based on the different states during the transmission sequence, “data bits”, “parity bit” or “stop bit” are ultiplexed to the tx output.Simulation of a transmit sequenceThe contents of the data bus are latched into thr at the rising edge of write. At the next rising edge of txclk, the contents of thr are loaded into tsr, the active low start bit is asserted to tx, and the txrdy flag indicates, that thr again is ready for new data to be written. At each rising edge of txclk, the contents of tsr is shifted totx. Parity generation takes place during shifting of data. Parity cycle is high one cycle next to last cycle, and tx gets the parity result. The internal txdone is high when shifting is over, and the active high stopbit is asserted to tx.For further details on the implementation can be referred to in the design source file available fromThe Receiver module.The master clock mclkx16 are divided down to the proper baud rate clock called rxclk, and equals to mclkx16/16. Serial data to be received at the rx input of the module, must follow the UART data format shown in fig. 3. Data received in serial format can be read out in parallel format, through the 8 bit data bus.Behavioral description of the receiver.Between successive transmissions, the transmission line is held high, according to standard UART behavior. The receiver waits in “idle” mode for the rx input to go low. At the falling edge of rx the receiver enter “hunting” mode, now searching for a valid start bit of a new data frame to be received. If a valid start bit is detected, the receiver enter “shift data” mode. If an invalid start bit is detected, the receiver returns to “idle” mode. During receive of a data frame, various parity and error checks are performed. When a complete data frame has been received the receiver returns to idle mode. The basic operation of the receiver works as shown below,The frequency of rxclk are equal to mclkx16/16, and the first rising edge of the rxclk will always occur at the center point of the start bit. Below is shown, how generation of the baud rate clock rxclk are synchronized to the center points of the start bit and the following data bits.Implementation of the receiver module.In order to create an easy to read and easy to maintain behavioral model of the receiver, two Verilog tasks are written to describe the different modes of the receiver. The Verilog task called “idle_reset” holds all necessary sequential statements to describe the receiver at reset condition, and when the receiver is in its idle mode.When the receiver is not at its reset condition, and not in its idle mode, the receiver samples data at the rx input, shifts the data to the “receive shift register”, and generates parity based on the incoming data. The Verilog task called “shift_data” holds all necessary sequential statements to describe all above actions. Using the two Verilog tasks described above, we are now able to create the behavioral level description of the receiver at its reset condition, idle mode or when shifting in data. All above actions is synchronous to the baudrate clock called rxclk, and the implementation is shown below.A complete data frame has been received, when the leading low start bit reaches rsr0, and the receiver returns to idle mode again at the next rising edge of rxclk. At return to “idle” mode the receiver raises the “receive data ready” interrupt to indicate, that the new data received now can be read out in parallel format. Error flags are updated as well upon return to “idle” mode, and cleared when data are read out of the receiver. At the falling edge of read, the contents of the rhr are latched to the data bus. In table 8 shown below are the various error checks supported by the receiver.Simulation of a receive sequence.Between successive transmissions, the transmission line is held high. At the falling edge of rx input, the internal rxcnt starts counting up, synchronous to mclkx16. If rx input stays low for 8 cycles of mclkx16, the internal status bit idle is reset, and there by enable generation of rxclk. Rxclk is now synchronized to the center point of the low start bit. At the rising edge of rxclk, data are shifted from the rx input to rsr. When the leading low start bit
展开阅读全文