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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_7/] [rtl/] [verilog/] [pci_target32_sm.v] - Blame information for rev 154

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

powered by: WebSVN 2.1.0

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