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 2

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

powered by: WebSVN 2.1.0

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