Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
data_xdomain Source File
1// clk_out must be more than twice as fast as the gate_in rate.
2`timescale 1ns / 1ns
3module data_xdomain #(
4 parameter size=16
5) (
6 input clk_in,
7 input gate_in,
8 input [size-1:0] data_in,
9 input clk_out,
10 output gate_out,
11 output [size-1:0] data_out
12);
13
14reg [size-1:0] data_latch=0;
15always @(posedge clk_in) if (gate_in) data_latch <= data_in;
16
17wire gate_x;
18flag_xdomain foo(
19 .clk1(clk_in), .flagin_clk1(gate_in),
20 .clk2(clk_out), .flagout_clk2(gate_x));
21
22wire [size-1:0] data_pipe;
23`ifdef HAPPY_VIVADO
24// Using data_latch directly is OK by Vivado, but simulation shows
25// that doing so markedly reduces the available throughput.
26assign data_pipe = data_latch;
27`else
28// Vivado complains bitterly about this version, calling it
29// CDC-4 Critical. See UG906 for discussion.
30reg_tech_cdc #(.POST_STAGES(0)) rtc[size-1:0] (.C(clk_out),
31 .I(data_latch), .O(data_pipe));
32`endif
33
34// CDC-15 Warning Clock enable controlled CDC structure detected
35// "The CDC engine only checks that [CE] is [valid in clk_out].
36// Also, you are responsible for constraining the latency from the
37// [clk_in] domain to [clk_out latch input], which is usually done
38// by a set_max_delay -datapath_only constraint."
39reg [size-1:0] data_out_r=0;
40reg gate_out_r=0;
41always @(posedge clk_out) begin
42 if (gate_x) data_out_r <= data_pipe;
43 gate_out_r <= gate_x;
44end
45assign data_out = data_out_r;
46assign gate_out = gate_out_r;
47
48endmodule