第七章 行为级建模双语版_第1页
第七章 行为级建模双语版_第2页
第七章 行为级建模双语版_第3页
第七章 行为级建模双语版_第4页
第七章 行为级建模双语版_第5页
已阅读5页,还剩100页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

(1)2024/3/12HardwareDescriptionLanguages

硬件描述语言

青岛科技大学信息学院宋廷强songtq@163.com

2024/3/1227BehavioralModeling

行为级建模(3)2024/3/12Main

contents本章学习目标Explainthesignificanceofstructuredproceduresalwaysandinitialinbehavioralmodeling.掌握结构化过程always和initial在行为级建模中的方法。Defineblockingandnonblockingproceduralassignments.掌握阻塞(blocking)和非阻塞(non-blocking)过程性赋值语句的定义方法。Understanddelay-basedtimingcontrolmechanisminbehavioralmodeling.Useregulardelays,intra-assignmentdelays,andzerodelays.理解行为级建模中基于延迟的时序控制机制。学习使用一般延迟、内嵌赋值延迟和零延迟。Describeevent-basedtimingcontrolmechanisminbehavioralmodeling.Useregulareventcontrol,namedeventcontrol,andeventORcontrol.理解行为级建模中基于事件的时序控制机制。学习使用一般事件控制、命名事件控制和事件OR(或)控制。(4)2024/3/12Uselevel-sensitivetimingcontrolmechanisminbehavioralmodeling.理解行为级建模中使用电平敏感的时序控制机制。Explainconditionalstatementsusingifandelse.掌握使用if和else解释条件语句。Describemultiwaybranching,usingcase,casex,andcasezstatements.掌握使用case,casex和casez语句讲解多路分支。Understandloopingstatementssuchaswhile,for,repeat,andforever.掌握使用while,for,repeat和forever等循环语句。Definesequentialandparallelblocks.掌握定义顺序块和并行块语句。Understandnamingofblocksanddisablingofnamedblocks.理解命名块和命名块的禁用。Usebehavioralmodelingstatementsinpracticalexamples.在设计实例中进行行为级建模。Verilogprovidesdesignerstheabilitytodescribedesignfunctionalityinanalgorithmicmanner.Inotherwords,thedesignerdescribesthebehaviorofthecircuit.Thus,behavioralmodelingrepresentsthecircuitataveryhighlevelofabstraction.提供的Verilog设计人员描述一个算法的方式设计功能的能力。换言之,设计者描述的电路的行为。因此,行为建模表示电路的抽象一个非常高的水平。DesignatthislevelresemblesCprogrammingmorethanitresemblesdigitalcircuitdesign.在这个级别的设计,类似于C语言编程也类似于数字电路设计。(5)2024/3/12(6)2024/3/12BehavioralVerilogconstructsaresimilartoClanguageconstructsinmanyways.Verilogisrichinbehavioralconstructsthatprovidethedesignerwithagreatamountofflexibility.行为级Verilog结构体在许多方面似于C语言语法结构。Verilog的丰富的行为结构为设计人员提供极大的灵活性。7.1StructuredProceduresTherearetwostructuredprocedurestatementsinVerilog:alwaysandinitial.Thesestatementsarethetwomostbasicstatementsinbehavioralmodeling.Allotherbehavioralstatementscanappearonlyinsidethesestructuredprocedurestatements.在Verilog中有两种结构化的过程语句:initial语句和always语句,它们是行为级建模的两种基本语句。其他所有的行为语句只能出现在这两种结构化过程语句里。(7)2024/3/12(8)2024/3/12VerilogisaconcurrentprogramminglanguageunliketheCprogramminglanguage,whichissequentialinnature.ActivityflowsinVerilogruninparallelratherthaninsequence.EachalwaysandinitialstatementrepresentsaseparateactivityflowinVerilog.Eachactivityflowstartsatsimulationtime0.Thestatementsalwaysandinitialcannotbenested.Thefundamentaldifferencebetweenthetwostatementsisexplainedinthefollowingsections.与C语言不同,Verilog在本质上是并发而非顺序的。Verilog中的各个执行流程(进程)并发执行,而不是顺序执行的。每个initial语句和always语句代表一个独立的执行过程,每个执行过程从仿真时间0开始执行,并且这两种语句不能嵌套使用。7.1.1initialStatementAllstatementsinsideaninitialstatementconstituteaninitialblock.所有在initial语句内的语句构成了一个initial块。

