altera_reset_controller.v 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. // (C) 2001-2018 Intel Corporation. All rights reserved.
  2. // Your use of Intel Corporation's design tools, logic functions and other
  3. // software and tools, and its AMPP partner logic functions, and any output
  4. // files from any of the foregoing (including device programming or simulation
  5. // files), and any associated documentation or information are expressly subject
  6. // to the terms and conditions of the Intel Program License Subscription
  7. // Agreement, Intel FPGA IP License Agreement, or other applicable
  8. // license agreement, including, without limitation, that your use is for the
  9. // sole purpose of programming logic devices manufactured by Intel and sold by
  10. // Intel or its authorized distributors. Please refer to the applicable
  11. // agreement for further details.
  12. // (C) 2001-2013 Altera Corporation. All rights reserved.
  13. // Your use of Altera Corporation's design tools, logic functions and other
  14. // software and tools, and its AMPP partner logic functions, and any output
  15. // files any of the foregoing (including device programming or simulation
  16. // files), and any associated documentation or information are expressly subject
  17. // to the terms and conditions of the Altera Program License Subscription
  18. // Agreement, Altera MegaCore Function License Agreement, or other applicable
  19. // license agreement, including, without limitation, that your use is for the
  20. // sole purpose of programming logic devices manufactured by Altera and sold by
  21. // Altera or its authorized distributors. Please refer to the applicable
  22. // agreement for further details.
  23. // $Id: //acds/rel/18.1std/ip/merlin/altera_reset_controller/altera_reset_controller.v#1 $
  24. // $Revision: #1 $
  25. // $Date: 2018/07/18 $
  26. // $Author: psgswbuild $
  27. // --------------------------------------
  28. // Reset controller
  29. //
  30. // Combines all the input resets and synchronizes
  31. // the result to the clk.
  32. // ACDS13.1 - Added reset request as part of reset sequencing
  33. // --------------------------------------
  34. `timescale 1 ns / 1 ns
  35. module altera_reset_controller
  36. #(
  37. parameter NUM_RESET_INPUTS = 6,
  38. parameter USE_RESET_REQUEST_IN0 = 0,
  39. parameter USE_RESET_REQUEST_IN1 = 0,
  40. parameter USE_RESET_REQUEST_IN2 = 0,
  41. parameter USE_RESET_REQUEST_IN3 = 0,
  42. parameter USE_RESET_REQUEST_IN4 = 0,
  43. parameter USE_RESET_REQUEST_IN5 = 0,
  44. parameter USE_RESET_REQUEST_IN6 = 0,
  45. parameter USE_RESET_REQUEST_IN7 = 0,
  46. parameter USE_RESET_REQUEST_IN8 = 0,
  47. parameter USE_RESET_REQUEST_IN9 = 0,
  48. parameter USE_RESET_REQUEST_IN10 = 0,
  49. parameter USE_RESET_REQUEST_IN11 = 0,
  50. parameter USE_RESET_REQUEST_IN12 = 0,
  51. parameter USE_RESET_REQUEST_IN13 = 0,
  52. parameter USE_RESET_REQUEST_IN14 = 0,
  53. parameter USE_RESET_REQUEST_IN15 = 0,
  54. parameter OUTPUT_RESET_SYNC_EDGES = "deassert",
  55. parameter SYNC_DEPTH = 2,
  56. parameter RESET_REQUEST_PRESENT = 0,
  57. parameter RESET_REQ_WAIT_TIME = 3,
  58. parameter MIN_RST_ASSERTION_TIME = 11,
  59. parameter RESET_REQ_EARLY_DSRT_TIME = 4,
  60. parameter ADAPT_RESET_REQUEST = 0
  61. )
  62. (
  63. // --------------------------------------
  64. // We support up to 16 reset inputs, for now
  65. // --------------------------------------
  66. input reset_in0,
  67. input reset_in1,
  68. input reset_in2,
  69. input reset_in3,
  70. input reset_in4,
  71. input reset_in5,
  72. input reset_in6,
  73. input reset_in7,
  74. input reset_in8,
  75. input reset_in9,
  76. input reset_in10,
  77. input reset_in11,
  78. input reset_in12,
  79. input reset_in13,
  80. input reset_in14,
  81. input reset_in15,
  82. input reset_req_in0,
  83. input reset_req_in1,
  84. input reset_req_in2,
  85. input reset_req_in3,
  86. input reset_req_in4,
  87. input reset_req_in5,
  88. input reset_req_in6,
  89. input reset_req_in7,
  90. input reset_req_in8,
  91. input reset_req_in9,
  92. input reset_req_in10,
  93. input reset_req_in11,
  94. input reset_req_in12,
  95. input reset_req_in13,
  96. input reset_req_in14,
  97. input reset_req_in15,
  98. input clk,
  99. output reg reset_out,
  100. output reg reset_req
  101. );
  102. // Always use async reset synchronizer if reset_req is used
  103. localparam ASYNC_RESET = (OUTPUT_RESET_SYNC_EDGES == "deassert");
  104. // --------------------------------------
  105. // Local parameter to control the reset_req and reset_out timing when RESET_REQUEST_PRESENT==1
  106. // --------------------------------------
  107. localparam MIN_METASTABLE = 3;
  108. localparam RSTREQ_ASRT_SYNC_TAP = MIN_METASTABLE + RESET_REQ_WAIT_TIME;
  109. localparam LARGER = RESET_REQ_WAIT_TIME > RESET_REQ_EARLY_DSRT_TIME ? RESET_REQ_WAIT_TIME : RESET_REQ_EARLY_DSRT_TIME;
  110. localparam ASSERTION_CHAIN_LENGTH = (MIN_METASTABLE > LARGER) ?
  111. MIN_RST_ASSERTION_TIME + 1 :
  112. (
  113. (MIN_RST_ASSERTION_TIME > LARGER)?
  114. MIN_RST_ASSERTION_TIME + (LARGER - MIN_METASTABLE + 1) + 1 :
  115. MIN_RST_ASSERTION_TIME + RESET_REQ_EARLY_DSRT_TIME + RESET_REQ_WAIT_TIME - MIN_METASTABLE + 2
  116. );
  117. localparam RESET_REQ_DRST_TAP = RESET_REQ_EARLY_DSRT_TIME + 1;
  118. // --------------------------------------
  119. wire merged_reset;
  120. wire merged_reset_req_in;
  121. wire reset_out_pre;
  122. wire reset_req_pre;
  123. // Registers and Interconnect
  124. (*preserve*) reg [RSTREQ_ASRT_SYNC_TAP: 0] altera_reset_synchronizer_int_chain;
  125. reg [ASSERTION_CHAIN_LENGTH-1: 0] r_sync_rst_chain;
  126. reg r_sync_rst;
  127. reg r_early_rst;
  128. // --------------------------------------
  129. // "Or" all the input resets together
  130. // --------------------------------------
  131. assign merged_reset = (
  132. reset_in0 |
  133. reset_in1 |
  134. reset_in2 |
  135. reset_in3 |
  136. reset_in4 |
  137. reset_in5 |
  138. reset_in6 |
  139. reset_in7 |
  140. reset_in8 |
  141. reset_in9 |
  142. reset_in10 |
  143. reset_in11 |
  144. reset_in12 |
  145. reset_in13 |
  146. reset_in14 |
  147. reset_in15
  148. );
  149. assign merged_reset_req_in = (
  150. ( (USE_RESET_REQUEST_IN0 == 1) ? reset_req_in0 : 1'b0) |
  151. ( (USE_RESET_REQUEST_IN1 == 1) ? reset_req_in1 : 1'b0) |
  152. ( (USE_RESET_REQUEST_IN2 == 1) ? reset_req_in2 : 1'b0) |
  153. ( (USE_RESET_REQUEST_IN3 == 1) ? reset_req_in3 : 1'b0) |
  154. ( (USE_RESET_REQUEST_IN4 == 1) ? reset_req_in4 : 1'b0) |
  155. ( (USE_RESET_REQUEST_IN5 == 1) ? reset_req_in5 : 1'b0) |
  156. ( (USE_RESET_REQUEST_IN6 == 1) ? reset_req_in6 : 1'b0) |
  157. ( (USE_RESET_REQUEST_IN7 == 1) ? reset_req_in7 : 1'b0) |
  158. ( (USE_RESET_REQUEST_IN8 == 1) ? reset_req_in8 : 1'b0) |
  159. ( (USE_RESET_REQUEST_IN9 == 1) ? reset_req_in9 : 1'b0) |
  160. ( (USE_RESET_REQUEST_IN10 == 1) ? reset_req_in10 : 1'b0) |
  161. ( (USE_RESET_REQUEST_IN11 == 1) ? reset_req_in11 : 1'b0) |
  162. ( (USE_RESET_REQUEST_IN12 == 1) ? reset_req_in12 : 1'b0) |
  163. ( (USE_RESET_REQUEST_IN13 == 1) ? reset_req_in13 : 1'b0) |
  164. ( (USE_RESET_REQUEST_IN14 == 1) ? reset_req_in14 : 1'b0) |
  165. ( (USE_RESET_REQUEST_IN15 == 1) ? reset_req_in15 : 1'b0)
  166. );
  167. // --------------------------------------
  168. // And if required, synchronize it to the required clock domain,
  169. // with the correct synchronization type
  170. // --------------------------------------
  171. generate if (OUTPUT_RESET_SYNC_EDGES == "none" && (RESET_REQUEST_PRESENT==0)) begin
  172. assign reset_out_pre = merged_reset;
  173. assign reset_req_pre = merged_reset_req_in;
  174. end else begin
  175. altera_reset_synchronizer
  176. #(
  177. .DEPTH (SYNC_DEPTH),
  178. .ASYNC_RESET(RESET_REQUEST_PRESENT? 1'b1 : ASYNC_RESET)
  179. )
  180. alt_rst_sync_uq1
  181. (
  182. .clk (clk),
  183. .reset_in (merged_reset),
  184. .reset_out (reset_out_pre)
  185. );
  186. altera_reset_synchronizer
  187. #(
  188. .DEPTH (SYNC_DEPTH),
  189. .ASYNC_RESET(0)
  190. )
  191. alt_rst_req_sync_uq1
  192. (
  193. .clk (clk),
  194. .reset_in (merged_reset_req_in),
  195. .reset_out (reset_req_pre)
  196. );
  197. end
  198. endgenerate
  199. generate if ( ( (RESET_REQUEST_PRESENT == 0) && (ADAPT_RESET_REQUEST==0) )|
  200. ( (ADAPT_RESET_REQUEST == 1) && (OUTPUT_RESET_SYNC_EDGES != "deassert") ) ) begin
  201. always @* begin
  202. reset_out = reset_out_pre;
  203. reset_req = reset_req_pre;
  204. end
  205. end else if ( (RESET_REQUEST_PRESENT == 0) && (ADAPT_RESET_REQUEST==1) ) begin
  206. wire reset_out_pre2;
  207. altera_reset_synchronizer
  208. #(
  209. .DEPTH (SYNC_DEPTH+1),
  210. .ASYNC_RESET(0)
  211. )
  212. alt_rst_sync_uq2
  213. (
  214. .clk (clk),
  215. .reset_in (reset_out_pre),
  216. .reset_out (reset_out_pre2)
  217. );
  218. always @* begin
  219. reset_out = reset_out_pre2;
  220. reset_req = reset_req_pre;
  221. end
  222. end
  223. else begin
  224. // 3-FF Metastability Synchronizer
  225. initial
  226. begin
  227. altera_reset_synchronizer_int_chain <= {RSTREQ_ASRT_SYNC_TAP{1'b1}};
  228. end
  229. always @(posedge clk)
  230. begin
  231. altera_reset_synchronizer_int_chain[RSTREQ_ASRT_SYNC_TAP:0] <=
  232. {altera_reset_synchronizer_int_chain[RSTREQ_ASRT_SYNC_TAP-1:0], reset_out_pre};
  233. end
  234. // Synchronous reset pipe
  235. initial
  236. begin
  237. r_sync_rst_chain <= {ASSERTION_CHAIN_LENGTH{1'b1}};
  238. end
  239. always @(posedge clk)
  240. begin
  241. if (altera_reset_synchronizer_int_chain[MIN_METASTABLE-1] == 1'b1)
  242. begin
  243. r_sync_rst_chain <= {ASSERTION_CHAIN_LENGTH{1'b1}};
  244. end
  245. else
  246. begin
  247. r_sync_rst_chain <= {1'b0, r_sync_rst_chain[ASSERTION_CHAIN_LENGTH-1:1]};
  248. end
  249. end
  250. // Standard synchronous reset output. From 0-1, the transition lags the early output. For 1->0, the transition
  251. // matches the early input.
  252. always @(posedge clk)
  253. begin
  254. case ({altera_reset_synchronizer_int_chain[RSTREQ_ASRT_SYNC_TAP], r_sync_rst_chain[1], r_sync_rst})
  255. 3'b000: r_sync_rst <= 1'b0; // Not reset
  256. 3'b001: r_sync_rst <= 1'b0;
  257. 3'b010: r_sync_rst <= 1'b0;
  258. 3'b011: r_sync_rst <= 1'b1;
  259. 3'b100: r_sync_rst <= 1'b1;
  260. 3'b101: r_sync_rst <= 1'b1;
  261. 3'b110: r_sync_rst <= 1'b1;
  262. 3'b111: r_sync_rst <= 1'b1; // In Reset
  263. default: r_sync_rst <= 1'b1;
  264. endcase
  265. case ({r_sync_rst_chain[1], r_sync_rst_chain[RESET_REQ_DRST_TAP] | reset_req_pre})
  266. 2'b00: r_early_rst <= 1'b0; // Not reset
  267. 2'b01: r_early_rst <= 1'b1; // Coming out of reset
  268. 2'b10: r_early_rst <= 1'b0; // Spurious reset - should not be possible via synchronous design.
  269. 2'b11: r_early_rst <= 1'b1; // Held in reset
  270. default: r_early_rst <= 1'b1;
  271. endcase
  272. end
  273. always @* begin
  274. reset_out = r_sync_rst;
  275. reset_req = r_early_rst;
  276. end
  277. end
  278. endgenerate
  279. endmodule