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

Subversion Repositories pci

[/] [pci/] [tags/] [asyst_2/] [rtl/] [verilog/] [pci_target32_sm.v] - Blame information for rev 133

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name: pci_target32_sm.v                                ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Tadej Markovic, tadej@opencores.org                   ////
10
////                                                              ////
11
////  All additional information is avaliable in the README.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2000 Tadej Markovic, tadej@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 132 mihad
// Revision 1.10  2003/08/08 16:36:33  tadejm
46
// Added 'three_left_out' to pci_pciw_fifo signaling three locations before full. Added comparison between current registered cbe and next unregistered cbe to signal wb_master whether it is allowed to performe burst or not. Due to this, I needed 'three_left_out' so that writing to pci_pciw_fifo can be registered, otherwise timing problems would occure.
47
//
48 108 tadejm
// Revision 1.9  2003/01/27 16:49:31  mihad
49
// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
50
//
51 77 mihad
// Revision 1.8  2003/01/21 16:06:56  mihad
52
// Bug fixes, testcases added.
53
//
54 73 mihad
// Revision 1.7  2002/09/24 19:09:17  mihad
55
// Number of state bits define was removed
56
//
57 56 mihad
// Revision 1.6  2002/09/24 18:30:00  mihad
58
// Changed state machine encoding to true one-hot
59
//
60 55 mihad
// Revision 1.5  2002/08/22 09:07:06  mihad
61
// Fixed a bug and provided testcase for it. Target was responding to configuration cycle type 1 transactions.
62
//
63 51 mihad
// Revision 1.4  2002/02/19 16:32:37  mihad
64
// Modified testbench and fixed some bugs
65
//
66 26 mihad
// Revision 1.3  2002/02/01 15:25:12  mihad
67
// Repaired a few bugs, updated specification, added test bench files and design document
68
//
69 21 mihad
// Revision 1.2  2001/10/05 08:14:30  mihad
70
// Updated all files with inclusion of timescale file for simulation purposes.
71
//
72 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
73
// New project directory structure
74 2 mihad
//
75 6 mihad
//
76 2 mihad
 
77 21 mihad
`include "pci_constants.v"
78 2 mihad
 
79 21 mihad
// synopsys translate_off
80 6 mihad
`include "timescale.v"
81 21 mihad
// synopsys translate_on
82 2 mihad
 
83 77 mihad
module pci_target32_sm
84 2 mihad
(
85
    // system inputs
86
    clk_in,
87
    reset_in,
88
    // master inputs
89
    pci_frame_in,
90
    pci_irdy_in,
91
    pci_idsel_in,
92
    pci_frame_reg_in,
93
    pci_irdy_reg_in,
94
    pci_idsel_reg_in,
95
    // target response outputs
96
    pci_trdy_out,
97
    pci_stop_out,
98
    pci_devsel_out,
99
    pci_trdy_en_out,
100
    pci_stop_en_out,
101
    pci_devsel_en_out,
102 21 mihad
    ad_load_out,
103
    ad_load_on_transfer_out,
104 2 mihad
    // address, data, bus command, byte enable in/outs
105
    pci_ad_reg_in,
106
    pci_ad_out,
107
    pci_ad_en_out,
108
    pci_cbe_reg_in,
109 108 tadejm
    pci_cbe_in,
110 2 mihad
    bckp_trdy_en_in,
111
    bckp_devsel_in,
112
    bckp_trdy_in,
113
    bckp_stop_in,
114 21 mihad
    pci_trdy_reg_in,
115
    pci_stop_reg_in,
116 2 mihad
 
117
    // backend side of state machine with control signals to pci_io_mux ...
118
    address_out,
119
    addr_claim_in,
120
    bc_out,
121
    bc0_out,
122
    data_out,
123
    data_in,
124
    be_out,
125 108 tadejm
    next_be_out,
126 2 mihad
    req_out,
127
    rdy_out,
128
    addr_phase_out,
129 21 mihad
    bckp_devsel_out,
130 2 mihad
    bckp_trdy_out,
131 21 mihad
    bckp_stop_out,
132 2 mihad
    last_reg_out,
133
    frame_reg_out,
134 21 mihad
    fetch_pcir_fifo_out,
135
    load_medium_reg_out,
136
    sel_fifo_mreg_out,
137
    sel_conf_fifo_out,
138
    load_to_pciw_fifo_out,
139 2 mihad
    load_to_conf_out,
140 21 mihad
    same_read_in,
141
    norm_access_to_config_in,
142
    read_completed_in,
143
    read_processing_in,
144
    target_abort_in,
145
    disconect_wo_data_in,
146
    disconect_w_data_in,
147
    target_abort_set_out,
148
    pciw_fifo_full_in,
149
    pcir_fifo_data_err_in,
150
    wbw_fifo_empty_in,
151
    wbu_del_read_comp_pending_in,
152
    wbu_frame_en_in
153 2 mihad
 
154
) ;
155
 