Aninitialblockstartsattime0,executesexactlyonceduringasimulation,andthendoesnotexecuteagain.initial块从仿真0时刻开始执行,在整个仿真过程中只执行一次。Iftherearemultipleinitialblocks,eachblockstartstoexecuteconcurrentlyattime0.如果一个模块中包括了若干个initial块,则这些initial块从仿真0时刻开始并发执行,且每个块的执行是各自独立的。(9)2024/3/12(10)2024/3/12Eachblockfinishesexecutionindependentlyofotherblocks.Multiplebehavioralstatementsmustbegrouped,typicallyusingthekeywordsbeginandend.Ifthereisonlyonebehavioralstatement,groupingisnotnecessary.如果在块内包含了多条行为语句,那么需要将这些语句组成一组,一般是使用关键字begin和end将它们组合为一个块语句;如果块内只有一条语句,则不必使用begin和end。Thisissimilartothebegin-endblocksinPascalprogramminglanguageorthe{}groupingintheCprogramminglanguage.Example7-1illustratestheuseoftheinitialstatement.这一点类似于Pascal语言中的begin和end块或C语言中的{}语句块。例7.1给出了使用initial语句的例子。Example7-1initialStatement(11)2024/3/12Theinitialblocksaretypicallyusedforinitialization,monitoring,waveformsandotherprocessesthatmustbeexecutedonlyonceduringtheentiresimulationrun.Thefollowingsubsectionsdiscussionhowtoinitializevaluesusingalternateshorthandsyntax.Theuseofsuchshorthandsyntaxhasthesameeffectasaninitialblockcombinedwithavariabledeclaration.由于initial块语句在整个仿真期间只能执行一次,因此它一般被用于初始化,信号监视,生成仿真波形等目的。在下面的小结中,我们讨论如何使用另一种简洁的语法来进行初始化。这种方法与initial语句和变量声明的组合具有相同的效果。(12)2024/3/12timestatementexecuted0m=1'b0;5a=1'b1;10x=1'b0;30b=1'b0;35y=1'b1;50$finish;CombinedVariableDeclarationandInitialization在变量声明的同时进行初始化(13)2024/3/12Example7-3CombinedPort/DataDeclarationandVariableInitializationmoduleadder(sum,co,a,b,ci);outputreg[7:0]sum=0;//Initialize8bitoutputsumoutputregco=0;//Initialize1bitoutputcoinput[7:0]a,b;inputci;----endmoduleCombinedANSICStylePortDeclarationandInitializationANSIC风格端口声明的声明初始化(14)2024/3/12moduleadder(outputreg[7:0]sum=0,//Initialize8bitoutputoutputregco=0,//Initialize1bitoutputcoinput[7:0]a,b,inputci);----endmoduleExample7-4CombinedANSICPortDeclarationandVariableInitialization7.1.2alwaysStatementAllbehavioralstatementsinsideanalwaysstatementconstituteanalwaysblock.Thealwaysstatementstartsattime0andexecutesthestatementsinthealwaysblockcontinuouslyinaloopingfashion.Thisstatementisusedtomodelablockofactivitythatisrepeatedcontinuouslyinadigitalcircuit.Anexampleisaclockgeneratormodulethattogglestheclocksignaleveryhalfcycle.Inrealcircuits,theclockgeneratorisactivefromtime0toaslongasthecircuitispoweredon.Example7-5illustratesonemethodtomodelaclockgeneratorinVerilog.always语句包括的所有行为语句构成了一个always语句块。该always语句块从仿真0时刻开始顺序执行其中的行为语句;在最后一条执行完成后,再次开始执行其中的第一条语句,如此循环往复,直至整个仿真结束。(15)2024/3/12(16)2024/3/12always语句通常用于对数字电路中一组反复执行的活动进行建模。例如时钟信号发生器,每半个时钟周期时钟信号翻转一次。在现实电路中只要电源接通,时钟信号发生器从时刻0就有效,一直工作下去。例7.5说明了用Verilog语言为时钟发生器建立模型的一种方法。Example7-5alwaysStatementmoduleclock_gen(outputregclock);//Initializeclockattimezeroinitialclock=1'b0;//Toggleclockeveryhalf-cycle(timeperiod=20)always#10clock=~clock;initial#1000$finish;endmodule(17)2024/3/12InExample7-5,thealwaysstatementstartsattime0andexecutesthestatementclock=~clockevery10timeunits.在例7.5中,always语句从仿真0时刻起,每隔10个时间单位执行一次对clock信号的取反操作。Noticethattheinitializationofclockhastobedoneinsideaseparateinitialstatement.Ifweputtheinitializationofclockinsidethealwaysblock,clockwillbeinitializedeverytimethealwaysisentered.Also,thesimulationmustbehaltedinsideaninitialstatement.Ifthereisno$stopor$finishstatementtohaltthesimulation,theclockgeneratorwillrunforever.注意,在这个例子中,clock信号是在initial语句中进行的初始化的;如果我们将初始化语句放在always块内,那么always语句的每次执行都会导致clock被初始化,而不是像initial那样只执行一次。如果我们没有使用($finish)或者($stop)语句停止仿真,那么这个时钟发生器将一直初始化。(18)2024/3/12(19)2024/3/12Cprogrammersmightdrawananalogybetweenthealwaysblockandaninfiniteloop.Buthardwaredesignerstendtoviewitasacontinuouslyrepeatedactivityinadigitalcircuitstartingfrompoweron.Theactivityisstoppedonlybypoweroff($finish)orbyaninterrupt($stop).从C语言角度来看,always类似于一个无限循环;而从硬件设计角度看,always反映了硬件电路通电之后连续地反复执行的特点。这种执行职能通过断电($finish)或者中断($stop)来停止7.2ProceduralAssignmentsProceduralassignmentsupdatevaluesofreg,integer,real,ortimevariables.Thevalueplacedonavariablewillremainunchangeduntilanotherproceduralassignmentupdatesthevariablewithadifferentvalue.TheseareunlikecontinuousassignmentsdiscussedinChapter6,DataflowModeling,whereoneassignmentstatementcancausethevalueoftheright-hand-sideexpressiontobecontinuouslyplacedontotheleft-hand-sidenet.Thesyntaxforthesimplestformofproceduralassignmentisshownbelow.过程赋值语句的更新对象是寄存器、整数、实数或时间变量。这些类型的变量在被赋值后,其值将保持不变,直到被其他过程赋值语句赋予新值。这与连续赋值语句是不同的,连续赋值语句总是处于活动状态,任意一个操作数的变化会导致表达式的重新计算并且重新赋值。但是过程赋值语句只有在执行到得时候才起作用。过程赋值语句最简单的语法形式如下:assignment::=variable_lvalue=[delay_or_event_control]expression(20)2024/3/12Theleft-handsideofaproceduralassignment<lvalue>canbeoneofthefollowing:过程赋值语句的左侧值可以是:Areg,integer,real,ortimeregistervariableoramemoryelementreg,整型数、实型数、时间寄存器变量或存储器单元。Abitselectofthesevariables(e.g.,addr[0])上述各种类型的位选(例如,addr[0])。Apartselectofthesevariables(e.g.,addr[31:16])上述各种类型的域选(例如,addr[31:16])。Aco上面三种类型的拼接。ncatenationofanyoftheabove(21)2024/3/12Theright-handsidecanbeanyexpressionthatevaluatestoavalue.Inbehavioralmodeling,alloperatorslistedinTable6-1onpage96canbeusedinbehavioralexpressions.赋值符的右侧可以是任意类型的合法表达式,在表达式中可以使用表6.1列出的所有操作符。Therearetwotypesofproceduralassignmentstatements:blockingandnonblocking.Verilog包括两种类型的过程赋值语句:阻塞赋值和非阻塞赋值语句(22)2024/3/127.2.1BlockingAssignmentsBlockingassignmentstatementsareexecutedintheordertheyarespecifiedinasequentialblock.Ablockingassignmentwillnotblockexecutionofstatementsthatfollowinaparallelblock.BothparallelandsequentialblocksarediscussedinSection7.7,SequentialandParallelBlocks.The=operatorisusedtospecifyblockingassignments.串行块中的阻塞赋值语句按顺序执行,它不会阻塞其后并行块中语句的执行。我们将在7.7节中对串块和并行块进行讨论。阻塞赋值语句使用“=”作为赋值符。(23)2024/3/12Example7-6BlockingStatementsregx,y,z;reg[15:0]reg_a,reg_b;integercount;//Allbehavioralstatementsmustbeinsideaninitialoralwaysblockinitialbeginx=0;y=1;z=1;//Scalarassignmentscount=0;//Assignmenttointegervariablesreg_a=16'b0;reg_b=reg_a;//initializevectors#15reg_a[2]=1'b1;//Bitselectassignmentwithdelay#10reg_b[15:13]={x,y,z}//Assignresultofconcatenationto//partselectofavectorcount=count+1;//Assignmenttoaninteger(increment)end(24)2024/3/12InExample7-6,thestatementy=1isexecutedonlyafterx=0isexecuted.Thebehaviorinaparticularblockissequentialinabegin-endblockifblockingstatementsareused,becausethestatementscanexecuteonlyinsequence.Thestatementcount=count+1isexecutedlast.Thesimulationtimesatwhichthestatementsareexecutedareasfollows:在例7.6中,只有在语句x=0执行完成后,才会执行y=1,而语句count=count+1按顺序在最后执行。由于阻塞赋值语句是按顺序执行的,因此如果在一个begin-end块中使用了阻塞赋值语句,那么这个块语句表现的是串行行为。在例7.6中,begin-end块中各条语句执行的时间为:Allstatementsx=0throughreg_b=reg_aareexecutedattime0X=0到仿真0时刻执行Statementreg_a[2]=0attime=15Statementreg_b[15:13]={x,y,z}attime=25Statementcount=count+1attime=25Sincethereisadelayof15and10intheprecedingstatements,count=count+1willbeexecutedattime=25units(25)2024/3/12(26)2024/3/12Allstatementsx=0throughreg_b=reg_aareexecutedattime0X=0到仿真0时刻执行Statementreg_a[2]=0attime=15reg_a[2]=0仿真时刻15执行Statementreg_b[15:13]={x,y,z}attime=25仿真时刻25执行Statementcount=count+1attime=25count=count+1仿真时刻25执行Sincethereisadelayof15and10intheprecedingstatements,count=count+1willbeexecutedattime=25units由于前面的语句中包含了15和10个单位的延迟,因此语句count=count+17.2.2NonblockingAssignmentsNonblockingassignmentsallowschedulingofassignmentswithoutblockingexecutionofthestatementsthatfollowinasequentialblock.A<=operatorisusedtospecifynonblockingassignments.Notethatthisoperatorhasthesamesymbolasarelationaloperator,less_than_equal_to.Theoperator<=isinterpretedasarelationaloperatorinanexpressionandasanassignmentoperatorinthecontextofanonblockingassignment.Toillustratethebehaviorofnonblockingstatementsanditsdifferencefromblockingstatements,letusconsiderExample7-7,whereweconvertsomeblockingassignmentstononblockingassignments,andobservethebehavior.非阻塞赋值语句允许赋值调度,但他不会阻塞位于同一个顺序块中后面语句的执行。非阻塞语句使用“<=”作为赋值符。“<=”在表达式中被解释为关系操作;“<=”在非阻塞赋值的环境下被解释成非阻塞赋值。为了说明非阻塞赋值语句的意义以及与阻塞赋值语句之间的区别,让我们来考虑例7.6中的部分阻塞赋值语句改为非阻塞语句的结果,例7.7给出了修改后的语句。(27)2024/3/12Example7-7NonblockingAssignmentsregx,y,z;reg[15:0]reg_a,reg_b;integercount;//AllbehavioralstatementsmustbeinsideaninitialoralwaysblockInitial所有的行为语句必须写在initial和

