The procedure is a form of subprograms. It contains local declarations and a sequence of statements. Procedure can be called in any place of the architecture. The procedure definition consists of two parts:
The procedure declaration, which contains the procedure name and the parameter list required when the procedure is called;
The procedure body, which consists of the local declarations and statements required to execute the procedure.
The procedure declaration consists of the procedure name and the formal parameter list.
In the procedure specification, the identifier and optional formal parameter list follow the reserved word procedure.
procedure Procedure_1 (variable X, Y: inout Real);
Objects classes constants, variables, signals, and files can be used as formal parameters. The class of each parameter is specified by the appropriate reserved word, unless the default class can be assumed (see below). In case of constants, variables and signals, the parameter mode determines the direction of the information flow and it decides which formal parameters can be read or written inside the procedure. Parameters of the file type have no mode assigned.
There are three modes available: in, out, and inout. When in mode is declared and object class is not defined, then by default it is assumed that the object is a constant. In case ofinout and out modes, the default class is variable. When a procedure is called, formal parameters are substituted by actual parameters. If a formal parameter is a constant, then actual parameter must be an expression. In case of formal parameters such as signal, variable and file, the actual parameters must be objects of the same class. Below example presents several procedure declarations with parameters of different classes and modes.
procedure Proc_1 (constant In1: in Integer; variable O1: out Integer);
procedure Proc_2 (signal Sig: inout Bit);
A procedure can be declared also without any parameters.
Procedure body defines the procedure's algorithm composed of sequential statements. When the procedure is called it starts executing the sequence of statements declared inside the procedure body.
The procedure body consists of the subprogram declarative part After the reserved word is and the subprogram statement part placed between the reserved words begin and end. The key word procedure and the procedure name may optionally follow the end reserved word.
Declarations of a procedure are local to this declaration and can declare subprogram declarations, subprogram bodies, types, subtypes, constants, variables, files, aliases, attribute declarations, attribute specifications, use clauses, group templates and group declarations.
procedure Proc_3 (X,Y : inout Integer) is
type Word_16 is range 0 to 65536;
subtype Byte is Word_16 range 0 to 255;
variable Vb1,Vb2,Vb3 : Real;
constant Pi : Real :=3.14;
procedure Compute (variable V1, V2: Real) is
end procedure Compute;
end procedure Proc_3;
A procedure can contain any sequential statements (including wait statements). A wait statement, however, cannot be used in procedures which are called from a process with a sensitivity list or from within a function.
procedure Transcoder_1 (variable Value: inout bit_vector (0 to 7)) is
case Value is
when "00000000" => Value:="01010101";
when "01010101" => Value:="00000000";
when others => Value:="11111111";
end procedure Transcoder_1;
The procedure Transcoder_1 transforms the value of a single variable, which is therefore a bi-directional parameter.
procedure Comp_3(In1,R:in real; Step :in integer; W1,W2:out real) is
variable counter: Integer;
W1 := 1.43 * In1;
W2 := 1.0;
L1: for counter in 1 to Step loop
W2 := W2 * W1;
exit L1 when W2 > R;
end loop L1;
assert ( W2 < R )
report "Out of range"
end procedure Comp_3;
The Comp_3 procedure calculates two variables of mode out: W1 and W2, both of the REAL type. The parameters of mode in: In1 and R constants are of real type and Step of the integer type. The W2 variable is calculated inside the loop statement. When the value of W2 variable is greater than R, the execution of the loop statement is terminated and the error report appears.
A procedure call is a sequential or concurrent statement, depending on where it is used. A sequential procedure call is executed whenever control reaches it, while a concurrent procedure call is activated whenever any of its parameters of in or inout mode changes its value.
All actual parameters in a procedure call must be of the same type as formal parameters they substitute.
The overloaded procedures are procedures with the same name but with different number or different types of formal parameters. The actual parameters decide which overloaded procedure will be called.
procedure Calculate (W1,W2: in Real; signal Out1:inout Integer);
procedure Calculate (W1,W2: in Integer; signal Out1: inout Real);
-- calling of overloaded procedures:
Calculate(23.76, 1.632, Sign1);
Calculate(23, 826, Sign2);
The procedure Calculate is an overloaded procedure as the parameters can be of different types. Only when the procedure is called the simulator determines which version of the procedure should be used, depending on the actual parameters.
Properties of Procedures
- Synthesis tools usually support procedures as long as they do not contain the wait statements.
- The Procedure declaration is optional - procedure body can exist without it. If, however, a procedure declaration is used, then a procedure body must accompany it.