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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [const_encoder/] [rtl/] [fifo.v] - Blame information for rev 27

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

Line No. Rev Author Line
1 13 dannori
/* *****************************************************************
2
 *
3 15 dannori
 *  This file is part of the
4
 *
5
 *   Tone Order and Constellation Encoder Core.
6
 *
7
 *
8
 * Description:
9
 *
10
 *  fifo is a synchronouys FIFO without write through. The read
11
 *  and write operation happens with the positive edge of the clk
12
 *  signal. If the FIFO is empty and performing a read/write operation
13
 *  with at the same clock cycle only the write operation will succeed.
14
 *  The read operation will not return a valid value.
15
 *
16
 *
17
 *********************************************************************
18 13 dannori
 *  Copyright (C) 2007 Guenter Dannoritzer
19
 *
20
 *   This source is free software; you can redistribute it
21
 *   and/or modify it under the terms of the
22
 *             GNU General Public License
23
 *   as published by the Free Software Foundation;
24
 *   either version 3 of the License,
25
 *   or (at your option) any later version.
26
 *
27
 *   This source is distributed in the hope
28
 *   that it will be useful, but WITHOUT ANY WARRANTY;
29
 *   without even the implied warranty of MERCHANTABILITY
30
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
 *   GNU General Public License for more details.
32
 *
33
 *   You should have received a copy of the
34 15 dannori
 *   GNU General Public License along with this source.
35 13 dannori
 *   If not, see <http://www.gnu.org/licenses/>.
36
 *
37
 * *****************************************************************/
38 12 dannori
module fifo(
39
          clk,
40
          reset,
41
          empty_o,
42
          full_o,
43
          one_available_o,
44
          two_available_o,
45
          we_i,
46
          data_i,
47
          re_i,
48
          data_o);
49
 
50
parameter DWIDTH = 8;
51
parameter AWIDTH = 4;
52
 
53
input                 clk;
54
input                 reset;
55
output                empty_o;
56
output                full_o;
57
output                one_available_o;
58
output                two_available_o;
59
input                 we_i;
60
input   [DWIDTH-1:0]  data_i;
61
input                 re_i;
62
output  [DWIDTH-1:0]  data_o;
63
 
64
 
65
 
66
 
67
//
68
// local reg/wires
69
// 
70
reg [AWIDTH-1:0]  read_ptr;
71
reg [AWIDTH-1:0]  write_ptr;
72
reg [AWIDTH:0]    fill_ctr;
73
 
74
wire              dp_we_i;
75
wire              dp_re_i;
76
 
77
//
78
// instantiate the dual port ram
79
//
80
generic_dpram #(.aw(AWIDTH),
81
                .dw(DWIDTH)
82
               )
83
              dpram ( .rclk(clk),
84
                      .rrst(reset),
85
                      .rce(ce),
86
                      .oe(dp_re_i),
87
                      .raddr(read_ptr),
88
                      .do(data_o),
89
 
90
                      .wclk(clk),
91
                      .wrst(reset),
92
                      .wce(ce),
93
                      .we(dp_we_i),
94
                      .waddr(write_ptr),
95
                      .di(data_i));
96
 
97
 
98
//
99
// control logic
100
// 
101
assign ce = 1'b1;
102
 
103
assign one_available_o = (fill_ctr > 1'b0) ? 1'b1 : 1'b0;
104
assign two_available_o = (fill_ctr > 1'b1) ? 1'b1 : 1'b0;
105
assign empty_o = |fill_ctr ? 1'b0 : 1'b1;
106
assign full_o = fill_ctr[AWIDTH] ? 1'b1 : 1'b0;
107
 
108
// make sure a write only happens to dp_ram when not full
109
assign dp_we_i = ~full_o ? we_i : 1'b0;
110
// make sure a read only happens to the dp_ram when not empty
111
assign dp_re_i = ~empty_o ? re_i : 1'b0;
112
 
113
//
114
// fill counter
115
// 
116
always @(posedge clk or posedge reset) begin
117
  if(reset) begin
118
    fill_ctr <= 0;
119
  end
120
  else begin
121 13 dannori
 
122 15 dannori
    if(dp_we_i & ~ dp_re_i) begin
123 12 dannori
      fill_ctr <= fill_ctr + 1;
124
    end
125 15 dannori
    else if(dp_re_i & ~ dp_we_i) begin
126 12 dannori
      fill_ctr <= fill_ctr - 1;
127
    end
128
  end
129
end
130
 
131
// 
132
// read pointer
133
// 
134
always @(posedge clk or posedge reset) begin
135
  if(reset) begin
136
    read_ptr <= 0;
137
  end
138
  else begin
139
    if(dp_re_i) begin
140
      read_ptr <= read_ptr + 1;
141
    end
142
  end
143
end
144
 
145
// 
146
// write pointer
147
//
148
always @(posedge clk or posedge reset) begin
149
  if(reset) begin
150
    write_ptr <= 0;
151
  end
152
  else begin
153
    if(dp_we_i) begin
154
      write_ptr <= write_ptr + 1;
155
    end
156
  end
157
end
158
 
159
 
160
endmodule

powered by: WebSVN 2.1.0

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