sysmgr.v 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * sysmgr.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 sysmgr (
  35. input wire clk_in,
  36. input wire rst_in,
  37. output wire clk_2x_out,
  38. output wire clk_1x_out,
  39. output wire rst_out
  40. );
  41. // Signals
  42. wire pll_lock;
  43. wire pll_reset_n;
  44. wire clk_2x_i;
  45. wire clk_1x_i;
  46. wire rst_i;
  47. reg [7:0] rst_cnt;
  48. // PLL instance
  49. `ifdef SIM
  50. reg toggle = 1'b0;
  51. initial
  52. rst_cnt <= 8'h80;
  53. always @(posedge clk_in)
  54. toggle <= ~toggle;
  55. assign clk_1x_i = toggle;
  56. assign clk_2x_i = clk_in;
  57. assign pll_lock = pll_reset_n;
  58. `else
  59. SB_PLL40_2F_PAD #(
  60. // 147 M
  61. .DIVR(4'b0000),
  62. .DIVF(7'b0110000),
  63. .DIVQ(3'b010),
  64. .FILTER_RANGE(3'b001),
  65. .FEEDBACK_PATH("SIMPLE"),
  66. .DELAY_ADJUSTMENT_MODE_FEEDBACK("FIXED"),
  67. .FDA_FEEDBACK(4'b0000),
  68. .SHIFTREG_DIV_MODE(2'b00),
  69. .PLLOUT_SELECT_PORTA("GENCLK"),
  70. .PLLOUT_SELECT_PORTB("GENCLK_HALF"),
  71. ) pll_I (
  72. .PACKAGEPIN(clk_in),
  73. .PLLOUTGLOBALA(clk_2x_i),
  74. .PLLOUTGLOBALB(clk_1x_i),
  75. .EXTFEEDBACK(1'b0),
  76. .DYNAMICDELAY(8'h00),
  77. .RESETB(pll_reset_n),
  78. .BYPASS(1'b0),
  79. .LATCHINPUTVALUE(1'b0),
  80. .LOCK(pll_lock),
  81. .SDI(1'b0),
  82. .SDO(),
  83. .SCLK(1'b0)
  84. );
  85. `endif
  86. assign clk_2x_out = clk_2x_i;
  87. assign clk_1x_out = clk_1x_i;
  88. // PLL reset generation
  89. assign pll_reset_n = ~rst_in;
  90. // Logic reset generation
  91. always @(posedge clk_1x_i or negedge pll_lock)
  92. if (!pll_lock)
  93. rst_cnt <= 8'h80;
  94. else if (rst_cnt[7])
  95. rst_cnt <= rst_cnt + 1;
  96. assign rst_i = rst_cnt[7];
  97. SB_GB rst_gbuf_I (
  98. .USER_SIGNAL_TO_GLOBAL_BUFFER(rst_i),
  99. .GLOBAL_BUFFER_OUTPUT(rst_out)
  100. );
  101. endmodule // sysmgr