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 51

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

powered by: WebSVN 2.1.0

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