Verilog 5 Tasks Functions
Verilog 5 Tasks Functions
task read_mem;
output [15:0] data_in;
input [15:0] addr; stack
definition
@(posedge clk) begin IR
…
PC
end
@(posedge read_grant) begin
ADDRESS = addr;
#15 data_in = data;
end
endtask
2/28/2017 ANAND S MOGHE 3
Tasks
• A task is enabled when the task name is encountered in the
Verilog description
• Task definition is contained within the definition of the
module.
• The arguments passed to the task are in the same order as
the task I/O declarations.
• You can use timing controls ( #DELAY , @, wait) freely in a
task.
• Arguments are passed by value to a task (or function).
-> This means that an argument to a task or a function cannot be
expected to change inside the task/function.
integer i;
begin
for (i=15; i>=0; i=i-1)
temp_reg[15-i] = in_vec[i]; Y = mux4_1(a,b,c,d,s);
swap_bits = temp_reg;
end
endfunction
• It must contain at least one input and does not contain any output or in-
out ports.
– A function returns only one value, which is the value of the function itself.
Therefore, arguments cannot be declared as output or in-out.
• The arguments passed to a function are in the same order as the function
parameter declarations
• A function cannot enable a task. But it can call another function. A task
can enable a function.
2nd invocation
(from initial block-2)
ANAND S MOGHE 8
VERILOG – (automatic )Tasks
Implication of static variables (arguments) in tasks.
T=0
arg1, arg2, arg3
2nd invocation
task bus_request;
output good;
begin : bus_request_task
if (grt == 1’b1) begin
good = 1’b0;
disable bus_request_task;
end
req = 1’b1;
fork: wait_for_grt
#60 disable wait_for_grt;
@(posedge grt) disable wait_for_grt;
join
good = (grt == 1’b1)
end
endtask
task bus_request;
output good;
begin : bus_request_task
if (grt == 1’b1) begin
good = 1’b0;
disable bus_request_task;
end
req = 1’b1;
fork: wait_for_grt
#60 disable wait_for_grt;
@(posedge grt) disable wait_for_grt;
join
good = (grt == 1’b1)
end
endtask