SystemVerilogSynopsysGlobalTechnicalServices©2008Synopsys,Inc.AllRightsReserved,VeriSiliconOnlyMaynotbedisclosedtoany3rdpartywithoutwrittenSynopsysconsentSystemVerilogDPI(DirectProgrammingInterface)VCS2006.06-SP2-2AgendaIntroduction1ImportingCMethodsScalarArguments2ImportingCMethods32©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2pgArrayArguments3OpenArrays4ExportingSystemVerilogmethodsContext/Puremethods5Compilation&Debug6DPISystemVerilogStandardtoconnectforeign-languagesDoesnotreplacePLI/VPIRestrictedDataTypesLittleAccesstoSimDatabaseFaster&EasierthanPLIC/C++(Model)NTB-OVorNTB-SVVerilog/SVDUTIntroduction:CIntegrationSupport3©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2PLI/VPIIEEEsimulationAPIWaveformdumpNetlistanalysisDirectCProprietaryVCSI/FForlegacyCode.DPIfornewapplicationsVCSMX(Model)SystemCModel DPI:DirectProgrammingInterfaceAninterfacebetweenSystemVerilogandaforeignprogramminglanguage:CorC++SimpleinterfacetoCmodelsAllowsSystemVerilogtocallaCfunctionjustlikeanyothernativeSystemVerilogfunction/taskVariablespasseddirectlyto/fromC/C++NOneedtowritePLI-likeapplications/wrappers4©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2WhyDPI?SystemVerilogusershaveC/C++indesignsandtestbenchthattheywanttoreuseDPIeasilyconnectsC/C++codetoSVwithouttheoverheadorcomplexityofVPI/PLISupportbothfunctionsandtasksSystemVerilogcancallCandCcancallSVImportDPI-CSystemVerilogcallingC/C++taskCcodemusthave:#includesvdpi.h//SystemVerilogcodeprogramautomatictest;importDPI-Ccontexttaskc_test(inputintaddr);QuickExample:ImporttaskfromC5©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2initialc_test(1000);endprogram//Ccode#includesvdpi.hvoidc_test(intaddr){...}vcs–R–sverilogtop.svc_test.cExportDPI-CCcallsSystemVerilogfunctionsorblockingtasksprogramautomatictest;importDPI-Ccontexttaskc_test(inputintaddr);initialctest(1000);#ilddihQuickExample:ExportSVTasktoC6©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2initialc_test(1000);exportDPI-Ctaskapb_write;taskapb_write(inputintaddr,data);...@(posedgeready);...endtaskendprogram#includesvdpi.hexternvoidapb_write(int,int);voidc_test(intaddr){...apb_write(addr,data);...}vcs–sverilogtop.svc_test.cDPIvs.TLITLITransactionLevelInterfaceinVCSforSystemC-SystemVerilogtransactionlevelco-simulationSystemCcallingSystemVeriloginterfacefunctions/tasksforclassmethodsSystemVerilogcallSystemCinterfacemethodsBlockingornon-blocking7©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2Underthehood,TLIisimplementedwithDPIButeasiertouseAutomaticallysynchronizesbetweentheSystemCdomainandSystemVerilogAgendaIntroduction1ImportingCMethodsScalarArguments2ImportingCMethods38©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2pgArrayArguments3OpenArrays4ExportingSystemVerilogmethodsContext/Puremethods5Compilation&Debug6ImportingaCroutineintoSystemVerilogBeforeyoucanuseaCroutineinSystemVerilog,youmustimportitThisdeclarestheCroutineinthecurrentscopeNowyoucancalltheCroutineasifitwereaSystemVerilogtaskorfunction9©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2SystemVerilogtaskorfunctionSystemVerilogdatatypesarepassedthroughtheargumentlistandmappedintoequivalentCstructuresIfaCroutinecallsbackintoSystemVerilog,itshouldbedeclaredasatask,otherwiseafunctionDeclarationofImportedFunctionsandTasksAnimportedtaskorfunctioncanbedeclaredanywhereanativeSVfunctionortaskcanbedeclaredImportedtasksandfunctionscanhavezeroormoreinput,outputandinoutarguments.refisnotallowed.ImportedtasksalwaysreturnavoidvalueimportDPI-CfunctionvoidmyInit();importDPI-Cpurefunctionrealsin(inputrealr);//math.h10©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2Importedfunctionscanreturna“small”valueorbeavoidfunctionvoid,byte,shortint,int,longint,real,shortreal,chandle,andstringScalarvaluesoftypebitandlogicMapCroutinenameifitconflictswithexistingSystemVerilogname//MaptheCroutine“test”to“c_test”inSystemVerilog.importDPI-Ctest=taskc_test();importDPI-CfunctionintgetStim(inputstringfname);MapargumentsbetweenSystemVerilogandCRecommendation:useintwheneverpossible!ItisyourresponsibilitytocorrectlydeclarecompatibledatatypesTheDPIdoesnotcheckfortypecompatibilityVCSproducesvc_hdrs.hwhenyoucompileUseitasaguidetoseehowtypesaremappedArgumentPassing11©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2ArgumentdirectionsinputInputtoCcodeoutputOutputfromCcode(initialvalueundefined)inoutInputandOutputfromCcoderefNotsupportedbyLRM.UseinoutinsteadFunctionreturntypes(32b)(unsigned)int,char*ArgumentDirectionInputargumentSmallvaluesofformalinputargumentspassedbyvalueint-int,bit-unsignedcharOthertypes(bit[7:0])arepassedbyreferenceInoutandoutputargumentspassedbyreference12©2008Synopsys,Inc.AllRightsReservedVCS2006.06-SP2-2OpenarraysarealwayspassedbyahandleShowninnextsectionProtectionIt’suptotheCcodetonotmodifyinputparametersUseconsttodoublecheckyourCcodeCommonmistake–forgettingargumentdirectionimportDPI-Cfunctionvoidbug(intout);A32-bit2-StateCounterprogramauto