【UVM】ScoreBoardを作成する~Monitor階層からトランザクションを取得する~【#1】

Systemverilog

はじめに

ScoreBoardはDUTの出力と期待値を比較する階層です。

UVMモデルのMonitorとAnalysis Portを介してDUTの出力を取得します。

サンプルコード

sample_scoreboard.svh

uvm_scoreboardを継承してsample_scoreboard.svhを作成します。

class sample_scoreboard extends uvm_scoreboard;
    `uvm_component_utils(sample_scoreboard)
    // Analysis Exportを宣言
    uvm_analysis_imp#(sample_sequence_item, sample_scoreboard) item_collected_export;

    function new(string name, uvm_component parent);
        super.new(name, parent);
        item_collected_export = new("item_collected_export", this);  // Analysis Exportを生成
    endfunction

    function void build_phase(uvm_phase phase);
        super.build_phase(phase);
    endfunction

    virtual function void write(sample_sequence_item item);  // Monitorから呼ばれるtask
        `uvm_info(this.get_name(), $sformatf("data=%x", item.data), UVM_NONE);
    endfunction

    virtual function void check_phase(uvm_phase phase);  // シミュレーション終了時に呼ばれる。まだ未使用。
    endfunction
endclass
sample_monitor.svh

Analysis Portを作成してScoreBoardにデータを送信します。

class sample_monitor extends uvm_monitor;
    `uvm_component_utils(sample_monitor)

    // ScoreBoardにデータを送信するためのAnalysis Portを宣言
    uvm_analysis_port#(sample_sequence_item) item_collected_port;

    virtual sample_if vif;
    sample_sequence_item item;

    function new(string name, uvm_component parent);
        super.new(name, parent);
        item = new("sample_sequence_item");
        item_collected_port = new("item_collected_port", this);  // Analysis Portを生成
    endfunction

    function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        if (!uvm_config_db#(virtual sample_if)::get(this, "", "vif", vif))
            `uvm_fatal(this.get_name(), "vif is invalid")
    endfunction

    task run_phase(uvm_phase phase);
        @(posedge vif.rst_n);
        forever begin
            @(posedge vif.clk iff vif.valid && vif.ready);
            item.data = vif.data;
            item_collected_port.write(item);  // ScoreBoardのwriteタスクにitemを送信
        end
    endtask
endclass
sample_env.svh

ScoreBoardとAgentのMonitorを接続します。

class sample_env extends uvm_env;
    `uvm_component_utils(sample_env)

    sample_agent agent;
    sample_scoreboard scoreboard;  // ScoreBoardを宣言

    function new(string name, uvm_component parent);
        super.new(name, parent);
    endfunction

    function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        agent = sample_agent::type_id::create("agent", this);
        scoreboard = sample_scoreboard::type_id::create("scoreboard", this);  // ScoreBoardを生成
    endfunction

    function void connect_phase(uvm_phase phase);
        // ScoreBoardとMonitorを接続
        agent.monitor.item_collected_port.connect(scoreboard.item_collected_export);
    endfunction
endclass

まとめ

ScoreBoardを作成しました。

コメント

タイトルとURLをコピーしました