Line 40... |
Line 40... |
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.2 2001/10/05 08:14:30 mihad
|
|
// 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 "constants.v"
|
`include "pci_constants.v"
|
|
// synopsys translate_off
|
`include "timescale.v"
|
`include "timescale.v"
|
`ifdef FPGA
|
// synopsys translate_on
|
// fifo design in FPGA will be synchronous
|
|
`ifdef SYNCHRONOUS
|
|
`else
|
|
`define SYNCHRONOUS
|
|
`endif
|
|
`endif
|
|
module WBW_FIFO_CONTROL
|
module WBW_FIFO_CONTROL
|
(
|
(
|
rclock_in,
|
rclock_in,
|
wclock_in,
|
wclock_in,
|
renable_in,
|
renable_in,
|
Line 149... |
Line 148... |
assign almost_full_out = almost_full && ~full ;
|
assign almost_full_out = almost_full && ~full ;
|
|
|
// clear generation for FFs and registers
|
// clear generation for FFs and registers
|
wire clear = reset_in || flush_in ;
|
wire clear = reset_in || flush_in ;
|
|
|
`ifdef SYNCHRONOUS
|
|
|
|
reg wclock_nempty_detect ;
|
reg wclock_nempty_detect ;
|
always@(posedge reset_in or posedge wclock_in)
|
always@(posedge reset_in or posedge wclock_in)
|
begin
|
begin
|
if (reset_in)
|
if (reset_in)
|
wclock_nempty_detect <= #`FF_DELAY 1'b0 ;
|
wclock_nempty_detect <= #`FF_DELAY 1'b0 ;
|
Line 191... |
Line 188... |
|
|
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[(ADDR_LENGTH - 1):1] <= #`FF_DELAY { (ADDR_LENGTH - 1){1'b0}} ;
|
// initial value is important - raddr initial value is 4, so this one is 5
|
raddr_plus_one[0] <= #`FF_DELAY 1'b1 ;
|
raddr_plus_one <= #`FF_DELAY 5 ;
|
end
|
end
|
else if (rallow)
|
else if (rallow)
|
raddr_plus_one <= #`FF_DELAY raddr_plus_one + 1'b1 ;
|
raddr_plus_one <= #`FF_DELAY raddr_plus_one + 1'b1 ;
|
end
|
end
|
|
|
// raddr is filled with raddr_plus_one on rising read clock edge when rallow is high
|
// raddr is filled with raddr_plus_one on rising read clock edge when rallow is high
|
always@(posedge rclock_in or posedge clear)
|
always@(posedge rclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
// initial value is 000......00
|
// initial value is 4
|
raddr <= #`FF_DELAY { ADDR_LENGTH{1'b0}} ;
|
raddr <= #`FF_DELAY 4 ;
|
else if (rallow)
|
else if (rallow)
|
raddr <= #`FF_DELAY raddr_plus_one ;
|
raddr <= #`FF_DELAY raddr_plus_one ;
|
end
|
end
|
|
|
`else
|
|
// asynchronous RAM storage for FIFOs - somewhat simpler control logic
|
|
//rallow generation
|
|
assign rallow = renable_in && ~empty ;
|
|
|
|
assign rallow_out = rallow ;
|
|
|
|
// read address counter - normal counter, nothing to it
|
|
// for asynchronous implementation, there is no need for pointing to next address.
|
|
// On clock edge that read is performed, read address will change and on the next clock edge
|
|
// asynchronous memory will provide next data
|
|
always@(posedge rclock_in or posedge clear)
|
|
begin
|
|
if (clear)
|
|
// initial value is 000......00
|
|
raddr <= #`FF_DELAY { ADDR_LENGTH{1'b0}} ;
|
|
else if (rallow)
|
|
raddr <= #`FF_DELAY raddr + 1'b1 ;
|
|
end
|
|
|
|
assign empty_out = empty ;
|
|
assign raddr_out = raddr ;
|
|
`endif
|
|
|
|
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
Read address control consists of Read address counter and Grey Address pipeline
|
Read address control consists of Read address counter and Grey Address pipeline
|
There are 4 Grey addresses:
|
There are 4 Grey addresses:
|
- rgrey_minus2 is Grey Code of address two before current address
|
- rgrey_minus2 is Grey Code of address two before current address
|
- rgrey_minus1 is Grey Code of address one before current address
|
- rgrey_minus1 is Grey Code of address one before current address
|
Line 246... |
Line 219... |
// grey code register for two before read address
|
// grey code register for two before read address
|
always@(posedge rclock_in or posedge clear)
|
always@(posedge rclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
begin
|
begin
|
// initial value is 100......010
|
// initial value is 0
|
rgrey_minus2[(ADDR_LENGTH - 1)] <= #`FF_DELAY 1'b1 ;
|
rgrey_minus2 <= #`FF_DELAY 0 ;
|
rgrey_minus2[(ADDR_LENGTH - 2):2] <= #`FF_DELAY { (ADDR_LENGTH - 3){1'b0} } ;
|
|
rgrey_minus2[1:0] <= #`FF_DELAY 2'b10 ;
|
|
end
|
end
|
else
|
else
|
if (rallow)
|
if (rallow)
|
rgrey_minus2 <= #`FF_DELAY rgrey_minus1 ;
|
rgrey_minus2 <= #`FF_DELAY rgrey_minus1 ;
|
end
|
end
|
Line 261... |
Line 232... |
// grey code register for one before read address
|
// grey code register for one before read address
|
always@(posedge rclock_in or posedge clear)
|
always@(posedge rclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
begin
|
begin
|
// initial value is 100......011
|
// initial value is 1
|
rgrey_minus1[(ADDR_LENGTH - 1)] <= #`FF_DELAY 1'b1 ;
|
rgrey_minus1 <= #`FF_DELAY 1 ;
|
rgrey_minus1[(ADDR_LENGTH - 2):2] <= #`FF_DELAY { (ADDR_LENGTH - 3){1'b0} } ;
|
|
rgrey_minus1[1:0] <= #`FF_DELAY 2'b11 ;
|
|
end
|
end
|
else
|
else
|
if (rallow)
|
if (rallow)
|
rgrey_minus1 <= #`FF_DELAY rgrey_addr ;
|
rgrey_minus1 <= #`FF_DELAY rgrey_addr ;
|
end
|
end
|
Line 276... |
Line 245... |
// grey code register for read address - represents current Read Address
|
// grey code register for read address - represents current Read Address
|
always@(posedge rclock_in or posedge clear)
|
always@(posedge rclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
begin
|
begin
|
// initial value is 100.......01
|
// initial value is 3 = ...00011
|
rgrey_addr[(ADDR_LENGTH - 1)] <= #`FF_DELAY 1'b1 ;
|
rgrey_addr <= #`FF_DELAY 3 ;
|
rgrey_addr[(ADDR_LENGTH - 2):1] <= #`FF_DELAY { (ADDR_LENGTH - 2){1'b0} } ;
|
|
rgrey_addr[0] <= #`FF_DELAY 1'b1 ;
|
|
end
|
end
|
else
|
else
|
if (rallow)
|
if (rallow)
|
rgrey_addr <= #`FF_DELAY rgrey_next ;
|
rgrey_addr <= #`FF_DELAY rgrey_next ;
|
end
|
end
|
Line 291... |
Line 258... |
// grey code register for next read address - represents Grey Code of next read address
|
// grey code register for next read address - represents Grey Code of next read address
|
always@(posedge rclock_in or posedge clear)
|
always@(posedge rclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
begin
|
begin
|
// initial value is 100......00
|
// initial value is 2 = ...00010
|
rgrey_next[(ADDR_LENGTH - 1)] <= #`FF_DELAY 1'b1 ;
|
rgrey_next <= #`FF_DELAY 2 ;
|
rgrey_next[(ADDR_LENGTH - 2):0] <= #`FF_DELAY { (ADDR_LENGTH - 1){1'b0} } ;
|
|
end
|
end
|
else
|
else
|
if (rallow)
|
if (rallow)
|
rgrey_next <= #`FF_DELAY {raddr[ADDR_LENGTH - 1], calc_rgrey_next} ;
|
rgrey_next <= #`FF_DELAY {raddr[ADDR_LENGTH - 1], calc_rgrey_next} ;
|
end
|
end
|
Line 310... |
Line 276... |
// grey code register for write address
|
// grey code register for write address
|
always@(posedge wclock_in or posedge clear)
|
always@(posedge wclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
begin
|
begin
|
// initial value is 100.....001
|
// initial value is 3 = ....011
|
wgrey_addr[(ADDR_LENGTH - 1)] <= #`FF_DELAY 1'b1 ;
|
wgrey_addr <= #`FF_DELAY 3 ;
|
wgrey_addr[(ADDR_LENGTH - 2):1] <= #`FF_DELAY { (ADDR_LENGTH - 2){1'b0} } ;
|
|
wgrey_addr[0] <= #`FF_DELAY 1'b1 ;
|
|
end
|
end
|
else
|
else
|
if (wallow)
|
if (wallow)
|
wgrey_addr <= #`FF_DELAY wgrey_next ;
|
wgrey_addr <= #`FF_DELAY wgrey_next ;
|
end
|
end
|
Line 325... |
Line 289... |
// grey code register for next write address
|
// grey code register for next write address
|
always@(posedge wclock_in or posedge clear)
|
always@(posedge wclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
begin
|
begin
|
// initial value is 100......00
|
// initial value is 2 = ...010
|
wgrey_next[(ADDR_LENGTH - 1)] <= #`FF_DELAY 1'b1 ;
|
wgrey_next <= #`FF_DELAY 2 ;
|
wgrey_next[(ADDR_LENGTH - 2):0] <= #`FF_DELAY { (ADDR_LENGTH - 1){1'b0} } ;
|
|
end
|
end
|
else
|
else
|
if (wallow)
|
if (wallow)
|
wgrey_next <= #`FF_DELAY {waddr[(ADDR_LENGTH - 1)], calc_wgrey_next} ;
|
wgrey_next <= #`FF_DELAY {waddr[(ADDR_LENGTH - 1)], calc_wgrey_next} ;
|
end
|
end
|
|
|
// write address counter - nothing special
|
// write address counter - nothing special - initial value is important though
|
always@(posedge wclock_in or posedge clear)
|
always@(posedge wclock_in or posedge clear)
|
begin
|
begin
|
if (clear)
|
if (clear)
|
// initial value 00.........00
|
// initial value 4
|
waddr <= #`FF_DELAY { (ADDR_LENGTH){1'b0} } ;
|
waddr <= #`FF_DELAY 4 ;
|
else
|
else
|
if (wallow)
|
if (wallow)
|
waddr <= #`FF_DELAY waddr + 1'b1 ;
|
waddr <= #`FF_DELAY waddr + 1'b1 ;
|
end
|
end
|
|
|