我想了解如何创建一个C++测试平台来驱动Verilog中的DUT激励。比方说,我有一个简单的场景:创建C++测试平台来驱动Verilog DUT
// Testbench Top.
module tb_top();
import "DPI-C" function void wait_for_input_ready();
initial
wait_for_input_ready();
import "DPI-C" function void notify_input_ready();
always @(posedge clk or negedge rst)
begin
// based on some condition here I want to send input-ready notify.
notify_input_ready();
end
endmodule
这里是我的C++代码:
test_case.h
extern "C" void wait_for_input_ready();
extern "C" void notify_input_ready();
test_case.cpp
#include "test_case.h"
std::conditional_variable cond_var;
std::mutex input_mutex;
bool input_ready = false;
void wait_for_input_ready()
{
std::unique_lock<std::mutex> lock(input_mutex);
while(input_ready != true)
cond_var.wait(lock, [&]{return input_ready == true;}); // This is where the problem happens.
}
void notify_input_ready()
{
std::unique_lock<std::mutex> lock(input_mutex);
is_ready = true;
cond_var.notify_one(); // Unblock to wait statement.
}
在这个例子中,条件变量上的等待语句永远阻塞,并且不会让模拟器执行Ve的任何其他部分rilog代码。那么这里的正确方法是什么?我应该在wait_for_input_ready函数里面用C++创建一个线程并完全分离它吗?
感谢您的指针戴夫。我正在尝试创建一个独立的(线程化)C++测试平台,它将通过Scemi API(例如基于DPI-C的函数)与模拟器上合成的HDL进行通信。但即使在我转向模拟器之前,我想用我的模拟器来测试整个事件(通过在tb_top中调用我的C++测试用例),并且因为所有模拟器都支持DPI-C。所以我的C++测试平台运行一个线程,它将等待来自HDL的输入就绪通知。来自HDL的通知调用将取消阻塞正在等待的C++线程,该线程将把数据发送到DUT。或者这甚至有可能? – sundar
SCE-MI有一个服务循环,通过仿真来仲裁C++端的所有线程。我认为可以用纯软件模拟来使用SCE-MI,但我不确定。我认为你会更直接地联系你的供应商,因为在这方面没有那么多知识的人。 –