hub75_top.v 7.6 KB

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