OpenCores
URL https://opencores.org/ocsvn/pci/pci/trunk

Subversion Repositories pci

[/] [pci/] [tags/] [rel_00/] [rtl/] [verilog/] [delayed_sync.v] - Blame information for rev 33

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "delayed_sync.v"                                  ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Miha Dolenc (mihad@opencores.org)                     ////
10
////                                                              ////
11
////  All additional information is avaliable in the README       ////
12
////  file.                                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org          ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
//
42
// CVS Revision History
43
//
44
// $Log: not supported by cvs2svn $
45 33 mihad
// Revision 1.3  2002/02/01 15:25:12  mihad
46
// Repaired a few bugs, updated specification, added test bench files and design document
47
//
48 21 mihad
// Revision 1.2  2001/10/05 08:14:28  mihad
49
// Updated all files with inclusion of timescale file for simulation purposes.
50
//
51 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:46  mihad
52
// New project directory structure
53 2 mihad
//
54 6 mihad
//
55 2 mihad
 
56
// module provides synchronization mechanism between requesting and completing side of the bridge
57 21 mihad
`include "pci_constants.v"
58 2 mihad
`include "bus_commands.v"
59 21 mihad
 
60
// synopsys translate_off
61 6 mihad
`include "timescale.v"
62 21 mihad
// synopsys translate_on
63
 
64 2 mihad
module DELAYED_SYNC
65
(
66
    reset_in,
67
    req_clk_in,
68
    comp_clk_in,
69
    req_in,
70
    comp_in,
71
    done_in,
72
    in_progress_in,
73
    comp_req_pending_out,
74
    req_req_pending_out,
75
    req_comp_pending_out,
76
    comp_comp_pending_out,
77
    addr_in,
78 21 mihad
    be_in,
79 2 mihad
    addr_out,
80 21 mihad
    be_out,
81 2 mihad
    we_in,
82
    we_out,
83
    bc_in,
84
    bc_out,
85
    status_in,
86
    status_out,
87
    comp_flush_out,
88
    burst_in,
89
    burst_out,
90
    retry_expired_in
91
);
92
 
93
// system inputs
94
input reset_in,         // reset input
95
      req_clk_in,       // requesting clock input
96
      comp_clk_in ;     // completing clock input
97
 
98
// request, completion, done and in progress indication inputs
99
input req_in,           // request qualifier - when 1 it indicates that valid request data is provided on inputs
100
      comp_in,          // completion qualifier - when 1, completing side indicates that request has completed
101
      done_in,          // done input - when 1 indicates that requesting side of the bridge has completed a transaction on requesting bus
102
      in_progress_in ;  // in progress indicator - indicates that current completion is in progress on requesting side of the bridge
103
 
104
// pending indication outputs
105
output  comp_req_pending_out,   // completion side request output - resynchronized from requesting clock to completing clock
106
        req_req_pending_out,    // request pending output for requesting side
107
        req_comp_pending_out,   // completion pending output for requesting side of the bridge - it indicates when completion is ready for completing on requesting bus
108
        comp_comp_pending_out ; // completion pending output for completing side of the bridge
109
 
110
// additional signals and wires for clock domain passage of signals
111 21 mihad
reg     comp_req_pending,
112
        req_req_pending,
113
        req_comp_pending,
114
        req_comp_pending_sample,
115 2 mihad
        comp_comp_pending,
116
        req_done_reg,
117
        comp_done_reg_main,
118
        comp_done_reg_clr,
119
        req_rty_exp_reg,
120
        req_rty_exp_clr,
121
        comp_rty_exp_reg,
122
        comp_rty_exp_clr ;
123
 
124 21 mihad
wire    sync_comp_req_pending,
125 2 mihad
        sync_req_comp_pending,
126
        sync_comp_done,
127
        sync_req_rty_exp,
128 21 mihad
        sync_comp_rty_exp_clr ;
129 2 mihad
 
130
// inputs from requesting side - only this side can set address, bus command, byte enables, write enable and burst - outputs are common for both sides
131
// all signals that identify requests are stored in this module
132
 
133
input [31:0]    addr_in ;   // address bus input
134
input [3:0]     be_in ;     // byte enable input
135
input           we_in ;     // write enable input - read/write request indication 1 = write request / 0 = read request
136
input [3:0]     bc_in ;     // bus command input
137
input           burst_in ;  // burst indicator    - qualifies operation as burst/single transfer 1 = burst / 0 = single transfer
138
 
139
// common request outputs used both by completing and requesting sides
140
// this outputs are not resynchronized, since flags determine the request status
141
output [31:0]   addr_out ;
142
output [3:0]    be_out ;
143
output          we_out ;
144
output [3:0]    bc_out ;
145
output          burst_out ;
146
 
147
// completion side signals encoded termination status - 0 = normal completion / 1 = error terminated completion
148 21 mihad
input          status_in ;
149 2 mihad
output         status_out ;
150
 
151
// input signals that delayed transaction has been retried for max number of times
152
// on this signal request is ditched, otherwise it would cause a deadlock
153 21 mihad
// requestor can issue another request and procedure will be repeated
154 2 mihad
input   retry_expired_in ;
155
 
156
// completion flush output - if in 2^^16 clock cycles transaction is not repeated by requesting agent - flush completion data
157
output  comp_flush_out ;
158
 
159
// output registers for common signals
160
reg [31:0]   addr_out ;
161
reg [3:0]    be_out ;
162
reg          we_out ;
163
reg [3:0]    bc_out ;
164
reg          burst_out ;
165
 
166
// delayed transaction information is stored only when request is issued and request nor completion are pending
167
wire new_request = req_in && ~req_comp_pending_out && ~req_req_pending_out ;
168
always@(posedge req_clk_in or posedge reset_in)
169
begin
170
    if (reset_in)
171
    begin
172
        addr_out  <= #`FF_DELAY 32'h0000_0000 ;
