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

Subversion Repositories uart16550

[/] [uart16550/] [trunk/] [rtl/] [verilog/] [uart_rfifo.v] - Blame information for rev 84

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

Line No. Rev Author Line
1 79 gorban
//////////////////////////////////////////////////////////////////////
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 84 gorban
// Revision 1.1  2002/07/22 23:02:23  gorban
64
// Bug Fixes:
65
//  * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
66
//   Problem reported by Kenny.Tung.
67
//  * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
68
//
69
// Improvements:
70
//  * Made FIFO's as general inferrable memory where possible.
71
//  So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
72
//  This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
73
//
74
//  * Added optional baudrate output (baud_o).
75
//  This is identical to BAUDOUT* signal on 16550 chip.
76
//  It outputs 16xbit_clock_rate - the divided clock.
77
//  It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
78
//
79 79 gorban
// Revision 1.16  2001/12/20 13:25:46  mohor
80
// rx push changed to be only one cycle wide.
81
//
82
// Revision 1.15  2001/12/18 09:01:07  mohor
83
// Bug that was entered in the last update fixed (rx state machine).
84
//
85
// Revision 1.14  2001/12/17 14:46:48  mohor
86
// overrun signal was moved to separate block because many sequential lsr
87
// reads were preventing data from being written to rx fifo.
88
// underrun signal was not used and was removed from the project.
89
//
90
// Revision 1.13  2001/11/26 21:38:54  gorban
91
// Lots of fixes:
92
// Break condition wasn't handled correctly at all.
93
// LSR bits could lose their values.
94
// LSR value after reset was wrong.
95
// Timing of THRE interrupt signal corrected.
96
// LSR bit 0 timing corrected.
97
//
98
// Revision 1.12  2001/11/08 14:54:23  mohor
99
// Comments in Slovene language deleted, few small fixes for better work of
100
// old tools. IRQs need to be fix.
101
//
102
// Revision 1.11  2001/11/07 17:51:52  gorban
103
// Heavily rewritten interrupt and LSR subsystems.
104
// Many bugs hopefully squashed.
105
//
106
// Revision 1.10  2001/10/20 09:58:40  gorban
107
// Small synopsis fixes
108
//
109
// Revision 1.9  2001/08/24 21:01:12  mohor
110
// Things connected to parity changed.
111
// Clock devider changed.
112
//
113
// Revision 1.8  2001/08/24 08:48:10  mohor
114
// FIFO was not cleared after the data was read bug fixed.
115
//
116
// Revision 1.7  2001/08/23 16:05:05  mohor
117
// Stop bit bug fixed.
118
// Parity bug fixed.
119
// WISHBONE read cycle bug fixed,
120
// OE indicator (Overrun Error) bug fixed.
121
// PE indicator (Parity Error) bug fixed.
122
// Register read bug fixed.
123
//
124
// Revision 1.3  2001/05/31 20:08:01  gorban
125
// FIFO changes and other corrections.
126
//
127
// Revision 1.3  2001/05/27 17:37:48  gorban
128
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
129
//
130
// Revision 1.2  2001/05/17 18:34:18  gorban
131
// First 'stable' release. Should be sythesizable now. Also added new header.
132
//
133
// Revision 1.0  2001-05-17 21:27:12+02  jacob
134
// Initial revision
135
//
136
//
137
 
138
// synopsys translate_off
139
`include "timescale.v"
140
// synopsys translate_on
141
 
142 84 gorban
`include "uart_defines.v"
143 79 gorban
 
144
module uart_rfifo (clk,
145
        wb_rst_i, data_in, data_out,
146
// Control signals
147
        push, // push strobe, active high
148
        pop,   // pop strobe, active high
149
// status signals
150
        overrun,
151
        count,
152
        error_bit,
153
        fifo_reset,
154
        reset_status
155
        );
156
 
157
 
158
// FIFO parameters
159
parameter fifo_width = `UART_FIFO_WIDTH;
160
parameter fifo_depth = `UART_FIFO_DEPTH;
161
parameter fifo_pointer_w = `UART_FIFO_POINTER_W;
162
parameter fifo_counter_w = `UART_FIFO_COUNTER_W;
163
 
164
input                           clk;
165
input                           wb_rst_i;
166
input                           push;
167
input                           pop;
168
input   [fifo_width-1:0] data_in;
169
input                           fifo_reset;
170
input       reset_status;
171
 
