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 26

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

powered by: WebSVN 2.1.0

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