156
/*----------------------------------------------------------------------------------------------------------------------
157
Various parameters needed for state machine and other stuff
158
----------------------------------------------------------------------------------------------------------------------*/
159 55 mihad
parameter       S_IDLE          = 3'b001 ;
160
parameter       S_WAIT          = 3'b010 ;
161
parameter       S_TRANSFERE     = 3'b100 ;
162 2 mihad
 
163
 
164
/*==================================================================================================================
165
System inputs.
166
==================================================================================================================*/
167
// PCI side clock and reset
168
input   clk_in,
169
        reset_in ;
170
 
171
 
172
/*==================================================================================================================
173
PCI interface signals - bidirectional signals are divided to inputs and outputs in I/O cells instantiation
174
module. Enables are separate signals.
175
==================================================================================================================*/
176
// master inputs
177
input   pci_frame_in,
178 21 mihad
        pci_irdy_in,
179
        pci_idsel_in ;
180 2 mihad
input   pci_frame_reg_in,
181 21 mihad
        pci_irdy_reg_in,
182
        pci_idsel_reg_in ;
183
 
184 2 mihad
// target response outputs
185
output  pci_trdy_out,
186
        pci_stop_out,
187
        pci_devsel_out ;
188
output  pci_trdy_en_out,
189 21 mihad
        pci_stop_en_out,
190
        pci_devsel_en_out ;
191
output  ad_load_out ;
192
output  ad_load_on_transfer_out ;
193 2 mihad
// address, data, bus command, byte enable in/outs
194
input   [31:0]  pci_ad_reg_in ;
195
output  [31:0]  pci_ad_out ;
196
output          pci_ad_en_out ;
197
input   [3:0]   pci_cbe_reg_in ;
198 108 tadejm
input   [3:0]   pci_cbe_in ;
199 21 mihad
input           bckp_trdy_en_in ;
200
input           bckp_devsel_in ;
201
input           bckp_trdy_in ;
202
input           bckp_stop_in ;
203
input           pci_trdy_reg_in ;
204
input           pci_stop_reg_in ;
205 2 mihad
 
206
 
207
/*==================================================================================================================
208
Other side of PCI Target state machine
209
==================================================================================================================*/
210
// Data, byte enables, bus commands and address ports
211 21 mihad
output  [31:0]  address_out ;       // current request address output - registered
212
input           addr_claim_in ;     // current request address claim input
213
output  [3:0]   bc_out ;            // current request bus command output - registered
214
output          bc0_out ;           // current cycle RW signal output
215
input   [31:0]  data_in ;           // for read operations - current dataphase data input
216
output  [31:0]  data_out ;          // for write operations - current request data output - registered
217
output   [3:0]  be_out ;            // current dataphase byte enable outputs - registered
218 108 tadejm
output   [3:0]  next_be_out ;       // next dataphase byte enable outputs - NOT registered
219 2 mihad
// Port connection control signals from PCI FSM
220 21 mihad
output          req_out ;           // Read is requested to WB master
221
output          rdy_out ;           // DATA / ADDRESS selection when read or write - registered
222
output          addr_phase_out ;    // Indicates address phase and also fast-back-to-back address phase - registered
223
output                  bckp_devsel_out ;       // DEVSEL output (which is registered) equivalent
224
output          bckp_trdy_out ;     // TRDY output (which is registered) equivalent
225
output                  bckp_stop_out ;         // STOP output (which is registered) equivalent
226
output          last_reg_out ;      // Indicates last data phase - registered
227
output          frame_reg_out ;     // FRAME output signal - registered
228
output          fetch_pcir_fifo_out ;// Read enable for PCIR_FIFO when when read is finishen on WB side
229
output          load_medium_reg_out ;// Load data from PCIR_FIFO to medium register (first data must be prepared on time)
230
output          sel_fifo_mreg_out ; // Read data selection between PCIR_FIFO and medium register
231
output          sel_conf_fifo_out ; // Read data selection between Configuration registers and "FIFO"
232
output          load_to_pciw_fifo_out ;// Write enable to PCIW_FIFO
233
output          load_to_conf_out ;  // Write enable to Configuration space registers
234 2 mihad
 
235
 
