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
22`ifdef HAPPY_VIVADO
23// Using data_latch directly is OK by Vivado, but simulation shows
24// that doing so markedly reduces the available throughput.
25wire [size-1:0] data_pipe = data_latch;
26`else
27// Vivado complains bitterly about this version, calling it
28// CDC-4 Critical.  See UG906 for discussion.
29(* ASYNC_REG = "TRUE" *) reg [size-1:0] data_pipe=0;
30always @(posedge clk_out) data_pipe <= data_latch;
31`endif
32
33// CDC-15  Warning  Clock enable controlled CDC structure detected
34// "The CDC engine only checks that [CE] is [valid in clk_out].
35// Also, you are responsible for constraining the latency from the
36// [clk_in] domain to [clk_out latch input], which is usually done
37// by a set_max_delay -datapath_only constraint."
38reg [size-1:0] data_out_r=0;
39reg gate_out_r=0;
40always @(posedge clk_out) begin
41     if (gate_x) data_out_r <= data_pipe;
42     gate_out_r <= gate_x;
43end
44assign data_out = data_out_r;
45assign gate_out = gate_out_r;
46
47endmodule