SSブログ

部品:AXIシミュレーション用モジュール [AXI]

作ったaxis_sliceを早速テストしたいところですが、いろんなパターンのreadyやvalidを作るのはめんどくさいです困難を極めます。

手を抜きます。

souce、マスター側
module    axis_source
(
    input  wire integer ratio,     // ratio
    input  wire         enable,    // enable
    input  wire         c_clk,     // Clock
    input  wire         c_rst,     // Reset
    input  wire         m_ready,   // Ready
    output wire         m_valid    // Valid
);
    reg     [3:0]  rand;
    reg     inhib;
    reg     valid;

    assign  m_valid = valid & ~inhib;

    always @(posedge c_clk) begin
        if (c_rst) begin
            valid    <= 1'b0;
            rand     <= 0;
            inhib    <= 1'b1;
        end
        else begin
            valid    <= enable;
            if (inhib | m_ready) begin
                rand     = $random;
                case (ratio)
                    default    : inhib    <= 0;
                    1        : inhib    <= &rand[3:0];
                    2        : inhib    <= &rand[2:0];
                    3        : inhib    <= &rand[1:0];
                    4        : inhib    <=  rand[0];
                    5        : inhib    <= |rand[1:0];
                    6        : inhib    <= |rand[2:0];
                    7        : inhib    <= |rand[3:0];
                endcase
            end
        end
    end
endmodule

sink、スレーブ側
module    axis_sink
(
    input  wire integer ratio,     // ratio
    input  wire         enable,    // enable
    input  wire         c_clk,     // Clock
    input  wire         c_rst,     // Reset
    output wire         s_ready,   // Ready
    input  wire         s_valid    // Valid
);
    reg     [3:0]  rand;
    reg     inhib;
    reg     ready;

    assign  s_ready = ready & ~inhib;

    always @(posedge c_clk) begin

        if (c_rst) begin
            ready    <= 1'b0;
            rand     <= 0;
            inhib    <= 1'b0;
        end
        else begin
            ready    <= enable;
            rand     = $random;
            case (ratio)
                default    : inhib    <= 0;
                1        : inhib    <= &rand[3:0];
                2        : inhib    <= &rand[2:0];
                3        : inhib    <= &rand[1:0];
                4        : inhib    <=  rand[0];
                5        : inhib    <= |rand[1:0];
                6        : inhib    <= |rand[2:0];
                7        : inhib    <= |rand[3:0];
            endcase
        end
    end

endmodule//

souceはvalidを、sinkはreadyを、ランダムでトグルさせます。テストデータの生成とチェックは別のテストベンチ側でやります。タイミングを生成するだけのモジュール。
有効の比率をratioで変えてて、0は100%、常に有効、1~7につれて有効の比率が下がります。4が50%ぐらい、たぶん。
こんな感じで使います。
`timescale 1ns / 1ps
`default_nettype none

module    tb;
    parameter    dw    = 16;

    reg     c_clk;
    reg     c_rst;

    reg     enable;

    integer s_ratio;
    integer d_ratio;

    initial      c_clk <= 1'b0;
    always   #5  c_clk <= ~c_clk;

    initial begin
        c_rst    <= 1'b1;
        enable   <= 1'b0;
        #100;

        @(posedge c_clk);
        c_rst    <= 1'b0;
        #200;

        /* 両方とも100% */
        @(posedge c_clk);
        enable   <= 1'b0;
        @(posedge c_clk);
        s_ratio  <= 0;
        d_ratio  <= 0;
        @(posedge c_clk);
        enable   <= 1'b1;
        #500;

        /* 送り側が多め */
        @(posedge c_clk);
        enable   <= 1'b0;
        @(posedge c_clk);
        s_ratio  <= 3;
        d_ratio  <= 5;
        @(posedge c_clk);
        enable   <= 1'b1;
        #500;

        /* 受け側が多め */
        @(posedge c_clk);
        enable   <= 1'b0;
        @(posedge c_clk);
        s_ratio  <= 5;
        d_ratio  <= 3;
        @(posedge c_clk);
        enable   <= 1'b1;
        #500;

        $display("finish");
        $stop;
    end

    wire            ts_ready;
    wire            ts_valid;
    wire  [dw-1:0]  ts_data ;

    ///////////////////////////////
    reg     [dw-1:0]    s_data;
    always @(posedge c_clk) begin
        if      (c_rst)                s_data <= 0;
        else if (ts_ready & ts_valid)  s_data <= s_data + 1;
    end

    assign  ts_data = s_data;

    ///////////////////////////////
    axis_source
    source
    (
        .ratio    (s_ratio   ),
        .enable   (enable    ),
        .c_clk    (c_clk     ),
        .c_rst    (c_rst     ),
        .m_ready  (ts_ready  ),
        .m_valid  (ts_valid  ) 
    );


    ///////////////////////////////
    axis_sink
    sink
    (
        .ratio    (d_ratio   ),
        .enable   (enable    ),
        .c_clk    (c_clk     ),
        .c_rst    (c_rst     ),
        .s_ready  (ts_ready  ),
        .s_valid  (ts_valid  ) 
    );

endmodule

`default_nettype wire

この例では直結。本来は間にテスト対象を挟んでデータのチェックを行わせます。

追記。
input wire integer ratio
この構文がisimで通らないので、変更しました。変更したソースは次の「部品:AXIストリームレジスタ、シミュレーション」に。
nice!(0)  コメント(0)  トラックバック(0) 

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。