236
/*==================================================================================================================
237
Status
238
==================================================================================================================*/
239 21 mihad
input           same_read_in ;              // Indicates the same read request (important when read is finished on WB side)
240
input           norm_access_to_config_in ;  // Indicates the access to Configuration space with MEMORY commands
241
input           read_completed_in ;         // Indicates that read request is completed on WB side
242
input           read_processing_in ;        // Indicates that read request is processing on WB side
243
input           target_abort_in ;           // Indicates target abort termination
244
input           disconect_wo_data_in ;      // Indicates disconnect without data termination
245
input                   disconect_w_data_in ;           // Indicates disconnect with data termination
246
input           pciw_fifo_full_in ;         // Indicates that write PCIW_FIFO is full
247
input           pcir_fifo_data_err_in ;     // Indicates data error on current data read from PCIR_FIFO
248
input           wbw_fifo_empty_in ;         // Indicates that WB SLAVE UNIT has no data to be written to PCI bus
249
input                   wbu_del_read_comp_pending_in ; // Indicates that WB SÈAVE UNIT has a delayed read pending
250
input           wbu_frame_en_in ;           // Indicates that WB SLAVE UNIT is accessing the PCI bus (important if
251
                                            //   address on PCI bus is also claimed by decoder in this PCI TARGET UNIT
252
output          target_abort_set_out ;      // Signal used to be set in configuration space registers
253 2 mihad
 
254
/*==================================================================================================================
255
END of input / output PORT DEFINITONS !!!
256
==================================================================================================================*/
257
 
258
// Delayed frame signal for determining the address phase
259 21 mihad
reg             previous_frame ;
260 2 mihad
// Delayed read completed signal for preparing the data from pcir fifo
261 21 mihad
reg             read_completed_reg ;
262
// Delayed disconnect with/without data for stop loading data to PCIW_FIFO
263
//reg             disconect_wo_data_reg ;
264 2 mihad
 
265 21 mihad
wire config_disconnect ;
266
wire disconect_wo_data = disconect_wo_data_in || config_disconnect ;
267
wire disconect_w_data = disconect_w_data_in ;
268 2 mihad
// Delayed frame signal for determining the address phase!
269
always@(posedge clk_in or posedge reset_in)
270
begin
271 21 mihad
    if (reset_in)
272
    begin
273 132 mihad
        previous_frame <= #`FF_DELAY 1'b0 ;
274 21 mihad
        read_completed_reg <= #`FF_DELAY 1'b0 ;
275
    end
276 2 mihad
    else
277 21 mihad
    begin
278
        previous_frame <= #`FF_DELAY pci_frame_reg_in ;
279
        read_completed_reg <= #`FF_DELAY read_completed_in ;
280
    end
281 2 mihad
end
282
 
283
// Address phase is when previous frame was 1 and this frame is 0 and frame isn't generated from pci master (in WBU)
284 21 mihad
wire    addr_phase = (previous_frame && ~pci_frame_reg_in && ~wbu_frame_en_in) ;
285 2 mihad
 
286 21 mihad
`ifdef      HOST
287
    `ifdef  NO_CNF_IMAGE
288
            // Wire tells when there is configuration (read or write) command with IDSEL signal active
289
            wire    config_access = 1'b0 ;
290
            // Write and read progresses are used for determining next state
291
            wire    write_progress  =   ( (read_completed_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in) ||
292
                                          (~read_processing_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in) ) ;
293
            wire    read_progress   =   ( (read_completed_in && wbw_fifo_empty_in) ) ;
294
    `else
295
            // Wire tells when there is configuration (read or write) command with IDSEL signal active
296 51 mihad
            wire    config_access = (pci_idsel_reg_in && pci_cbe_reg_in[3]) && (~pci_cbe_reg_in[2] && pci_cbe_reg_in[1]) &&     // idsel asserted with correct bus command(101x)
297
                                    (pci_ad_reg_in[1:0] == 2'b00) ;        // has to be type 0 configuration cycle
298
 
299 21 mihad
            // Write and read progresses are used for determining next state
300
            wire    write_progress  =   ( (norm_access_to_config_in) ||
301
                                                                  (read_completed_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in) ||
302
                                          (~read_processing_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in) ) ;
303
            wire    read_progress   =   ( (~read_completed_in && norm_access_to_config_in) ||
304
                                          (read_completed_in && wbw_fifo_empty_in) ) ;
305
    `endif
306
`else
307
            // Wire tells when there is configuration (read or write) command with IDSEL signal active
308 51 mihad
            wire    config_access = (pci_idsel_reg_in && pci_cbe_reg_in[3]) && (~pci_cbe_reg_in[2] && pci_cbe_reg_in[1]) &&     // idsel asserted with correct bus command(101x)
309
                                    (pci_ad_reg_in[1:0] == 2'b00) ;        // has to be type 0 configuration cycle
310
 
311 21 mihad
            // Write and read progresses are used for determining next state
312
            wire    write_progress  =   ( (norm_access_to_config_in) ||
313
                                                                  (read_completed_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in) ||
314
                                          (~read_processing_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in) ) ;
315
            wire    read_progress   =   ( (~read_completed_in && norm_access_to_config_in) ||
316
                                          (read_completed_in && wbw_fifo_empty_in) ) ;
317
`endif
318 2 mihad
 
319 21 mihad
// Signal for loading data to medium register from pcir fifo when read completed from WB side!
320
wire    prepare_rd_fifo_data = (read_completed_in && ~read_completed_reg) ;
321 2 mihad
 
