1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/*
* delay.v
*
* Generates a delay line/bus using a combination of SRL and Register
*
* Copyright (C) 2014 Ettus Corporation LLC
* Copyright 2018 Ettus Research, a National Instruments Company
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* vim: ts=4 sw=4
*/
`ifdef SIM
`default_nettype none
`endif
// ---------------------------------------------------------------------------
// Single line delay
// ---------------------------------------------------------------------------
module delay_bit #(
parameter integer DELAY = 1
)(
input wire d,
output wire q,
input wire clk
);
// Signals
wire [4:0] addr = DELAY - 2;
wire ff_in;
// Generate SRL if needed (or bypass if not)
generate
if (DELAY > 17) begin
SRLC32E srl_I (
.Q(ff_in),
.A(addr),
.CE(1'b1),
.CLK(clk),
.D(d)
);
end else if (DELAY > 1) begin
SRL16E srl_I (
.Q(ff_in),
.A0(addr[0]),
.A1(addr[1]),
.A2(addr[2]),
.A3(addr[3]),
.CE(1'b1),
.CLK(clk),
.D(d)
);
end else begin
assign ff_in = d;
end
endgenerate
// Generate flip-flop if needed (or bypass if not)
generate
if (DELAY > 0) begin
FDRE ff_I (
.Q(q),
.C(clk),
.CE(1'b1),
.D(ff_in),
.R(1'b0)
);
end else begin
assign q = ff_in;
end
endgenerate
endmodule // delay_bit
// ---------------------------------------------------------------------------
// Bus delay
// ---------------------------------------------------------------------------
module delay_bus #(
parameter integer DELAY = 1,
parameter integer WIDTH = 1
)(
input wire [WIDTH-1:0] d,
output wire [WIDTH-1:0] q,
input wire clk
);
genvar i;
// Variables / Signals
wire [4:0] addr = DELAY - 2;
wire [WIDTH-1:0] ff_in;
// Generate SRL if needed (or bypass if not)
generate
if (DELAY > 17) begin
for (i=0; i<WIDTH; i=i+1)
SRLC32E srl_I (
.Q(ff_in[i]),
.A(addr),
.CE(1'b1),
.CLK(clk),
.D(d[i])
);
end else if (DELAY > 1) begin
for (i=0; i<WIDTH; i=i+1)
SRL16E srl_I (
.Q(ff_in[i]),
.A0(addr[0]),
.A1(addr[1]),
.A2(addr[2]),
.A3(addr[3]),
.CE(1'b1),
.CLK(clk),
.D(d[i])
);
end else begin
assign ff_in = d;
end
endgenerate
// Generate flip-flop if needed (or bypass if not)
generate
if (DELAY > 0) begin
for (i=0; i<WIDTH; i=i+1)
FDRE ff_I (
.Q(q[i]),
.C(clk),
.CE(1'b1),
.D(ff_in[i]),
.R(1'b0)
);
end else begin
assign q = ff_in;
end
endgenerate
endmodule // delay_bus
|