]>
Commit | Line | Data |
---|---|---|
1 | ////////////////////////////////////////////////////////////////////// | |
2 | //// //// | |
3 | //// File name: wb_master.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: pci_wb_master.v,v $ | |
45 | // Revision 1.1 2007-03-20 17:50:56 sithglan | |
46 | // add shit | |
47 | // | |
48 | // Revision 1.6 2004/01/24 11:54:18 mihad | |
49 | // Update! SPOCI Implemented! | |
50 | // | |
51 | // Revision 1.5 2003/10/24 09:35:40 tadejm | |
52 | // Added missing signals to 2 sensitivity lists. Everything works the same as before. | |
53 | // | |
54 | // Revision 1.4 2003/08/21 20:56:40 tadejm | |
55 | // WB Master is now WISHBONE B3 compatible. | |
56 | // | |
57 | // Revision 1.3 2003/03/14 15:31:57 mihad | |
58 | // Entered the option to disable no response counter in wb master. | |
59 | // | |
60 | // Revision 1.2 2003/01/30 22:01:09 mihad | |
61 | // Updated synchronization in top level fifo modules. | |
62 | // | |
63 | // Revision 1.1 2003/01/27 16:49:31 mihad | |
64 | // Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed. | |
65 | // | |
66 | // Revision 1.7 2002/12/05 12:19:23 mihad | |
67 | // *** empty log message *** | |
68 | // | |
69 | // Revision 1.6 2002/10/11 14:15:29 mihad | |
70 | // Cleaned up non-blocking assignments in combinatinal logic statements | |
71 | // | |
72 | // Revision 1.5 2002/03/05 11:53:47 mihad | |
73 | // Added some testcases, removed un-needed fifo signals | |
74 | // | |
75 | // Revision 1.4 2002/02/19 16:32:37 mihad | |
76 | // Modified testbench and fixed some bugs | |
77 | // | |
78 | // Revision 1.3 2002/02/01 15:25:13 mihad | |
79 | // Repaired a few bugs, updated specification, added test bench files and design document | |
80 | // | |
81 | // Revision 1.2 2001/10/05 08:14:30 mihad | |
82 | // Updated all files with inclusion of timescale file for simulation purposes. | |
83 | // | |
84 | // Revision 1.1.1.1 2001/10/02 15:33:47 mihad | |
85 | // New project directory structure | |
86 | // | |
87 | // | |
88 | ||
89 | `define WB_FSM_BITS 3 // number of bits needed for FSM states | |
90 | ||
91 | ||
92 | `include "bus_commands.v" | |
93 | `include "pci_constants.v" | |
94 | //synopsys translate_off | |
95 | `include "timescale.v" | |
96 | //synopsys translate_on | |
97 | ||
98 | module pci_wb_master | |
99 | ( wb_clock_in, // CLK_I | |
100 | reset_in, // RST_I | |
101 | ||
102 | pci_tar_read_request, | |
103 | pci_tar_address, | |
104 | pci_tar_cmd, | |
105 | pci_tar_be, | |
106 | pci_tar_burst_ok, | |
107 | pci_cache_line_size, | |
108 | cache_lsize_not_zero, | |
109 | wb_read_done_out, | |
110 | w_attempt, | |
111 | ||
112 | pcir_fifo_wenable_out, | |
113 | pcir_fifo_data_out, | |
114 | pcir_fifo_be_out, | |
115 | pcir_fifo_control_out, | |
116 | //pcir_fifo_renable_out, for PCI Target !!! | |
117 | //pcir_fifo_data_in, for PCI Target !!! | |
118 | //pcir_fifo_be_in, for PCI Target !!! | |
119 | //pcir_fifo_control_in, for PCI Target !!! | |
120 | //pcir_fifo_flush_out, for PCI Target !!! | |
121 | //pcir_fifo_almost_empty_in, for PCI Target !!! | |
122 | //pcir_fifo_empty_in, NOT used | |
123 | //pcir_fifo_transaction_ready_in, NOT used | |
124 | //pciw_fifo_wenable_out, for PCI Target !!! | |
125 | //pciw_fifo_addr_data_out, for PCI Target !!! | |
126 | //pciw_fifo_cbe_out, for PCI Target !!! | |
127 | //pciw_fifo_control_out, for PCI Target !!! | |
128 | pciw_fifo_renable_out, | |
129 | pciw_fifo_addr_data_in, | |
130 | pciw_fifo_cbe_in, | |
131 | pciw_fifo_control_in, | |
132 | //pciw_fifo_flush_out, NOT used | |
133 | //pciw_fifo_almost_full_in, for PCI Target !!! | |
134 | //pciw_fifo_full_in, for PCI Target !!! | |
135 | pciw_fifo_almost_empty_in, | |
136 | pciw_fifo_empty_in, | |
137 | pciw_fifo_transaction_ready_in, | |
138 | ||
139 | pci_error_sig_out, | |
140 | pci_error_bc, | |
141 | write_rty_cnt_exp_out, | |
142 | error_source_out, | |
143 | read_rty_cnt_exp_out, | |
144 | ||
145 | wb_cyc_o, | |
146 | wb_stb_o, | |
147 | wb_we_o, | |
148 | wb_cti_o, | |
149 | wb_bte_o, | |
150 | wb_sel_o, | |
151 | wb_adr_o, | |
152 | wb_dat_i, | |
153 | wb_dat_o, | |
154 | wb_ack_i, | |
155 | wb_rty_i, | |
156 | wb_err_i | |
157 | // CYC_O, | |
158 | // STB_O, | |
159 | // WE_O, | |
160 | // SEL_O, | |
161 | // ADR_O, | |
162 | // MDATA_I, | |
163 | // MDATA_O, | |
164 | // ACK_I, | |
165 | // RTY_I, | |
166 | // ERR_I, | |
167 | ); | |
168 | ||
169 | /*---------------------------------------------------------------------------------------------------------------------- | |
170 | Various parameters needed for state machine and other stuff | |
171 | ----------------------------------------------------------------------------------------------------------------------*/ | |
172 | parameter S_IDLE = `WB_FSM_BITS'h0 ; | |
173 | parameter S_WRITE = `WB_FSM_BITS'h1 ; | |
174 | parameter S_WRITE_ERR_RTY = `WB_FSM_BITS'h2 ; | |
175 | parameter S_READ = `WB_FSM_BITS'h3 ; | |
176 | parameter S_READ_RTY = `WB_FSM_BITS'h4 ; | |
177 | parameter S_TURN_ARROUND = `WB_FSM_BITS'h5 ; | |
178 | ||
179 | /*---------------------------------------------------------------------------------------------------------------------- | |
180 | System signals inputs | |
181 | wb_clock_in - WISHBONE bus clock input | |
182 | reset_in - system reset input controlled by bridge's reset logic | |
183 | ----------------------------------------------------------------------------------------------------------------------*/ | |
184 | input wb_clock_in ; | |
185 | input reset_in ; | |
186 | ||
187 | /*---------------------------------------------------------------------------------------------------------------------- | |
188 | Control signals from PCI Target for READS to PCIR_FIFO | |
189 | ---------------------------------------------------------------------------------------------------------------------*/ | |
190 | input pci_tar_read_request ; // read request from PCI Target | |
191 | input [31:0] pci_tar_address ; // address for requested read from PCI Target | |
192 | input [3:0] pci_tar_cmd ; // command for requested read from PCI Target | |
193 | input [3:0] pci_tar_be ; // byte enables for requested read from PCI Target | |
194 | input pci_tar_burst_ok ; | |
195 | input [7:0] pci_cache_line_size ; // CACHE line size register value for burst length | |
196 | input cache_lsize_not_zero ; | |
197 | output wb_read_done_out ; // read done and PCIR_FIFO has data ready | |
198 | output w_attempt ; | |
199 | ||
200 | reg wb_read_done_out ; | |
201 | reg wb_read_done ; | |
202 | ||
203 | /*---------------------------------------------------------------------------------------------------------------------- | |
204 | PCIR_FIFO control signals used for sinking data into PCIR_FIFO and status monitoring | |
205 | ---------------------------------------------------------------------------------------------------------------------*/ | |
206 | output pcir_fifo_wenable_out ; // PCIR_FIFO write enable output | |
207 | output [31:0] pcir_fifo_data_out ; // data output to PCIR_FIFO | |
208 | output [3:0] pcir_fifo_be_out ; // byte enable output to PCIR_FIFO | |
209 | output [3:0] pcir_fifo_control_out ; // control bus output to PCIR_FIFO | |
210 | ||
211 | reg [31:0] pcir_fifo_data_out ; | |
212 | reg pcir_fifo_wenable_out ; | |
213 | reg pcir_fifo_wenable ; | |
214 | reg [3:0] pcir_fifo_control_out ; | |
215 | reg [3:0] pcir_fifo_control ; | |
216 | ||
217 | /*---------------------------------------------------------------------------------------------------------------------- | |
218 | PCIW_FIFO control signals used for fetching data from PCIW_FIFO and status monitoring | |
219 | ---------------------------------------------------------------------------------------------------------------------*/ | |
220 | output pciw_fifo_renable_out ; // read enable for PCIW_FIFO output | |
221 | input [31:0] pciw_fifo_addr_data_in ; // address and data input from PCIW_FIFO | |
222 | input [3:0] pciw_fifo_cbe_in ; // command and byte_enables from PCIW_FIFO | |
223 | input [3:0] pciw_fifo_control_in ; // control bus input from PCIW_FIFO | |
224 | input pciw_fifo_almost_empty_in ; // almost empty status indicator from PCIW_FIFO | |
225 | input pciw_fifo_empty_in ; // empty status indicator from PCIW_FIFO | |
226 | input pciw_fifo_transaction_ready_in ; // write transaction is ready in PCIW_FIFO | |
227 | ||
228 | reg pciw_fifo_renable_out ; | |
229 | reg pciw_fifo_renable ; | |
230 | ||
231 | /*---------------------------------------------------------------------------------------------------------------------- | |
232 | Control INPUT / OUTPUT signals for configuration space reporting registers !!! | |
233 | ---------------------------------------------------------------------------------------------------------------------*/ | |
234 | output pci_error_sig_out ; // When error occures (on WB bus, retry counter, etc.) | |
235 | output [3:0] pci_error_bc ; // bus command at which error occured ! | |
236 | output write_rty_cnt_exp_out ; // Signaling that RETRY counter has expired during write transaction! | |
237 | output read_rty_cnt_exp_out ; // Signaling that RETRY counter has expired during read transaction! | |
238 | // if error_source is '0' other side didn't respond | |
239 | // if error_source is '1' other side RETRIED for max retry counter value | |
240 | output error_source_out ; // Signaling error source - '0' other WB side signaled error OR didn't respond | |
241 | // if '1' wridge counted max value in retry counter because of RTY responds | |
242 | reg pci_error_sig_out ; | |
243 | reg write_rty_cnt_exp_out ; | |
244 | reg read_rty_cnt_exp_out ; | |
245 | reg error_source_out ; | |
246 | ||
247 | /*---------------------------------------------------------------------------------------------------------------------- | |
248 | WISHBONE bus interface signals - can be connected directly to WISHBONE bus | |
249 | ---------------------------------------------------------------------------------------------------------------------*/ | |
250 | output wb_cyc_o; // cycle indicator output | |
251 | output wb_stb_o; // strobe output - data is valid when strobe and cycle indicator are high | |
252 | output wb_we_o; // write enable output - 1 - write operation, 0 - read operation | |
253 | output [2:0] wb_cti_o; // WB B3 - cycle type identifier | |
254 | output [1:0] wb_bte_o; // WB B3 - burst type | |
255 | output [3:0] wb_sel_o; // Byte select outputs | |
256 | output [31:0] wb_adr_o; // WISHBONE address output | |
257 | input [31:0] wb_dat_i; // WISHBONE interface input data bus | |
258 | output [31:0] wb_dat_o; // WISHBONE interface output data bus | |
259 | input wb_ack_i; // Acknowledge input - qualifies valid data on data output bus or received data on data input bus | |
260 | input wb_rty_i; // retry input - signals from WISHBONE slave that cycle should be terminated and retried later | |
261 | input wb_err_i; // Signals from WISHBONE slave that access resulted in an error | |
262 | ||
263 | reg wb_cyc_o; | |
264 | reg wb_stb_o; | |
265 | reg wb_we_o; | |
266 | reg [2:0] wb_cti_o; | |
267 | reg [1:0] wb_bte_o; | |
268 | reg [3:0] wb_sel_o; | |
269 | reg [31:0] wb_dat_o; | |
270 | ||
271 | ||
272 | ||
273 | /*########################################################################################################### | |
274 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
275 | LOGIC, COUNTERS, STATE MACHINE and some control register bits | |
276 | ============================================================= | |
277 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
278 | ###########################################################################################################*/ | |
279 | ||
280 | reg last_data_transferred ; // signal is set by STATE MACHINE after each complete transfere ! | |
281 | ||
282 | // wire for write attempt - 1 when PCI Target attempt to write and PCIW_FIFO has a write transaction ready | |
283 | reg w_attempt; | |
284 | always@(posedge wb_clock_in or posedge reset_in) | |
285 | begin | |
286 | if (reset_in) | |
287 | w_attempt <= #`FF_DELAY 1'b0; | |
288 | else | |
289 | begin | |
290 | if (pciw_fifo_transaction_ready_in && ~pciw_fifo_empty_in) | |
291 | w_attempt <= #`FF_DELAY 1'b1; | |
292 | else | |
293 | if (last_data_transferred) | |
294 | w_attempt <= #`FF_DELAY 1'b0; | |
295 | end | |
296 | end | |
297 | ||
298 | // wire for read attempt - 1 when PCI Target is attempting a read and PCIR_FIFO is not full ! | |
299 | // because of transaction ordering, PCI Master must not start read untill all writes are done -> at that | |
300 | // moment PCIW_FIFO is empty !!! (when read is pending PCI Target will block new reads and writes) | |
301 | wire r_attempt = ( pci_tar_read_request && !w_attempt && pciw_fifo_empty_in ) ; | |
302 | ||
303 | // Signal is used for reads on WB, when there is retry! | |
304 | reg first_wb_data_access ; | |
305 | ||
306 | reg last_data_from_pciw_fifo ; // signal tells when there is last data in pciw_fifo | |
307 | reg last_data_from_pciw_fifo_reg ; | |
308 | reg last_data_to_pcir_fifo ; // signal tells when there will be last data for pcir_fifo | |
309 | ||
310 | // Logic used in State Machine logic implemented out of State Machine because of less delay! | |
311 | always@(posedge wb_clock_in or posedge reset_in) | |
312 | begin | |
313 | if (reset_in) | |
314 | last_data_from_pciw_fifo <= #`FF_DELAY 1'b0 ; | |
315 | else | |
316 | begin | |
317 | if ((pciw_fifo_renable_out) && | |
318 | (pciw_fifo_control_in[`LAST_CTRL_BIT] || pciw_fifo_almost_empty_in)) // if last data is going to be transfered | |
319 | last_data_from_pciw_fifo <= #`FF_DELAY 1'b1 ; // signal for last data from PCIW_FIFO | |
320 | else | |
321 | last_data_from_pciw_fifo <= #`FF_DELAY 1'b0 ; | |
322 | end | |
323 | end | |
324 | ||
325 | reg read_count_load; | |
326 | reg read_count_enable; | |
327 | ||
328 | reg [(`PCIR_ADDR_LENGTH - 1):0] max_read_count ; | |
329 | always@(pci_cache_line_size or cache_lsize_not_zero or pci_tar_cmd) | |
330 | begin | |
331 | if (cache_lsize_not_zero) | |
332 | if ( (pci_cache_line_size >= `PCIR_DEPTH) || (~pci_tar_cmd[1] && ~pci_tar_cmd[0]) ) | |
333 | // If cache line size is larger than FIFO or BC_MEM_READ_MUL command is performed! | |
334 | max_read_count = `PCIR_DEPTH - 1'b1; | |
335 | else | |
336 | max_read_count = pci_cache_line_size ; | |
337 | else | |
338 | max_read_count = 1'b1; | |
339 | end | |
340 | ||
341 | reg [(`PCIR_ADDR_LENGTH - 1):0] read_count ; | |
342 | ||
343 | // cache line bound indicator - it signals when data for one complete cacheline was read | |
344 | wire read_bound_comb = ~|( { read_count[(`PCIR_ADDR_LENGTH - 1):2], read_count[0] } ) ; | |
345 | ||
346 | reg read_bound ; | |
347 | always@(posedge wb_clock_in or posedge reset_in) | |
348 | begin | |
349 | if ( reset_in ) | |
350 | read_bound <= #`FF_DELAY 1'b0 ; | |
351 | else if (read_count_load) | |
352 | read_bound <= #`FF_DELAY 1'b0 ; | |
353 | else if ( read_count_enable ) | |
354 | read_bound <= #`FF_DELAY read_bound_comb ; | |
355 | end | |
356 | ||
357 | // down counter with load | |
358 | always@(posedge reset_in or posedge wb_clock_in) | |
359 | begin | |
360 | if (reset_in) | |
361 | read_count <= #`FF_DELAY 0 ; | |
362 | else | |
363 | if (read_count_load) | |
364 | read_count <= #`FF_DELAY max_read_count ; | |
365 | else | |
366 | if (read_count_enable) | |
367 | read_count <= #`FF_DELAY read_count - 1'b1 ; | |
368 | end | |
369 | ||
370 | // Logic used in State Machine logic implemented out of State Machine because of less delay! | |
371 | // definition of signal telling, when there is last data written into FIFO | |
372 | always@(pci_tar_cmd or pci_tar_burst_ok or read_bound) | |
373 | begin | |
374 | // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR | |
375 | // (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok | |
376 | case ({pci_tar_cmd, pci_tar_burst_ok}) | |
377 | {`BC_MEM_READ, 1'b1}, | |
378 | {`BC_MEM_READ_LN, 1'b1} : | |
379 | begin // when burst cycle | |
380 | if (read_bound) | |
381 | last_data_to_pcir_fifo = 1'b1 ; | |
382 | else | |
383 | last_data_to_pcir_fifo = 1'b0 ; | |
384 | end | |
385 | {`BC_MEM_READ_MUL, 1'b1} : | |
386 | begin // when burst cycle | |
387 | if (read_bound) | |
388 | last_data_to_pcir_fifo = 1'b1 ; | |
389 | else | |
390 | last_data_to_pcir_fifo = 1'b0 ; | |
391 | end | |
392 | default : | |
393 | // {`BC_IO_READ, 1'b0}, | |
394 | // {`BC_IO_READ, 1'b1}, | |
395 | // {`BC_MEM_READ, 1'b0}, | |
396 | // {`BC_MEM_READ_LN, 1'b0}, | |
397 | // {`BC_MEM_READ_MUL, 1'b0}: | |
398 | begin // when single cycle | |
399 | last_data_to_pcir_fifo = 1'b1 ; | |
400 | end | |
401 | endcase | |
402 | end | |
403 | ||
404 | reg wait_for_wb_response ; | |
405 | ||
406 | `ifdef PCI_WBM_NO_RESPONSE_CNT_DISABLE | |
407 | wire set_retry = 1'b0 ; | |
408 | ||
409 | `else | |
410 | reg [3:0] wb_no_response_cnt ; | |
411 | reg [3:0] wb_response_value ; | |
412 | reg set_retry ; // | |
413 | ||
414 | // internal WB no response retry generator counter! | |
415 | always@(posedge reset_in or posedge wb_clock_in) | |
416 | begin | |
417 | if (reset_in) | |
418 | wb_no_response_cnt <= #`FF_DELAY 4'h0 ; | |
419 | else | |
420 | wb_no_response_cnt <= #`FF_DELAY wb_response_value ; | |
421 | end | |
422 | // internal WB no response retry generator logic | |
423 | always@(wait_for_wb_response or wb_no_response_cnt) | |
424 | begin | |
425 | if (wb_no_response_cnt == 4'h8) // when there isn't response for 8 clocks, set internal retry | |
426 | begin | |
427 | wb_response_value = 4'h0 ; | |
428 | set_retry = 1'b1 ; | |
429 | end | |
430 | else | |
431 | begin | |
432 | if (wait_for_wb_response) | |
433 | wb_response_value = wb_no_response_cnt + 1'h1 ; // count clocks when no response | |
434 | else | |
435 | wb_response_value = 4'h0 ; | |
436 | set_retry = 1'b0 ; | |
437 | end | |
438 | end | |
439 | `endif | |
440 | ||
441 | wire retry = wb_rty_i || set_retry ; // retry signal - logic OR function between wb_rty_i and internal WB no response retry! | |
442 | reg [7:0] rty_counter ; // output from retry counter | |
443 | reg [7:0] rty_counter_in ; // input value - output value + 1 OR output value | |
444 | reg rty_counter_almost_max_value ; // signal tells when retry counter riches maximum value - 1! | |
445 | reg reset_rty_cnt ; // signal for asynchronous reset of retry counter after each complete transfere | |
446 | ||
447 | // sinchronous signal after each transfere and asynchronous signal 'reset_rty_cnt' after reset | |
448 | // for reseting the retry counter | |
449 | always@(posedge reset_in or posedge wb_clock_in) | |
450 | begin | |
451 | if (reset_in) | |
452 | reset_rty_cnt <= #`FF_DELAY 1'b1 ; // asynchronous set when reset signal is active | |
453 | else | |
454 | reset_rty_cnt <= #`FF_DELAY wb_ack_i || wb_err_i || last_data_transferred ; // synchronous set after completed transfere | |
455 | end | |
456 | ||
457 | // Retry counter register control | |
458 | always@(posedge reset_in or posedge wb_clock_in) | |
459 | begin | |
460 | if (reset_in) | |
461 | rty_counter <= #`FF_DELAY 8'h00 ; | |
462 | else | |
463 | begin | |
464 | if (reset_rty_cnt) | |
465 | rty_counter <= #`FF_DELAY 8'h00 ; | |
466 | else if (retry) | |
467 | rty_counter <= #`FF_DELAY rty_counter_in ; | |
468 | end | |
469 | end | |
470 | // Retry counter logic | |
471 | always@(rty_counter) | |
472 | begin | |
473 | if(rty_counter == `WB_RTY_CNT_MAX - 1'b1) // stop counting | |
474 | begin | |
475 | rty_counter_in = rty_counter ; | |
476 | rty_counter_almost_max_value = 1'b1 ; | |
477 | end | |
478 | else | |
479 | begin | |
480 | rty_counter_in = rty_counter + 1'b1 ; // count up | |
481 | rty_counter_almost_max_value = 1'b0 ; | |
482 | end | |
483 | end | |
484 | ||
485 | reg [31:0] addr_cnt_out ; // output value from address counter to WB ADDRESS output | |
486 | reg [31:0] addr_cnt_in ; // input address value to address counter | |
487 | reg addr_into_cnt ; // control signal for loading starting address into counter | |
488 | reg addr_into_cnt_reg ; | |
489 | reg addr_count ; // control signal for count enable | |
490 | reg [3:0] bc_register ; // used when error occures during writes! | |
491 | ||
492 | // wb address counter register control | |
493 | always@(posedge wb_clock_in or posedge reset_in) | |
494 | begin | |
495 | if (reset_in) // reset counter | |
496 | begin | |
497 | addr_cnt_out <= #`FF_DELAY 32'h0000_0000 ; | |
498 | bc_register <= #`FF_DELAY 4'h0 ; | |
499 | addr_into_cnt_reg <= #`FF_DELAY 1'b0; | |
500 | end | |
501 | else | |
502 | begin | |
503 | addr_cnt_out <= #`FF_DELAY addr_cnt_in ; // count up or hold value depending on cache line counter logic | |
504 | addr_into_cnt_reg <= #`FF_DELAY addr_into_cnt; | |
505 | if (addr_into_cnt) | |
506 | bc_register <= #`FF_DELAY pciw_fifo_cbe_in ; | |
507 | end | |
508 | end | |
509 | ||
510 | // when '1', the bus command is IO command - not supported commands are checked in pci_decoder modules | |
511 | wire io_memory_bus_command = !pci_tar_cmd[3] && !pci_tar_cmd[2] ; | |
512 | ||
513 | // wb address counter logic | |
514 | always@(addr_into_cnt or r_attempt or addr_count or pciw_fifo_addr_data_in or pci_tar_address or addr_cnt_out or | |
515 | io_memory_bus_command) | |
516 | begin | |
517 | if (addr_into_cnt) // load starting address into counter | |
518 | begin | |
519 | if (r_attempt) | |
520 | begin // if read request, then load read addresss from PCI Target | |
521 | addr_cnt_in = {pci_tar_address[31:2], pci_tar_address[1] && io_memory_bus_command, | |
522 | pci_tar_address[0] && io_memory_bus_command} ; | |
523 | end | |
524 | else | |
525 | begin // if not read request, then load write address from PCIW_FIFO | |
526 | addr_cnt_in = pciw_fifo_addr_data_in[31:0] ; | |
527 | end | |
528 | end | |
529 | else | |
530 | if (addr_count) | |
531 | begin | |
532 | addr_cnt_in = addr_cnt_out + 3'h4 ; // count up for 32-bit alligned address | |
533 | end | |
534 | else | |
535 | begin | |
536 | addr_cnt_in = addr_cnt_out ; | |
537 | end | |
538 | end | |
539 | ||
540 | reg retried ; // Signal is output value from FF and is set for one clock period after retried_d is set | |
541 | reg retried_d ; // Signal is set whenever cycle is retried and is input to FF for delaying -> used in S_IDLE state | |
542 | reg retried_write; | |
543 | reg rty_i_delayed; // Dignal used for determinig the source of retry! | |
544 | ||
545 | reg first_data_is_burst ; // Signal is set in S_WRITE or S_READ states, when data transfere is burst! | |
546 | reg first_data_is_burst_reg ; | |
547 | wire burst_transfer ; // This signal is set when data transfere is burst and is reset with RESET or last data transfered | |
548 | reg burst_chopped; // This signal is set when WB_SEL_O is changed during burst write transaction | |
549 | reg burst_chopped_delayed; | |
550 | ||
551 | // FFs output signals tell, when there is first data out from FIFO (for BURST checking) | |
552 | // and for delaying retried signal | |
553 | always@(posedge wb_clock_in or posedge reset_in) | |
554 | begin | |
555 | if (reset_in) // reset signals | |
556 | begin | |
557 | retried <= #`FF_DELAY 1'b0 ; | |
558 | retried_write <= #`FF_DELAY 1'b0 ; | |
559 | rty_i_delayed <= #`FF_DELAY 1'B0 ; | |
560 | end | |
561 | else | |
562 | begin | |
563 | retried <= #`FF_DELAY retried_d ; // delaying retried signal | |
564 | retried_write <= #`FF_DELAY retried ; | |
565 | rty_i_delayed <= #`FF_DELAY wb_rty_i ; | |
566 | end | |
567 | end | |
568 | ||
569 | // Determinig if first data is a part of BURST or just a single transfere! | |
570 | always@(addr_into_cnt or r_attempt or pci_tar_burst_ok or max_read_count or | |
571 | pciw_fifo_control_in or pciw_fifo_empty_in) | |
572 | begin | |
573 | if (addr_into_cnt) | |
574 | begin | |
575 | if (r_attempt) | |
576 | begin | |
577 | // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR | |
578 | // (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok | |
579 | if (pci_tar_burst_ok && (max_read_count != 8'h1)) | |
580 | first_data_is_burst = 1'b1 ; | |
581 | else | |
582 | first_data_is_burst = 1'b0 ; | |
583 | end | |
584 | else | |
585 | begin | |
586 | first_data_is_burst = 1'b0 ; | |
587 | end | |
588 | end | |
589 | else | |
590 | first_data_is_burst = pciw_fifo_control_in[`BURST_BIT] && ~pciw_fifo_empty_in && | |
591 | ~pciw_fifo_control_in[`LAST_CTRL_BIT] /*&& ~pciw_fifo_control_in[`DATA_ERROR_CTRL_BIT]*/; | |
592 | end | |
593 | ||
594 | // FF for seting and reseting burst_transfer signal | |
595 | always@(posedge wb_clock_in or posedge reset_in) | |
596 | begin | |
597 | if (reset_in) | |
598 | begin | |
599 | burst_chopped <= #`FF_DELAY 1'b0; | |
600 | burst_chopped_delayed <= #`FF_DELAY 1'b0; | |
601 | first_data_is_burst_reg <= #`FF_DELAY 1'b0 ; | |
602 | end | |
603 | else | |
604 | begin | |
605 | if (pciw_fifo_transaction_ready_in) | |
606 | begin | |
607 | if (pciw_fifo_control_in[`DATA_ERROR_CTRL_BIT]) | |
608 | burst_chopped <= #`FF_DELAY 1'b1; | |
609 | else if (wb_ack_i || wb_err_i || wb_rty_i) | |
610 | burst_chopped <= #`FF_DELAY 1'b0; | |
611 | end | |
612 | else | |
613 | burst_chopped <= #`FF_DELAY 1'b0; | |
614 | burst_chopped_delayed <= #`FF_DELAY burst_chopped; | |
615 | if (last_data_transferred || first_data_is_burst) | |
616 | first_data_is_burst_reg <= #`FF_DELAY ~last_data_transferred ; | |
617 | end | |
618 | end | |
619 | assign burst_transfer = first_data_is_burst || first_data_is_burst_reg ; | |
620 | ||
621 | reg [(`WB_FSM_BITS - 1):0] c_state ; //current state register | |
622 | reg [(`WB_FSM_BITS - 1):0] n_state ; //next state input to current state register | |
623 | ||
624 | //################################## | |
625 | // WISHBONE B3 master state machine | |
626 | //################################## | |
627 | ||
628 | // state machine register control and registered outputs (without wb_adr_o counter) | |
629 | always@(posedge wb_clock_in or posedge reset_in) | |
630 | begin | |
631 | if (reset_in) // reset state machine to S_IDLE state | |
632 | begin | |
633 | c_state <= #`FF_DELAY S_IDLE; | |
634 | wb_cyc_o <= #`FF_DELAY 1'b0; | |
635 | wb_stb_o <= #`FF_DELAY 1'b0; | |
636 | wb_we_o <= #`FF_DELAY 1'b0; | |
637 | wb_cti_o <= #`FF_DELAY 3'h2; | |
638 | wb_bte_o <= #`FF_DELAY 2'h0; | |
639 | wb_sel_o <= #`FF_DELAY 4'h0; | |
640 | wb_dat_o <= #`FF_DELAY 32'h0; | |
641 | pcir_fifo_data_out <= #`FF_DELAY 32'h0; | |
642 | pcir_fifo_control_out <= #`FF_DELAY 4'h0; | |
643 | pcir_fifo_wenable_out <= #`FF_DELAY 1'b0; | |
644 | end | |
645 | else | |
646 | begin | |
647 | c_state <= #`FF_DELAY n_state; | |
648 | wb_bte_o <= #`FF_DELAY 2'h0; | |
649 | case (n_state) // synthesis parallel_case full_case | |
650 | S_WRITE: | |
651 | begin | |
652 | wb_cyc_o <= #`FF_DELAY ~addr_into_cnt; | |
653 | wb_stb_o <= #`FF_DELAY ~addr_into_cnt; | |
654 | wb_we_o <= #`FF_DELAY ~addr_into_cnt; | |
655 | // if '1' then next burst BE is not equat to current one => burst is chopped into singles | |
656 | // OR if last data is going to be transfered | |
657 | if ((wb_stb_o && wb_ack_i) || addr_into_cnt_reg || (~wb_cyc_o && (retried || burst_chopped_delayed))) | |
658 | begin | |
659 | if (burst_transfer && ~pciw_fifo_control_in[`DATA_ERROR_CTRL_BIT] && | |
660 | ~(pciw_fifo_renable_out && (pciw_fifo_control_in[`LAST_CTRL_BIT] || pciw_fifo_almost_empty_in))) | |
661 | wb_cti_o <= #`FF_DELAY 3'h2; | |
662 | else | |
663 | wb_cti_o <= #`FF_DELAY 3'h7; | |
664 | end | |
665 | if ((pciw_fifo_renable_out && ~addr_into_cnt) || addr_into_cnt_reg) | |
666 | begin | |
667 | wb_sel_o <= #`FF_DELAY ~pciw_fifo_cbe_in; | |
668 | wb_dat_o <= #`FF_DELAY pciw_fifo_addr_data_in; | |
669 | end | |
670 | end | |
671 | S_WRITE_ERR_RTY: | |
672 | begin | |
673 | wb_cyc_o <= #`FF_DELAY 1'b0; | |
674 | wb_stb_o <= #`FF_DELAY 1'b0; | |
675 | wb_we_o <= #`FF_DELAY 1'b0; | |
676 | wb_cti_o <= #`FF_DELAY 3'h2; | |
677 | // stay the same as previous | |
678 | //wb_sel_o <= #`FF_DELAY 4'h0; | |
679 | //wb_dat_o <= #`FF_DELAY 32'h0; | |
680 | end | |
681 | S_READ: | |
682 | begin | |
683 | wb_cyc_o <= #`FF_DELAY ~addr_into_cnt; | |
684 | wb_stb_o <= #`FF_DELAY ~addr_into_cnt; | |
685 | wb_we_o <= #`FF_DELAY 1'b0; | |
686 | if ((wb_stb_o && wb_ack_i) || addr_into_cnt_reg || (~wb_cyc_o && retried)) | |
687 | begin | |
688 | if (burst_transfer && ~read_bound_comb) | |
689 | wb_cti_o <= #`FF_DELAY 3'h2; | |
690 | else | |
691 | wb_cti_o <= #`FF_DELAY 3'h7; | |
692 | end | |
693 | if (burst_transfer) | |
694 | wb_sel_o <= #`FF_DELAY 4'hF; | |
695 | else | |
696 | wb_sel_o <= #`FF_DELAY ~pci_tar_be; | |
697 | // no need to change att all | |
698 | //wb_dat_o <= #`FF_DELAY 32'h0; | |
699 | end | |
700 | S_READ_RTY: | |
701 | begin | |
702 | wb_cyc_o <= #`FF_DELAY 1'b0; | |
703 | wb_stb_o <= #`FF_DELAY 1'b0; | |
704 | wb_we_o <= #`FF_DELAY 1'b0; | |
705 | wb_cti_o <= #`FF_DELAY 3'h2; | |
706 | // no need to change att all | |
707 | //wb_sel_o <= #`FF_DELAY 4'h0; | |
708 | //wb_dat_o <= #`FF_DELAY 32'h0; | |
709 | end | |
710 | S_TURN_ARROUND: | |
711 | begin | |
712 | wb_cyc_o <= #`FF_DELAY 1'b0; | |
713 | wb_stb_o <= #`FF_DELAY 1'b0; | |
714 | wb_we_o <= #`FF_DELAY 1'b0; | |
715 | wb_cti_o <= #`FF_DELAY 3'h2; | |
716 | // no need to change att all | |
717 | //wb_sel_o <= #`FF_DELAY 4'h0; | |
718 | //wb_dat_o <= #`FF_DELAY 32'h0; | |
719 | end | |
720 | default: // S_IDLE: | |
721 | begin | |
722 | wb_cyc_o <= #`FF_DELAY 1'b0; | |
723 | wb_stb_o <= #`FF_DELAY 1'b0; | |
724 | wb_we_o <= #`FF_DELAY 1'b0; | |
725 | wb_cti_o <= #`FF_DELAY 3'h2; | |
726 | // no need to change att all | |
727 | //wb_sel_o <= #`FF_DELAY 4'h0; | |
728 | //wb_dat_o <= #`FF_DELAY 32'h0; | |
729 | end | |
730 | endcase | |
731 | pcir_fifo_data_out <= #`FF_DELAY wb_dat_i; | |
732 | pcir_fifo_control_out <= #`FF_DELAY pcir_fifo_control ; | |
733 | pcir_fifo_wenable_out <= #`FF_DELAY pcir_fifo_wenable ; | |
734 | end | |
735 | end | |
736 | ||
737 | assign wb_adr_o = addr_cnt_out ; | |
738 | ||
739 | // state machine logic | |
740 | always@(c_state or | |
741 | wb_ack_i or | |
742 | wb_rty_i or | |
743 | wb_err_i or | |
744 | w_attempt or | |
745 | r_attempt or | |
746 | retried or | |
747 | burst_chopped or | |
748 | burst_chopped_delayed or | |
749 | rty_i_delayed or | |
750 | pci_tar_read_request or | |
751 | rty_counter_almost_max_value or | |
752 | set_retry or | |
753 | last_data_to_pcir_fifo or | |
754 | first_wb_data_access or | |
755 | pciw_fifo_control_in or | |
756 | pciw_fifo_empty_in or | |
757 | burst_transfer or | |
758 | last_data_from_pciw_fifo_reg | |
759 | ) | |
760 | begin | |
761 | case (c_state) | |
762 | S_IDLE: | |
763 | begin | |
764 | // Default values for signals not used in this state | |
765 | pcir_fifo_wenable = 1'b0 ; | |
766 | pcir_fifo_control = 4'h0 ; | |
767 | addr_count = 1'b0 ; | |
768 | read_count_enable = 1'b0 ; | |
769 | pci_error_sig_out = 1'b0 ; | |
770 | error_source_out = 1'b0 ; | |
771 | retried_d = 1'b0 ; | |
772 | last_data_transferred = 1'b0 ; | |
773 | wb_read_done = 1'b0 ; | |
774 | wait_for_wb_response = 1'b0 ; | |
775 | write_rty_cnt_exp_out = 1'b0 ; | |
776 | pci_error_sig_out = 1'b0 ; | |
777 | read_rty_cnt_exp_out = 1'b0 ; | |
778 | case ({w_attempt, r_attempt, retried}) | |
779 | 3'b101 : // Write request for PCIW_FIFO to WB bus transaction | |
780 | begin // If there was retry, the same transaction must be initiated | |
781 | pciw_fifo_renable = 1'b0 ; // the same data | |
782 | addr_into_cnt = 1'b0 ; // the same address | |
783 | read_count_load = 1'b0 ; // no need for cache line when there is write | |
784 | n_state = S_WRITE ; | |
785 | end | |
786 | 3'b100 : // Write request for PCIW_FIFO to WB bus transaction | |
787 | begin // If there is new transaction | |
788 | if (burst_chopped_delayed) | |
789 | begin | |
790 | addr_into_cnt = 1'b0 ; // address must not be latched into address counter | |
791 | pciw_fifo_renable = 1'b1 ; // first location is address (in FIFO), next will be data | |
792 | end | |
793 | else | |
794 | begin | |
795 | if (pciw_fifo_control_in[`ADDR_CTRL_BIT]) | |
796 | addr_into_cnt = 1'b1 ; // address must be latched into address counter | |
797 | else | |
798 | addr_into_cnt = 1'b0 ; | |
799 | pciw_fifo_renable = 1'b1 ; // first location is address (in FIFO), next will be data | |
800 | end | |
801 | read_count_load = 1'b0 ; // no need for cache line when there is write | |
802 | n_state = S_WRITE ; | |
803 | end | |
804 | 3'b011 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction | |
805 | begin // If there was retry, the same transaction must be initiated | |
806 | addr_into_cnt = 1'b0 ; // the same address | |
807 | read_count_load = 1'b0 ; // cache line counter must not be changed for retried read | |
808 | pciw_fifo_renable = 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO | |
809 | n_state = S_READ ; | |
810 | end | |
811 | 3'b010 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction | |
812 | begin // If there is new transaction | |
813 | addr_into_cnt = 1'b1 ; // address must be latched into counter from separate request bus | |
814 | read_count_load = 1'b1 ; // cache line size must be latched into its counter | |
815 | pciw_fifo_renable = 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO | |
816 | n_state = S_READ ; | |
817 | end | |
818 | default : // stay in IDLE state | |
819 | begin | |
820 | pciw_fifo_renable = 1'b0 ; | |
821 | addr_into_cnt = 1'b0 ; | |
822 | read_count_load = 1'b0 ; | |
823 | n_state = S_IDLE ; | |
824 | end | |
825 | endcase | |
826 | end | |
827 | S_WRITE: // WRITE from PCIW_FIFO to WB bus | |
828 | begin | |
829 | // Default values for signals not used in this state | |
830 | pcir_fifo_wenable = 1'b0 ; | |
831 | pcir_fifo_control = 4'h0 ; | |
832 | addr_into_cnt = 1'b0 ; | |
833 | read_count_load = 1'b0 ; | |
834 | read_count_enable = 1'b0 ; | |
835 | wb_read_done = 1'b0 ; | |
836 | read_rty_cnt_exp_out = 1'b0 ; | |
837 | case ({wb_ack_i, wb_err_i, wb_rty_i}) | |
838 | 3'b100 : // If writting of one data is acknowledged | |
839 | begin | |
840 | addr_count = 1'b1 ; // prepare next address if there will be burst | |
841 | retried_d = 1'b0 ; // there was no retry | |
842 | pci_error_sig_out = 1'b0 ; // there was no error | |
843 | error_source_out = 1'b0 ; | |
844 | write_rty_cnt_exp_out = 1'b0 ; // there was no retry | |
845 | wait_for_wb_response = 1'b0 ; | |
846 | // if last data was transfered ! | |
847 | if (last_data_from_pciw_fifo_reg) | |
848 | begin | |
849 | n_state = S_TURN_ARROUND; | |
850 | if (~pciw_fifo_empty_in) | |
851 | pciw_fifo_renable = 1'b0 ; // prepare next value (address when new trans., data when burst tran.) | |
852 | else | |
853 | pciw_fifo_renable = 1'b0 ; | |
854 | last_data_transferred = 1'b1 ; // signal for last data transfered | |
855 | end | |
856 | // next burst data has different byte enables ! | |
857 | else if (burst_transfer && burst_chopped) | |
858 | begin | |
859 | n_state = S_IDLE ; | |
860 | pciw_fifo_renable = 1'b0 ; // next value (address when new trans., data when burst tran.) | |
861 | last_data_transferred = 1'b0 ; | |
862 | end | |
863 | else | |
864 | begin | |
865 | n_state = S_WRITE ; | |
866 | pciw_fifo_renable = 1'b1 ; // prepare next value (address when new trans., data when burst tran.) | |
867 | last_data_transferred = 1'b0 ; | |
868 | end | |
869 | end | |
870 | 3'b010 : // If writting of one data is terminated with ERROR | |
871 | begin | |
872 | if (~pciw_fifo_empty_in) | |
873 | pciw_fifo_renable = 1'b1 ; // prepare next value (address when new trans., data when cleaning FIFO) | |
874 | else | |
875 | pciw_fifo_renable = 1'b0 ; | |
876 | addr_count = 1'b0 ; // no need for new address | |
877 | retried_d = 1'b0 ; // there was no retry | |
878 | last_data_transferred = 1'b1 ; // signal for last data transfered | |
879 | pci_error_sig_out = 1'b1 ; // segnal for error reporting | |
880 | error_source_out = 1'b0 ; // error source from other side of WB bus | |
881 | write_rty_cnt_exp_out = 1'b0 ; // there was no retry | |
882 | wait_for_wb_response = 1'b0 ; | |
883 | if (last_data_from_pciw_fifo_reg) // if last data was transfered | |
884 | n_state = S_TURN_ARROUND ; // go to S_TURN_ARROUND for new transfere | |
885 | else // if there wasn't last data of transfere | |
886 | n_state = S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO | |
887 | end | |
888 | 3'b001 : // If writting of one data is retried | |
889 | begin | |
890 | addr_count = 1'b0 ; | |
891 | last_data_transferred = 1'b0 ; | |
892 | retried_d = 1'b1 ; // there was a retry | |
893 | wait_for_wb_response = 1'b0 ; | |
894 | if(rty_counter_almost_max_value) // If retry counter reached maximum allowed value | |
895 | begin | |
896 | if (last_data_from_pciw_fifo_reg) // if last data was transfered | |
897 | pciw_fifo_renable = 1'b0 ; | |
898 | else // if there wasn't last data of transfere | |
899 | pciw_fifo_renable = 1'b1 ; | |
900 | n_state = S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO | |
901 | write_rty_cnt_exp_out = 1'b1 ; // signal for reporting write counter expired | |
902 | pci_error_sig_out = 1'b1 ; | |
903 | error_source_out = 1'b1 ; // error ocuerd because of retry counter | |
904 | end | |
905 | else | |
906 | begin | |
907 | pciw_fifo_renable = 1'b0 ; | |
908 | n_state = S_IDLE ; // go to S_IDLE state for retrying the transaction | |
909 | write_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired yet | |
910 | pci_error_sig_out = 1'b0 ; | |
911 | error_source_out = 1'b0 ; | |
912 | end | |
913 | end | |
914 | default : | |
915 | begin | |
916 | addr_count = 1'b0 ; | |
917 | last_data_transferred = 1'b0 ; | |
918 | wait_for_wb_response = 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented) | |
919 | error_source_out = 1'b0 ; // if error ocures, error source is from other WB bus side | |
920 | if((rty_counter_almost_max_value)&&(set_retry)) // when no WB response and RTY CNT reached maximum allowed value | |
921 | begin | |
922 | retried_d = 1'b1 ; | |
923 | if (last_data_from_pciw_fifo_reg) // if last data was transfered | |
924 | pciw_fifo_renable = 1'b0 ; | |
925 | else // if there wasn't last data of transfere | |
926 | pciw_fifo_renable = 1'b1 ; | |
927 | n_state = S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO | |
928 | write_rty_cnt_exp_out = 1'b1 ; // signal for reporting write counter expired | |
929 | pci_error_sig_out = 1'b1 ; // signal for error reporting | |
930 | end | |
931 | else | |
932 | begin | |
933 | pciw_fifo_renable = 1'b0 ; | |
934 | retried_d = 1'b0 ; | |
935 | n_state = S_WRITE ; // stay in S_WRITE state to wait WB to response | |
936 | write_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired yet | |
937 | pci_error_sig_out = 1'b0 ; | |
938 | end | |
939 | end | |
940 | endcase | |
941 | end | |
942 | S_WRITE_ERR_RTY: // Clean current write transaction from PCIW_FIFO if ERROR or Retry counter expired occures | |
943 | begin | |
944 | pciw_fifo_renable = !last_data_from_pciw_fifo_reg ; // put out next data (untill last data or FIFO empty) | |
945 | last_data_transferred = 1'b1 ; // after exiting this state, negedge of this signal is used | |
946 | // Default values for signals not used in this state | |
947 | pcir_fifo_wenable = 1'b0 ; | |
948 | pcir_fifo_control = 4'h0 ; | |
949 | addr_into_cnt = 1'b0 ; | |
950 | read_count_load = 1'b0 ; | |
951 | read_count_enable = 1'b0 ; | |
952 | addr_count = 1'b0 ; | |
953 | pci_error_sig_out = 1'b0 ; | |
954 | error_source_out = 1'b0 ; | |
955 | retried_d = 1'b0 ; | |
956 | wb_read_done = 1'b0 ; | |
957 | write_rty_cnt_exp_out = 1'b0 ; | |
958 | read_rty_cnt_exp_out = 1'b0 ; | |
959 | wait_for_wb_response = 1'b0 ; | |
960 | // If last data is cleaned out from PCIW_FIFO | |
961 | if (last_data_from_pciw_fifo_reg) | |
962 | n_state = S_IDLE ; | |
963 | else | |
964 | n_state = S_WRITE_ERR_RTY ; // Clean until last data is cleaned out from FIFO | |
965 | end | |
966 | S_READ: // READ from WB bus to PCIR_FIFO | |
967 | begin | |
968 | // Default values for signals not used in this state | |
969 | pciw_fifo_renable = 1'b0 ; | |
970 | addr_into_cnt = 1'b0 ; | |
971 | read_count_load = 1'b0 ; | |
972 | pci_error_sig_out = 1'b0 ; | |
973 | error_source_out = 1'b0 ; | |
974 | write_rty_cnt_exp_out = 1'b0 ; | |
975 | case ({wb_ack_i, wb_err_i, wb_rty_i}) | |
976 | 3'b100 : // If reading of one data is acknowledged | |
977 | begin | |
978 | pcir_fifo_wenable = 1'b1 ; // enable writting data into PCIR_FIFO | |
979 | addr_count = 1'b1 ; // prepare next address if there will be burst | |
980 | read_count_enable = 1'b1 ; // decrease counter value for cache line size | |
981 | retried_d = 1'b0 ; // there was no retry | |
982 | read_rty_cnt_exp_out = 1'b0 ; // there was no retry | |
983 | wait_for_wb_response = 1'b0 ; | |
984 | // if last data was transfered | |
985 | if (last_data_to_pcir_fifo) | |
986 | begin | |
987 | pcir_fifo_control[`LAST_CTRL_BIT] = 1'b1 ; // FIFO must indicate LAST data transfered | |
988 | pcir_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b0 ; | |
989 | pcir_fifo_control[`UNUSED_CTRL_BIT] = 1'b0 ; | |
990 | pcir_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ; | |
991 | last_data_transferred = 1'b1 ; // signal for last data transfered | |
992 | wb_read_done = 1'b1 ; // signal last data of read transaction for PCI Target | |
993 | n_state = S_TURN_ARROUND ; | |
994 | end | |
995 | else // if not last data transfered | |
996 | begin | |
997 | pcir_fifo_control = 4'h0 ; // ZERO for control code | |
998 | last_data_transferred = 1'b0 ; // not last data transfered | |
999 | wb_read_done = 1'b0 ; // read is not done yet | |
1000 | n_state = S_READ ; | |
1001 | end | |
1002 | end | |
1003 | 3'b010 : // If reading of one data is terminated with ERROR | |
1004 | begin | |
1005 | pcir_fifo_wenable = 1'b1 ; // enable for writting to FIFO data with ERROR | |
1006 | addr_count = 1'b0 ; // no need for new address | |
1007 | pcir_fifo_control[`LAST_CTRL_BIT] = 1'b0 ; | |
1008 | pcir_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b1 ; // FIFO must indicate the DATA with ERROR | |
1009 | pcir_fifo_control[`UNUSED_CTRL_BIT] = 1'b0 ; | |
1010 | pcir_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ; | |
1011 | last_data_transferred = 1'b1 ; // signal for last data transfered | |
1012 | wb_read_done = 1'b1 ; // signal last data of read transaction for PCI Target | |
1013 | read_count_enable = 1'b0 ; // no need for cache line, when error occures | |
1014 | n_state = S_TURN_ARROUND ; | |
1015 | retried_d = 1'b0 ; // there was no retry | |
1016 | wait_for_wb_response = 1'b0 ; | |
1017 | read_rty_cnt_exp_out = 1'b0 ; // there was no retry | |
1018 | end | |
1019 | 3'b001 : // If reading of one data is retried | |
1020 | begin | |
1021 | pcir_fifo_wenable = 1'b0 ; | |
1022 | pcir_fifo_control = 4'h0 ; | |
1023 | addr_count = 1'b0 ; | |
1024 | read_count_enable = 1'b0 ; | |
1025 | wait_for_wb_response = 1'b0 ; | |
1026 | case ({first_wb_data_access, rty_counter_almost_max_value}) | |
1027 | 2'b10 : | |
1028 | begin // if first data of the cycle (CYC_O) is retried - after each retry CYC_O goes inactive | |
1029 | n_state = S_IDLE ; // go to S_IDLE state for retrying the transaction | |
1030 | read_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired yet | |
1031 | last_data_transferred = 1'b0 ; | |
1032 | wb_read_done = 1'b0 ; | |
1033 | retried_d = 1'b1 ; // there was a retry | |
1034 | end | |
1035 | 2'b11 : | |
1036 | begin // if retry counter reached maximum value | |
1037 | n_state = S_READ_RTY ; // go here to wait for PCI Target to remove read request | |
1038 | read_rty_cnt_exp_out = 1'b1 ; // signal for reporting read counter expired | |
1039 | last_data_transferred = 1'b0 ; | |
1040 | wb_read_done = 1'b0 ; | |
1041 | retried_d = 1'b1 ; // there was a retry | |
1042 | end | |
1043 | default : // if retry occures after at least 1 data was transferred without breaking cycle (CYC_O inactive) | |
1044 | begin // then PCI device will retry access! | |
1045 | n_state = S_TURN_ARROUND ; // go to S_TURN_ARROUND state | |
1046 | read_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired | |
1047 | last_data_transferred = 1'b1 ; | |
1048 | wb_read_done = 1'b1 ; | |
1049 | retried_d = 1'b0 ; // retry must not be retried, since there is not a first data | |
1050 | end | |
1051 | endcase | |
1052 | end | |
1053 | default : | |
1054 | begin | |
1055 | addr_count = 1'b0 ; | |
1056 | read_count_enable = 1'b0 ; | |
1057 | read_rty_cnt_exp_out = 1'b0 ; | |
1058 | wait_for_wb_response = 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented) | |
1059 | if((rty_counter_almost_max_value)&&(set_retry)) // when no WB response and RTY CNT reached maximum allowed value | |
1060 | begin | |
1061 | retried_d = 1'b1 ; | |
1062 | n_state = S_TURN_ARROUND ; // go here to stop read request | |
1063 | pcir_fifo_wenable = 1'b1 ; | |
1064 | pcir_fifo_control[`LAST_CTRL_BIT] = 1'b0 ; | |
1065 | pcir_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b1 ; // FIFO must indicate the DATA with ERROR | |
1066 | pcir_fifo_control[`UNUSED_CTRL_BIT] = 1'b0 ; | |
1067 | pcir_fifo_control[`ADDR_CTRL_BIT] = 1'b0 ; | |
1068 | last_data_transferred = 1'b1 ; | |
1069 | wb_read_done = 1'b1 ; | |
1070 | end | |
1071 | else | |
1072 | begin | |
1073 | retried_d = 1'b0 ; | |
1074 | n_state = S_READ ; // stay in S_READ state to wait WB to response | |
1075 | pcir_fifo_wenable = 1'b0 ; | |
1076 | pcir_fifo_control = 4'h0 ; | |
1077 | last_data_transferred = 1'b0 ; | |
1078 | wb_read_done = 1'b0 ; | |
1079 | end | |
1080 | end | |
1081 | endcase | |
1082 | end | |
1083 | S_READ_RTY: // Wait for PCI Target to remove read request, when retry counter reaches maximum value! | |
1084 | begin | |
1085 | // Default values for signals not used in this state | |
1086 | pciw_fifo_renable = 1'b0 ; | |
1087 | pcir_fifo_wenable = 1'b0 ; | |
1088 | pcir_fifo_control = 4'h0 ; | |
1089 | addr_into_cnt = 1'b0 ; | |
1090 | read_count_load = 1'b0 ; | |
1091 | read_count_enable = 1'b0 ; | |
1092 | addr_count = 1'b0 ; | |
1093 | pci_error_sig_out = 1'b0 ; | |
1094 | error_source_out = 1'b0 ; | |
1095 | retried_d = 1'b0 ; | |
1096 | wb_read_done = 1'b0 ; | |
1097 | write_rty_cnt_exp_out = 1'b0 ; | |
1098 | read_rty_cnt_exp_out = 1'b0 ; | |
1099 | wait_for_wb_response = 1'b0 ; | |
1100 | // wait for PCI Target to remove read request | |
1101 | if (pci_tar_read_request) | |
1102 | begin | |
1103 | n_state = S_READ_RTY ; // stay in this state until read request is removed | |
1104 | last_data_transferred = 1'b0 ; | |
1105 | end | |
1106 | else // when read request is removed | |
1107 | begin | |
1108 | n_state = S_IDLE ; | |
1109 | last_data_transferred = 1'b1 ; // when read request is removed, there is "last" data | |
1110 | end | |
1111 | end | |
1112 | // Turn arround cycle after writting to PCIR_FIFO (for correct data when reading from PCIW_FIFO) | |
1113 | default: // S_TURN_ARROUND: | |
1114 | begin | |
1115 | // Default values for signals not used in this state | |
1116 | pciw_fifo_renable = 1'b0 ; | |
1117 | pcir_fifo_wenable = 1'b0 ; | |
1118 | pcir_fifo_control = 4'h0 ; | |
1119 | addr_into_cnt = 1'b0 ; | |
1120 | read_count_load = 1'b0 ; | |
1121 | read_count_enable = 1'b0 ; | |
1122 | addr_count = 1'b0 ; | |
1123 | pci_error_sig_out = 1'b0 ; | |
1124 | error_source_out = 1'b0 ; | |
1125 | retried_d = 1'b0 ; | |
1126 | last_data_transferred = 1'b1 ; | |
1127 | wb_read_done = 1'b0 ; | |
1128 | write_rty_cnt_exp_out = 1'b0 ; | |
1129 | read_rty_cnt_exp_out = 1'b0 ; | |
1130 | wait_for_wb_response = 1'b0 ; | |
1131 | n_state = S_IDLE ; | |
1132 | end | |
1133 | endcase | |
1134 | end | |
1135 | ||
1136 | // Signal for retry monitor in state machine when there is read and first (or single) data access | |
1137 | wire ack_rty_response = wb_ack_i || wb_rty_i ; | |
1138 | ||
1139 | // Signal first_wb_data_access is set when no WB cycle present till end of first data access of WB cycle on WB bus | |
1140 | always@(posedge wb_clock_in or posedge reset_in) | |
1141 | begin | |
1142 | if (reset_in) | |
1143 | first_wb_data_access = 1'b1 ; | |
1144 | else | |
1145 | begin | |
1146 | if (~wb_cyc_o) | |
1147 | first_wb_data_access = 1'b1 ; | |
1148 | else if (ack_rty_response) | |
1149 | first_wb_data_access = 1'b0 ; | |
1150 | end | |
1151 | end | |
1152 | ||
1153 | // Signals to FIFO | |
1154 | assign pcir_fifo_be_out = 4'hf ; // pci_tar_be ; | |
1155 | ||
1156 | // Signals to Conf. space | |
1157 | assign pci_error_bc = bc_register ; | |
1158 | ||
1159 | ||
1160 | always@(posedge wb_clock_in or posedge reset_in) | |
1161 | begin | |
1162 | if (reset_in) | |
1163 | wb_read_done_out <= #`FF_DELAY 1'b0 ; | |
1164 | else | |
1165 | wb_read_done_out <= #`FF_DELAY wb_read_done ; | |
1166 | end | |
1167 | ||
1168 | always@(pciw_fifo_renable or addr_into_cnt_reg or pciw_fifo_control_in or pciw_fifo_empty_in) | |
1169 | begin | |
1170 | pciw_fifo_renable_out = pciw_fifo_renable || addr_into_cnt_reg ; | |
1171 | last_data_from_pciw_fifo_reg = pciw_fifo_control_in[`ADDR_CTRL_BIT] || pciw_fifo_empty_in ; | |
1172 | end | |
1173 | ||
1174 | ||
1175 | endmodule | |
1176 |