always块内beginx=0;y=1;z=1;//Scalarassignments变量赋值

count=0;//Assignmenttointegervariables整形变量赋值

reg_a=16‘b0;reg_b=reg_a;//Initializevectors向量的初始化

reg_a[2]<=#151‘b1;//Bitselectassignmentwithdelay带延迟的地位选赋值reg_b[15:13]<=#10{x,y,z};//Assignresultofconcatenationtopartselectofavector把拼接操作的结果赋值给向量的部分位count<=count+1;//Assignmenttoaninteger(increment)End//给整型变量赋值(28)2024/3/12Inthisexample,thestatementsx=0throughreg_b=reg_aareexecutedsequentiallyattime0.Thenthethreenonblockingassignmentsareprocessedatthesamesimulationtime.在本例中,语句通过reg_bx=0=reg_a在时间顺序执行。然后三个非阻塞在同一仿真时间处理。reg_a[2]=0isscheduledtoexecuteafter15units(i.e.,time=15)reg_b[15:13]={x,y,z}isscheduledtoexecuteafter10timeunits(i.e.,time=10)count=count+1isscheduledtobeexecutedwithoutanydelay(i.e.,time=0)(29)2024/3/12Thus,thesimulatorschedulesanonblockingassignmentstatementtoexecuteandcontinuestothenextstatementintheblockwithoutwaitingforthenonblockingstatementtocompleteexecution.Typically,nonblockingassignmentstatementsareexecutedlastinthetimestepinwhichtheyarescheduled,thatis,afteralltheblockingassignmentsinthattimestepareexecuted.因此,模拟器调度非阻塞赋值语句来执行,并继续在该块中的下一个语句,而无需等待非阻塞语句来完成执行。通常情况下,非阻塞赋值语句在其被调度,也就是说,在该时间步长的所有阻塞的分配被执行之后的时间步最后被执行。(30)2024/3/12(31)2024/3/12Intheexampleabove,wemixedblockingandnonblockingassignmentstoillustratetheirbehavior.However,itisrecommendedthatblockingandnonblockingassignmentsnotbemixedinthesamealwaysblock.在上面的例子中,我们用混合阻塞和非阻塞赋值来说明它们的行为。然而,我们建议不要在同一个always块中混合使用阻塞和非阻塞赋值语句。ApplicationofnonblockingassignmentsHavingdescribedthebehaviorofnonblockingassignments,itisimportanttounderstandwhytheyareusedindigitaldesign.Theyareusedasamethodtomodelseveralconcurrentdatatransfersthattakeplaceafteracommonevent.Considerthefollowingexamplewherethreeconcurrentdatatransferstakeplaceatthepositiveedgeofclock.在描述了非阻塞赋值的行为,理解他们为什么在数字化设计中是非常重要的。它们被用作一个方法来模拟多个并发数据传输所发生的公共事件之后。考虑下面的例子,其中三个并行数据传输发生在时钟的上升沿。always@(posedgeclock)beginreg1<=#1in1;reg2<=@(negedgeclock)in2^in3;reg3<=#1reg1;//Theoldvalueofreg1end(32)2024/3/12Ateachpositiveedgeofclock,thefollowingsequencetakesplaceforthenonblockingassignments.在每个时钟的上升沿,按以下顺序发生了非阻塞赋值。Areadoperationisperformedoneachright-hand-sidevariable,in1,in2,in3,andreg1,atthepositiveedgeofclock.Theright-hand-sideexpressionsareevaluated,andtheresultsarestoredinternallyinthesimulator.在每个时钟上升沿到来时读取in1,in2,in3和reg1,计算右侧表达式的值;Thewriteoperationstotheleft-hand-sidevariablesarescheduledtobeexecutedatthetimespecifiedbytheintra-assignmentdelayineachassignment,thatis,schedule"write"toreg1after1timeunit,toreg2atthenextnegativeedgeofclock,andtoreg3after1timeunit.对左值的赋值由仿真器调度到相应的仿真时刻,延迟时间由语句中内嵌的延迟值确定。在本例中,对reg1的赋值需要等一个时间单位,对reg2的赋值需要等到时钟信号下降沿到来的时刻,对reg3的赋值需要等一个时间单位;(33)2024/3/12(34)2024/3/12Thewriteoperationsareexecutedatthescheduledtimesteps.Theorderinwhichthewriteoperationsareexecutedisnotimportantbecausetheinternallystoredright-hand-sideexpressionvaluesareusedtoassigntotheleft-hand-sidevalues.每个赋值操作在被调度的仿真时刻完成。注意,对左侧变量的赋值使用的是由仿真器保存的表达式“旧值”。Thus,thefinalvaluesofreg1,reg2,andreg3arenotdependentontheorderinwhichtheassignmentsareprocessed.在本例中,对reg3赋值使用的是reg1的“旧值”,而不是在此之前对reg1赋予的新值,reg1的“旧值”是在赋值事件调度时由仿真器保存的。Example7-8NonblockingStatementstoEliminateRaceConditions//Illustration1:Twoconcurrentalwaysblockswithblocking//statementsalways@(posedgeclock)a=b;always@(posedgeclock)b=a;//Illustration2:Twoconcurrentalwaysblockswithnonblocking//statementsalways@(posedgeclock)a<=b;always@(posedgeclock)b<=a;(35)2024/3/12(36)2024/3/12However,nonblockingstatementsusedinIllustration2eliminatetheracecondition.Atthepositiveedgeofclock,thevaluesofallright-hand-sidevariablesare"read,"andtheright-hand-sideexpressionsareevaluatedandstoredintemporaryvariables.Duringthewriteoperation,thevaluesstoredinthetemporaryvariablesareassignedtotheleft-hand-sidevariables.Separatingthereadandwriteoperationsensuresthatthevaluesofregistersaandbareswappedcorrectly,regardlessoftheorderinwhichthewriteoperationsareperformed.Example7-9showshownonblockingassignmentsshowninIllustration2couldbeemulatedusingblockingassignments.例中,产生了竞争的情况:a=b和b=a,具体执行顺序的先后取决于所使用的仿真器,因此这段代码达不到交换a和b值的目的。在每个时钟上升沿到来的时候,仿真器读取每个操作数的值,进而计算表达式的值并保存在临时变量中;当赋值的时候,仿真器将这些保存的值赋予非阻塞赋值语句的左侧变量。

