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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_6/] [rtl/] [verilog/] [pci_delayed_sync.v] - Blame information for rev 154

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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