P. 1
QuestaSim Tutorial

QuestaSim Tutorial

|Views: 688|Likes:
Published by Vivek
Questa Sim tutorial!
Questa Sim tutorial!

More info:

Published by: Vivek on Jan 15, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

04/11/2014

pdf

text

original

Questa SIM Tutorial, v10.0c

236

Using SystemVerilog DPI for Data Passing

Run the Simulation

1/* MTI_DPI */
2
3/*
4 * Copyright 2004 Mentor Graphics Corporation.
5 *
6 * Note:
7 * This file is automatically generated.
8 * Please do not edit this file - you will lose your edits.
9 *

10 * Settings when this file was generated:
11 * PLATFORM = 'win32'
12 * Info = SE 6.1c 2005.11
13*/
14#ifndef INCLUDED_DPI_TYPES
15#define INCLUDED_DPI_TYPES
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include "svdpi.h"
22
23DPI_DLLESPEC
24void
25print_int(
26

int int_in);

27
28DPI_DLLESPEC
29void
30print_logic(
31

svLogic logic_in);

32
33#ifdef __cplusplus
34} /* extern "C" */
35#endif
36
37#endif /* INCLUDED */
38

AtthetopofthisfileisinformationforinternalDPIpurposes.Butifyougodowntoline
25, you'll see a function prototype for the print_int function. As expected, the input
parameter is an int type.

Justbelowthisfunctionistheprototypeforthe print_logicfunction,whichhasaninput
parameter of type "svLogic" (i.e. SystemVerilog Logic). This file includes another
headerfilecalled svdpi.h,whichispartoftheSystemVeriloglanguageandisshippedin
the Questa SIM installation directory (that's why we have "-
I$(QUESTA_HOME)/include"onthecommandlineforCcompilationintheMakefile's
"foreign" target – seeFigure17-3). This svLogic type is basically an unsigned char.

When you put #include dpi_types.h in your C source file, all these function prototypes
and data types will be made available to you. In fact, we strongly recommend that you
use this file when writing the C code that will interface with Verilog via DPI.

Lookbackatthe test.svfile(Figure17-2)andlookfortheDPIimportstatements.There
isonefor print_intandonefor print_logic.Thevlogcompilerlooksatthesestatements,
sees the names of the functions being imported along with their parameters and return
values (in Verilog terms), and then creates the correct DPI header file for you. In the
caseofthe print_logicfunction,itsawthattheinputparameterwasoftype"logic".Soit

Using SystemVerilog DPI for Data Passing

Lesson Wrap-Up

Questa SIM Tutorial, v10.0c

237

put logic's counterpart of "svLogic" in the header file. Now both elements of the dual
personality for this particular object are defined and everything should pass over to C
properly.

Let'sgobacktosimulation.Weshouldbeonline#26,justafterthepointwherethebad
logicvalueof0gotprintedinsteadofanX.Nowthatweknowwewereusingthewrong
function for this particular type of data, we will use the print_logic function instead.

15.ClickStepOvertoexecutethisline.TheXvalueisprintedoutthistime(Figure17-11).
You can take a look at the foreign.c file to see how this was accomplished.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->