hub75_top_tb.v 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * hub75_top_tb.v
  3. *
  4. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  5. * All rights reserved.
  6. *
  7. * BSD 3-clause, see LICENSE.bsd
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * * Neither the name of the <organization> nor the
  17. * names of its contributors may be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * vim: ts=4 sw=4
  32. */
  33. `default_nettype none
  34. `timescale 1ns / 100ps
  35. module hub75_top_tb;
  36. // Params
  37. localparam integer N_BANKS = 2;
  38. localparam integer N_ROWS = 32;
  39. localparam integer N_COLS = 64;
  40. localparam integer N_CHANS = 3;
  41. localparam integer N_PLANES = 8;
  42. localparam integer BITDEPTH = 24;
  43. localparam integer LOG_N_BANKS = $clog2(N_BANKS);
  44. localparam integer LOG_N_ROWS = $clog2(N_ROWS);
  45. localparam integer LOG_N_COLS = $clog2(N_COLS);
  46. // Signals
  47. reg rst = 1'b1;
  48. reg clk = 1'b0;
  49. reg clk_2x = 1'b0;
  50. wire [$clog2(N_ROWS)-1:0] hub75_addr;
  51. wire [(N_BANKS*N_CHANS)-1:0] hub75_data;
  52. wire hub75_clk;
  53. wire hub75_le;
  54. wire hub75_blank;
  55. wire [LOG_N_BANKS-1:0] fbw_bank_addr;
  56. wire [LOG_N_ROWS-1:0] fbw_row_addr;
  57. wire fbw_row_store;
  58. wire fbw_row_rdy;
  59. wire fbw_row_swap;
  60. wire [BITDEPTH-1:0] fbw_data;
  61. wire [LOG_N_COLS-1:0] fbw_col_addr;
  62. wire fbw_wren;
  63. wire frame_swap;
  64. wire frame_rdy;
  65. // SPI Reader
  66. `ifndef PATTERN
  67. wire spi_mosi;
  68. wire spi_miso;
  69. wire spi_cs_n;
  70. wire spi_clk;
  71. wire [23:0] sr_addr;
  72. wire [15:0] sr_len;
  73. wire sr_go;
  74. wire sr_rdy;
  75. wire [7:0] sr_data;
  76. wire sr_valid;
  77. `endif
  78. // Setup recording
  79. initial begin
  80. $dumpfile("hub75_top_tb.vcd");
  81. $dumpvars(0,hub75_top_tb);
  82. end
  83. // Reset pulse
  84. initial begin
  85. # 200 rst = 0;
  86. # 10000000 $finish;
  87. end
  88. // Clocks
  89. always #33 clk = !clk; // ~ 30 MHz
  90. always #16.5 clk_2x = !clk_2x; // ~ 60 MHz
  91. // DUT
  92. hub75_top #(
  93. .N_BANKS(N_BANKS),
  94. .N_ROWS(N_ROWS),
  95. .N_COLS(N_COLS),
  96. .N_CHANS(N_CHANS),
  97. .N_PLANES(N_PLANES),
  98. .BITDEPTH(BITDEPTH)
  99. ) dut_I (
  100. .hub75_addr(hub75_addr),
  101. .hub75_data(hub75_data),
  102. .hub75_clk(hub75_clk),
  103. .hub75_le(hub75_le),
  104. .hub75_blank(hub75_blank),
  105. .fbw_bank_addr(fbw_bank_addr),
  106. .fbw_row_addr(fbw_row_addr),
  107. .fbw_row_store(fbw_row_store),
  108. .fbw_row_rdy(fbw_row_rdy),
  109. .fbw_row_swap(fbw_row_swap),
  110. .fbw_data(fbw_data),
  111. .fbw_col_addr(fbw_col_addr),
  112. .fbw_wren(fbw_wren),
  113. .frame_swap(frame_swap),
  114. .frame_rdy(frame_rdy),
  115. .ctrl_run(1'b1),
  116. .cfg_pre_latch_len(8'h80),
  117. .cfg_latch_len(8'h80),
  118. .cfg_post_latch_len(8'h80),
  119. .cfg_bcm_bit_len(8'h06),
  120. .clk(clk),
  121. .clk_2x(clk_2x),
  122. .rst(rst)
  123. );
  124. `ifdef PATTERN
  125. pgen #(
  126. .N_ROWS(N_BANKS * N_ROWS),
  127. .N_COLS(N_COLS),
  128. .BITDEPTH(BITDEPTH)
  129. ) pgen_I (
  130. .fbw_row_addr({fbw_bank_addr, fbw_row_addr}),
  131. .fbw_row_store(fbw_row_store),
  132. .fbw_row_rdy(fbw_row_rdy),
  133. .fbw_row_swap(fbw_row_swap),
  134. .fbw_data(fbw_data),
  135. .fbw_col_addr(fbw_col_addr),
  136. .fbw_wren(fbw_wren),
  137. .frame_swap(frame_swap),
  138. .frame_rdy(frame_rdy),
  139. .clk(clk),
  140. .rst(rst)
  141. );
  142. `else
  143. vgen #(
  144. .ADDR_BASE(24'h040000),
  145. .N_FRAMES(30),
  146. .N_ROWS(N_BANKS * N_ROWS),
  147. .N_COLS(N_COLS),
  148. .BITDEPTH(BITDEPTH)
  149. ) vgen_I (
  150. .sr_addr(sr_addr),
  151. .sr_len(sr_len),
  152. .sr_go(sr_go),
  153. .sr_rdy(sr_rdy),
  154. .sr_data(sr_data),
  155. .sr_valid(sr_valid),
  156. .fbw_row_addr({fbw_bank_addr, fbw_row_addr}),
  157. .fbw_row_store(fbw_row_store),
  158. .fbw_row_rdy(fbw_row_rdy),
  159. .fbw_row_swap(fbw_row_swap),
  160. .fbw_data(fbw_data),
  161. .fbw_col_addr(fbw_col_addr),
  162. .fbw_wren(fbw_wren),
  163. .frame_swap(frame_swap),
  164. .frame_rdy(frame_rdy),
  165. .ui_up(1'b0),
  166. .ui_mode(1'b0),
  167. .ui_down(1'b0),
  168. .clk(clk),
  169. .rst(rst)
  170. );
  171. spi_flash_reader spi_reader_I (
  172. .spi_mosi(spi_mosi),
  173. .spi_miso(spi_miso),
  174. .spi_cs_n(spi_cs_n),
  175. .spi_clk(spi_clk),
  176. .addr(sr_addr),
  177. .len(sr_len),
  178. .go(sr_go),
  179. .rdy(sr_rdy),
  180. .data(sr_data),
  181. .valid(sr_valid),
  182. .clk(clk),
  183. .rst(rst)
  184. );
  185. `endif
  186. endmodule // hub75_top_tb