always
: statements inside in these blocks are executed sequentially ʳ
always @(<sensitivity-list>)
: fire if any signal in sensitivity list changesalways @(*)
: means all input includedrepeat(n)
: replicate a block n
times`timescale <time_unit>/<time_precision>
`timescale 1ns/1ps
: says 1 step is 1ns and I guess to report with precision upto 1psposedge <signal>
, negedge <signal>
: positive & negative edge of a signal respectively
always @(posedge clk or negedge rst) begin ... end
posedge
is like rising_edge(signal)
in VHDLbegin .. end
is not needed if there's only one statementfunction
vs task
: task can take up simulation time, unlike function
logic
: apparently same as reg
>>>
vs >>
: >>>
copies sign bit. >>
fills in with 0
<<<
, which sounds meaningless anyway.$unsigned(v)
: type cast to unsignedcasex
and casez
: case
with wildcards allowed
unique
, priority
modifiers: ??
Table from here:
Strength | Value | |
---|---|---|
supply | 7 | Su |
strong | 6 | St |
pull | 5 | Pu |
large | 4 | La |
weak | 3 | We |
medium | 2 | Me |
small | 1 | Sm |
highz | 0 | HiZ |
See:
—
Signal states ??
~Z~ | 'High impedence' / 'tristate' |
~X~ | Unknown state |
~?~ | Don't care |
In simulation, all values start with x
by default.
AND | 0 | 1 | x | z |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | x | x |
x | 0 | x | x | x |
z | 0 | x | x | x |
initial
blockalways
blockinitial
blocks??https://www.pace.edu.in/img/course/Verilog_HDL_Module4.pdf
=
<=
//
/* ... */
z
: high impedencex
: unknown/uninitialized0
: logic 01
: logic 1localparam
: similar to parameter
but cannot be modified by module instance argument or with defparam
Format: n'bVAL
:
n
: number of bitsb
: baseVAL
: valueDefault is base is decimal.
8'hFF
: 8-bit hex number of value FF
(ie, 0xFF
)5'b101
: 5-bit binary number (ie, 0b00101
)1
: decimal number3'o5
: 3-bit octal number (ie, 0o5
)https://users.ece.utexas.edu/~patt/04s.382N/tutorial/verilog_manual.html
`define
, `include
, `ifdef .. else .. `endif
,`include "file.v"
: include another verilog file`define
: make text macros (à la C)See:
// word size
`define wsize 32
`define word [`wsize-1:0]
...
...input `word a, b;
?:
cond ? true : false
<<
and >>
{1'b0, 1'b1, 1'b0}
gives 3'b010
{2 {expr}}
is same as {expr, expr}
{2 {1'b0}, 1'b1}
is 3'b001
~ |
Unary negation |
& |
AND |
│ |
OR |
^ |
XOR |
~^a or ^~a |
XNOR |
&a |
Reduction AND |
│a |
Reduction OR |
~&a |
Reduction NAND |
~│a |
Reduction NOR |
^ |
Reduction XOR |
~^a or ^~a |
Reduction XNOR |
Possible for sized values like vectors ??
'Indexing' into a vector/similar
Example:
wire [7:0] a;
// 0th bit of a
0]
a[
// 4th bit of a
4] a[
'Slicing a vector/similar
Example:
wire [7:0] a;
// 2nd, 1st and 0th bits of a
2:0]
a[
// 5th, 4th and 3rd bits of a
5:3] a[
$dumpfile("name.vcd")
: dump wave info as vcd$dumpvars(number_of_levels, instance_name)
: dump wave info as vcd
$readmemb("filename", instance_name.mem, starting_addr)
: read from a binary file ??$readmemh("filename", instance_name.mem, starting_addr)
: read from a hex file ??$strobe
: print messages on screen after end of current time slot (postpone region)
printf
in C$strobe()
$display
: print messages (active region)$write
: like $display
, but no newline$time
: returns current simulation time$finish
: end simulationSee:
specify
blocksA relatively obscure part of verilog..
'Defines a delay across a module'
Delays are mentioned in picoseconds
A => B = 12
: simple combinationational path from A to B with delay 12ps
See:
iverilog-vpi --install-dir
ʳtemp[0] <= a^b;
temp[1] <= a&b;
function <name> (args); <body> endfunction
<type> <name> [<size>];
$size <name>
for
loop: for(int i=0; i<5; i++) begin ... end
Stuff not in verilog:
===
and !==
++
, --
(incr/decr)+=
, -=
(assignment)always_ff
, always_comb
, always_latch
priorty
, unique
parallel_case
and full_case
pragmas in verilog ??interface
typedef enum {red, green, blue} Colour;
typedef enum {red=10, green=20, blue=30} Colours;
always
stuffalways_comb
: a combinatory block
Verilog's always
block was less expressive. Specialized blocks convey the meaning more clearly.
<val_type> <name> [<index_type>];
// Assoc array with string index and int values
int fruitprice[string];
"Apple": 190,
fruitprice = '{"Orange": 120};
See: https://www.chipverify.com/systemverilog/systemverilog-associative-array
https://www.chipverify.com/systemverilog/systemverilog-class
this
: current object (or is it class??)function new ()
: constructor
extends
class subclass extends baseclass;
super.<attribute>
virtual class
: abstract class
Can be passed to simulation with a +
character
These arguments are accessible with plusargs
functions
https://www.chipverify.com/systemverilog/systemverilog-command-line-input
$test$plusargs (str)
: Check if the argument str
exists ??
$value$plusargs (str, var)
str
to var
7:0] addr;
bit [8'hB; } constraint addr_limit { addr <=
https://www.chipverify.com/systemverilog/systemverilog-constraints
coverpoint
: variablescovergroup
block: groups cover pointshttps://www.chipverify.com/systemverilog/systemverilog-functional-coverage
Apparently, iverilog doesn't consider input as systemverilog by default. Got to use -g2005-sv
.
$ iverilog -g mem.sv
Unknown/Unsupported Language generation mem.sv
Supported generations are:
1995 -- IEEE1364-1995
2001 -- IEEE1364-2001
2005 -- IEEE1364-2005
2005-sv -- IEEE1800-2005
2009 -- IEEE1800-2009
2012 -- IEEE1800-2012
Other generation flags:
assertions | supported-assertions | no-assertions
specify | no-specify
verilog-ams | no-verilog-ams
std-include | no-std-include
relative-include | no-relative-include
xtypes | no-xtypes
icarus-misc | no-icarus-misc
io-range-error | no-io-range-error
strict-ca-eval | no-strict-ca-eval
strict-expr-width | no-strict-expr-width
shared-loop-index | no-shared-loop-index
$ iverilog -g2005-sv mem.sv
if
conditionLooks like boolean expressions serving as conditions for if
always need to be enclosed within parenthesis.
This works:
if (en_wr)
but this doesn't
if en_wr
Execute only if a macro is defined:
`ifdef MACRO_NAME
`endif