Subversion Repositories pentevo

Rev

Rev 291 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. /*
  2.  
  3. reset...init...save.start_write.stop_write.restore.start_read(compare).stop_read.loop
  4.  
  5. */
  6.  
  7. module mem_tester(
  8.  
  9.     clk,
  10.  
  11.     rst_n,
  12.  
  13. // pass/fail counters
  14.     pass_counter,
  15.     fail_counter,
  16.  
  17. // DRAM signals
  18.     DRAM_DQ,
  19.  
  20.     DRAM_MA,
  21.  
  22.     DRAM_RAS0_N,
  23.     DRAM_RAS1_N,
  24.     DRAM_LCAS_N,
  25.     DRAM_UCAS_N,
  26.     DRAM_WE_N
  27. );
  28.  
  29. parameter DRAM_DATA_SIZE = 16;
  30. parameter DRAM_MA_SIZE = 10;
  31.  
  32.     inout [DRAM_DATA_SIZE-1:0] DRAM_DQ;
  33.     output [DRAM_MA_SIZE-1:0] DRAM_MA;
  34.     output DRAM_RAS0_N,DRAM_RAS1_N,DRAM_LCAS_N,DRAM_UCAS_N,DRAM_WE_N;
  35.  
  36.     input clk;
  37.  
  38.     input rst_n;
  39.  
  40.  
  41.  
  42.     reg inc_pass_ctr;
  43.     reg inc_err_ctr;
  44.  
  45.     reg check_in_progress; // when 1 - enables errors checking
  46.  
  47.  
  48. //----
  49.  
  50.     reg [15:0] pass_counter;
  51.     output [15:0] pass_counter;
  52.     reg [15:0] fail_counter;
  53.     output [15:0] fail_counter;
  54.     reg was_error;
  55.  
  56.     always @(posedge clk, negedge rst_n)
  57.     begin
  58.         if( !rst_n )
  59.         begin
  60.             pass_counter <= 16'd0;
  61.             fail_counter <= 16'd0;
  62.         end
  63.         else if( inc_pass_ctr )
  64.         begin
  65.             if( (!was_error)&&(pass_counter!=16'hffff) )
  66.                 pass_counter <= pass_counter + 16'd1;
  67.             if( (was_error)&&(fail_counter!=16'hffff) )
  68.                 fail_counter <= fail_counter + 16'd1;
  69.             was_error <= 1'b0;
  70.         end
  71.         else if( inc_err_ctr )
  72.             was_error <= 1'b1;
  73.     end
  74.  
  75. //----
  76.  
  77.  
  78.  
  79.     reg rnd_init,rnd_save,rnd_restore; // rnd_vec_gen control
  80.     wire [DRAM_DATA_SIZE-1:0] rnd_out; // rnd_vec_gen output
  81.  
  82.     rnd_vec_gen my_rnd( .clk(clk), .init(rnd_init), .next(ram_ready), .save(rnd_save), .restore(rnd_restore), .out(rnd_out) );
  83.     defparam my_rnd.OUT_SIZE = DRAM_DATA_SIZE;
  84.  
  85.     defparam my_rnd.LFSR_LENGTH = 17;
  86.     defparam my_rnd.LFSR_FEEDBACK = 14;
  87.  
  88.  
  89.  
  90.  
  91.     reg ram_start,ram_rnw;
  92.     wire ram_stop,ram_ready;
  93.     wire [DRAM_DATA_SIZE-1:0] ram_rdat;
  94.  
  95.     dram_control my_ram( .clk(clk), .start(ram_start), .rnw(ram_rnw), .stop(ram_stop), .ready(ram_ready),
  96.                          .rdat(ram_rdat), .wdat(rnd_out),
  97.                          .DRAM_DQ(DRAM_DQ), .DRAM_MA(DRAM_MA), .DRAM_RAS0_N(DRAM_RAS0_N), .DRAM_RAS1_N(DRAM_RAS1_N),
  98.                          .DRAM_LCAS_N(DRAM_LCAS_N), .DRAM_UCAS_N(DRAM_UCAS_N), .DRAM_WE_N(DRAM_WE_N) );
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. // FSM states and registers
  107.     reg [3:0] curr_state,next_state;
  108.  
  109. parameter RESET        = 4'h0;
  110.  
  111. parameter INIT1        = 4'h1;
  112. parameter INIT2        = 4'h2;
  113.  
  114. parameter BEGIN_WRITE1 = 4'h3;
  115. parameter BEGIN_WRITE2 = 4'h4;
  116. parameter BEGIN_WRITE3 = 4'h5;
  117. parameter BEGIN_WRITE4 = 4'h6;
  118.  
  119. parameter WRITE        = 4'h7;
  120.  
  121. parameter BEGIN_READ1  = 4'h8;
  122. parameter BEGIN_READ2  = 4'h9;
  123. parameter BEGIN_READ3  = 4'hA;
  124. parameter BEGIN_READ4  = 4'hB;
  125.  
  126. parameter READ         = 4'hC;
  127.  
  128. parameter END_READ     = 4'hD;
  129.  
  130. parameter INC_PASSES1  = 4'hE;
  131. parameter INC_PASSES2  = 4'hF;
  132.  
  133.  
  134. // FSM dispatcher
  135.  
  136.     always @*
  137.     begin
  138.         case( curr_state )
  139.  
  140.         RESET:
  141.             next_state <= INIT1;
  142.  
  143.         INIT1:
  144.                 next_state <= INIT2;
  145.  
  146.         INIT2:
  147.             if( ram_stop )
  148.                 next_state <= BEGIN_WRITE1;
  149.             else
  150.                 next_state <= INIT2;
  151.  
  152.         BEGIN_WRITE1:
  153.             next_state <= BEGIN_WRITE2;
  154.  
  155.         BEGIN_WRITE2:
  156.             next_state <= BEGIN_WRITE3;
  157.  
  158.         BEGIN_WRITE3:
  159.             next_state <= BEGIN_WRITE4;
  160.  
  161.         BEGIN_WRITE4:
  162.             if( ram_stop )
  163.                 next_state <= BEGIN_WRITE4;
  164.             else
  165.                 next_state <= WRITE;
  166.  
  167.         WRITE:
  168.             if( ram_stop )
  169.                 next_state <= BEGIN_READ1;
  170.             else
  171.                 next_state <= WRITE;
  172.  
  173.         BEGIN_READ1:
  174.             next_state <= BEGIN_READ2;
  175.  
  176.         BEGIN_READ2:
  177.             next_state <= BEGIN_READ3;
  178.  
  179.         BEGIN_READ3:
  180.             next_state <= BEGIN_READ4;
  181.  
  182.         BEGIN_READ4:
  183.             if( ram_stop )
  184.                 next_state <= BEGIN_READ4;
  185.             else
  186.                 next_state <= READ;
  187.  
  188.         READ:
  189.             if( ram_stop )
  190.                 next_state <= END_READ;
  191.             else
  192.                 next_state <= READ;
  193.  
  194.         END_READ:
  195.             next_state <= INC_PASSES1;
  196.  
  197.         INC_PASSES1:
  198.             next_state <= INC_PASSES2;
  199.  
  200.         INC_PASSES2:
  201.             next_state <= BEGIN_WRITE1;
  202.  
  203.  
  204.  
  205.  
  206.         default:
  207.             next_state <= RESET;
  208.  
  209.  
  210.         endcase
  211.     end
  212.  
  213.  
  214. // FSM sequencer
  215.  
  216.     always @(posedge clk,negedge rst_n)
  217.     begin
  218.         if( !rst_n )
  219.             curr_state <= RESET;
  220.         else
  221.             curr_state <= next_state;
  222.     end
  223.  
  224.  
  225. // FSM controller
  226.  
  227.     always @(posedge clk)
  228.     begin
  229.         case( curr_state )
  230.  
  231. //////////////////////////////////////////////////
  232.         RESET:
  233.         begin
  234.             // various initializings begin
  235.  
  236.             inc_pass_ctr <= 1'b0;
  237.             check_in_progress <= 1'b0;
  238.             rnd_init <= 1'b1; //begin RND init
  239.             rnd_save <= 1'b0;
  240.             rnd_restore <= 1'b0;
  241.             ram_start <= 1'b1;
  242.             ram_rnw   <= 1'b1;
  243.         end
  244.  
  245.         INIT1:
  246.         begin
  247.             rnd_init <= 1'b0; // end rnd init
  248.             ram_start <= 1'b0;
  249.         end
  250.  
  251.         INIT2:
  252.         begin
  253.         end
  254.  
  255.  
  256.  
  257. //////////////////////////////////////////////////
  258.         BEGIN_WRITE1:
  259.         begin
  260.             rnd_save <= 1'b1;
  261.         end
  262.  
  263.         BEGIN_WRITE2:
  264.         begin
  265.             rnd_save   <= 1'b0;
  266.             ram_start <= 1'b1;
  267.             ram_rnw   <= 1'b0;
  268.         end
  269.  
  270.         BEGIN_WRITE3:
  271.         begin
  272.             ram_start <= 1'b0;
  273.         end
  274.  
  275. /*      BEGIN_WRITE4:
  276.         begin
  277.             rnd_save   <= 1'b0;
  278.             ram_start <= 1'b1;
  279.         end
  280. */
  281. /*      WRITE:
  282.         begin
  283.             ram_start <= 1'b0;
  284.         end
  285. */
  286.  
  287.  
  288.  
  289. //////////////////////////////////////////////////
  290.         BEGIN_READ1:
  291.         begin
  292.             rnd_restore <= 1'b1;
  293.         end
  294.  
  295.         BEGIN_READ2:
  296.         begin
  297.             rnd_restore <= 1'b0;
  298.             ram_start <= 1'b1;
  299.             ram_rnw <= 1'b1;
  300.         end
  301.  
  302.         BEGIN_READ3:
  303.         begin
  304.                 ram_start <= 1'b0;
  305.         end
  306.  
  307.         BEGIN_READ4:
  308.         begin
  309.                 check_in_progress <= 1'b1;
  310.         end
  311. /*
  312.         READ:
  313.         begin
  314.             ram_start <= 1'b0;
  315.             check_in_progress <= 1'b1;
  316.         end
  317. */
  318.         END_READ:
  319.         begin
  320.             check_in_progress <= 1'b0;
  321.         end
  322.  
  323.         INC_PASSES1:
  324.         begin
  325.             inc_pass_ctr <= 1'b1;
  326.         end
  327.  
  328.         INC_PASSES2:
  329.         begin
  330.             inc_pass_ctr <= 1'b0;
  331.         end
  332.  
  333.  
  334.  
  335.  
  336.         endcase
  337.     end
  338.  
  339.  
  340.  
  341.  
  342.  
  343.     always @(posedge clk)
  344.         inc_err_ctr <= check_in_progress & ram_ready & ((ram_rdat==rnd_out) ? 1'b0: 1'b1);
  345.  
  346.  
  347.  
  348. endmodule
  349.  
  350.  
  351.