OpenCores
URL https://opencores.org/ocsvn/pci/pci/trunk

Subversion Repositories pci

[/] [pci/] [tags/] [rel_7/] [rtl/] [verilog/] [pci_wbr_fifo_control.v] - Diff between revs 114 and 154

Only display areas with differences | Details | Blame | View Log

Rev 114 Rev 154
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
////  File name "wbr_fifo_control.v"                              ////
////  File name "wbr_fifo_control.v"                              ////
////                                                              ////
////                                                              ////
////  This file is part of the "PCI bridge" project               ////
////  This file is part of the "PCI bridge" project               ////
////  http://www.opencores.org/cores/pci/                         ////
////  http://www.opencores.org/cores/pci/                         ////
////                                                              ////
////                                                              ////
////  Author(s):                                                  ////
////  Author(s):                                                  ////
////      - Miha Dolenc (mihad@opencores.org)                     ////
////      - Miha Dolenc (mihad@opencores.org)                     ////
////                                                              ////
////                                                              ////
////  All additional information is avaliable in the README       ////
////  All additional information is avaliable in the README       ////
////  file.                                                       ////
////  file.                                                       ////
////                                                              ////
////                                                              ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
//// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org          ////
//// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org          ////
////                                                              ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
//// later version.                                               ////
////                                                              ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
//// details.                                                     ////
////                                                              ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
//
// CVS Revision History
// CVS Revision History
//
//
// $Log: not supported by cvs2svn $
// $Log: not supported by cvs2svn $
// Revision 1.3  2003/07/29 08:20:11  mihad
// Revision 1.3  2003/07/29 08:20:11  mihad
// Found and simulated the problem in the synchronization logic.
// Found and simulated the problem in the synchronization logic.
// Repaired the synchronization logic in the FIFOs.
// Repaired the synchronization logic in the FIFOs.
//
//
// Revision 1.2  2003/03/26 13:16:18  mihad
// Revision 1.2  2003/03/26 13:16:18  mihad
// Added the reset value parameter to the synchronizer flop module.
// Added the reset value parameter to the synchronizer flop module.
// Added resets to all synchronizer flop instances.
// Added resets to all synchronizer flop instances.
// Repaired initial sync value in fifos.
// Repaired initial sync value in fifos.
//
//
// Revision 1.1  2003/01/27 16:49:31  mihad
// Revision 1.1  2003/01/27 16:49:31  mihad
// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
//
//
// Revision 1.6  2002/11/27 20:36:12  mihad
// Revision 1.6  2002/11/27 20:36:12  mihad
// Changed the code a bit to make it more readable.
// Changed the code a bit to make it more readable.
// Functionality not changed in any way.
// Functionality not changed in any way.
// More robust synchronization in fifos is still pending.
// More robust synchronization in fifos is still pending.
//
//
// Revision 1.5  2002/09/30 16:03:04  mihad
// Revision 1.5  2002/09/30 16:03:04  mihad
// Added meta flop module for easier meta stable FF identification during synthesis
// Added meta flop module for easier meta stable FF identification during synthesis
//
//
// Revision 1.4  2002/09/25 15:53:52  mihad
// Revision 1.4  2002/09/25 15:53:52  mihad
// Removed all logic from asynchronous reset network
// Removed all logic from asynchronous reset network
//
//
// Revision 1.3  2002/02/01 15:25:13  mihad
// Revision 1.3  2002/02/01 15:25:13  mihad
// Repaired a few bugs, updated specification, added test bench files and design document
// Repaired a few bugs, updated specification, added test bench files and design document
//
//
// Revision 1.2  2001/10/05 08:14:30  mihad
// Revision 1.2  2001/10/05 08:14:30  mihad
// Updated all files with inclusion of timescale file for simulation purposes.
// Updated all files with inclusion of timescale file for simulation purposes.
//
//
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
// New project directory structure
// New project directory structure
//
//
//
//
 
 
/* FIFO_CONTROL module provides read/write address and status generation for
/* FIFO_CONTROL module provides read/write address and status generation for
   FIFOs implemented with standard dual port SRAM cells in ASIC or FPGA designs */
   FIFOs implemented with standard dual port SRAM cells in ASIC or FPGA designs */
