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

Subversion Repositories ethmac

[/] [ethmac/] [trunk/] [rtl/] [verilog/] [eth_fifo.v] - Blame information for rev 353

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 40 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_fifo.v                                                  ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 346 olof
////  http://www.opencores.org/project,ethmac                     ////
7 40 mohor
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
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 330 igorm
// 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 100 mohor
// 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 94 mohor
// 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 40 mohor
//
57 94 mohor
//
58 40 mohor
 
59 100 mohor
`include "eth_defines.v"
60 40 mohor
`include "timescale.v"
61
 
62 100 mohor
module eth_fifo (data_in, data_out, clk, reset, write, read, clear, almost_full, full, almost_empty, empty, cnt);
63 40 mohor
 
64
parameter DATA_WIDTH    = 32;
65
parameter DEPTH         = 8;
66
parameter CNT_WIDTH     = 4;
67
 
68
input                     clk;
69
input                     reset;
70
input                     write;
71
input                     read;
72
input                     clear;
73
input   [DATA_WIDTH-1:0]  data_in;
74
 
75
output  [DATA_WIDTH-1:0]  data_out;
76
output                    almost_full;
77
output                    full;
78
output                    almost_empty;
79
output                    empty;
80 100 mohor
output  [CNT_WIDTH-1:0]   cnt;
81 40 mohor
 
82 100 mohor
`ifdef ETH_FIFO_XILINX
83
`else
84 330 igorm
  `ifdef ETH_ALTERA_ALTSYNCRAM
85
  `else
86
    reg     [DATA_WIDTH-1:0]  fifo  [0:DEPTH-1];
87
    reg     [DATA_WIDTH-1:0]  data_out;
88
  `endif
89 100 mohor
`endif
90
 
91 40 mohor
reg     [CNT_WIDTH-1:0]   cnt;
92
reg     [CNT_WIDTH-2:0]   read_pointer;
93
reg     [CNT_WIDTH-2:0]   write_pointer;
94
 
95
 
96
always @ (posedge clk or posedge reset)
97
begin
98
  if(reset)
99 352 olof
    cnt <= 0;
100 40 mohor
  else
101
  if(clear)
102 352 olof
    cnt <= { {(CNT_WIDTH-1){1'b0}}, read^write};
103 40 mohor
  else
104
  if(read ^ write)
105
    if(read)
106 352 olof
      cnt <= cnt - 1'b1;
107 40 mohor
    else
108 352 olof
      cnt <= cnt + 1'b1;
109 40 mohor
end
110
 
111
always @ (posedge clk or posedge reset)
112
begin
113
  if(reset)
114 352 olof
    read_pointer <= 0;
115 40 mohor
  else
116
  if(clear)
117 352 olof
    read_pointer <= { {(CNT_WIDTH-2){1'b0}}, read};
118 40 mohor
  else
119
  if(read & ~empty)
120 352 olof
    read_pointer <= read_pointer + 1'b1;
121 40 mohor
end
122
 
123
always @ (posedge clk or posedge reset)
124
begin
125
  if(reset)
126 352 olof
    write_pointer <= 0;
127 40 mohor
  else
128
  if(clear)
129 352 olof
    write_pointer <= { {(CNT_WIDTH-2){1'b0}}, write};
130 40 mohor
  else
131
  if(write & ~full)
132 352 olof
    write_pointer <= write_pointer + 1'b1;
133 40 mohor
end
134
 
135
assign empty = ~(|cnt);
136
assign almost_empty = cnt == 1;
137
assign full  = cnt == DEPTH;
138
assign almost_full  = &cnt[CNT_WIDTH-2:0];
139
 
140
 
141
 
142 100 mohor
`ifdef ETH_FIFO_XILINX
143
  xilinx_dist_ram_16x32 fifo
144
  ( .data_out(data_out),
145
    .we(write & ~full),
146
    .data_in(data_in),
147
    .read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
148
    .write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
149
    .wclk(clk)
150
  );
151 330 igorm
`else   // !ETH_FIFO_XILINX
152
`ifdef ETH_ALTERA_ALTSYNCRAM
153
  altera_dpram_16x32    altera_dpram_16x32_inst
154
  (
155
        .data             (data_in),
156
        .wren             (write & ~full),
157
        .wraddress        (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
158
        .rdaddress        (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
159
        .clock            (clk),
160
        .q                (data_out)
161
  );  //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
162
`else   // !ETH_ALTERA_ALTSYNCRAM
163 100 mohor
  always @ (posedge clk)
164
  begin
165
    if(write & clear)
166 352 olof
      fifo[0] <= data_in;
167 100 mohor
    else
168
   if(write & ~full)
169 352 olof
      fifo[write_pointer] <= data_in;
170 100 mohor
  end
171
 
172 40 mohor
 
173 330 igorm
  always @ (posedge clk)
174
  begin
175
    if(clear)
176 352 olof
      data_out <= fifo[0];
177 330 igorm
    else
178 352 olof
      data_out <= fifo[read_pointer];
179 330 igorm
  end
180
`endif  // !ETH_ALTERA_ALTSYNCRAM
181
`endif  // !ETH_FIFO_XILINX
182 100 mohor
 
183 330 igorm
 
184 40 mohor
endmodule

powered by: WebSVN 2.1.0

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