Jagannadha Naidu K VIT University ECE301 - VLSI System Design 2 Task 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. VIT University ECE301 - VLSI System Design 4 Task Format task <task_name>; <task_declarations > input declarations; output declarations; inout declarations; begin <assignments> end endtask task task log_cal log_cal; ; parameter parameter DEL = 30; DEL = 30; output output [7:0]and_out,or_out,xor_out; [7:0]and_out,or_out,xor_out; input input [7:0]in1, in2; [7:0]in1, in2; begin begin #DEL #DEL and_out and_out = in1 & in2; = in1 & in2; or_out or_out = in1 | in2; = in1 | in2; xor_out xor_out = in1 ^ in2; = in1 ^ in2; end end endtask endtask VIT University ECE301 - VLSI System Design 5 Example VIT University ECE301 - VLSI System Design 6 Re-entrant Task Problem Task is called concurrently from two places in the 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 are allocated dynamically for each invocation VIT University ECE301 - VLSI System Design 7 Example VIT University ECE301 - VLSI System Design 8 Cont VIT University ECE301 - VLSI System Design 9 Functions VIT University ECE301 - VLSI System Design 10 Function properties VIT University ECE301 - VLSI System Design 11 Function properties Function 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. VIT University ECE301 - VLSI System Design 12 Function Format function <range><function_name>; <function_declarations > input declarations; begin <assignments> end endfunction function function par_cal par_cal; ; input input [15:0]dat_in; [15:0]dat_in; begin begin par_cal par_cal = ^ = ^dat_in dat_in; ; end end endfunction endfunction VIT University ECE301 - VLSI System Design 13 Function Example VIT University ECE301 - VLSI System Design 14 Function Calling A function is called or enabled by a function enable call that specifies the argument values passed to the function. A function call is a part of an expression i.e. an operand within an expression. Function returns the computed result in the name of the function itself VIT University ECE301 - VLSI System Design 15 Function Calling The list of input arguments must match the order of input declarations in the function definition. Arguments are passed by value, not by reference. A function can be called more than once concurrently with each call having its own control. Variables declared within a function is static. VIT University ECE301 - VLSI System Design 16 Function calling example Function calling example function function par_cal par_cal; ; input input [15:0]dat_in; [15:0]dat_in; begin begin par_cal par_cal = ^ = ^dat_in dat_in; ; end end endfunction endfunction wire [15:0]data; reg parity_value; always @(enable) begin if (enable == 1b1) parity_value = par_cal(data); end VIT University ECE301 - VLSI System Design 17 Automatic (Recursive ) Functions The keyword automatic can be used to declare a recursive (automatic) function where all function declarations are allocated dynamically for each recursive calls VIT University ECE301 - VLSI System Design 18 VIT University ECE301 - VLSI System Design 19 Task and Functions Summary functions can enable other function, not a task. execute in 0 simulation time. do not support delay, event or timing controls. must have at least one input argument, can have more than one input. return single value , they can not have output or inout arguments. tasks can enable other functions and tasks. execute in non 0 simulation time. can have delays, event or timing controls. can have zero or more arguments of type input, output or inout. do not return any value, but can pass multiple values thro output and inout args.