`include "pci_constants.v"
`include "pci_constants.v"
// synopsys translate_off
// synopsys translate_off
`include "timescale.v"
`include "timescale.v"
// synopsys translate_on
// synopsys translate_on
 
 
module pci_wbr_fifo_control
module pci_wbr_fifo_control
(
(
    rclock_in,
    rclock_in,
    wclock_in,
    wclock_in,
    renable_in,
    renable_in,
    wenable_in,
    wenable_in,
    reset_in,
    reset_in,
    flush_in,
    flush_in,
    empty_out,
    empty_out,
    waddr_out,
    waddr_out,
    raddr_out,
    raddr_out,
    rallow_out,
    rallow_out,
    wallow_out
    wallow_out
) ;
) ;
 
 
parameter ADDR_LENGTH = 7 ;
parameter ADDR_LENGTH = 7 ;
 
 
// independent clock inputs - rclock_in = read clock, wclock_in = write clock
// independent clock inputs - rclock_in = read clock, wclock_in = write clock
input  rclock_in, wclock_in;
input  rclock_in, wclock_in;
 
 
// enable inputs - read address changes on rising edge of rclock_in when reads are allowed
// enable inputs - read address changes on rising edge of rclock_in when reads are allowed
//                 write address changes on rising edge of wclock_in when writes are allowed
//                 write address changes on rising edge of wclock_in when writes are allowed
input  renable_in, wenable_in;
input  renable_in, wenable_in;
 
 
// reset input
// reset input
input  reset_in;
input  reset_in;
 
 
// flush input
// flush input
input flush_in ;
input flush_in ;
 
 
// empty status output
// empty status output
output empty_out;
output empty_out;
 
 
// read and write addresses outputs
// read and write addresses outputs
output [(ADDR_LENGTH - 1):0] waddr_out, raddr_out;
output [(ADDR_LENGTH - 1):0] waddr_out, raddr_out;
 
 
// read and write allow outputs
// read and write allow outputs
output rallow_out, wallow_out ;
output rallow_out, wallow_out ;
 
 
// read address register
// read address register
reg [(ADDR_LENGTH - 1):0] raddr ;
reg [(ADDR_LENGTH - 1):0] raddr ;
 
 
// write address register
// write address register
reg [(ADDR_LENGTH - 1):0] waddr;
reg [(ADDR_LENGTH - 1):0] waddr;
assign waddr_out = waddr ;
assign waddr_out = waddr ;
 
 
// grey code register
// grey code register
reg [(ADDR_LENGTH - 1):0] wgrey_addr ;
reg [(ADDR_LENGTH - 1):0] wgrey_addr ;
 
 
// next write gray address calculation - bitwise xor between address and shifted address
// next write gray address calculation - bitwise xor between address and shifted address
wire [(ADDR_LENGTH - 2):0] calc_wgrey_next  = waddr[(ADDR_LENGTH - 1):1] ^ waddr[(ADDR_LENGTH - 2):0] ;
wire [(ADDR_LENGTH - 2):0] calc_wgrey_next  = waddr[(ADDR_LENGTH - 1):1] ^ waddr[(ADDR_LENGTH - 2):0] ;
 
 
// grey code register
// grey code register
reg [(ADDR_LENGTH - 1):0] rgrey_addr ;
reg [(ADDR_LENGTH - 1):0] rgrey_addr ;
 
 
// next read gray address calculation - bitwise xor between address and shifted address
// next read gray address calculation - bitwise xor between address and shifted address
wire [(ADDR_LENGTH - 2):0] calc_rgrey_next  = raddr[(ADDR_LENGTH - 1):1] ^ raddr[(ADDR_LENGTH - 2):0] ;
wire [(ADDR_LENGTH - 2):0] calc_rgrey_next  = raddr[(ADDR_LENGTH - 1):1] ^ raddr[(ADDR_LENGTH - 2):0] ;
 
 
// FF for registered empty flag
// FF for registered empty flag
wire empty ;
wire empty ;
 
 
// write allow wire
// write allow wire
wire wallow = wenable_in ;
wire wallow = wenable_in ;
 
 
// write allow output assignment
// write allow output assignment
assign wallow_out = wallow ;
assign wallow_out = wallow ;
 
 
// read allow wire
// read allow wire
wire rallow ;
wire rallow ;
 
 
// clear generation for FFs and registers
// clear generation for FFs and registers
wire clear = reset_in /*|| flush_in*/ ; // flush changed to synchronous operation
wire clear = reset_in /*|| flush_in*/ ; // flush changed to synchronous operation
 
 
assign empty_out = empty ;
assign empty_out = empty ;
 
 
//rallow generation
//rallow generation
assign rallow = renable_in && !empty ; // reads allowed if read enable is high and FIFO is not empty
assign rallow = renable_in && !empty ; // reads allowed if read enable is high and FIFO is not empty
 
 
// rallow output assignment
// rallow output assignment
assign rallow_out = renable_in ;
assign rallow_out = renable_in ;
 
 
// at any clock edge that rallow is high, this register provides next read address, so wait cycles are not necessary
// at any clock edge that rallow is high, this register provides next read address, so wait cycles are not necessary
// when FIFO is empty, this register provides actual read address, so first location can be read
// when FIFO is empty, this register provides actual read address, so first location can be read
reg [(ADDR_LENGTH - 1):0] raddr_plus_one ;
reg [(ADDR_LENGTH - 1):0] raddr_plus_one ;
 
 
// address output mux - when FIFO is empty, current actual address is driven out, when it is non - empty next address is driven out
// address output mux - when FIFO is empty, current actual address is driven out, when it is non - empty next address is driven out
// done for zero wait state burst
// done for zero wait state burst
assign raddr_out = rallow ? raddr_plus_one : raddr ;
assign raddr_out = rallow ? raddr_plus_one : raddr ;
 
 
always@(posedge rclock_in or posedge clear)
always@(posedge rclock_in or posedge clear)
begin
begin
    if (clear)
    if (clear)
    begin
    begin
        raddr_plus_one <= #`FF_DELAY 2 ;
        raddr_plus_one <= #`FF_DELAY 2 ;
        raddr          <= #`FF_DELAY 1 ;
        raddr          <= #`FF_DELAY 1 ;
    end
    end
    else if (flush_in)
    else if (flush_in)
    begin
    begin
        raddr_plus_one <= #`FF_DELAY waddr + 1'b1 ;
        raddr_plus_one <= #`FF_DELAY waddr + 1'b1 ;
        raddr          <= #`FF_DELAY waddr ;
        raddr          <= #`FF_DELAY waddr ;
    end
    end
    else if (rallow)
    else if (rallow)
    begin
    begin
        raddr_plus_one <= #`FF_DELAY raddr_plus_one + 1'b1 ;
        raddr_plus_one <= #`FF_DELAY raddr_plus_one + 1'b1 ;
        raddr          <= #`FF_DELAY raddr_plus_one ;
        raddr          <= #`FF_DELAY raddr_plus_one ;
    end
    end
