2015-10-19 171 views
0

我想了解如何创建一个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++创建一个线程并完全分离它吗?

回答

3

您不能将SystemVerilog线程的概念与C++线程混合在一起。从DPI的角度来看,一切都在同一个线程中执行。如果您希望C++代码看起来像是SystemVerilog线程,则需要将您的C++代码作为任务导入,并让它调用导出的SystemVerilog任务。

你可能需要阅读一些链接: https://s3.amazonaws.com/verificationacademy-news/DVCon2013/Papers/MGC_DVCon_13_Easy_Steps_Towards_Virtual_Prototyping_Using_the_SystemVerilog_DPI.pdf

https://verificationacademy.com/forums/ovm/how-maintain-database-c-function-if-firmware-hardware-co-simulation-used#reply-37204

+0

感谢您的指针戴夫。我正在尝试创建一个独立的(线程化)C++测试平台,它将通过Scemi API(例如基于DPI-C的函数)与模拟器上合成的HDL进行通信。但即使在我转向模拟器之前,我想用我的模拟器来测试整个事件(通过在tb_top中调用我的C++测试用例),并且因为所有模拟器都支持DPI-C。所以我的C++测试平台运行一个线程,它将等待来自HDL的输入就绪通知。来自HDL的通知调用将取消阻塞正在等待的C++线程,该线程将把数据发送到DUT。或者这甚至有可能? – sundar

+0

SCE-MI有一个服务循环,通过仿真来仲裁C++端的所有线程。我认为可以用纯软件模拟来使用SCE-MI,但我不确定。我认为你会更直接地联系你的供应商,因为在这方面没有那么多知识的人。 –