SystemVerilog_DPI

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

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

1 / 63
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功