Example7-9ImplementingNonblockingAssignmentsusingBlockingAssignments例7-9中使用阻塞赋值实现非阻塞赋值(37)2024/3/12Fordigitaldesign,useofnonblockingassignmentsinplaceofblockingassignmentsishighlyrecommendedinplaceswhereconcurrentdatatransferstakeplaceafteracommonevent.Insuchcases,blockingassignmentscanpotentiallycauseraceconditionsbecausethefinalresultdependsontheorderinwhichtheassignmentsareevaluated.对于数字化设计,在发生阻塞赋值使用非阻塞赋值强烈建议在一个公共事件后并发的数据传输发生的地方。在这种情况下,阻塞赋值可能会导致竞态条件,因为最终结果取决于在其中分配的计算顺序上。(38)2024/3/12(39)2024/3/12Nonblockingassignmentscanbeusedeffectivelytomodelconcurrentdatatransfersbecausethefinalresultisnotdependentontheorderinwhichtheassignmentsareevaluated.Typicalapplicationsofnonblockingassignmentsincludepipelinemodelingandmodelingofseveralmutuallyexclusivedatatransfers.Onthedownside,nonblockingassignmentscanpotentiallycauseadegradationinthesimulatorperformanceandincreaseinmemoryusage.非阻塞赋值可以被有效地用于并行数据传输进行建模,因为最终的结果是不依赖于所述分配的计算顺序上。非阻塞赋值的典型应用包括多种相互独立的数据传输管道建模和模拟。在下行路上,非阻塞赋值可能会导致在模拟器性能退化和增加内存使用情况。7.3TimingControlsVariousbehavioraltimingcontrolconstructsareavailableinVerilog.InVerilog,iftherearenotimingcontrolstatements,thesimulationtimedoesnotadvance.Timingcontrolsprovideawaytospecifythesimulationtimeatwhichproceduralstatementswillexecute.Therearethreemethodsoftimingcontrol:delay-basedtimingcontrol,event-basedtimingcontrol,andlevel-sensitivetimingcontrol.Verilog中,通过指定过程赋值发生的时刻,来控制仿真时间向前推进。Verilog提供了三种时序控制方法:基于延迟的时序控制、基于事件的时序控制和电平敏感的时序控制。(40)2024/3/127.3.1Delay-BasedTimingControlDelay-basedtimingcontrolinanexpressionspecifiesthetimedurationbetweenwhenthestatementisencounteredandwhenitisexecuted.Weuseddelay-basedtimingcontrolstatementswhenwritingfewmodulesintheprecedingchaptersbutdidnotexplainthemindetail.Inthissection,wewilldiscussdelay-basedtimingcontrolstatements.Delaysarespecifiedbythesymbol#.Syntaxforthedelay-basedtimingcontrolstatementisshownbelow.基于延迟的时序控制出现在表达式中,它指定了语句开始执行到执行完成之间的时间间隔。我们在前面的章节写几个模块时,没有具体说明采用延迟型定时控制语句的方法。在本节中,我们将讨论基于延迟的时间控制语句。延迟是由符号#指定。基于延迟的定时控制语句如下所示。delay3::=#delay_value|#(delay_value[,delay_value[,delay_value]])delay2::=#delay_value|#(delay_value[,delay_value])delay_value::=unsigned_number|parameter_identifier|specparam_identifier|mintypmax_expression(41)2024/3/12Delay-basedtimingcontrolcanbespecifiedbyanumber,identifier,oramintypmax_expression.Therearethreetypesofdelaycontrolforproceduralassignments:regulardelaycontrol,intra-assignmentdelaycontrol,andzerodelaycontrol.基于延迟的时序控制可以由数字,标识符或表达式,需要在延迟值前加上关键字#。对于过程赋值,有三种类型的延迟控制:常规延迟控制、复制内嵌延迟控制和零延迟控制。(42)2024/3/12RegulardelaycontrolRegulardelaycontrolisusedwhenanon-zerodelayisspecifiedtotheleftofaproceduralassignment.UsageofregulardelaycontrolisshowninExample7-10.常规延迟控制位于赋值语句的左边,用于指定一个非零延迟值。例7.10所示。(43)2024/3/12Example7-10RegularDelayControlparameterlatency=20;//defineparameters定义参数parameterdelta=2;regx,y,z,p,q;//defineregistervariables定义寄存器变量initialbeginx=0;//nodelaycontrol没有延迟控制#10y=1;//delaycontrolwithanumber.Delayexecutionofy=1by10units延迟值是数字的延迟控制。第10个时间单位才执行y=1

