---
+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Member level 3
    Points: 1,824, Level: 9

    Join Date
    Apr 2004
    Posts
    65
    Helped
    0 / 0
    Points
    1,824
    Level
    9

    system verilog read file

    How to make a SystemVerilog Class to read a text vector
    and how to sync it with the global clock? read every byte per cycle

    I have tried to write one but it seems not work... can anyone give me a hint on that?

    Code:
    class   #(parameter File_Name  = "input_vector.txt",
                parameter Data_Width = 12) SIM_MEM;
        
        reg     [Data_Width-1:0]    Data;
        
        function new(input File_P);
        integer     File_P;
        begin
          File_P = $fopen(File_Name, "r");
          if(!File_P) begin
            $display("File %s open failded, no such file!", File_Name);
            $finish(2);
            end
          else begin
            if(!$feof(File_P)) begin            
                $fscanf(File_P, "%h", Data);
                return Data;
                end
            else begin                            
                $display("%s reaches file's end!", File_Name);  
                $fclose(File_P);                
                $finish(2);
            end
        end
      endclass
    the input vector format:
    000
    123
    AAB
    012
    0EF
    23F
    876
    ...
    ...
    ...

    •   Alt28th May 2007, 07:14

      advertising

        
       

  2. #2
    Member level 3
    Points: 1,824, Level: 9

    Join Date
    Apr 2004
    Posts
    65
    Helped
    0 / 0
    Points
    1,824
    Level
    9

    systemverilog file read

    any hint?



    •   Alt29th May 2007, 03:03

      advertising

        
       

  3. #3
    Member level 2
    Points: 1,641, Level: 9

    Join Date
    Sep 2004
    Posts
    43
    Helped
    3 / 3
    Points
    1,641
    Level
    9

    fscanf system verilog

    I think PERL or Python are more suited for text handling.



    •   Alt29th May 2007, 07:18

      advertising

        
       

  4. #4
    Member level 3
    Points: 1,824, Level: 9

    Join Date
    Apr 2004
    Posts
    65
    Helped
    0 / 0
    Points
    1,824
    Level
    9

    fscanf systemverilog

    I do not use sv to process my text file; I just use it read the vector from the file and feed the vector to the testbenches or DUT.
    The reason why I need a sv class here is the class can be easily reused and called.



+ Post New Thread
Please login