pkt_fifo_tb.v 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * pkt_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 pkt_fifo_tb;
  36. // Signals
  37. reg rst = 1'b1;
  38. reg clk = 1'b0;
  39. wire [7:0] wr_data;
  40. wire wr_last;
  41. wire wr_ena;
  42. wire full;
  43. wire [7:0] rd_data;
  44. wire rd_last;
  45. wire rd_ena;
  46. wire empty;
  47. // Setup recording
  48. initial begin
  49. $dumpfile("pkt_fifo_tb.vcd");
  50. $dumpvars(0,pkt_fifo_tb);
  51. end
  52. // Reset pulse
  53. initial begin
  54. # 200 rst = 0;
  55. # 1000000 $finish;
  56. end
  57. // Clocks
  58. always #10 clk = !clk;
  59. // DUT
  60. pkt_fifo #(
  61. .AWIDTH(5)
  62. ) dut_I (
  63. .wr_data(wr_data),
  64. .wr_last(wr_last),
  65. .wr_ena(wr_ena),
  66. .full(full),
  67. .rd_data(rd_data),
  68. .rd_last(rd_last),
  69. .rd_ena(rd_ena),
  70. .empty(empty),
  71. .clk(clk),
  72. .rst(rst)
  73. );
  74. // Feed some data
  75. assign rd_ena = r & ~empty;
  76. reg [7:0] cnt;
  77. reg r;
  78. always @(posedge clk)
  79. if (rst)
  80. r <= 1'b0;
  81. else
  82. r <= $random & $random;
  83. always @(posedge clk)
  84. if (rst)
  85. cnt <= 0;
  86. else
  87. cnt <= cnt + 1;
  88. assign wr_data = cnt;
  89. assign wr_last = (cnt[2:0] == 3'b111);
  90. assign wr_ena = ~full & (cnt[7:6] == 2'b01);
  91. endmodule // pkt_fifo_tb