172
output  [fifo_width-1:0] data_out;
173
output                          overrun;
174
output  [fifo_counter_w-1:0]     count;
175
output                          error_bit;
176
 
177
wire    [fifo_width-1:0] data_out;
178
wire [7:0] data8_out;
179
// flags FIFO
180
reg     [2:0]    fifo[fifo_depth-1:0];
181
 
182
// FIFO pointers
183
reg     [fifo_pointer_w-1:0]     top;
184
reg     [fifo_pointer_w-1:0]     bottom;
185
 
186
reg     [fifo_counter_w-1:0]     count;
187
reg                             overrun;
188
 
189
wire [fifo_pointer_w-1:0] top_plus_1 = top + 1'b1;
190
 
191
raminfr #(fifo_pointer_w,8,fifo_depth) rfifo
192
        (.clk(clk),
193
                        .we(push),
194
                        .a(top),
195
                        .dpra(bottom),
196
                        .di(data_in[fifo_width-1:fifo_width-8]),
197
                        .dpo(data8_out)
198
                );
199
 
200
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
201
begin
202
        if (wb_rst_i)
203
        begin
204
                top             <= #1 0;
205
                bottom          <= #1 1'b0;
206
                count           <= #1 0;
207
        end
208
        else
209
        if (fifo_reset) begin
210
                top             <= #1 0;
211
                bottom          <= #1 1'b0;
212
                count           <= #1 0;
213
        end
214
  else
215
        begin
216
                case ({push, pop})
217
                2'b10 : if (count<fifo_depth)  // overrun condition
218
                        begin
219
                                top       <= #1 top_plus_1;
220
                                fifo[top] <= #1 data_in[2:0];
221
                                count     <= #1 count + 1'b1;
222
                        end
223
                2'b01 : if(count>0)
224
                        begin
225
        fifo[bottom] <= #1 0;
226
                                bottom   <= #1 bottom + 1'b1;
227
                                count    <= #1 count - 1'b1;
228
                        end
229
                2'b11 : begin
230
        fifo[bottom] <= #1 0;
231
                                bottom   <= #1 bottom + 1'b1;
232
                                top       <= #1 top_plus_1;
233
                                fifo[top] <= #1 data_in[2:0];
234
                        end
235
    default: ;
236
                endcase
237
        end
238
end   // always
239
 
240
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
241
begin
242
  if (wb_rst_i)
243
    overrun   <= #1 1'b0;
244
  else
245
  if(fifo_reset | reset_status)
246
    overrun   <= #1 1'b0;
247
  else
248
  if(push & (count==fifo_depth))
249
    overrun   <= #1 1'b1;
250
end   // always
251
 
252
 
253
// please note though that data_out is only valid one clock after pop signal
254
assign data_out = {data8_out,fifo[bottom]};
255
 
256
// Additional logic for detection of error conditions (parity and framing) inside the FIFO
257
// for the Line Status Register bit 7
258
 
259
wire    [2:0]    word0 = fifo[0];
260
wire    [2:0]    word1 = fifo[1];
261
wire    [2:0]    word2 = fifo[2];
262
wire    [2:0]    word3 = fifo[3];
263
wire    [2:0]    word4 = fifo[4];
264
wire    [2:0]    word5 = fifo[5];
265
wire    [2:0]    word6 = fifo[6];
266
wire    [2:0]    word7 = fifo[7];
267
 
268
wire    [2:0]    word8 = fifo[8];
269
wire    [2:0]    word9 = fifo[9];
270
wire    [2:0]    word10 = fifo[10];
271
wire    [2:0]    word11 = fifo[11];
272
wire    [2:0]    word12 = fifo[12];
273
wire    [2:0]    word13 = fifo[13];
274
wire    [2:0]    word14 = fifo[14];
275
wire    [2:0]    word15 = fifo[15];
276
 
277
// a 1 is returned if any of the error bits in the fifo is 1
278
assign  error_bit = |(word0[2:0]  | word1[2:0]  | word2[2:0]  | word3[2:0]  |
279
                              word4[2:0]  | word5[2:0]  | word6[2:0]  | word7[2:0]  |
280
                              word8[2:0]  | word9[2:0]  | word10[2:0] | word11[2:0] |
281
                              word12[2:0] | word13[2:0] | word14[2:0] | word15[2:0] );
282
 
283
endmodule

powered by: WebSVN 2.1.0

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