はじめに
VPI(Verilog Procedural Interface)を試します。
環境はIcarus Verilogです。
Cコードの作成
vpi_user.hをインクルードしてHello Worldを表示するSystemタスクを作成します。
hello.cpp
#include "vpi_user.h"
static int hello_calltf(char *user_data){
vpi_printf("hello world\n");
return 0;
}
void hello_register(void){
s_vpi_systf_data tf_data;
tf_data.type = vpiSysTask; // vpiSysTask or vpiSysFunc
tf_data.tfname = "$hello"; // Verilogで使用するときにSystemタスク名
tf_data.calltf = hello_calltf; // 実行する関数を登録
vpi_register_systf(&tf_data); // 定義したSystemタスクを登録
}
void (*vlog_startup_routines[]) () = { // おまじない
hello_register, 0
};
Verilogコードの作成
Cで作成したSystemタスクをVerilogで呼び出します。
sample.sv
module sample;
initial begin
$hello; // 作成したSystemタスクを実行
end
endmodule
コンパイルと実行
iverilog-vpi hello.cpp
iverilog sample.sv
vvp -M. -mhello a.out
# 出力
# Hello World
まとめ
Icarus Verilog環境でVPIを実装しました。
コメント