1 //////////////////////////////////////////////////////////////////////
3 //// File name "pci_master32_sm_if.v" ////
5 //// This file is part of the "PCI bridge" project ////
6 //// http://www.opencores.org/cores/pci/ ////
9 //// - Miha Dolenc (mihad@opencores.org) ////
11 //// All additional information is avaliable in the README ////
15 //////////////////////////////////////////////////////////////////////
17 //// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org ////
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. ////
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. ////
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 ////
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 ////
40 //////////////////////////////////////////////////////////////////////
42 // CVS Revision History
44 // $Log: pci_master32_sm_if.v,v $
45 // Revision 1.1 2007-03-20 17:50:56 sithglan
48 // Revision 1.7 2004/03/19 16:36:55 mihad
49 // Single PCI Master write fix.
51 // Revision 1.6 2003/12/19 11:11:30 mihad
52 // Compact PCI Hot Swap support added.
53 // New testcases added.
54 // Specification updated.
55 // Test application changed to support WB B3 cycles.
57 // Revision 1.5 2003/06/12 10:12:22 mihad
58 // Changed one critical PCI bus signal logic.
60 // Revision 1.4 2003/01/27 16:49:31 mihad
61 // Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
63 // Revision 1.3 2002/02/01 15:25:12 mihad
64 // Repaired a few bugs, updated specification, added test bench files and design document
66 // Revision 1.2 2001/10/05 08:14:29 mihad
67 // Updated all files with inclusion of timescale file for simulation purposes.
69 // Revision 1.1.1.1 2001/10/02 15:33:46 mihad
70 // New project directory structure
74 `include "pci_constants.v"
75 `include "bus_commands.v"
77 // synopsys translate_off
78 `include "timescale.v"
79 // synopsys translate_on
81 /*====================================================================
82 Module provides interface between PCI bridge internals and PCI master
84 ====================================================================*/
85 module pci_master32_sm_if
90 // interconnect to pci master state machine
104 // status inputs from master SM
114 // WISHBONE WRITE fifo inputs and outputs
116 wbw_fifo_addr_data_in,
120 wbw_fifo_transaction_ready_in,
122 // WISHBONE READ fifo inputs and outputs
123 wbr_fifo_wenable_out,
126 wbr_fifo_control_out,
128 // delayed transaction control logic inputs and outputs
140 // configuration space interconnect
150 // two signals for pci control and status
154 posted_write_not_present_out
161 // PCI master state machine interconnect
162 output [31:0] address_out ; // address output
164 output [3:0] bc_out ; // bus command output
167 output [31:0] data_out ; // data output for writes
168 reg [31:0] data_out ;
170 input [31:0] data_in ; // data input for reads
171 output [3:0] be_out ; // byte enable output
174 output req_out ; // request output
176 output rdy_out ; // ready output
179 output last_out ; // last data indicator output
181 output [31:0] next_data_out ; // next data output
182 output [3:0] next_be_out ; // next byte enable output
183 output next_last_out ; // next transfer last indicator
193 // WISHBONE write fifo interconnect
194 output wbw_renable_out ; // WBW_FIFO read enable signal
196 input [31:0] wbw_fifo_addr_data_in ; // WBW_FIFO address/data bus
197 input [3:0] wbw_fifo_cbe_in ; // WBW_FIFO command/byte enable bus
198 input [3:0] wbw_fifo_control_in ; // WBW_FIFO control bus
199 input wbw_fifo_empty_in ; // WBW_FIFO's empty status indicator
200 input wbw_fifo_transaction_ready_in ; // WBW_FIFO transaction ready indicator
202 // WISHBONE read FIFO interconnect
203 output wbr_fifo_wenable_out ; // write enable for WBR_FIFO
205 output [31:0] wbr_fifo_data_out ; // data output to WBR_FIFO
207 output [3:0] wbr_fifo_be_out ; // byte enable output for WBR_FIFO
209 output [3:0] wbr_fifo_control_out ; // WBR_FIFO control output
211 // delayed transaction control logic inputs and outputs
212 input [31:0] del_wdata_in ; // delayed write data input
213 output del_complete_out ; // delayed transaction completed output
215 input del_req_in ; // delayed transaction request
216 input [31:0] del_addr_in ; // delayed transaction address
217 input [3:0] del_bc_in ; // delayed transaction bus command input
218 input [3:0] del_be_in ; // delayed transaction byte enables input
219 input del_burst_in ; // delayed transaction burst req. indicator
220 output del_error_out ; // delayed transation error termination signal
222 output del_rty_exp_out ; // retry expired output for delayed transactions
224 input del_we_in ; // delayed write request indicator
226 output [31:0] err_addr_out ; // erroneous address output
227 output [3:0] err_bc_out ; // erroneous bus command output
229 output err_signal_out ; // error signalization
231 output err_source_out ; // error source indicator
233 input [7:0] cache_line_size_in ; // cache line size value input
235 output err_rty_exp_out ; // retry expired error output
237 output mabort_received_out ; // master abort signaled to status register
238 output tabort_received_out ; // target abort signaled to status register
240 output posted_write_not_present_out ; // used in target state machine - must deny read completions when this signal is 0
243 assign err_bc_out = bc_out ;
245 // assign read outputs
246 /*==================================================================================================================
247 WISHBONE read FIFO data outputs - just link them to SM data outputs and delayed BE input
248 ==================================================================================================================*/
249 assign wbr_fifo_data_out = data_in ;
250 assign wbr_fifo_be_out = del_be_in ;
252 // decode if current bus command is configuration command
253 wire conf_cyc_bc = ( bc_out[3:1] == `BC_CONF_RW ) ;
255 // register for indicating that current data is also last in transfer
258 // register indicating that last data was transfered OK
259 reg last_transfered ;
260 always@(posedge reset_in or posedge clk_in)
263 last_transfered <= #`FF_DELAY 1'b0 ;
265 last_transfered <= #`FF_DELAY ~wait_in && last_out && wtransfer_in ;
268 // status signals output assignement
269 assign mabort_received_out = mabort_in ;
271 wire tabort_ff_in = ~wait_in && rerror_in ;
273 reg tabort_received_out ;
274 always@(posedge reset_in or posedge clk_in)
277 tabort_received_out <= #`FF_DELAY 1'b0 ;
279 tabort_received_out <= #`FF_DELAY tabort_ff_in ;
282 // error recovery indicator
285 // operation is locked until error recovery is in progress or error bit is not cleared in configuration space
286 wire err_lock = err_recovery ;
288 // three requests are possible - posted write, delayed write and delayed read
290 reg posted_write_req ;
293 // assign request output
294 assign req_out = del_write_req || posted_write_req || del_read_req ;
296 // posted write is not present, when WB Write Fifo is empty and posted write transaction is not beeing requested at present time
297 assign posted_write_not_present_out = !posted_write_req && wbw_fifo_empty_in ;
299 // write requests are staged, so data is read from source into current data register and next data register
301 always@(posedge reset_in or posedge clk_in)
304 write_req_int <= #`FF_DELAY 1'b0 ;
306 write_req_int <= #`FF_DELAY posted_write_req || del_write_req ;
310 // ready output is generated one clock after request for reads and two after for writes
311 always@(posedge reset_in or posedge clk_in)
314 rdy_out <= #`FF_DELAY 1'b0 ;
316 rdy_out <= #`FF_DELAY del_read_req || ( (posted_write_req || del_write_req) && write_req_int) ;
319 // wires with logic used as inputs to request FFs
320 wire do_posted_write = ( wbw_fifo_transaction_ready_in && ~wbw_fifo_empty_in && ~err_lock ) ;
321 wire do_del = ( del_req_in && ~err_lock && wbw_fifo_empty_in ) ;
322 wire do_del_write = do_del && del_we_in ;
323 wire do_del_read = do_del && ~del_we_in ;
325 // register for indicating current operation's data source
326 parameter DELAYED_WRITE = 1'b1 ;
327 parameter POSTED_WRITE = 1'b0 ;
329 // new data source - depending on which transaction will be processed next - delayed read is here because source of byte enables must
330 // be specified for delayed reads also - data source is not relevant for delayed reads, so value is don't care anyway
331 wire new_data_source = (do_del_write || do_del_read) ? DELAYED_WRITE : POSTED_WRITE ; // input to data source register
332 wire data_source_change = ~req_out ; // change (enable) for data source register - when no requests are in progress
334 reg data_source ; // data source value
335 always@(posedge reset_in or posedge clk_in)
338 // default value is posted write source - wbw_fifo
339 data_source <= #`FF_DELAY POSTED_WRITE ;
341 if (data_source_change)
342 // change data source on rising clock edge
343 data_source <= #`FF_DELAY new_data_source ;
346 // multiplexer for data output to PCI MASTER state machine
347 reg [31:0] source_data ;
348 reg [3:0] source_be ;
349 always@(data_source or wbw_fifo_addr_data_in or wbw_fifo_cbe_in or del_wdata_in or del_be_in or del_burst_in)
353 source_data = wbw_fifo_addr_data_in ;
354 source_be = wbw_fifo_cbe_in ;
357 source_data = del_wdata_in ;
358 // read all bytes during delayed burst read!
359 source_be = ~( del_be_in | {4{del_burst_in}} ) ;
364 wire waddr = wbw_fifo_control_in[`ADDR_CTRL_BIT] ;
366 // address change indicator - address is allowed to be loaded only when no transaction is in progress!
367 wire address_change = ~req_out ; // address change - whenever there is no request in progress
369 // new address - input to register storing address of current request - if posted write request will be next,
370 // load address and bus command from wbw_fifo, else load data from delayed transaction logic
371 wire [31:0] new_address = ( ~req_out && do_posted_write ) ? wbw_fifo_addr_data_in[31:0] : del_addr_in[31:0] ;
372 wire [3:0] new_bc = ( ~req_out && do_posted_write ) ? wbw_fifo_cbe_in : del_bc_in ;
374 // address counter enable - only for posted writes when data is actually transfered
375 wire addr_count_en = !wait_in && posted_write_req && rtransfer_in ;
377 always@(posedge reset_in or posedge clk_in)
380 bc_out <= #`FF_DELAY `BC_RESERVED0 ;
383 bc_out <= #`FF_DELAY new_bc ;
386 reg [29:0] current_dword_address ;
388 // DWORD address counter with load
389 always@(posedge reset_in or posedge clk_in)
392 current_dword_address <= #`FF_DELAY 30'h0000_0000 ;
395 current_dword_address <= #`FF_DELAY new_address[31:2] ;
398 current_dword_address <= #`FF_DELAY current_dword_address + 1'b1 ;
401 reg [1:0] current_byte_address ;
402 always@(posedge reset_in or posedge clk_in)
405 current_byte_address <= #`FF_DELAY 2'b00 ;
408 current_byte_address <= #`FF_DELAY new_address[1:0] ;
411 // byte address generation logic
412 reg [ 1: 0] generated_byte_adr ;
413 reg [ 1: 0] pci_byte_adr ;
418 4'bxxx0:generated_byte_adr = 2'b00 ;
419 4'bxx01:generated_byte_adr = 2'b01 ;
420 4'bx011:generated_byte_adr = 2'b10 ;
421 4'b0111:generated_byte_adr = 2'b11 ;
422 4'b1111:generated_byte_adr = 2'b00 ;
426 always@(generated_byte_adr or bc_out or current_byte_address)
428 // for memory access commands, set lower 2 address bits to 0
429 if ((bc_out == `BC_MEM_READ) | (bc_out == `BC_MEM_WRITE) |
430 (bc_out == `BC_MEM_READ_MUL) | (bc_out == `BC_MEM_READ_LN) |
431 (bc_out == `BC_MEM_WRITE_INVAL))
433 pci_byte_adr = 2'b00 ;
435 else if ((bc_out == `BC_IO_WRITE) | (bc_out == `BC_IO_READ))
437 pci_byte_adr = generated_byte_adr ;
441 pci_byte_adr = current_byte_address ;
445 // address output to PCI master state machine assignment
446 assign address_out = { current_dword_address, pci_byte_adr } ;
448 // the same for erroneous address assignement
449 assign err_addr_out = { current_dword_address, pci_byte_adr } ;
451 // cacheline size counter - for read transaction length control
452 // cache line count is enabled during burst reads when data is actually transfered
453 wire read_count_enable = ~wait_in && del_read_req && del_burst_in && wtransfer_in ;
455 // cache line counter is loaded when del read request is not in progress
456 wire read_count_load = ~del_read_req ;
458 reg [(`WBR_ADDR_LENGTH - 1):0] max_read_count ;
459 always@(cache_line_size_in or del_bc_in)
461 if ( (cache_line_size_in >= `WBR_DEPTH) || (~del_bc_in[1] && ~del_bc_in[0]) )
462 max_read_count = `WBR_DEPTH - 1'b1;
464 max_read_count = cache_line_size_in ;
467 reg [(`WBR_ADDR_LENGTH - 1):0] read_count ;
469 // cache line bound indicator - it signals when data for one complete cacheline was read
470 wire read_bound_comb = ~|(read_count[(`WBR_ADDR_LENGTH - 1):2]) ;
472 always@(posedge clk_in or posedge reset_in)
475 read_bound <= #`FF_DELAY 1'b0 ;
476 else if (read_count_load)
477 read_bound <= #`FF_DELAY 1'b0 ;
478 else if ( read_count_enable )
479 read_bound <= #`FF_DELAY read_bound_comb ;
482 wire read_count_change_val = read_count_load | read_count_enable ;
484 wire [(`WBR_ADDR_LENGTH - 1):0] read_count_next = read_count_load ? max_read_count : (read_count - 1'b1) ;
486 // down counter with load
487 always@(posedge reset_in or posedge clk_in)
490 read_count <= #`FF_DELAY 0 ;
492 /* if (read_count_load)
493 read_count <= #`FF_DELAY max_read_count ;
495 if (read_count_enable)
496 read_count <= #`FF_DELAY read_count - 1'b1 ;
497 */ if (read_count_change_val)
498 read_count <= #`FF_DELAY read_count_next ;
501 // flip flop indicating error recovery is in progress
502 reg err_recovery_in ;
503 always@(posedge reset_in or posedge clk_in)
506 err_recovery <= #`FF_DELAY 1'b0 ;
508 err_recovery <= #`FF_DELAY err_recovery_in ;
511 /*// retry counter implementation
512 reg [7:0] retry_count ;
514 wire retry_expired = ~|(retry_count[7:1]) ;
516 // loading of retry counter - whenever no request is present or other termination than retry or wait is signalled
517 wire retry_load = ~req_out || (~wait_in && rtransfer_in) ;
519 // retry DOWN counter with load
520 always@(posedge reset_in or posedge clk_in)
523 retry_count <= #`FF_DELAY 8'hFF ;
526 retry_count <= #`FF_DELAY `PCI_RTY_CNT_MAX ;
529 retry_count <= #`FF_DELAY retry_count - 1'b1 ;
532 /*==================================================================================================================
533 Delayed write requests are always single transfers!
534 Delayed write request starts, when no request is currently beeing processed and it is signaled from other side
536 ==================================================================================================================*/
537 // delayed write request FF input control
538 reg del_write_req_input ;
555 // delayed write is not in progress and is requested
556 // delayed write can be requested when no other request is in progress
557 del_write_req_input = ~posted_write_req && ~del_read_req && do_del_write ;
561 // delayed write request is in progress - assign input
562 del_write_req_input = wait_in ||
563 ( /*~( retry_in && retry_expired) &&*/
564 ~rtransfer_in && ~rerror_in && ~mabort_in
569 // delayed write request FLIP-FLOP
570 always@(posedge reset_in or posedge clk_in)
573 del_write_req <= #`FF_DELAY 1'b0 ;
575 del_write_req <= #`FF_DELAY del_write_req_input ;
578 /*================================================================================================
579 Posted write request indicator.
580 Posted write starts whenever no request is in progress and one whole posted write is
581 stored in WBW_FIFO. It ends on error terminations ( master, target abort, retry expired) or
582 data transfer terminations if last data is on top of FIFO.
583 Continues on wait, retry, and disconnect without data.
584 ================================================================================================*/
585 // posted write request FF input control
586 reg posted_write_req_input ;
601 if (~posted_write_req)
603 // posted write is not in progress
604 posted_write_req_input = ~del_write_req && ~del_read_req && do_posted_write ;
608 posted_write_req_input = wait_in ||
609 (/*~(retry_in && retry_expired && ~rtransfer_in) &&*/
610 ~rerror_in && ~mabort_in &&
617 // posted write request flip flop
618 always@(posedge reset_in or posedge clk_in)
621 posted_write_req <= #`FF_DELAY 1'b0 ;
623 posted_write_req <= #`FF_DELAY posted_write_req_input ;
627 /*================================================================================================
628 Delayed read request indicator.
629 Delayed read starts whenever no request is in progress and delayed read request is signaled from
630 other side of bridge. It ends on error terminations ( master, target abort, retry expired) or
631 data transfer terminations if it is not burst transfer or on cache line bounds on burst transfer.
632 It also ends on disconnects.
633 Continues on wait and retry.
634 ================================================================================================*/
635 // delayed read FF input control
636 reg del_read_req_input ;
655 del_read_req_input = ~del_write_req && ~posted_write_req && ~del_complete_out && do_del_read ;
659 del_read_req_input = wait_in ||
660 ( ~(retry_in && (~first_in /*|| retry_expired */)) &&
661 ~mabort_in && ~rerror_in &&
667 // delayed read request FF
668 always@(posedge reset_in or posedge clk_in)
671 del_read_req <= #`FF_DELAY 1'b0 ;
673 del_read_req <= #`FF_DELAY del_read_req_input ;
676 // wire indicating last entry of transaction on top of fifo
677 wire wlast = wbw_fifo_control_in[`LAST_CTRL_BIT] ;
679 wire last_int = posted_write_req && wlast || del_write_req ;
681 // intermidiate data, byte enable and last registers
682 reg [31:0] intermediate_data ;
683 reg [3:0] intermediate_be ;
684 reg intermediate_last ;
686 wire intermediate_enable = ( posted_write_req || del_write_req ) && ( ~write_req_int || (( ~rdy_out || ~wait_in && rtransfer_in ) && ~intermediate_last)) ;
688 always@(posedge reset_in or posedge clk_in)
692 intermediate_data <= #`FF_DELAY 32'h0000_0000 ;
693 intermediate_be <= #`FF_DELAY 4'h0 ;
694 intermediate_last <= #`FF_DELAY 1'b0 ;
697 if ( intermediate_enable )
699 intermediate_data <= #`FF_DELAY source_data ;
700 intermediate_be <= #`FF_DELAY source_be ;
701 intermediate_last <= #`FF_DELAY last_int ;
705 // multiplexer for next data
706 reg [31:0] next_data_out ;
707 reg [3:0] next_be_out ;
708 reg write_next_last ;
709 reg [3:0] write_next_be ;
717 wbw_fifo_addr_data_in or
723 if( rtransfer_in & ~wait_in )
725 next_data_out = wbw_fifo_addr_data_in ;
726 write_next_last = wlast ;
727 write_next_be = wbw_fifo_cbe_in ;
731 next_data_out = intermediate_data ;
732 write_next_last = intermediate_last ;
733 write_next_be = intermediate_be ;
737 always@(del_read_req or source_be or write_next_be)
740 next_be_out = source_be ;
742 next_be_out = write_next_be ;
744 /*================================================================================================
745 WBW_FIFO read enable - read from WBW_FIFO is performed on posted writes, when data transfer
746 termination is received - transfer or disconnect with data. Reads are enabled during error
747 recovery also, since erroneous transaction must be pulled out of FIFO!
748 ================================================================================================*/
749 // wbw_fifo read enable input control
751 assign wbw_renable_out = ~req_out && (do_posted_write || err_recovery) ||
752 posted_write_req && ( ~write_req_int || (~rdy_out && ~intermediate_last) || (~wait_in && rtransfer_in && ~intermediate_last)) ;
754 /*================================================================================================
755 WBR_FIFO write enable control -
756 writes to FIFO are possible only when delayed read request is in progress and data transfer
757 or error termination is signalled. It is not enabled on retry or disconnect without data.
758 ================================================================================================*/
759 // wbr_fifo write enable control - enabled when transfer is in progress and data is transfered or error is signalled
760 assign wbr_fifo_wenable_out = del_read_req && ~wait_in && ( rtransfer_in || mabort_in || rerror_in ) ;
762 /*================================================================================================
763 WBR_FIFO control output for identifying data entries.
764 This is necesary because of prefetched reads, which partially succeed. On error, error entry
765 gets in to signal it on WISHBONE bus if WISHBONE master reads up to this entry.
766 ================================================================================================*/
767 assign wbr_fifo_control_out[`ADDR_CTRL_BIT] = 1'b0 ;
768 assign wbr_fifo_control_out[`LAST_CTRL_BIT] = last_transfered ;
769 assign wbr_fifo_control_out[`DATA_ERROR_CTRL_BIT] = rerror_in || (mabort_in && ~conf_cyc_bc) ;
770 assign wbr_fifo_control_out[`UNUSED_CTRL_BIT] = 1'b0 ;
772 // retry expired error for posted writes control
773 //assign err_rty_exp_out = posted_write_req && ~wait_in && retry_in && retry_expired && ~rtransfer_in;
774 assign err_rty_exp_out = 1'b0 ;
776 // error source and error signal output control logic - only for posted writes
777 assign err_source_out = mabort_in /*|| err_rty_exp_out*/ ;
779 assign err_signal_out = /*err_rty_exp_out || */ posted_write_req && ~wait_in && (mabort_in || rerror_in) ;
781 //assign del_rty_exp_out = (~wait_in && (del_read_req || del_write_req)) && (retry_in && retry_expired && ~rtransfer_in) ;
782 assign del_rty_exp_out = 1'b0 ;
784 assign del_error_out = ~wait_in && (del_write_req || del_read_req) && ( (mabort_in && ~conf_cyc_bc) || rerror_in ) ;
786 wire del_write_complete = del_write_req && ~wait_in && ( rtransfer_in || rerror_in || mabort_in ) ;
787 wire del_read_complete = del_read_req && ~wait_in && ( rerror_in || mabort_in || last_transfered || ( retry_in && ~first_in ) ) ;
789 assign del_complete_out = ~wait_in && ( del_write_complete || del_read_complete ) ;
791 // next last output generation
792 assign next_last_out = del_write_req || del_read_req && ( ~del_burst_in || read_bound ) || posted_write_req && ( write_next_last ) ;
793 /*==================================================================================================================
794 Error recovery FF gets a value of one, when during posted write error occurs. It is cleared when all the data provided
795 for erroneous transaction is pulled out of WBW_FIFO
796 ==================================================================================================================*/
798 // error recovery flip flop input - used when posted write is terminated with an error
807 // when error recovery is not set - drive its input so it gets set
809 err_recovery_in = ~last_out && ~intermediate_last && err_signal_out ;
811 // when error recovery is set, wbw_fifo is enabled - clear err_recovery when last data entry of erroneous transaction is pulled out of fifo
812 err_recovery_in = ~wlast ;
815 wire data_out_load = (posted_write_req || del_write_req) && ( !rdy_out || ( !wait_in && rtransfer_in ) ) ;
817 wire be_out_load = (req_out && !rdy_out) || ( posted_write_req && !wait_in && rtransfer_in ) ;
819 wire last_load = req_out && ( ~rdy_out || ~wait_in && wtransfer_in ) ;
821 always@(posedge reset_in or posedge clk_in)
824 data_out <= #`FF_DELAY 32'h0000_0000 ;
827 data_out <= #`FF_DELAY intermediate_data ;
830 always@(posedge clk_in or posedge reset_in)
833 be_out <= #`FF_DELAY 4'hF ;
836 be_out <= #`FF_DELAY posted_write_req ? intermediate_be : source_be ;
839 always@(posedge reset_in or posedge clk_in)
842 current_last <= #`FF_DELAY 1'b0 ;
845 current_last <= #`FF_DELAY next_last_out ;
848 assign last_out = current_last ;