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 21

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

powered by: WebSVN 2.1.0

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