sysmgr.v 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * sysmgr.v
  3. *
  4. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  5. * All rights reserved.
  6. *
  7. * BSD 3-clause, see LICENSE.bsd
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * * Neither the name of the <organization> nor the
  17. * names of its contributors may be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * vim: ts=4 sw=4
  32. */
  33. `default_nettype none
  34. module sysmgr (
  35. input wire clk_in,
  36. input wire rst_in,
  37. output wire clk_out,
  38. output wire rst_out
  39. );
  40. // Signals
  41. wire pll_lock;
  42. wire pll_reset_n;
  43. wire clk_i;
  44. wire rst_i;
  45. reg [3:0] rst_cnt;
  46. // PLL instance
  47. `ifdef SIM
  48. assign clk_i = clk_in;
  49. assign pll_lock = pll_reset_n;
  50. `else
  51. SB_PLL40_PAD #(
  52. .DIVR(4'b0000),
  53. `ifdef PANEL_FAST
  54. .DIVF(7'b1001111),
  55. `else
  56. .DIVF(7'b0111111),
  57. `endif
  58. .DIVQ(3'b101),
  59. .FILTER_RANGE(3'b001),
  60. .FEEDBACK_PATH("SIMPLE"),
  61. .DELAY_ADJUSTMENT_MODE_FEEDBACK("FIXED"),
  62. .FDA_FEEDBACK(4'b0000),
  63. .SHIFTREG_DIV_MODE(2'b00),
  64. .PLLOUT_SELECT("GENCLK"),
  65. .ENABLE_ICEGATE(1'b0)
  66. ) pll_I (
  67. .PACKAGEPIN(clk_in),
  68. .PLLOUTCORE(),
  69. .PLLOUTGLOBAL(clk_i),
  70. .EXTFEEDBACK(1'b0),
  71. .DYNAMICDELAY(8'h00),
  72. .RESETB(pll_reset_n),
  73. .BYPASS(1'b0),
  74. .LATCHINPUTVALUE(1'b0),
  75. .LOCK(pll_lock),
  76. .SDI(1'b0),
  77. .SDO(),
  78. .SCLK(1'b0)
  79. );
  80. `endif
  81. assign clk_out = clk_i;
  82. // PLL reset generation
  83. assign pll_reset_n = ~rst_in;
  84. // Logic reset generation
  85. always @(posedge clk_i or negedge pll_lock)
  86. if (!pll_lock)
  87. rst_cnt <= 4'h8;
  88. else if (rst_cnt[3])
  89. rst_cnt <= rst_cnt + 1;
  90. assign rst_i = rst_cnt[3];
  91. SB_GB rst_gbuf_I (
  92. .USER_SIGNAL_TO_GLOBAL_BUFFER(rst_i),
  93. .GLOBAL_BUFFER_OUTPUT(rst_out)
  94. );
  95. endmodule // sysmgr