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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_10/] [rtl/] [verilog/] [pci_wb_slave.v] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 77 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "wb_slave.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 113 simons
// Revision 1.2  2003/08/03 18:05:06  mihad
46
// Added limited WISHBONE B3 support for WISHBONE Slave Unit.
47
// Doesn't support full speed bursts yet.
48
//
49 106 mihad
// Revision 1.1  2003/01/27 16:49:31  mihad
50
// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
51
//
52 77 mihad
// Revision 1.4  2002/08/19 16:54:25  mihad
53
// Got rid of undef directives
54
//
55
// Revision 1.3  2002/02/01 15:25:13  mihad
56
// Repaired a few bugs, updated specification, added test bench files and design document
57
//
58
// Revision 1.2  2001/10/05 08:14:30  mihad
59
// Updated all files with inclusion of timescale file for simulation purposes.
60
//
61
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
62
// New project directory structure
63
//
64
//
65
 
66
`include "bus_commands.v"
67
`include "pci_constants.v"
68
 
69
// synopsys translate_off
70
`include "timescale.v"
71
// synopsys translate_on
72
 
73
module pci_wb_slave
74
               (    wb_clock_in,
75
                    reset_in,
76
                    wb_hit_in,
77
                    wb_conf_hit_in,
78
                    wb_map_in,
79
                    wb_pref_en_in,
80
                    wb_mrl_en_in,
81
                    wb_addr_in,
82
                    del_bc_in,
83
                    wb_del_req_pending_in,
84
                    wb_del_comp_pending_in,
85
                    pci_drcomp_pending_in,
86
                    del_bc_out,
87
                    del_req_out,
88
                    del_done_out,
89
                    del_burst_out,
90
                    del_write_out,
91
                    del_write_in,
92
                    del_error_in,
93
                    del_in_progress_out,
94
                    ccyc_addr_in,
95
                    wb_del_addr_in,
96
                    wb_del_be_in,
97
                    wb_conf_offset_out,
98
                    wb_conf_renable_out,
99
                    wb_conf_wenable_out,
100
                    wb_conf_be_out,
101
                    wb_conf_data_in,
102
                    wb_conf_data_out,
103
                    wb_data_out,
104
                    wb_cbe_out,
105
                    wbw_fifo_wenable_out,
106
                    wbw_fifo_control_out,
107
                    wbw_fifo_almost_full_in,
108
                    wbw_fifo_full_in,
109
                    wbr_fifo_renable_out,
110
                    wbr_fifo_be_in,
111
                    wbr_fifo_data_in,
112
                    wbr_fifo_control_in,
113
                    wbr_fifo_flush_out,
114
                    wbr_fifo_empty_in,
115
                    pciw_fifo_empty_in,
116
                    wbs_lock_in,
117
                    cache_line_size_not_zero,
118
                    sample_address_out,
119
                    CYC_I,
120
                    STB_I,
121
                    WE_I,
122
                    SEL_I,
123
                    SDATA_I,
124
                    SDATA_O,
125
                    ACK_O,
126
                    RTY_O,
127
                    ERR_O,
128
                    CAB_I
129
                );
130
 
131
/*----------------------------------------------------------------------------------------------------------------------
132
Various parameters needed for state machine and other stuff
133
----------------------------------------------------------------------------------------------------------------------*/
134
parameter WBR_SEL  = 1'b0 ;
135
parameter CONF_SEL = 1'b1 ;
136
 
137
`define FSM_BITS 3
138
parameter S_IDLE         = `FSM_BITS'h0 ;
139
parameter S_DEC1         = `FSM_BITS'h1 ;
140
parameter S_DEC2         = `FSM_BITS'h2 ;
141
parameter S_START        = `FSM_BITS'h3 ;
142
parameter S_W_ADDR_DATA  = `FSM_BITS'h4 ;
143
parameter S_READ         = `FSM_BITS'h5 ;
144
parameter S_CONF_WRITE   = `FSM_BITS'h6 ;
145
parameter S_CONF_READ    = `FSM_BITS'h7 ;
146
 
147
/*----------------------------------------------------------------------------------------------------------------------
148
System signals inputs
149
wb_clock_in - WISHBONE bus clock input
150
reset_in    - system reset input controlled by bridge's reset logic
151
----------------------------------------------------------------------------------------------------------------------*/
152
input wb_clock_in, reset_in ;
153
 
154
/*----------------------------------------------------------------------------------------------------------------------
155
Inputs from address decoding logic
156
wb_hit_in - Decoder logic indicates if address is in a range of one of images
157
wb_conf_hit_in - Decoder logic indicates that address is in configuration space range
158
wb_map_in   - Decoder logic provides information about image mapping - memory mapped image   - wb_map_in = 0
159
                                                                       IO space mapped image - wb_map_in = 1
160
wb_pref_en_in - Prefetch enable signal from currently selected image - used for PCI bus command usage
161
wb_addr_in - Address already transalted from WB bus to PCI bus input
162
wb_mrl_en_in - Memory read line enable input for each image
163
----------------------------------------------------------------------------------------------------------------------*/
164
input [4:0]     wb_hit_in ;         // hit indicators
165
input           wb_conf_hit_in ;    // configuration hit indicator
166
input [4:0]     wb_pref_en_in ;     // prefetch enable from all images
167
input [4:0]     wb_mrl_en_in ;      // Memory Read line command enable from images
168
input [4:0]     wb_map_in ;         // address space mapping indicators - 1 memory space mapping, 0-IO space mapping
169
input [31:0]    wb_addr_in ;        // Translated address input
170
 
171
/*----------------------------------------------------------------------------------------------------------------------
172
Delayed transaction control inputs and outputs:
173
Used for locking particular accesses when delayed transactions are in progress:
174
wb_del_addr_in - delayed transaction address input - when completion is ready it's used for transaction decoding
175
wb_del_be_in   - delayed transaction byte enable input - when completion is ready it's used for transaction decoding
176
----------------------------------------------------------------------------------------------------------------------*/
177
input  [31:0] wb_del_addr_in ;
178
input  [3:0]  wb_del_be_in ;
179
 
180
input [3:0] del_bc_in ;           // delayed request bus command used
181
input       wb_del_req_pending_in ;   // delayed request pending indicator
182
input       wb_del_comp_pending_in ;  // delayed completion pending indicator
183
input       pci_drcomp_pending_in ; // PCI initiated delayed read completion pending
184
 
185
output [3:0] del_bc_out ; // delayed transaction bus command output
186
 
187
output del_req_out ; // output for issuing delayed transaction requests
188
 