322
// Write allowed to PCIW_FIFO
323 21 mihad
wire    write_to_fifo   =   ((read_completed_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in) ||
324
                                                         (~read_processing_in && ~pciw_fifo_full_in && ~wbu_del_read_comp_pending_in)) ;
325 2 mihad
// Read allowed from PCIR_FIFO
326 21 mihad
wire    read_from_fifo  =   (read_completed_in && wbw_fifo_empty_in) ;
327
`ifdef      HOST
328
    `ifdef  NO_CNF_IMAGE
329
            // Read request is allowed to be proceed regarding the WB side
330
            wire    read_request    =   (~read_completed_in && ~read_processing_in) ;
331
    `else
332
            // Read request is allowed to be proceed regarding the WB side
333
            wire    read_request    =   (~read_completed_in && ~read_processing_in && ~norm_access_to_config_in) ;
334
    `endif
335
`else
336
            // Read request is allowed to be proceed regarding the WB side
337
            wire    read_request    =   (~read_completed_in && ~read_processing_in && ~norm_access_to_config_in) ;
338
`endif
339 2 mihad
 
340
// Critically calculated signals are latched in this clock period (address phase) to be used in the next clock period
341 21 mihad
reg             rw_cbe0 ;
342
reg             wr_progress ;
343
reg             rd_progress ;
344
reg             rd_from_fifo ;
345
reg             rd_request ;
346
reg             wr_to_fifo ;
347
reg             same_read_reg ;
348 2 mihad
 
349
always@(posedge clk_in or posedge reset_in)
350
begin
351 21 mihad
    if (reset_in)
352
    begin
353
        rw_cbe0                         <= #`FF_DELAY 1'b0 ;
354
        wr_progress                     <= #`FF_DELAY 1'b0 ;
355
        rd_progress                     <= #`FF_DELAY 1'b0 ;
356
        rd_from_fifo                    <= #`FF_DELAY 1'b0 ;
357
        rd_request                      <= #`FF_DELAY 1'b0 ;
358
        wr_to_fifo                      <= #`FF_DELAY 1'b0 ;
359
        same_read_reg                   <= #`FF_DELAY 1'b0 ;
360
    end
361
    else
362
    begin
363
        if (addr_phase)
364
        begin
365
            rw_cbe0                     <= #`FF_DELAY pci_cbe_reg_in[0] ;
366
            wr_progress                 <= #`FF_DELAY write_progress ;
367
            rd_progress                 <= #`FF_DELAY read_progress ;
368
            rd_from_fifo                <= #`FF_DELAY read_from_fifo ;
369
            rd_request                  <= #`FF_DELAY read_request ;
370
            wr_to_fifo                  <= #`FF_DELAY write_to_fifo ;
371
            same_read_reg               <= #`FF_DELAY same_read_in ;
372
        end
373
    end
374 2 mihad
end
375
 
376 21 mihad
`ifdef      HOST
377
    `ifdef  NO_CNF_IMAGE
378
            wire    norm_access_to_conf_reg     = 1'b0 ;
379
            wire    cnf_progress                = 1'b0 ;
380
    `else
381
            reg     norm_access_to_conf_reg ;
382
            reg     cnf_progress ;
383
            always@(posedge clk_in or posedge reset_in)
384
            begin
385
                if (reset_in)
386
                begin
387
                    norm_access_to_conf_reg     <= #`FF_DELAY 1'b0 ;
388
                    cnf_progress                <= #`FF_DELAY 1'b0 ;
389
                end
390
                else
391
                begin
392
                    if (addr_phase)
393
                    begin
394
                        norm_access_to_conf_reg <= #`FF_DELAY norm_access_to_config_in ;
395
                        cnf_progress            <= #`FF_DELAY config_access ;
396
                    end
397
                end
398
            end
399
    `endif
400
`else
401
            reg     norm_access_to_conf_reg ;
402
            reg     cnf_progress ;
403
            always@(posedge clk_in or posedge reset_in)
404
            begin
405
                if (reset_in)
406
                begin
407
                    norm_access_to_conf_reg     <= #`FF_DELAY 1'b0 ;
408
                    cnf_progress                <= #`FF_DELAY 1'b0 ;
409
                end
410
                else
411
                begin
412
                    if (addr_phase)
413
                    begin
414
                        norm_access_to_conf_reg <= #`FF_DELAY norm_access_to_config_in ;
415
                        cnf_progress            <= #`FF_DELAY config_access ;
416
                    end
417
                end
418
            end
