Technical data

Using the VHDL FLI with foreign subprograms
ModelSim EE/PLUS Reference Manual VHDL Foreign Language Interface and Verilog PLI
-
461
C subprogram example
Functions declared in this code,
in_params
and
out_params,
have parameters
and return types that match the procedures in the subsequent package declaration
(
pkg
).
#include <stdio.h>
#include "mti.h" ‘
char *severity[] = { "NOTE", "WARNING", "ERROR", "FAILURE"};
static char *get_string(varID id);
void in_params (
int vhdl_integer, /* IN integer */
int vhdl_enum, /* IN severity_level */
double *vhdl_real, /* IN real */
varID vhdl_array /* IN string */
)
{
printf("Integer = %d\n", vhdl_integer);
printf("Enum = %s\n", severity[vhdl_enum]);
printf("Real = %g\n", *vhdl_real);
printf("String = %s\n", get_string(vhdl_array)); }
void out_params (
int *vhdl_integer, /* OUT integer */
char *vhdl_enum, /* OUT severity_level */
double *vhdl_real, /* OUT real */
varID vhdl_array /* OUT string */
)
{
char *val;
int i, len, first;
*vhdl_integer += 1;
*vhdl_enum += 1;
if (*vhdl_enum > 3)
*vhdl_enum = 0;
*vhdl_real += 1.01;
/* rotate the array */
val = mti_GetArrayVarValue(vhdl_array, NULL);
len = mti_TickLength(mti_GetVarType(vhdl_array));
first = val[0];
for (i = 0; i < len - 1; i++)
val[i] = val[i+1];
val[len - 1] = first;
}