|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



EXPORT


Export Methods



Methods implemented in SystemVerilog and specified in export declarations can be called from C, such methods are referred to as exported methods.



Steps To Write Export Methods



In SV Code :
Setp1: Export the systemverilog function


export "DPI-C" function export_func;


Step2: Define the systemverilog function


function void export_func();
$display("SV: Hello from SV ");
endfunction



In C code :
Step3: Export the Systemverilog function


extern void export_func(void);



Step4: Invoke the systemverilog function


void import_func()
{
export_func();
}



Full Example:



CODE: SV_file.sv
program main;

export "DPI-C" function export_func;
import "DPI-C" function void import_func();

function void export_func();
$display("SV: Hello from SV ");
endfunction

initial
begin
import_func();
end

endprogram


CODE: C_file.c
#include "stdio.h"
#include "vc_hdrs.h"
#include "svdpi.h"

extern void export_func(void);

void import_func()
{
export_func();
}

RESULTS:

SV: Hello from SV


Blocking Export Dpi Task




SV Dpi allows C to call a SystemVerilog method which consumes time.



CODE:SV_file.sv
program main;

export "DPI-C" task export_task;
import "DPI-C" context task import_task();

task export_task();
$display("SV: Entered the export function . wait for some time : %0d ",$time);
#100;
$display("SV: After waiting %0d",$time);
endtask

initial
begin
$display("SV: Before calling import function %0d",$time);
import_task();
$display("SV: After calling import function %0d",$time);
end

endprogram
CODE: C_file.c
extern void export_task();

void import_task()
{
printf(" C: Before calling export function\n");
export_task();
printf(" C: After calling export function\n");
}
RESULTS

SV: Before calling import function 0
C: Before calling export function
SV: Entered the export function . wait for some time : 0
SV: After waiting 100
C: After calling export function
SV: After calling import function 100


Index
Introductions
Layers
Import
Naming
Export
Pure And Context
Data Types
Arrays
Passing Structs And Unions
Arguments Type
Disablie

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright 2007-2017 :: all rights reserved www.testbench.in::Disclaimer