Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 如何在Verilog中声明全局变量?_Variables_Verilog_Global - Fatal编程技术网

Variables 如何在Verilog中声明全局变量?

Variables 如何在Verilog中声明全局变量?,variables,verilog,global,Variables,Verilog,Global,我写这篇文章是想问如何在Verilog中声明一个全局变量。由参数和定义关键字声明的内容本质上是常量,而不是变量 我需要的是: `define Glitch module Cell ( Shift_In, Shift_Out_Screwed, Clk ); input Clk, Shift_In; output Shift_Out_Screwed; wire Shift_Out_Screwed; wire Shift_Out; Inve

我写这篇文章是想问如何在Verilog中声明一个全局变量。由
参数
定义
关键字声明的内容本质上是常量,而不是变量

我需要的是:

`define Glitch 
module Cell ( Shift_In, Shift_Out_Screwed, Clk ); 
    input  Clk, Shift_In; 
    output  Shift_Out_Screwed; 
    wire  Shift_Out_Screwed; 
    wire  Shift_Out; 

    Inverter INV1 ( Shift_In, Shift_Out, Clk ); 
    assign Shift_Out_Screwed = Glitch ? ~Shift_Out : Shift_Out 
endmodule
这是一个非常简单的小故障插入。当
Glitch==1
时,原始输出反转;当
Glitch==0
时,原始输出保持不变。我希望信号
Glitch
外部simulation testbench.v文件中定义,尽管此处声明并使用了该文件,但我不想将信号
Glitch
添加到模块
单元
的输入端口列表中。这是因为我的真实电路是一个非常复杂的电路,如果我给某个单元添加一个输入端口,就会有许多其他单元受到影响


有人知道如何在Verilog中声明全局变量吗

你正在努力解决的问题听起来像是错误注入。您希望能够从测试台在输出端口上注入位错误。您可以这样做:

module Cell ( Shift_In, Shift_Out_Screwed, Clk ); 
    input  Clk, Shift_In; 
    output  Shift_Out_Screwed; 
    wire  Shift_Out_Screwed; 
    wire  Shift_Out; 

    Inverter INV1 ( Shift_In, Shift_Out, Clk ); 

    `ifdef SIMULATION
    // This logic is used in simulation, but not synthesis.  Use care.
    logic Glitch = 1'b0;
    assign Shift_Out_Screwed = Glitch ? ~Shift_Out : Shift_Out 
    `else
    // This logic is used in synthesis, but not simulation.  Use care.
    assign Shift_out_Screwed = Shift_out;
    `endif
endmodule
initial begin
   ...
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   ...
end
注意,我使用“SIMULATION”预处理器开关来隐藏合成中的“Glitch”错误注入。小心使用此技术以避免产生模拟/合成不匹配

在您的测试台中,您可以通过引用设计层次结构中的“故障”信号,在您的单元的特定实例中引发故障,如下所示:

module Cell ( Shift_In, Shift_Out_Screwed, Clk ); 
    input  Clk, Shift_In; 
    output  Shift_Out_Screwed; 
    wire  Shift_Out_Screwed; 
    wire  Shift_Out; 

    Inverter INV1 ( Shift_In, Shift_Out, Clk ); 

    `ifdef SIMULATION
    // This logic is used in simulation, but not synthesis.  Use care.
    logic Glitch = 1'b0;
    assign Shift_Out_Screwed = Glitch ? ~Shift_Out : Shift_Out 
    `else
    // This logic is used in synthesis, but not simulation.  Use care.
    assign Shift_out_Screwed = Shift_out;
    `endif
endmodule
initial begin
   ...
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   ...
end
上面的代码片段将注入一个周期的“小故障”


另一种方法是:注入错误的更传统的方法是使用测试台中的“force”语句覆盖被测设备中的驱动。

您正在努力解决的问题听起来像是错误注入。您希望能够从测试台在输出端口上注入位错误。您可以这样做:

module Cell ( Shift_In, Shift_Out_Screwed, Clk ); 
    input  Clk, Shift_In; 
    output  Shift_Out_Screwed; 
    wire  Shift_Out_Screwed; 
    wire  Shift_Out; 

    Inverter INV1 ( Shift_In, Shift_Out, Clk ); 

    `ifdef SIMULATION
    // This logic is used in simulation, but not synthesis.  Use care.
    logic Glitch = 1'b0;
    assign Shift_Out_Screwed = Glitch ? ~Shift_Out : Shift_Out 
    `else
    // This logic is used in synthesis, but not simulation.  Use care.
    assign Shift_out_Screwed = Shift_out;
    `endif
endmodule
initial begin
   ...
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   ...
end
注意,我使用“SIMULATION”预处理器开关来隐藏合成中的“Glitch”错误注入。小心使用此技术以避免产生模拟/合成不匹配

在您的测试台中,您可以通过引用设计层次结构中的“故障”信号,在您的单元的特定实例中引发故障,如下所示:

module Cell ( Shift_In, Shift_Out_Screwed, Clk ); 
    input  Clk, Shift_In; 
    output  Shift_Out_Screwed; 
    wire  Shift_Out_Screwed; 
    wire  Shift_Out; 

    Inverter INV1 ( Shift_In, Shift_Out, Clk ); 

    `ifdef SIMULATION
    // This logic is used in simulation, but not synthesis.  Use care.
    logic Glitch = 1'b0;
    assign Shift_Out_Screwed = Glitch ? ~Shift_Out : Shift_Out 
    `else
    // This logic is used in synthesis, but not simulation.  Use care.
    assign Shift_out_Screwed = Shift_out;
    `endif
endmodule
initial begin
   ...
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   @(posedge Clk); #1;
   $top.u_foo.u_bar.u_cell.Glitch = 1'b1;
   ...
end
上面的代码片段将注入一个周期的“小故障”


另一种方法是:注入错误的一种更传统的方法是使用测试台中的“force”语句覆盖被测设备中的驱动。

请说明是否需要可合成。不,它不必是可合成的……您可能需要传递
Glitch
的值。大多数模拟器都支持这种内置功能。非常感谢e19293001!我试试看。还有我的好奇:如果我需要它是可合成的呢?…如果测试台需要覆盖
故障
,那么
参数
是可合成的合适选择。否则,传递命令行变量也是一种选择。也可以在全局空间中简单地声明
reg Glitch='b0
。请说明是否需要可合成。不,它不必是可合成的…您可能需要传递
Glitch
的值。大多数模拟器都支持这种内置功能。非常感谢e19293001!我试试看。还有我的好奇:如果我需要它是可合成的呢?…如果测试台需要覆盖
故障
,那么
参数
是可合成的合适选择。否则,传递命令行变量也是一种选择。也可以在全局空间中简单地声明
reg Glitch='b0