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

Subversion Repositories brsfmnce

[/] [brsfmnce/] [trunk/] [RTL/] [BRSFmnCE.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
`timescale 1ns / 1ps
2
////////////////////////////////////////////////////////////////////////////////
3
// Company:         M. A. Morris & Associates 
4
// Engineer:        Michael A. Morris 
5
// 
6
// Create Date:     11:48:14 07/27/2008 
7
// Design Name:     Parameterizable Synchronous Block RAM FIFO
8
// Module Name:     BRSFmnCE.v
9
// Project Name:    C:\XProjects\VerilogComponentsLib\FIFO - Block RAM
10
// Target Devices:  SRAM FPGA: XC3S1400AN-5FFG676I, XC3S700AN-4FGG484I
11
// Tool versions:   Xilinx ISE10.1i SP3 
12
//
13
// Description:
14
//
15
//  This module implements a synchronous FIFO using Block RAM resources such as 
16
//  thos found in SRAM-based FPGAs. This module has been used in several
17
//  projects based on Xilinx Spartan 3AN FPGAs. It can be adapted to other deve-
18
//  lopment systems, but only Xilinx ISE has been used to date.
19
//
20
//  All components used in this module are inferred, including the Block RAM.
21
//  This allows the depth and width to be set by parameters. Furthermore, the
22
//  state of the memory, the write pointer, and FIFO flags can be initialized.
23
//  This allows FIFO to be preconditioned with a copyright notice, configura-
24
//  tion data, etc.
25
//
26
// Dependencies: None
27
//
28
// Revision:
29
// 
30
//  1.00    08G27   MAM     File Created
31
//
32
//  1.10    13H12   MAM     Prepared for release on Opencores.com. Converted to
33
//                          Verilog-2001 format.
34
//
35 3 MichaelA
// Additional Comments:
36
//
37
//  Note:   Initialization of the FIFO memory contents only occurs once. If
38
//          Reset is reasserted, current implementation cannot reinitialize
39
//          memory contents unless Reset also causes reload of the configuration
40 2 MichaelA
//          image of the SRAM-based FPGA.
41
//
42
////////////////////////////////////////////////////////////////////////////////
43
 
44 3 MichaelA
module BRSFmnCE #(
45 2 MichaelA
    parameter pAddr        = 10,            // Number of Address Bits
46
    parameter pWidth       = 8,             // Number of Data Bits
47
    parameter pRAMInitSize = 128,           // Amount Data to Init into FIFO RAM
48
    parameter pFRAM_Init   = "RAMINIT.mif"  // RAM Memory Initialization File
49
)(
50
    input   Rst,                        // System Reset - Synchronous
51 3 MichaelA
    input   Clk,                        // System Clock
52 2 MichaelA
 
53
    input   Clr,                        // FIFO Clear
54 3 MichaelA
 
55 2 MichaelA
    input   WE,                         // FIFO Write Enable
56
    input   [(pWidth - 1):0] DI,        // FIFO Input Data
57 3 MichaelA
 
58 2 MichaelA
    input   RE,                         // FIFO Read Enable
59
    output  reg [(pWidth - 1):0] DO,    // FIFO Output Data
60
    output  reg ACK,                    // FIFO Read Acknowledge
61 3 MichaelA
 
62 2 MichaelA
    output  reg FF,                     // FIFO Full Flag
63
    output  reg AF,                     // FIFO Almost Full Flag (Full - 1)
64
    output  HF,                         // FIFO Half Full Flag
65
    output  reg AE,                     // FIFO Almost Empty Flag (Count == 1)
66
    output  reg EF,                     // FIFO Empty Flag (Count == 0)
67 3 MichaelA
 
68 2 MichaelA
    output  [pAddr:0] Cnt               // FIFO Word Count
69
);
70
 
71
////////////////////////////////////////////////////////////////////////////////
72
//
73
//  Module Signal Declarations
74
//
75
 
76
    reg     [(pWidth - 1):0] FRAM [((2**pAddr) - 1):0];
77
 
78
    reg     [(pAddr - 1):0] WPtr, RPtr, WCnt;
79
 
80
    wire    Wr, Rd, CE;
81
 
82
////////////////////////////////////////////////////////////////////////////////
83
//
84
//  Implementation
85
//
86
 
87
//
88
//  Combinatorial Control Signals
89
//
90
 
91
assign Wr = WE & ~FF;
92
assign Rd = RE & ~EF;
93
assign CE = Wr ^ Rd;
94
 
95
//
96
//  Read Acknowledge
97
//
98
 
99
always @(posedge Clk)
100
begin
101
    if(Rst | Clr)
102
        ACK <= #1 0;
103
    else
104
        ACK <= #1 Rd;
105
end
106
 
107
//
108
//  Write Address Counter
109
//
110
 
111
always @(posedge Clk)
112
begin
113
    if(Rst)
114
        WPtr <= #1 pRAMInitSize;
115
    else if(Clr)
116
        WPtr <= #1 0;
117
    else if(Wr)
118
        WPtr <= #1 WPtr + 1;
119
end
120
 
121
//
122
//  Read Address Counter
123
//
124
 
125
always @(posedge Clk)
126
begin
127
    if(Rst | Clr)
128
        RPtr <= #1 0;
129
    else if(Rd)
130
        RPtr <= #1 RPtr + 1;
131
end
132
 
133
//
134
//   Word Counter
135
//
136
 
137
always @(posedge Clk)
138
begin
139
    if(Rst)
140
        WCnt <= #1 pRAMInitSize;
141
    else if(Clr)
142
        WCnt <= #1 0;
143
    else if(Wr & ~Rd)
144
        WCnt <= #1 WCnt + 1;
145
    else if(Rd & ~Wr)
146
        WCnt <= #1 WCnt - 1;
147
end
148
 
149
//
150
//  External Word Count
151
//
152
 
153
assign Cnt = {FF, WCnt};
154
 
155
//
156
//  Empty Flag Register
157
//
158
 
159
always @(posedge Clk)
160
begin
161
    if(Rst)
162
        EF <= #1 (pRAMInitSize == 0);
163
    else if(Clr)
164
        EF <= #1 1;
165
    else if(CE)
166
        EF <= #1 ((WE) ? 0 : (~|Cnt[pAddr:1]));
167
end
168
 
169
//
170
//  Almost Empty Flag Register
171
//
172
 
173
always @(posedge Clk)
174
begin
175
    if(Rst)
176
        AE <= #1 (pRAMInitSize == 1);
177
    else if(Clr)
178
        AE <= #1 0;
179
    else if(CE)
180
        AE <= #1 (Rd & (~|Cnt[pAddr:2]) & Cnt[1] & ~Cnt[0]) | (Wr & EF);
181
end
182
 
183
//
184
//  Full Flag Register
185
//
186
 
187
always @(posedge Clk)
188
begin
189
    if(Rst)
190
        FF <= #1 (pRAMInitSize == (1 << pAddr));
191
    else if(Clr)
192
        FF <= #1 0;
193
    else if(CE)
194
        FF <= #1 ((RE) ? 0 : (&WCnt));
195
end
196
 
197
//
198
//  Almost Full Flag Register
199
//
200
 
201
always @(posedge Clk)
202
begin
203
    if(Rst)
204
        AF <= #1 (pRAMInitSize == ((1 << pAddr) - 1));
205
    else if(Clr)
206
        AF <= #1 0;
207
    else if(CE)
208
        AF <= #1 (Wr & (~Cnt[pAddr] & (&Cnt[(pAddr-1):1]) & ~Cnt[0]))
209
                 | (Rd & FF);
210
end
211
 
212
//
213
//  Half-Full Flag
214
//
215
 
216
assign HF = ~EF & (Cnt[pAddr] | Cnt[(pAddr - 1)]);
217
 
218
////////////////////////////////////////////////////////////////////////////////
219
//
220
//  FIFO Block RAM
221
//
222
 
223
initial
224 3 MichaelA
    $readmemh(pFRAM_Init, FRAM, 0, ((1 << pAddr) - 1));
225 2 MichaelA
 
226
always @(posedge Clk)
227
begin
228
    if(Wr)
229
        FRAM[WPtr] <= #1 DI;
230
end
231
 
232
always @(posedge Clk)
233
begin
234
    DO <= #1 FRAM[RPtr];
235
end
236
 
237
endmodule

powered by: WebSVN 2.1.0

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