hub75_top.v 7.6 KB

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