一個簡單的import and export case
這個例子是在Cadence的IUS9.2上面所測的
看起來Cadence 的export使用task會有問題, VCS似乎沒有此種限制,
因此本例只使用function
gcc –I/IUS9.2/linux/tools/include/ -shared –o test.so test.c
使用gcc時, 副檔名必須為c
g++ –I/IUS9.2/linux/tools/include/ -fPIC -shared –o test.so test.cpp
使用g++時, 副檔名必須為cpp
-fPIC 對所有的C及C++檔案有宣告 extern項目的code是必要的
irun_92 main.sv –sv_lib test.so
//test.c
#include <stdio.h>
#include “svdpi.h”
extern void ex_task(); // 使用外部的function
void import_task() {
printf(“C: Before calling export function\n”);
ex_task();
printf(“C: After calling export function\n”);
}
//test.cpp
#include <stdio.h>
#include “svdpi.h”
//extern void ex_task();
void import_task() {
//printf(“C: Before calling export function\n”);
//ex_task(); 在Cadence加上g++ 不能使用此種回叫模式
printf(“C: After calling export function\n”);
}
// DPI case
`timescale 1ns/100ps
module main();
export “DPI-C” ex_task = function export_task; //將export_task放給外面使用,
並將名稱改成ex_task, 所以在C/C++中的使用名稱為ex_task, 但在systemverilog的原始定義為export_task()
import “DPI-C” context function void test();
function export_task();
$display(“SV: Entered the export function, wait for some time: %0d”, $time);
endfunction
initial begin
$display(“SV: Before calling import function %0d”, $time);
#1;
import_task();
#1;
$display(“SV: After calling function %0d”, $time);
end
endmodule
沒有留言:
張貼留言