2015-10-19 176 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,但我不確定。我認爲你會更直接地聯繫你的供應商,因爲在這方面沒有那麼多知識的人。 –