#latencyz=0;//Delaycontrolwithidentifier.Delayof20units使用标识符的的延迟控制。延迟20个时间单位。#(latency+delta)p=1;//Delaycontrolwithexpression使用表达式控制的延迟

#yx=x+1;//Delaycontrolwithidentifier.Takevalueofy.使用标识符的的延迟控制。用v的值

#(4:5:6)q=0;//Minimum,typicalandmaximumdelayvalues.//Discussedingate-levelmodelingchapter.End最小,最大和典型延迟值,第五章已经讨论过(44)2024/3/12InExample7-10,theexecutionofaproceduralassignmentisdelayedbythenumberspecifiedbythedelaycontrol.Forbegin-endgroups,delayisalwaysrelativetotimewhenthestatementisencountered.Thus,y=1isexecuted10u在实例7-10中,程序分配的执行是通过延迟控制指定的数字延迟。对于begin-end块中的语句,延迟总是指遇到该赋值语句时,需要等待执行的相对时间。以例7.10中的语句来说明。

因为begin-end块中的第一条语句是在时刻0开始执行的,执行10个单元后,遇到第二条语句,于是执行y=1。(45)2024/3/12Intra-assignmentdelaycontrolInsteadofspecifyingdelaycontroltotheleftoftheassignment,itispossibletoassignadelaytotherightoftheassignmentoperator.Suchdelayspecificationalterstheflowofactivityinadifferentmanner.Example7-11showsthecontrastbetweenintra-assignmentdelaysandregulardelays.除了可以将延迟控制置于赋值语句之前,还可以将它嵌入到赋值语句中,放在赋值符的右边。这种延迟方式的效果与常规延迟赋值是完全不同的。在7.11中我们对两种延迟控制进行了比较。(46)2024/3/12(47)2024/3/12Notethedifferencebetweenintra-assignmentdelaysandregulardelays.Regulardelaysdefertheexecutionoftheentireassignment.Intra-assignmentdelayscomputetheright-hand-sideexpressionatthecurrenttimeanddefertheassignmentofthecomputedvaluetotheleft-hand-sidevariable.Intra-assignmentdelaysarelikeusingregulardelayswithatemporaryvariabletostorethecurrentvalueofaright-hand-sideexpression.注意常规延迟和内嵌赋值延迟的区别。对常规延迟,它推迟的是整个赋值语句的执行。对于内嵌赋值语句,仿真器首先立即计算出右侧表达式的值,推迟指定的时间之后,再将这个值赋予左侧变量。因此,内嵌延迟的效果相当于将表达式的值保存在临时变量中,然后使用常规延迟控制将这个值赋予左侧变量。(48)2024/3/12ZerodelaycontrolProceduralstatementsindifferentalways-initialblocksmaybeevaluatedatthesamesimulationtime.Theorderofexecutionofthesestatementsindifferentalways-initialblocksisnondeterministic.Zerodelaycontrolisamethodtoensurethatastatementisexecutedlast,afterallotherstatementsinthatsimulationtimeareexecuted.Thisisusedtoeliminateraceconditions.However,iftherearemultiplezerodelaystatements,theorderbetweenthemisnondeterministic.Example7-12illustrateszerodelaycontrol.

