The Verilog Golden Reference Guide

3y ago
113 Views
4 Downloads
368.47 KB
151 Pages
Last View : Today
Last Download : 3m ago
Upload by : Genevieve Webb
Transcription

TheVerilog GoldenReferenceGuideDOULOS

Version 1.0, August 1996 Copyright 1996, Doulos, All Rights Reserved.No part of this publication may be reproduced, stored in a retrievalsystem, or transmitted, in any form or by any means, electronic,mechanical, photocopying, recording or otherwise, without theprior written permission of DOULOS. Printed in the UnitedKingdom of Great Britain and Northern Ireland.Verilog-XLTM is a trademark and Verilog a registered trademark ofCadence Design Systems Inc.DOULOSChurch Hatch,22 Market Place,Ringwood.Hampshire.BH24 1AWEngland.Tel ( 44) (0)1425 471223Fax ( 44) (0)1425 471573Email info@doulos.co.ukURL http://www.doulos.co.uk

PrefaceThe Verilog Golden Reference Guide is a compact quick referenceguide to the Verilog hardware description language, its syntax,semantics, synthesis and application to hardware design.The Verilog Golden Reference Guide is not intended as areplacement for the IEEE Standard Verilog Language ReferenceManual. Unlike that document, the Golden Reference guide does notoffer a complete, formal description of Verilog. Rather, it offersanswers to the questions most often asked during the practicalapplication of Verilog, in a convenient reference format.Nor is The Verilog Golden Reference Guide intended to be anintroductory tutorial. Information is presented here in a tersereference format, not in the progressive and sympathetic mannernecessary to learn a subject as complex as Verilog. However,acknowledging that those already familiar with computer languagesmay wish to use this guide as a Verilog text book, a brief informalintroduction to the subject is given at the start.The main feature of The Verilog Golden Reference Guide is that itembodies much practical wisdom gathered over many Verilogprojects. It does not only provide a handy syntax reference; there aremany similar books which perform that task adequately. It alsowarns you of the most common language errors, gives clues whereto look when your code will not compile, alerts you to synthesisissues, and gives advice on improving your coding style.The Verilog Golden Reference Guide was developed to add value tothe Doulos range of Verilog training courses, and also to complementHDL PaceMaker, the Verilog Computer Based Training packagefrom Doulos.3

Using This GuideThe main body of this guide is divided into three main parts, each ofwhich is organised alphabetically. Each section is indexed by a keyterm which appears prominently at the top of each page. Often youcan find the information you want by flicking through the guidelooking for the appropriate key term. If that fails, there is a full indexat the back.Most of the information in this guide is organised around the Verilogsyntax headings, but there are additional special sections on CodingStandards, Design Flow, Errors, Reserved Words and, after the mainalphabetical reference section, Compiler Directives, System Tasksand Functions and Command Line Options.If you are new to Verilog, you should start by reading A BriefIntroduction to Verilog, which follows overleaf.The IndexBold index entries have corresponding pages in the main body of theguide. The remaining index entries are followed by a list ofappropriate page references in the alphabetical reference sections,given in order of importance.Key To Notation Used To Define Verilog SyntaxThe syntax definitions are written to look like examples whereverpossible, but it has been necessary to introduce some extra notation.In brief, square brackets [] enclose optional items, three dots . meansrepetition, and curly brackets {} enclose comments. ItalicNamesrepresent parts of the syntax defined elsewhere. A full description ofthe notation follows:Curly brackets {} enclose comments that are not part of the Verilogsyntax being defined, but give you further information about thesyntax definition. Bold curly brackets {} are part of the Verilog syntax(concatenation operator).Syntax enclosed in square brackets [] is optional. Bold squarebrackets [] are part of the Verilog syntax (vector range, bit and partselect, memory element). means zero or more repetitions of the preceding item or line, ormeans a list, as follows:Item . means zero or more repetitions of the Item., . means repeat in a comma separated list (e.g. A, B, C).4