173
        be_out    <= #`FF_DELAY 4'h0 ;
174
        we_out    <= #`FF_DELAY 1'b0 ;
175
        bc_out    <= #`FF_DELAY `BC_RESERVED0 ;
176
        burst_out <= #`FF_DELAY 1'b0 ;
177
    end
178
    else
179
        if (new_request)
180
        begin
181
            addr_out  <= #`FF_DELAY addr_in ;
182
            be_out    <= #`FF_DELAY be_in ;
183
            we_out    <= #`FF_DELAY we_in ;
184
            bc_out    <= #`FF_DELAY bc_in ;
185
            burst_out <= #`FF_DELAY burst_in ;
186
        end
187
end
188
 
189
// completion pending cycle counter
190
reg [16:0] comp_cycle_count ;
191
 
192
/*=================================================================================================================================
193
Passing of requests between clock domains:
194
request originates on requesting side. It's then synchronized with two flip-flops to cross to completing clock domain
195
=================================================================================================================================*/
196
// main request flip-flop triggered on requesting side's clock
197
// request is cleared whenever completion or retry expired is signalled from opposite side of the bridge
198
wire req_req_clear = req_comp_pending || (req_rty_exp_reg && ~req_rty_exp_clr) ;
199
always@(posedge req_clk_in or posedge reset_in)
200
begin
201
    if ( reset_in )
202
        req_req_pending <= #`FF_DELAY 1'b0 ;
203 21 mihad
    else
204 2 mihad
    if ( req_req_clear )
205
        req_req_pending <= #`FF_DELAY 1'b0 ;
206 21 mihad
    else
207 2 mihad
    if ( req_in )
208
        req_req_pending <= #`FF_DELAY 1'b1 ;
209
end
210
 
211
// interemediate stage request synchronization flip - flop - this one is prone to metastability
212
// and should have setup and hold times disabled during simulation
213
synchronizer_flop req_sync
214
(
215 21 mihad
    .data_in        (req_req_pending),
216
    .clk_out        (comp_clk_in),
217
    .sync_data_out  (sync_comp_req_pending),
218 2 mihad
    .async_reset    (reset_in)
219
) ;
220
 
221
// wire for clearing completion side request flag - whenever completion or retry expired are signalled
222
wire comp_req_pending_clear = comp_req_pending && ( comp_in || retry_expired_in) ;
223
 
224
// wire for enabling request flip - flop - it is enabled when completion is not active and done is not active
225
wire comp_req_pending_ena   = ~comp_comp_pending && ~comp_done_reg_main && ~comp_rty_exp_reg ;
226
 
227
// completion side request flip flop - gets a value from intermediate stage sync flip flop
228
always@(posedge comp_clk_in or posedge reset_in)
229
begin
230
    if ( reset_in )
231
        comp_req_pending <= #`FF_DELAY 1'b0 ;
232
    else
233
    if ( comp_req_pending_clear )
234
        comp_req_pending <= #`FF_DELAY 1'b0 ;
235
    else
236
    if ( comp_req_pending_ena )
237
        comp_req_pending <= #`FF_DELAY sync_comp_req_pending ;
238
end
239
 
240
// completion side request output assignment - when request ff is set and completion ff is not set
241
assign comp_req_pending_out = comp_req_pending ;
242
 
