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

Subversion Repositories ethmac10g

[/] [ethmac10g/] [trunk/] [rtl/] [verilog/] [rx_engine/] [SwitchSyncFIFO.v] - Blame information for rev 71

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

Line No. Rev Author Line
1 71 fisher5090
//
2
// Module SwitchSyncFIFO
3
//
4
// the differences between this FIFO and the general one are listed below
5
//    1. because there is no any write and read acknowledgements, the user should take advantage of the status flags to generate the write and read requests.
6
//    2. after the full flag has been asserted, the word can not be written into the FIFO even if the reacd request is being asserted at the same cycle.
7
//
8
// Created:
9
//          by - Xinchun Liu
10
//          at - 2006-09-25
11
// History: 
12
//                      2007-1-31 9:50          change iReset to nReset  Revised  By Wang Dawei wangdawei@ncic.ac.cn
13
//
14
`resetall
15
`timescale 1ns/10ps
16
 
17
module SwitchSyncFIFO (
18
        nReset,
19
        iClk,
20
        iWEn,
21
        ivDataIn,
22
        iREn,
23
        ovDataOut,
24
        qEmpty,
25
        qFull,
26
        qvCount
27
);
28
 
29
// Default address and data width
30
parameter   pDepthWidth = 5 ;
31
parameter   pWordWidth = 16 ;
32
 
33
input   nReset ;
34
input   iClk ;
35
input iWEn ;
36
input [pWordWidth-1:0]   ivDataIn ;
37
input   iREn ;
38
output   [pWordWidth-1:0]        ovDataOut ;
39
output   qEmpty ;
40
output  qFull ;
41
output   [pDepthWidth:0] qvCount ;
42
 
43
wire    nReset ;
44
wire    iClk ;
45
wire    iWEn ;
46
wire  [pWordWidth-1:0]   ivDataIn ;
47
wire    iREn ;
48
wire  [pWordWidth-1:0]   ovDataOut_i ;
49
wire    qEmpty ;
50
wire    qFull ;
51
wire  [pDepthWidth:0]    qvCount ;
52
 
53
wire  MemWEn;
54
wire  MemREn;
55
wire  [pDepthWidth-1:0] vWriteAddr ;
56
wire  [pDepthWidth-1:0] vReadAddr ;
57
 
58
DualPortRAM #( pDepthWidth, pWordWidth )   Fifo_Storage                         // Generic synchronous two-port RAM interface
59
   (
60
      .clock   ( iClk ) ,
61
      .MemWEn   ( MemWEn ) ,
62
      .qvWAddr   ( vWriteAddr ) ,
63
      .vDataIn          ( ivDataIn ) ,
64
      .qvRAddr          ( vReadAddr ) ,
65
      .vDataOut         ( ovDataOut_i   )
66
   );
67
 
68
 
69
reg  [pWordWidth-1:0]    ovDataOut ;
70
 
71
always @ ( posedge iClk )
72
   if ( MemREn )
73
       ovDataOut <= ovDataOut_i ;
74
   else
75
       ovDataOut <= 0;
76
 
77
FifoControl #( pDepthWidth ) Fifo_Ctrl
78
   (
79
      .Reset   ( nReset ) ,
80
      .clock   ( iClk ) ,
81
      .iWEn   ( iWEn ) ,
82
      .MemWEn   ( MemWEn ) ,
83
      .MemREn   (MemREn),
84
      .qvWAddr   ( vWriteAddr ) ,
85
      .iREn             ( iREn ) ,
86
      .qvRAddr   ( vReadAddr ) ,
87
      .qEmpty  ( qEmpty ) ,
88
      .qFull   ( qFull ) ,
89
      .qvCount ( qvCount )
90
   ) ;
91
 
92
endmodule
93
 
94
module FifoControl(
95
      Reset ,
96
      clock ,
97
      iWEn ,
98
      MemWEn ,
99
      MemREn,
100
      qvWAddr ,
101
      iREn ,
102
      qvRAddr ,
103
      qEmpty ,
104
      qFull ,
105
      qvCount
106
   ) ;
107
 
108
parameter   pDepthWidth = 5;
109
 
