top.v 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * 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. * BSD 3-clause, see LICENSE.bsd
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * * Neither the name of the <organization> nor the
  19. * names of its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. `default_nettype none
  34. module top (
  35. // HDMI PMOD
  36. output wire hdmi_clk,
  37. output wire hdmi_hsync,
  38. output wire hdmi_vsync,
  39. output wire hdmi_de,
  40. output wire hdmi_r,
  41. output wire hdmi_g,
  42. output wire hdmi_b,
  43. output wire hdmi_i,
  44. // Slave SPI interface
  45. input wire slave_mosi,
  46. output wire slave_miso,
  47. input wire slave_cs_n,
  48. input wire slave_clk,
  49. // Clock
  50. input wire clk12m_in
  51. );
  52. // Signals
  53. // -------
  54. // Fast Bus
  55. wire [15:0] fbus_addr;
  56. wire [15:0] fbus_din;
  57. wire [15:0] fbus_dout;
  58. wire fbus_cyc;
  59. wire fbus_we;
  60. wire fbus_ack;
  61. // Slow Bus
  62. wire [7:0] sb_addr;
  63. wire [7:0] sb_data;
  64. wire sb_first;
  65. wire sb_last;
  66. wire sb_stb;
  67. wire [7:0] sb_out;
  68. // Bridge
  69. reg [31:0] data;
  70. reg pending;
  71. // Clocks / Reset
  72. wire clk_2x;
  73. wire clk_1x;
  74. wire rst;
  75. // SPI interface
  76. // -------------
  77. spi_fast spi_I (
  78. .spi_mosi(slave_mosi),
  79. .spi_miso(slave_miso),
  80. .spi_cs_n(slave_cs_n),
  81. .spi_clk(slave_clk),
  82. .addr(sb_addr),
  83. .data(sb_data),
  84. .first(sb_first),
  85. .last(sb_last),
  86. .strobe(sb_stb),
  87. .out(sb_out),
  88. .clk(clk_1x),
  89. .rst(rst)
  90. );
  91. // Slow -> Fast bus bridge
  92. // -----------------------
  93. assign fbus_din = data[15:0];
  94. assign fbus_addr = data[31:16];
  95. assign fbus_cyc = pending;
  96. assign fbus_we = 1'b1;
  97. always @(posedge clk_1x)
  98. if (rst)
  99. pending <= 1'b0;
  100. else
  101. pending <= (pending & ~fbus_ack) | (sb_last & sb_stb & |(data[24:22]));
  102. always @(posedge clk_1x)
  103. if (sb_stb & ~pending)
  104. data <= { data[24:0], sb_data };
  105. // HDMI text mode core
  106. // -------------------
  107. hdmi_text_2x #(
  108. .DW(4)
  109. ) text_I (
  110. .hdmi_data({hdmi_i, hdmi_b, hdmi_g, hdmi_r}),
  111. .hdmi_hsync(hdmi_hsync),
  112. .hdmi_vsync(hdmi_vsync),
  113. .hdmi_de(hdmi_de),
  114. .hdmi_clk(hdmi_clk),
  115. .bus_addr(fbus_addr),
  116. .bus_din(fbus_din),
  117. .bus_dout(fbus_dout),
  118. .bus_cyc(fbus_cyc),
  119. .bus_we(fbus_we),
  120. .bus_ack(fbus_ack),
  121. .clk_1x(clk_1x),
  122. .clk_2x(clk_2x),
  123. .rst(rst)
  124. );
  125. // Clock / Reset generation
  126. // ------------------------
  127. sysmgr sysmgr_I (
  128. .clk_in(clk12m_in),
  129. .rst_in(1'b0),
  130. .clk_2x_out(clk_2x),
  131. .clk_1x_out(clk_1x),
  132. .rst_out(rst)
  133. );
  134. endmodule // top