hub75_bcm.v 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * hub75_bcm.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_bcm #(
  27. parameter integer N_ROWS = 32,
  28. parameter integer N_PLANES = 8,
  29. // Auto-set
  30. parameter integer LOG_N_ROWS = $clog2(N_ROWS)
  31. )(
  32. // PHY
  33. output wire [LOG_N_ROWS-1:0] phy_addr,
  34. output wire phy_le,
  35. // Shifter interface
  36. output wire [N_PLANES-1:0] shift_plane,
  37. output wire shift_go,
  38. input wire shift_rdy,
  39. // Blanking interface
  40. output wire [N_PLANES-1:0] blank_plane,
  41. output wire blank_go,
  42. input wire blank_rdy,
  43. // Control
  44. input wire [LOG_N_ROWS-1:0] ctrl_row,
  45. input wire ctrl_go,
  46. output wire ctrl_rdy,
  47. // Config
  48. input wire [7:0] cfg_pre_latch_len,
  49. input wire [7:0] cfg_latch_len,
  50. input wire [7:0] cfg_post_latch_len,
  51. // Clock / Reset
  52. input wire clk,
  53. input wire rst
  54. );
  55. genvar i;
  56. // Signals
  57. // -------
  58. // FSM
  59. localparam
  60. ST_IDLE = 0,
  61. ST_SHIFT = 1,
  62. ST_WAIT_TO_LATCH = 2,
  63. ST_PRE_LATCH = 3,
  64. ST_DO_LATCH = 4,
  65. ST_POST_LATCH = 5,
  66. ST_ISSUE_BLANK = 6;
  67. reg [2:0] fsm_state;
  68. reg [2:0] fsm_state_next;
  69. reg [7:0] timer_val;
  70. wire timer_trig;
  71. reg [N_PLANES-1:0] plane;
  72. wire plane_last;
  73. reg [LOG_N_ROWS-1:0] addr;
  74. reg [LOG_N_ROWS-1:0] addr_out;
  75. wire addr_ce;
  76. wire le;
  77. // FSM
  78. // ---
  79. // State register
  80. always @(posedge clk or posedge rst)
  81. if (rst)
  82. fsm_state <= ST_IDLE;
  83. else
  84. fsm_state <= fsm_state_next;
  85. // Next-State logic
  86. always @(*)
  87. begin
  88. // Default is to not move
  89. fsm_state_next = fsm_state;
  90. // Transitions ?
  91. case (fsm_state)
  92. ST_IDLE:
  93. if (ctrl_go)
  94. fsm_state_next = ST_SHIFT;
  95. ST_SHIFT:
  96. fsm_state_next = ST_WAIT_TO_LATCH;
  97. ST_WAIT_TO_LATCH:
  98. if (shift_rdy & blank_rdy)
  99. fsm_state_next = ST_PRE_LATCH;
  100. ST_PRE_LATCH:
  101. if (timer_trig)
  102. fsm_state_next = ST_DO_LATCH;
  103. ST_DO_LATCH:
  104. if (timer_trig)
  105. fsm_state_next = ST_POST_LATCH;
  106. ST_POST_LATCH:
  107. if (timer_trig)
  108. fsm_state_next = ST_ISSUE_BLANK;
  109. ST_ISSUE_BLANK:
  110. fsm_state_next = plane_last ? ST_IDLE : ST_SHIFT;
  111. endcase
  112. end
  113. // Timer
  114. // -----
  115. always @(posedge clk)
  116. begin
  117. if (fsm_state != fsm_state_next) begin
  118. // Default is to trigger all the time
  119. timer_val <= 8'h80;
  120. // Preload for next state
  121. case (fsm_state_next)
  122. ST_PRE_LATCH: timer_val <= cfg_pre_latch_len;
  123. ST_DO_LATCH: timer_val <= cfg_latch_len;
  124. ST_POST_LATCH: timer_val <= cfg_post_latch_len;
  125. endcase
  126. end else begin
  127. timer_val <= timer_val - 1;
  128. end
  129. end
  130. assign timer_trig = timer_val[7];
  131. // Plane counter
  132. // -------------
  133. always @(posedge clk)
  134. if (fsm_state == ST_IDLE)
  135. plane <= { {(N_PLANES-1){1'b0}}, 1'b1 };
  136. else if (fsm_state == ST_ISSUE_BLANK)
  137. plane <= { plane[N_PLANES-2:0], 1'b0 };
  138. assign plane_last = plane[N_PLANES-1];
  139. // External Control
  140. // ----------------
  141. // Shifter
  142. assign shift_plane = plane;
  143. assign shift_go = (fsm_state == ST_SHIFT);
  144. // Blanking
  145. assign blank_plane = plane;
  146. assign blank_go = (fsm_state == ST_ISSUE_BLANK);
  147. // Address
  148. always @(posedge clk)
  149. if (ctrl_go)
  150. addr <= ctrl_row;
  151. always @(posedge clk)
  152. if (fsm_state == ST_DO_LATCH)
  153. addr_out <= addr;
  154. // Latch
  155. assign le = (fsm_state == ST_DO_LATCH);
  156. // Ready ?
  157. assign ctrl_rdy = (fsm_state == ST_IDLE);
  158. // PHY
  159. // ---
  160. assign phy_addr = addr_out;
  161. assign phy_le = le;
  162. endmodule // hub75_bcm