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 439

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 439 julius
////  http://www.opencores.org/project,ethmac                     ////
7 6 julius
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
10 439 julius
////      - Julius Baxter (julius@opencores.org)                  ////
11 6 julius
////                                                              ////
12
////  All additional information is avaliable in the Readme.txt   ////
13
////  file.                                                       ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2001 Authors                                   ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
 
42 409 julius
`include "ethmac_defines.v"
43 6 julius
`include "timescale.v"
44
 
45 439 julius
module eth_fifo (data_in, data_out, clk, reset, write, read, clear,
46
                 almost_full, full, almost_empty, empty, cnt);
47 6 julius
 
48
parameter DATA_WIDTH    = 32;
49
parameter DEPTH         = 8;
50 439 julius
parameter CNT_WIDTH     = 3;
51 6 julius
 
52
input                     clk;
53
input                     reset;
54
input                     write;
55
input                     read;
56
input                     clear;
57
input   [DATA_WIDTH-1:0]  data_in;
58
 
59
output  [DATA_WIDTH-1:0]  data_out;
60
output                    almost_full;
61
output                    full;
62
output                    almost_empty;
63
output                    empty;
64
output  [CNT_WIDTH-1:0]   cnt;
65
 
66
 
67
 
68 403 julius
reg [CNT_WIDTH-1:0]        cnt;
69
   reg                    final_read;
70
 
71 6 julius
always @ (posedge clk or posedge reset)
72
begin
73
  if(reset)
74 403 julius
    cnt <= 0;
75 6 julius
  else
76
  if(clear)
77 403 julius
    cnt <= { {(CNT_WIDTH-1){1'b0}}, read^write};
78 6 julius
  else
79
  if(read ^ write)
80
    if(read)
81 439 julius
      cnt <= cnt - 1;
82 6 julius
    else
83 439 julius
      cnt <= cnt + 1;
84 6 julius
end
85
 
86 403 julius
 
87
`ifdef ETH_FIFO_GENERIC
88
 
89
   reg     [DATA_WIDTH-1:0]  fifo  [0:DEPTH-1] /*synthesis syn_ramstyle = "no_rw_check"*/ ;
90
 
91
 
92 439 julius
   // This should make the synthesis tool infer a RAM
93
   reg [CNT_WIDTH-1:0] waddr, raddr, raddr_reg;
94
   reg                 clear_reg; // Register the clear pulse
95
 
96
   reg                 fallthrough_read;
97
   reg [CNT_WIDTH-1:0] fallthrough_read_addr;
98
 
99 403 julius
 
100
   always @(posedge clk)
101
     if (reset)
102 439 julius
       fallthrough_read <= 0;
103
     else
104
       fallthrough_read <= empty & write;
105
 
106
   always @(posedge clk)
107
     if (empty & write)
108
       fallthrough_read_addr <= waddr;
109
 
110
   always @(posedge clk)
111
     if (reset)
112 403 julius
       waddr <= 0;
113
     else if (write)
114
       waddr <= waddr + 1;
115
 
116
   reg                 read_reg;
117
   always @(posedge clk)
118
     read_reg <= read;
119
 
120
   always @(posedge clk)
121
     if (reset)
122
       raddr <= 0;
123
     else if (clear)
124
       raddr <= waddr;
125 439 julius
     else if (read | clear_reg)
126 403 julius
       raddr <= raddr + 1;
127
 
128
   always @ (posedge clk)
129
     if (write & ~full)
130
       fifo[waddr] <=  data_in;
131
 
132
 
133
   always @(posedge clk)
134
     clear_reg <= clear;
135
 
136
   always @ (posedge clk)
137
     if (read | clear_reg)
138
       raddr_reg <= raddr;
139 439 julius
     else if (fallthrough_read) // To pulse RE for fall-through on Xilinx
140
       raddr_reg <= fallthrough_read_addr;
141 403 julius
 
142
   assign  data_out = fifo[raddr_reg];
143
 
144
 
145
   always @(posedge clk)
146
     if (reset)
147
       final_read <= 0;
148
     else if (final_read & read & !write)
149
       final_read <= ~final_read;
150
     else if ((cnt == 1) & read & !write)
151
       final_read <= 1; // Indicate last read data has been output
152
 
153
   assign empty = ~(|cnt);
154
   assign almost_empty = cnt==1;
155 439 julius
   assign full  = {{32-CNT_WIDTH{1'b0}},cnt} == (DEPTH-1);
156
   assign almost_full  = &cnt[CNT_WIDTH-1:0];
157 403 julius
 
158
`else // !`ifdef ETH_FIFO_GENERIC
159
 
160 439 julius
reg     [CNT_WIDTH-1:0]   read_pointer;
161
reg     [CNT_WIDTH-1:0]   write_pointer;
162 403 julius
 
163
 
164 6 julius
always @ (posedge clk or posedge reset)
165
begin
166
  if(reset)
167 403 julius
    read_pointer <= 0;
168 6 julius
  else
169
  if(clear)
170 439 julius
    //read_pointer <= { {(CNT_WIDTH-1){1'b0}}, read};
171
    read_pointer <= { {(CNT_WIDTH-1){1'b0}}, 1'b1};
172 6 julius
  else
173
  if(read & ~empty)
174 403 julius
    read_pointer <= read_pointer + 1'b1;
175 6 julius
end
176
 
177
always @ (posedge clk or posedge reset)
178
begin
179
  if(reset)
180 403 julius
    write_pointer <= 0;
181 6 julius
  else
182
  if(clear)
183 439 julius
    write_pointer <= { {(CNT_WIDTH-1){1'b0}}, write};
184 6 julius
  else
185
  if(write & ~full)
186 403 julius
    write_pointer <= write_pointer + 1'b1;
187 6 julius
end
188
 
189
`ifdef ETH_FIFO_XILINX
190
  xilinx_dist_ram_16x32 fifo
191
  ( .data_out(data_out),
192
    .we(write & ~full),
193
    .data_in(data_in),
194
    .read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
195
    .write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
196
    .wclk(clk)
197
  );
198
`else   // !ETH_FIFO_XILINX
199
`ifdef ETH_ALTERA_ALTSYNCRAM
200
  altera_dpram_16x32    altera_dpram_16x32_inst
201 403 julius
  (
202
        .data             (data_in),
203
        .wren             (write & ~full),
204
        .wraddress        (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
205
        .rdaddress        (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
206
        .clock            (clk),
207
        .q                (data_out)
208
  );  //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
209
`endif //  `ifdef ETH_ALTERA_ALTSYNCRAM
210
`endif // !`ifdef ETH_FIFO_XILINX
211 6 julius
 
212
 
213 403 julius
assign empty = ~(|cnt);
214
assign almost_empty = cnt == 1;
215 439 julius
assign full  = cnt == (DEPTH-1);
216
assign almost_full  = &cnt[CNT_WIDTH-1:0];
217 6 julius
 
218 403 julius
`endif // !`ifdef ETH_FIFO_GENERIC
219
 
220 6 julius
 
221
 
222
endmodule

powered by: WebSVN 2.1.0

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