在同一仿真时刻,位于不同always和initial块中的过程语句有可能被同时计算,但是执行(赋值)顺序是不确定的,与使用的仿真器类型有关。在这种情况下,零延迟控制可以保证带零延迟控制的语句将在执行时刻相同的多条语句中最后执行,从而避免发生竞争。但需要注意的是,如果存在多条带有零延迟的语句,则它们之间的执行顺序也将是不确定的。(49)2024/3/12Example7-12ZeroDelayControlinitialbeginx=0;y=0;endinitialbegin#0x=1;//zerodelaycontrol零延迟控制#0y=1;end(50)2024/3/12InExample7-12,fourstatements—x=0,y=0,x=1,y=1—aretobeexecutedatsimulationtime0.However,sincex=1andy=1have#0,theywillbeexecutedlast.Thus,attheendoftime0,xwillhavevalue1andywillhavevalue1.Theorderinwhichx=1andy=1areexecutedisnotdeterministic.在例7.12中,具有零延迟,语句被最后执行,仿真0时刻结束时,x和y的值都为1,但它们的执行顺序是不确定的。Theaboveexamplewasusedasanillustration.However,using#0isnotarecommendedpractice.在实际设计中,尽量不要使用零延迟控制(51)2024/3/127.3.2Event-BasedTimingControlAneventisthechangeinthevalueonaregisteroranet.Eventscanbeutilizedtotriggerexecutionofastatementorablockofstatements.Therearefourtypesofevent-basedtimingcontrol:regulareventcontrol,namedeventcontrol,eventORcontrol,andlevel-sensitivetimingcontrol.在Verilog中,事件是指某一个寄存器或线网变量的值发生了变化。Verilog提供了4种类型的事件控制:常规事件控制、命名事件控制、OR(或)事件控制和电平敏感时序控制。(52)2024/3/12RegulareventcontrolThe@symbolisusedtospecifyaneventcontrol.Statementscanbeexecutedonchangesinsignalvalueoratapositiveornegativetransitionofthesignalvalue.Thekeywordposedgeisusedforapositivetransition,asshowninExample7-13.事件控制使用符号@来说明,语句继续执行的条件是信号的值发生变化、发生正向跳变和负向跳变。关键字posedge用于指明正向跳变,negedge用于指明负向跳变。如例7.13所示:(53)2024/3/12NamedeventcontrolVerilogprovidesthecapabilitytodeclareaneventandthentriggerandrecognizetheoccurrenceofthatevent(seeExample7-14).Theeventdoesnotholdanydata.Anamedeventisdeclaredbythekeywordevent.Aneventistriggeredbythesymbol->.Thetriggeringoftheeventisrecognizedbythesymbol@.Verilog语言提供了命名事件控制机制。用户可以在程序中声明event(事件)类型的变量,触发该变量,并且识别该事件是否已经发生。命名事件由关键字event声明,它不能保存任何值。事件的触发用符号->表示;判断事件是否发生使用符号@来识别。(54)2024/3/12(55)2024/3/12EventORControlSometimesatransitiononanyoneofmultiplesignalsoreventscantriggertheexecutionofastatementorablockofstatements.ThisisexpressedasanORofeventsorsignals.ThelistofeventsorsignalsexpressedasanORisalsoknownasasensitivitylist.Thekeywordorisusedtospecifymultipletriggers,asshowninExample7-15.有时,多个信号或者事件中发生的任意一个变化都能够触发语句或语句块的执行。在Verilog语言中,可以使用“或”表达式来表示这种情况。由关键词“or”连接的多个事件名或者信号名组成的列表称为敏感列表。关键词“or”用于表示这种关系,如例7.15所示。(56)2024/3/12Sensitivitylistscanalsobespecifiedusingthe

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论