简体   繁体   English

TestBench不执行实例模块

[英]TestBench doesn't execute instance module

I'm new to verilog and I'm trying to build a verilog code that models a direct mapped cache. 我是Verilog的新手,我正在尝试构建用于模拟直接映射缓存的Verilog代码。 Every thing is working fine within the compilation process but the testbench module doesn't seem to execute the "Memory" module (instance). 在编译过程中一切正常,但是testbench模块似乎没有执行“内存”模块(实例)。 The output variables are always unknowns except for those that I assign values in the testbench itself, even the RAM register which I had filled up with data in the main module. 输出变量总是未知的,除了那些我在测试台本身中分配值的变量,甚至是我已经在主模块中填满数据的RAM寄存器。 What do you think seems to be the problem? 您认为这似乎是什么问题? Thanks in advance This is the instance module code: 预先感谢这是实例模块代码:

module Memory (outdata,address,indata,RE,WE);
input [31:0]address;
input [31:0]indata;
output reg [31:0]outdata;
input RE,WE;
//Declared the inputs and outputs
reg[31:0]RAM[0:1023];
reg[19:0]tag[0:1023];
reg valid [0:1023];
reg [31:0]Data[0:1023];
//Defined the registers that were supposed to be modules
//Divided the cache into tag,data and valid
//Starting thr Reading Process
always @ (RE or WE)
begin
  if (RE==1)
  begin
    if (address[31:12] == tag [address[11:2]])
    begin
      if (valid[address[11:2]] ==1)
      begin
        outdata = Data[address[11:2]];
      end
      else if (valid[address[11:2]] ==0) //Read from RAM
      begin
        Data[address[11:2]] = RAM [address];
        valid[address[11:2]] =1;
        outdata = Data[address[11:2]];
      end
    end
    if (address[31:12] != tag [address[11:2]])
    begin
      Data[address[11:2]] <= RAM [address];
      tag[address[11:2]] <= address [31:12];
      valid[address[11:2]] =1;
      outdata <= Data[address[11:2]];
    end
  end
  //Starting the Writing Process
  else if (WE==1)
  begin
    if(address[31:12]==tag[address[11:2]]) //Hit
    begin
      Data[address[11:2]]<=indata;
      valid[address[11:2]] =1;
      RAM[address]<=indata;
    end
    if (address[31:12] != tag [address[11:2]])//Miss
    begin
      RAM[address]<=indata;
    end
  end
end
initial
begin 
  $readmemb("D:\Verilog Project Data/MyMemory.txt",RAM);
end
endmodule
// Filling up the RAM

This is a module where I write the data I want to fill the RAM with in a file: 这是一个模块,我在其中写入要在文件中填充RAM的数据:

module WritingToMemory;
reg[31:0]i;
integer file;
initial
begin
  i=0;
  file = $fopen("D:\Verilog Project Data/MyMemory.txt");
  $fmonitor(file,"%b\n",i);
  for(i=0; i<1024; i=i+1)
  begin
    #1
    i=i;
  end
end
endmodule

TestBench module: TestBench模块:

module TestBench;
reg[31:0]address;
reg[31:0]indata;
reg RE;
reg WE;
wire[31:0]outdata;
initial
begin
  $monitor("address= %b, Inputputdata= %b, Outputdata= %b, Data=%b,  RAMdata=%b",
            address,indata,outdata, Data[address[11:2]],RAM[address]);
  #10
  RE = 1;
  address = 0;
  #10
  RE=1;
  address =0;
  #10
  RE=1;
  address=0;
end
Memory M1(outdata,address,indata,RE,WE);
endmodule

Are you sure you simulated this? 您确定您模拟了吗? It does not compile in the current state. 它不会在当前状态下编译。 Next time could you please indent the code you post? 下次您可以缩进您发布的代码吗?

Getting to your question, there are three issues: 提出问题,有三个问题:

1) You initialize only RAM, the Tag and Valid arrays are all x. 1)您仅初始化RAM,Tag和Valid数组均为x。 Your HW would be completely unpredictable in real silicon. 您的硬件在真正的芯片中将是完全不可预测的。 Before a cache can be used, the tags and valid bits must be initialized. 必须先初始化标签和有效位,然后才能使用缓存。 Now you know why ;) 现在你知道为什么;)

2) Your testbench is really generating only one transaction. 2)您的测试台实际上只生成一个事务。 You wrote: 你写了:

#10
RE = 1;
address = 0;
#10
RE=1;
address =0;
#10
RE=1;
address=0;

Since neither RE nor address ever change after the first assignment, the always @ (RE or WE) statement never gets triggered again. 由于第一次分配后,RE和地址都不会更改,因此always @ (RE or WE)不会再次触发always @ (RE or WE)语句。 you need to have RE go back to 0 or address change. 您需要让RE返回0或更改地址。 Or, which is much more likely in the behaviour of an actual cache, introduce a clock. 或者,在实际缓存的行为中更有可能引入时钟。

3) always @ (RE or WE) is also incorrect, because address is not part of the sensitivity list. 3) always @ (RE or WE)也不正确,因为地址不是敏感度列表的一部分。 This would cause the memory to latch the address only when the strobe is activated, which might or not be correct in your implementation. 这将导致内存仅在激活选通脉冲时才锁存地址,这在您的实现中可能正确,也可能不正确。 That's another very good reason to introduce a clock 那是引入时钟的另一个很好的理由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM