-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtfrstb.v
304 lines (276 loc) · 7.29 KB
/
tfrstb.v
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
////////////////////////////////////////////////////////////////////////////////
//
// Filename: rtl/hdmi/tfrstb.v
// {{{
// Project: 10Gb Ethernet switch
//
// Purpose: Illustrates a slow method of moving data across clock domains,
// together with a formal proof of the same. This is the "faster"
// version of two methods, the second one given in tfrslow.v. This one
// is faster because it requires only a single round trip of the request
// and the acknowledgement.
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2023-2024, Gisselquist Technology, LLC
// {{{
// This file is part of the ETH10G project.
//
// The ETH10G project contains free software and gateware, licensed under the
// terms of the 3rd version of the GNU General Public License as published by
// the Free Software Foundation.
//
// This project is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. (It's in the $(ROOT)/doc directory. Run make with no
// target there if the PDF file isn't present.) If not, see
// <http://www.gnu.org/licenses/> for a copy.
// }}}
// License: GPL, v3, as defined and found on www.gnu.org,
// {{{
// http://www.gnu.org/licenses/gpl.html
//
////////////////////////////////////////////////////////////////////////////////
//
`default_nettype none
// }}}
module tfrstb (
// {{{
input wire i_a_clk,
input wire i_a_reset_n,
input wire i_a_valid,
output wire o_a_ready,
//
input wire i_b_clk,
input wire i_b_reset_n,
output reg o_b_valid,
input wire i_b_ready
// }}}
);
// Register declarations
// {{{
localparam NFF = 2;
reg a_req, a_ack;
reg [NFF-2:0] a_pipe;
reg b_req, b_last, b_stb;
reg [NFF-2:0] b_pipe;
// }}}
// Launch
// {{{
initial a_req = 0;
always @(posedge i_a_clk, negedge i_a_reset_n)
if (!i_a_reset_n)
a_req <= 1'b0;
else if (i_a_valid && o_a_ready)
a_req <= !a_req;
// }}}
// Request to B
// {{{
initial { b_last, b_req, b_pipe } = 0;
always @(posedge i_b_clk, negedge i_b_reset_n)
if (!i_b_reset_n)
{ b_last, b_req, b_pipe } <= 0;
else begin
{ b_last, b_req, b_pipe } <= { b_req, b_pipe, a_req };
if (o_b_valid && !i_b_ready)
b_last <= b_last;
end
// }}}
// Return ACK
// {{{
always @(posedge i_a_clk, negedge i_a_reset_n)
if (!i_a_reset_n)
{ a_ack, a_pipe } <= 2'b0;
else
{ a_ack, a_pipe } <= { a_pipe, b_last };
// }}}
// Return ready
assign o_a_ready = (a_ack == a_req);
// Outgoing strobe and data
// {{{
always @(*)
b_stb = (b_last != b_req);
initial o_b_valid = 0;
always @(posedge i_b_clk, negedge i_b_reset_n)
if (!i_b_reset_n)
o_b_valid <= 1'b0;
else if (!o_b_valid || i_b_ready)
o_b_valid <= b_stb;
// }}}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Formal properties
// {{{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
`ifdef FORMAL
// Define our registers, and f_past_valid_*
// {{{
(* gclk *) reg gbl_clk;
reg f_past_valid_gbl, f_past_valid_a,
f_past_valid_b;
localparam LGCLK = 5;
(* anyconst *) reg [LGCLK-2:0] f_step_a, f_step_b;
reg [LGCLK-1:0] f_count_a, f_count_b;
initial f_past_valid_gbl = 0;
always @(posedge gbl_clk)
f_past_valid_gbl <= 1;
initial f_past_valid_a = 0;
always @(posedge i_a_clk)
f_past_valid_a <= 1;
initial f_past_valid_b = 0;
always @(posedge i_b_clk)
f_past_valid_b <= 1;
// }}}
////////////////////////////////////////////////////////////////////////
//
// Assume two clocks
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(posedge gbl_clk)
begin
f_count_a <= f_count_a + { 1'b0, f_step_a } + 1;
f_count_b <= f_count_b + { 1'b0, f_step_b } + 1;
end
always @(*)
assume(i_a_clk == f_count_a[LGCLK-1]);
always @(*)
assume(i_b_clk == f_count_b[LGCLK-1]);
// }}}
////////////////////////////////////////////////////////////////////////
//
// Reset assumptions
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// Start in reset
always @(*)
if (!f_past_valid_gbl)
assume(!i_a_reset_n && !i_b_reset_n);
// Both resets will always fall together
always @(posedge gbl_clk)
assume($fell(i_b_reset_n) == $fell(i_a_reset_n));
// }}}
////////////////////////////////////////////////////////////////////////
//
// Stability properties
// {{{
////////////////////////////////////////////////////////////////////////
//
//
//
// On clock A
// {{{
always @(posedge gbl_clk)
if (!$rose(i_a_clk))
begin
assume(!$rose(i_a_reset_n));
assume($stable(i_a_valid));
if (i_a_reset_n)
assert($stable(o_a_ready));
end
// }}}
//
// On clock B
// {{{
always @(posedge gbl_clk)
if (!$rose(i_b_clk))
begin
assume(!$rose(i_b_reset_n));
if (i_b_reset_n)
assume($stable(i_b_ready));
if (f_past_valid_b && i_b_reset_n && $stable(i_b_reset_n))
begin
assert($stable(o_b_valid));
end
end
// }}}
// }}}
////////////////////////////////////////////////////////////////////////
//
// AXI Stream properties
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(posedge i_a_clk)
if (!f_past_valid_a || !i_a_reset_n)
assume(!i_a_valid);
else if ($past(i_a_valid && !o_a_ready))
begin
assume(i_a_valid);
end
always @(posedge i_b_clk)
if (!f_past_valid_b || !i_b_reset_n)
assert(!o_b_valid);
else if ($past(o_b_valid && !i_b_ready))
begin
assert(o_b_valid);
end
// }}}
////////////////////////////////////////////////////////////////////////
//
// Induction
// {{{
////////////////////////////////////////////////////////////////////////
//
//
always @(posedge gbl_clk)
case({ a_ack, a_pipe, b_last, b_req, b_pipe, a_req })
6'b000_000: begin end
6'b000_001: begin end
6'b000_011: begin end
6'b000_111: begin end
6'b001_111: begin end
6'b011_111: begin end
6'b111_111: begin end
6'b111_110: begin end
6'b111_100: begin end
6'b111_000: begin end
6'b110_000: begin end
6'b100_000: begin end
6'b000_000: begin end
default: assert(0);
endcase
// }}}
////////////////////////////////////////////////////////////////////////
//
// Cover checks
// {{{
////////////////////////////////////////////////////////////////////////
//
//
reg [3:0] cvr_stbcount;
initial cvr_stbcount <= 0;
always @(posedge i_b_clk, negedge i_b_reset_n)
if (!i_b_reset_n)
cvr_stbcount <= 0;
else if (o_b_valid && i_b_ready)
cvr_stbcount <= cvr_stbcount + 1;
always @(*)
begin
cover(cvr_stbcount == 1);
cover(cvr_stbcount == 2);
cover(cvr_stbcount == 3);
cover(cvr_stbcount == 4);
cover(cvr_stbcount == 5);
//
// These next two take too much CPU time, so we don't insist
// upon them here.
// cover(cvr_stbcount == 6);
// cover(cvr_stbcount[3]);
end
// }}}
`endif
// }}}
endmodule