end
end
 
 
/*-----------------------------------------------------------------------------------------------
/*-----------------------------------------------------------------------------------------------
Read address control consists of Read address counter and Grey Address register
Read address control consists of Read address counter and Grey Address register
--------------------------------------------------------------------------------------------------*/
--------------------------------------------------------------------------------------------------*/
// grey coded address
// grey coded address
always@(posedge rclock_in or posedge clear)
always@(posedge rclock_in or posedge clear)
begin
begin
    if (clear)
    if (clear)
    begin
    begin
        rgrey_addr <= #`FF_DELAY 0 ;
        rgrey_addr <= #`FF_DELAY 0 ;
    end
    end
    else if (flush_in)
    else if (flush_in)
    begin
    begin
        rgrey_addr <= #`FF_DELAY wgrey_addr ;   // when flushed, copy value from write side
        rgrey_addr <= #`FF_DELAY wgrey_addr ;   // when flushed, copy value from write side
    end
    end
    else if (rallow)
    else if (rallow)
    begin
    begin
        rgrey_addr <= #`FF_DELAY {raddr[ADDR_LENGTH - 1], calc_rgrey_next} ;
        rgrey_addr <= #`FF_DELAY {raddr[ADDR_LENGTH - 1], calc_rgrey_next} ;
    end
    end
