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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [ethmac/] [eth_fifo.v] - Blame information for rev 409

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

Line No. Rev Author Line
1 6 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_fifo.v                                                  ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 409 julius
////  http://www.opencores.org/project,ethmac                   ////
7 6 julius
////                                                              ////
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 403 julius
// $Log: not supported by cvs2svn $
44 6 julius
// 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 409 julius
// ETH_FIFO_XILINX in ethmac_defines.v).
47 6 julius
//
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 409 julius
`include "ethmac_defines.v"
60 6 julius
`include "timescale.v"
61
 
62
module eth_fifo (data_in, data_out, clk, reset, write, read, clear, almost_full, full, almost_empty, empty, cnt);
63
 
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
output  [CNT_WIDTH-1:0]   cnt;
81
 
82
 
83
 
84 403 julius
reg [CNT_WIDTH-1:0]        cnt;
85
   reg                    final_read;
86
 
87 6 julius
always @ (posedge clk or posedge reset)
88
begin
89
  if(reset)
90 403 julius
    cnt <= 0;
91 6 julius
  else
92
  if(clear)
93 403 julius
    cnt <= { {(CNT_WIDTH-1){1'b0}}, read^write};
94 6 julius
  else
95
  if(read ^ write)
96
    if(read)
97 403 julius
      cnt <= cnt - 1'b1;
98 6 julius
    else
99 403 julius
      cnt <= cnt + 1'b1;
100 6 julius
end
101
 
102 403 julius
 
103
`ifdef ETH_FIFO_GENERIC
104
 
105
   reg     [DATA_WIDTH-1:0]  fifo  [0:DEPTH-1] /*synthesis syn_ramstyle = "no_rw_check"*/ ;
106
 
107
 
108
   // This should make the synthesis tool infer RAMs
109
   reg [CNT_WIDTH-2:0] waddr, raddr, raddr_reg;
110
   reg                 clear_reg; // Register the clear pulse   
111
 
112
   always @(posedge clk)
113
     if (reset)
114
       waddr <= 0;
115
     else if (write)
116
       waddr <= waddr + 1;
117
 
118
   wire                raddr_reg_adv;
119
   reg                 read_reg;
120
   always @(posedge clk)
121
     read_reg <= read;
122
 
123
   // Advance the address after a read = first/next word fallthrough   
124
   assign raddr_reg_adv = (cnt > 2) & read_reg;
125
 
126
   always @(posedge clk)
127
     if (reset)
128
       raddr <= 0;
129
     else if (clear)
130
       raddr <= waddr;
131
     else if (read | clear_reg )
132
       raddr <= raddr + 1;
133
 
134
   always @ (posedge clk)
135
     if (write & ~full)
136
       fifo[waddr] <=  data_in;
137
 
138
 
139
   always @(posedge clk)
140
     clear_reg <= clear;
141
 
142
   always @ (posedge clk)
143
     if (read | clear_reg)
144
       raddr_reg <= raddr;
145
 
146
   assign  data_out = fifo[raddr_reg];
147
 
148
 
149
   always @(posedge clk)
150
     if (reset)
151
       final_read <= 0;
152
     else if (final_read & read & !write)
153
       final_read <= ~final_read;
154
     else if ((cnt == 1) & read & !write)
155
       final_read <= 1; // Indicate last read data has been output
156
 
157
 
158
   assign empty = ~(|cnt);
159
   assign almost_empty = cnt==1;
160
   assign full  = cnt == DEPTH;
161
   assign almost_full  = &cnt[CNT_WIDTH-2:0];
162
 
163
`else // !`ifdef ETH_FIFO_GENERIC
164
 
165
reg     [CNT_WIDTH-2:0]   read_pointer;
166
reg     [CNT_WIDTH-2:0]   write_pointer;
167
 
168
 
169 6 julius
always @ (posedge clk or posedge reset)
170
begin
171
  if(reset)
172 403 julius
    read_pointer <= 0;
173 6 julius
  else
174
  if(clear)
175 403 julius
    //read_pointer <= { {(CNT_WIDTH-2){1'b0}}, read};
176
    read_pointer <= { {(CNT_WIDTH-2){1'b0}}, 1'b1};
177 6 julius
  else
178
  if(read & ~empty)
179 403 julius
    read_pointer <= read_pointer + 1'b1;
180 6 julius
end
181
 
182
always @ (posedge clk or posedge reset)
183
begin
184
  if(reset)
185 403 julius
    write_pointer <= 0;
186 6 julius
  else
187
  if(clear)
188 403 julius
    write_pointer <= { {(CNT_WIDTH-2){1'b0}}, write};
189 6 julius
  else
190
  if(write & ~full)
191 403 julius
    write_pointer <= write_pointer + 1'b1;
192 6 julius
end
193
 
194
`ifdef ETH_FIFO_XILINX
195
  xilinx_dist_ram_16x32 fifo
196
  ( .data_out(data_out),
197
    .we(write & ~full),
198
    .data_in(data_in),
199
    .read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
200
    .write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
201
    .wclk(clk)
202
  );
203
`else   // !ETH_FIFO_XILINX
204
`ifdef ETH_ALTERA_ALTSYNCRAM
205
  altera_dpram_16x32    altera_dpram_16x32_inst
206 403 julius
  (
207
        .data             (data_in),
208
        .wren             (write & ~full),
209
        .wraddress        (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
210
        .rdaddress        (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
211
        .clock            (clk),
212
        .q                (data_out)
213
  );  //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
214
`endif //  `ifdef ETH_ALTERA_ALTSYNCRAM
215
`endif // !`ifdef ETH_FIFO_XILINX
216 6 julius
 
217
 
218 403 julius
assign empty = ~(|cnt);
219
assign almost_empty = cnt == 1;
220
assign full  = cnt == DEPTH;
221
assign almost_full  = &cnt[CNT_WIDTH-2:0];
222 6 julius
 
223 403 julius
`endif // !`ifdef ETH_FIFO_GENERIC
224
 
225 6 julius
 
226
 
227
endmodule

powered by: WebSVN 2.1.0

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