From ec527508ff8cde5de88a043483c16d50dee18995 Mon Sep 17 00:00:00 2001 From: fengbh <1953356163@qq.com> Date: Mon, 9 Dec 2024 15:47:29 +0800 Subject: [PATCH] add me241101_dpi --- .gitignore | 14 ++++++++++++-- me241101_dpi/Makefile | 12 ++++++++++++ me241101_dpi/ReadMe.md | 31 +++++++++++++++++++++++++++++++ me241101_dpi/sv_main.c | 10 ++++++++++ me241101_dpi/testbench.sv | 29 +++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 me241101_dpi/Makefile create mode 100644 me241101_dpi/ReadMe.md create mode 100644 me241101_dpi/sv_main.c create mode 100644 me241101_dpi/testbench.sv diff --git a/.gitignore b/.gitignore index 4a15efa..6fbfca7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -2_dpi -3_python_learn 4_c_re 5_vpi sv_lab @@ -16,3 +14,15 @@ me241100_svExample/simv me241100_svExample/ucli.key me241100_svExample/vc_hdrs.h me241100_svExample/wave.fsdb + +me241101_dpi/csrc/ +me241101_dpi/simv.daidir/ +me241101_dpi/verdiLog/ +me241101_dpi/*.log +me241101_dpi/novas.* +me241101_dpi/simv +me241101_dpi/ucli.key +me241101_dpi/vc_hdrs.h +me241101_dpi/wave.fsdb +me241101_dpi/*.o +me241101_dpi/*.so \ No newline at end of file diff --git a/me241101_dpi/Makefile b/me241101_dpi/Makefile new file mode 100644 index 0000000..2758e60 --- /dev/null +++ b/me241101_dpi/Makefile @@ -0,0 +1,12 @@ +sv_main.so: sv_main.c + - gcc -fPIC -c sv_main.c -I ${VCS_HOME}/include + - gcc -shared -o sv_main.so sv_main.o +#sv_main.so: sv_main.c +# - gcc -fPIC -shared -o sv_main.so -c sv_main.c -I ${VCS_HOME}/include +comp: + - vcs -full64 +v2k -sverilog -LDFLAGS -Wl,--no-as-needed -debug_access+all -top testbench -l compile.log \ + testbench.sv +sim: sv_main.so + - ./simv -l sim.log -sv_root . -sv_lib sv_main +clean: + - \rm -rf *.log simv simv.daidir *.a *.o *.so csrc *.key \ No newline at end of file diff --git a/me241101_dpi/ReadMe.md b/me241101_dpi/ReadMe.md new file mode 100644 index 0000000..03902a0 --- /dev/null +++ b/me241101_dpi/ReadMe.md @@ -0,0 +1,31 @@ +# dpi + +## 概述 + +使用vcs编译dpi的简单例子 + +> 需要准备好vcs+verdi的仿真环境。 + +### 特性 + +- 动态调用 +- Makefile 管理 + +## 快速开始 + +### 一、仿真 + +```bash +make clean comp sim +``` + +### 二、检查log + +查看log,检查是否正确调用dpi。 + +## 更多 + +[PLI 学习 - 博涵 - 博客园](https://www.cnblogs.com/fengbohan/p/18595069/pli-learning-zx6kpe) + + + diff --git a/me241101_dpi/sv_main.c b/me241101_dpi/sv_main.c new file mode 100644 index 0000000..9ab2c9f --- /dev/null +++ b/me241101_dpi/sv_main.c @@ -0,0 +1,10 @@ +#include +#include +#include + +extern void sv_hello(); +int c_hello(const char *name, int age) { + vpi_printf("c_hello: %s, %d\n", name, age); + sv_hello(); + return 0; +} diff --git a/me241101_dpi/testbench.sv b/me241101_dpi/testbench.sv new file mode 100644 index 0000000..d8f7253 --- /dev/null +++ b/me241101_dpi/testbench.sv @@ -0,0 +1,29 @@ +//=========================================================================== +// Organization : Individual Developer +// Filename : testbench.sv +// Author : Feng Bohan +// Create Time : 16:17:37 2024-11-22 +// Last Modified: 16:20:09 2024-11-22 +// Abstract : +//-------------------------------------------------------------------------- +// Description: +// +//-------------------------------------------------------------------------- +// Modification History: +//-------------------------------------------------------------------------- +// Rev Date Who Description +// --- ---- --- ----------- +// 0.0.01 2024-11-22 Feng Bohan initial version +//=========================================================================== +module testbench; + import "DPI-C" context function int c_hello(input string name, input int age); + export "DPI-C" function sv_hello; + function void sv_hello(); + $display("sv_hello"); + endfunction + + initial begin + c_hello("testbench", 18); + end +endmodule +