hub75_shift.v 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * hub75_shift.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_shift #(
  27. parameter integer N_BANKS = 2,
  28. parameter integer N_COLS = 64,
  29. parameter integer N_CHANS = 3,
  30. parameter integer N_PLANES = 8,
  31. // Auto-set
  32. parameter integer SDW = N_BANKS * N_CHANS,
  33. parameter integer LOG_N_COLS = $clog2(N_COLS)
  34. )(
  35. // PHY
  36. output wire [SDW-1:0] phy_data,
  37. output wire phy_clk,
  38. // RAM interface
  39. input wire [(N_BANKS*N_CHANS*N_PLANES)-1:0] ram_data,
  40. output wire [LOG_N_COLS-1:0] ram_col_addr,
  41. output wire ram_rden,
  42. // Control
  43. input wire [N_PLANES-1:0] ctrl_plane,
  44. input wire ctrl_go,
  45. output wire ctrl_rdy,
  46. // Clock / Reset
  47. input wire clk,
  48. input wire rst
  49. );
  50. genvar i;
  51. // Signals
  52. // -------
  53. reg active_0;
  54. reg active_1;
  55. reg active_2;
  56. reg [LOG_N_COLS:0] cnt_0;
  57. reg cnt_last_0;
  58. wire [SDW-1:0] ram_data_bit;
  59. reg [SDW-1:0] data_2;
  60. // Control logic
  61. // -------------
  62. // Active / Valid flag
  63. always @(posedge clk or posedge rst)
  64. if (rst) begin
  65. active_0 <= 1'b0;
  66. active_1 <= 1'b0;
  67. active_2 <= 1'b0;
  68. end else begin
  69. active_0 <= (active_0 & ~cnt_last_0) | ctrl_go;
  70. active_1 <= active_0;
  71. active_2 <= active_1;
  72. end
  73. // Counter
  74. always @(posedge clk)
  75. if (ctrl_go) begin
  76. cnt_0 <= 0;
  77. cnt_last_0 <= 1'b0;
  78. end else if (active_0) begin
  79. cnt_0 <= cnt_0 + 1;
  80. cnt_last_0 <= (cnt_0 == (N_COLS - 2));
  81. end
  82. // Ready ?
  83. assign ctrl_rdy = ~active_0;
  84. // Data path
  85. // ---------
  86. // RAM access
  87. assign ram_rden = active_0;
  88. assign ram_col_addr = cnt_0[LOG_N_COLS-1:0];
  89. // Data plane mux
  90. generate
  91. for (i=0; i<SDW; i=i+1)
  92. assign ram_data_bit[i] = |(ram_data[((i+1)*N_PLANES)-1:i*N_PLANES] & ctrl_plane);
  93. endgenerate
  94. // Mux register
  95. always @(posedge clk)
  96. data_2 <= ram_data_bit;
  97. // PHY
  98. // ---
  99. assign phy_data = data_2;
  100. assign phy_clk = active_2;
  101. endmodule // hub75_shift