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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orp/] [orp_soc/] [rtl/] [verilog/] [uart16550.old/] [uart_fifo.v] - Blame information for rev 746

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

Line No. Rev Author Line
1 746 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  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
////  Known problems (limits):                                    ////
21
////  Note that the same FIFO is used for both transmission  and  ////
22
////  reception but the error bit generation is ignored in tx.    ////
23
////                                                              ////
24
////  To Do:                                                      ////
25
////  Nothing.                                                    ////
26
////                                                              ////
27
////  Author(s):                                                  ////
28
////      - gorban@opencores.org                                  ////
29
////      - Jacob Gorban                                          ////
30
////      - Igor Mohor (igorm@opencores.org)                      ////
31
////                                                              ////
32
////  Created:        2001/05/12                                  ////
33
////  Last Updated:   2001/05/17                                  ////
34
////                  (See log for the revision history)          ////
35
////                                                              ////
36
////                                                              ////
37
//////////////////////////////////////////////////////////////////////
38
////                                                              ////
39
//// Copyright (C) 2000, 2001 Authors                             ////
40
////                                                              ////
41
//// This source file may be used and distributed without         ////
42
//// restriction provided that this copyright statement is not    ////
43
//// removed from the file and that any derivative work contains  ////
44
//// the original copyright notice and the associated disclaimer. ////
45
////                                                              ////
46
//// This source file is free software; you can redistribute it   ////
47
//// and/or modify it under the terms of the GNU Lesser General   ////
48
//// Public License as published by the Free Software Foundation; ////
49
//// either version 2.1 of the License, or (at your option) any   ////
50
//// later version.                                               ////
51
////                                                              ////
52
//// This source is distributed in the hope that it will be       ////
53
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
54
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
55
//// PURPOSE.  See the GNU Lesser General Public License for more ////
56
//// details.                                                     ////
57
////                                                              ////
58
//// You should have received a copy of the GNU Lesser General    ////
59
//// Public License along with this source; if not, download it   ////
60
//// from http://www.opencores.org/lgpl.shtml                     ////
61
////                                                              ////
62
//////////////////////////////////////////////////////////////////////
63
//
64
// CVS Revision History
65
//
66
// $Log: not supported by cvs2svn $
67
// Revision 1.17  2002/01/13 20:13:07  gorban
68
// Removed confusing comment
69
//
70
// Revision 1.16  2001/12/20 13:25:46  mohor
71
// rx push changed to be only one cycle wide.
72
//
73
// Revision 1.15  2001/12/18 09:01:07  mohor
74
// Bug that was entered in the last update fixed (rx state machine).
75
//
76
// Revision 1.14  2001/12/17 14:46:48  mohor
77
// overrun signal was moved to separate block because many sequential lsr
78
// reads were preventing data from being written to rx fifo.
79
// underrun signal was not used and was removed from the project.
80
//
81
// Revision 1.13  2001/11/26 21:38:54  gorban
82
// Lots of fixes:
83
// Break condition wasn't handled correctly at all.
84
// LSR bits could lose their values.
85
// LSR value after reset was wrong.
86
// Timing of THRE interrupt signal corrected.
87
// LSR bit 0 timing corrected.
88
//
89
// Revision 1.12  2001/11/08 14:54:23  mohor
90
// Comments in Slovene language deleted, few small fixes for better work of
91
// old tools. IRQs need to be fix.
92
//
93
// Revision 1.11  2001/11/07 17:51:52  gorban
94
// Heavily rewritten interrupt and LSR subsystems.
95
// Many bugs hopefully squashed.
96
//
97
// Revision 1.10  2001/10/20 09:58:40  gorban
98
// Small synopsis fixes
99
//
100
// Revision 1.9  2001/08/24 21:01:12  mohor
101
// Things connected to parity changed.
102
// Clock devider changed.
103
//
104
// Revision 1.8  2001/08/24 08:48:10  mohor
105
// FIFO was not cleared after the data was read bug fixed.
106
//
107
// Revision 1.7  2001/08/23 16:05:05  mohor
108
// Stop bit bug fixed.
109
// Parity bug fixed.
110
// WISHBONE read cycle bug fixed,
111
// OE indicator (Overrun Error) bug fixed.
112
// PE indicator (Parity Error) bug fixed.
113
// Register read bug fixed.
114
//
115
// Revision 1.3  2001/05/31 20:08:01  gorban
116
// FIFO changes and other corrections.
117
//
118
// Revision 1.3  2001/05/27 17:37:48  gorban
119
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
120
//
121
// Revision 1.2  2001/05/17 18:34:18  gorban
122
// First 'stable' release. Should be sythesizable now. Also added new header.
123
//
124
// Revision 1.0  2001-05-17 21:27:12+02  jacob
125
// Initial revision
126
//
127
//
128
 
129
// synopsys translate_off
130
`include "timescale.v"
131
// synopsys translate_on
132
 
133
`include "uart_defines.v"
134
 
135
module uart_fifo (clk,
136
        wb_rst_i, data_in, data_out,
137
// Control signals
138
        push, // push strobe, active high
139
        pop,   // pop strobe, active high
140
// status signals
141
        overrun,
142
        count,
143
        error_bit,
144
        fifo_reset,
145
        reset_status
146
        );
147
 
148
 
149
// FIFO parameters
150
parameter fifo_width = `UART_FIFO_WIDTH;
151
parameter fifo_depth = `UART_FIFO_DEPTH;
152
parameter fifo_pointer_w = `UART_FIFO_POINTER_W;
153
parameter fifo_counter_w = `UART_FIFO_COUNTER_W;
154
 
155
input                           clk;
156
input                           wb_rst_i;
157
input                           push;
158
input                           pop;
159
input   [fifo_width-1:0] data_in;
160
input                           fifo_reset;
161
input       reset_status;
162
 
163
output  [fifo_width-1:0] data_out;
164
output                          overrun;
165
output  [fifo_counter_w-1:0]     count;
166
output                          error_bit;
167
 
168
wire    [fifo_width-1:0] data_out;
169
 
170
// FIFO itself
171
reg     [fifo_width-1:0] fifo[fifo_depth-1:0];
172
 
173
// FIFO pointers
174
reg     [fifo_pointer_w-1:0]     top;
175
reg     [fifo_pointer_w-1:0]     bottom;
176
 
177
reg     [fifo_counter_w-1:0]     count;
178
reg                             overrun;
179
 
180
wire [fifo_pointer_w-1:0] top_plus_1 = top + 1'b1;
181
 
182
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
183
begin
184
        if (wb_rst_i)
185
        begin
186
                top             <= #1 0;
187
                bottom          <= #1 1'b0;
188
                count           <= #1 0;
189
                fifo[0]          <= #1 0;
190
                fifo[1]         <= #1 0;
191
                fifo[2]         <= #1 0;
192
                fifo[3]         <= #1 0;
193
                fifo[4]         <= #1 0;
194
                fifo[5]         <= #1 0;
195
                fifo[6]         <= #1 0;
196
                fifo[7]         <= #1 0;
197
                fifo[8]         <= #1 0;
198
                fifo[9]         <= #1 0;
199
                fifo[10]        <= #1 0;
200
                fifo[11]        <= #1 0;
201
                fifo[12]        <= #1 0;
202
                fifo[13]        <= #1 0;
203
                fifo[14]        <= #1 0;
204
                fifo[15]        <= #1 0;
205
        end
206
        else
207
        if (fifo_reset) begin
208
                top             <= #1 0;
209
                bottom          <= #1 1'b0;
210
                count           <= #1 0;
211
        end
212
  else
213
        begin
214
                case ({push, pop})
215
                2'b10 : if (count<fifo_depth)  // overrun condition
216
                        begin
217
                                top       <= #1 top_plus_1;
218
                                fifo[top] <= #1 data_in;
219
                                count     <= #1 count + 1'b1;
220
                        end
221
                2'b01 : if(count>0)
222
                        begin
223
        fifo[bottom] <= #1 0;
224
                                bottom   <= #1 bottom + 1'b1;
225
                                count    <= #1 count - 1'b1;
226
                        end
227
                2'b11 : begin
228
        fifo[bottom] <= #1 0;
229
                                bottom   <= #1 bottom + 1'b1;
230
                                top       <= #1 top_plus_1;
231
                                fifo[top] <= #1 data_in;
232
                        end
233
    default: ;
234
                endcase
235
        end
236
end   // always
237
 
238
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
239
begin
240
  if (wb_rst_i)
241
    overrun   <= #1 1'b0;
242
  else
243
  if(fifo_reset | reset_status)
244
    overrun   <= #1 1'b0;
245
  else
246
  if(push & (count==fifo_depth))
247
    overrun   <= #1 1'b1;
248
end   // always
249
 
250
 
251
assign data_out = fifo[bottom];
252
 
253
// Additional logic for detection of error conditions (parity and framing) inside the FIFO
254
// for the Line Status Register bit 7
255
 
256
wire    [fifo_width-1:0] word0 = fifo[0];
257
wire    [fifo_width-1:0] word1 = fifo[1];
258
wire    [fifo_width-1:0] word2 = fifo[2];
259
wire    [fifo_width-1:0] word3 = fifo[3];
260
wire    [fifo_width-1:0] word4 = fifo[4];
261
wire    [fifo_width-1:0] word5 = fifo[5];
262
wire    [fifo_width-1:0] word6 = fifo[6];
263
wire    [fifo_width-1:0] word7 = fifo[7];
264
 
265
wire    [fifo_width-1:0] word8 = fifo[8];
266
wire    [fifo_width-1:0] word9 = fifo[9];
267
wire    [fifo_width-1:0] word10 = fifo[10];
268
wire    [fifo_width-1:0] word11 = fifo[11];
269
wire    [fifo_width-1:0] word12 = fifo[12];
270
wire    [fifo_width-1:0] word13 = fifo[13];
271
wire    [fifo_width-1:0] word14 = fifo[14];
272
wire    [fifo_width-1:0] word15 = fifo[15];
273
 
274
// a 1 is returned if any of the error bits in the fifo is 1
275
assign  error_bit = |(word0[2:0]  | word1[2:0]  | word2[2:0]  | word3[2:0]  |
276
                              word4[2:0]  | word5[2:0]  | word6[2:0]  | word7[2:0]  |
277
                              word8[2:0]  | word9[2:0]  | word10[2:0] | word11[2:0] |
278
                              word12[2:0] | word13[2:0] | word14[2:0] | word15[2:0] );
279
 
280
endmodule

powered by: WebSVN 2.1.0

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