Table of Contents Previous page Next page Index

ModelSim

Model Technology Inc.


Using the VHDL FLI with foreign architectures

To use the foreign language interface with C models, you first create and compile an architecture with the FOREIGN attribute. The string value of the attribute is used to specify the name of a C initialization function and the name of an object file to load. When the simulator elaborates the architecture, the initialization function is called. Parameters to the function include a list of ports and a list of generics. See "Mapping to VHDL data types" .

Declaring the FOREIGN attribute

Starting with VHDL93, the FOREIGN attribute is declared in package STANDARD. With the 1987 version, you need to declare the attribute yourself. You can declare it in a separate package, or you can declare it directly in the architecture. (This will also work with VHDL93).

The FOREIGN attribute string

The value of the FOREIGN attribute is a string containing three parts. For the following declaration:

ATTRIBUTE foreign OF arch_name : ARCHITECTURE IS "app_init app.so; parameter"; 

the attribute string parses this way:

app_init 

The name of the initialization function for this architecture. This part is required. See "The C initialization function" .

app.so

The path to the shared object file to load. This part is required. See "Location of shared object files" .

parameter

A string that is passed to the initialization function. This part is preceded by a semicolon and is optional.

If the initialization function has a leading '+' or '-', the VHDL architecture body will be elaborated in addition to the foreign code. If '+' is used (as in the example below), the VHDL will be elaborated first. If '-' is used, the VHDL will be elaborated after the foreign initialization function is called.

UNIX environment variables can also be used within the string as in this example:

ATTRIBUTE foreign OF arch_name : ARCHITECTURE IS "+app_init $CAE/app.so"; 

Location of shared object files

The simulator searches for object files in the following order:

In the search information above "<so>" refers to the path specified in the FOREIGN attribute string. MGC_WD and MGC_HOME are user-definable environment variables. MODEL_TECH is set internally by vsim to the directory where the vsim executable resides.

Note: The .so extension will work on all platforms (it is not necessary to use the .sl extension on HPs).

The C initialization function

This is the entry point into the foreign C model. The initialization function typically:

The declaration of an initialization function is:

app_init(
  mtiRegionIdT       region,   
  char              *param,    
  mtiInterfaceListT *generics,  
  mtiInterfaceListT *ports
) 

The function specified in the foreign attribute is called during elaboration. The first parameter is a region ID that can be used to determine the location in the design for this instance. The second parameter is the last part of the string in the foreign attribute. The third parameter is a linked list of the generic values for this instance. The list will be NULL if there are no generics. The last parameter is a linked list of the ports for this instance. The typedef mtiInterfaceListT in mti.h describes the entries in these lists.

Restrictions on generics

RECORD generics are not supported in the foreign language interface.



Model Technology Inc.
Voice: (503) 641-1340
Fax: (503)526-5410
http://www.model.com
sales@model.com
TOC PREV NEXT INDEX

ModelSim