pkt_spi_write_tb.v 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * pkt_spi_write_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_spi_write_tb;
  36. // Signals
  37. reg rst = 1'b1;
  38. reg clk = 1'b0;
  39. wire [7:0] sb_addr;
  40. wire [7:0] sb_data;
  41. wire sb_first;
  42. wire sb_last;
  43. wire sb_strobe;
  44. wire [7:0] spf_wr_data;
  45. wire spf_wr_last;
  46. wire spf_wr_ena;
  47. wire spf_full = 1'b0;
  48. // Setup recording
  49. initial begin
  50. $dumpfile("pkt_spi_write_tb.vcd");
  51. $dumpvars(0,pkt_spi_write_tb);
  52. end
  53. // Reset pulse
  54. initial begin
  55. # 200 rst = 0;
  56. # 1000000 $finish;
  57. end
  58. // Clocks
  59. always #10 clk = !clk;
  60. // DUT
  61. pkt_spi_write #(
  62. .BASE(8'hA4)
  63. ) pkt_I (
  64. .sb_addr(sb_addr),
  65. .sb_data(sb_data),
  66. .sb_first(sb_first),
  67. .sb_last(sb_last),
  68. .sb_strobe(sb_strobe),
  69. .fifo_data(spf_wr_data),
  70. .fifo_last(spf_wr_last),
  71. .fifo_wren(spf_wr_ena),
  72. .fifo_full(spf_full),
  73. .clk(clk),
  74. .rst(rst)
  75. );
  76. // SPI data generation
  77. reg [7:0] cnt;
  78. always @(posedge clk)
  79. if (rst)
  80. cnt <= 0;
  81. else
  82. cnt <= cnt + 1;
  83. assign sb_addr = sb_strobe ? 8'ha5 : 8'hxx;
  84. assign sb_data = sb_strobe ? cnt : 8'hxx;
  85. assign sb_first = sb_strobe ? cnt[7:4] == 4'h0 : 1'bx;
  86. assign sb_last = sb_strobe ? cnt[7:4] == 4'hf : 1'bx;
  87. assign sb_strobe = cnt[3:0] == 4'hf;
  88. endmodule // pkt_spi_write_tb