There must be at least one item in the list. There is no , at the end ofthe list.Words in lower-case letters are reserved words, built into the Veriloglanguage (e.g. module)Capitalised Words (not in italics) are Verilog identifiers, i.e. userdefined names that are not reserved identifiers (e.g. InstanceName).Italic Words are syntactic categories, i.e. the name of a syntaxdefinition given in full elsewhere. A syntactic category can be eitherdefined on the same page, defined on a separate page, or one of thespecial categories defined below.Italics indicates a syntactic category which is defined and used onthe same page.Special syntactic categories:MinTypMaxExpression is defined with Expression.UnsignedNumber is defined with Number.SomethingExpression Expression, where the Something givesinformation about the meaning of the expression (e.g.ConstantExpression, ConstantMinTypMaxExpression).5

A Brief Introduction To VerilogThe following paragraphs give a brief technical introduction toVerilog suitable for the reader with no prior knowledge of thelanguage.BackgroundThe Verilog Hardware Description Language (HDL) is a language fordescribing the behaviour and structure of electronic circuits, and isan IEEE standard (IEEE Std. 1364-1995).Verilog is used to simulate the functionality of digital electroniccircuits at levels of abstraction ranging from stochastic and purebehaviour down to gate and switch level, and is also used tosynthesize (i.e. automatically generate) gate level descriptions frommore abstract (Register Transfer Level) descriptions. Verilog iscommonly used to support the high level design (or language baseddesign) process, in which an electronic design is verified by means ofthorough simulation at a high level of abstraction before proceedingto detailed design using automatic synthesis tools. Verilog is alsowidely used for gate level verification of ICs, including simulation,fault simulation and timing verification.The Verilog HDL was originally developed together with theVerilog-XL simulator by Gateway Design Automation, andintroduced in 1984. In 1989 Cadence Design Systems acquiredGateway, and with it the rights to the Verilog language and theVerilog-XL simulator. In 1990 Cadence placed the Verilog language(but not Verilog-XL) into the public domain. A non profit makingorganisation, Open Verilog International (OVI) was formed with thetask of taking the language through the IEEE standardizationprocedure, and Verilog became an IEEE standard in 1995. OVI willcontinue to maintain and develop the language.The LanguageIn this section as in the rest of the guide, words given in CapitalisedItalics are technical terms whose definitions may be found in themain body of this guide.An hierarchical portion of a hardware design is described in Verilogby a Module. The Module defines both the interface to the block ofhardware (i.e. the inputs and outputs) and its internal structure orbehaviour.A number of primitives, or Gates, are built into the Verilog language.They represent basic logic gates (e.g. and, or). In addition UserDefined Primitives (UDPs) may be defined.6

The structure of an electronic circuit is described by making Instancesof Modules and Primitives (UDPs and Gates) within a higher levelModule, and connecting the Instances together using Nets. A Netrepresents an electrical connection, a wire or a bus. A list of Portconnections is used to connect Nets to the Ports of a Module orPrimitive Instance, where a Port represents a pin. Registers (see below)may also be connected to the input Ports (only) of an Instance.Nets (and Registers) have values formed from the logic values 0, 1, X(unknown or uninitialised) and Z (high impedance or floating). Inaddition to logic values, Nets also have a Strength value. Strengths areused extensively in switch level models, and to resolve situationswhere a net has more than one driver.The behaviour of an electronic circuit is described using Initial andAlways constructs and Continuous Assignments. Along with UDPs andGates these represent the leaves in the hierarchy tree of the design.Each Initial, Always, Continuous Assignment, UDP and Gate Instanceexecutes concurrently with respect to all others, but the Statementsinside an Initial or Always are in many ways similar to the statementsin a software programming language. They are executed at timesdictated by Timing Controls, such as delays, and (simulation) eventcontrols. Statements execute in sequence in a Begin-End block, or inparallel in a Fork-Join block. A Continuous Assignment modifies thevalues of Nets. An Initial or Always modifies the values of Registers.An Initial or Always can be decomposed into named Tasks andFunctions, which can be given arguments. There are also a number ofbuilt in System Tasks and Functions. The Programming LanguageInterface (PLI) is an integral part of the Verilog language, andprovides a means of calling functions written in C in the same way asSystem Tasks and Functions.CompilationVerilog source code is usually typed into one or more text files on acomputer. Those text files are then submitted to a Verilog compileror interpreter which builds the data files necessary for simulation orsynthesis. Sometimes simulation immediately follows compilationwith no intermediate data files being created.7

