Advertisement
Guest User

Untitled

a guest
May 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3. ////////////////////////////////////////////////////////////////////////////////
  4. // Company:
  5. // Engineer:
  6. //
  7. // Create Date:   17:22:48 05/21/2017
  8. // Design Name:   serdes
  9. // Module Name:   C:/Users/root/Documents/WSC/SERDES/test.v
  10. // Project Name:  SERDES
  11. // Target Device:  
  12. // Tool versions:  
  13. // Description:
  14. //
  15. // Verilog Test Fixture created by ISE for module: serdes
  16. //
  17. // Dependencies:
  18. //
  19. // Revision:
  20. // Revision 0.01 - File Created
  21. // Additional Comments:
  22. //
  23. ////////////////////////////////////////////////////////////////////////////////
  24.  
  25. module test;
  26.     // test file
  27.     integer plik_wej, plik_wyj;
  28.     integer i = 0;
  29.     reg [7:0] test_wyj = 8'b0;
  30.     reg [7:0] test_wej [3:0];
  31.    
  32.     // Inputs
  33.     reg [7:0] par_in;
  34.     reg clk;
  35.     reg reset;
  36.  
  37.     // Outputs
  38.     wire [7:0] par_out;
  39.  
  40.     // Instantiate the Unit Under Test (UUT)
  41.     serdes uut (
  42.         .par_in(par_in),
  43.         .par_out(par_out),
  44.         .clk(clk),
  45.         .reset(reset)
  46.     );
  47.     always #1 clk = ~clk;
  48.    
  49.     initial begin
  50.        
  51.         // Initialize Inputs
  52.         par_in = 0;
  53.         clk = 0;
  54.         reset = 0;
  55.         test_wej[0][7:0] = 8'b0;
  56.         test_wej[1][7:0] = 8'b0;
  57.         test_wej[2][7:0] = 8'b0;
  58.         test_wej[3][7:0] = 8'b0;
  59.         // Wait 10 ns for global reset to finish
  60.         #16;
  61.         reset = 1;
  62.     end
  63.        
  64.     always @ (posedge clk) begin
  65.         plik_wej = $fopen("dane.dat", "r");
  66.         plik_wyj = $fopen("wyjscie.dat", "w");
  67.    
  68.         // main test code
  69.         while(!$feof(plik_wej)) begin
  70.             #16;
  71.             $fscanf(plik_wej, "%h\n", par_in[7:0]);
  72.             $fwrite(plik_wyj, "%h\n", par_out[7:0]);
  73.         end
  74.         $fclose(plik_wyj);
  75.         $fclose(plik_wej);
  76.        
  77.        //match test
  78.         plik_wyj = $fopen("wyjscie.dat", "r");
  79.         plik_wej = $fopen("dane.dat", "r");
  80.         while(!$feof(plik_wej)) begin
  81.             test_wej[3][7:0] = test_wej[2][7:0];
  82.             test_wej[2][7:0] = test_wej[1][7:0];
  83.             test_wej[1][7:0] = test_wej[0][7:0];
  84.             $fscanf(plik_wej, "%h\n", test_wej[0][7:0]);
  85.             $fscanf(plik_wyj, "%h\n", test_wyj[7:0]);
  86.             if (test_wej[3][7:0] == test_wyj[7:0] && i < 8) begin
  87.                 i = i + 1;
  88.                 $display("odebrano %d. bajt, wynik zgodny z oczekiwaniami, biezaca wartosc [%h]",i ,test_wyj[7:0]);
  89.                 if (i == 8) begin
  90.                     $display("wykryto koniec ramki");
  91.                 end
  92.             end
  93.             else begin
  94.                 if (test_wyj[7:0] != test_wej[3][7:0] && test_wej[3][7:0] == 8'h81) begin
  95.                     $display("wykryto poczatek ramki");
  96.                     i = 0;
  97.                 end
  98.                 else begin
  99.                     if (i < 8) begin
  100.                         $display("wynik !!!niezgodny!!! z oczekiwaniami, biezaca wartosc wyjsciowa [%h], wejsciowa [%h]", test_wyj[7:0], test_wej[3][7:0]);
  101.                     end
  102.                     else begin
  103.                         $display("przeslano bajt [%h] poza ramka", test_wej[3][7:0]);
  104.                     end
  105.                 end
  106.             end
  107.         end
  108.        
  109.         $fclose(plik_wej);
  110.         $fclose(plik_wyj);
  111.        
  112.         $finish;
  113.     end
  114.      
  115. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement