1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-02-07 06:44:09 +08:00
oh/common/hdl/oh_dsync.v

38 lines
1.2 KiB
Coq
Raw Normal View History

//#############################################################################
//# 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
parameter DELAY = 0 // random delay
)
(
input clk, // clock
input nreset, // clock
input din, // input data
output dout // synchronized data
);
`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
endmodule // oh_dsync