Title: Cosimulation using ModelSim
1Cosimulation using ModelSim
- Prepared by
- Hemanta Gupta
- IV Yr. B.Tech, CSE
2Cosimulation
- Given a source application, it can be partitioned
such that some modules are implemented in HW
the rest in SW. - After partitioning, HW modules are available as
VHDL code SW modules as C code. - Cosimulation - Simulating the VHDL C modules
together for verification performance analysis.
3Modelsim
- Modelsim from Model Technologies - Tool chosen
for Cosimulation. - Provides useful feature known as Foreign
Language Interface (FLI).
4Foreign Language Interface
- FLI routines - C programming language functions
that provide procedural access to information
within Modelsims HDL simulator. - Can be used 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, and control (to some extent)
a simulation run.
5Foreign Language Interface (Contd.)
- Foreign Subprogram - 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) which may
include accessing simulator information through
FLI function calls, writes its inout and out
parameters, and returns a value (in the case of a
function).
6Simple Source Program Model
- A generic C program has a series of global
variables and function definitions followed by a
main( ) function. - Assumption - Nested function calls are assumed
to occur only within main( ) . - The main( ) function in turn may be viewed as an
alternating set of SW blocks calls to HW
functions.
7Simple Source Program Model (Contd.)
- main( )
-
- Variable declaration
- --------------------------
- SW block //no embedded HW calls
- --------------------------
- HW call(s)
- --------------------------
- SW block
- --------------------------
- HW call(s)
8Original Strategy for Cosimulation
- For the original source program, assume that n
functions have been mapped to HW. - Create a top-level VHDL entity whose architecture
consists of (n1) processes running concurrently. - One process corresponds to the C main( )
function, while the remaining n processes
correspond to the n functions mapped to HW.
9Original Strategy for Cosimulation (Contd.)
- Each function mapped to HW has a set of signals
associated with it, viz. a start bit, a stop bit,
a set of input signals a set of output signals. - The set of signals for all n functions is
declared in the architecture of the top-level
entity.
10Original Strategy for Cosimulation (Contd.)
- A process corresponding to a HW function has the
following general structure - Process begin
- Wait until start1 and startEVENT
- Start lt 0
- Read input values from set of input signals
- Call appropriate VHDL function/procedure with
these input values as parameters - Set output signals with the values returned
- Stop lt 1
- End process
11Original Strategy for Cosimulation (Contd.)
- The process corresponding to main( ) simply
contains a call to an equivalent foreign
subprogram with the following structure - main( )
-
- Create handles for all signals declared in
top-level entity - ------------------------------------------------
-------------------- - Variable declaration
- --------------------------------------------------
------------------ - SW block
- --------------------------------------------------
------------------ - Set input signals appropriately using handles
- Set start bit to high
- Wait for stop bit to go high
? HW call - Set stop bit to low
- Read required values from output signals
- --------------------------------------------------
------------------ - SW block
-
12Original Strategy for Cosimulation (Contd.)
- --architecture for top-level entity
- Signal
- Signal
- Main process begin
- Call foreign subprogram for main( )
- End process
- HW_1 process begin
-
- End process
- .
- .
- .
- HW_n process begin
-
- End process
13Original Strategy for Cosimulation (Contd.)
- Issues
- FLI API does not provide a facility for waiting
on a signal within a foreign subprogram.
14Current Strategy for Cosimulation
- Cosimulation strategy - Create a top-level VHDL
entity whose architecture consists of a single
sequential process corresponding to the C main( )
function. - Create local variables for this process
corresponding to the local variables defined in
main( ).
15Current Strategy for Cosimulation (Contd.)
- For each of the contiguous blocks of SW code in
main( ), create a corresponding foreign
subprogram within the VHDL design. - Each foreign subprogram reads/writes to required
variables by creating handles corresponding to
the local variables which are written to/read
within the corresponding SW block in main( ).
16Current Strategy for Cosimulation (Contd.)
- Functions mapped to HW are also made available as
VHDL procedures/functions within the VHDL design. - The C main( ) function is then translated to the
equivalent single process within the VHDL
top-level entity.
17Current Strategy for Cosimulation (Contd.)
- --Architecture of top-level entity
- Process
- Variable .
- Variable .
- begin
- Call to foreign subprogram ? SW block
- ------------------------------------------------
------------ - Call to VHDL functions/procedures ? HW call
- ------------------------------------------------
------------ - Call to foreign subprogram ? SW block
- ------------------------------------------------
------------ - Call to VHDL functions/procedures ? HW call
- End process
18Current Strategy for Cosimulation (Contd.)
- Issues
- Undesirable fragmentation of main( ).
- Problems with handling SW HW calls embedded
within loops.
19Generic Program Model
- Earlier restriction on nesting function calls is
removed. Function calls may be nested anywhere. - Functions have a more generic structure in which
basic operations, HW functions calls and SW
function calls need to be handled in different
ways.
20Generic Program Model (Contd.)
- Function structure
- lttypegt ltnamegt (ltargsgt)
-
- Variable declaration
- .
- Block of Basic instructions
- .
- Call to SW function
- .
- Call to HW function
- .
21Proposed Cosimulation Strategy
- Assume that the original source consists of
(mn1) functions with m mapped to SW, n to HW
and 1 main( ) function. - Create a top-level VHDL entity whose architecture
consists of (m1) sequential processes
(corresponding to the m SW functions 1 main )
and n procedures (corresponding to the n HW
functions)
22Proposed Cosimulation Strategy (Contd.)
- Each of the m SW functions is mapped to an
equivalent process in the VHDL design. - Each of these processes has a start signal, a
stop signal a set of I/O signals which are all
declared in the architecture of the top-level
entity.
23Proposed Cosimulation Strategy (Contd.)
- Translation of SW function to equivalent process
- SW_fun_i process
- Variable ? Equivalent to local variables in SW
fun. - Begin
- Wait until start goes high reset it
- .
- Call foreign subprogram eq. to C basic
instruction block - .
- Set appropriate Input signals
- Set appropriate start signal to high ? SW fun.
call - Wait for appropriate stop signal to go high
reset it - Read return value from Output signals
- .
- Call appropriate VHDL procedure ? HW fun. Call
- .
- Set stop to high
- End process
24Proposed Cosimulation Strategy (Contd.)
- Translation of HW function to equivalent VHDL
procedure - Procedure HW_fun_k() is
- Variable declaration
- Begin
- .
- VHDL instructions eq. to C basic instruction
block - .
- Set appropriate Input signals
- Set appropriate start signal to high ? SW fun.
call - Wait for appropriate stop signal to go high
reset it - Read return value from Output signals
- .
- Call appropriate VHDL procedure ? HW fun. Call
- .
- End process
25Proposed Cosimulation Strategy (Contd.)
- The process corresponding to the C main( )
function needs no start, stop or I/O signals
since it is executed only once is not called
from any other function. - Apart from this, the strategy for creating this
process is the same as that for creating the
processes corresponding to the m SW functions.
26Proposed Cosimulation Strategy (Contd.)
- Translation of main( ) to equivalent process
- Main process
- Variable ? Equivalent to local variables in C
main. - Begin
- .
- Call foreign subprogram eq. to C basic
instruction block - .
- Set appropriate Input signals
- Set appropriate start signal to high ? SW fun.
call - Wait for appropriate stop signal to go high
reset it - Read return value from Output signals
- .
- Call appropriate VHDL procedure ? HW fun. Call
- .
- End process