source: XOpenSparcT1/trunk/OC-Ethernet/eth_fifo.v @ 6

Revision 6, 6.2 KB checked in by pntsvt00, 14 years ago (diff)

versione iniziale opensparc

Line 
1//////////////////////////////////////////////////////////////////////
2////                                                              ////
3////  eth_fifo.v                                                  ////
4////                                                              ////
5////  This file is part of the Ethernet IP core project           ////
6////  http://www.opencores.org/projects/ethmac/                   ////
7////                                                              ////
8////  Author(s):                                                  ////
9////      - Igor Mohor ([email protected])                      ////
10////                                                              ////
11////  All additional information is avaliable in the Readme.txt   ////
12////  file.                                                       ////
13////                                                              ////
14//////////////////////////////////////////////////////////////////////
15////                                                              ////
16//// Copyright (C) 2001 Authors                                   ////
17////                                                              ////
18//// This source file may be used and distributed without         ////
19//// restriction provided that this copyright statement is not    ////
20//// removed from the file and that any derivative work contains  ////
21//// the original copyright notice and the associated disclaimer. ////
22////                                                              ////
23//// This source file is free software; you can redistribute it   ////
24//// and/or modify it under the terms of the GNU Lesser General   ////
25//// Public License as published by the Free Software Foundation; ////
26//// either version 2.1 of the License, or (at your option) any   ////
27//// later version.                                               ////
28////                                                              ////
29//// This source is distributed in the hope that it will be       ////
30//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32//// PURPOSE.  See the GNU Lesser General Public License for more ////
33//// details.                                                     ////
34////                                                              ////
35//// You should have received a copy of the GNU Lesser General    ////
36//// Public License along with this source; if not, download it   ////
37//// from http://www.opencores.org/lgpl.shtml                     ////
38////                                                              ////
39//////////////////////////////////////////////////////////////////////
40//
41// CVS Revision History
42//
43// $Log: not supported by cvs2svn $
44// Revision 1.3  2002/04/22 13:45:52  mohor
45// Generic ram or Xilinx ram can be used in fifo (selectable by setting
46// ETH_FIFO_XILINX in eth_defines.v).
47//
48// Revision 1.2  2002/03/25 13:33:04  mohor
49// When clear and read/write are active at the same time, cnt and pointers are
50// set to 1.
51//
52// Revision 1.1  2002/02/05 16:44:39  mohor
53// Both rx and tx part are finished. Tested with wb_clk_i between 10 and 200
54// MHz. Statuses, overrun, control frame transmission and reception still  need
55// to be fixed.
56//
57//
58
59`include "eth_defines.v"
60`include "timescale.v"
61
62module eth_fifo (data_in, data_out, clk, reset, write, read, clear, almost_full, full, almost_empty, empty, cnt);
63
64parameter DATA_WIDTH    = 32;
65parameter DEPTH         = 8;
66parameter CNT_WIDTH     = 4;
67
68parameter Tp            = 1;
69
70input                     clk;
71input                     reset;
72input                     write;
73input                     read;
74input                     clear;
75input   [DATA_WIDTH-1:0]  data_in;
76
77output  [DATA_WIDTH-1:0]  data_out;
78output                    almost_full;
79output                    full;
80output                    almost_empty;
81output                    empty;
82output  [CNT_WIDTH-1:0]   cnt;
83
84`ifdef ETH_FIFO_XILINX
85`else
86  `ifdef ETH_ALTERA_ALTSYNCRAM
87  `else
88    reg     [DATA_WIDTH-1:0]  fifo  [0:DEPTH-1];
89    reg     [DATA_WIDTH-1:0]  data_out;
90  `endif
91`endif
92
93reg     [CNT_WIDTH-1:0]   cnt;
94reg     [CNT_WIDTH-2:0]   read_pointer;
95reg     [CNT_WIDTH-2:0]   write_pointer;
96
97
98always @ (posedge clk or posedge reset)
99begin
100  if(reset)
101    cnt <=#Tp 0;
102  else
103  if(clear)
104    cnt <=#Tp { {(CNT_WIDTH-1){1'b0}}, read^write};
105  else
106  if(read ^ write)
107    if(read)
108      cnt <=#Tp cnt - 1'b1;
109    else
110      cnt <=#Tp cnt + 1'b1;
111end
112
113always @ (posedge clk or posedge reset)
114begin
115  if(reset)
116    read_pointer <=#Tp 0;
117  else
118  if(clear)
119    read_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, read};
120  else
121  if(read & ~empty)
122    read_pointer <=#Tp read_pointer + 1'b1;
123end
124
125always @ (posedge clk or posedge reset)
126begin
127  if(reset)
128    write_pointer <=#Tp 0;
129  else
130  if(clear)
131    write_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, write};
132  else
133  if(write & ~full)
134    write_pointer <=#Tp write_pointer + 1'b1;
135end
136
137assign empty = ~(|cnt);
138assign almost_empty = cnt == 1;
139assign full  = cnt == DEPTH;
140assign almost_full  = &cnt[CNT_WIDTH-2:0];
141
142
143
144`ifdef ETH_FIFO_XILINX
145  xilinx_dist_ram_16x32 fifo
146  ( .data_out(data_out), 
147    .we(write & ~full),
148    .data_in(data_in),
149    .read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
150    .write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
151    .wclk(clk)
152  );
153`else   // !ETH_FIFO_XILINX
154`ifdef ETH_ALTERA_ALTSYNCRAM
155  altera_dpram_16x32    altera_dpram_16x32_inst
156  (
157        .data             (data_in),
158        .wren             (write & ~full),
159        .wraddress        (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
160        .rdaddress        (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
161        .clock            (clk),
162        .q                (data_out)
163  );  //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
164`else   // !ETH_ALTERA_ALTSYNCRAM
165  always @ (posedge clk)
166  begin
167    if(write & clear)
168      fifo[0] <=#Tp data_in;
169    else
170   if(write & ~full)
171      fifo[write_pointer] <=#Tp data_in;
172  end
173 
174
175  always @ (posedge clk)
176  begin
177    if(clear)
178      data_out <=#Tp fifo[0];
179    else
180      data_out <=#Tp fifo[read_pointer];
181  end
182`endif  // !ETH_ALTERA_ALTSYNCRAM
183`endif  // !ETH_FIFO_XILINX
184
185
186endmodule
Note: See TracBrowser for help on using the repository browser.