sysmgr.v 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * sysmgr.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * Copyright (C) 2019-2020 Sylvain Munaut <tnt@246tNt.com>
  7. * SPDX-License-Identifier: CERN-OHL-P-2.0
  8. */
  9. `default_nettype none
  10. `include "boards.vh"
  11. module sysmgr (
  12. input wire clk_in,
  13. input wire rst_in,
  14. output wire clk_24m,
  15. output wire clk_48m,
  16. output wire rst_out
  17. );
  18. // Signals
  19. wire pll_lock;
  20. wire pll_reset_n;
  21. wire clk_24m_i;
  22. wire clk_48m_i;
  23. wire rst_i;
  24. reg [3:0] rst_cnt;
  25. // PLL instance
  26. `ifdef PLL_CORE
  27. SB_PLL40_2F_CORE #(
  28. `else
  29. SB_PLL40_2F_PAD #(
  30. `endif
  31. .DIVR(`PLL_DIVR),
  32. .DIVF(`PLL_DIVF),
  33. .DIVQ(`PLL_DIVQ),
  34. .FILTER_RANGE(`PLL_FILTER_RANGE),
  35. .FEEDBACK_PATH("SIMPLE"),
  36. .DELAY_ADJUSTMENT_MODE_FEEDBACK("FIXED"),
  37. .FDA_FEEDBACK(4'b0000),
  38. .SHIFTREG_DIV_MODE(2'b00),
  39. .PLLOUT_SELECT_PORTA("GENCLK"),
  40. .PLLOUT_SELECT_PORTB("GENCLK_HALF"),
  41. .ENABLE_ICEGATE_PORTA(1'b0),
  42. .ENABLE_ICEGATE_PORTB(1'b0)
  43. ) pll_I (
  44. `ifdef PLL_CORE
  45. .REFERENCECLK(clk_in),
  46. `else
  47. .PACKAGEPIN(clk_in),
  48. `endif
  49. .PLLOUTCOREA(),
  50. .PLLOUTGLOBALA(clk_48m_i),
  51. .PLLOUTCOREB(),
  52. .PLLOUTGLOBALB(clk_24m_i),
  53. .EXTFEEDBACK(1'b0),
  54. .DYNAMICDELAY(8'h00),
  55. .RESETB(pll_reset_n),
  56. .BYPASS(1'b0),
  57. .LATCHINPUTVALUE(1'b0),
  58. .LOCK(pll_lock),
  59. .SDI(1'b0),
  60. .SDO(),
  61. .SCLK(1'b0)
  62. );
  63. assign clk_24m = clk_24m_i;
  64. assign clk_48m = clk_48m_i;
  65. // PLL reset generation
  66. assign pll_reset_n = ~rst_in;
  67. // Logic reset generation
  68. always @(posedge clk_24m_i or negedge pll_lock)
  69. if (!pll_lock)
  70. rst_cnt <= 4'h0;
  71. else if (~rst_cnt[3])
  72. rst_cnt <= rst_cnt + 1;
  73. assign rst_i = ~rst_cnt[3];
  74. SB_GB rst_gbuf_I (
  75. .USER_SIGNAL_TO_GLOBAL_BUFFER(rst_i),
  76. .GLOBAL_BUFFER_OUTPUT(rst_out)
  77. );
  78. endmodule // sysmgr