419
`endif
420
 
421 2 mihad
// Signal used in S_WAIT state to determin next state
422 21 mihad
wire s_wait_progress =  (
423
                        (~cnf_progress && rw_cbe0 && wr_progress && ~target_abort_in) ||
424
                        (~cnf_progress && ~rw_cbe0 && same_read_reg && rd_progress && ~target_abort_in && ~pcir_fifo_data_err_in) ||
425
                        (~cnf_progress && ~rw_cbe0 && ~same_read_reg && norm_access_to_conf_reg && ~target_abort_in) ||
426
                        (cnf_progress && ~target_abort_in)
427
                        ) ;
428 2 mihad
 
429
// Signal used in S_TRANSFERE state to determin next state
430 21 mihad
wire s_tran_progress =  (
431
                        (rw_cbe0 && !disconect_wo_data) ||
432
                        (~rw_cbe0 && !disconect_wo_data && !target_abort_in && !pcir_fifo_data_err_in)
433
                        ) ;
434
 
435 2 mihad
// Clock enable for PCI state machine driven directly from critical inputs - FRAME and IRDY
436 21 mihad
wire            pcit_sm_clk_en ;
437 2 mihad
// FSM states signals indicating the current state
438 21 mihad
reg             state_idle ;
439
reg             state_wait ;
440
reg             sm_transfere ;
441
reg             backoff ;
442
reg             state_default ;
443
wire            state_backoff   = sm_transfere && backoff ;
444
wire            state_transfere = sm_transfere && !backoff ;
445
 
446
always@(posedge clk_in or posedge reset_in)
447
begin
448
    if ( reset_in )
449
        backoff <= #`FF_DELAY 1'b0 ;
450
    else if ( state_idle )
451
        backoff <= #`FF_DELAY 1'b0 ;
452
    else
453
        backoff <= #`FF_DELAY (state_wait && !s_wait_progress) ||
454
                              (sm_transfere && !s_tran_progress && !pci_frame_in && !pci_irdy_in) ||
455
                              backoff ;
456
end
457
assign config_disconnect = sm_transfere && (norm_access_to_conf_reg || cnf_progress) ;
458
 
459 2 mihad
// Clock enable module used for preserving the architecture because of minimum delay for critical inputs
460 77 mihad
pci_target32_clk_en pci_target_clock_en
461 2 mihad
(
462 21 mihad
    .addr_phase             (addr_phase),
463
    .config_access          (config_access),
464
    .addr_claim_in          (addr_claim_in),
465
    .pci_frame_in           (pci_frame_in),
466
    .state_wait             (state_wait),
467
    .state_transfere        (sm_transfere),
468
    .state_default          (state_default),
469
    .clk_enable             (pcit_sm_clk_en)
470 2 mihad
);
471
 
472 56 mihad
reg [2:0]  c_state ; //current state register
473
reg [2:0]  n_state ; //next state input to current state register
474 2 mihad
 
475
// state machine register control
476
always@(posedge clk_in or posedge reset_in)
477
begin
478
    if (reset_in) // reset state machine to S_IDLE state
479
        c_state <= #`FF_DELAY S_IDLE ;
480
    else
481 21 mihad
        if (pcit_sm_clk_en) // if conditions are true, then FSM goes to next state!
482
            c_state <= #`FF_DELAY n_state ;
483
end
484 2 mihad
 
485
// state machine logic
486 21 mihad
always@(c_state)
487 2 mihad
begin
488 21 mihad
    case (c_state)
489
    S_IDLE :
490
    begin
491
        state_idle      <= 1'b1 ;
492
        state_wait      <= 1'b0 ;
493
        sm_transfere <= 1'b0 ;
494
        state_default   <= 1'b0 ;
495
        n_state <= S_WAIT ;
496
    end
497
    S_WAIT :
498
    begin
499
        state_idle      <= 1'b0 ;
500
        state_wait      <= 1'b1 ;
501
        sm_transfere <= 1'b0 ;
502
        state_default   <= 1'b0 ;
503
        n_state <= S_TRANSFERE ;
504
    end
505
    S_TRANSFERE :
506
    begin
507
        state_idle      <= 1'b0 ;
508
        state_wait      <= 1'b0 ;
509
        sm_transfere <= 1'b1 ;
510
        state_default   <= 1'b0 ;
511
        n_state <= S_IDLE ;
512
    end
513
    default :
514
    begin
515
        state_idle      <= 1'b0 ;
516
        state_wait      <= 1'b0 ;
517
        sm_transfere <= 1'b0 ;
518
        state_default   <= 1'b1 ;
519
        n_state <= S_IDLE ;
520
    end
521
    endcase
522 2 mihad
end
523
 
524
        // if not retry and not target abort
525
        // NO CRITICAL SIGNALS
526 21 mihad
wire    trdy_w          =   (
527
        (state_wait && ~cnf_progress && rw_cbe0 && wr_progress && ~target_abort_in) ||
528
        (state_wait && ~cnf_progress && ~rw_cbe0 && same_read_reg && rd_progress && ~target_abort_in && !pcir_fifo_data_err_in) ||
529
        (state_wait && ~cnf_progress && ~rw_cbe0 && ~same_read_reg && norm_access_to_conf_reg && ~target_abort_in) ||
530 2 mihad
        (state_wait && cnf_progress && ~target_abort_in)
531 21 mihad
                            ) ;