189
output del_done_out ; // output indicating current delayed completion finished on WISHBONE bus
190
 
191
output del_burst_out ; // delayed burst transaction indicator
192
 
193
output del_in_progress_out ; // delayed in progress indicator - since delayed transaction can be a burst transaction, progress indicator must be used for proper operation
194
 
195
output del_write_out ;   // write enable for delayed transaction - used for indicating that transaction is a write
196
 
197
input  del_write_in ;    // indicates that current delayed completion is from a write request
198
input  del_error_in ;    // indicate that delayed request terminated with an error - used for write requests
199
 
200
input  [31:0] ccyc_addr_in ; // configuration cycle address input - it's separate from other addresses, since it is stored separately and decoded for type 0 configuration access
201
 
202
/*----------------------------------------------------------------------------------------------------------------------
203
Configuration space access control and data signals
204
wb_conf_offset_out  - lower 12 bits of address input provided for register offset
205
wb_conf_renable     - read enable signal for configuration space accesses
206
wb_conf_wenable     - write enable signal for configuration space accesses
207
wb_conf_be_out      - byte enable signals for configuration space accesses
208
wb_conf_data_in     - data from configuration space
209
wb_conf_data_in     - data provided for configuration space
210
----------------------------------------------------------------------------------------------------------------------*/
211
output [11:0]   wb_conf_offset_out ;  // register offset output
212
output          wb_conf_renable_out,  // configuration read and write enable outputs
213
                wb_conf_wenable_out ;
214
output [3:0]    wb_conf_be_out ;      // byte enable outputs for configuration space
215
input  [31:0]   wb_conf_data_in ;     // configuration data input from configuration space
216
output [31:0]   wb_conf_data_out ;    // configuration data output for configuration space
217
 
218
/*----------------------------------------------------------------------------------------------------------------------
219
Data from WISHBONE bus output to interiror of the core:
220
Data output is used for normal and configuration accesses.
221
---------------------------------------------------------------------------------------------------------------------*/
222
output [31:0] wb_data_out ;
223
 
224
/*----------------------------------------------------------------------------------------------------------------------
225
Bus command - byte enable output - during address phase of image access this bus holds information about PCI
226
bus command that should be used, during dataphases ( configuration or image access ) this bus contains inverted
227
SEL_I signals
228
---------------------------------------------------------------------------------------------------------------------*/
229
output [3:0] wb_cbe_out ;
230
 
231
/*----------------------------------------------------------------------------------------------------------------------
232
WBW_FIFO control signals used for sinking data into WBW_FIFO and status monitoring
233
---------------------------------------------------------------------------------------------------------------------*/
234
output       wbw_fifo_wenable_out ;    // write enable for WBW_FIFO output
235
output [3:0] wbw_fifo_control_out ;    // control bus output for WBW_FIFO
236
input        wbw_fifo_almost_full_in ; // almost full status indicator from WBW_FIFO
237
input        wbw_fifo_full_in ;        // full status indicator from WBW_FIFO
238
 
239
/*----------------------------------------------------------------------------------------------------------------------
240
WBR_FIFO control signals used for fetching data from WBR_FIFO and status monitoring
241
---------------------------------------------------------------------------------------------------------------------*/
242
output          wbr_fifo_renable_out ;      // WBR_FIFO read enable output
243
input   [3:0]   wbr_fifo_be_in ;            // byte enable input from WBR_FIFO
244
input   [31:0]  wbr_fifo_data_in ;          // data input from WBR_FIFO
245
input   [3:0]   wbr_fifo_control_in ;       // control bus input from WBR_FIFO
246
output          wbr_fifo_flush_out ;        // flush signal for WBR_FIFO
247
input           wbr_fifo_empty_in ;         // empty status indicator from WBR_FIFO
248
 
249
// used for transaction ordering requirements - WISHBONE read cannot complete until writes from PCI are completed
250
input           pciw_fifo_empty_in ;        // empty status indicator from PCIW_FIFO
251
 
252
/*----------------------------------------------------------------------------------------------------------------------
253
wbs_lock_in: internal signal that locks out all accesses, except delayed completions or configuration accesses.
254
( when master operation is disabled via master enable bit in configuration spacei )
255
---------------------------------------------------------------------------------------------------------------------*/
256
input           wbs_lock_in ;
257
 
258
// cache line size register must hold appropriate value to enable read bursts and special commands on PCI bus!
259
input           cache_line_size_not_zero ;
260
 
261
// state machine signals to wb_addr_mux when to sample wb address input
262
output          sample_address_out ;
263
reg             sample_address_out ;
264
 
265
/*----------------------------------------------------------------------------------------------------------------------
266
WISHBONE bus interface signals - can be connected directly to WISHBONE bus
267
---------------------------------------------------------------------------------------------------------------------*/
268
input           CYC_I ;     // cycle indicator
269
input           STB_I ;     // strobe input - input data is valid when strobe and cycle indicator are high
270
input           WE_I  ;     // write enable input - 1 - write operation, 0 - read operation
271
input   [3:0]   SEL_I ;     // Byte select inputs
272
input   [31:0]  SDATA_I ;   // WISHBONE slave interface input data bus
273
output  [31:0]  SDATA_O ;   // WISHBONE slave interface output data bus
274
output          ACK_O ;     // Acknowledge output - qualifies valid data on data output bus or received data on data input bus
275
output          RTY_O ;     // retry output - signals to WISHBONE master that cycle should be terminated and retried later
276
output          ERR_O ;     // Signals to WISHBONE master that access resulted in an error
277
input           CAB_I ;     // consecutive address burst input - indicates that master will do a serial address transfer in current cycle
278
 
279
`ifdef REGISTER_WBS_OUTPUTS
280
reg [31:0]  SDATA_O ;
281
reg         ACK_O   ;
282
reg         RTY_O   ;
283
reg         ERR_O   ;
284
 
285
reg [3:0] del_bc_out ; // delayed transaction bus command output
286
reg       del_req_out ; // output for issuing delayed transaction requests
287
reg       del_done_out ; // output indicating current delayed completion finished on WISHBONE bus
288
reg       del_burst_out ; // delayed burst transaction indicator
289
reg       del_in_progress_out ; // delayed in progress indicator - since delayed transaction can be a burst transaction, progress indicator must be used for proper operation
290
reg       del_write_out ;   // write enable for delayed transaction - used for indicating that transaction is a write
291
 
292
`ifdef HOST
293
reg          wb_conf_wenable_out ;
294
reg [31:0]   wb_conf_data_out ;    // configuration data output for configuration space
295
`endif
296
 
297
reg [3:0]  wb_conf_be_out ;      // byte enable outputs for configuration space
298
reg [31:0] wb_data_out ;
299
 
300
reg [3:0] wb_cbe_out ;
301
 
302
reg       wbw_fifo_wenable_out ;    // write enable for WBW_FIFO output
303
reg [3:0] wbw_fifo_control_out ;    // control bus output for WBW_FIFO
304
 
305
reg       wbr_fifo_renable_out ;      // WBR_FIFO read enable output
306
`endif
307
 
