# 四、DPI-C机制 ## 1. DPI-C的介绍 DPI-C(Direct Programming Interface for C) 是允许SystemVerilog与C或C++代码交互的接口。虽然是SystemVerilog的内容,但是许多Verilog仿真器也支持。 ## 2. VCS使用DPI-C示例 我们使用[VCS仿真框架搭建](VCS仿真框架搭建.md)一节中的示例,进行修改。 ### 2.1 创建C文件 创建`csrc`文件夹,并在此文件夹下创建`dpi.c`文件: ```c #include #include #define SIZE 3 //检测101 const char series[SIZE] = {1,0,1}; static int count = 0; static char buf[SIZE] = { 0 }; void demo_difftest(char out){ static diff_out_last=false; //存储上一次的结果 bool diff_out = true;; if(count < SIZE) return; for(int i=0; i