532 2 mihad
        // if not disconnect without data and not target abort (only during reads)
533
        // MUST BE ANDED WITH CRITICAL ~FRAME
534 21 mihad
wire    trdy_w_frm      =   (
535
        (state_transfere && !cnf_progress && !norm_access_to_conf_reg && rw_cbe0 && !disconect_wo_data) ||
536
        (state_transfere && !cnf_progress && !norm_access_to_conf_reg && ~rw_cbe0 && !disconect_wo_data && ~pcir_fifo_data_err_in) ||
537 108 tadejm
        (state_transfere && !cnf_progress && !norm_access_to_conf_reg && disconect_w_data && pci_irdy_reg_in &&
538
                                                                         ((~rw_cbe0 && ~pcir_fifo_data_err_in) || rw_cbe0))
539 21 mihad
                            ) ;
540 2 mihad
        // if not disconnect without data and not target abort (only during reads)
541
        // MUST BE ANDED WITH CRITICAL ~FRAME AND IRDY
542 21 mihad
wire    trdy_w_frm_irdy =   ( ~bckp_trdy_in ) ;
543 2 mihad
// TRDY critical module used for preserving the architecture because of minimum delay for critical inputs
544 77 mihad
pci_target32_trdy_crit pci_target_trdy_critical
545 2 mihad
(
546 21 mihad
    .trdy_w                 (trdy_w),
547
    .trdy_w_frm             (trdy_w_frm),
548
    .trdy_w_frm_irdy        (trdy_w_frm_irdy),
549
    .pci_frame_in           (pci_frame_in),
550
    .pci_irdy_in            (pci_irdy_in),
551
    .pci_trdy_out           (pci_trdy_out)
552 2 mihad
);
553
 
554 21 mihad
        // if target abort or retry
555 2 mihad
        // NO CRITICAL SIGNALS
556 21 mihad
wire    stop_w          =   (
557
        (state_wait && target_abort_in) ||
558
        (state_wait && ~cnf_progress && rw_cbe0 && ~wr_progress) ||
559
        (state_wait && ~cnf_progress && ~rw_cbe0 && same_read_reg && ~rd_progress) ||
560
        (state_wait && ~cnf_progress && ~rw_cbe0 && same_read_reg && rd_progress && pcir_fifo_data_err_in) ||
561
        (state_wait && ~cnf_progress && ~rw_cbe0 && ~same_read_reg && ~norm_access_to_conf_reg)
562
                            ) ;
563
        // if asserted, wait for deactivating the frame
564 2 mihad
        // MUST BE ANDED WITH CRITICAL ~FRAME
565 21 mihad
wire    stop_w_frm      =   (
566
        (state_backoff && ~bckp_stop_in)
567
                            ) ;
568
        // if target abort or if disconnect without data (after data transfere)
569 2 mihad
        // MUST BE ANDED WITH CRITICAL ~FRAME AND ~IRDY
570 21 mihad
wire    stop_w_frm_irdy =   (
571
        (state_transfere && (disconect_wo_data)) ||
572
        (state_transfere && ~rw_cbe0 && pcir_fifo_data_err_in)
573
                            ) ;
574 2 mihad
// STOP critical module used for preserving the architecture because of minimum delay for critical inputs
575 77 mihad
pci_target32_stop_crit pci_target_stop_critical
576 2 mihad
(
577 21 mihad
    .stop_w                 (stop_w),
578
    .stop_w_frm             (stop_w_frm),
579
    .stop_w_frm_irdy        (stop_w_frm_irdy),
580
    .pci_frame_in           (pci_frame_in),
581
    .pci_irdy_in            (pci_irdy_in),
582
    .pci_stop_out           (pci_stop_out)
583 2 mihad
);
584
 
585 21 mihad
        // if OK to respond and not target abort
586 2 mihad
        // NO CRITICAL SIGNALS
587 21 mihad
wire    devs_w          =   (
588
        (addr_phase && config_access) ||
589
        (addr_phase && ~config_access && addr_claim_in) ||
590
        (state_wait && ~target_abort_in && !(~cnf_progress && ~rw_cbe0 && same_read_reg && rd_progress && pcir_fifo_data_err_in) )
591
                            ) ;
592
 
593
        // if not target abort (only during reads) or if asserted, wait for deactivating the frame
594 2 mihad
        // MUST BE ANDED WITH CRITICAL ~FRAME
595 21 mihad
wire    devs_w_frm      =   (
596
        (state_transfere && rw_cbe0) ||
597
        (state_transfere && ~rw_cbe0 && ~pcir_fifo_data_err_in) ||
598
        (state_backoff && ~bckp_devsel_in)
599
                            ) ;
600
        // if not target abort (only during reads)