308
reg [(`FSM_BITS - 1):0]  c_state ; //current state register
309
 
310
reg [(`FSM_BITS - 1):0]  n_state ; //next state input to current state register
311
 
312
// state machine register control
313
always@(posedge wb_clock_in or posedge reset_in)
314
begin
315
    if (reset_in)
316
        c_state <= #`FF_DELAY S_IDLE ;
317
    else
318
        c_state <= #`FF_DELAY n_state ;
319
end
320
 
321
 
322
// variable for bus command multiplexer logic output for delayed requests
323
reg [3:0] del_bc ;
324
 
325
//register for intermediate data and select storage
326
reg [35:0] d_incoming ;
327
 
328
// enable for incoming data register
329
reg d_incoming_ena ;
330
 
331
// incoming data register control logic
332
always@(posedge wb_clock_in or posedge reset_in)
333
begin
334
    if (reset_in)
335
        d_incoming <= #`FF_DELAY {35{1'b0}} ;
336
    else if (d_incoming_ena)
337
        d_incoming <= #`FF_DELAY {SEL_I, SDATA_I} ;
338
end
339
 
340
/*===================================================================================================================================================================================
341
Write allow for image accesses. Writes through images are allowed when all of following are true:
342
- WBW_FIFO musn't be almost full nor full for image writes to be allowed - Every transaction takes at least two locations in the FIFO
343
- delayed read from from WISHBONE to PCI request musn't be present
344
- delayed read from PCI to WISHBONE completion musn't be present
345
- lock input musn't be set - it can be set because of error reporting or because PCI master state machine is disabled
346
===================================================================================================================================================================================*/
347
wire wimg_wallow           = ~|{ wbw_fifo_almost_full_in , wbw_fifo_full_in, wb_del_req_pending_in, pci_drcomp_pending_in, wbs_lock_in } ;
348
reg img_wallow ;
349
/*===================================================================================================================================================================================
350
WISHBONE slave can request an image read accesses when all of following are true:
351
- delayed completion is not present
352
- delayed request is not present
353
- operation is not locked because of error reporting mechanism or because PCI master is disabled
354
===================================================================================================================================================================================*/
355
wire wdo_del_request     = ~|{ wb_del_req_pending_in, wb_del_comp_pending_in, wbs_lock_in } ;
356
reg do_del_request ;
357
/*===================================================================================================================================================================================
358
WISHBONE slave can complete an image read accesses when all of following are true:
359
- delayed read completion is present
360
- delayed read completion is the same as current read access ( dread_completion_hit is 1 )
361
- PCI Write FIFO is empty - no posted write is waiting to be finished in PCIW_FIFO
362
- WBR_FIFO empty status is not active
363
===================================================================================================================================================================================*/
364
wire wdel_addr_hit = ( wb_del_addr_in == wb_addr_in ) && ( SEL_I == wb_del_be_in ) ;
365
reg  del_addr_hit ;
366
wire wdel_completion_allow = wb_del_comp_pending_in && ((~del_write_in && ~WE_I && pciw_fifo_empty_in && ~wbr_fifo_empty_in) || (del_write_in && WE_I)) ;
367
reg del_completion_allow ;
368
 
369
/*----------------------------------------------------------------------------------------------------------------------
370
img_hit - state of wb_hit_in bus when when state machine signals decode is over
371
---------------------------------------------------------------------------------------------------------------------*/
372
reg [4:0] img_hit ;
373
wire wb_hit = |( img_hit ) ;
374
 
375
/*----------------------------------------------------------------------------------------------------------------------
376
Control logic for image control signals
377
pref_en - prefetch enable of currently selected image
378
mrl_en  - Memory read line enable of currently selected image
379
map     - Address space mapping for currently selected image
380
---------------------------------------------------------------------------------------------------------------------*/
381
reg pref_en, mrl_en, map ;
382
wire wpref_en   = |(wb_pref_en_in & wb_hit_in) ;
383
wire wmrl_en    = |(wb_mrl_en_in & wb_hit_in) ;
384
wire wmap       = |(wb_map_in & wb_hit_in) ;
385
 
386
// state machine controls when results from decoders, comparison etc. are sampled into registers to decode an access
387
reg decode_en ;
388
 
389
reg wb_conf_hit ;
390
always@(posedge reset_in or posedge wb_clock_in)
391
begin
392
    if (reset_in)
393
    begin
394
        img_wallow           <= #`FF_DELAY 1'b0 ;
395
        wb_conf_hit          <= #`FF_DELAY 1'b0 ;
396
        do_del_request       <= #`FF_DELAY 1'b0 ;
397
        del_addr_hit         <= #`FF_DELAY 1'b0 ;
398
        del_completion_allow <= #`FF_DELAY 1'b0 ;
399
        img_hit              <= #`FF_DELAY 5'h00 ;
400
        pref_en              <= #`FF_DELAY 1'b0 ;
401
        mrl_en               <= #`FF_DELAY 1'b0 ;
402
        map                  <= #`FF_DELAY 1'b0 ;
403
    end
404
    else
405
    if (decode_en)
406
    begin
407
        img_wallow           <= #`FF_DELAY wimg_wallow ;
408
        wb_conf_hit          <= #`FF_DELAY wb_conf_hit_in ;
409
        do_del_request       <= #`FF_DELAY wdo_del_request ;
410
        del_addr_hit         <= #`FF_DELAY wdel_addr_hit ;
411
        del_completion_allow <= #`FF_DELAY wdel_completion_allow ;
412
        img_hit              <= #`FF_DELAY wb_hit_in ;
413
        pref_en              <= #`FF_DELAY wpref_en && cache_line_size_not_zero ;
414
        mrl_en               <= #`FF_DELAY wmrl_en  && cache_line_size_not_zero ;
415
        map                  <= #`FF_DELAY wmap ;
416
    end
417
end
418
 
