2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Function: Clock synchronizer #
|
|
|
|
//#############################################################################
|
|
|
|
//# Author: Andreas Olofsson #
|
|
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
|
|
|
//#############################################################################
|
2015-11-16 09:58:47 -05:00
|
|
|
|
2016-06-19 17:36:00 -04:00
|
|
|
module oh_dsync #(parameter PS = 2, // number of sync stages
|
2020-02-02 23:12:19 -05:00
|
|
|
parameter DELAY = 0 // random delay
|
2016-04-11 12:01:59 -04:00
|
|
|
)
|
|
|
|
(
|
2016-06-19 17:08:46 -04:00
|
|
|
input clk, // clock
|
|
|
|
input nreset, // clock
|
|
|
|
input din, // input data
|
|
|
|
output dout // synchronized data
|
2016-04-11 12:01:59 -04:00
|
|
|
);
|
2015-11-06 16:51:35 -05:00
|
|
|
|
2020-02-02 23:12:19 -05:00
|
|
|
`ifdef CFG_ASIC
|
|
|
|
asic_dsync asic_dsync (.clk(clk),
|
|
|
|
.nreset(nreset),
|
|
|
|
.din(din),
|
|
|
|
.dout(dout));
|
|
|
|
`else
|
|
|
|
reg [PS:0] sync_pipe;
|
|
|
|
always @ (posedge clk or negedge nreset)
|
|
|
|
if(!nreset)
|
|
|
|
sync_pipe[PS:0] <= 1'b0;
|
|
|
|
else
|
|
|
|
sync_pipe[PS:0] <= {sync_pipe[PS-1:0],din};
|
|
|
|
// drive randomize delay from testbench
|
|
|
|
assign dout = (DELAY & sync_pipe[PS]) | //extra cycle
|
|
|
|
(~DELAY & sync_pipe[PS-1]); //default
|
|
|
|
`endif // !`ifdef CFG_ASIC
|
2016-06-19 17:08:46 -04:00
|
|
|
|
2015-11-30 13:45:49 -05:00
|
|
|
endmodule // oh_dsync
|
|
|
|
|
2015-11-06 16:51:35 -05:00
|
|
|
|