601 2 mihad
        // MUST BE ANDED WITH CRITICAL ~FRAME AND IRDY
602 21 mihad
wire    devs_w_frm_irdy =   (
603
        (state_transfere && ~rw_cbe0 && pcir_fifo_data_err_in)
604
                            ) ;
605 2 mihad
// DEVSEL critical module used for preserving the architecture because of minimum delay for critical inputs
606 77 mihad
pci_target32_devs_crit pci_target_devsel_critical
607 2 mihad
(
608 21 mihad
    .devs_w                 (devs_w),
609
    .devs_w_frm             (devs_w_frm),
610
    .devs_w_frm_irdy        (devs_w_frm_irdy),
611
    .pci_frame_in           (pci_frame_in),
612
    .pci_irdy_in            (pci_irdy_in),
613
    .pci_devsel_out         (pci_devsel_out)
614 2 mihad
);
615
 
616 21 mihad
// signal used in AD enable module with preserving the hierarchy because of minimum delay for critical inputs
617
assign  pci_ad_en_out =    (
618
        (addr_phase && config_access && ~pci_cbe_reg_in[0]) ||
619
        (addr_phase && ~config_access && addr_claim_in && ~pci_cbe_reg_in[0]) ||
620
        (state_wait && ~rw_cbe0) ||
621
        (state_transfere && ~rw_cbe0) ||
622
        (state_backoff && ~rw_cbe0 && ~pci_frame_reg_in)
623
                            ) ;
624 2 mihad
 
625 21 mihad
wire fast_back_to_back  =   (addr_phase && ~pci_irdy_reg_in) ;
626 2 mihad
 
627 21 mihad
        // if cycle will progress or will not be stopped
628 2 mihad
        // NO CRITICAL SIGNALS
629 21 mihad
wire    ctrl_en       =
630
        /*(~wbu_frame_en_in && fast_back_to_back) ||*/
631
        (addr_phase && config_access) ||
632
        (addr_phase && ~config_access && addr_claim_in) ||
633
        (state_wait) ||
634
        (state_transfere && ~(pci_frame_reg_in && ~pci_irdy_reg_in && (~pci_stop_reg_in || ~pci_trdy_reg_in))) ||
635
        (state_backoff && ~(pci_frame_reg_in && ~pci_irdy_reg_in && (~pci_stop_reg_in || ~pci_trdy_reg_in))) ;
636 2 mihad
 
637 21 mihad
assign pci_trdy_en_out   = ctrl_en ;
638
assign pci_stop_en_out   = ctrl_en ;
639
assign pci_devsel_en_out = ctrl_en ;
640
 
641 2 mihad
// target ready output signal delayed for one clock used in conjunction with irdy_reg to select which
642
//   data are registered in io mux module - from fifo or medoum register
643 21 mihad
reg             bckp_trdy_reg ;
644 2 mihad
// delayed indicators for states transfere and backoff
645 21 mihad
reg             state_transfere_reg ;
646
reg             state_backoff_reg ;
647 2 mihad
always@(posedge clk_in or posedge reset_in)
648
begin
649 21 mihad
    if (reset_in)
650 2 mihad
    begin
651 21 mihad
        bckp_trdy_reg <= #`FF_DELAY 1'b1 ;
652
        state_transfere_reg <= #`FF_DELAY 1'b0 ;
653
        state_backoff_reg <= #`FF_DELAY 1'b0 ;
654
    end
655
    else
656
    begin
657
        bckp_trdy_reg <= #`FF_DELAY bckp_trdy_in ;
658
        state_transfere_reg <= #`FF_DELAY state_transfere ;
659
        state_backoff_reg <= #`FF_DELAY state_backoff ;
660
    end
661 2 mihad
end
662
 
663
// Read control signals assignments
664 21 mihad
assign
665
    fetch_pcir_fifo_out =   (
666
        (prepare_rd_fifo_data) ||
667
        (state_wait && ~cnf_progress && ~rw_cbe0 && same_read_reg && rd_from_fifo && ~target_abort_in) ||
668
        (bckp_trdy_en_in && ~pci_trdy_reg_in && ~cnf_progress && ~rw_cbe0 && same_read_reg && rd_from_fifo && ~pci_irdy_reg_in)
669
                            ) ;
670 2 mihad
 
671 21 mihad
assign  ad_load_out         =   (state_wait) ;
672 2 mihad
 
673 21 mihad
assign  ad_load_on_transfer_out = (bckp_trdy_en_in && ~rw_cbe0) ;
674 2 mihad
 
675 21 mihad
assign  load_medium_reg_out =   (
676
        (prepare_rd_fifo_data) ||
677
        (state_wait && ~rw_cbe0 && ~cnf_progress && same_read_reg && rd_from_fifo && ~target_abort_in) ||
678
        (~pci_irdy_reg_in && ~rw_cbe0 && ~cnf_progress && same_read_reg && rd_from_fifo && ~pci_trdy_reg_in && bckp_trdy_en_in)
679
                                ) ;