419
wire   del_burst = CAB_I && (pref_en || mrl_en) && ~WE_I && cache_line_size_not_zero ; // delayed burst indicator - only when WB master attempts CAB transfer and cache line size register is set appropriately and
420
                                                                                       // either prefetch enable or memory read line enable of corresponding image are set -
421
                                                                                       // applies for reads only - delayed write cannot be a burst
422
wire do_dread_completion = del_completion_allow && del_addr_hit ;
423
 
424
// address allignement indicator
425
wire alligned_address = ~|(wb_addr_in[1:0]) ;
426
 
427
`ifdef GUEST
428
 
429
    // wires indicating allowance for configuration cycle generation requests
430
    wire do_ccyc_req  = 1'b0 ;
431
    wire do_ccyc_comp = 1'b0 ;
432
 
433
    // wires indicating allowance for interrupt acknowledge cycle generation requests
434
    wire do_iack_req  = 1'b0 ;
435
    wire do_iack_comp = 1'b0 ;
436
 
437
    // variables for configuration access control signals
438
    reg conf_wenable ;
439
    assign wb_conf_wenable_out = 1'b0 ;
440
 
441
    // configuration cycle data register hit
442
    wire ccyc_hit = 1'b0 ;
443
    wire iack_hit = 1'b0 ;
444
 
445
    wire wccyc_hit = 1'b0 ;
446
    wire wiack_hit = 1'b0 ;
447
 
448
`else
449
`ifdef HOST
450
    // only host implementation has access for generating interrupt acknowledge and configuration cycles
451
    // configuration cycle data register hit
452
    reg current_delayed_is_ccyc ;
453
    reg current_delayed_is_iack ;
454
 
455 113 simons
    wire wccyc_hit = (wb_addr_in[8:2] == {1'b1, `CNF_DATA_ADDR})
456
    `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
457
    `else
458
                     && alligned_address
459
    `endif
460
                     ;
461
    wire wiack_hit = (wb_addr_in[8:2] == {1'b1, `INT_ACK_ADDR})
462
    `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
463
    `else
464
                     && alligned_address
465
    `endif
466
                     ;
467 77 mihad
    reg iack_hit ;
468
    reg ccyc_hit ;
469
    always@(posedge reset_in or posedge wb_clock_in)
470
    begin
471
        if (reset_in)
472
        begin
473
            ccyc_hit <= #`FF_DELAY 1'b0 ;
474
            iack_hit <= #`FF_DELAY 1'b0 ;
475
        end
476
        else
477
        if (decode_en)
478
        begin
479
            ccyc_hit <= #`FF_DELAY wccyc_hit ;
480
            iack_hit <= #`FF_DELAY wiack_hit ;
481
        end
482
    end
483
 
484
    // wires indicating allowance for configuration cycle generation requests
485
    wire do_ccyc_req  = do_del_request && ccyc_hit;
486
    wire do_ccyc_comp = del_completion_allow && ccyc_hit && current_delayed_is_ccyc ; // && del_bc_hit
487
 
488
    // wires indicating allowance for interrupt acknowledge cycle generation requests
489
    wire do_iack_req  = do_del_request && iack_hit ;
490
    wire do_iack_comp = del_completion_allow && iack_hit && current_delayed_is_iack ; // && del_bc_hit
491
 
492
    // variables for configuration access control signals
493
    reg conf_wenable ;
494
 
495
    // following flip-flops remember whether current delayed transaction is interrupt acknowledge or configuration cycle transaction
496
    always@(posedge wb_clock_in or posedge reset_in)
497
    begin
498
        if ( reset_in )
499
        begin
500
            current_delayed_is_ccyc <= #`FF_DELAY 1'b0 ;
501
            current_delayed_is_iack <= #`FF_DELAY 1'b0 ;
502
        end
503
        else
504
        if ( del_done_out )
505
        begin
506
            current_delayed_is_ccyc <= #`FF_DELAY 1'b0 ;
507
            current_delayed_is_iack <= #`FF_DELAY 1'b0 ;
508
        end
509
        else
510
        if ( del_req_out && wb_conf_hit )
511
        begin
512
            current_delayed_is_ccyc <= #`FF_DELAY do_ccyc_req ;
513
            current_delayed_is_iack <= #`FF_DELAY do_iack_req ;
514
        end
515
    end
516
 
517
`endif
518
`endif
519
 
520
// configuration read enable - supplied for host and guest bridges
521
reg conf_renable ;
522
assign wb_conf_renable_out = conf_renable ;
523
 
524
// burst access indicator
525
wire burst_transfer = CYC_I && CAB_I ;
526
 
527
// SEL_I error indicator for IO accesses - select lines must be alligned with address
528
reg sel_error ;
529
always@(wb_addr_in or SEL_I)
530
begin
531
    case (wb_addr_in[1:0])
532
        2'b00: sel_error = ~SEL_I[0] ; // select 0 must be 1, all others are don't cares.
533
        2'b01: sel_error = ~SEL_I[1] || SEL_I[0] ; // byte 0 can't be selected, byte 1 must be selected
534
        2'b10: sel_error = ~SEL_I[2] || SEL_I[1] || SEL_I[0] ; // bytes 0 and 1 can't be selected, byte 2 must be selected
535
        2'b11: sel_error = ~SEL_I[3] || SEL_I[2] || SEL_I[1] || SEL_I[0] ; // bytes 0, 1 and 2 can't be selected, byte 3 must be selected
536
    endcase
537
end
538
 
539
// WBW_FIFO control output
540
reg [3:0] wbw_fifo_control ;
541
 
542
// WBW_FIFO wenable output assignment
543
reg wbw_fifo_wenable ;
544
 
545
// WBR_FIFO control outputs
546
reg wbr_fifo_flush, wbr_fifo_renable ; // flush and read enable outputs
547
 
548
// flush signal for WBR_FIFO must be registered, since it asinchronously resets some status registers
549
wire            wbr_fifo_flush_reg ;
550
pci_async_reset_flop async_reset_as_wbr_flush
551
(
552
    .data_in              (wbr_fifo_flush),
553
    .clk_in               (wb_clock_in),
554
    .async_reset_data_out (wbr_fifo_flush_reg),
555
    .reset_in                     (reset_in)
556
) ;
557
assign  wbr_fifo_flush_out = wbr_fifo_flush_reg ;
558
 
559
// delayed transaction request control signals
560
reg del_req, del_done ;
561
 
562
// WISHBONE handshaking control outputs
563
reg ack, rty, err ;
564
 
