hub75_top.v 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. parameter integer PHY_AIR = 0, // PHY Address Inc/Reset
  34. parameter SCAN_MODE = "ZIGZAG", // 'LINEAR' or 'ZIGZAG'
  35. // Auto-set
  36. parameter integer SDW = N_BANKS * N_CHANS,
  37. parameter integer LOG_N_BANKS = $clog2(N_BANKS),
  38. parameter integer LOG_N_ROWS = $clog2(N_ROWS),
  39. parameter integer LOG_N_COLS = $clog2(N_COLS)
  40. )(
  41. // Hub75 interface pads
  42. output wire hub75_addr_inc,
  43. output wire hub75_addr_rst,
  44. output wire [LOG_N_ROWS-1:0] hub75_addr,
  45. output wire [SDW-1:0] hub75_data,
  46. output wire hub75_clk,
  47. output wire hub75_le,
  48. output wire hub75_blank,
  49. // Frame Buffer write interface
  50. // Row store/swap
  51. input wire [LOG_N_BANKS-1:0] fbw_bank_addr,
  52. input wire [LOG_N_ROWS-1:0] fbw_row_addr,
  53. input wire fbw_row_store,
  54. output wire fbw_row_rdy,
  55. input wire fbw_row_swap,
  56. // Line buffer access
  57. input wire [BITDEPTH-1:0] fbw_data,
  58. input wire [LOG_N_COLS-1:0] fbw_col_addr,
  59. input wire fbw_wren,
  60. // Frame buffer swap
  61. input wire frame_swap,
  62. output wire frame_rdy,
  63. // Control / Config
  64. input wire ctrl_run,
  65. input wire [7:0] cfg_pre_latch_len,
  66. input wire [7:0] cfg_latch_len,
  67. input wire [7:0] cfg_post_latch_len,
  68. input wire [7:0] cfg_bcm_bit_len,
  69. // Clock / Reset
  70. input wire clk,
  71. input wire rst
  72. );
  73. // Signals
  74. // -------
  75. // Frame swap logic
  76. reg frame_swap_pending;
  77. wire frame_swap_fb;
  78. // PHY interface
  79. wire phy_addr_inc;
  80. wire phy_addr_rst;
  81. wire [LOG_N_ROWS-1:0] phy_addr;
  82. wire [SDW-1:0] phy_data;
  83. wire phy_clk;
  84. wire phy_le;
  85. wire phy_blank;
  86. // Frame Buffer access
  87. // Read - Back Buffer loading
  88. wire [LOG_N_ROWS-1:0] fbr_row_addr;
  89. wire fbr_row_load;
  90. wire fbr_row_rdy;
  91. wire fbr_row_swap;
  92. // Read - Front Buffer access
  93. wire [(N_BANKS*N_CHANS*N_PLANES)-1:0] fbr_data;
  94. wire [LOG_N_COLS-1:0] fbr_col_addr;
  95. wire fbr_rden;
  96. // Scanning
  97. wire scan_go;
  98. wire scan_rdy;
  99. // Binary Code Modulator
  100. wire [LOG_N_ROWS-1:0] bcm_row;
  101. wire bcm_row_first;
  102. wire bcm_go;
  103. wire bcm_rdy;
  104. // Shifter
  105. wire [N_PLANES-1:0] shift_plane;
  106. wire shift_go;
  107. wire shift_rdy;
  108. // Blanking control
  109. wire [N_PLANES-1:0] blank_plane;
  110. wire blank_go;
  111. wire blank_rdy;
  112. // Sub-blocks
  113. // ----------
  114. // Synchronized frame swap logic
  115. always @(posedge clk or posedge rst)
  116. if (rst)
  117. frame_swap_pending <= 1'b0;
  118. else
  119. frame_swap_pending <= (frame_swap_pending & ~scan_rdy) | frame_swap;
  120. assign frame_rdy = ~frame_swap_pending;
  121. assign scan_go = scan_rdy & ~frame_swap_pending & ctrl_run;
  122. assign frame_swap_fb = frame_swap_pending & scan_rdy;
  123. // The signal direction usage legend to the right of the modules has the
  124. // following structure:
  125. // * Signal direction -> (output from the module)
  126. // * Signal direction <- (input to the module)
  127. // * top: signal is connected to top and exposed to the world
  128. // * pad: signal is a gpio pad id the direction indicates if the pad is an
  129. // input (<-), output (->) or bidir (<->)
  130. // * local: signal is conneted to some local module logic
  131. // * hub75_*: signal is connected to the module hub75_*
  132. // Frame Buffer
  133. hub75_framebuffer #(
  134. .N_BANKS(N_BANKS),
  135. .N_ROWS(N_ROWS),
  136. .N_COLS(N_COLS),
  137. .N_CHANS(N_CHANS),
  138. .N_PLANES(N_PLANES),
  139. .BITDEPTH(BITDEPTH)
  140. ) fb_I (
  141. .wr_bank_addr(fbw_bank_addr), // <- top
  142. .wr_row_addr(fbw_row_addr), // <- top
  143. .wr_row_store(fbw_row_store), // <- top
  144. .wr_row_rdy(fbw_row_rdy), // -> top
  145. .wr_row_swap(fbw_row_swap), // <- top
  146. .wr_data(fbw_data), // <- top
  147. .wr_col_addr(fbw_col_addr), // <- top
  148. .wr_en(fbw_wren), // <- top
  149. .rd_row_addr(fbr_row_addr), // <- hub75_scan
  150. .rd_row_load(fbr_row_load), // <- hub75_scan
  151. .rd_row_rdy(fbr_row_rdy), // -> hub75_scan
  152. .rd_row_swap(fbr_row_swap), // <- hub75_scan
  153. .rd_data(fbr_data), // -> hub75_shift
  154. .rd_col_addr(fbr_col_addr), // <- hub75_shift
  155. .rd_en(fbr_rden), // <- hub75_shift
  156. .frame_swap(frame_swap_fb), // <- local
  157. .clk(clk), // <- top
  158. .rst(rst) // <- top
  159. );
  160. // Scan
  161. hub75_scan #(
  162. .N_ROWS(N_ROWS),
  163. .SCAN_MODE(SCAN_MODE)
  164. ) scan_I (
  165. .bcm_row(bcm_row), // -> hub75_bcm
  166. .bcm_row_first(bcm_row_first), // -> hub75_bcm
  167. .bcm_go(bcm_go), // -> hub75_bcm
  168. .bcm_rdy(bcm_rdy), // <- hub75_bcm
  169. .fb_row_addr(fbr_row_addr), // -> hub75_framebuffer
  170. .fb_row_load(fbr_row_load), // -> hub75_framebuffer
  171. .fb_row_rdy(fbr_row_rdy), // <- hub75_framebuffer
  172. .fb_row_swap(fbr_row_swap), // -> hub75_framebuffer
  173. .ctrl_go(scan_go), // <- local
  174. .ctrl_rdy(scan_rdy), // -> local
  175. .clk(clk), // <- top
  176. .rst(rst) // <- top
  177. );
  178. // Binary Code Modulator control
  179. hub75_bcm #(
  180. .N_PLANES(N_PLANES)
  181. ) bcm_I (
  182. .phy_addr_inc(phy_addr_inc), // -> hub75_phy
  183. .phy_addr_rst(phy_addr_rst), // -> hub75_phy
  184. .phy_addr(phy_addr), // -> hub75_phy
  185. .phy_le(phy_le), // -> hub75_phy
  186. .shift_plane(shift_plane), // -> hub75_shift
  187. .shift_go(shift_go), // -> hub75_shift
  188. .shift_rdy(shift_rdy), // <- hub75_shift
  189. .blank_plane(blank_plane), // -> hub75_blanking
  190. .blank_go(blank_go), // -> hub75_blanking
  191. .blank_rdy(blank_rdy), // <- hub75_blanking
  192. .ctrl_row(bcm_row), // <- hub75_scan
  193. .ctrl_row_first(bcm_row_first), // <- hub75_scan
  194. .ctrl_go(bcm_go), // <- hub75_scan
  195. .ctrl_rdy(bcm_rdy), // -> hub75_scan
  196. .cfg_pre_latch_len(cfg_pre_latch_len), // <- top
  197. .cfg_latch_len(cfg_latch_len), // <- top
  198. .cfg_post_latch_len(cfg_post_latch_len), // <- top
  199. .clk(clk), // <- top
  200. .rst(rst) // <- top
  201. );
  202. // Shifter
  203. hub75_shift #(
  204. .N_BANKS(N_BANKS),
  205. .N_COLS(N_COLS),
  206. .N_CHANS(N_CHANS),
  207. .N_PLANES(N_PLANES)
  208. ) shift_I (
  209. .phy_data(phy_data), // -> hub75_phy
  210. .phy_clk(phy_clk), // -> hub75_phy
  211. .ram_data(fbr_data), // <- hub75_framebuffer
  212. .ram_col_addr(fbr_col_addr), // -> hub75_framebuffer
  213. .ram_rden(fbr_rden), // -> hub75_framebuffer
  214. .ctrl_plane(shift_plane), // <- hub75_bcm
  215. .ctrl_go(shift_go), // <- hub75_bcm
  216. .ctrl_rdy(shift_rdy), // -> hub75_bcm
  217. .clk(clk), // <- top
  218. .rst(rst) // <- top
  219. );
  220. // Blanking control
  221. hub75_blanking #(
  222. .N_PLANES(N_PLANES)
  223. ) blank_I (
  224. .phy_blank(phy_blank), // -> hub75_phy
  225. .ctrl_plane(blank_plane), // <- hub75_bcm
  226. .ctrl_go(blank_go), // <- hub75_bcm
  227. .ctrl_rdy(blank_rdy), // -> hub75_bcm
  228. .cfg_bcm_bit_len(cfg_bcm_bit_len), // <- top
  229. .clk(clk), // <- top
  230. .rst(rst) // <- top
  231. );
  232. // Physical layer control
  233. hub75_phy #(
  234. .N_BANKS(N_BANKS),
  235. .N_ROWS(N_ROWS),
  236. .N_CHANS(N_CHANS),
  237. .PHY_AIR(PHY_AIR)
  238. ) phy_I (
  239. .hub75_addr_inc(hub75_addr_inc),// -> pad
  240. .hub75_addr_rst(hub75_addr_rst),// -> pad
  241. .hub75_addr(hub75_addr), // -> pad
  242. .hub75_data(hub75_data), // -> pad
  243. .hub75_clk(hub75_clk), // -> pad
  244. .hub75_le(hub75_le), // -> pad
  245. .hub75_blank(hub75_blank), // -> pad
  246. .phy_addr_inc(phy_addr_inc), // <- hub75_bcm
  247. .phy_addr_rst(phy_addr_rst), // <- hub75_bcm
  248. .phy_addr(phy_addr), // <- hub75_bcm
  249. .phy_data(phy_data), // <- hub75_shift
  250. .phy_clk(phy_clk), // <- hub75_shift
  251. .phy_le(phy_le), // <- hub75_bcm
  252. .phy_blank(phy_blank), // <- hub75_blanking
  253. .clk(clk), // <- top
  254. .rst(rst) // <- top
  255. );
  256. endmodule // hub75_top