680 2 mihad
 
681 21 mihad
assign  sel_fifo_mreg_out = (~pci_irdy_reg_in && ~bckp_trdy_reg) ;
682 2 mihad
 
683 21 mihad
`ifdef      HOST
684
    `ifdef  NO_CNF_IMAGE
685
            assign  sel_conf_fifo_out = 1'b0 ;
686
    `else
687
            assign  sel_conf_fifo_out = (cnf_progress || norm_access_to_conf_reg) ;
688
    `endif
689
`else
690
            assign  sel_conf_fifo_out = (cnf_progress || norm_access_to_conf_reg) ;
691
`endif
692
 
693 2 mihad
// Write control signals assignments
694
assign
695 21 mihad
    load_to_pciw_fifo_out = (
696
        (state_wait && (~cnf_progress && ~norm_access_to_conf_reg) && rw_cbe0 && wr_to_fifo && ~target_abort_in) ||
697
        (state_transfere_reg && ~state_backoff && rw_cbe0 && wr_to_fifo /*&& ~disconect_wo_data_reg*/ && ~pci_irdy_reg_in && ~bckp_trdy_reg && (~cnf_progress && ~norm_access_to_conf_reg)) ||
698
        ((state_backoff || state_backoff_reg) && rw_cbe0 && wr_to_fifo && ~pci_irdy_reg_in && ~bckp_trdy_reg && (~cnf_progress && ~norm_access_to_conf_reg))
699
                            ) ;
700 2 mihad
 
701 21 mihad
`ifdef      HOST
702
    `ifdef  NO_CNF_IMAGE
703
            assign  load_to_conf_out =  1'b0 ;
704
    `else
705
            assign  load_to_conf_out =  (
706
            (state_transfere_reg && cnf_progress && rw_cbe0 && ~pci_irdy_reg_in && ~bckp_trdy_reg) ||
707
            (state_transfere_reg && norm_access_to_conf_reg && rw_cbe0 && ~pci_irdy_reg_in && ~bckp_trdy_reg)
708
                                        ) ;
709
    `endif
710
`else
711
            assign  load_to_conf_out =  (
712
            (state_transfere_reg && cnf_progress && rw_cbe0 && ~pci_irdy_reg_in && ~bckp_trdy_reg) ||
713
            (state_transfere_reg && norm_access_to_conf_reg && rw_cbe0 && ~pci_irdy_reg_in && ~bckp_trdy_reg)
714
                                        ) ;
715
`endif
716 2 mihad
 
717
// General control sigal assignments
718 21 mihad
assign  addr_phase_out = addr_phase ;
719
assign  last_reg_out = (pci_frame_reg_in && ~pci_irdy_reg_in) ;
720
assign  frame_reg_out = pci_frame_reg_in ;
721
assign  bckp_devsel_out = bckp_devsel_in ;
722
assign  bckp_trdy_out   = bckp_trdy_in ;
723
assign  bckp_stop_out   = bckp_stop_in ;
724
assign  target_abort_set_out = (bckp_devsel_in && bckp_trdy_in && ~bckp_stop_in && bckp_trdy_en_in) ;
725 2 mihad
// request signal for delayed sinc. module
726 21 mihad
reg master_will_request_read ;
727
always@(posedge clk_in or posedge reset_in)
728
begin
729
    if ( reset_in )
730
        master_will_request_read <= #`FF_DELAY 1'b0 ;
731
    else
732 26 mihad
        master_will_request_read <= #`FF_DELAY ((state_wait && ~target_abort_in) || (state_backoff && ~target_abort_set_out)) && ~cnf_progress && ~norm_access_to_conf_reg && ~rw_cbe0 && rd_request ;
733 21 mihad
end
734
// MORE OPTIMIZED READS, but not easy to control in a testbench!
735
//assign  req_out = master_will_request_read ; 
736
assign req_out = master_will_request_read && !pci_irdy_reg_in && !read_processing_in ;
737
 
738 2 mihad
// ready tells when address or data are written into fifo - RDY ? DATA : ADDRESS
739 21 mihad
assign  rdy_out = ~bckp_trdy_reg ;
740 2 mihad
 
741
// data and address outputs assignments!
742 21 mihad
assign  pci_ad_out = data_in ;
743 2 mihad
 
744 21 mihad
assign  data_out = pci_ad_reg_in ;
745
assign  be_out = pci_cbe_reg_in ;
746 108 tadejm
assign  next_be_out = pci_cbe_in ;
747 21 mihad
assign  address_out = pci_ad_reg_in ;
748
assign  bc_out = pci_cbe_reg_in ;
749
assign  bc0_out = rw_cbe0 ;
750 2 mihad
 
751
 
752 21 mihad
endmodule

powered by: WebSVN 2.1.0

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