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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [wb_slave.v] - Blame information for rev 154

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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