243
// requesting side request pending output
244
assign req_req_pending_out  = req_req_pending ;
245
/*=================================================================================================================================
246
Passing of completions between clock domains:
247
completion originates on completing side. It's then synchronized with two flip-flops to cross to requesting clock domain
248
=================================================================================================================================*/
249
// main completion Flip - Flop - triggered by completing side's clock
250
// completion side completion pending flag is cleared when done flag propagates through clock domains
251
wire comp_comp_clear = comp_done_reg_main && ~comp_done_reg_clr ;
252
always@(posedge comp_clk_in or posedge reset_in)
253
begin
254
    if ( reset_in )
255
        comp_comp_pending <= #`FF_DELAY 1'b0 ;
256
    else
257
    if ( comp_comp_clear )
258
        comp_comp_pending <= #`FF_DELAY 1'b0 ;
259
    else
260
    if ( comp_in && comp_req_pending )
261
        comp_comp_pending <= #`FF_DELAY 1'b1 ;
262
end
263
 
264
assign comp_comp_pending_out = comp_comp_pending ;
265
 
266
// interemediate stage completion synchronization flip - flop - this one is prone to metastability
267
synchronizer_flop comp_sync
268
(
269 21 mihad
    .data_in        (comp_comp_pending),
270
    .clk_out        (req_clk_in),
271
    .sync_data_out  (sync_req_comp_pending),
272 2 mihad
    .async_reset    (reset_in)
273
) ;
274
 
275
// request side completion pending flip flop is cleared whenever done is signalled or completion counter expires - 2^^16 clock cycles
276
wire req_comp_pending_clear = done_in || comp_cycle_count[16];
277
 
278
// request side completion pending flip flop is disabled while done flag is set
279
wire req_comp_pending_ena   = ~req_done_reg ;
280
 
281
// request side completion flip flop - gets a value from intermediate stage sync flip flop
282
always@(posedge req_clk_in or posedge reset_in)
283
begin
284
    if ( reset_in )
285
        req_comp_pending <= #`FF_DELAY 1'b0 ;
286
    else
287
    if ( req_comp_pending_clear )
288
        req_comp_pending <= #`FF_DELAY 1'b0 ;
289
    else
290
    if ( req_comp_pending_ena )
291
        req_comp_pending <= #`FF_DELAY sync_req_comp_pending ;
292
end
293
 
294
// sampling FF - used for sampling incoming completion flag from completing side
295
always@(posedge req_clk_in or posedge reset_in)
296
begin
297
    if ( reset_in )
298
        req_comp_pending_sample <= #`FF_DELAY 1'b0 ;
299
    else
300
        req_comp_pending_sample <= #`FF_DELAY sync_req_comp_pending ;
301
end
302
 
303
// requesting side completion pending output assignment
304
assign req_comp_pending_out = req_comp_pending && ~req_req_pending ;
305
 
306
/*==================================================================================================================================
307
Passing of delayed transaction done signal between clock domains.
308
Done is signalled by requesting side of the bridge and is passed to completing side of the bridge
309
==================================================================================================================================*/
310
// main done flip-flop triggered on requesting side's clock
311
// when completing side removes completion flag, done flag is also removed, so requests can proceede
312
wire req_done_clear = ~req_comp_pending_sample ;
313
always@(posedge req_clk_in or posedge reset_in)
314
begin
315
    if ( reset_in )
316
        req_done_reg <= #`FF_DELAY 1'b0 ;
317
    else
318
    if ( req_done_clear )
319
        req_done_reg <= #`FF_DELAY 1'b0 ;
320
    else
321
    if ( done_in || comp_cycle_count[16] )
322
        req_done_reg <= #`FF_DELAY 1'b1 ;
323
end
324
 
325
synchronizer_flop done_sync
326
(
327 21 mihad
    .data_in        (req_done_reg),
328
    .clk_out        (comp_clk_in),
329
    .sync_data_out  (sync_comp_done),
330 2 mihad
    .async_reset    (reset_in)
331
) ;
332
 
333
always@(posedge comp_clk_in or posedge reset_in)
334
begin
335
    if ( reset_in )
336
        comp_done_reg_main <= #`FF_DELAY 1'b0 ;
337
    else
338
        comp_done_reg_main <= #`FF_DELAY sync_comp_done ;
339
end
340
 
341
always@(posedge comp_clk_in or posedge reset_in)
342
begin
343
    if ( reset_in )
344
        comp_done_reg_clr <= #`FF_DELAY 1'b0 ;
345
    else
346
        comp_done_reg_clr <= #`FF_DELAY comp_done_reg_main ;
347
end
348
 
