hub75_top.v 8.2 KB

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