//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// eth_fifo.v ////
|
//// eth_fifo.v ////
|
//// ////
|
//// ////
|
//// This file is part of the Ethernet IP core project ////
|
//// This file is part of the Ethernet IP core project ////
|
//// http://www.opencores.org/project,ethmac ////
|
//// http://www.opencores.org/project,ethmac ////
|
//// ////
|
//// ////
|
//// Author(s): ////
|
//// Author(s): ////
|
//// - Igor Mohor (igorM@opencores.org) ////
|
//// - Igor Mohor (igorM@opencores.org) ////
|
//// ////
|
//// ////
|
//// All additional information is avaliable in the Readme.txt ////
|
//// All additional information is avaliable in the Readme.txt ////
|
//// file. ////
|
//// file. ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2001 Authors ////
|
//// Copyright (C) 2001 Authors ////
|
//// ////
|
//// ////
|
//// 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 2002/04/22 13:45:52 mohor
|
// Revision 1.3 2002/04/22 13:45:52 mohor
|
// Generic ram or Xilinx ram can be used in fifo (selectable by setting
|
// Generic ram or Xilinx ram can be used in fifo (selectable by setting
|
// ETH_FIFO_XILINX in eth_defines.v).
|
// ETH_FIFO_XILINX in eth_defines.v).
|
//
|
//
|
// Revision 1.2 2002/03/25 13:33:04 mohor
|
// Revision 1.2 2002/03/25 13:33:04 mohor
|
// When clear and read/write are active at the same time, cnt and pointers are
|
// When clear and read/write are active at the same time, cnt and pointers are
|
// set to 1.
|
// set to 1.
|
//
|
//
|
// Revision 1.1 2002/02/05 16:44:39 mohor
|
// Revision 1.1 2002/02/05 16:44:39 mohor
|
// Both rx and tx part are finished. Tested with wb_clk_i between 10 and 200
|
// Both rx and tx part are finished. Tested with wb_clk_i between 10 and 200
|
// MHz. Statuses, overrun, control frame transmission and reception still need
|
// MHz. Statuses, overrun, control frame transmission and reception still need
|
// to be fixed.
|
// to be fixed.
|
//
|
//
|
//
|
//
|
|
|
`include "ethmac_defines.v"
|
`include "ethmac_defines.v"
|
`include "timescale.v"
|
`include "timescale.v"
|
|
|
module eth_fifo (data_in, data_out, clk, reset, write, read, clear,
|
module eth_fifo (data_in, data_out, clk, reset, write, read, clear,
|
almost_full, full, almost_empty, empty, cnt);
|
almost_full, full, almost_empty, empty, cnt);
|
|
|
parameter DATA_WIDTH = 32;
|
parameter DATA_WIDTH = 32;
|
parameter DEPTH = 8;
|
parameter DEPTH = 8;
|
parameter CNT_WIDTH = 4;
|
parameter CNT_WIDTH = 4;
|
|
|
input clk;
|
input clk;
|
input reset;
|
input reset;
|
input write;
|
input write;
|
input read;
|
input read;
|
input clear;
|
input clear;
|
input [DATA_WIDTH-1:0] data_in;
|
input [DATA_WIDTH-1:0] data_in;
|
|
|
output [DATA_WIDTH-1:0] data_out;
|
output [DATA_WIDTH-1:0] data_out;
|
output almost_full;
|
output almost_full;
|
output full;
|
output full;
|
output almost_empty;
|
output almost_empty;
|
output empty;
|
output empty;
|
output [CNT_WIDTH-1:0] cnt;
|
output [CNT_WIDTH-1:0] cnt;
|
|
|
`ifdef ETH_FIFO_XILINX
|
`ifdef ETH_FIFO_XILINX
|
`else
|
`else
|
`ifdef ETH_ALTERA_ALTSYNCRAM
|
`ifdef ETH_ALTERA_ALTSYNCRAM
|
`else
|
`else
|
reg [DATA_WIDTH-1:0] fifo [0:DEPTH-1];
|
reg [DATA_WIDTH-1:0] fifo [0:DEPTH-1];
|
reg [DATA_WIDTH-1:0] data_out;
|
reg [DATA_WIDTH-1:0] data_out;
|
`endif
|
`endif
|
`endif
|
`endif
|
|
|
reg [CNT_WIDTH-1:0] cnt;
|
reg [CNT_WIDTH-1:0] cnt;
|
reg [CNT_WIDTH-2:0] read_pointer;
|
reg [CNT_WIDTH-2:0] read_pointer;
|
reg [CNT_WIDTH-2:0] write_pointer;
|
reg [CNT_WIDTH-2:0] write_pointer;
|
|
|
|
|
always @ (posedge clk or posedge reset)
|
always @ (posedge clk or posedge reset)
|
begin
|
begin
|
if(reset)
|
if(reset)
|
cnt <= 0;
|
cnt <= 0;
|
else
|
else
|
if(clear)
|
if(clear)
|
cnt <= { {(CNT_WIDTH-1){1'b0}}, read^write};
|
cnt <= { {(CNT_WIDTH-1){1'b0}}, read^write};
|
else
|
else
|
if(read ^ write)
|
if(read ^ write)
|
if(read)
|
if(read)
|
cnt <= cnt - 1;
|
cnt <= cnt - 1;
|
else
|
else
|
cnt <= cnt + 1;
|
cnt <= cnt + 1;
|
end
|
end
|
|
|
|
|
always @ (posedge clk or posedge reset)
|
always @ (posedge clk or posedge reset)
|
begin
|
begin
|
if(reset)
|
if(reset)
|
read_pointer <= 0;
|
read_pointer <= 0;
|
else
|
else
|
if(clear)
|
if(clear)
|
read_pointer <= { {(CNT_WIDTH-2){1'b0}}, read};
|
read_pointer <= { {(CNT_WIDTH-2){1'b0}}, read};
|
else
|
else
|
if(read & ~empty)
|
if(read & ~empty)
|
read_pointer <= read_pointer + 1'b1;
|
read_pointer <= read_pointer + 1'b1;
|
end
|
end
|
|
|
always @ (posedge clk or posedge reset)
|
always @ (posedge clk or posedge reset)
|
begin
|
begin
|
if(reset)
|
if(reset)
|
write_pointer <= 0;
|
write_pointer <= 0;
|
else
|
else
|
if(clear)
|
if(clear)
|
write_pointer <= { {(CNT_WIDTH-2){1'b0}}, write};
|
write_pointer <= { {(CNT_WIDTH-2){1'b0}}, write};
|
else
|
else
|
if(write & ~full)
|
if(write & ~full)
|
write_pointer <= write_pointer + 1'b1;
|
write_pointer <= write_pointer + 1'b1;
|
end
|
end
|
|
|
assign empty = ~(|cnt);
|
assign empty = ~(|cnt);
|
assign almost_empty = cnt == 1;
|
assign almost_empty = cnt == 1;
|
assign full = cnt == DEPTH;
|
assign full = cnt == DEPTH;
|
assign almost_full = &cnt[CNT_WIDTH-2:0];
|
assign almost_full = &cnt[CNT_WIDTH-2:0];
|
|
|
|
|
|
|
`ifdef ETH_FIFO_XILINX
|
`ifdef ETH_FIFO_XILINX
|
xilinx_dist_ram_16x32 fifo
|
xilinx_dist_ram_16x32 fifo
|
( .data_out(data_out),
|
( .data_out(data_out),
|
.we(write & ~full),
|
.we(write & ~full),
|
.data_in(data_in),
|
.data_in(data_in),
|
.read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
|
.read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
|
.write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
|
.write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
|
.wclk(clk)
|
.wclk(clk)
|
);
|
);
|
`else // !ETH_FIFO_XILINX
|
`else // !ETH_FIFO_XILINX
|
`ifdef ETH_ALTERA_ALTSYNCRAM
|
`ifdef ETH_ALTERA_ALTSYNCRAM
|
altera_dpram_16x32 altera_dpram_16x32_inst
|
altera_dpram_16x32 altera_dpram_16x32_inst
|
(
|
(
|
.data (data_in),
|
.data (data_in),
|
.wren (write & ~full),
|
.wren (write & ~full),
|
.wraddress (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
|
.wraddress (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
|
.rdaddress (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
|
.rdaddress (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
|
.clock (clk),
|
.clock (clk),
|
.q (data_out)
|
.q (data_out)
|
); //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
|
); //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
|
`else // !ETH_ALTERA_ALTSYNCRAM
|
`else // !ETH_ALTERA_ALTSYNCRAM
|
always @ (posedge clk)
|
always @ (posedge clk)
|
begin
|
begin
|
if(write & clear)
|
if(write & clear)
|
fifo[0] <= data_in;
|
fifo[0] <= data_in;
|
else
|
else
|
if(write & ~full)
|
if(write & ~full)
|
fifo[write_pointer] <= data_in;
|
fifo[write_pointer] <= data_in;
|
end
|
end
|
|
|
|
|
always @ (posedge clk)
|
always @ (posedge clk)
|
begin
|
begin
|
if(clear)
|
if(clear)
|
data_out <= fifo[0];
|
data_out <= fifo[0];
|
else
|
else
|
data_out <= fifo[read_pointer];
|
data_out <= fifo[read_pointer];
|
end
|
end
|
`endif // !ETH_ALTERA_ALTSYNCRAM
|
`endif // !ETH_ALTERA_ALTSYNCRAM
|
`endif // !ETH_FIFO_XILINX
|
`endif // !ETH_FIFO_XILINX
|
|
|
|
|
endmodule
|
endmodule
|
|
|