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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [opencores.org/] [wishbone/] [ip/] [wb_uart16550/] [rtl/] [verilog/] [rfifo] - Blame information for rev 131

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 131 jt_eaton
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  uart_rfifo.v (Modified from uart_fifo.v)                    ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the "UART 16550 compatible" project    ////
7
////  http://www.opencores.org/cores/uart16550/                   ////
8
////                                                              ////
9
////  Documentation related to this project:                      ////
10
////  - http://www.opencores.org/cores/uart16550/                 ////
11
////                                                              ////
12
////  Projects compatibility:                                     ////
13
////  - WISHBONE                                                  ////
14
////  RS232 Protocol                                              ////
15
////  16550D uart (mostly supported)                              ////
16
////                                                              ////
17
////  Overview (main Features):                                   ////
18
////  UART core receiver FIFO                                     ////
19
////                                                              ////
20
////  To Do:                                                      ////
21
////  Nothing.                                                    ////
22
////                                                              ////
23
////  Author(s):                                                  ////
24
////      - gorban@opencores.org                                  ////
25
////      - Jacob Gorban                                          ////
26
////      - Igor Mohor (igorm@opencores.org)                      ////
27
////                                                              ////
28
////  Created:        2001/05/12                                  ////
29
////  Last Updated:   2002/07/22                                  ////
30
////                  (See log for the revision history)          ////
31
////                                                              ////
32
////                                                              ////
33
//////////////////////////////////////////////////////////////////////
34
////                                                              ////
35
//// Copyright (C) 2000, 2001 Authors                             ////
36
////                                                              ////
37
//// This source file may be used and distributed without         ////
38
//// restriction provided that this copyright statement is not    ////
39
//// removed from the file and that any derivative work contains  ////
40
//// the original copyright notice and the associated disclaimer. ////
41
////                                                              ////
42
//// This source file is free software; you can redistribute it   ////
43
//// and/or modify it under the terms of the GNU Lesser General   ////
44
//// Public License as published by the Free Software Foundation; ////
45
//// either version 2.1 of the License, or (at your option) any   ////
46
//// later version.                                               ////
47
////                                                              ////
48
//// This source is distributed in the hope that it will be       ////
49
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
50
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
51
//// PURPOSE.  See the GNU Lesser General Public License for more ////
52
//// details.                                                     ////
53
////                                                              ////
54
//// You should have received a copy of the GNU Lesser General    ////
55
//// Public License along with this source; if not, download it   ////
56
//// from http://www.opencores.org/lgpl.shtml                     ////
57
////                                                              ////
58
//////////////////////////////////////////////////////////////////////
59
//
60
// CVS Revision History
61
//
62
// $Log: not supported by cvs2svn $
63
// Revision 1.3  2003/06/11 16:37:47  gorban
64
// This fixes errors in some cases when data is being read and put to the FIFO at the same time. Patch is submitted by Scott Furman. Update is very recommended.
65
//
66
// Revision 1.2  2002/07/29 21:16:18  gorban
67
// The uart_defines.v file is included again in sources.
68
//
69
// Revision 1.1  2002/07/22 23:02:23  gorban
70
// Bug Fixes:
71
//  * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
72
//   Problem reported by Kenny.Tung.
73
//  * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
74
//
75
// Improvements:
76
//  * Made FIFO's as general inferrable memory where possible.
77
//  So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
78
//  This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
79
//
80
//
81
// Revision 1.16  2001/12/20 13:25:46  mohor
82
// rx push changed to be only one cycle wide.
83
//
84
// Revision 1.15  2001/12/18 09:01:07  mohor
85
// Bug that was entered in the last update fixed (rx state machine).
86
//
87
// Revision 1.14  2001/12/17 14:46:48  mohor
88
// overrun signal was moved to separate block because many sequential lsr
89
// reads were preventing data from being written to rx fifo.
90
// underrun signal was not used and was removed from the project.
91
//
92
// Revision 1.13  2001/11/26 21:38:54  gorban
93
// Lots of fixes:
94
// Break condition wasn't handled correctly at all.
95
// LSR bits could lose their values.
96
// LSR value after reset was wrong.
97
// Timing of THRE interrupt signal corrected.
98
// LSR bit 0 timing corrected.
99
//
100
// Revision 1.12  2001/11/08 14:54:23  mohor
101
// Comments in Slovene language deleted, few small fixes for better work of
102
// old tools. IRQs need to be fix.
103
//
104
// Revision 1.11  2001/11/07 17:51:52  gorban
105
// Heavily rewritten interrupt and LSR subsystems.
106
// Many bugs hopefully squashed.
107
//
108
// Revision 1.10  2001/10/20 09:58:40  gorban
109
// Small synopsis fixes
110
//
111
// Revision 1.9  2001/08/24 21:01:12  mohor
112
// Things connected to parity changed.
113
// Clock devider changed.
114
//
115
// Revision 1.8  2001/08/24 08:48:10  mohor
116
// FIFO was not cleared after the data was read bug fixed.
117
//
118
// Revision 1.7  2001/08/23 16:05:05  mohor
119
// Stop bit bug fixed.
120
// Parity bug fixed.
121
// WISHBONE read cycle bug fixed,
122
// OE indicator (Overrun Error) bug fixed.
123
// PE indicator (Parity Error) bug fixed.
124
// Register read bug fixed.
125
//
126
// Revision 1.3  2001/05/31 20:08:01  gorban
127
// FIFO changes and other corrections.
128
//
129
// Revision 1.3  2001/05/27 17:37:48  gorban
130
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
131
//
132
// Revision 1.2  2001/05/17 18:34:18  gorban
133
// First 'stable' release. Should be sythesizable now. Also added new header.
134
//
135
// Revision 1.0  2001-05-17 21:27:12+02  jacob
136
// Initial revision
137
//
138
//
139
 
