| 1 |
2 |
mihad |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// File name "pci_master32_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 |
|
|
//// - Miha Dolenc (mihad@opencores.org) ////
|
| 10 |
|
|
//// ////
|
| 11 |
|
|
//// All additional information is avaliable in the README ////
|
| 12 |
|
|
//// file. ////
|
| 13 |
|
|
//// ////
|
| 14 |
|
|
//// ////
|
| 15 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 16 |
|
|
//// ////
|
| 17 |
|
|
//// Copyright (C) 2001 Miha Dolenc, mihad@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:29 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:46 mihad
|
| 49 |
|
|
// New project directory structure
|
| 50 |
2 |
mihad |
//
|
| 51 |
6 |
mihad |
//
|
| 52 |
2 |
mihad |
|
| 53 |
|
|
// module includes pci master state machine and surrounding logic
|
| 54 |
21 |
mihad |
|
| 55 |
|
|
// synopsys translate_off
|
| 56 |
6 |
mihad |
`include "timescale.v"
|
| 57 |
21 |
mihad |
// synopsys translate_on
|
| 58 |
|
|
`include "pci_constants.v"
|
| 59 |
6 |
mihad |
|
| 60 |
2 |
mihad |
module PCI_MASTER32_SM
|
| 61 |
|
|
(
|
| 62 |
|
|
// system inputs
|
| 63 |
|
|
clk_in,
|
| 64 |
|
|
reset_in,
|
| 65 |
|
|
// arbitration
|
| 66 |
|
|
pci_req_out,
|
| 67 |
|
|
pci_gnt_in,
|
| 68 |
|
|
// master in/outs
|
| 69 |
|
|
pci_frame_in,
|
| 70 |
|
|
pci_frame_out,
|
| 71 |
|
|
pci_frame_out_in,
|
| 72 |
|
|
pci_frame_load_out,
|
| 73 |
|
|
pci_frame_en_in,
|
| 74 |
|
|
pci_frame_en_out,
|
| 75 |
|
|
pci_irdy_in,
|
| 76 |
|
|
pci_irdy_out,
|
| 77 |
|
|
pci_irdy_en_out,
|
| 78 |
21 |
mihad |
|
| 79 |
2 |
mihad |
// target response inputs
|
| 80 |
|
|
pci_trdy_in,
|
| 81 |
|
|
pci_trdy_reg_in,
|
| 82 |
|
|
pci_stop_in,
|
| 83 |
|
|
pci_stop_reg_in,
|
| 84 |
|
|
pci_devsel_in,
|
| 85 |
|
|
pci_devsel_reg_in,
|
| 86 |
|
|
|
| 87 |
|
|
// address, data, bus command, byte enable in/outs
|
| 88 |
|
|
pci_ad_reg_in,
|
| 89 |
|
|
pci_ad_out,
|
| 90 |
|
|
pci_ad_en_out,
|
| 91 |
|
|
pci_cbe_out,
|
| 92 |
|
|
pci_cbe_en_out,
|
| 93 |
|
|
|
| 94 |
|
|
// other side of state machine
|
| 95 |
|
|
address_in,
|
| 96 |
|
|
bc_in,
|
| 97 |
|
|
data_in,
|
| 98 |
|
|
data_out,
|
| 99 |
|
|
be_in,
|
| 100 |
|
|
req_in,
|
| 101 |
|
|
rdy_in,
|
| 102 |
|
|
last_in,
|
| 103 |
|
|
next_data_in,
|
| 104 |
|
|
next_be_in,
|
| 105 |
|
|
next_last_in,
|
| 106 |
21 |
mihad |
ad_load_out,
|
| 107 |
|
|
ad_load_on_transfer_out,
|
| 108 |
2 |
mihad |
wait_out,
|
| 109 |
|
|
wtransfer_out,
|
| 110 |
|
|
rtransfer_out,
|
| 111 |
|
|
retry_out,
|
| 112 |
|
|
rerror_out,
|
| 113 |
|
|
first_out,
|
| 114 |
|
|
mabort_out,
|
| 115 |
|
|
latency_tim_val_in
|
| 116 |
|
|
) ;
|
| 117 |
|
|
|
| 118 |
|
|
// system inputs
|
| 119 |
|
|
input clk_in,
|
| 120 |
|
|
reset_in ;
|
| 121 |
|
|
|
| 122 |
|
|
/*==================================================================================================================
|
| 123 |
|
|
PCI interface signals - bidirectional signals are divided to inputs and outputs in I/O cells instantiation
|
| 124 |
|
|
module. Enables are separate signals.
|
| 125 |
|
|
==================================================================================================================*/
|
| 126 |
|
|
// arbitration
|
| 127 |
|
|
output pci_req_out ;
|
| 128 |
|
|
|
| 129 |
|
|
input pci_gnt_in ;
|
| 130 |
|
|
|
| 131 |
|
|
// master in/outs
|
| 132 |
|
|
input pci_frame_in ;
|
| 133 |
|
|
input pci_frame_en_in ;
|
| 134 |
|
|
input pci_frame_out_in ;
|
| 135 |
|
|
|
| 136 |
|
|
output pci_frame_out,
|
| 137 |
|
|
pci_frame_en_out ;
|
| 138 |
|
|
|
| 139 |
|
|
output pci_frame_load_out ;
|
| 140 |
|
|
|
| 141 |
|
|
input pci_irdy_in ;
|
| 142 |
|
|
output pci_irdy_out,
|
| 143 |
|
|
pci_irdy_en_out;
|
| 144 |
21 |
mihad |
|
| 145 |
2 |
mihad |
// target response inputs
|
| 146 |
|
|
input pci_trdy_in,
|
| 147 |
|
|
pci_trdy_reg_in,
|
| 148 |
|
|
pci_stop_in,
|
| 149 |
|
|
pci_stop_reg_in,
|
| 150 |
|
|
pci_devsel_in,
|
| 151 |
|
|
pci_devsel_reg_in ;
|
| 152 |
21 |
mihad |
|
| 153 |
2 |
mihad |
// address, data, bus command, byte enable in/outs
|
| 154 |
|
|
input [31:0] pci_ad_reg_in ;
|
| 155 |
|
|
output [31:0] pci_ad_out ;
|
| 156 |
|
|
|
| 157 |
|
|
reg [31:0] pci_ad_out ;
|
| 158 |
|
|
|
| 159 |
|
|
output pci_ad_en_out ;
|
| 160 |
|
|
|
| 161 |
|
|
output [3:0] pci_cbe_out ;
|
| 162 |
|
|
|
| 163 |
|
|
reg [3:0] pci_cbe_out ;
|
| 164 |
|
|
|
| 165 |
|
|
output pci_cbe_en_out ;
|
| 166 |
|
|
|
| 167 |
|
|
input [31:0] address_in ; // current request address input
|
| 168 |
|
|
|
| 169 |
|
|
input [3:0] bc_in ; // current request bus command input
|
| 170 |
|
|
|
| 171 |
|
|
input [31:0] data_in ; // current dataphase data input
|
| 172 |
|
|
|
| 173 |
|
|
output [31:0] data_out ; // for read operations - current request data output
|
| 174 |
|
|
|
| 175 |
21 |
mihad |
reg [31:0] data_out ;
|
| 176 |
2 |
mihad |
|
| 177 |
|
|
input [3:0] be_in ; // current dataphase byte enable inputs
|
| 178 |
|
|
|
| 179 |
|
|
input req_in ; // initiator cycle is requested
|
| 180 |
|
|
input rdy_in ; // requestor indicates that data is ready to be sent for write transaction and ready to
|
| 181 |
|
|
// be received on read transaction
|
| 182 |
|
|
input last_in ; // last dataphase in current transaction indicator
|
| 183 |
|
|
|
| 184 |
|
|
// status outputs
|
| 185 |
|
|
output wait_out, // wait indicates to the backend that dataphases are not in progress on PCI bus
|
| 186 |
|
|
wtransfer_out, // on any rising clock edge that this status is 1, data is transferred - heavy constraints here
|
| 187 |
|
|
rtransfer_out, // registered transfer indicator - when 1 indicates that data was transfered on previous clock cycle
|
| 188 |
|
|
retry_out, // retry status output - when target signals a retry
|
| 189 |
|
|
rerror_out, // registered error output - when 1 indicates that error was signalled by a target on previous clock cycle
|
| 190 |
|
|
first_out , // indicates whether or not any data was transfered in current transaction
|
| 191 |
|
|
mabort_out; // master abort indicator
|
| 192 |
|
|
|
| 193 |
|
|
reg wait_out ;
|
| 194 |
|
|
|
| 195 |
|
|
// latency timer value input - state machine starts latency timer whenever it starts a transaction and last is not
|
| 196 |
21 |
mihad |
// asserted ( meaning burst transfer ).
|
| 197 |
2 |
mihad |
input [7:0] latency_tim_val_in ;
|
| 198 |
|
|
|
| 199 |
|
|
// next data, byte enable and last inputs
|
| 200 |
|
|
input [31:0] next_data_in ;
|
| 201 |
|
|
input [3:0] next_be_in ;
|
| 202 |
|
|
input next_last_in ;
|
| 203 |
|
|
|
| 204 |
|
|
// clock enable for data output flip-flops - whenever data is transfered, sm loads next data to those flip flops
|
| 205 |
21 |
mihad |
output ad_load_out,
|
| 206 |
|
|
ad_load_on_transfer_out ;
|
| 207 |
2 |
mihad |
|
| 208 |
|
|
// parameters - states - one hot
|
| 209 |
|
|
// idle state
|
| 210 |
|
|
parameter S_IDLE = 4'h1 ;
|
| 211 |
|
|
|
| 212 |
|
|
// address state
|
| 213 |
|
|
parameter S_ADDRESS = 4'h2 ;
|
| 214 |
|
|
|
| 215 |
|
|
// transfer state - dataphases
|
| 216 |
|
|
parameter S_TRANSFER = 4'h4 ;
|
| 217 |
|
|
|
| 218 |
|
|
// turn arround state
|
| 219 |
|
|
parameter S_TA_END = 4'h8 ;
|
| 220 |
|
|
|
| 221 |
|
|
// change state - clock enable for sm state register
|
| 222 |
|
|
wire change_state ;
|
| 223 |
|
|
// next state for state machine
|
| 224 |
|
|
reg [4:0] next_state ;
|
| 225 |
|
|
// SM state register
|
| 226 |
|
|
reg [4:0] cur_state ;
|
| 227 |
|
|
|
| 228 |
|
|
// variables for indicating which state state machine is in
|
| 229 |
|
|
// this variables are used to reduce logic levels in case of heavily constrained PCI signals
|
| 230 |
|
|
reg sm_idle ;
|
| 231 |
|
|
reg sm_address ;
|
| 232 |
|
|
reg sm_data_phases ;
|
| 233 |
|
|
reg sm_turn_arround ;
|
| 234 |
|
|
|
| 235 |
|
|
// state machine register control logic with clock enable
|
| 236 |
|
|
always@(posedge reset_in or posedge clk_in)
|
| 237 |
|
|
begin
|
| 238 |
|
|
if (reset_in)
|
| 239 |
|
|
cur_state <= #`FF_DELAY S_IDLE ;
|
| 240 |
|
|
else
|
| 241 |
|
|
if ( change_state )
|
| 242 |
|
|
cur_state <= #`FF_DELAY next_state ;
|
| 243 |
|
|
end
|
| 244 |
|
|
|
| 245 |
|
|
// parameters - data selector - ad and bc lines switch between address/data and bus command/byte enable respectively
|
| 246 |
|
|
parameter SEL_ADDR_BC = 2'b01 ;
|
| 247 |
|
|
parameter SEL_DATA_BE = 2'b00 ;
|
| 248 |
|
|
parameter SEL_NEXT_DATA_BE = 2'b11 ;
|
| 249 |
|
|
|
| 250 |
|
|
reg [1:0] wdata_selector ;
|
| 251 |
|
|
|
| 252 |
|
|
wire u_dont_have_pci_bus = pci_gnt_in || ~pci_frame_in || ~pci_irdy_in ; // pci master can't start a transaction when GNT is deasserted ( 1 ) or
|
| 253 |
|
|
// bus is not in idle state ( FRAME and IRDY both 1 )
|
| 254 |
|
|
wire u_have_pci_bus = ~pci_gnt_in && pci_frame_in && pci_irdy_in ;
|
| 255 |
|
|
|
| 256 |
|
|
// decode count enable - counter that counts cycles passed since address phase
|
| 257 |
21 |
mihad |
wire sm_decode_count_enable = sm_data_phases ; // counter is enabled when master wants to transfer
|
| 258 |
2 |
mihad |
wire decode_count_enable = sm_decode_count_enable && pci_trdy_in && pci_stop_in && pci_devsel_in ; // and target is not responding
|
| 259 |
21 |
mihad |
wire decode_count_load = ~decode_count_enable ;
|
| 260 |
2 |
mihad |
reg [2:0] decode_count ;
|
| 261 |
|
|
|
| 262 |
|
|
wire decode_to = ~( decode_count[2] || decode_count[1]) ;
|
| 263 |
|
|
|
| 264 |
|
|
always@(posedge reset_in or posedge clk_in)
|
| 265 |
|
|
begin
|
| 266 |
|
|
if ( reset_in )
|
| 267 |
|
|
// initial value of counter is 4
|
| 268 |
|
|
decode_count <= #`FF_DELAY 3'h4 ;
|
| 269 |
|
|
else
|
| 270 |
|
|
if ( decode_count_load )
|
| 271 |
|
|
decode_count <= #`FF_DELAY 3'h4 ;
|
| 272 |
|
|
else
|
| 273 |
|
|
if ( decode_count_enable )
|
| 274 |
|
|
decode_count <= #`FF_DELAY decode_count - 1'b1 ;
|
| 275 |
|
|
end
|
| 276 |
|
|
|
| 277 |
|
|
// Bus commands LSbit indicates whether operation is a read or a write
|
| 278 |
|
|
wire do_write = bc_in[0] ;
|
| 279 |
|
|
|
| 280 |
|
|
// latency timer
|
| 281 |
|
|
reg [7:0] latency_timer ;
|
| 282 |
|
|
|
| 283 |
21 |
mihad |
wire latency_time_out = ~(
|
| 284 |
|
|
(latency_timer[7] || latency_timer[6] || latency_timer[5] || latency_timer[4]) ||
|
| 285 |
|
|
(latency_timer[3] || latency_timer[2] || latency_timer[1] )
|
| 286 |
|
|
) ;
|
| 287 |
2 |
mihad |
|
| 288 |
21 |
mihad |
wire latency_timer_enable = (sm_address || sm_data_phases) && ~latency_time_out ;
|
| 289 |
2 |
mihad |
wire latency_timer_load = ~sm_address && ~sm_data_phases ;
|
| 290 |
|
|
|
| 291 |
|
|
always@(posedge clk_in or posedge reset_in)
|
| 292 |
|
|
begin
|
| 293 |
|
|
if (reset_in)
|
| 294 |
21 |
mihad |
latency_timer <= #`FF_DELAY 8'h00 ;
|
| 295 |
2 |
mihad |
else
|
| 296 |
|
|
if ( latency_timer_load )
|
| 297 |
|
|
latency_timer <= #`FF_DELAY latency_tim_val_in ;
|
| 298 |
|
|
else
|
| 299 |
21 |
mihad |
if ( latency_timer_enable) // latency timer counts down until it expires - then it stops
|
| 300 |
2 |
mihad |
latency_timer <= #`FF_DELAY latency_timer - 1'b1 ;
|
| 301 |
|
|
end
|
| 302 |
|
|
|
| 303 |
|
|
// master abort indicators - when decode time out occurres and still no target response is received
|
| 304 |
|
|
wire do_master_abort = decode_to && pci_trdy_in && pci_stop_in && pci_devsel_in ;
|
| 305 |
|
|
reg mabort1 ;
|
| 306 |
|
|
always@(posedge reset_in or posedge clk_in)
|
| 307 |
|
|
begin
|
| 308 |
|
|
if (reset_in)
|
| 309 |
|
|
mabort1 <= #`FF_DELAY 1'b0 ;
|
| 310 |
|
|
else
|
| 311 |
|
|
mabort1 <= #`FF_DELAY do_master_abort ;
|
| 312 |
|
|
end
|
| 313 |
|
|
|
| 314 |
|
|
reg mabort2 ;
|
| 315 |
|
|
always@(posedge reset_in or posedge clk_in)
|
| 316 |
|
|
begin
|
| 317 |
|
|
if ( reset_in )
|
| 318 |
|
|
mabort2 <= #`FF_DELAY 1'b0 ;
|
| 319 |
|
|
else
|
| 320 |
|
|
mabort2 <= #`FF_DELAY mabort1 ;
|
| 321 |
|
|
end
|
| 322 |
|
|
|
| 323 |
|
|
// master abort is only asserted for one clock cycle
|
| 324 |
|
|
assign mabort_out = mabort1 && ~mabort2 ;
|
| 325 |
|
|
|
| 326 |
|
|
// register indicating when master should do timeout termination (latency timer expires)
|
| 327 |
|
|
reg timeout ;
|
| 328 |
|
|
always@(posedge reset_in or posedge clk_in)
|
| 329 |
|
|
begin
|
| 330 |
|
|
if (reset_in)
|
| 331 |
|
|
timeout <= #`FF_DELAY 1'b0 ;
|
| 332 |
21 |
mihad |
else
|
| 333 |
2 |
mihad |
timeout <= #`FF_DELAY (latency_time_out && ~pci_frame_out_in && pci_gnt_in || timeout ) && ~wait_out ;
|
| 334 |
|
|
end
|
| 335 |
|
|
|
| 336 |
|
|
wire timeout_termination = sm_turn_arround && timeout && pci_stop_reg_in ;
|
| 337 |
|
|
|
| 338 |
|
|
// frame control logic
|
| 339 |
|
|
// frame is forced to 0 (active) when state machine is in idle state, since only possible next state is address state which always drives frame active
|
| 340 |
|
|
wire force_frame = ~sm_idle ;
|
| 341 |
|
|
// slow signal for frame calculated from various registers in the core
|
| 342 |
21 |
mihad |
wire slow_frame = last_in || (latency_time_out && pci_gnt_in) || (next_last_in && sm_data_phases) || mabort1 ;
|
| 343 |
2 |
mihad |
// critical timing frame logic in separate module - some combinations of target signals force frame to inactive state immediately after sampled asserted
|
| 344 |
|
|
// (STOP)
|
| 345 |
|
|
FRAME_CRIT frame_iob_feed
|
| 346 |
|
|
(
|
| 347 |
|
|
.pci_frame_out (pci_frame_out),
|
| 348 |
|
|
.force_frame_in (force_frame),
|
| 349 |
|
|
.slow_frame_in (slow_frame),
|
| 350 |
|
|
.pci_stop_in (pci_stop_in)
|
| 351 |
|
|
) ;
|
| 352 |
|
|
|
| 353 |
|
|
// frame IOB flip flop's clock enable signal
|
| 354 |
|
|
// slow clock enable - calculated from internal - non critical paths
|
| 355 |
|
|
wire frame_load_slow = sm_idle || sm_address || mabort1 ;
|
| 356 |
|
|
|
| 357 |
|
|
// critical clock enable for frame IOB in separate module - target response signals actually allow frame value change - critical timing
|
| 358 |
|
|
FRAME_LOAD_CRIT frame_iob_ce
|
| 359 |
|
|
(
|
| 360 |
|
|
.pci_frame_load_out (pci_frame_load_out),
|
| 361 |
|
|
.sm_data_phases_in (sm_data_phases),
|
| 362 |
|
|
.frame_load_slow_in (frame_load_slow),
|
| 363 |
|
|
.pci_trdy_in (pci_trdy_in),
|
| 364 |
|
|
.pci_stop_in (pci_stop_in)
|
| 365 |
|
|
) ;
|
| 366 |
|
|
|
| 367 |
|
|
// IRDY driving
|
| 368 |
|
|
// non critical path for IRDY calculation
|
| 369 |
|
|
wire irdy_slow = pci_frame_out_in && mabort1 || mabort2 ;
|
| 370 |
|
|
|
| 371 |
|
|
// critical path in separate module
|
| 372 |
|
|
IRDY_OUT_CRIT irdy_iob_feed
|
| 373 |
|
|
(
|
| 374 |
|
|
.pci_irdy_out (pci_irdy_out),
|
| 375 |
|
|
.irdy_slow_in (irdy_slow),
|
| 376 |
|
|
.pci_frame_out_in (pci_frame_out_in),
|
| 377 |
|
|
.pci_trdy_in (pci_trdy_in),
|
| 378 |
|
|
.pci_stop_in (pci_stop_in)
|
| 379 |
|
|
) ;
|
| 380 |
21 |
mihad |
|
| 381 |
2 |
mihad |
// transfer FF indicator - when first transfer occurs it is set to 1 so backend can distinguish between disconnects and retries.
|
| 382 |
|
|
wire sm_transfer = sm_data_phases ;
|
| 383 |
|
|
reg transfer ;
|
| 384 |
|
|
|
| 385 |
|
|
wire transfer_input = sm_transfer && (~(pci_trdy_in || pci_devsel_in) || transfer) ;
|
| 386 |
|
|
|
| 387 |
|
|
always@(posedge clk_in or posedge reset_in)
|
| 388 |
|
|
begin
|
| 389 |
|
|
if (reset_in)
|
| 390 |
|
|
transfer <= #`FF_DELAY 1'b0 ;
|
| 391 |
|
|
else
|
| 392 |
|
|
transfer <= #`FF_DELAY transfer_input ;
|
| 393 |
|
|
end
|
| 394 |
|
|
|
| 395 |
|
|
assign first_out = ~transfer ;
|
| 396 |
|
|
|
| 397 |
|
|
// fast transfer status output - it's only negated target ready, since wait indicator qualifies valid transfer
|
| 398 |
|
|
assign wtransfer_out = ~pci_trdy_in ;
|
| 399 |
|
|
|
| 400 |
|
|
// registered transfer status output - calculated from registered target response inputs
|
| 401 |
|
|
assign rtransfer_out = ~(pci_trdy_reg_in || pci_devsel_reg_in) ;
|
| 402 |
|
|
|
| 403 |
|
|
// registered error status - calculated from registered target response inputs
|
| 404 |
|
|
assign rerror_out = (~pci_stop_reg_in && pci_devsel_reg_in) ;
|
| 405 |
|
|
|
| 406 |
|
|
// retry is signalled to backend depending on registered target response or when latency timer expires
|
| 407 |
|
|
assign retry_out = timeout_termination || (~pci_stop_reg_in && ~pci_devsel_reg_in) ;
|
| 408 |
|
|
|
| 409 |
|
|
// AD output flip flops' clock enable
|
| 410 |
|
|
// new data is loaded to AD outputs whenever state machine is idle, bus was granted and bus is in idle state or
|
| 411 |
|
|
// when address phase is about to be finished
|
| 412 |
21 |
mihad |
wire ad_load_slow = sm_address ;
|
| 413 |
|
|
wire ad_load_on_grant = sm_idle && pci_frame_in && pci_irdy_in ;
|
| 414 |
2 |
mihad |
|
| 415 |
21 |
mihad |
MAS_AD_LOAD_CRIT mas_ad_load_feed
|
| 416 |
|
|
(
|
| 417 |
|
|
.ad_load_out (ad_load_out),
|
| 418 |
|
|
.ad_load_in (ad_load_slow),
|
| 419 |
|
|
.ad_load_on_grant_in (ad_load_on_grant),
|
| 420 |
|
|
.pci_gnt_in (pci_gnt_in)
|
| 421 |
|
|
);
|
| 422 |
|
|
|
| 423 |
2 |
mihad |
// next data loading is allowed when state machine is in transfer state and operation is a write
|
| 424 |
21 |
mihad |
assign ad_load_on_transfer_out = sm_data_phases && do_write ;
|
| 425 |
2 |
mihad |
|
| 426 |
|
|
// request for a bus is issued anytime when backend is requesting a transaction and state machine is in idle state
|
| 427 |
|
|
assign pci_req_out = ~(req_in && sm_idle) ;
|
| 428 |
|
|
|
| 429 |
|
|
// change state signal is actually clock enable for state register
|
| 430 |
|
|
// Non critical path for state change enable:
|
| 431 |
|
|
// state is always changed when:
|
| 432 |
|
|
// - address phase is finishing
|
| 433 |
|
|
// - state machine is in turn arround state
|
| 434 |
|
|
// - state machine is in transfer state and master abort termination is in progress
|
| 435 |
|
|
|
| 436 |
|
|
wire ch_state_slow = sm_address || sm_turn_arround || sm_data_phases && ( pci_frame_out_in && mabort1 || mabort2 ) ;
|
| 437 |
|
|
|
| 438 |
|
|
// a bit more critical change state enable is calculated with GNT signal
|
| 439 |
|
|
wire ch_state_med = ch_state_slow || sm_idle && u_have_pci_bus && req_in && rdy_in ;
|
| 440 |
|
|
|
| 441 |
|
|
// most critical change state enable - calculated from target response signals
|
| 442 |
|
|
MAS_CH_STATE_CRIT state_machine_ce
|
| 443 |
|
|
(
|
| 444 |
|
|
.change_state_out (change_state),
|
| 445 |
|
|
.ch_state_med_in (ch_state_med),
|
| 446 |
|
|
.sm_data_phases_in (sm_data_phases),
|
| 447 |
|
|
.pci_trdy_in (pci_trdy_in),
|
| 448 |
|
|
.pci_stop_in (pci_stop_in)
|
| 449 |
|
|
) ;
|
| 450 |
|
|
|
| 451 |
|
|
// ad enable driving
|
| 452 |
|
|
// also divided in several categories - from less critical to most critical in separate module
|
| 453 |
21 |
mihad |
//wire ad_en_slowest = do_write && (sm_address || sm_data_phases && ~pci_frame_out_in) ;
|
| 454 |
|
|
//wire ad_en_on_grant = sm_idle && pci_frame_in && pci_irdy_in || sm_turn_arround ;
|
| 455 |
|
|
//wire ad_en_slow = ad_en_on_grant && ~pci_gnt_in || ad_en_slowest ;
|
| 456 |
|
|
//wire ad_en_keep = sm_data_phases && do_write && (pci_frame_out_in && ~mabort1 && ~mabort2) ;
|
| 457 |
2 |
mihad |
|
| 458 |
21 |
mihad |
wire ad_en_slow = do_write && ( sm_address || ( sm_data_phases && !( ( pci_frame_out_in && mabort1 ) || mabort2 ) ) ) ;
|
| 459 |
|
|
wire ad_en_on_grant = ( sm_idle && pci_frame_in && pci_irdy_in ) || sm_turn_arround ;
|
| 460 |
|
|
|
| 461 |
|
|
// critical timing ad enable - calculated from grant input
|
| 462 |
2 |
mihad |
MAS_AD_EN_CRIT ad_iob_oe_feed
|
| 463 |
|
|
(
|
| 464 |
|
|
.pci_ad_en_out (pci_ad_en_out),
|
| 465 |
|
|
.ad_en_slow_in (ad_en_slow),
|
| 466 |
21 |
mihad |
.ad_en_on_grant_in (ad_en_on_grant),
|
| 467 |
|
|
.pci_gnt_in (pci_gnt_in)
|
| 468 |
2 |
mihad |
) ;
|
| 469 |
|
|
|
| 470 |
|
|
// cbe enable driving
|
| 471 |
|
|
wire cbe_en_on_grant = sm_idle && pci_frame_in && pci_irdy_in || sm_turn_arround ;
|
| 472 |
|
|
wire cbe_en_slow = cbe_en_on_grant && ~pci_gnt_in || sm_address || sm_data_phases && ~pci_frame_out_in ;
|
| 473 |
|
|
wire cbe_en_keep = sm_data_phases && pci_frame_out_in && ~mabort1 && ~mabort2 ;
|
| 474 |
|
|
|
| 475 |
|
|
// most critical cbe enable in separate module - calculated with most critical target inputs
|
| 476 |
|
|
CBE_EN_CRIT cbe_iob_feed
|
| 477 |
|
|
(
|
| 478 |
|
|
.pci_cbe_en_out (pci_cbe_en_out),
|
| 479 |
|
|
.cbe_en_slow_in (cbe_en_slow),
|
| 480 |
|
|
.cbe_en_keep_in (cbe_en_keep),
|
| 481 |
|
|
.pci_stop_in (pci_stop_in),
|
| 482 |
|
|
.pci_trdy_in (pci_trdy_in)
|
| 483 |
|
|
|
| 484 |
|
|
) ;
|
| 485 |
|
|
|
| 486 |
|
|
// IRDY enable is equal to FRAME enable delayed for one clock
|
| 487 |
|
|
assign pci_irdy_en_out = pci_frame_en_in ;
|
| 488 |
|
|
|
| 489 |
|
|
// frame enable driving - sometimes it's calculated from non critical paths
|
| 490 |
|
|
wire frame_en_slow = (sm_idle && u_have_pci_bus && req_in && rdy_in) || sm_address || (sm_data_phases && ~pci_frame_out_in) ;
|
| 491 |
|
|
wire frame_en_keep = sm_data_phases && pci_frame_out_in && ~mabort1 && ~mabort2 ;
|
| 492 |
|
|
|
| 493 |
|
|
// most critical frame enable - calculated from heavily constrained target inputs in separate module
|
| 494 |
|
|
FRAME_EN_CRIT frame_iob_en_feed
|
| 495 |
|
|
(
|
| 496 |
|
|
.pci_frame_en_out (pci_frame_en_out),
|
| 497 |
|
|
.frame_en_slow_in (frame_en_slow),
|
| 498 |
|
|
.frame_en_keep_in (frame_en_keep),
|
| 499 |
|
|
.pci_stop_in (pci_stop_in),
|
| 500 |
21 |
mihad |
.pci_trdy_in (pci_trdy_in)
|
| 501 |
2 |
mihad |
) ;
|
| 502 |
|
|
|
| 503 |
|
|
// state machine next state definitions
|
| 504 |
|
|
always@(
|
| 505 |
|
|
cur_state or
|
| 506 |
|
|
do_write or
|
| 507 |
|
|
pci_frame_out_in
|
| 508 |
|
|
)
|
| 509 |
|
|
begin
|
| 510 |
|
|
// default values for state machine outputs
|
| 511 |
|
|
wait_out = 1'b1 ;
|
| 512 |
|
|
wdata_selector = SEL_ADDR_BC ;
|
| 513 |
|
|
sm_idle = 1'b0 ;
|
| 514 |
|
|
sm_address = 1'b0 ;
|
| 515 |
|
|
sm_data_phases = 1'b0 ;
|
| 516 |
|
|
sm_turn_arround = 1'b0 ;
|
| 517 |
|
|
|
| 518 |
|
|
case ( cur_state )
|
| 519 |
|
|
|
| 520 |
|
|
S_IDLE: begin
|
| 521 |
|
|
// indicate the state
|
| 522 |
|
|
sm_idle = 1'b1 ;
|
| 523 |
|
|
// assign next state - only possible is address - if state machine is supposed to stay in idle state
|
| 524 |
|
|
// outside signals disable the clock
|
| 525 |
21 |
mihad |
next_state = S_ADDRESS ;
|
| 526 |
|
|
wdata_selector = SEL_DATA_BE ;
|
| 527 |
2 |
mihad |
end
|
| 528 |
|
|
|
| 529 |
|
|
S_ADDRESS: begin
|
| 530 |
|
|
// indicate the state
|
| 531 |
|
|
sm_address = 1'b1 ;
|
| 532 |
|
|
// select appropriate data/be for outputs
|
| 533 |
21 |
mihad |
wdata_selector = SEL_NEXT_DATA_BE ;
|
| 534 |
2 |
mihad |
// only possible next state is transfer state
|
| 535 |
|
|
next_state = S_TRANSFER ;
|
| 536 |
|
|
end
|
| 537 |
|
|
|
| 538 |
|
|
S_TRANSFER: begin
|
| 539 |
|
|
// during transfers wait indicator is inactive - all status signals are now valid
|
| 540 |
|
|
wait_out = 1'b0 ;
|
| 541 |
|
|
// indicate the state
|
| 542 |
|
|
sm_data_phases = 1'b1 ;
|
| 543 |
|
|
// select appropriate data/be for outputs
|
| 544 |
|
|
wdata_selector = SEL_NEXT_DATA_BE ;
|
| 545 |
|
|
if ( pci_frame_out_in )
|
| 546 |
|
|
begin
|
| 547 |
|
|
// when frame is inactive next state will be turn arround
|
| 548 |
|
|
next_state = S_TA_END ;
|
| 549 |
|
|
end
|
| 550 |
|
|
else
|
| 551 |
|
|
// while frame is active state cannot be anything else then transfer
|
| 552 |
|
|
next_state = S_TRANSFER ;
|
| 553 |
|
|
end
|
| 554 |
21 |
mihad |
|
| 555 |
2 |
mihad |
S_TA_END: begin
|
| 556 |
|
|
// wait is still inactive because of registered statuses
|
| 557 |
|
|
wait_out = 1'b0 ;
|
| 558 |
|
|
// indicate the state
|
| 559 |
|
|
sm_turn_arround = 1'b1 ;
|
| 560 |
|
|
// next state is always idle
|
| 561 |
|
|
next_state = S_IDLE ;
|
| 562 |
|
|
end
|
| 563 |
|
|
default: next_state = S_IDLE ;
|
| 564 |
|
|
endcase
|
| 565 |
|
|
end
|
| 566 |
|
|
|
| 567 |
|
|
// ad and cbe lines multiplexer for write data
|
| 568 |
21 |
mihad |
reg [1:0] rdata_selector ;
|
| 569 |
|
|
always@(posedge clk_in or posedge reset_in)
|
| 570 |
2 |
mihad |
begin
|
| 571 |
21 |
mihad |
if ( reset_in )
|
| 572 |
|
|
rdata_selector <= #`FF_DELAY SEL_ADDR_BC ;
|
| 573 |
|
|
else
|
| 574 |
|
|
if ( change_state )
|
| 575 |
|
|
rdata_selector <= #`FF_DELAY wdata_selector ;
|
| 576 |
|
|
end
|
| 577 |
|
|
|
| 578 |
|
|
always@(rdata_selector or address_in or bc_in or data_in or be_in or next_data_in or next_be_in)
|
| 579 |
|
|
begin
|
| 580 |
|
|
case ( rdata_selector )
|
| 581 |
2 |
mihad |
SEL_ADDR_BC: begin
|
| 582 |
|
|
pci_ad_out = address_in ;
|
| 583 |
|
|
pci_cbe_out = bc_in ;
|
| 584 |
|
|
end
|
| 585 |
|
|
|
| 586 |
|
|
SEL_DATA_BE: begin
|
| 587 |
|
|
pci_ad_out = data_in ;
|
| 588 |
|
|
pci_cbe_out = be_in ;
|
| 589 |
|
|
end
|
| 590 |
|
|
SEL_NEXT_DATA_BE,
|
| 591 |
|
|
2'b10: begin
|
| 592 |
|
|
pci_ad_out = next_data_in ;
|
| 593 |
|
|
pci_cbe_out = next_be_in ;
|
| 594 |
|
|
end
|
| 595 |
|
|
endcase
|
| 596 |
|
|
end
|
| 597 |
|
|
|
| 598 |
|
|
// data output mux for reads
|
| 599 |
|
|
always@(mabort_out or pci_ad_reg_in)
|
| 600 |
|
|
begin
|
| 601 |
|
|
if ( mabort_out )
|
| 602 |
|
|
data_out = 32'hFFFF_FFFF ;
|
| 603 |
|
|
else
|
| 604 |
|
|
data_out = pci_ad_reg_in ;
|
| 605 |
|
|
end
|
| 606 |
21 |
mihad |
endmodule
|