Syntax SummaryModule Structuremodule M (P1, P2, P3, P4);input P1, P2;output [7:0] P3;inout P4;reg [7:0] R1, M1[1:1024];wire W1, W2, W3, W4;parameter C1 "This is a string";initialbegin : BlockName// Statementsendalwaysbegin// Statementsend// Continuous assignments.assign W1 Expression;wire (Strong1, Weak0) [3:0] #(2,3) W2 Expression;// Module instances.COMP U1 (W3, W4);COMP U2 (.P1(W3), .P2(W4));task T1;input A1;inout A2;output A3;begin// Statementsendendtaskfunction [7:0] F1;input A1;begin// StatementsF1 Expression;endendfunctionendmodule8

Statements#delaywait (Expression)@(A or B or C)@(posedge Clk)Reg Expression;Reg Expression;VectorReg[Bit] Expression;VectorReg[MSB:LSB] Expression;Memory[Address] Expression;assign Reg Expressiondeassign Reg;TaskEnable(.);disable TaskOrBlock;- EventName;if (Condition).else if (Condition).else.case (Selection)Choice1 :.Choice2, Choice3 :.default :.endcasefor (I 0; I MAX; I I 1).repeat (8).while (Condition).forever.This quick reference syntax summary does not follow the notational conventionsused in the rest of the Guide.9

10

TheVerilogGoldenReferenceGuideAlphabetical Reference Section11

AlwaysContains one or more statements (procedural assignments, task enables, if,case and loop statements), which are executed repeatedly throughout asimulation run, as directed by their timing controls.SyntaxalwaysStatementWheremodule- HERE -endmoduleRulesOnly registers (reg, integer, real, time, realtime) may be assigned in analways.Every always starts executing at the start of simulation, and continuesexecuting throughout simulation; when the last statement in the always isreached, execution continues from the top of the always.Gotchas!An always containing more than one statement must enclose the statementsin a begin-end or fork-join block.An always with no timing controls will loop forever.Synthesisalways is one of the most useful Verilog statements for synthesis, yet analways is often unsynthesizable. For best results, code should be restrictedto one of the following templates:always @(Inputs)begin.end// All the inputsalways @(Inputs)if (Enable)begin.end// All the inputs// Combinational logic// Latched actions12

always @(posedge Clock) // Clock onlybegin.// Synchronous actionsendalways @(posedge Clock or negedge Reset)// Clock and Reset onlybeginif (!Reset)// Test active level of asynchronous reset.// Asynchronous actionselse.// Synchronous actionsend// Gives flipflops logicExampleThe following example shows a Register Transfer Level always:always @(posedge Clock or negedge Reset)beginif (!Reset)// Asynchronous resetCount 0;elseif (!Load)// Synchronous loadCount Data;elseCount Count 1;endThe following example shows an always which describes combinational logic:always @(A or BbeginR {A, B, C,F 0;begin : Loopinteger I;for (I 0;if (R[I])beginF I;disableendend // Loopendor C or D)D}I 4; I I 1)Loop;See AlsoBegin, Fork, Initial, Statement, Timing Control13

BeginUsed to group statements, so that they execute in sequence. The Verilogsyntax often requires exactly one statement, for example in an always. Ifmore than one statement is needed, the statements may be included in abegin-end block.Syntaxbegin [: Label[ Declarations.]]Statements.endDeclaration {either} Register Parameter EventWhereSee Statement.RulesA begin-end block must contain at least one statement.Statements in a begin-end block are executed in sequence. Timing controlsare relative to the previous statement. The begin-end block completes whenthe bottom-most statement has completed.Begin-end and fork-join blocks may be nested within themselves and eachother.If a begin-end block is to contain local declarations, it must be named (i.e. itmust have a label).If a begin-end block is to be disabled, it must be named.Gotchas!The Verilog LRM allows begin-end blocks to be interleaved during simulation.This means that even where a begin-end block contains two adjacentstatements with no timing control between them, a simulator may choose toexecute part of another process (E.g. statements in another always) betweenthe two statements. This is a source of non-determinism in the language.TipsBegin-end blocks can be labelled to improve readability, even if there are nolocal declarations, and the block is not to be disabled.Use local declarations for registers that will not be used elsewhere. Thismakes the intent of the declaration explicit.14

Exampleinitialbegin : GenerateInputsinteger I;for (I 0; I 8; I I 1)#Period {A, B, C} I;endinitialbeginLoad 0;Enable 0;Reset 0;#10 Reset 1;#25 Enable 1;#100 Load 1;end// Time 0// Time 10// Time 35// Time 135See AlsoFork, Disable, Statement.15

CaseA statement which conditionally executes at most one branch, depending onthe value of the case expression.SyntaxCaseKeyword (Expression)Expression,. : StatementExpression,. : Statement.[default [:] Statement]endcase{Expression may be variable}{Any number of cases}{Need not be at the end}CaseKeyword {either} case casex casezWhereSee Statement.RulesXs and Zs in a casex statement, and Zs in a casez statement mean “don’tcare”.One default statement at most may be included. It is executed if no labelexpressions match the case expression. (A ‘label’ is an expression or acomma-separated list of expressions on the left of a colon, or the reservedword default, which may or may not be followed by a colon.)Where a label is a comma-separated list of two or more expressions, the labelis matched if the case expression matches any one of the label expressions.If no label expressions match the case expression and there is no defaultstatement, the case statement has no effect.Gotchas!If more than one statement is to be executed for a particular label, thestatements must be enclosed in a begin-end or fork-join block.A branch is only executed if the corresponding label is the first one to matchthe case expression. Case labels need not be mutually exclusive, so aVerilog compiler will not report an error where the same label has erroneouslybeen repeated.The syntax of a casex or casez statement ends with the reserved wordendcase, not endcasex or endcasez.An X or Z in the casex expression or a Z in a casez expression is matchedwith any value in a case label. This may give confusing simulation results.SynthesisAssignments within case statements generally synthesize to multiplexers. Ifvariables (i.e. registers or nets) are used for case labels, priority encodersmay be synthesized.16

Incomplete assignments (i.e. where outputs remain unassigned for certaininput conditions) in an unclocked always synthesize to transparent latches.Incomplete assignments in a clocked always synthesize to recirculationaround registers.TipsFor simulation, always use default as the last case statement, to trap illegalconditions.casez is usually preferable to casex, because the presence of Xs insimulation may give misleading or confusing results.Use the alternative character ? for Z in casex and casez labels. This makes itclear that a “don’t care” value and not a high impedance value is intended.Examplecase (Address)0 : A 1;// Select a single Address value1 : begin// Execute more than one statementA 1;B 1;end2, 3, 4 : C 1;// Pick out several Address valuesdefault :// Mop up the rest display("Illegal Address value %h in %m at %t",Address, realtime);endcasecasex (Instruction)8'b000xxxxx : Valid 1;8'b1xxxxxxx : Neg 1;defaultbeginValid 0;Neg 0;endendcasecasez ({A, B,8'b1?8'b010?8'b001?00default :endcaseC, D, E[3:0]}): Op 2'b00;: Op 2'b01;: Op 2'b10;Op 2'bxx;See AlsoIf17

