5

シンプルなテキスト ファイルである SREC ファイルがあり、Verilog で 1 行ずつ読みたいと思っています。どうやってやるの?

4

2 に答える 2

4

解決策をありがとう。各行に 32 の HEX 番号を含む 2 つの .txt ファイルを使用するように少し変更しましたが、コードの各行が何をするのか理解できなかったため、途中でいくつかの問題が見つかりました。私の調査結果は次のとおりです。

vars と regs の宣言のみ

////////I'm using inputs.txt and outputs.txt to read both lines at the same time
module Decryption_Top_Testbench;
////////TEXT DOC variables

integer               file_outputs    ; // var to see if file exists 
integer               scan_outputs    ; // captured text handler
integer               file_inputs     ; // var to see if file exists
integer               scan_inputs     ; // captured text handler

//TXT
reg [127:0] captured_outputs; ///Actual text obtained from outputs.txt lines
reg [127:0] captured_inputs;  ///Actual text obtained from inputs.txt lines

両方のファイルを開く

initial 
begin

 // TEXT FILE outputs///////////////////////

  file_outputs = $fopen("C:/outputs.txt", "r"); //Opening text file

//you should use the full path if you don't want to get in the trouble 
//of using environment vars 

    if (file_outputs == 0) begin               // If outputs file is not found
      $display("data_file handle was NULL"); //simulation monitor command
      $finish;
    end
  // TEXT FILE inputs///////////////////////
    file_inputs = $fopen("C:/inputs.txt", "r"); //Opening text file (inputs)
      if (file_inputs == 0) begin               //If inputs file is not found
        $display("data_file handle was NULL");
        $finish;
      end
end

この部分では、HEX 形式で 1 ​​行ずつ読み取り、「captured_outputs」レジスターと「captured_inputs」レジスターに格納します。

///Since I'm using it just to simulate I'm not interested on a clock pulse,
/// I want it to happen all at the same time with whatever comes first

always @(* )
begin

   if (!$feof(file_outputs)) 
   begin
   ///!$feof means if not reaching the end of file
   ///file_outputs is always returning a different number other than "0" if the doc 
   ///has not ended. When reaching "0" it means the doc is over.
   ///Since both of my docs are the same length I'm only validating one of them
   ///but if you have different lenghts you should verify each doc you're reading

   ///

   scan_inputs = $fscanf(file_inputs, "%h\n", captured_inputs);        //Inputs Line text
   scan_outputs = $fscanf(file_outputs, "%h\n", captured_outputs);     //Outputs line text

   $display ("Line :[inputs: %h _ outputs: %h ]" captured_inputs, captured_outputs);  
   // Displaying each line at the simulation monitor

   ///$fscanf means formatted text, $scanf would read text ignoring the format
   /// %h\n means it should expect HEX numbers and the end of line character, that means 
   /// the line is over, but if you want to use a diff criteria 
   /// you can replace \n to whatever you may need 



   end

   else
   begin

   $finish;
   $fclose(file_outputs); //Closing files just in case to prevent wasting memory
   $fclose(file_inputs);

   end

end

私は、Verilog でコードを書き始めている人なら誰でも理解し、この優れた機能を自分のプロジェクトに追加できるような何かに貢献したかっただけです。

楽しみ!

于 2016-05-10T05:19:24.257 に答える