349
/*=================================================================================================================================
350
Passing of retry expired signal between clock domains
351
Retry expiration originates on completing side. It's then synchronized with two flip-flops to cross to requesting clock domain
352
=================================================================================================================================*/
353
// main retry expired Flip - Flop - triggered by completing side's clock
354
wire comp_rty_exp_clear = comp_rty_exp_clr && comp_rty_exp_reg ;
355
 
356
// retry expired is a special case of transaction removal - retry expired propagates from completing
357
// clock domain to requesting clock domain to remove all pending requests and than propagates back
358
// to completing side to qualify valid new requests
359
 
360
always@(posedge comp_clk_in or posedge reset_in)
361
begin
362
    if ( reset_in )
363
        comp_rty_exp_reg <= #`FF_DELAY 1'b0 ;
364
    else
365
    if ( comp_rty_exp_clear )
366
        comp_rty_exp_reg <= #`FF_DELAY 1'b0 ;
367
    else
368
    if ( retry_expired_in && comp_req_pending)
369
        comp_rty_exp_reg <= #`FF_DELAY 1'b1 ;
370
end
371
 
372
// interemediate stage retry expired synchronization flip - flop - this one is prone to metastability
373
synchronizer_flop rty_exp_sync
374
(
375 21 mihad
    .data_in        (comp_rty_exp_reg),
376
    .clk_out        (req_clk_in),
377
    .sync_data_out  (sync_req_rty_exp),
378 2 mihad
    .async_reset    (reset_in)
379
) ;
380
 
381
// request retry expired flip flop - gets a value from intermediate stage sync flip flop
382
always@(posedge req_clk_in or posedge reset_in)
383
begin
384
    if ( reset_in )
385
        req_rty_exp_reg <= #`FF_DELAY 1'b0 ;
386
    else
387
        req_rty_exp_reg <= #`FF_DELAY sync_req_rty_exp ;
388
end
389
 
390
always@(posedge req_clk_in or posedge reset_in)
391
begin
392
    if ( reset_in )
393
        req_rty_exp_clr <= #`FF_DELAY 1'b0 ;
394
    else
395
        req_rty_exp_clr <= #`FF_DELAY req_rty_exp_reg ;
396
end
397
 
398
synchronizer_flop rty_exp_back_prop_sync
399
(
400 33 mihad
    .data_in        (req_rty_exp_reg && req_rty_exp_clr),
401 21 mihad
    .clk_out        (comp_clk_in),
402
    .sync_data_out  (sync_comp_rty_exp_clr),
403 2 mihad
    .async_reset    (reset_in)
404
) ;
405
 
406
always@(posedge comp_clk_in or posedge reset_in)
407
begin
408
    if ( reset_in )
409
        comp_rty_exp_clr <= #`FF_DELAY 1'b0 ;
410
    else
411
        comp_rty_exp_clr <= #`FF_DELAY sync_comp_rty_exp_clr ;
412
end
413
 
414
// completion status flip flop - if 0 when completion is signalled it's finished OK otherwise it means error
415
reg status_out ;
416 21 mihad
always@(posedge comp_clk_in or posedge reset_in)
417 2 mihad
begin
418
    if (reset_in)
419
        status_out <= #`FF_DELAY 1'b0 ;
420
    else
421
    if (comp_in && comp_req_pending)
422
        status_out <= #`FF_DELAY status_in ;
423
end
424
 
425
// clocks counter - it counts how many clock cycles completion is present without beeing repeated
426
// if it counts to 2^^16 cycles the completion must be ditched
427
 
428
// wire for clearing this counter
429
wire clear_count = in_progress_in || ~req_comp_pending_out ;
430
always@(posedge req_clk_in or posedge reset_in)
431
begin
432
    if (reset_in)
433
        comp_cycle_count <= #`FF_DELAY 17'h0_0000 ;
434
    else
435
    if (clear_count)
436
        comp_cycle_count <= #`FF_DELAY 17'h0_0000 ;
437
    else
438
        comp_cycle_count <= #`FF_DELAY comp_cycle_count + 1'b1 ;
439
end
440
 
441
// completion flush output - used for flushing fifos when counter expires
442
// if counter doesn't expire, fifo flush is up to WISHBONE slave or PCI target state machines
443
reg comp_flush_out ;
444
always@(posedge req_clk_in or posedge reset_in)
445
begin
446
    if (reset_in)
447
        comp_flush_out <= #`FF_DELAY 1'b0 ;
448
    else
449
        comp_flush_out <= #`FF_DELAY comp_cycle_count[16] ;
450
end
451
 
452
endmodule //delayed_sync

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.