Presentation is loading. Please wait.

Presentation is loading. Please wait.

VHDL FLI. FLI Definition FLI routines are C programming language functions that provide procedural access to information within the HDL simulator.

Similar presentations


Presentation on theme: "VHDL FLI. FLI Definition FLI routines are C programming language functions that provide procedural access to information within the HDL simulator."— Presentation transcript:

1 VHDL FLI

2 FLI Definition FLI routines are C programming language functions that provide procedural access to information within the HDL simulator

3 Using the VHDL FLI A user-written application can use these functions to: – traverse the hierarchy of an HDL design – get information about and set the values of VHDL objects in the design – get information about a simulation – control (to some extent) a simulation run

4 Important Concepts -Elaboration When the simulator starts, it first goes through an elaboration phase during which the entire design is loaded and connected and initial values are set. During his phase all foreign shared libraries are loaded and the initialization functions of all foreign architectures are executed.

5 Foreign Architecture A foreign architecture is a design unit that is instantiated in a design but that does not (generally) contain any VHDL code Instead it is a link to a C model that can communicate to the rest of the design through the ports of the foreign architecture a C model creates processes and reads and drives signal values behaving in the same manner as VHDL code but with the advantage of the power of C

6 Foreign Subprogram A foreign subprogram is a VHDL function or procedure that is implemented in C as opposed to VHDL A foreign subprogram: – reads its in and inout parameters – performs some operation(s) – writes its inout and out parameters

7 Using the VHDL FLI with Foreign Architectures To use the foreign language interface with C models, you first define Attribute ATTRIBUTE foreign OF arch_name : ARCHITECTURE IS “app_init app.so[; parameter]”; app_init — The name of the initialization function for this architecture. This part is required. app.so — The path to the shared object file to load. This part is required. parameter — A string that is passed to the initialization function. This part is preceded by a semicolon and is optional

8 Location of Shared Object Files The simulator searches for object files in the following order – $MGC_WD/ or./ (If MGC_WD is not set, then it will use “.”) – – within $LD_LIBRARY_PATH ($SHLIB_PATH on HP only) – $MGC_HOME/lib/ – $MODEL_TECH/ – $MODEL_TECH/../

9 The C Initialization Function allocates memory to hold variables for the instance registers a callback function to free the memory when the simulator is restarted saves the handles to the signals in the port list creates drivers on the ports that will be driven creates one or more processes (a C function that can be called when a signal changes) sensitizes each process to a list of signals

10 declaration of initialization func app_init( mtiRegionIdT region, char *param, mtiInterfaceListT *generics, mtiInterfaceListT *ports ) The header file mti.h externs all of the FLI functions and types that can be used by an FLI application.

11 Declaring a Foreign Subprogram in VHDL To call a foreign C subprogram: – write a VHDL subprogram declaration that has the equivalent VHDL parameters and return type – use the FOREIGN attribute to specify which C function and module to load – write a subprogram body for the subprogram, but it will never be called

12 Declaring a Foreign Subprogram in VHDL procedure in_params( vhdl_integer : IN integer; vhdl_enum : IN severity_level; vhdl_real : IN real; vhdl_array : IN string); attribute FOREIGN of in_params : procedure is “in_params app.dll”; procedure in_params( vhdl_integer : IN integer; vhdl_enum : IN severity_level; vhdl_real : IN real; vhdl_array : IN string) is begin report “ERROR: foreign subprogram in_params not called”; end;

13 Matching VHDL Parameters with C Parameters

14 Arrays Array and record SIGNAL parameters are passed as an mtiVariableIdT type Any array or record subelements of these composite variables are also of type mtiVariableIdT The values of all scalar subelements are of type mtiSignalIdT Arrays are not NULL-terminated. The length of an array can be determined by calling mti_TickLength() on the array’s type. To access the signal IDs, use mti_GetVarSubelements() at each composite level For each subelement that is of a scalar type, use mti_GetVarValueIndirect() to get the signal ID of the scalar

15 Enumeration Enumeration object values are equated to the position number of the corresponding identifier or character literal in the VHDL type declaration -- C interface values TYPE std_ulogic IS('U',-- 0 'X',-- 1 '0',-- 2 '1',-- 3 'Z',-- 4 'W',-- 5 'L',-- 6 'H',-- 7 '-' – );

16 Matching VHDL Return Types with C Return Types

17 C Example #include #include "mti.h“ char *severity[] = {"NOTE", "WARNING", "ERROR", "FAILURE"}; static char *get_string(mtiVariableIdT id); void in_params ( int vhdl_integer, /* IN integer */ int vhdl_enum, /* IN severity_level */ double *vhdl_real, /* IN real */ mtiVariableIdT 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)); }

18 C Example void out_params ( int *vhdl_integer, /* OUT integer */ char *vhdl_enum, /* OUT severity_level */ double *vhdl_real, /* OUT real */ mtiVariableIdT 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;

19 C Example /* 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; }

20 C Example /* Convert a VHDL String array into a NULL terminated string */ static char *get_string(mtiVariableIdT id) { static char buf[1000]; mtiTypeIdT type; int len; mti_GetArrayVarValue(id, buf); type = mti_GetVarType(id); len = mti_TickLength(type); buf[len] = 0; return buf; }

21 Package (pkg) Example package pkg is procedure in_params( vhdl_integer : IN integer; vhdl_enum : IN severity_level; vhdl_real : IN real; vhdl_array : IN string); attribute foreign of in_params : procedure is "in_params test.dll"; procedure out_params( vhdl_integer : OUT integer; vhdl_enum : OUT severity_level; vhdl_real : OUT real; vhdl_array : OUT string); attribute foreign of out_params : procedure is "out_params test.dll"; end;

22 Package (pkg) Example package body pkg is procedure in_params( vhdl_integer : IN integer; vhdl_enum : IN severity_level; vhdl_real : IN real; vhdl_array : IN string) is begin report "ERROR: foreign subprogram in_params not called"; end; procedure out_params( vhdl_integer : OUT integer; vhdl_enum : OUT severity_level; vhdl_real : OUT real; vhdl_array : OUT string) is begin report "ERROR: foreign subprogram out_params not called"; end;

23 Entity (test) Example entity test is end test; use work.pkg.all; architecture only of test is begin process variable int : integer := 0; variable enum : severity_level := note; variable r : real := 0.0; variable s : string(1 to 5) := "abcde"; begin for i in 1 to 10 loop in_params(int, enum, r, s); out_params(int, enum, r, s); end loop; wait; end process; end;


Download ppt "VHDL FLI. FLI Definition FLI routines are C programming language functions that provide procedural access to information within the HDL simulator."

Similar presentations


Ads by Google