hub75_top.v 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * hub75_top.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  7. * All rights reserved.
  8. *
  9. * LGPL v3+, see LICENSE.lgpl3
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 3 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with this program; if not, write to the Free Software Foundation,
  23. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25. `default_nettype none
  26. module hub75_top #(
  27. parameter integer N_BANKS = 2, // # of parallel readout rows
  28. parameter integer N_ROWS = 32, // # of rows (must be power of 2!!!)
  29. parameter integer N_COLS = 64, // # of columns
  30. parameter integer N_CHANS = 3, // # of data channel
  31. parameter integer N_PLANES = 8, // # bitplanes
  32. parameter integer BITDEPTH = 24, // # bits per color
  33. // Auto-set
  34. parameter integer LOG_N_BANKS = $clog2(N_BANKS),
  35. parameter integer LOG_N_ROWS = $clog2(N_ROWS),
  36. parameter integer LOG_N_COLS = $clog2(N_COLS)
  37. )(
  38. // Hub75 interface pads
  39. output wire [LOG_N_ROWS-1:0] hub75_addr,
  40. output wire [(N_BANKS*N_CHANS)-1:0] hub75_data,
  41. output wire hub75_clk,
  42. output wire hub75_le,
  43. output wire hub75_blank,
  44. // Frame Buffer write interface
  45. // Row store/swap
  46. input wire [LOG_N_BANKS-1:0] fbw_bank_addr,
  47. input wire [LOG_N_ROWS-1:0] fbw_row_addr,
  48. input wire fbw_row_store,
  49. output wire fbw_row_rdy,
  50. input wire fbw_row_swap,
  51. // Line buffer access
  52. input wire [BITDEPTH-1:0] fbw_data,
  53. input wire [LOG_N_COLS-1:0] fbw_col_addr,
  54. input wire fbw_wren,
  55. // Frame buffer swap
  56. input wire frame_swap,
  57. output wire frame_rdy,
  58. // Config
  59. input wire [7:0] cfg_pre_latch_len,
  60. input wire [7:0] cfg_latch_len,
  61. input wire [7:0] cfg_post_latch_len,
  62. input wire [7:0] cfg_bcm_bit_len,
  63. // Clock / Reset
  64. input wire clk,
  65. input wire rst
  66. );
  67. // Signals
  68. // -------
  69. // Frame swap logic
  70. reg frame_swap_pending;
  71. wire frame_swap_fb;
  72. // PHY interface
  73. wire [LOG_N_ROWS-1:0] phy_addr;
  74. wire [(N_BANKS*N_CHANS)-1:0] phy_data;
  75. wire phy_clk;
  76. wire phy_le;
  77. wire phy_blank;
  78. // Frame Buffer access
  79. // Read - Back Buffer loading
  80. wire [LOG_N_ROWS-1:0] fbr_row_addr;
  81. wire fbr_row_load;
  82. wire fbr_row_rdy;
  83. wire fbr_row_swap;
  84. // Read - Front Buffer access
  85. wire [(N_BANKS*N_CHANS*N_PLANES)-1:0] fbr_data;
  86. wire [LOG_N_COLS-1:0] fbr_col_addr;
  87. wire fbr_rden;
  88. // Scanning
  89. wire scan_go;
  90. wire scan_rdy;
  91. // Binary Code Modulator
  92. wire [LOG_N_ROWS-1:0] bcm_row;
  93. wire bcm_go;
  94. wire bcm_rdy;
  95. // Shifter
  96. wire [N_PLANES-1:0] shift_plane;
  97. wire shift_go;
  98. wire shift_rdy;
  99. // Blanking control
  100. wire [N_PLANES-1:0] blank_plane;
  101. wire blank_go;
  102. wire blank_rdy;
  103. // Sub-blocks
  104. // ----------
  105. // Synchronized frame swap logic
  106. always @(posedge clk or posedge rst)
  107. if (rst)
  108. frame_swap_pending <= 1'b0;
  109. else
  110. frame_swap_pending <= (frame_swap_pending & ~scan_rdy) | frame_swap;
  111. assign frame_rdy = ~frame_swap_pending;
  112. assign scan_go = scan_rdy & ~frame_swap_pending;
  113. assign frame_swap_fb = frame_swap_pending & scan_rdy;
  114. // The signal direction usage legend to the right of the modules has the
  115. // following structure:
  116. // * Signal direction -> (output from the module)
  117. // * Signal direction <- (input to the module)
  118. // * top: signal is connected to top and exposed to the world
  119. // * pad: signal is a gpio pad id the direction indicates if the pad is an
  120. // input (<-), output (->) or bidir (<->)
  121. // * local: signal is conneted to some local module logic
  122. // * hub75_*: signal is connected to the module hub75_*
  123. // Frame Buffer
  124. hub75_framebuffer #(
  125. .N_BANKS(N_BANKS),
  126. .N_ROWS(N_ROWS),
  127. .N_COLS(N_COLS),
  128. .N_CHANS(N_CHANS),
  129. .N_PLANES(N_PLANES),
  130. .BITDEPTH(BITDEPTH)
  131. ) fb_I (
  132. .wr_bank_addr(fbw_bank_addr), // <- top
  133. .wr_row_addr(fbw_row_addr), // <- top
  134. .wr_row_store(fbw_row_store), // <- top
  135. .wr_row_rdy(fbw_row_rdy), // -> top
  136. .wr_row_swap(fbw_row_swap), // <- top
  137. .wr_data(fbw_data), // <- top
  138. .wr_col_addr(fbw_col_addr), // <- top
  139. .wr_en(fbw_wren), // <- top
  140. .rd_row_addr(fbr_row_addr), // <- hub75_scan
  141. .rd_row_load(fbr_row_load), // <- hub75_scan
  142. .rd_row_rdy(fbr_row_rdy), // -> hub75_scan
  143. .rd_row_swap(fbr_row_swap), // <- hub75_scan
  144. .rd_data(fbr_data), // -> hub75_shift
  145. .rd_col_addr(fbr_col_addr), // <- hub75_shift
  146. .rd_en(fbr_rden), // <- hub75_shift
  147. .frame_swap(frame_swap_fb), // <- local
  148. .clk(clk), // <- top
  149. .rst(rst) // <- top
  150. );
  151. // Scan
  152. hub75_scan #(
  153. .N_ROWS(N_ROWS)
  154. ) scan_I (
  155. .bcm_row(bcm_row), // -> hub75_bcm
  156. .bcm_go(bcm_go), // -> hub75_bcm
  157. .bcm_rdy(bcm_rdy), // <- hub75_bcm
  158. .fb_row_addr(fbr_row_addr), // -> hub75_framebuffer
  159. .fb_row_load(fbr_row_load), // -> hub75_framebuffer
  160. .fb_row_rdy(fbr_row_rdy), // <- hub75_framebuffer
  161. .fb_row_swap(fbr_row_swap), // -> hub75_framebuffer
  162. .ctrl_go(scan_go), // <- local
  163. .ctrl_rdy(scan_rdy), // -> local
  164. .clk(clk), // <- top
  165. .rst(rst) // <- top
  166. );
  167. // Binary Code Modulator control
  168. hub75_bcm #(
  169. .N_PLANES(N_PLANES)
  170. ) bcm_I (
  171. .phy_addr(phy_addr), // -> hub75_phy
  172. .phy_le(phy_le), // -> hub75_phy
  173. .shift_plane(shift_plane), // -> hub75_shift
  174. .shift_go(shift_go), // -> hub75_shift
  175. .shift_rdy(shift_rdy), // <- hub75_shift
  176. .blank_plane(blank_plane), // -> hub75_blanking
  177. .blank_go(blank_go), // -> hub75_blanking
  178. .blank_rdy(blank_rdy), // <- hub75_blanking
  179. .ctrl_row(bcm_row), // <- hub75_scan
  180. .ctrl_go(bcm_go), // <- hub75_scan
  181. .ctrl_rdy(bcm_rdy), // -> hub75_scan
  182. .cfg_pre_latch_len(cfg_pre_latch_len), // <- top
  183. .cfg_latch_len(cfg_latch_len), // <- top
  184. .cfg_post_latch_len(cfg_post_latch_len), // <- top
  185. .clk(clk), // <- top
  186. .rst(rst) // <- top
  187. );
  188. // Shifter
  189. hub75_shift #(
  190. .N_BANKS(N_BANKS),
  191. .N_COLS(N_COLS),
  192. .N_CHANS(N_CHANS),
  193. .N_PLANES(N_PLANES)
  194. ) shift_I (
  195. .phy_data(phy_data), // -> hub75_phy
  196. .phy_clk(phy_clk), // -> hub75_phy
  197. .ram_data(fbr_data), // <- hub75_framebuffer
  198. .ram_col_addr(fbr_col_addr), // -> hub75_framebuffer
  199. .ram_rden(fbr_rden), // -> hub75_framebuffer
  200. .ctrl_plane(shift_plane), // <- hub75_bcm
  201. .ctrl_go(shift_go), // <- hub75_bcm
  202. .ctrl_rdy(shift_rdy), // -> hub75_bcm
  203. .clk(clk), // <- top
  204. .rst(rst) // <- top
  205. );
  206. // Blanking control
  207. hub75_blanking #(
  208. .N_PLANES(N_PLANES)
  209. ) blank_I (
  210. .phy_blank(phy_blank), // -> hub75_phy
  211. .ctrl_plane(blank_plane), // <- hub75_bcm
  212. .ctrl_go(blank_go), // <- hub75_bcm
  213. .ctrl_rdy(blank_rdy), // -> hub75_bcm
  214. .cfg_bcm_bit_len(cfg_bcm_bit_len), // <- top
  215. .clk(clk), // <- top
  216. .rst(rst) // <- top
  217. );
  218. // Physical layer control
  219. hub75_phy #(
  220. .N_BANKS(N_BANKS),
  221. .N_ROWS(N_ROWS),
  222. .N_CHANS(N_CHANS)
  223. ) phy_I (
  224. .hub75_addr(hub75_addr), // -> pad
  225. .hub75_data(hub75_data), // -> pad
  226. .hub75_clk(hub75_clk), // -> pad
  227. .hub75_le(hub75_le), // -> pad
  228. .hub75_blank(hub75_blank), // -> pad
  229. .phy_addr(phy_addr), // <- hub75_bcm
  230. .phy_data(phy_data), // <- hub75_shift
  231. .phy_clk(phy_clk), // <- hub75_shift
  232. .phy_le(phy_le), // <- hub75_bcm
  233. .phy_blank(phy_blank), // <- hub75_blanking
  234. .clk(clk), // <- top
  235. .rst(rst) // <- top
  236. );
  237. endmodule // hub75_top