Skip to content

Commit 1d7d73d

Browse files
committed
Add VPI C example
1 parent 7391256 commit 1d7d73d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

tests/basic/README.org

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#+title: Nim/SystemVerilog VPI Example
2+
3+
This directory contains the "Hello" example from [[https://www.asic-world.com/verilog/pli6.html][this asic-world PLI
4+
tutorial]] translated from C to Nim.
5+
6+
- To run the Nim code with SystemVerilog, run ~make~ in this
7+
directory.
8+
- To run the original C code from the tutorial, cd to the ~orig/~
9+
directory in here, and run ~make~ there.

tests/basic/orig/libvpi.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// https://www.asic-world.com/verilog/pli6.html
2+
3+
#include "vpi_user.h"
4+
5+
void hello() {
6+
vpi_printf("\n\nHello!!\n\n");
7+
}
8+
9+
// Associate C Function with a New System Task
10+
void registerHelloSystfs() {
11+
s_vpi_systf_data task_data_s;
12+
p_vpi_systf_data task_data_p = &task_data_s;
13+
task_data_p->type = vpiSysTask;
14+
task_data_p->tfname = "$hello";
15+
task_data_p->calltf = hello;
16+
task_data_p->compiletf = 0;
17+
18+
vpi_register_systf(task_data_p);
19+
}
20+
21+
// Register the new system task here
22+
// https://cdecl.org/?q=void+%28*vlog_startup_routines%5B+%5D+%29+%28%29
23+
void (*vlog_startup_routines[ ] ) () = {
24+
registerHelloSystfs,
25+
0 // last entry must be 0
26+
};

tests/basic/orig/tb.sv

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../tb.sv

0 commit comments

Comments
 (0)