110
input  Reset ;
111
input  clock ;
112
input  iWEn ;
113
output  MemWEn ;
114
output  MemREn ;
115
output  [pDepthWidth-1:0] qvWAddr ;
116
input  iREn ;
117
output  [pDepthWidth-1:0] qvRAddr ;
118
output  qEmpty ;
119
output  qFull ;
120
output  [pDepthWidth:0] qvCount ;
121
 
122
wire  Reset ;
123
wire  clock ;
124
wire  iWEn ;
125
wire  MemWEn ;
126
reg  [pDepthWidth-1:0] qvWAddr ;
127
wire  iREn ;
128
reg  [pDepthWidth-1:0] qvRAddr ;
129
reg  qEmpty ;
130
reg  qFull ;
131
reg  [pDepthWidth:0] qvCount ;
132
 
133
wire  MemREn ;
134
 
135
// write allow wire - writes are allowed when fifo is not full
136
// read  allow wire - reads  are allowed when fifo is not empty
137
assign MemWEn = iWEn && ( ~qFull ) ;
138
assign MemREn = iREn && ( ~qEmpty ) ;
139
 
140
// write address module
141
always @ ( posedge clock or negedge Reset) begin
142
   if( ~Reset ) begin
143
                qvWAddr <= 0 ;
144
        end
145
   else  begin
146
                if( MemWEn )   qvWAddr <= qvWAddr + 1'b1 ;
147
        end
148
end
149
 
150
// read address module
151
always @ ( posedge clock or negedge Reset) begin
152
   if( ~Reset ) begin
153
                qvRAddr <= 0 ;
154
        end
155
   else  begin
156
                if( MemREn )   qvRAddr <= qvRAddr + 1'b1 ;
157
        end
158
end
159
 
160
// flags module
161
always @ ( posedge clock or negedge Reset) begin
162
   if( ~Reset ) begin
163
                qFull  <= 0 ;
164
                qEmpty   <= 1 ;
165
                qvCount   <= 0 ;
166
        end
167
   else  begin
168
                if( MemWEn )   begin
169
                        if( qEmpty )   qEmpty <= 0 ;
170
                        if ( ~MemREn ) begin
171
                           qvCount <= qvCount + 1'b1 ;
172
                           if( qvCount[pDepthWidth-1:0] == { pDepthWidth{1'b1} } )
173
                              qFull <= 1 ;
174
                        end
175
                end
176
                else  begin
177
                   if( MemREn ) begin
178
                      qvCount <= qvCount - 1'b1 ;
179
                                if( qvCount == 1'b1 )  qEmpty <= 1;
180
                                if( qFull ) qFull <= 0;
181
                        end
182
                end
183
        end
184
end
185
 
186
endmodule
187
 
188
//=============================================================================================================
189
 
190
module DualPortRAM
191
   (
192
      clock ,
193
      MemWEn ,
194
      qvWAddr ,
195
      vDataIn ,
196
      qvRAddr ,
197
      vDataOut
198
        );
199
 
200
// Default address and data width
201
parameter   pDepthWidth = 5 ;
202
parameter   pWordWidth = 16 ;
203
 
204
// Generic synchronous two-port RAM interface
205
input clock ;           // clock
206
input MemWEn ;  // write enable input
207
input [pDepthWidth-1:0] qvWAddr ;        // write address bus
208
input [pWordWidth-1:0]  vDataIn ;        // input data bus
209
input [pDepthWidth-1:0] qvRAddr ;        // read address bus
210
output   [pWordWidth-1:0]  vDataOut ;    // output data bus
211
 
212
 
213
// Generic two-port synchronous RAM model
214
 
215
// Generic RAM's registers and wires
216
reg   [pWordWidth-1:0]  mem[(1<<pDepthWidth)-1:0] /*synthesis syn_ramstyle="no_rw_check"*/;
217
 
218
always @ ( posedge clock )
219
   if ( MemWEn )
220
                mem[qvWAddr] <= vDataIn ;
221
 
222
assign vDataOut = mem[qvRAddr] ;
223
 
224
endmodule
225
 
226
 
227
///**********************************************************************
228
//                                               FIFO                                           
229
///**********************************************************************

powered by: WebSVN 2.1.0

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