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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [pci_target32_sm.v] - Blame information for rev 56

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

powered by: WebSVN 2.1.0

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