verilog io命令 - 写作和阅读

时间:2018-03-15 08:32:35

标签: verilog test-bench

我正在尝试使用io命令编写verilog测试平台 - 我想打开一个文件,将随机数据写入其中,然后读取数据。 下面的任务使用随机数据创建一个文件 - temp_file.vec,但是文件中的读取会遇到问题。显示输出显示以下内容:

  

" ncsim:* E,SYSFMT   (/home/tomers/Gfast_CPE_2_1/TestBench/virtual_dpr/tb.v,100|38):空   文件描述符传递给$ fgets。当前行是
  X           r = $ fgets(line,MAX_LINE_LENGTH,file);"

task task_wr_and_read_mem;
   input [31:0] loop_num;
   begin :file_block
     file  = $fopen("temp_file.vec","w");
     repeat (loop_num) 
      begin
//        #1
        @ (posedge clk);       
        wr_req <= 1;
    add_to_generate1 = $random;
    wr_addr <= {23'b0,add_to_generate1,3'b0};
    byteen <=  ($urandom%62) + 8'b1;
    wdata <= $random;
        #1
            $fdisplay(file, "Address::%h:: byteen %b :: wdata %h", wr_addr,byteen,wdata);
        wait (wr_rdy);
//        @ (posedge clk);      
      end
      $fclose(file);
      file  = $fopen("temp_file.vec","r");
      if (file == 0)
    begin
                $display ("file_is_missing");  
        disable file_block;
    end 
      r = $fgets(line, MAX_LINE_LENGTH,file );
      while (!$feof(file))
    begin
          $display ("current line is %d",line);  
          r = $fgets(line, MAX_LINE_LENGTH,file);
        end
    end

endtask

0 个答案:

没有答案