Coding StandardsCoding standards are divided into two categories. Lexical coding standards,which control text layout, naming conventions and commenting, are intendedto improve readability and ease of maintenance. Synthesis coding standards,which control Verilog style, are intended to avoid common synthesis pitfallsand find synthesis errors early in the design flow.The following lists of coding standards will need to be modified according tothe choice of tools and personal preferences.Lexical Coding StandardsLimit the contents of each Verilog source file to one module, and do not splitmodules across files.Source file names should relate to the file contents (e.g. ModuleName.v).Write only one declaration or statement per line.Use indentation as shown in the examples.Be consistent about the case of user defined names (e.g. first letter a capital).User defined names should be meaningful and informative, although localnames (e.g. loop variables) may be terse.Write comments to explain (not duplicate) the Verilog code. It is particularlyimportant to comment interfaces (e.g. module parameters, ports, task andfunction arguments).Use parameters or define macros wherever possible, instead of directlyembedding literal numbers and strings in declarations and statements.Synthesis Coding StandardsPartition the design into small functional blocks, and use a behavioural stylefor each block. Avoid gate level descriptions except for critical parts of thedesign.Have a well defined clocking strategy, and implement that strategy explicitly inVerilog (e.g. single clock, multi-phase clocks, gated clocks, multiple clockdomains). Ensure that clock and reset signals in Verilog are clean (i.e. notgenerated from combinational logic or unintentionally gated).Have a well defined (manufacturing) testing strategy, and code up the Verilogappropriately (e.g. all flipflops resettable, test access from external pins, nofunctional redundancy).Every Verilog always should conform to one of the standard synthesizableprocess templates (see Always).An always describing combinational and latched logic must have all of theinputs in the event control list at the top of the always.A combinational always must not contain incomplete assignments, i.e. alloutputs must be assigned for all combinations of input values.An always describing combinational and latched logic must not containfeedback, i.e. registers assigned as outputs from the always must not beread as inputs to the always.18

A clocked always must have only the clock and any asynchronous controlinputs (usually reset or set) in the event control list.Avoid unwanted latches. Unwant

The Verilog Golden Reference Guide is a compact quick reference guide to the Verilog hardware description language, its syntax, semantics, synthesis and application to hardware design. The Verilog Golden Reference Guide is not intended as a replacement for the IEEE Standard Verilog Language Reference Manual.

Related Documents:

May 02, 2018 · D. Program Evaluation ͟The organization has provided a description of the framework for how each program will be evaluated. The framework should include all the elements below: ͟The evaluation methods are cost-effective for the organization ͟Quantitative and qualitative data is being collected (at Basics tier, data collection must have begun)

Silat is a combative art of self-defense and survival rooted from Matay archipelago. It was traced at thé early of Langkasuka Kingdom (2nd century CE) till thé reign of Melaka (Malaysia) Sultanate era (13th century). Silat has now evolved to become part of social culture and tradition with thé appearance of a fine physical and spiritual .

Verilog-A HDL Overview 1.1 Overview This Verilog-A Hardware Description Language (HDL) language reference manual defines a behavioral language for analog systems. Verilog-A HDL is derived from the IEEE 1364 Verilog HDL specification. This document is intended to cover the definition and semantics of Verilog-A HDL as proposed by Open Verilog .

On an exceptional basis, Member States may request UNESCO to provide thé candidates with access to thé platform so they can complète thé form by themselves. Thèse requests must be addressed to esd rize unesco. or by 15 A ril 2021 UNESCO will provide thé nomineewith accessto thé platform via their émail address.

̶The leading indicator of employee engagement is based on the quality of the relationship between employee and supervisor Empower your managers! ̶Help them understand the impact on the organization ̶Share important changes, plan options, tasks, and deadlines ̶Provide key messages and talking points ̶Prepare them to answer employee questions

Dr. Sunita Bharatwal** Dr. Pawan Garga*** Abstract Customer satisfaction is derived from thè functionalities and values, a product or Service can provide. The current study aims to segregate thè dimensions of ordine Service quality and gather insights on its impact on web shopping. The trends of purchases have

Verilog PLI Tutorial ? : 20% Complete What's new in Verilog 2001? : 50% Complete Verilog Quick Reference. Verilog in One Day : This tutorial is in bit lighter sense, with humor, So take it cool and enjoy. INTRODUCTION Introduction. Verilog is a HARDWARE DESCRIPTION LANGUAGE (HDL). A hardware

The API is most useful when there is a need to automate a well-defined workflow, such as repeating the same tasks to configure access control for new vRealize Operations Manager users. The API is also useful when performing queries on the vRealize Operations Manager data repository, such as retrieving data for particular assets in your virtual environment. In addition, you can use the API to .