565
`ifdef REGISTER_WBS_OUTPUTS
566
// wire for write attempt - 1 when external WB master is attempting a write
567
// wire for read attempt  - 1 when external master is attempting a read
568
wire wattempt = ( CYC_I && STB_I && WE_I ) && (!ACK_O && !ERR_O && !RTY_O) ;
569
wire rattempt = ( CYC_I && STB_I && ~WE_I ) && (!ACK_O && !ERR_O && !RTY_O) ;
570
 
571
`else
572
// wire for write attempt - 1 when external WB master is attempting a write
573
// wire for read attempt  - 1 when external master is attempting a read
574
wire wattempt = ( CYC_I && STB_I && WE_I ) ; // write is qualified when cycle, strobe and write enable inputs are all high
575
wire rattempt = ( CYC_I && STB_I && ~WE_I ) ; // read is qualified when cycle and strobe are high and write enable is low
576
 
577
`endif
578
/*----------------------------------------------------------------------------------------------------------------------
579
Delayed transaction bus command generation
580
Bus command for delayed reads depends on image's address space mapping and control bits and
581
whether or not these are interrupt acknowledge requests or configuration cycle requests
582
---------------------------------------------------------------------------------------------------------------------*/
583
 
584
always@(map or mrl_en or ccyc_hit or WE_I or wb_conf_hit or CAB_I or pref_en)
585
begin
586
`ifdef HOST
587
// only host implementation supports configuration and interrupt acknowledge commands
588
    if (wb_conf_hit)
589
    begin
590
        case( {ccyc_hit, WE_I} )
591
            2'b11:  del_bc = `BC_CONF_WRITE ;
592
            2'b10:  del_bc = `BC_CONF_READ ;
593
            2'b01:  del_bc = `BC_RESERVED0 ; // invalid combination - interrupt acknowledge cycle must be a read
594
            2'b00:  del_bc = `BC_IACK ;
595
        endcase
596
    end
597
    else
598
`endif
599
    begin
600
        if ( map )
601
        begin
602
            del_bc = `BC_IO_READ ;
603
        end
604
        else
605
        begin
606
            case ({(CAB_I && mrl_en), pref_en})
607
                2'b00: del_bc = `BC_MEM_READ ;     // if this is not burst transfer or memory read line command is disabled - use memory read
608
                2'b01: del_bc = `BC_MEM_READ ;     // same as previous case
609
                2'b10: del_bc = `BC_MEM_READ_LN ;  // burst transfer, memory read line command enabled, prefetch disabled - use memory read line command
610
                2'b11: del_bc = `BC_MEM_READ_MUL ; // same as previous case, except prefetch is enabled - use memory read multiple command
611
            endcase
612
        end
613
    end
614
end
615
 
616
reg del_in_progress ; // state machine indicates whether current read completion is in progress on WISHBONE bus
617
 
618
wire image_access_error = (map && (burst_transfer || sel_error)) ||   // IO write is a burst or has wrong select lines active= Error
619
                          (~map && ~alligned_address) ;               // Mem write to nonaligned address = error;
620
 
621
`ifdef HOST
622
    reg [1:0]   wbw_data_out_sel ;
623
    parameter SEL_ADDR_IN = 2'b10 ;
624
    parameter SEL_CCYC_ADDR = 2'b11 ;
625
    parameter SEL_DATA_IN   = 2'b00 ;
626
`else
627
`ifdef GUEST
628
    reg wbw_data_out_sel ;
629
    parameter SEL_ADDR_IN = 1'b1 ;
630
    parameter SEL_DATA_IN = 1'b0 ;
631
`endif
632
`endif
633
 
634
`ifdef WB_DECODE_FAST
635
    `ifdef REGISTER_WBS_OUTPUTS
636
        `define PCI_WB_SLAVE_S_DEC1
637
    `endif
638
`endif
639
 
640
`ifdef WB_DECODE_MEDIUM
641
    `define PCI_WB_SLAVE_S_DEC1
642
`endif
643
 
644
`ifdef WB_DECODE_SLOW
645
    `define PCI_WB_SLAVE_S_DEC1
646
    `define PCI_WB_SLAVE_S_DEC2
647
`endif
648
// state machine logic
649
always@(
650
        c_state                     or
651
        wattempt                    or
652
        img_wallow                  or
653
        burst_transfer              or
654
        wb_hit                      or
655
        map                         or
656
        alligned_address            or
657
        rattempt                    or
658
        do_dread_completion         or
659
        wbr_fifo_control_in         or
660
        wb_conf_hit                 or
661
        do_ccyc_req                 or
662
        do_ccyc_comp                or
663
        ccyc_hit                    or
664
        del_error_in                or
665
        do_iack_req                 or
666
        do_iack_comp                or
667
        iack_hit                    or
668
        image_access_error          or
669
        wbw_fifo_almost_full_in     or
670
        wbw_fifo_full_in            or
671
        do_del_request              or
672
        wbr_fifo_empty_in
673
       )
674
begin
675
    // default signal values
676
    // response signals inactive
677
    ack         = 1'b0 ;
678
    rty         = 1'b0 ;
679
    err         = 1'b0 ;
680
 
681
    //write signals inactive
682
    wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b1 ;
683
    wbw_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b0 ;
684
    wbw_fifo_control[`LAST_CTRL_BIT] = 1'b0 ;
