sys_mgr.v 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * sys_mgr.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2020 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 sys_mgr (
  35. input wire [3:0] delay,
  36. input wire clk_in,
  37. output wire clk_1x,
  38. output wire clk_2x,
  39. output wire clk_4x,
  40. output wire clk_rd,
  41. output wire sync_4x,
  42. output wire sync_rd,
  43. output wire rst
  44. );
  45. wire pll_lock;
  46. SB_PLL40_2F_PAD #(
  47. .FEEDBACK_PATH("SIMPLE"),
  48. .DIVR(4'b0000),
  49. // 48
  50. // .DIVF(7'b0111111),
  51. // .DIVQ(3'b100),
  52. // 96
  53. // .DIVF(7'b0111111),
  54. // .DIVQ(3'b011),
  55. // 144
  56. // .DIVF(7'b0101111),
  57. // .DIVQ(3'b010),
  58. // 147
  59. .DIVF(7'b0110000),
  60. .DIVQ(3'b010),
  61. // 200
  62. // .DIVF(7'b1000010),
  63. // .DIVQ(3'b010),
  64. .FILTER_RANGE(3'b001),
  65. .DELAY_ADJUSTMENT_MODE_RELATIVE("DYNAMIC"),
  66. .FDA_RELATIVE(15),
  67. .SHIFTREG_DIV_MODE(0),
  68. .PLLOUT_SELECT_PORTA("GENCLK"),
  69. .PLLOUT_SELECT_PORTB("GENCLK")
  70. ) pll_I (
  71. .PACKAGEPIN(clk_in),
  72. .DYNAMICDELAY({delay, 4'h0}),
  73. .PLLOUTGLOBALA(clk_rd),
  74. .PLLOUTGLOBALB(clk_4x),
  75. .RESETB(1'b1),
  76. .LOCK(pll_lock)
  77. );
  78. ice40_serdes_crg #(
  79. .NO_CLOCK_2X(0)
  80. ) crg_I (
  81. .clk_4x(clk_4x),
  82. .pll_lock(pll_lock),
  83. .clk_1x(clk_1x),
  84. .clk_2x(clk_2x),
  85. .rst(rst)
  86. );
  87. `ifdef MEM_spi
  88. ice40_serdes_sync #(
  89. .PHASE(2),
  90. .NEG_EDGE(0),
  91. `ifdef VIDEO_none
  92. .GLOBAL_BUF(0),
  93. .LOCAL_BUF(0),
  94. .BEL_COL("X22"),
  95. .BEL_ROW("Y4"),
  96. `else
  97. .GLOBAL_BUF(0),
  98. .LOCAL_BUF(1),
  99. .BEL_COL("X15")
  100. `endif
  101. ) sync_4x_I (
  102. .clk_slow(clk_1x),
  103. .clk_fast(clk_4x),
  104. .rst(rst),
  105. .sync(sync_4x)
  106. );
  107. assign sync_rd = 1'b0;
  108. `endif
  109. `ifdef MEM_hyperram
  110. ice40_serdes_sync #(
  111. .PHASE(2),
  112. .NEG_EDGE(0),
  113. .GLOBAL_BUF(0),
  114. .LOCAL_BUF(1),
  115. .BEL_COL("X12"),
  116. .BEL_ROW("Y15")
  117. ) sync_4x_I (
  118. .clk_slow(clk_1x),
  119. .clk_fast(clk_4x),
  120. .rst(rst),
  121. .sync(sync_4x)
  122. );
  123. ice40_serdes_sync #(
  124. .PHASE(2),
  125. .NEG_EDGE(0),
  126. .GLOBAL_BUF(0),
  127. .LOCAL_BUF(1),
  128. .BEL_COL("X13"),
  129. .BEL_ROW("Y15")
  130. ) sync_rd_I (
  131. .clk_slow(clk_1x),
  132. .clk_fast(clk_rd),
  133. .rst(rst),
  134. .sync(sync_rd)
  135. );
  136. `endif
  137. endmodule