In a large design, there are some portions of code which might be repeated or called multiple times.
A common block that encapsulates some functionality within the design, it is called sub-program.
Procedure is a type of subprogram that can be called multiple times throughout the design
Advantages of using procedure
Avoids code repetition
Can be declared with or without any arguments
Can have input, output and inout ports
May/may not include timing delays as procedures can be executed in non-zero simulation time
2. Highlights for procedure
No return as the function
Unlike functions, procedures can contain wait-statements
Do not have to specify the length of data type like port declaration. Just need to specify type std_logic_vector, for example, is enough.
Procedure can be declared with or without arguments
Procedures without arguments are used to run sequences of events - mostly used in testbench where procedure is used to drive specific signals
Parameters (inputs/outputs/inout) to a procedure can be signals, variables, or constants
Procedure is declared within the architecture’s declarative region or in the package
3. Procedure structure
Syntax
A procedure’s parameter list defines its inputs and outputs, kind of like a mini-module. It can be a signal or a constant, but unlike a module, it can also be a variable. You can declare objects between the “is” and “begin” keywords that are only valid inside the procedure. These may include constants, variables, types, subtypes, and aliases, but not signals.
Unlike functions, procedures may contain wait-statements. Therefore, they are often used in testbenches like simple BFM’s for simulating interfaces, or for checking output from the device under test (DUT).
a. Procedure parameters
Procedure parameters are similar to port declartions.
It can be:
Mode IN
Mode OUT
Mode INOUT
Inside a procedure, parameters with specified mode or direction is restricted as following table.
Mode
Readable
Changed
IN
OK
NO
OUT
NO
Assign back to caller
INOUT
OK
Assign back to caller
Example
Want to call the above procedure?
To make the mapping valid, the formal and actual must be of same data type, class and mode
b. Parameters classes
VHDL supports four classes of objects
Constant
Variable
Signal
File
If classes are not specified in the argument list. The default class will be selected
Mode
Default classes
IN
constant
OUT
variable
INOUT
variable
c. Explicitly specify class of procedure parameters
Explicitly specify class of input and output parameters declared in a procedure is oftern helpful. It simplifies usage and expands capabilities of a procedure.
Here is an example when not specified class in the argument list
We need a variable TEMP_BUS to pass value to a signal OUT_BUS.
And explicitly specified class for parameters
We can see, with explicited declaration, there is no need of variable TEMP_BUS to pass value to signal OUT_BUS.