685
    wbw_fifo_control[`UNUSED_CTRL_BIT] = 1'b0 ;
686
 
687
    wbw_fifo_wenable = 1'b0 ;
688
    d_incoming_ena   = 1'b0 ;
689
 
690
    // read signals inactive
691
    wbr_fifo_flush   = 1'b0 ;
692
    wbr_fifo_renable = 1'b0 ;
693
    del_req          = 1'b0 ;
694
    del_done         = 1'b0 ;
695
 
696
    // configuration space control signals inactive
697
    conf_wenable = 1'b0 ;
698
    conf_renable = 1'b0 ;
699
 
700
    // read is not in progress
701
    del_in_progress = 1'b0 ;
702
 
703
    decode_en = 1'b0 ;
704
 
705
    wbw_data_out_sel         = SEL_ADDR_IN ;
706
 
707
    sample_address_out = 1'b0 ;
708
 
709
    case (c_state)
710
    S_IDLE: begin
711
                if ( wattempt || rattempt )
712
                begin
713
 
714
                `ifdef PCI_WB_SLAVE_S_DEC1
715
                    n_state = S_DEC1 ;
716
                `else
717
                    decode_en = 1'b1 ;
718
                    n_state = S_START ;
719
                `endif
720
 
721
                    sample_address_out = 1'b1 ;
722
                end
723
                else
724
                    n_state = S_IDLE ;
725
            end
726
`ifdef PCI_WB_SLAVE_S_DEC1
727
    S_DEC1: begin
728
                if ( wattempt || rattempt )
729
                begin
730
 
731
                `ifdef PCI_WB_SLAVE_S_DEC2
732
                    n_state = S_DEC2 ;
733
                `else
734
                    decode_en = 1'b1 ;
735
                    n_state = S_START ;
736
                `endif
737
 
738
                end
739
                else
740
                    n_state = S_IDLE ;
741
            end
742
`endif
743
`ifdef PCI_WB_SLAVE_S_DEC2
744
    S_DEC2: begin
745
 
746
                if ( wattempt || rattempt )
747
                begin
748
                    decode_en = 1'b1 ;
749
                    n_state = S_START ;
750
                end
751
                else
752
                    n_state = S_IDLE ;
753
            end
754
`endif
755
    S_START:begin
756
                if (wb_conf_hit) // configuration space hit
757
                begin
758
                    `ifdef HOST
759
                        wbw_data_out_sel = SEL_CCYC_ADDR ;
760
                    `endif
761
 
762
                    if ( wattempt )
763
                        n_state = S_CONF_WRITE ; // go to conf. write state
764
                    else
765
                    if ( rattempt )
766
                    begin
767
                        n_state     = S_CONF_READ ; // go to conf. read state
768
                    end
769
                    else
770
                        n_state = S_IDLE ; // master terminated - go back to idle state
771
 
772
                end // wb_conf_hit
773
                else
774
                if( wb_hit && (wattempt || rattempt) )
775
                begin
776
                    wbw_data_out_sel = SEL_DATA_IN ;
777
 
778
                    // check error conditions for image writes or reads
779
                    if ( image_access_error )
780
                    begin
781
                        n_state = S_IDLE ; // go back to idle state because of an error condition
782
                        err     = 1'b1 ;
783
                    end // error conditions
784
                    else
785
                    // check for retry conditions for image writes or reads
786
                    if ( (wattempt && ~img_wallow) ||
787
                         (rattempt && ~do_dread_completion) // write to image not allowed, no read ready yet - retry
788
                       )
789
                    begin
790
                        n_state = S_IDLE ; // go back to IDLE
791
 
792
                        rty     = 1'b1 ;
793
 
794
                        del_req = do_del_request && rattempt ;
795
 
796
                    end //retry
797
                    else // everything OK - proceed
798
                    if ( wattempt )
799
                    begin
800
                        n_state = S_W_ADDR_DATA ; // goto write transfer state
801
 
802
                        // respond with acknowledge
803
                        ack              = 1'b1 ;
804
 
805
                        wbw_fifo_wenable = 1'b1 ;
806
 
807
                        // data is latched to data incoming intermidiate stage - it will be put in FIFO later
808
                        d_incoming_ena   = 1'b1 ;
809
                    end
810
                    else
811
                    begin
812
                        err = wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] ;
813
                        ack = ~wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] ;
814
                        wbr_fifo_renable    = 1'b1 ;
815
                        del_in_progress = 1'b1 ;
816
 
817
                        if ( wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT] )
818
                        begin
819
 
820
                            n_state = S_IDLE ; // go back to idle state
821
                            // respond that read is finished
822
                            del_done     = 1'b1 ;
823
 
824
                        end // end read
825
                        else
826
                            n_state = S_READ ; // go to read state
827
                    end
828
                end
829
                else
830
                    n_state = S_IDLE ;
831
 
832
            end
833
 
834
    S_W_ADDR_DATA: begin
835
                        wbw_data_out_sel = SEL_DATA_IN ;
836
                        err = burst_transfer && wattempt && ~alligned_address ;
837
                        rty = burst_transfer && wattempt && (wbw_fifo_almost_full_in || wbw_fifo_full_in) ;
838
 
839
                        if ( ~burst_transfer || wattempt && ( ~alligned_address || wbw_fifo_almost_full_in || wbw_fifo_full_in ) )
840
                        begin
841
                            n_state = S_IDLE ;
842
 
843
                            // write last data to FIFO and don't latch new data
844
                            wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ;
845
                            wbw_fifo_control[`LAST_CTRL_BIT] = 1'b1 ;
846
                            wbw_fifo_wenable = 1'b1 ;
847
                        end
848
                        else
849
                        begin
850
                            n_state = S_W_ADDR_DATA ;
851
                            wbw_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ;