140
 
141
 
142
module `VARIANT`RFIFO  (clk,
143
        wb_rst_i, data_in, data_out,
144
// Control signals
145
        push, // push strobe, active high
146
        pop,   // pop strobe, active high
147
// status signals
148
        overrun,
149
        count,
150
        error_bit,
151
        fifo_reset,
152
        reset_status
153
        );
154
 
155
 
156
// FIFO parameters
157
parameter fifo_width = `UART_FIFO_WIDTH;
158
parameter fifo_depth = `UART_FIFO_DEPTH;
159
parameter fifo_pointer_w = `UART_FIFO_POINTER_W;
160
parameter fifo_counter_w = `UART_FIFO_COUNTER_W;
161
 
162
input                           clk;
163
input                           wb_rst_i;
164
input                           push;
165
input                           pop;
166
input   [fifo_width-1:0]        data_in;
167
input                           fifo_reset;
168
input       reset_status;
169
 
170
output  [fifo_width-1:0]        data_out;
171
output                          overrun;
172
output  [fifo_counter_w-1:0]    count;
173
output                          error_bit;
174
 
175
wire    [fifo_width-1:0]        data_out;
176
wire [7:0] data8_out;
177
// flags FIFO
178
reg     [2:0]   fifo[fifo_depth-1:0];
179
 
180
// FIFO pointers
181
reg     [fifo_pointer_w-1:0]    top;
182
reg     [fifo_pointer_w-1:0]    bottom;
183
 
184
reg     [fifo_counter_w-1:0]    count;
185
reg                             overrun;
186
 
187
wire [fifo_pointer_w-1:0] top_plus_1 = top + 4'h1;
188
 
189
 
190
 
191
`VARIANT`RAMINFR
192
  #( .addr_width  ( fifo_pointer_w ),
193
     .data_width  ( 8              ),
194
     .depth       ( fifo_depth     )
195
     ) rfifo (
196
             .clk(clk),
197
             .we(push),
198
             .a(top),
199
             .dpra(bottom),
200
             .di(data_in[fifo_width-1:fifo_width-8]),
201
             .dpo(data8_out)
202
                );
203
 
204
always @(posedge clk ) // synchronous FIFO
205
begin
206
        if (wb_rst_i)
207
        begin
208
                top             <=  0;
209
                bottom          <=  0;
210
                count           <=  0;
211
                fifo[0] <=  0;
212
                fifo[1] <=  0;
213
                fifo[2] <=  0;
