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

Subversion Repositories ethmac

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

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
////  http://www.opencores.org/projects/ethmac/                   ////
7
////                                                              ////
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
parameter Tp            = 1;
69
 
70
input                     clk;
71
input                     reset;
72
input                     write;
73
input                     read;
74
input                     clear;
75
input   [DATA_WIDTH-1:0]  data_in;
76
 
77
output  [DATA_WIDTH-1:0]  data_out;
78
output                    almost_full;
79
output                    full;
80
output                    almost_empty;
81
output                    empty;
82 100 mohor
output  [CNT_WIDTH-1:0]   cnt;
83 40 mohor
 
84 100 mohor
`ifdef ETH_FIFO_XILINX
85
`else
86 330 igorm
  `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 100 mohor
`endif
92
 
93 40 mohor
reg     [CNT_WIDTH-1:0]   cnt;
94
reg     [CNT_WIDTH-2:0]   read_pointer;
95
reg     [CNT_WIDTH-2:0]   write_pointer;
96
 
97
 
98
always @ (posedge clk or posedge reset)
99
begin
100
  if(reset)
101
    cnt <=#Tp 0;
102
  else
103
  if(clear)
104 94 mohor
    cnt <=#Tp { {(CNT_WIDTH-1){1'b0}}, read^write};
105 40 mohor
  else
106
  if(read ^ write)
107
    if(read)
108
      cnt <=#Tp cnt - 1'b1;
109
    else
110
      cnt <=#Tp cnt + 1'b1;
111
end
112
 
113
always @ (posedge clk or posedge reset)
114
begin
115
  if(reset)
116
    read_pointer <=#Tp 0;
117
  else
118
  if(clear)
119 94 mohor
    read_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, read};
120 40 mohor
  else
121
  if(read & ~empty)
122
    read_pointer <=#Tp read_pointer + 1'b1;
123
end
124
 
125
always @ (posedge clk or posedge reset)
126
begin
127
  if(reset)
128
    write_pointer <=#Tp 0;
129
  else
130
  if(clear)
131 94 mohor
    write_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, write};
132 40 mohor
  else
133
  if(write & ~full)
134
    write_pointer <=#Tp write_pointer + 1'b1;
135
end
136
 
137
assign empty = ~(|cnt);
138
assign almost_empty = cnt == 1;
139
assign full  = cnt == DEPTH;
140
assign almost_full  = &cnt[CNT_WIDTH-2:0];
141
 
142
 
143
 
144 100 mohor
`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 330 igorm
`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 100 mohor
  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 40 mohor
 
175 330 igorm
  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 100 mohor
 
185 330 igorm
 
186 40 mohor
endmodule

powered by: WebSVN 2.1.0

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