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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [ethmac/] [eth_fifo.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////////
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.3  2002/04/22 13:45:52  mohor
45
// Generic ram or Xilinx ram can be used in fifo (selectable by setting
46
// XILINX_SPARTAN6_FPGA in eth_defines.v).
47
//
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
`include "eth_defines.v"
60
`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
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
output  [CNT_WIDTH-1:0]   cnt;
83
 
84
`ifndef XILINX_SPARTAN6_FPGA
85
    reg     [DATA_WIDTH-1:0]  fifo  [0:DEPTH-1];
86
    reg     [DATA_WIDTH-1:0]  data_out;
87
`endif
88
 
89
reg     [CNT_WIDTH-1:0]   cnt;
90
reg     [CNT_WIDTH-2:0]   read_pointer;
91
reg     [CNT_WIDTH-2:0]   write_pointer;
92
 
93
 
94
always @ (posedge clk or posedge reset)
95
begin
96
  if(reset)
97
    cnt <=#Tp 0;
98
  else
99
  if(clear)
100
    cnt <=#Tp { {(CNT_WIDTH-1){1'b0}}, read^write};
101
  else
102
  if(read ^ write)
103
    if(read)
104
      cnt <=#Tp cnt - 1'b1;
105
    else
106
      cnt <=#Tp cnt + 1'b1;
107
end
108
 
109
always @ (posedge clk or posedge reset)
110
begin
111
  if(reset)
112
    read_pointer <=#Tp 0;
113
  else
114
  if(clear)
115
    read_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, read};
116
  else
117
  if(read & ~empty)
118
    read_pointer <=#Tp read_pointer + 1'b1;
119
end
120
 
121
always @ (posedge clk or posedge reset)
122
begin
123
  if(reset)
124
    write_pointer <=#Tp 0;
125
  else
126
  if(clear)
127
    write_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, write};
128
  else
129
  if(write & ~full)
130
    write_pointer <=#Tp write_pointer + 1'b1;
131
end
132
 
133
assign empty = ~(|cnt);
134
assign almost_empty = cnt == 1;
135
assign full  = cnt == DEPTH;
136
assign almost_full  = &cnt[CNT_WIDTH-2:0];
137
 
138
 
139
 
140
`ifdef XILINX_SPARTAN6_FPGA
141
  xilinx_dist_ram_16x32 fifo
142
  ( .data_out(data_out),
143
    .we(write & ~full),
144
    .data_in(data_in),
145
    .read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
146
    .write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
147
    .wclk(clk)
148
  );
149
`else
150
  always @ (posedge clk)
151
  begin
152
    if(write & clear)
153
      fifo[0] <=#Tp data_in;
154
    else
155
   if(write & ~full)
156
      fifo[write_pointer] <=#Tp data_in;
157
  end
158
 
159
 
160
  always @ (posedge clk)
161
  begin
162
    if(clear)
163
      data_out <=#Tp fifo[0];
164
    else
165
      data_out <=#Tp fifo[read_pointer];
166
  end
167
`endif
168
 
169
 
170
endmodule

powered by: WebSVN 2.1.0

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