Добавил:
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

12.21 vpi_handle_by_name()

vpi_handle_by_name()

Synopsis:

Get a handle to an object with a specific name.

 

 

 

 

Syntax:

vpi_handle_by_name(name, scope)

 

 

 

 

 

 

Type

Description

 

Returns:

 

 

 

vpiHandle

Handle to an object

 

 

 

 

 

 

Type

Name

Description

Arguments:

 

 

 

char *

name

A character string or pointer to a string containing the name

 

 

 

of an object

 

 

 

 

 

vpiHandle

scope

Handle to a Verilog-AMS HDL scope

 

 

 

 

The VPI routine vpi_handle_by_name() shall return a handle to an object with a specific name. This function can be applied to all objects with a fullname property. The name can be hierarchical or simple. If scope is NULL, then name shall be searched for from the top level of hierarchy. Otherwise, name shall be searched for from scope using the scope search rules defined by the Verilog-AMS HDL.

12.22 vpi_handle_multi()

vpi_handle_multi()

Synopsis: Obtain a handle to inter-module paths with a many-to-one relationship.

Syntax: vpi_handle_multi(type, ref1, ref2, ...)

 

Type

Description

 

Returns:

 

 

 

vpiHandle

Handle to an object

 

 

 

 

 

 

Type

Name

Description

Arguments:

 

 

 

int

type

An integer constant representing the type of object for

 

 

 

which to obtain a handle

 

 

 

 

 

vpiHandle

ref1, ref2, ...

Handles to two or more reference objects

 

 

 

 

Related

Use vpi_iterate() and vpi_scan() to obtain handles to objects with a one-to-many relationship

routines:

Use vpi_handle() to obtain handles to objects with a one-to-one relationship

 

 

 

 

The VPI routine vpi_handle_multi() shall return a handle to objects of type vpiInterModPath associated with a list of output port and input port reference objects. The ports shall be of the same size and can be at different levels of the hierarchy. This routine performs a many-to-one operation instead of the usual one-to-one or one-to-many.

12.22.1 Derivatives for analog system task/functions

The VPI routine vpi_handle_multi() is used to access the derivative handles associated with analog system task/functions (see also: vpi_register_analog_systf()). The first argument is the type vpiDerivative. The second is the handle for the task/function argument for which a partial derivative is

299

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

Accellera

 

Version 2.3.1, June 1, 2009

VERILOG-AMS

to be declared. The third argument indicates the value with respect to which the derivative being declared shall be calculated. For example, assuming argHandle2 and argHandle3 are handles to the second and third arguments of an analog system task, then vpi_handle_multi(vpiDerivative, argHandle2, argHandle3) indicates the partial derivative of the returned value with respect to the third argument. For vpiDerivative, the vpi_handle_multi() function can only be called for those derivatives allocated during the derivtf phase of execution.

12.22.2 Examples

The following example illustrates the declaration and use of derivative handles in a analog task $resistor(), which implements a conductance relationship. The task can be used as follows:

module resistor(p, n); electrical p, n; parameter real r = 1k; real curr;

analog begin

$resistor(curr, V(p, n), r); I(p, n) <+ curr;

end endmodule

The implementation of the analog task can be performed by the resistor_compile_tf() and resistor_call_tf() routines shown below:

#include "vpiutils.h"

/* compiletf() */

static int resistor_compiletf(p_cb_data cb_data) {

vpiHandle funcHandle, i_handle, v_handle, r_handle, didv_handle; int type;

s_vpi_value value; double g; p_resistor_data res;

/* Retrieve handle to current function */ funcHandle = vpi_handle(vpiSysTfCall, NULL);

/* Get the handle on the first function argument*/ i_handle = vpi_handle_by_index(funcHandle, 1);

/* Check that argument exists */ if (!i_handle) {

vpi_error("Not enough arguments for $resistor function.");

}

/* Check that argument #1 is a real variable */ type = vpi_get(vpiType, v_handle);

if (type != vpiRealVar) {

vpi_error("Arg #1 of $resistor should be a real variable"); return 1;

}

/* Get the handle on the second function argument*/ v_handle = vpi_handle_by_index(funcHandle, 2);

/* Check that argument exists */

Copyright © 2009 Accellera Organization, Inc.

300

 

Accellera

Analog and Mixed-signal Extensions to Verilog HDL

Version 2.3.1, June 1, 2009

if (!v_handle) {

vpi_error("Not enough arguments for $resistor function."); return 1;

}

/* Check that argument #1 is a real valued */ type = vpi_get(vpiType, v_handle);

if (type != vpiRealVar && type != vpiRealVal) { vpi_error("Arg #2 of $resistor should be a real variable"); return 1;

}

/* Get the handle on the third function argument*/ r_handle = vpi_handle_by_index(funcHandle, 3);

/* Check that argument exists */ if (!v_handle) {

vpi_error("Not enough arguments for $resistor function."); return 1;

}

/* Check that argument #3 is real valued */ type = vpi_get(vpiType, r_handle);

if (type != vpiRealVar && type != vpiRealVal) { vpi_error("Arg #3 of $resistor should be a real variable"); return 1;

}

return 0;

}

/* derivtf() */

static p_vpi_stf_partials resistor_derivtf(p_cb_data cb_data) { static t_vpi_stf_partials derivs;

static int deriv_of[] = { 1 }; static int deriv_to[] = { 2 };

derivs.count = 1; derivs.derivative_of = deriv_of; derivs.derivative_to = deriv_to;

return &derivs;

}

/* load() */

static int resistor_calltf(int data, int reason) { vpiHandle funcHandle, i_handle, v_handle, didv_handle; double g;

s_vpi_value value;

/* Retrieve handle to current function */ funcHandle = vpi_handle(vpiSysTfCall, NULL); i_handle = vpi_handle_by_index(funcHandle, 1); v_handle = vpi_handle_by_index(funcHandle, 2);

didv_handle = vpi_handle_multi(vpiDerivative, i_handle, v_handle);

/* Get resistance value, compute conductance and store it as */ /* derivative */

value.format = vpiRealVal; vpi_get_value(r_handle, &value);

301

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

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