【问题标题】:Creating C++ testbench to drive a Verilog DUT创建 C++ 测试平台来驱动 Verilog DUT
【发布时间】:2015-10-19 06:40:58
【问题描述】:

我正在尝试了解如何在 Verilog 中创建 C++ 测试平台来驱动对 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.
    }

在此示例中,条件变量上的等待语句将永远阻塞,并且不会让模拟器执行 Verilog 代码的任何其他部分。那么这里的正确方法是什么?我应该在 wait_for_input_ready 函数中用 C++ 创建一个线程并完全分离它吗?

【问题讨论】:

    标签: c++ verilog system-verilog system-verilog-dpi


    【解决方案1】:

    您不能将 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

    【讨论】:

    • 感谢戴夫的指点。我正在尝试创建一个独立的(线程)C++ 测试平台,它将通过 Scemi API(例如基于函数的 DPI-C)与仿真器上合成的 HDL 进行通信。但即使在我转向模拟器之前,我也想使用我的模拟器来测试整个事情(通过在 tb_top 中调用我的 c++ 测试用例),因为所有模拟器都支持 DPI-C。因此,我的 C++ 测试平台运行一个线程,该线程将等待来自 HDL 的输入就绪通知。来自 HDL 的通知调用将解除阻塞等待的 C++ 线程,该线程将依次将数据发送到 DUT。或者这甚至可能吗?
    • SCE-MI 有一个服务循环,通过模拟仲裁 C++ 端的所有线程。我认为可以将 SCE-MI 与纯软件模拟一起使用,但我不确定。我认为直接联系您的供应商会获得更好的帮助,因为在这方面有知识的人并不多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    相关资源
    最近更新 更多