SoC Verilog-Quick
SoC Verilog-Quick
initial
begin
//set stimulus to test the code
A_input=0;
B_input=0;
C_input=0;
#100 $finish;
end
Internal to
module
HDL
• Traditional PL: Sequential process
• HDL: Characteristics of digital hardware
– Connections of parts
– Concurrent operations
– Concept of propagation delay and timing
Popularity of Verilog HDL
• Verilog HDL
– General-purpose
– Easy to learn, easy to use
– Similar in syntax to C
– Allows different levels of abstraction and mixing them
– Supported by most popular logic synthesis tools
– Post-logic-synthesis simulation libraries by all
fabrication vendors
Alternative of Verilog® HDL
• VHDL
– VHSIC (Very High Speed Integrated Circuit)
Hardware Description Language
– Developed under contract from DARPA
– IEEE standard
– Public domain
– Other EDA vendors adapted VHDL
VHDL vs. Verilog
Behavioral
Dataflow
VHDL
Structural Verilog
& Gate
Switch
VHDL vs. Verilog
• Ada based • C and Ada
constructs constructs
• High level: system • Low Level: Gate &
descriptor structural descriptor
• Mostly in America, • Mostly in Europe
Japan….
Definition of Module
• Interface: port and parameter declaration
• Body: Internal part of module
• Add-ons (optional)
Some points to remember
• The name of Module
• Comments in Verilog
– One line comment (// ………….)
– Block Comment (/*…………….*/)
input [3:0] a, b;
input c_in;
...
endmodule
Module Interface – ALU ?
Behavioural Modelling
Behavioural Modelling of Mux
Lexical Conventions: Numbers
General syntax: <size>’<base><number>
<size> :
number of bits (in decimal)
<base> :
– d or D for decimal (radix 10)
– b or B for binary (radix 2)
– o or O for octal (radix 8)
– h or H for hexadecimal (radix 16)
<number> :
is the number in radix <base>
Examples:
– 4’b1111
– 12’habc
– 16’d255
Lexical Conventions: Numbers
• Underscore character
– Use ‘_’ to improve readability, not at
starting
• 12’b1111_0000_1010
Structural Modelling
Structural Modelling
Structural Modelling of Mux
Primitive Gates
Dataflow Modelling
Dataflow Modelling for Mux
Lexical Conventions
• Very similar to C
– Verilog is case-sensitive
– All keywords are in lowercase
– A Verilog program is a string of tokens which can
be:
• Whitespace
• Comments
• Numbers
• Strings
• Identifiers
• Keywords
Outline
• Lexical Conventions in Verilog HDL
• Whitespace, comments, number specification,
string, operators, identifiers
• Logic Values
• Data Types in Verilog HDL
• Value set and strengths
• Nets and Registers
• Vectors
• Integer, Real, and Time Register Data Types
• Arrays, Memories, Parameters and Strings
Lexical Conventions
• Very similar to C
– Verilog is case-sensitive
– All keywords are in lowercase
– A Verilog program is a string of tokens which can
be:
• Whitespace
• Comments
• Numbers
• Strings
• Keywords
• Identifiers
Lexical Conventions (cont’d)
• Number Specification
– Sized numbers
– Unsized numbers
– Unknown and high-impedance values
– Negative numbers
Lexical Conventions (cont’d)
Sized numbers
o General syntax: <size>’<base><number>
<size> :
number of bits (in decimal)
<base> :
– d or D for decimal (radix 10)
– b or B for binary (radix 2)
– o or O for octal (radix 8)
– h or H for hexadecimal (radix 16)
<number> :
is the number in radix <base>
Examples:
– 4’b1111
– 12’habc
– 16’d255
Lexical Conventions (cont’d)
Unsized numbers
o Default base is decimal
o Default size is at least 32
o Examples:
23232
’habc
’o234
o Examples:
23232 //32-bit decimal no
’habc //32-bit hex no
’o234 //32-bit octal no
Lexical Conventions (cont’d)
X or Z values
– Unknown value: lowercase x
• 4 bits in hex, 3 bits in octal, 1 bit in binary
– High-impedance value: lowercase z
• 4 bits in hex, 3 bits in octal, 1 bit in binary
– Examples:
• 12’h13x //this is 12-bit hex
• 6’ox //this is 6-bit octal no -> xxxxxx
• 32’bz //this is 32-bit high impedance no
Value Set
• Syntax:
– wire/reg [msb_index : lsb_index] data_id;
• Example
wire a;
wire [7:0] bus;
wire [31:0] busA, busB, busC;
reg clock;
reg [0:40] virtual_addr;
Vectors( cont’d) Variable Vector
Part Select
• Consider
wire [7:0] bus;
wire [31:0] busA, busB, busC;
reg [0:40] virtual_addr;
integer i;
initial
i = delta; // i gets the value 2 (rounded value of 2.13)
Register Data Types (cont’d)
• Time
o Verilog simulation is done with respect to simulation time
o Used to store values of simulation time
o time register data type
o Keyword: time
o Bit width: implementation-dependent (at least 64)
o $time system function gives current simulation time
o Example:
time save_sim_time;
initial
save_sim_time = $time;
Arrays
• Data types: wire, reg, integer, time, real,
realtime and vector register etc..
• Single dimensional array
• Multi-dimensional array is also possible
• Syntax:
<data_type> <array_var_name> [start_idx : end_idx]
[start_idx : end_idx] ...
[start_idx : end_idx];
• Access:
<array_name> [<subscrip/index>]
For multidimensional indexes for each dimension
Arrays
• Examples:
integer count [0:7]; //array of 8 count variable
reg bool [31:0]; // array of 32 one-bit boolean
time chk_point [1:100];
integer matrix[4:0][0:16]; //two dimentional
reg [4:0] port_id [0:7];
reg [63:0] array_4d [15:0][7:0][7:0][255:0];
wire w_array1[7:0][5:0]; //array of single bit wires
wire [7:0] w_array2 [5:0]; //array of 8-bit vector wire
count[5] = 0;
chk_point[100] = 0;
port_id[3] = 0;
matrix[1][0] = 33559;
array_4d[0][0][0][0][15:0] = 0;
port_id = 0; // Illegal
matrix [1] = 0; // Illegal
Memories
• RAM, ROM and register-files used many
times in digital systems
• Modeled as a one-dimensional array of
registers
• Memory = array of registers (register
data type) in Verilog
• Word = an element of the array
– Can be one or more bits
Memories
• Examples:
reg mem1bit [0:1023];
reg [7:0] membyte[0:1023];
membyte[511] //fetches 1 byte word
addr:511
• Note the difference (as in arrays):
• n 1-bit register Vs one n-bit register
reg mem1bit[0:127];
reg [0:127] register;
Parameter
• Similar to const in C
– But can be overridden for each module at compile-time
• Constants to be defined by parameter
• Can not be used as variable
• Syntax:
parameter <const_id> = <value>;
• Gives flexibility
– Allows to customize the module
• Example:
parameter port_id = 5;
parameter cache_line_width = 256;
parameter bus_width = 8;
parameter signed [15:0] WIDTH;
wire [bus_width-1:0] bus;