source: XOpenSparcT1/trunk/OC-UART/uart_tfifo.v @ 6

Revision 6, 8.7 KB checked in by pntsvt00, 13 years ago (diff)

versione iniziale opensparc

Line 
1//////////////////////////////////////////////////////////////////////
2////                                                              ////
3////  uart_tfifo.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 transmitter 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.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// 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`include "uart_defines.v"
143
144module uart_tfifo (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        fifo_reset,
153        reset_status
154        );
155
156
157// FIFO parameters
158parameter fifo_width = `UART_FIFO_WIDTH;
159parameter fifo_depth = `UART_FIFO_DEPTH;
160parameter fifo_pointer_w = `UART_FIFO_POINTER_W;
161parameter fifo_counter_w = `UART_FIFO_COUNTER_W;
162
163input                           clk;
164input                           wb_rst_i;
165input                           push;
166input                           pop;
167input   [fifo_width-1:0]        data_in;
168input                           fifo_reset;
169input       reset_status;
170
171output  [fifo_width-1:0]        data_out;
172output                          overrun;
173output  [fifo_counter_w-1:0]    count;
174
175wire    [fifo_width-1:0]        data_out;
176
177// FIFO pointers
178reg     [fifo_pointer_w-1:0]    top;
179reg     [fifo_pointer_w-1:0]    bottom;
180
181reg     [fifo_counter_w-1:0]    count;
182reg                             overrun;
183wire [fifo_pointer_w-1:0] top_plus_1 = top + 1'b1;
184
185raminfr #(fifo_pointer_w,fifo_width,fifo_depth) tfifo 
186        (.clk(clk), 
187                        .we(push), 
188                        .a(top), 
189                        .dpra(bottom), 
190                        .di(data_in), 
191                        .dpo(data_out)
192                ); 
193
194
195always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
196begin
197        if (wb_rst_i)
198        begin
199                top             <= #1 0;
200                bottom          <= #1 1'b0;
201                count           <= #1 0;
202        end
203        else
204        if (fifo_reset) begin
205                top             <= #1 0;
206                bottom          <= #1 1'b0;
207                count           <= #1 0;
208        end
209  else
210        begin
211                case ({push, pop})
212                2'b10 : if (count<fifo_depth)  // overrun condition
213                        begin
214                                top       <= #1 top_plus_1;
215                                count     <= #1 count + 1'b1;
216                        end
217                2'b01 : if(count>0)
218                        begin
219                                bottom   <= #1 bottom + 1'b1;
220                                count    <= #1 count - 1'b1;
221                        end
222                2'b11 : begin
223                                bottom   <= #1 bottom + 1'b1;
224                                top       <= #1 top_plus_1;
225                        end
226    default: ;
227                endcase
228        end
229end   // always
230
231always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
232begin
233  if (wb_rst_i)
234    overrun   <= #1 1'b0;
235  else
236  if(fifo_reset | reset_status) 
237    overrun   <= #1 1'b0;
238  else
239  if(push & (count==fifo_depth))
240    overrun   <= #1 1'b1;
241end   // always
242
243endmodule
Note: See TracBrowser for help on using the repository browser.