5

我创建了一个模块,它接受一个指定模块数据线字节宽度的参数。它看起来像:

module wrapper#
(
    parameter DATA_BYTE_WIDTH = 1
)
( 
    din, dout, ..
);
    localparam DATA_BIT_WIDTH = 8*DATA_BYTE_WIDTH;
    input [DATA_BIT_WIDTH-1:0] din;
    output [DATA_BIT_WIDTH-1:0] dout;
    .....
    generate
        if( DATA_BYTE_WIDTH == 1 ) begin
            // Various modules and interconnects for 1-byte data
        else if( DATA_BYTE_WIDTH == 2) begin
            // Various modules and interconnects for 2-byte data
        else if....
            // and so on, for 4, 8, and 16
        else 
           // DATA_BYTE_WIDTH is not a valid value
           // HERE is where I want to throw an error
        end
    endgenerate

    // other code

endmodule

问题是唯一有效的宽度是 1、2、4、8 或 16 个字节。如果 DATA_BYTE_WIDTH 使用任何其他值,则根本不会生成互连。但赛灵思似乎并不关心这一点。如果提供了无效值,它将很高兴地“生成”任何内容:生成的设计合成但根本不起作用。

有没有办法检查参数的值并在它无效时抛出错误?我已经尝试过$error和(如这里assert所讨论的),以及(如这里所提到的)。Xilinx 拒绝使用任何这些函数,而是抛出语法错误并拒绝继续。$display

理想情况下,我希望在决赛中投入一些东西elsegenerate但此时我会满足于几乎任何东西。

4

1 回答 1

4

Verilog 没有一个干净的解决方案来验证参数。至少在任何版本的 IEEE Std 1364 中都没有提到过。最好的 Verilog 唯一解决方法是使用不存在的模块。

generate
  // ...
  else begin // invalid parameter configuration
    nonexistent_module_to_throw_a_custom_error_message_for invalid_parameters();
  end
endgenerate

错误的替代方法是将不存在的模块行替换为:

initial begin
  $display("Runtime error for invalid parameter value %b",DATA_BYTE_WIDTH);
  $finish(1);
end

这是一个错误的选择,因为大多数综合工具都会忽略$display(我相信他们也会忽略$finish)。您也不会知道有一个参数问题,直到模拟,编译后。不存在的模块更胜一筹,因为它是一个语法干净的参数条件编译错误。它只缺少显示违规参数值的消息。

从 IEEE Std 1800-2009 开始,SystemVerilog 中确实存在一个干净的解决方案,它添加了详细系统任务。看起来 Xilinx ISE 不支持 SystemVerilog。Xilinx Vivado 可以,但我不确定它是否完全抱怨 LRM。如果可以,请尝试一下。阅读IEEE Std 1800-2012 § 20.11细化系统任务中的完整描述。(*-2012 可免费下载,以促进 SV 的采用。*-2009 较旧且仍处于付费墙后面。关于详细系统任务的部分逐字逐句在两个版本之间。)

generate
  // ...
  else begin // invalid parameter configuration
    $error("Elaboration error for invalid parameter value %b in", DATA_BYTE_WIDTH);

    /* alternative $fatal. This prevents further elaboration from 
       happening. $error allows the rest of the design to elaborate.
       Both block simulation. */
    //$fatal(1,"Fatal elab. error for invalid parameter value %b in", DATA_BYTE_WIDTH);
  end
endgenerate
于 2015-04-22T18:34:19.190 回答