System Verilog Lecture
System Verilog Lecture
Jean-Michel Chabloz
How we study SystemVerilog
Huge language:
Case sensiti&e
+nitial bloc0s
7lways bloc0s
Continuous assignments
5instantiations o) submodules6
SystemVerilog basic data ty$es
9ata ty$es:
bit A#:;B a?
logic A>:;B b?
9ecimal literal:
a FG #:? .. automatically e-tended to the length o) a with ;
$adding
a FG Hd#:?
a FG !>4d#:? .. s$eci)ies that a is !>-bits wide
Ins$eci)ied length:
H!' H;' H-' Hz .. )ills with all !s' ;s' -s' zs
binary literal
!>4b!;;;J!!;;J!!!; .. underscores can be $ut anywhere
e-ce$t the beginning o) a literal
Hb!!;!! .. automatically resized with zeroes i) )ed to something
bigger
he-adecimal literal:
!>4hc? .. 1;;;;;;;;!!;;2
Hhcd: .. 2K3;;;;;!!;;!!;!2
@ac0ed array access
bit AC:;B a
aA#B FG aALB?
bit AM:;BAC:;B b:
bA#B FG !#?
bit AC:;B a?
aA":>B FG >4b!;?
aA":;B FG aAC::B?
U: and
V : or
W : -or
X : not
a FG Xa
c FG a V b
logic o$erators
UU: and
V V: or
Y : not
eEuality: GG
diseguality: YG
greather than: Z
lower than: F
u$ counter:
KKK3
!!!;!
!!!!;
!!!!!
;;;;;
;;;;!
;;;!;
KKK3
Riming Control in @rocesses
\!;ns: waits )or !; ns
\!;: wait )or !; time units time unit s$eci)ied during elaboration or
with a ]timescale directi&e in the code
\5a6: wait )or a number o) time units eEual to the &alue o) &ariable a
\5a/!$s6: wait )or a number o) $icoseconds eEual to the &alue o) a
^5$osedge a6: waits )or the $ositi&e edge o) a
^5b6: wait until b toggles
wait5e-$r6: waits until e-$r is true
wait5b6: wait until b is one
Riming chec0s can be bundled with the ne-t instr: \!;ns aFGYa
)or0K 8oin
S$awn concurrent $rocesses )rom a single $rocess: 7 is $rinted at
";ns? T at >;ns? 8oin waits until both sub$rocesses ha&e )inished'
the last dis$lay ta0es $lace at :;ns
initial begin
%-ns;
fork
begin
%&ns;
$display( 67n8 );
end
begin
%-ns;
$display( 97n8 );
%&ns;
end
join
$display(bot* )inis*ed);
end
@rocedural assignments
%on-bloc0ing assignment
1FG1
Tloc0ing assignment
1G1
TIR:
e-:
%o error is signaled
,ays to a&oid:
Variables:
logic a;
bit [7:0] b;
we are actually de)ining &ariables
Variables &s %ets
%ets:
c FG @ac0age%ame::Sunction%ame5a'b6
or
c FG Sunction%ame5a'b6?
im$ort @ac0age%ame::/?
In$ac0ed arrays
bit a A#:;B?
b G newA!;;B?
Can be resized with: b G newA>;;B5b6?
E G P E' L Q? .. E3$ushJbac05L6
E G P e' E Q? .. E3$ushJ)ront5e6
E G PQ? .. E3delete56
Structure
endmodule
Structure
@ositional instantiation
module tb (); 22 topAle3el testbenc*
*as no inputs2outputs
bit cl0, rst;
bit [7:! a, b;
simple/)i)o %(G',J)
dut (
?cl0(cl0),
?rst(rst),
?a(a),
?b(b));
5
endmodule
module %(
parameter DE<FH"G',
parameter HIDFH"J
)
simple/)i)o (
input logic cl0,
input logic rst,
input logic [HIDFHA-:! a,
output logic [HIDFHA-:! b
);
localparam internal/param/name;
endmodule
@arameters
Nther notation
module tb (); 22 topAle3el testbenc*
*as no inputs2outputs
bit cl0, rst;
bit [7:! a, b;
simple/)i)o %(
?DE<FH(G'),
?HIDFH(J))
dut (
?cl0(cl0),
?rst(rst),
?a(a),
?b(b));
5
endmodule
module simple/)i)o (
input logic cl0,
input logic rst,
input logic [HIDFHA-:! a,
output logic [HIDFHA-:! b
);
parameter DE<FH"G'
parameter HIDFH"J
localparam internal/param/name;
5
endmodule
@arameters
a <= top.dut.subDutUnit.intObjectName;
e-:
initial begin : input:ontroller
5
i) (a""-) begin : terminationHandler
end
end
`ood Restbench Structure
Rhe testbench
$rogram must use
access all 9IR
signals in read and
write through the
de)ault cloc0ing
bloc0
Nnly timing
construct allowed
in the testbench
$rogram: \\
top module
generation of clock
testbench
program
drive
DUT inputs
check
DUT outputs
DUT
clk
`ood Restbench Structure
7lternati&e: se&eral $rograms are allowed
all use cloc0ing bloc0 in lin0s to the 9IR
top module
generation of clock
testbench
program
drive inputs
DUT
clk
testbench
program
check outputs
`ood testbench structure
*ou can use any structure you li0e' e&erything is allowed
Rhe one below is more IVM-li0e
top module
generation of clock
testbench
program
drive some inputs
DUT
clk
testbench
program
collect outputs
translate them into
a higher level
model
testbench
program
drive other inputs
program
check outputs
`ood testbench structure