gpt4 book ai didi

c++ - 创建 C++ 测试台以​​驱动 Verilog DUT

转载 作者:行者123 更新时间:2023-11-28 00:10:51 24 4
gpt4 key购买 nike

我正在尝试了解如何创建一个 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++ 代码:

测试用例.h

    extern "C" void wait_for_input_ready();
extern "C" void notify_input_ready();

测试用例.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++ 创建一个线程并将其完全分离吗?

最佳答案

您不能将 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++ - 创建 C++ 测试台以​​驱动 Verilog DUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33208099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com