UVM基础知识1:在vcs中,sv通过DPI调用C函数实例(连接简单的C子程序)

来源:systemverilog验证 测试平台编写指南(书籍)


1 新建counter7.c文件

    vi counter7.c

#include

void counter7(
            svBitVecVal * o,
    const   svBitVecVal * i,
    const   svBit         reset,
    const   svBit         load){
  
  static unsigned char count = 0;

  if (reset)      count = 0;
  else if (load)  count = *i;
  else            count++;
  count = count&0x7f;

  *o = count;
}

2 新建counter.sv文件

 vi counter.sv


3 制作makefile

import "DPI-C" function void counter7 ( 
    output bit[6:0] out,
    input bit[6:0]  in,
    input bit       reset,load);

import "DPI-C" function real sin(input real r); 

program automatic counter;
  bit [6:0] out, in;
  bit       reset,  load;

  initial begin 
    $display("sin(0.5) = %f",sin(0.5));

    $monitor ("SV: out = %3d, in = %3d, reset = %0d, load = %0d\n",out, in, reset, load);
    reset = 0;
    load  = 0;
    in    = 126;
    out   = 42;
    counter7(out, in, reset, load);

    #10 reset = 1;
    counter7(out, in, reset, load);

  end 
endprogram

vi makefile

run: vcs sim 

vcs:
	vcs -full64 -sverilog counter.sv counter7.c

sim:
	./simv

clean:
	rm -f simv novas.conf *.log *.dump *.rc *.key test.fsdb
	rm -rf csrc/ simv.daidir/ verdiLog/


4 输入 make run 即可有以下结果

UVM基础知识1:在vcs中,sv通过DPI调用C函数实例(连接简单的C子程序)_第1张图片


你可能感兴趣的:(UVM基础知识)