Verilog HDL Quick Reference Guide New
Verilog HDL Quick Reference Guide New
Verilog HDL Quick Reference Guide New
Author: Nikola Jevtovi Computer Science Department School of Electrical Engineering University of Belgrade email: [email protected]
Reference
http://www.sutherland-hdl.com/
[email protected] Verilog HDL Quick Reference Guide 2
1. Hierarchy Scopes
Verilog HDL constructs that represent hierarchy scope are:
Module definitions Function definitions Task definitions Named statement blocks ( begin - end or fork - join) Specify blocks
Each scope has its own name space. An identifier name defined within a scope is unique to that scope. References to an identifier name will search first in the local scope, and then search upward through the scope hierarchy up to a module boundary.
[email protected] Verilog HDL Quick Reference Guide 4
2. Concurrency
The following Verilog HDL constructs are independent processes that are evaluated concurrently in simulation time:
3. Reserved Keywords
always and assign attribute begin buf bufif0 bufif1 case casex casez cmos deassign default defparam disable edge else end endattribute endcase endfunction endmodule endprimitive endspecify endtable endtask event for force forever fork function highz0 highz1 if ifnone initial inout input integer join medium module large macromodule nand negedge nmos nor not notif0 notif1 or output parameter pmos posedge primitive pull0 pull1 pulldown pullup rcmos real realtime reg release repeat rnmos rpmos rtran rtranif0 rtranif1 scalared signed small specify specparam strength strong0 strong1 supply0 supply1 table task time tran tranif0 tranif1 tri tri0 tri1 triand trior trireg unsigned vectored wait wand weak0 weak1 while wire wor xnor xor
4. Lexical Conventions
4.2 Comments
// begins a single line comment, terminated by a newline. /* begins a multi-line comment, terminated by a */.
4. Lexical Conventions
legal identifier name uppercase identifier is unique from xor keyword an escaped identifier (must be followed by a white space)
Verilog HDL Quick Reference Guide 8
4. Lexical Conventions
Logic Value Description 0 zero, low, or false 1 one, high, or true z or Z high impedance (tri-stated or floating) x or X unknown or uninitialized
4. Lexical Conventions
Strength Level 7 6 5 4 3 2 1 0
Strength Name
Specification Keyword
Display Mnemonic
Su0 St0 Pu0 Su1 St1 Pu1
supply0 supply1 Supply Drive strong0 strong1 Strong Drive pull0 pull1 Pull Drive large Large Capacitive weak0 weak1 Weak Drive medium Med. Capacitive small Small Capacitive High Impedance highz0 highz1
Verilog HDL Quick Reference Guide
La0
We0 Me0 Sm0 HiZ0
La1
We1 Me1 Sm1 HiZ1
10
4. Lexical Conventions
decimal
hexadecimal
[email protected]
d or D
h or H
0-9, _
0-9, a-f, A-F, x, X, z, Z, ?, _
Verilog HDL Quick Reference Guide 11
4. Lexical Conventions
12
4. Lexical Conventions
13
5. Module Definitions
Verilog HDL models are represented as modules. Syntax: Implicit Internal Connection (connects the port to an internal net or register of the same name )
module module_name (port_name, port_name, ... ); {module_items} endmodule
-
Explicit Internal Connection (connects the port to an internal signal with a different name, or a bit select, part select, or concatenation of internal signals)
5. Module Definitions
module_items are:
module port declarations data type declarations module instances primitive instances procedural blocks continuous assignments task definitions function definitions specify blocks
Module functionality may be: - Behavioral - modeled with procedural blocks or continuous assignment statements. - Structural - modeled as a netlist of module instances or primitive instances. - A combination of behavioral and structural.
15
5. Module Definitions
Module definitions may not be nested. Instead, modules instantiate other modules. Module definitions may be expressed using parameter constants. Each instance of a module may redefine the parameters to be unique to that instance. Module items may appear in any order, but port declarations and data type declarations should be listed before the ports or signals are referenced.
16
Syntax:
port_direction [port_size] port_name, port_name,... ; port_direction is declared as: - input for scalar or vector input ports. - output for scalar or vector output ports. - inout for scalar or vector bi-directional ports. port_size is a range from [ msb : lsb ]
Examples
input a,b,sel; output [7:0] result; inout [0:15] data_bus; input [15:12] addr; parameter word = 32; input [word-1:0] addr;
[email protected]
Notes 3 scalar ports little endian convention big endian convention msb:lsb may be any integer constant expressions may be used
17
Syntax:
register_type [size] variable_name , variable_name,...; register_type [size] memory_name [array_size]; net_type [size] #(delay) net_name , net_name , ... ; net_type (drive_strength) [size] #(delay) net_name = continuous_assignment ; trireg (capacitance_strength) [size] #(delay, decay_time) net_name, net_name,...; parameter constant_name = value,constant_name = value,...; specparam constant_name = value,constant_name = value,...; event event_name, event_name, ... ; delay (optional) may only be specified on net data types. size is a range from [msb : lsb]. array_size is from [ first_address : last_address] strength (opt.) specified as (strength1,strength0) or _(strength0,strength1) decay_time (opt.) The syntax is (rise_delay,fall_delay,decay_time)
[email protected] Verilog HDL Quick Reference Guide 18
19
Functionality wire or tri Simple interconnecting wire wor or trior Wired outputs OR together wand or triand Wired outputs AND together tri0 Pulls down when tri-stated tri1 Pulls up when tri-stated supply0 Constant logic 0 (supply strength) supply1 Constant logic 1 (supply strength) trireg Stores last value when tri-stated (capacitance strength)
Nets transfer both logic values and logic strengths. A net data type must be used when a signal is driven by the output of some device; a signal is also declared as an input port or inout port; a signal is on the left-hand side of a continuous assignment.
[email protected] Verilog HDL Quick Reference Guide 20
Other Types
parameter specparam event
21
wire a, b, c;
3 scalar nets tri1 [7:0] data_bus; 8-bit net, pulls-up when tri-stated reg [1:8] result; an 8-bit unsigned variable a memory array; 8-bits wide, reg [7:0] RAM [0:1023]; with 1K of addresses wire #(2.4,1.8) carry; a net with rise, fall delays net with drive strength and a wire (strong1,pull0) sum = a+b; continuous assignment trireg (small) #(0,0,35) ram_bit; net with small capacitance and 35 time unit decay time
22
8. Module Instances
same module unique from one another. instance_array_range (optional) instantiates multiple modules, each instance connected to separate bits of a vector.
[email protected] Verilog HDL Quick Reference Guide 23
8. Module Instances
module reg4 (q,d,clock); module dff (q,qb,data,clk); output [3:0] q; output q, qb; input [3:0] d; input data, clk; input clock; //default delay parameter wire [3:0] q, d; parameter delay = 1; wire clock; dff_udp #(delay) (q,data,clk); //port order connection, not (qb, q); //2nd port not connected endmodule dff u1 (q[0], , d[0], clock); //port name connection, //qb not connected dff u2 (.clk(clock),.q(q[1]),.data(d[1])); //explicit parameter redefine dff u3 (q[2], ,d[2], clock); defparam u3.delay = 3.2; //implicit parameter redefine dff #(2) u4 (q[3], , d[3], clock); endmodule
[email protected] Verilog HDL Quick Reference Guide 24
8. Module Instances
module tribuf64bit (out,in,enable); output [63:0] out; input [63:0] in; input enable; wire [63:0] out, in; wire enable; //array of 8 8-bit tri-state //buffers;each instance is connected //to 8-bit part selects of the 64-bit //vectors;The scalar enable line is //connected to all instances tribuf8bit i[7:0] (out,in,enable); endmodule
25
9. Primitive Instances
Terminal Order (1_output, 1-or-more_inputs) (1-or-more_outputs, 1_input) (1_output, 1_input, 1_control) (1_output) (1_output, 1-or-more_inputs)
user-defined-primitives
26
9. Primitive Instances
27
9. Primitive Instances
Primitive Delay Syntax #delay or #(delay) Single delay for all output transitions
#(delay, delay)
9. Primitive Instances
Primitive Instance Examples and i1 (out,in1,in2); and #5 (o,i1,i2,i3,i4); not #(2,3) u7(out,in); buf (pull0,strong1)(y,a); wire [31:0] y, a; buf #2.7 i[31:0] (y,a); Notes zero delay gate primitive same delay for all transitions separate rise & fall delays output drive strengths model ECL
array of 32 buffers
29
type_of_block @(sensitivity_list) statement_group: group_name local_variable_declarations timing_control procedural_statements end_of_statement_group type_of_block is either initial or always: - initial procedural blocks process statements one time. - always procedural blocks process statements repeatedly. statement_group--end_of_statement_group is used to group two or
Syntax:
more procedural statements together and control the execution order: - begin--end groups two or more statements together sequentially. - fork--join groups two or more statements together in parallel.
30
Notes
initial procedure executes statements one time; The fork--join group places statements in parallel.
always procedure executes
statements repeatedly. a statement group is not required when there is only one statement
31
may be a literal number, a variable, or an expression. @(edge signal or edge signal or ... ) Delays execution until there is a logic transition on a signal: edge (optional) maybe either posedge or negedge. If no edge is specified, then any logic transition is used. or is used to specify events on any of several signals. signal may be scalar or vector, and any data type. wait (expression) Delays execution until the expression evaluates as true.
32
register_data_type = expression;
-
deassign register_data_type;
-
release net_or_register_data_type;
34
If-else statement :
case (net_or_register_or_literal) case_match1: statement or statement_group case_match2, case_match3: statement or statement_group default: statement or statement_group endcase casez (net_or_register_or_literal) casex (net_or_register_or_literal)
[email protected]
statements:
Discontinuing execution :
disable group_name;
36
//A 50 ns clock oscillator that starts after 1000 time units initial begin clk = 0; #1000 forever #25 clk = ~clk; end //Sensitivity list models sequential logic always @(posedge clk) begin //Non-blocking assignments avoid race conditions in the byte swap word[15:8]<= word[7:0]; word[7:0] <= word[15:8]; end //Sensitivity list models combinational logic always @(a or b or sel) if (sel==0) y = a + b; else y = a * b;
[email protected] Verilog HDL Quick Reference Guide 37
11. Operators
Arithmetic Operators
m+n
m-n
m*n
m/n
m%n
Bitwise Operators
~m
&m
m&n
m|n
m^n
^m
m~^n
~^m
m^~n
^~m
~|m m&&n
Logical Operators
m||n
Relational Operators
m<n m>n
m<=n
m>=n
m<<n
{m,n}
m>>n
{n{m}} ->m
38
11. Operators
! * + << < == & ^ | && || ?: ~ / >> <= != ~& ~^ ~| + % (unary) (binary)
highest
precedence
> ===
>= !==
lowest
Verilog HDL Quick Reference Guide 39
Continuous Assignment Examples //A 32-bit wide 2:1 MUX wire [31:0] mux_out; assign mux_out = sel? a : b; //A 16-bit wide tri-state buffer with delay tri [0:15] #2.8 buf_out = en? in: 16'bz; //A 64-bit ALU with ECL output strengths wire [63:0] (strong1,pull0) alu_out= alu_function(opcode,a,b);
[email protected] Verilog HDL Quick Reference Guide 40
Syntax
task task_name; input, output, and inout declarations local variable declarations procedural_statement or statement_group endtask Example of a Task task read_mem; //TASK DEFINITION input [15:0] address; //declaration order output [31:0] data; // determines order begin // of arguments when read_request = 1; // task is called wait (read_grant) addr_bus = address; data = data_bus; #5 addr_bus = 16'bz; read_request = 0; end endtask read_mem(PC, IR); //TASK CALL
[email protected] Verilog HDL Quick Reference Guide 41
Syntax
function [size_or_type] function_name; input declarations local variable declarations procedural_statement or statement_group endfunction Example of a Function
function [7:0] GetByte; //FUNCTION DEFINITION input [63:0] Word; //declaration order input [3:0] ByteNum; //determines order integer Bit; //of arguments when reg [7:0] temp; //called begin for (Bit=0; Bit<=7; Bit=Bit+1) temp[Bit] = Word[((ByteNum-1)*8)+Bit]; GetByte = temp; //A function returns end // the value assigned endfunction // to its name this_byte = GetByte(data,4); //FUNCTION CALL
[email protected] Verilog HDL Quick Reference Guide 42
Syntax
factors, synthesis factors, etc. value may be integer, real, delay, or quoted string.
43
The reference_event is an edge of an input signal that establishes a reference point for changes on the data event. The data_event is the input signal that is monitored for changes. The limit and threshold are delay values. The notifier (optional) is a reg variable used as a flag.
Verilog HDL Quick Reference Guide 44
path_token is either *> for full or => for parallel connection. edge (optional) may be either posedge or negedge. source (optional) is the input port or value the output will receive.
45
(a => b) = 1.8; //parallel connection path; one delay for all output transitions (a -*> b) = 2:3:4;/*full connection path; one min:typ:max delay range for all output transitions; b receives the inverted value of a */ specparam t1 = 3:4:6, //different path delays for rise, fall transitions t2 = 2:3:4; (a => y) = (t1,t2); (a *> y1,y2) = (2,3,4,3,4,3);//different delays for 6 output transitions (posedge clk => (qb -: d)) = (2.6, 1.8); /* edge-sensitive path delay; timing path is positive edge of clock to qb; qb receives the inverted value of data*/ if (rst && pst) (posedge clk=> (q +: d))=2; //state-dependent edge sensitive path delay if (opcode = 3'b000) // state-dependent path delays; (a,b *> o) = 15; // an ALU with different delays for certain if (opcode = 3'b001) // operations; (a,b *> o) = 25; ifnone (a,b *> o) = 10; // (default delay has no condition) [email protected] Verilog HDL Quick Reference Guide 46
Syntax
primitive primitive_name (output, input, input, ... ); output terminal_declaration; input terminal_declaration; reg output_terminal; initial output_terminal = logic_value; table table_entry; table_entry; endtable endprimitive
48