fifo_tb.v 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * fifo_tb.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  7. * All rights reserved.
  8. *
  9. * BSD 3-clause, see LICENSE.bsd
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * * Neither the name of the <organization> nor the
  19. * names of its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. `default_nettype none
  34. `timescale 1ns / 100ps
  35. module fifo_tb;
  36. // Signals
  37. reg rst = 1'b1;
  38. reg clk = 1'b0;
  39. wire [7:0] wr_data;
  40. wire wr_ena;
  41. wire wr_full;
  42. wire [7:0] rd_data;
  43. wire rd_ena;
  44. wire rd_empty;
  45. // Setup recording
  46. initial begin
  47. $dumpfile("fifo_tb.vcd");
  48. $dumpvars(0,fifo_tb);
  49. end
  50. // Reset pulse
  51. initial begin
  52. # 200 rst = 0;
  53. # 1000000 $finish;
  54. end
  55. // Clocks
  56. always #10 clk = !clk;
  57. // DUT
  58. // fifo_sync_shift #(
  59. fifo_sync_ram #(
  60. .DEPTH(4),
  61. .WIDTH(8)
  62. ) dut_I (
  63. .wr_data(wr_data),
  64. .wr_ena(wr_ena),
  65. .wr_full(wr_full),
  66. .rd_data(rd_data),
  67. .rd_ena(rd_ena),
  68. .rd_empty(rd_empty),
  69. .clk(clk),
  70. .rst(rst)
  71. );
  72. // Data generateion
  73. reg [7:0] cnt;
  74. reg rnd_rd;
  75. reg rnd_wr;
  76. always @(posedge clk)
  77. if (rst) begin
  78. cnt <= 8'h00;
  79. rnd_rd <= 1'b0;
  80. rnd_wr <= 1'b0;
  81. end else begin
  82. cnt <= cnt + wr_ena;
  83. rnd_rd <= $random;
  84. rnd_wr <= $random;
  85. end
  86. assign wr_data = wr_ena ? cnt : 8'hxx;
  87. assign wr_ena = rnd_wr & ~wr_full;
  88. assign rd_ena = rnd_rd & ~rd_empty;
  89. endmodule // fifo_tb