IRVS VLSI IDEA INNOVATORS

IRVS VLSI IDEA INNOVATORS
VLSI Project, Embedded Project, Matlab Projects and courses with 100% Placements

Saturday, December 11, 2010

Functions

• Used to group together executable, sequential statements to define new mathematical or logical functions.

• Also used to define bus resolution functions, operators, and conversion functions between data types.

• When defined in a package, the function must be split into a declaration and a body.

Syntax: Function Body


FUNCTION function_name [] RETURN data_type IS
[declarations]
BEGIN
(sequential statements)
END
function_name;

= [CONSTANT] constant_name : constant_type ; or
= SIGNAL signal_name : signal_type ;


Where :(FUNCTION DECLARATION)

package - - end
package body - - end
entity – is - - begin - end
architecture –is - - begin- end
block - - begin - end
generate - - begin - end
process - - begin - end
function – is - - begin - end
procedure – is - - begin - end



NOTE:
Function Body is NOT allowed inside a Package

Rules :

• The function_name may be an identifier or an operator.

• Functions cannot assign signals or variables defined outside themselves, nor can then contain wait statements.

• A function must execute a return statement.

• Pure functions cannot have side effects - they must do nothing but return a value.

• There can be any number of such parameters (even zero), can only be CONSTANT (default) or SIGNAL (VARIABLES are not allowed).

• Their types can be any of the synthesizable data types (BOOLEAN,STD_LOGIC, INTEGER, etc.).

• No range specification should be included (for example, do not enter RANGE when using INTEGER, or TO/DOWNTO when using STD_LOGIC_VECTOR).

• On the other hand, there is only one return value, whose type is specified by data_type.

REMEMBER THIS !

• The return type must be a name; it cannot include a constraint.

• Variables defined inside a function are initialized each time the function is called.

• The declaration and body must conform, i.e. the parameters and return type must be identical between the two.

• The function declaration ends with a ";", whereas the function body has is at the corresponding point in the syntax.

Synthesis :

• Each call to a function is synthesized as a separate block of combinational logic.

Example :

FUNCTION f1 (a, b: INTEGER; SIGNAL c: STD_LOGIC_VECTOR)
RETURN BOOLEAN IS
BEGIN
(sequential statements)
END f1;


• The function, named f1, receives three parameters (a, b, and c).

• a and b are CONSTANTS (notice that the word CONSTANT can be omitted, for it is the default object), while c is a SIGNAL.

• a and b are of type INTEGER, while c is of type STD_LOGIC_VECTOR.

• Notice that neither RANGE nor DOWNTO was specified.

• The output parameter (there can be only one) is of type BOOLEAN.


information shared by information shared by www.irvs.info