CS623: CVLSI: V. Kamakoti and Shankar Balachandran
CS623: CVLSI: V. Kamakoti and Shankar Balachandran
Lecture 16
V. Kamakoti and
Shankar Balachandran
Differences
A function can enable another function but
not another task. A task can enable
another task
Functions always execute in 0 simulation
time, tasks may not.
Functions should not contain any delays,
timing controls tasks may have
Differences
Functions must have at least one input
argument task may have zero or more
input, output and inout arguments
Function returns a single value, while task
may pass more than one value through
output/inout arguments. Functions cannot
have inout/output arguments
Example - Tasks
module operation;
parameter delay = 10;
//argument, parameter declarations
always @(A or B)
begin
bitwise_oper(AB_AND,AB_OR,A,B)
end
task bitwise_oper;
output [15:0] ab_and,ab_or;
input [15:0] a,b;
begin
#delay ab_and = a &b;
ab_or = a | b;
end
endtask
endmodule
Tasks (Continued)
Tasks operate on reg variables defined
in the module directly
module sequence;
reg clk;
initial
init_sequence;
.
task init_sequence;
begin
clk = 1b0;
end
endtask
endmodule
Functions - Example
module parity;
Summary
A register with name as the function name
is declared implicitly when a function is
declared. The return value of the function
is passed back to this register
Tasks and functions are included in a
design hierarchy and can be addressed by
hierarchical name referencing.
Contd
Contd
Contd
Force and release to be used only in stimulus
blocks
Overriding parameters
module hello_world;
parameter id_num = 0;
endmodule
module top;
defparam w1.id_num = 1; w2.id_num = 2;
hello_world w1();
hello_world w2();
endmodule
Contd
File output
integer handle1;
initial
handle1 = $fopen(file1.out);
$fclose(handle1);
$fdisplay(handle1,)
$fmonitor(handle1,)
Hierarchy display %m
module top;
M m1();
endmodule;
module M;
$display(%m) // output top.m1
endmodule
Random Numbers
$random
$random <seed>;
//seed is optional
initial r_seed = 2;
always @(posedge clk)
addr = $random(r_seed);
References
Chapter 9: Samir Palnitkar - Verilog HDL,
First edition
Chapter 3: J. Bhasker A Verilog HDL
Primer, First edition
Thank You