Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
VAMS-LRM-2-3-1.pdf
Скачиваний:
43
Добавлен:
05.06.2015
Размер:
3.73 Mб
Скачать

 

Accellera

Analog and Mixed-signal Extensions to Verilog HDL

Version 2.3.1, June 1, 2009

This example defines an analog user defined function called geomcalc, which returns both the area and perimeter of a rectangle.

analog function real geomcalc; input l, w;

output area, perim; real l, w, area, perim; begin

area = l * w;

perim = 2 * ( l + w ); end

endfunction

Example 3 — Initialization of a vector variable

The analog user defined function called arrayadd adds the contents of a second array to the first.

analog function real arrayadd; inout [0:1]a;

input [0:1]b;

real a[0:1], b[0:1]; integer i;

begin

for(i = 0; i < 2; i = i + 1) begin a[i] = a[i] + b[i];

end end

endfunction

4.7.2 Returning a value from an analog user defined function

There are three ways to return a value from an analog user defined function: using the implicit analog user defined function identifier variable, using an output argument, or using an inout argument.

4.7.2.1 Analog user defined function identifier variable

The analog user defined function definition implicitly declares a variable, internal to the analog user defined function, with the same name as the analog_function_identifier. This variable inherits the same type as the type specified in the analog user define d function declaration. This internal variable is initialised to zero (0) and can be used within the body of the analog user defined function. The last value assigned to this variable will be the return value of the analog user defined function. If this internal variable is not assigned during the execution of the analog user defined function, then the analog user defined function will return the initialised value of zero (0). A analog user defined function shall always return a scalar numerical value.

The following line (from the first example in 4.7.1) illustrates this concept:

maxValue = (n1 > n2) ? n1 : n2;

4.7.2.2 Output arguments

An output argument allows the user to return more than one value. The argument passed to an output argument must be an analog variable reference. If the output argument is defined as an array then the argument passed into the function must be an analog variable or an array assignment pattern of analog variables of equivalent size. All output arguments of an analog user defined function are initialised to zero (0), which in turn means that the argument passed to it is reset to zero (0). During the execution of the function, these variables can be read and assigned in the flow. At the end of the execution of the analog user

85

Copyright © 2009 Accellera Organization, Inc. All rights reserved.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]