852
                            wbw_fifo_control[`LAST_CTRL_BIT] = 1'b0 ;
853
                            ack              = wattempt ;
854
                            wbw_fifo_wenable = wattempt ;
855
                            d_incoming_ena   = wattempt ;
856
                        end
857
                    end // S_W_ADDR_DATA
858
 
859
    S_READ:begin
860
                // this state is for reads only - in this state read is in progress all the time
861
                del_in_progress = 1'b1 ;
862
 
863
                ack = burst_transfer && rattempt && ~wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] && alligned_address    && ~wbr_fifo_empty_in ;
864
                err = burst_transfer && rattempt && ((wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || ~alligned_address) && ~wbr_fifo_empty_in) ;
865
                //rty = burst_transfer && rattempt && wbr_fifo_empty_in && alligned_address ;
866
 
867
                // if acknowledge is beeing signalled then enable read from wbr fifo
868
                wbr_fifo_renable = burst_transfer && rattempt && alligned_address && ~wbr_fifo_empty_in ;
869
 
870
                if ( ~burst_transfer || rattempt && (~alligned_address || wbr_fifo_empty_in || wbr_fifo_control_in[`DATA_ERROR_CTRL_BIT] || wbr_fifo_control_in[`LAST_CTRL_BIT]) )
871
                begin
872
                    n_state = S_IDLE ;
873
                    del_done = 1'b1 ;
874
                    wbr_fifo_flush = ~wbr_fifo_empty_in ;
875
                end
876
                else
877
                begin
878
                    n_state          = S_READ ;
879
                end
880
            end // S_READ
881
 
882
    S_CONF_WRITE:  begin
883
                        `ifdef HOST
884
                            wbw_data_out_sel = SEL_CCYC_ADDR ;
885 113 simons
                            del_req          = do_ccyc_req && ~burst_transfer
886
                              `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
887
                              `else
888
                                               && alligned_address
889
                              `endif
890
                                               ;
891
                            del_done         = do_ccyc_comp && ~burst_transfer
892
                              `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
893
                              `else
894
                                               && alligned_address
895
                              `endif
896
                                               ;
897
                            del_in_progress  = do_ccyc_comp && ~burst_transfer
898
                              `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
899
                              `else
900
                                               && alligned_address
901
                              `endif
902
                                               ;
903 77 mihad
                        `endif
904
 
905
                        n_state         = S_IDLE ; // next state after configuration access is always idle
906
 
907 113 simons
                        if ( burst_transfer
908
                        `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
909
                        `else
910
                            | ~alligned_address
911
                        `endif
912
                           )
913 77 mihad
                        begin
914
                            err = 1'b1 ;
915
                        end
916
                        else
917
                        begin
918
                            `ifdef HOST
919
                            if ( do_ccyc_req || (ccyc_hit && ~do_ccyc_comp))
920
                            begin
921
                                rty = 1'b1 ;
922
                            end
923
                            else
924
                            if ( do_ccyc_comp )
925
                            begin
926
                                err = del_error_in ;
927
                                ack = ~del_error_in ;
928
                            end
929
                            else
930
                            begin
931
                                ack = ~ccyc_hit ;
932
                                conf_wenable = ~ccyc_hit ;
933
                            end
934
                            `else
935
                            ack = 1'b1 ;
936
                            conf_wenable = 1'b1 ;
937
                            `endif
938
                        end
939
                    end // S_CONF_WRITE
940
 
941
    S_CONF_READ:   begin
942
                        `ifdef HOST
943
                            wbw_data_out_sel = SEL_CCYC_ADDR ;
944 113 simons
                            del_req          = ~burst_transfer
945
                          `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
946
                          `else
947
                                                && alligned_address
948
                          `endif
949
                                                && ( do_ccyc_req  || do_iack_req  ) ;
950
                            del_done         = ~burst_transfer
951
                          `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
952
                          `else
953
                                                && alligned_address
954
                          `endif
955
                                                && ( do_ccyc_comp || do_iack_comp ) ;
956
                            del_in_progress  = ~burst_transfer
957
                          `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
958
                          `else
959
                                                && alligned_address
960
                          `endif
961
                                                && ( do_ccyc_comp || do_iack_comp ) ;
962
                            wbr_fifo_renable = ~burst_transfer
963
                          `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
964
                          `else
965
                                                && alligned_address
966
                          `endif
967
                                                && ( do_ccyc_comp || do_iack_comp ) ;
968 77 mihad
                        `endif
969
 
970
                        n_state = S_IDLE ; // next state after configuration access is always idle
971
 
972 113 simons
                        if ( burst_transfer
973
                        `ifdef PCI_WBS_ALLOW_NON_ALLIGNED_CONFIG_ACCESS
974
                        `else
975
                              | ~alligned_address
976
                        `endif
977
                           )
978 77 mihad
                        begin
979
                            err = 1'b1 ;
980
                        end
981
                        else
982
                        begin
983
                            `ifdef HOST
984
                            if ( do_ccyc_req || ( ccyc_hit && ~do_ccyc_comp ))
985
                            begin
986
                                rty = 1'b1 ;
987
                            end
988
                            else
989
                            if ( do_iack_req || ( iack_hit && ~do_iack_comp ))
990
                            begin
991
                                rty = 1'b1 ;
992
                            end
993
                            else
994
                            if ( do_iack_comp || do_ccyc_comp )
995
                            begin
996
                                err = del_error_in ;
997
                                ack = ~del_error_in ;
998
                            end
999
                            else
1000
                            begin
1001
                                ack = ~( ccyc_hit || iack_hit ) ;
1002
                                conf_renable = ~( ccyc_hit || iack_hit ) ;
1003
                            end
1004
                            `else
1005
                            ack = 1'b1 ;
1006
                            conf_renable = 1'b1 ;
1007
                            `endif
1008
                        end
1009
                    end //S_CONF_READ
1010
    default:begin
1011
                n_state = S_IDLE ; // return to idle state
1012
            end //default
1013
    endcase
1014
end
1015
 
1016
// configuration space offset output assignment
1017
assign wb_conf_offset_out = {wb_addr_in[11:2], 2'b00} ; // upper 10 bits of address input and two zeros
1018
 
1019
// data output assignment - for image writes, first data is address, subsequent data comes from intermediate register
1020
reg [31:0] wb_data ;
1021
`ifdef HOST
1022
reg [1:0] wbw_data_out_sel_reg ;
1023
always@(posedge wb_clock_in or posedge reset_in)
1024
begin
1025
    if ( reset_in )
1026
        wbw_data_out_sel_reg <= #`FF_DELAY SEL_ADDR_IN ;
1027
    else
1028
        wbw_data_out_sel_reg <= #`FF_DELAY wbw_data_out_sel ;
1029
end
1030
 
1031
always@(wbw_data_out_sel_reg or wb_addr_in or ccyc_addr_in or d_incoming)
1032
begin
1033
    case ( wbw_data_out_sel_reg )
1034
        SEL_CCYC_ADDR:  wb_data = ccyc_addr_in ;
1035
        SEL_DATA_IN:    wb_data = d_incoming ;
1036
        default: wb_data        = wb_addr_in ;
1037
    endcase
1038
end
1039
`else
1040
`ifdef GUEST
1041
reg wbw_data_out_sel_reg ;
1042
always@(posedge wb_clock_in or posedge reset_in)
1043
begin
1044
    if ( reset_in )
1045
        wbw_data_out_sel_reg <= #`FF_DELAY SEL_ADDR_IN ;
1046
    else
1047
        wbw_data_out_sel_reg <= #`FF_DELAY wbw_data_out_sel ;
1048
end
1049
 
1050
always@(wbw_data_out_sel_reg or wb_addr_in or d_incoming)
1051
begin
1052
    if ( wbw_data_out_sel_reg )
1053
        wb_data = wb_addr_in ;
1054
    else
1055
        wb_data = d_incoming ;
1056
end
1057
`endif
1058
`endif
1059
 
1060
// command / byte enable assignment - with address, bus command is provided, with data - byte enables are provided
1061
reg [3:0] wb_cbe ;
1062
 
1063
always@(wbw_data_out_sel_reg or d_incoming or map)
1064
begin
1065
    if (wbw_data_out_sel_reg && map)
1066
        wb_cbe = `BC_IO_WRITE ;
1067
    else
1068
    if (wbw_data_out_sel_reg)
1069
        wb_cbe = `BC_MEM_WRITE ;
1070
    else
1071
        wb_cbe = ~(d_incoming[35:32]) ;
1072
end
1073
 
1074
// for configuration writes, data output is always data from WISHBONE - in guest implementation data is all 0.
1075
`ifdef GUEST
1076
    assign wb_conf_data_out = 32'h00000000 ;
1077
`endif
1078
 
1079
`ifdef GUEST
1080
    `ifdef NO_CNF_IMAGE
1081
    `else
1082
        `define PCI_WB_SLAVE_DO_OUT_MUX
1083
    `endif
1084
`else
1085
`ifdef HOST
1086
    `define PCI_WB_SLAVE_DO_OUT_MUX ;
1087
`endif
1088
`endif
1089
 
1090
`ifdef PCI_WB_SLAVE_DO_OUT_MUX
1091
    reg [31:0] sdata_source ;
1092
 
1093
    // WISHBONE data output select lines for output multiplexor
1094
    wire sdata_o_sel_new = ( wb_conf_hit_in && ~wiack_hit && ~wccyc_hit ) ? CONF_SEL : WBR_SEL ;
1095
    reg sdata_o_sel ;
1096
 
1097
    always@(posedge wb_clock_in or posedge reset_in)
1098
    begin
1099
        if ( reset_in )
1100
            sdata_o_sel <= #`FF_DELAY WBR_SEL ;
1101
        else
1102
        if ( decode_en )
1103
            sdata_o_sel <= #`FF_DELAY sdata_o_sel_new ;
1104
    end
1105
 
1106
    always@(sdata_o_sel or wbr_fifo_data_in or wb_conf_data_in)
1107
    begin
1108
        case (sdata_o_sel)
1109
            WBR_SEL :sdata_source = wbr_fifo_data_in ;
1110
            CONF_SEL:sdata_source = wb_conf_data_in ;
1111
        endcase
1112
    end
1113
`else
1114
    wire [31:0] sdata_source = wbr_fifo_data_in ;
1115
`endif
1116
 
1117
`ifdef REGISTER_WBS_OUTPUTS
1118
 
1119
always@(posedge wb_clock_in or posedge reset_in)
1120
begin
1121
    if ( reset_in )
1122
    begin
1123
        ACK_O         <= #`FF_DELAY 1'b0 ;
1124
        RTY_O         <= #`FF_DELAY 1'b0 ;
1125
        ERR_O         <= #`FF_DELAY 1'b0 ;
1126
        SDATA_O       <= #`FF_DELAY 0 ;
1127
        del_write_out <= #`FF_DELAY 1'b0 ;
1128
 
1129
        `ifdef HOST
1130
        wb_conf_wenable_out <= #`FF_DELAY 1'b0 ;
1131
        wb_conf_data_out    <= #`FF_DELAY 0 ;
1132
        `endif
1133
 
1134
        del_bc_out    <= #`FF_DELAY `BC_RESERVED0 ;
1135
        del_req_out <= #`FF_DELAY 1'b0 ;
1136
        del_done_out <= #`FF_DELAY 1'b0 ;
1137
        del_burst_out <= #`FF_DELAY 1'b0 ;
1138
        del_in_progress_out <= #`FF_DELAY 1'b0 ;
1139
        wb_conf_be_out <= #`FF_DELAY 0 ;
1140
        wb_data_out    <= #`FF_DELAY 0 ;
1141
        wb_cbe_out <= #`FF_DELAY 0 ;
1142
        wbw_fifo_wenable_out <= #`FF_DELAY 0 ;
1143
        wbw_fifo_control_out <= #`FF_DELAY 0 ;
1144
        wbr_fifo_renable_out <= #`FF_DELAY 0 ;
1145
    end
1146
    else
1147
    begin
1148
        ACK_O   <= #`FF_DELAY ack && !ACK_O ;
1149
        RTY_O   <= #`FF_DELAY rty && !RTY_O ;
1150
        ERR_O    <= #`FF_DELAY err && !ERR_O ;
1151
        SDATA_O       <= #`FF_DELAY sdata_source ;
1152
        del_write_out <= #`FF_DELAY WE_I ;
1153
 
1154
        `ifdef HOST
1155
        wb_conf_wenable_out <= #`FF_DELAY conf_wenable ;
1156
        wb_conf_data_out    <= #`FF_DELAY SDATA_I ;
1157
        `endif
1158
 
1159
        del_bc_out <= #`FF_DELAY del_bc ;
1160
        del_req_out <= #`FF_DELAY del_req ;
1161
        del_done_out <= #`FF_DELAY del_done ;
1162
        del_burst_out <= #`FF_DELAY del_burst ;
1163
        del_in_progress_out <= #`FF_DELAY del_in_progress ;
1164
        wb_conf_be_out <= #`FF_DELAY SEL_I ;
1165
        wb_data_out <= #`FF_DELAY wb_data ;
1166
        wb_cbe_out <= #`FF_DELAY wb_cbe ;
1167
        wbw_fifo_wenable_out <= #`FF_DELAY wbw_fifo_wenable ;
1168
        wbw_fifo_control_out <= #`FF_DELAY wbw_fifo_control ;
1169
        wbr_fifo_renable_out <= #`FF_DELAY wbr_fifo_renable ;
1170
    end
1171
end
1172
 
1173
`else
1174
 
1175
assign SDATA_O = sdata_source ;
1176
 
1177
assign ACK_O = ack ;
1178
assign RTY_O = rty ;
1179
assign ERR_O = err ;
1180
 
1181
// write operation indicator for delayed transaction requests
1182
assign del_write_out = WE_I ;
1183
assign del_bc_out = del_bc ;
1184
assign del_req_out  = del_req ; // read request
1185
assign del_done_out = del_done ; // read done
1186
assign del_burst_out = del_burst ;
1187
assign del_in_progress_out = del_in_progress ;
1188
`ifdef HOST
1189
assign wb_conf_data_out = SDATA_I ;
1190
assign wb_conf_wenable_out = conf_wenable ;
1191
`endif
1192
// Configuration space byte enables output
1193
assign wb_conf_be_out = SEL_I ; // just route select lines from WISHBONE to conf space
1194
assign wb_data_out    = wb_data ;
1195
assign wb_cbe_out = wb_cbe ;
1196
assign wbw_fifo_wenable_out = wbw_fifo_wenable ; //write enable for WBW_FIFO
1197
assign wbw_fifo_control_out = wbw_fifo_control ; //control bus output for WBW_FIFO
1198
assign wbr_fifo_renable_out = wbr_fifo_renable ; //read enable for wbr_fifo
1199
`endif
1200
 
1201
endmodule //WB_SLAVE

powered by: WebSVN 2.1.0

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