214
                fifo[3] <=  0;
215
                fifo[4] <=  0;
216
                fifo[5] <=  0;
217
                fifo[6] <=  0;
218
                fifo[7] <=  0;
219
                fifo[8] <=  0;
220
                fifo[9] <=  0;
221
                fifo[10] <=  0;
222
                fifo[11] <=  0;
223
                fifo[12] <=  0;
224
                fifo[13] <=  0;
225
                fifo[14] <=  0;
226
                fifo[15] <=  0;
227
        end
228
        else
229
        if (fifo_reset) begin
230
                top             <=  0;
231
                bottom          <=  0;
232
                count           <=  0;
233
                fifo[0] <=  0;
234
                fifo[1] <=  0;
235
                fifo[2] <=  0;
236
                fifo[3] <=  0;
237
                fifo[4] <=  0;
238
                fifo[5] <=  0;
239
                fifo[6] <=  0;
240
                fifo[7] <=  0;
241
                fifo[8] <=  0;
242
                fifo[9] <=  0;
243
                fifo[10] <=  0;
244
                fifo[11] <=  0;
245
                fifo[12] <=  0;
246
                fifo[13] <=  0;
247
                fifo[14] <=  0;
248
                fifo[15] <=  0;
249
        end
250
  else
251
        begin
252
                case ({push, pop})
253
                2'b10 : if (count
254
                        begin
255
                                top       <=  top_plus_1;
256
                                fifo[top] <=  data_in[2:0];
257
                                count     <=  count + 5'd1;
258
                        end
259
                2'b01 : if(count>0)
260
                        begin
261
        fifo[bottom] <=  0;
262
                                bottom   <=  bottom + 4'd1;
263
                                count    <=  count - 5'd1;
264
                        end
265
                2'b11 : begin
266
                                bottom   <=  bottom + 4'd1;
267
                                top       <=  top_plus_1;
268
                                fifo[top] <=  data_in[2:0];
269
                        end
270
    default: ;
271
                endcase
272
        end
273
end   // always
274
 
275
always @(posedge clk ) // synchronous FIFO
276
begin
277
  if (wb_rst_i)
278
    overrun   <=  1'b0;
279
  else
280
  if(fifo_reset | reset_status)
281
    overrun   <=  1'b0;
282
  else
283
  if(push & ~pop & (count==fifo_depth))
284
    overrun   <=  1'b1;
285
end   // always
286
 
287
 
288
// please note though that data_out is only valid one clock after pop signal
289
assign data_out = {data8_out,fifo[bottom]};
290
 
291
// Additional logic for detection of error conditions (parity and framing) inside the FIFO
292
// for the Line Status Register bit 7
293
 
294
wire    [2:0]   word0 = fifo[0];
295
wire    [2:0]   word1 = fifo[1];
296
wire    [2:0]   word2 = fifo[2];
297
wire    [2:0]   word3 = fifo[3];
298
wire    [2:0]   word4 = fifo[4];
299
wire    [2:0]   word5 = fifo[5];
300
wire    [2:0]   word6 = fifo[6];
301
wire    [2:0]   word7 = fifo[7];
302
 
303
wire    [2:0]   word8 = fifo[8];
304
wire    [2:0]   word9 = fifo[9];
305
wire    [2:0]   word10 = fifo[10];
306
wire    [2:0]   word11 = fifo[11];
307
wire    [2:0]   word12 = fifo[12];
308
wire    [2:0]   word13 = fifo[13];
309
wire    [2:0]   word14 = fifo[14];
310
wire    [2:0]   word15 = fifo[15];
311
 
312
// a 1 is returned if any of the error bits in the fifo is 1
313
assign  error_bit = |(word0[2:0]  | word1[2:0]  | word2[2:0]  | word3[2:0]  |
314
                              word4[2:0]  | word5[2:0]  | word6[2:0]  | word7[2:0]  |
315
                              word8[2:0]  | word9[2:0]  | word10[2:0] | word11[2:0] |
316
                              word12[2:0] | word13[2:0] | word14[2:0] | word15[2:0] );
317
 
318
endmodule

powered by: WebSVN 2.1.0

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