Function Prototype Statements have the same function as symbols in schematic design files. Both provide a shorthand description of a logic function, listing its name and its input, output, and bidirectional ports.
However, megafunction and macrofunction input port default values are not automatically assigned as they are in Block Editor files; you must assign them explicitly in the Subdesign Section of a Text Design File (.tdf). You can also assign a default value for bidirectional ports in the Subdesign Section. However, output ports cannot be assigned a default value.
When you wish to implement an instance of a megafunction or macrofunction, you must ensure that its logic is defined in its own design file. You then use a Function Prototype Statement to specify the ports of the function, and implement an instance of the function with an in-line logic function reference or an Instance Declaration.
To implement an instance of a primitive, you also use an in-line logic function reference or an Instance Declaration. However, in contrast to megafunctions and macrofunctions, primitive logic is predefined, so you do not need to define the primitive logic in a separate design file. In addition, you do not need to use a Function Prototype Statement unless you wish to change the order of the primitive inputs.
The following examples show Function Prototype Statements. The first is for the parameterized function lpm_add_sub; the second is for the unparameterized function compare:
FUNCTION lpm_add_sub (cin, dataa[LPM_WIDTH-1..0], datab[LPM_WIDTH-1..0], add_sub) WITH (LPM_WIDTH, LPM_REPRESENTATION, LPM_DIRECTION, ADDERTYPE, ONE_INPUT_IS_CONSTANT) RETURNS (result[LPM_WIDTH-1..0], cout, overflow); FUNCTION compare (a[3..0], b[3..0]) RETURNS (less, equal, greater);
The Function Prototype Statement has the following characteristics:
When you specify the function name, you can use the name substitution feature to specify a text string for the name that is replaced by a different text string when the design is compiled. Before you can use the name substitution feature, you must turn on the NAME_SUBSTITUTION option in the TDF's Options Statement and specify the replacement string for the name in the TDF's Parameters Statement. You can then specify the text string to be replaced in the Function Prototype Statement using the format @ <text string>.
As an alternative to using a Function Prototype Statement in a file, you can use an Include Statement to call an AHDL Include File (.inc) that contains a Function Prototype Statement.
Function Prototypes for all Quartus® Prime megafunctions are stored in AHDL Include Files in the \quartus\libraries\megafunctions directory; Function Prototypes for Quartus® Prime primitives are built into the Quartus® Prime software. Online help for all megafunctions and primitives shows the Function Prototype for each Altera-provided function.