end
end
 
 
/*--------------------------------------------------------------------------------------------
/*--------------------------------------------------------------------------------------------
Write address control consists of write address counter and Grey Code Register
Write address control consists of write address counter and Grey Code Register
----------------------------------------------------------------------------------------------*/
----------------------------------------------------------------------------------------------*/
// grey coded address for status generation in write clock domain
// grey coded address for status generation in write clock domain
always@(posedge wclock_in or posedge clear)
always@(posedge wclock_in or posedge clear)
begin
begin
    if (clear)
    if (clear)
    begin
    begin
        wgrey_addr <= #1 0 ;
        wgrey_addr <= #1 0 ;
    end
    end
    else
    else
    if (wallow)
    if (wallow)
    begin
    begin
        wgrey_addr <= #1 {waddr[(ADDR_LENGTH - 1)], calc_wgrey_next} ;
        wgrey_addr <= #1 {waddr[(ADDR_LENGTH - 1)], calc_wgrey_next} ;
    end
    end
end
end
 
 
// write address counter - nothing special except initial value
// write address counter - nothing special except initial value
always@(posedge wclock_in or posedge clear)
always@(posedge wclock_in or posedge clear)
begin
begin
    if (clear)
    if (clear)
        // initial value is 1
        // initial value is 1
        waddr <= #`FF_DELAY 1 ;
        waddr <= #`FF_DELAY 1 ;
    else
    else
    if (wallow)
    if (wallow)
        waddr <= #`FF_DELAY waddr + 1'b1 ;
        waddr <= #`FF_DELAY waddr + 1'b1 ;
end
end
 
 
 
 
/*------------------------------------------------------------------------------------------------------------------------------
/*------------------------------------------------------------------------------------------------------------------------------
Empty control:
Empty control:
Gray coded write address pointer is synchronized to read clock domain and compared to Gray coded read address pointer.
Gray coded write address pointer is synchronized to read clock domain and compared to Gray coded read address pointer.
If they are equal, fifo is empty.
If they are equal, fifo is empty.
--------------------------------------------------------------------------------------------------------------------------------*/
--------------------------------------------------------------------------------------------------------------------------------*/
wire [(ADDR_LENGTH - 1):0] rclk_sync_wgrey_addr ;
wire [(ADDR_LENGTH - 1):0] rclk_sync_wgrey_addr ;
reg  [(ADDR_LENGTH - 1):0] rclk_wgrey_addr ;
reg  [(ADDR_LENGTH - 1):0] rclk_wgrey_addr ;
pci_synchronizer_flop #(ADDR_LENGTH, 0) i_synchronizer_reg_wgrey_addr
pci_synchronizer_flop #(ADDR_LENGTH, 0) i_synchronizer_reg_wgrey_addr
(
(
    .data_in        (wgrey_addr),
    .data_in        (wgrey_addr),
    .clk_out        (rclock_in),
    .clk_out        (rclock_in),
    .sync_data_out  (rclk_sync_wgrey_addr),
    .sync_data_out  (rclk_sync_wgrey_addr),
    .async_reset    (clear)
    .async_reset    (clear)
) ;
) ;
 
 
always@(posedge rclock_in or posedge clear)
always@(posedge rclock_in or posedge clear)
begin
begin
    if (clear)
    if (clear)
        rclk_wgrey_addr <= #`FF_DELAY 0 ;
        rclk_wgrey_addr <= #`FF_DELAY 0 ;
    else
    else
        rclk_wgrey_addr <= #`FF_DELAY rclk_sync_wgrey_addr ;
        rclk_wgrey_addr <= #`FF_DELAY rclk_sync_wgrey_addr ;
end
end
 
 
assign empty = (rgrey_addr == rclk_wgrey_addr) ;
assign empty = (rgrey_addr == rclk_wgrey_addr) ;
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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