tasks and func
TRANSCRIPT
-
8/12/2019 Tasks and Func
1/19
VIT University ECE301 - VLSI System Design 1
Task and Functions
Jagannadha Naidu K
-
8/12/2019 Tasks and Func
2/19
VIT University ECE301 - VLSI System Design 2
Task
-
8/12/2019 Tasks and Func
3/19
VIT University ECE301 - VLSI System Design 3
Task Properties Declared within a module
Referenced only by a behavior within the module
Task can be used with delay, timing or event control constructs. Tasks can have zero or more arguments.
Supports input, output and inout arguments.
Passes the values through output and inout arguments to the
task call.
A task can call other tasks and functions as well.
Tasks are declared with keyword task and endtask.
-
8/12/2019 Tasks and Func
4/19
VIT University ECE301 - VLSI System Design 4
Task Format
task ;
input declarations;
output declarations;
inout declarations;
begin
end
endtask
tasktask log_callog_cal;;
parameterparameter DEL = 30;DEL = 30;
outputoutput [7:0]and_out,or_out,xor_out;[7:0]and_out,or_out,xor_out;
inputinput [7:0]in1, in2;[7:0]in1, in2;
beginbegin
#DEL#DEL and_outand_out = in1 & in2;= in1 & in2;or_outor_out = in1 | in2;= in1 | in2;
xor_outxor_out = in1 ^ in2;= in1 ^ in2;
endend
endtaskendtask
-
8/12/2019 Tasks and Func
5/19
VIT University ECE301 - VLSI System Design 5
Example
-
8/12/2019 Tasks and Func
6/19
VIT University ECE301 - VLSI System Design 6
Re-entrant TaskProblem
Task is called concurrently from two places inthe code, these task calls will operate on the
same task variables
Solution Keyword automatic is added in front of the
task keyword to make the tasks re-entrant
All items declared inside automatic tasks areallocated dynamically for each invocation
-
8/12/2019 Tasks and Func
7/19
VIT University ECE301 - VLSI System Design 7
Example
-
8/12/2019 Tasks and Func
8/19
VIT University ECE301 - VLSI System Design 8
Cont
-
8/12/2019 Tasks and Func
9/19
VIT University ECE301 - VLSI System Design 9
Functions
-
8/12/2019 Tasks and Func
10/19
VIT University ECE301 - VLSI System Design 10
Function properties
-
8/12/2019 Tasks and Func
11/19
VIT University ECE301 - VLSI System Design 11
Function propertiesFunction properties
Functions should not contain delay information.
Functions must contain at least one input.
Supports only input arguments.
A function can call other function only. Can return only one value.
Functions are declared with keyword function and
endfunction.
-
8/12/2019 Tasks and Func
12/19
VIT University ECE301 - VLSI System Design 12
Function Formatfunction
;
input declarations;
begin
end
endfunction
functionfunction par_calpar_cal;;
inputinput [15:0]dat_in;[15:0]dat_in;
beginbegin
par_calpar_cal = ^= ^dat_indat_in;;
endend
endfunctionendfunction
-
8/12/2019 Tasks and Func
13/19
VIT University ECE301 - VLSI System Design 13
Function Example
-
8/12/2019 Tasks and Func
14/19
VIT University ECE301 - VLSI System Design 14
Function Calling
A function is called or enabled by a function enablecall that specifies the argument values passed to thefunction.
A function call is a part of an expression i.e. anoperand within an expression.
Function returns the computed result in the name ofthe function itself
-
8/12/2019 Tasks and Func
15/19
VIT University ECE301 - VLSI System Design 15
Function Calling
The list of input arguments must match the orderof input declarations in the function definition.
Arguments are passed by value, not by reference.
A function can be called more than onceconcurrently with each call having its own control.
Variables declared within a function is static.
-
8/12/2019 Tasks and Func
16/19
VIT University ECE301 - VLSI System Design 16
Function calling exampleFunction calling example
functionfunction par_calpar_cal;;
inputinput [15:0]dat_in;[15:0]dat_in;
beginbegin
par_calpar_cal = ^= ^dat_indat_in;;
endend
endfunctionendfunction
wire [15:0]data;
reg parity_value;
always @(enable)
begin
if(enable == 1b1)
parity_value = par_cal(data);
end
-
8/12/2019 Tasks and Func
17/19
VIT University ECE301 - VLSI System Design 17
Automatic (Recursive ) Functions
The keyword automatic can be used to declare a
recursive (automatic) function where all functiondeclarations are allocated dynamically for each
recursive calls
-
8/12/2019 Tasks and Func
18/19
VIT University ECE301 - VLSI System Design 18
-
8/12/2019 Tasks and Func
19/19
VIT University ECE301 - VLSI System Design 19
Task and Functions Summary
functions
can enable other function, nota task.
execute in 0 simulation time.
do not support delay, event ortiming controls.
must have at least one input
argument, can have more thanone input.
return single value , they cannot have output or inoutarguments.
tasks
can enable other functions andtasks.
execute in non 0 simulationtime.
can have delays, event ortiming controls.
can have zero or morearguments of type input,output or inout.
do not return any value, butcan pass multiple values thro
output and inout args.