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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_7/] [rtl/] [verilog/] [pci_delayed_sync.v] - Blame information for rev 77

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

powered by: WebSVN 2.1.0

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