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

Subversion Repositories spacewire

[/] [spacewire/] [tags/] [arelease/] [rtl/] [eth_fifo.v] - Blame information for rev 27

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 btltz
//////////////////////////////////////////////////////////////////////
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
// Revision 1.5  2005/04/13 20:32           btltz
45
// expand depth for use. change to asychronous read. output comment. delete all delay
46
// use Xilinx block dpRAM template style. not use clear.
47
//
48
// Revision 1.4  2005/02/21 12:48:07  igorm
49
// Warning fixes.
50
//
51
// Revision 1.3  2002/04/22 13:45:52  mohor
52
// Generic ram or Xilinx ram can be used in fifo (selectable by setting
53
// ETH_FIFO_XILINX in eth_defines.v).
54
//
55
// Revision 1.2  2002/03/25 13:33:04  mohor
56
// When clear and read/write are active at the same time, cnt and pointers are
57
// set to 1.
58
//
59
// Revision 1.1  2002/02/05 16:44:39  mohor
60
// Both rx and tx part are finished. Tested with wb_clk_i between 10 and 200
61
// MHz. Statuses, overrun, control frame transmission and reception still  need
62
// to be fixed.
63
//
64
//
65
 
66
 
67
//`include "timescale.v"
68
`define XIL_BRAM            //Use Xilinx block RAM
69
//`define XIL_DISRAM     //Use Xilinx distributed RAM
70
`define reset   1     //WISHBONE style reset
71
 
72
module eth_fifo (data_in, data_out, clk, reset, write, read, almost_full, full, almost_empty, empty, cnt);
73
 
74
parameter DATA_WIDTH    = 32;
75
parameter DEPTH         = 511;
76
parameter CNT_WIDTH     = (DEPTH <= 7) ?  3 :
77
                          ((DEPTH <= 15) ? 4 :
78
                                                                         ((DEPTH <= 31) ? 5 :
79
                                                                          ((DEPTH <= 63) ? 6 :
80
                                                                           ((DEPTH <= 127) ? 7 :
81
                                                                                 ((DEPTH <= 255) ? 8 :
82
                                                                                  ((DEPTH <= 511) ? 9 :
83
                                                                                   ((DEPTH <= 1023) ? 10 :
84
                                                                                         ((DEPTH <= 2047) ? 11 :
85
                                                                                          ((DEPTH <= 4095) ? 12 : 'bx   // Add more ?
86
                                                                                           )))))))));
87
 
88
//parameter Tp            = 1;
89
 
90
input                     clk;
91
input                     reset;
92
input                     write;
93
input                     read;
94
// input                     clear;
95
input   [DATA_WIDTH-1:0]  data_in;
96
 
97
output  [DATA_WIDTH-1:0]  data_out;
98
output                    almost_full;
99
output                    full;
100
output                    almost_empty;
101
output                    empty;
102
output  [CNT_WIDTH-1:0]   cnt;
103
 
104
`ifdef ETH_FIFO_XILINX
105
`else
106
  `ifdef ETH_ALTERA_ALTSYNCRAM
107
  `else
108
    reg     [DATA_WIDTH-1:0]  dpRam  [0:DEPTH-1];
109
   // reg     [DATA_WIDTH-1:0]  data_out;
110
  `endif
111
`endif
112
 
113
reg     [CNT_WIDTH-1:0]   cnt;
114
reg     [CNT_WIDTH-1:0]   read_pointer;
115
reg     [CNT_WIDTH-1:0]   write_pointer;
116
 
117
 
118
always @ (posedge clk or posedge reset)
119
begin
120
  if(reset)
121
    cnt <= 0;
122
  else
123
  if(read ^ write)
124
    if(read)
125
      cnt <= cnt - 1'b1;
126
    else
127
      cnt <= cnt + 1'b1;
128
end
129
 
130
always @ (posedge clk or posedge reset)
131
begin
132
  if(reset)
133
    read_pointer <= 0;
134
  else
135
  if(read & ~empty)
136
    read_pointer <= read_pointer + 1'b1;
137
end
138
 
139
always @ (posedge clk or posedge reset)
140
begin
141
  if(reset)
142
    write_pointer <= 0;
143
  else
144
  if(write & ~full)
145
    write_pointer <= write_pointer + 1'b1;
146
end
147
 
148
// UNregistered outputs. assert while clk after low->high + gate latency
149
assign empty = ~(|cnt);
150
assign almost_empty = cnt == 1;                //pulse output
151
assign full  = cnt == DEPTH;
152
assign almost_full  = &cnt[CNT_WIDTH-2:0]; //pulse output
153
 
154
 
155
 
156
`ifdef ETH_FIFO_XILINX
157
  xilinx_dist_ram_16x32 fifo
158
  ( .data_out(data_out),
159
    .we(write & ~full),
160
    .data_in(data_in),
161
    .read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
162
    .write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
163
    .wclk(clk)
164
  );
165
`else   // !ETH_FIFO_XILINX
166
`ifdef ETH_ALTERA_ALTSYNCRAM
167
  altera_dpram_16x32    altera_dpram_16x32_inst
168
  (
169
        .data             (data_in),
170
        .wren              (write & ~full),
171
        .wraddress        (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
172
        .rdaddress        (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
173
        .clock            (clk),
174
        .q                (data_out)
175
  );  //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
176
`else   // !ETH_ALTERA_ALTSYNCRAM
177
 
178
`ifdef XIL_BRAM
179
reg [CNT_WIDTH-1:0]  rp1;
180
 always @ (posedge clk) begin
181
  if(write & ~full)
182
      dpRam[write_pointer] <= data_in;
183
  rp1 <= read_pointer;
184
  end
185
 
186
assign   data_out = dpRam[rp1];   // if use block RAM, 1 clock data output latency 
187
`else
188
  always @ (posedge clk) begin
189
  if(write & ~full)
190
      dpRam[write_pointer] <= data_in;
191
  end
192
  assign   data_out = dpRam[read_pointer];
193
`endif
194
 
195
`endif  // !ETH_ALTERA_ALTSYNCRAM
196
`endif  // !ETH_FIFO_XILINX
197
 
198
 
199
endmodule
200
 
201
`undef reset
202
`undef XIL_BRAM

powered by: WebSVN 2.1.0

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