1 |
18 |
unneback |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// raminfr.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 |
|
|
//// Inferrable Distributed RAM for FIFOs ////
|
19 |
|
|
//// ////
|
20 |
|
|
//// Known problems (limits): ////
|
21 |
|
|
//// None . ////
|
22 |
|
|
//// ////
|
23 |
|
|
//// To Do: ////
|
24 |
|
|
//// Nothing so far. ////
|
25 |
|
|
//// ////
|
26 |
|
|
//// Author(s): ////
|
27 |
|
|
//// - gorban@opencores.org ////
|
28 |
|
|
//// - Jacob Gorban ////
|
29 |
|
|
//// ////
|
30 |
|
|
//// Created: 2002/07/22 ////
|
31 |
|
|
//// Last Updated: 2002/07/22 ////
|
32 |
|
|
//// (See log for the revision history) ////
|
33 |
|
|
//// ////
|
34 |
|
|
//// ////
|
35 |
|
|
//////////////////////////////////////////////////////////////////////
|
36 |
|
|
//// ////
|
37 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
38 |
|
|
//// ////
|
39 |
|
|
//// This source file may be used and distributed without ////
|
40 |
|
|
//// restriction provided that this copyright statement is not ////
|
41 |
|
|
//// removed from the file and that any derivative work contains ////
|
42 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
43 |
|
|
//// ////
|
44 |
|
|
//// This source file is free software; you can redistribute it ////
|
45 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
46 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
47 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
48 |
|
|
//// later version. ////
|
49 |
|
|
//// ////
|
50 |
|
|
//// This source is distributed in the hope that it will be ////
|
51 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
52 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
53 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
54 |
|
|
//// details. ////
|
55 |
|
|
//// ////
|
56 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
57 |
|
|
//// Public License along with this source; if not, download it ////
|
58 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
59 |
|
|
//// ////
|
60 |
|
|
//////////////////////////////////////////////////////////////////////
|
61 |
|
|
//
|
62 |
|
|
// CVS Revision History
|
63 |
|
|
//
|
64 |
|
|
// $Log: raminfr.v,v $
|
65 |
|
|
// Revision 1.2 2002/07/29 21:16:18 gorban
|
66 |
|
|
// The uart_defines.v file is included again in sources.
|
67 |
|
|
//
|
68 |
|
|
// Revision 1.1 2002/07/22 23:02:23 gorban
|
69 |
|
|
// Bug Fixes:
|
70 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
71 |
|
|
// Problem reported by Kenny.Tung.
|
72 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
73 |
|
|
//
|
74 |
|
|
// Improvements:
|
75 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
76 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
77 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
78 |
|
|
//
|
79 |
|
|
// * Added optional baudrate output (baud_o).
|
80 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
81 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
82 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
83 |
|
|
//
|
84 |
|
|
|
85 |
|
|
//Following is the Verilog code for a dual-port RAM with asynchronous read.
|
86 |
|
|
`include "uart_defines.v"
|
87 |
|
|
module raminfr
|
88 |
|
|
(clk, we, a, dpra, di, dpo);
|
89 |
|
|
|
90 |
|
|
parameter addr_width = 4;
|
91 |
|
|
parameter data_width = 8;
|
92 |
|
|
parameter depth = 16;
|
93 |
|
|
|
94 |
|
|
input clk;
|
95 |
|
|
input we;
|
96 |
|
|
input [addr_width-1:0] a;
|
97 |
|
|
input [addr_width-1:0] dpra;
|
98 |
|
|
input [data_width-1:0] di;
|
99 |
|
|
//output [data_width-1:0] spo;
|
100 |
|
|
output [data_width-1:0] dpo;
|
101 |
|
|
reg [data_width-1:0] ram [depth-1:0];
|
102 |
|
|
`ifdef SYNC_RAM
|
103 |
|
|
reg [data_width-1:0] dpo;
|
104 |
|
|
`else
|
105 |
|
|
wire [data_width-1:0] dpo;
|
106 |
|
|
`endif
|
107 |
|
|
|
108 |
|
|
wire [data_width-1:0] di;
|
109 |
|
|
wire [addr_width-1:0] a;
|
110 |
|
|
wire [addr_width-1:0] dpra;
|
111 |
|
|
|
112 |
|
|
always @(posedge clk) begin
|
113 |
|
|
if (we)
|
114 |
|
|
ram[a] <= di;
|
115 |
|
|
end
|
116 |
|
|
|
117 |
|
|
`ifdef SYNC_RAM
|
118 |
|
|
always @(negedge clk)
|
119 |
|
|
dpo = ram[dpra];
|
120 |
|
|
`else
|
121 |
|
|
assign dpo = ram[dpra];
|
122 |
|
|
`endif
|
123 |
|
|
|
124 |
|
|
endmodule
|
125 |
|
|
|
126 |
|
|
//////////////////////////////////////////////////////////////////////
|
127 |
|
|
//// ////
|
128 |
|
|
//// uart_sync_flops.v ////
|
129 |
|
|
//// ////
|
130 |
|
|
//// ////
|
131 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
132 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
133 |
|
|
//// ////
|
134 |
|
|
//// Documentation related to this project: ////
|
135 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
136 |
|
|
//// ////
|
137 |
|
|
//// Projects compatibility: ////
|
138 |
|
|
//// - WISHBONE ////
|
139 |
|
|
//// RS232 Protocol ////
|
140 |
|
|
//// 16550D uart (mostly supported) ////
|
141 |
|
|
//// ////
|
142 |
|
|
//// Overview (main Features): ////
|
143 |
|
|
//// UART core receiver logic ////
|
144 |
|
|
//// ////
|
145 |
|
|
//// Known problems (limits): ////
|
146 |
|
|
//// None known ////
|
147 |
|
|
//// ////
|
148 |
|
|
//// To Do: ////
|
149 |
|
|
//// Thourough testing. ////
|
150 |
|
|
//// ////
|
151 |
|
|
//// Author(s): ////
|
152 |
|
|
//// - Andrej Erzen (andreje@flextronics.si) ////
|
153 |
|
|
//// - Tadej Markovic (tadejm@flextronics.si) ////
|
154 |
|
|
//// ////
|
155 |
|
|
//// Created: 2004/05/20 ////
|
156 |
|
|
//// Last Updated: 2004/05/20 ////
|
157 |
|
|
//// (See log for the revision history) ////
|
158 |
|
|
//// ////
|
159 |
|
|
//// ////
|
160 |
|
|
//////////////////////////////////////////////////////////////////////
|
161 |
|
|
//// ////
|
162 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
163 |
|
|
//// ////
|
164 |
|
|
//// This source file may be used and distributed without ////
|
165 |
|
|
//// restriction provided that this copyright statement is not ////
|
166 |
|
|
//// removed from the file and that any derivative work contains ////
|
167 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
168 |
|
|
//// ////
|
169 |
|
|
//// This source file is free software; you can redistribute it ////
|
170 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
171 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
172 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
173 |
|
|
//// later version. ////
|
174 |
|
|
//// ////
|
175 |
|
|
//// This source is distributed in the hope that it will be ////
|
176 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
177 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
178 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
179 |
|
|
//// details. ////
|
180 |
|
|
//// ////
|
181 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
182 |
|
|
//// Public License along with this source; if not, download it ////
|
183 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
184 |
|
|
//// ////
|
185 |
|
|
//////////////////////////////////////////////////////////////////////
|
186 |
|
|
//
|
187 |
|
|
// CVS Revision History
|
188 |
|
|
//
|
189 |
|
|
// $Log: uart_sync_flops.v,v $
|
190 |
|
|
// Revision 1.1 2004/05/21 11:43:25 tadejm
|
191 |
|
|
// Added to synchronize RX input to Wishbone clock.
|
192 |
|
|
//
|
193 |
|
|
//
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
`include "timescale.v"
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
module uart_sync_flops
|
200 |
|
|
(
|
201 |
|
|
// internal signals
|
202 |
|
|
rst_i,
|
203 |
|
|
clk_i,
|
204 |
|
|
stage1_rst_i,
|
205 |
|
|
stage1_clk_en_i,
|
206 |
|
|
async_dat_i,
|
207 |
|
|
sync_dat_o
|
208 |
|
|
);
|
209 |
|
|
|
210 |
|
|
parameter Tp = 1;
|
211 |
|
|
parameter width = 1;
|
212 |
|
|
parameter init_value = 1'b0;
|
213 |
|
|
|
214 |
|
|
input rst_i; // reset input
|
215 |
|
|
input clk_i; // clock input
|
216 |
|
|
input stage1_rst_i; // synchronous reset for stage 1 FF
|
217 |
|
|
input stage1_clk_en_i; // synchronous clock enable for stage 1 FF
|
218 |
|
|
input [width-1:0] async_dat_i; // asynchronous data input
|
219 |
|
|
output [width-1:0] sync_dat_o; // synchronous data output
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
//
|
223 |
|
|
// Interal signal declarations
|
224 |
|
|
//
|
225 |
|
|
|
226 |
|
|
reg [width-1:0] sync_dat_o;
|
227 |
|
|
reg [width-1:0] flop_0;
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
// first stage
|
231 |
|
|
always @ (posedge clk_i or posedge rst_i)
|
232 |
|
|
begin
|
233 |
|
|
if (rst_i)
|
234 |
|
|
flop_0 <= #Tp {width{init_value}};
|
235 |
|
|
else
|
236 |
|
|
flop_0 <= #Tp async_dat_i;
|
237 |
|
|
end
|
238 |
|
|
|
239 |
|
|
// second stage
|
240 |
|
|
always @ (posedge clk_i or posedge rst_i)
|
241 |
|
|
begin
|
242 |
|
|
if (rst_i)
|
243 |
|
|
sync_dat_o <= #Tp {width{init_value}};
|
244 |
|
|
else if (stage1_rst_i)
|
245 |
|
|
sync_dat_o <= #Tp {width{init_value}};
|
246 |
|
|
else if (stage1_clk_en_i)
|
247 |
|
|
sync_dat_o <= #Tp flop_0;
|
248 |
|
|
end
|
249 |
|
|
|
250 |
|
|
endmodule
|
251 |
|
|
//////////////////////////////////////////////////////////////////////
|
252 |
|
|
//// ////
|
253 |
|
|
//// uart_regs.v ////
|
254 |
|
|
//// ////
|
255 |
|
|
//// ////
|
256 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
257 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
258 |
|
|
//// ////
|
259 |
|
|
//// Documentation related to this project: ////
|
260 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
261 |
|
|
//// ////
|
262 |
|
|
//// Projects compatibility: ////
|
263 |
|
|
//// - WISHBONE ////
|
264 |
|
|
//// RS232 Protocol ////
|
265 |
|
|
//// 16550D uart (mostly supported) ////
|
266 |
|
|
//// ////
|
267 |
|
|
//// Overview (main Features): ////
|
268 |
|
|
//// Registers of the uart 16550 core ////
|
269 |
|
|
//// ////
|
270 |
|
|
//// Known problems (limits): ////
|
271 |
|
|
//// Inserts 1 wait state in all WISHBONE transfers ////
|
272 |
|
|
//// ////
|
273 |
|
|
//// To Do: ////
|
274 |
|
|
//// Nothing or verification. ////
|
275 |
|
|
//// ////
|
276 |
|
|
//// Author(s): ////
|
277 |
|
|
//// - gorban@opencores.org ////
|
278 |
|
|
//// - Jacob Gorban ////
|
279 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
280 |
|
|
//// ////
|
281 |
|
|
//// Created: 2001/05/12 ////
|
282 |
|
|
//// Last Updated: (See log for the revision history ////
|
283 |
|
|
//// ////
|
284 |
|
|
//// ////
|
285 |
|
|
//////////////////////////////////////////////////////////////////////
|
286 |
|
|
//// ////
|
287 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
288 |
|
|
//// ////
|
289 |
|
|
//// This source file may be used and distributed without ////
|
290 |
|
|
//// restriction provided that this copyright statement is not ////
|
291 |
|
|
//// removed from the file and that any derivative work contains ////
|
292 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
293 |
|
|
//// ////
|
294 |
|
|
//// This source file is free software; you can redistribute it ////
|
295 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
296 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
297 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
298 |
|
|
//// later version. ////
|
299 |
|
|
//// ////
|
300 |
|
|
//// This source is distributed in the hope that it will be ////
|
301 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
302 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
303 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
304 |
|
|
//// details. ////
|
305 |
|
|
//// ////
|
306 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
307 |
|
|
//// Public License along with this source; if not, download it ////
|
308 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
309 |
|
|
//// ////
|
310 |
|
|
//////////////////////////////////////////////////////////////////////
|
311 |
|
|
//
|
312 |
|
|
// CVS Revision History
|
313 |
|
|
//
|
314 |
|
|
// $Log: uart_regs.v,v $
|
315 |
|
|
// Revision 1.42 2004/11/22 09:21:59 igorm
|
316 |
|
|
// Timeout interrupt should be generated only when there is at least ony
|
317 |
|
|
// character in the fifo.
|
318 |
|
|
//
|
319 |
|
|
// Revision 1.41 2004/05/21 11:44:41 tadejm
|
320 |
|
|
// Added synchronizer flops for RX input.
|
321 |
|
|
//
|
322 |
|
|
// Revision 1.40 2003/06/11 16:37:47 gorban
|
323 |
|
|
// 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.
|
324 |
|
|
//
|
325 |
|
|
// Revision 1.39 2002/07/29 21:16:18 gorban
|
326 |
|
|
// The uart_defines.v file is included again in sources.
|
327 |
|
|
//
|
328 |
|
|
// Revision 1.38 2002/07/22 23:02:23 gorban
|
329 |
|
|
// Bug Fixes:
|
330 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
331 |
|
|
// Problem reported by Kenny.Tung.
|
332 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
333 |
|
|
//
|
334 |
|
|
// Improvements:
|
335 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
336 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
337 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
338 |
|
|
//
|
339 |
|
|
// * Added optional baudrate output (baud_o).
|
340 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
341 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
342 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
343 |
|
|
//
|
344 |
|
|
// Revision 1.37 2001/12/27 13:24:09 mohor
|
345 |
|
|
// lsr[7] was not showing overrun errors.
|
346 |
|
|
//
|
347 |
|
|
// Revision 1.36 2001/12/20 13:25:46 mohor
|
348 |
|
|
// rx push changed to be only one cycle wide.
|
349 |
|
|
//
|
350 |
|
|
// Revision 1.35 2001/12/19 08:03:34 mohor
|
351 |
|
|
// Warnings cleared.
|
352 |
|
|
//
|
353 |
|
|
// Revision 1.34 2001/12/19 07:33:54 mohor
|
354 |
|
|
// Synplicity was having troubles with the comment.
|
355 |
|
|
//
|
356 |
|
|
// Revision 1.33 2001/12/17 10:14:43 mohor
|
357 |
|
|
// Things related to msr register changed. After THRE IRQ occurs, and one
|
358 |
|
|
// character is written to the transmit fifo, the detection of the THRE bit in the
|
359 |
|
|
// LSR is delayed for one character time.
|
360 |
|
|
//
|
361 |
|
|
// Revision 1.32 2001/12/14 13:19:24 mohor
|
362 |
|
|
// MSR register fixed.
|
363 |
|
|
//
|
364 |
|
|
// Revision 1.31 2001/12/14 10:06:58 mohor
|
365 |
|
|
// After reset modem status register MSR should be reset.
|
366 |
|
|
//
|
367 |
|
|
// Revision 1.30 2001/12/13 10:09:13 mohor
|
368 |
|
|
// thre irq should be cleared only when being source of interrupt.
|
369 |
|
|
//
|
370 |
|
|
// Revision 1.29 2001/12/12 09:05:46 mohor
|
371 |
|
|
// LSR status bit 0 was not cleared correctly in case of reseting the FCR (rx fifo).
|
372 |
|
|
//
|
373 |
|
|
// Revision 1.28 2001/12/10 19:52:41 gorban
|
374 |
|
|
// Scratch register added
|
375 |
|
|
//
|
376 |
|
|
// Revision 1.27 2001/12/06 14:51:04 gorban
|
377 |
|
|
// Bug in LSR[0] is fixed.
|
378 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
379 |
|
|
//
|
380 |
|
|
// Revision 1.26 2001/12/03 21:44:29 gorban
|
381 |
|
|
// Updated specification documentation.
|
382 |
|
|
// Added full 32-bit data bus interface, now as default.
|
383 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
384 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
385 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
386 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
387 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
388 |
|
|
//
|
389 |
|
|
// Revision 1.25 2001/11/28 19:36:39 gorban
|
390 |
|
|
// Fixed: timeout and break didn't pay attention to current data format when counting time
|
391 |
|
|
//
|
392 |
|
|
// Revision 1.24 2001/11/26 21:38:54 gorban
|
393 |
|
|
// Lots of fixes:
|
394 |
|
|
// Break condition wasn't handled correctly at all.
|
395 |
|
|
// LSR bits could lose their values.
|
396 |
|
|
// LSR value after reset was wrong.
|
397 |
|
|
// Timing of THRE interrupt signal corrected.
|
398 |
|
|
// LSR bit 0 timing corrected.
|
399 |
|
|
//
|
400 |
|
|
// Revision 1.23 2001/11/12 21:57:29 gorban
|
401 |
|
|
// fixed more typo bugs
|
402 |
|
|
//
|
403 |
|
|
// Revision 1.22 2001/11/12 15:02:28 mohor
|
404 |
|
|
// lsr1r error fixed.
|
405 |
|
|
//
|
406 |
|
|
// Revision 1.21 2001/11/12 14:57:27 mohor
|
407 |
|
|
// ti_int_pnd error fixed.
|
408 |
|
|
//
|
409 |
|
|
// Revision 1.20 2001/11/12 14:50:27 mohor
|
410 |
|
|
// ti_int_d error fixed.
|
411 |
|
|
//
|
412 |
|
|
// Revision 1.19 2001/11/10 12:43:21 gorban
|
413 |
|
|
// Logic Synthesis bugs fixed. Some other minor changes
|
414 |
|
|
//
|
415 |
|
|
// Revision 1.18 2001/11/08 14:54:23 mohor
|
416 |
|
|
// Comments in Slovene language deleted, few small fixes for better work of
|
417 |
|
|
// old tools. IRQs need to be fix.
|
418 |
|
|
//
|
419 |
|
|
// Revision 1.17 2001/11/07 17:51:52 gorban
|
420 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
421 |
|
|
// Many bugs hopefully squashed.
|
422 |
|
|
//
|
423 |
|
|
// Revision 1.16 2001/11/02 09:55:16 mohor
|
424 |
|
|
// no message
|
425 |
|
|
//
|
426 |
|
|
// Revision 1.15 2001/10/31 15:19:22 gorban
|
427 |
|
|
// Fixes to break and timeout conditions
|
428 |
|
|
//
|
429 |
|
|
// Revision 1.14 2001/10/29 17:00:46 gorban
|
430 |
|
|
// fixed parity sending and tx_fifo resets over- and underrun
|
431 |
|
|
//
|
432 |
|
|
// Revision 1.13 2001/10/20 09:58:40 gorban
|
433 |
|
|
// Small synopsis fixes
|
434 |
|
|
//
|
435 |
|
|
// Revision 1.12 2001/10/19 16:21:40 gorban
|
436 |
|
|
// Changes data_out to be synchronous again as it should have been.
|
437 |
|
|
//
|
438 |
|
|
// Revision 1.11 2001/10/18 20:35:45 gorban
|
439 |
|
|
// small fix
|
440 |
|
|
//
|
441 |
|
|
// Revision 1.10 2001/08/24 21:01:12 mohor
|
442 |
|
|
// Things connected to parity changed.
|
443 |
|
|
// Clock devider changed.
|
444 |
|
|
//
|
445 |
|
|
// Revision 1.9 2001/08/23 16:05:05 mohor
|
446 |
|
|
// Stop bit bug fixed.
|
447 |
|
|
// Parity bug fixed.
|
448 |
|
|
// WISHBONE read cycle bug fixed,
|
449 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
450 |
|
|
// PE indicator (Parity Error) bug fixed.
|
451 |
|
|
// Register read bug fixed.
|
452 |
|
|
//
|
453 |
|
|
// Revision 1.10 2001/06/23 11:21:48 gorban
|
454 |
|
|
// DL made 16-bit long. Fixed transmission/reception bugs.
|
455 |
|
|
//
|
456 |
|
|
// Revision 1.9 2001/05/31 20:08:01 gorban
|
457 |
|
|
// FIFO changes and other corrections.
|
458 |
|
|
//
|
459 |
|
|
// Revision 1.8 2001/05/29 20:05:04 gorban
|
460 |
|
|
// Fixed some bugs and synthesis problems.
|
461 |
|
|
//
|
462 |
|
|
// Revision 1.7 2001/05/27 17:37:49 gorban
|
463 |
|
|
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
|
464 |
|
|
//
|
465 |
|
|
// Revision 1.6 2001/05/21 19:12:02 gorban
|
466 |
|
|
// Corrected some Linter messages.
|
467 |
|
|
//
|
468 |
|
|
// Revision 1.5 2001/05/17 18:34:18 gorban
|
469 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
470 |
|
|
//
|
471 |
|
|
// Revision 1.0 2001-05-17 21:27:11+02 jacob
|
472 |
|
|
// Initial revision
|
473 |
|
|
//
|
474 |
|
|
//
|
475 |
|
|
|
476 |
|
|
// synopsys translate_off
|
477 |
|
|
`include "timescale.v"
|
478 |
|
|
// synopsys translate_on
|
479 |
|
|
|
480 |
|
|
`include "uart_defines.v"
|
481 |
|
|
|
482 |
|
|
`define UART_DL1 7:0
|
483 |
|
|
`define UART_DL2 15:8
|
484 |
|
|
|
485 |
|
|
module uart_regs (clk,
|
486 |
|
|
wb_rst_i, wb_addr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_re_i,
|
487 |
|
|
|
488 |
|
|
// additional signals
|
489 |
|
|
modem_inputs,
|
490 |
|
|
stx_pad_o, srx_pad_i,
|
491 |
|
|
|
492 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
493 |
|
|
`else
|
494 |
|
|
// debug interface signals enabled
|
495 |
|
|
ier, iir, fcr, mcr, lcr, msr, lsr, rf_count, tf_count, tstate, rstate,
|
496 |
|
|
`endif
|
497 |
|
|
rts_pad_o, dtr_pad_o, int_o
|
498 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
499 |
|
|
, baud_o
|
500 |
|
|
`endif
|
501 |
|
|
|
502 |
|
|
);
|
503 |
|
|
|
504 |
|
|
input clk;
|
505 |
|
|
input wb_rst_i;
|
506 |
|
|
input [`UART_ADDR_WIDTH-1:0] wb_addr_i;
|
507 |
|
|
input [7:0] wb_dat_i;
|
508 |
|
|
output [7:0] wb_dat_o;
|
509 |
|
|
input wb_we_i;
|
510 |
|
|
input wb_re_i;
|
511 |
|
|
|
512 |
|
|
output stx_pad_o;
|
513 |
|
|
input srx_pad_i;
|
514 |
|
|
|
515 |
|
|
input [3:0] modem_inputs;
|
516 |
|
|
output rts_pad_o;
|
517 |
|
|
output dtr_pad_o;
|
518 |
|
|
output int_o;
|
519 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
520 |
|
|
output baud_o;
|
521 |
|
|
`endif
|
522 |
|
|
|
523 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
524 |
|
|
`else
|
525 |
|
|
// if 32-bit databus and debug interface are enabled
|
526 |
|
|
output [3:0] ier;
|
527 |
|
|
output [3:0] iir;
|
528 |
|
|
output [1:0] fcr; /// bits 7 and 6 of fcr. Other bits are ignored
|
529 |
|
|
output [4:0] mcr;
|
530 |
|
|
output [7:0] lcr;
|
531 |
|
|
output [7:0] msr;
|
532 |
|
|
output [7:0] lsr;
|
533 |
|
|
output [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
534 |
|
|
output [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
535 |
|
|
output [2:0] tstate;
|
536 |
|
|
output [3:0] rstate;
|
537 |
|
|
|
538 |
|
|
`endif
|
539 |
|
|
|
540 |
|
|
wire [3:0] modem_inputs;
|
541 |
|
|
reg enable;
|
542 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
543 |
|
|
assign baud_o = enable; // baud_o is actually the enable signal
|
544 |
|
|
`endif
|
545 |
|
|
|
546 |
|
|
|
547 |
|
|
wire stx_pad_o; // received from transmitter module
|
548 |
|
|
wire srx_pad_i;
|
549 |
|
|
wire srx_pad;
|
550 |
|
|
|
551 |
|
|
reg [7:0] wb_dat_o;
|
552 |
|
|
|
553 |
|
|
wire [`UART_ADDR_WIDTH-1:0] wb_addr_i;
|
554 |
|
|
wire [7:0] wb_dat_i;
|
555 |
|
|
|
556 |
|
|
|
557 |
|
|
reg [3:0] ier;
|
558 |
|
|
reg [3:0] iir;
|
559 |
|
|
reg [1:0] fcr; /// bits 7 and 6 of fcr. Other bits are ignored
|
560 |
|
|
reg [4:0] mcr;
|
561 |
|
|
reg [7:0] lcr;
|
562 |
|
|
reg [7:0] msr;
|
563 |
|
|
`ifdef UART_FIX_BAUDRATE
|
564 |
|
|
wire [15:0] dl;
|
565 |
|
|
assign dl = 16'h`UART_DIVISOR;
|
566 |
|
|
`else
|
567 |
|
|
reg [15:0] dl; // 32-bit divisor latch
|
568 |
|
|
`endif
|
569 |
|
|
reg [7:0] scratch; // UART scratch register
|
570 |
|
|
reg start_dlc; // activate dlc on writing to UART_DL1
|
571 |
|
|
reg lsr_mask_d; // delay for lsr_mask condition
|
572 |
|
|
reg msi_reset; // reset MSR 4 lower bits indicator
|
573 |
|
|
//reg threi_clear; // THRE interrupt clear flag
|
574 |
|
|
reg [15:0] dlc; // 32-bit divisor latch counter
|
575 |
|
|
reg int_o;
|
576 |
|
|
|
577 |
|
|
reg [3:0] trigger_level; // trigger level of the receiver FIFO
|
578 |
|
|
reg rx_reset;
|
579 |
|
|
reg tx_reset;
|
580 |
|
|
|
581 |
|
|
wire dlab; // divisor latch access bit
|
582 |
|
|
wire cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i; // modem status bits
|
583 |
|
|
wire loopback; // loopback bit (MCR bit 4)
|
584 |
|
|
wire cts, dsr, ri, dcd; // effective signals
|
585 |
|
|
wire cts_c, dsr_c, ri_c, dcd_c; // Complement effective signals (considering loopback)
|
586 |
|
|
wire rts_pad_o, dtr_pad_o; // modem control outputs
|
587 |
|
|
|
588 |
|
|
// LSR bits wires and regs
|
589 |
|
|
wire [7:0] lsr;
|
590 |
|
|
wire lsr0, lsr1, lsr2, lsr3, lsr4, lsr5, lsr6, lsr7;
|
591 |
|
|
reg lsr0r, lsr1r, lsr2r, lsr3r, lsr4r, lsr5r, lsr6r, lsr7r;
|
592 |
|
|
wire lsr_mask; // lsr_mask
|
593 |
|
|
|
594 |
|
|
//
|
595 |
|
|
// ASSINGS
|
596 |
|
|
//
|
597 |
|
|
|
598 |
|
|
assign lsr[7:0] = { lsr7r, lsr6r, lsr5r, lsr4r, lsr3r, lsr2r, lsr1r, lsr0r };
|
599 |
|
|
|
600 |
|
|
assign {cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i} = modem_inputs;
|
601 |
|
|
assign {cts, dsr, ri, dcd} = ~{cts_pad_i,dsr_pad_i,ri_pad_i,dcd_pad_i};
|
602 |
|
|
|
603 |
|
|
assign {cts_c, dsr_c, ri_c, dcd_c} = loopback ? {mcr[`UART_MC_RTS],mcr[`UART_MC_DTR],mcr[`UART_MC_OUT1],mcr[`UART_MC_OUT2]}
|
604 |
|
|
: {cts_pad_i,dsr_pad_i,ri_pad_i,dcd_pad_i};
|
605 |
|
|
|
606 |
|
|
assign dlab = lcr[`UART_LC_DL];
|
607 |
|
|
assign loopback = mcr[4];
|
608 |
|
|
|
609 |
|
|
// assign modem outputs
|
610 |
|
|
assign rts_pad_o = mcr[`UART_MC_RTS];
|
611 |
|
|
assign dtr_pad_o = mcr[`UART_MC_DTR];
|
612 |
|
|
|
613 |
|
|
// Interrupt signals
|
614 |
|
|
wire rls_int; // receiver line status interrupt
|
615 |
|
|
wire rda_int; // receiver data available interrupt
|
616 |
|
|
wire ti_int; // timeout indicator interrupt
|
617 |
|
|
wire thre_int; // transmitter holding register empty interrupt
|
618 |
|
|
wire ms_int; // modem status interrupt
|
619 |
|
|
|
620 |
|
|
// FIFO signals
|
621 |
|
|
reg tf_push;
|
622 |
|
|
reg rf_pop;
|
623 |
|
|
wire [`UART_FIFO_REC_WIDTH-1:0] rf_data_out;
|
624 |
|
|
wire rf_error_bit; // an error (parity or framing) is inside the fifo
|
625 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
626 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
627 |
|
|
wire [2:0] tstate;
|
628 |
|
|
wire [3:0] rstate;
|
629 |
|
|
wire [9:0] counter_t;
|
630 |
|
|
|
631 |
|
|
wire thre_set_en; // THRE status is delayed one character time when a character is written to fifo.
|
632 |
|
|
reg [7:0] block_cnt; // While counter counts, THRE status is blocked (delayed one character cycle)
|
633 |
|
|
reg [7:0] block_value; // One character length minus stop bit
|
634 |
|
|
|
635 |
|
|
// Transmitter Instance
|
636 |
|
|
wire serial_out;
|
637 |
|
|
|
638 |
|
|
uart_transmitter transmitter(clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, serial_out, tstate, tf_count, tx_reset, lsr_mask);
|
639 |
|
|
|
640 |
|
|
// Synchronizing and sampling serial RX input
|
641 |
|
|
uart_sync_flops i_uart_sync_flops
|
642 |
|
|
(
|
643 |
|
|
.rst_i (wb_rst_i),
|
644 |
|
|
.clk_i (clk),
|
645 |
|
|
.stage1_rst_i (1'b0),
|
646 |
|
|
.stage1_clk_en_i (1'b1),
|
647 |
|
|
.async_dat_i (srx_pad_i),
|
648 |
|
|
.sync_dat_o (srx_pad)
|
649 |
|
|
);
|
650 |
|
|
defparam i_uart_sync_flops.width = 1;
|
651 |
|
|
defparam i_uart_sync_flops.init_value = 1'b1;
|
652 |
|
|
|
653 |
|
|
// handle loopback
|
654 |
|
|
wire serial_in = loopback ? serial_out : srx_pad;
|
655 |
|
|
assign stx_pad_o = loopback ? 1'b1 : serial_out;
|
656 |
|
|
|
657 |
|
|
// Receiver Instance
|
658 |
|
|
uart_receiver receiver(clk, wb_rst_i, lcr, rf_pop, serial_in, enable,
|
659 |
|
|
counter_t, rf_count, rf_data_out, rf_error_bit, rf_overrun, rx_reset, lsr_mask, rstate, rf_push_pulse);
|
660 |
|
|
|
661 |
|
|
|
662 |
|
|
// Asynchronous reading here because the outputs are sampled in uart_wb.v file
|
663 |
|
|
always @(dl or dlab or ier or iir or scratch
|
664 |
|
|
or lcr or lsr or msr or rf_data_out or wb_addr_i or wb_re_i) // asynchrounous reading
|
665 |
|
|
begin
|
666 |
|
|
case (wb_addr_i)
|
667 |
|
|
`UART_REG_RB : wb_dat_o = dlab ? dl[`UART_DL1] : rf_data_out[10:3];
|
668 |
|
|
`UART_REG_IE : wb_dat_o = dlab ? dl[`UART_DL2] : ier;
|
669 |
|
|
`UART_REG_II : wb_dat_o = {4'b1100,iir};
|
670 |
|
|
`UART_REG_LC : wb_dat_o = lcr;
|
671 |
|
|
`UART_REG_LS : wb_dat_o = lsr;
|
672 |
|
|
`UART_REG_MS : wb_dat_o = msr;
|
673 |
|
|
`UART_REG_SR : wb_dat_o = scratch;
|
674 |
|
|
default: wb_dat_o = 8'b0; // ??
|
675 |
|
|
endcase // case(wb_addr_i)
|
676 |
|
|
end // always @ (dl or dlab or ier or iir or scratch...
|
677 |
|
|
|
678 |
|
|
|
679 |
|
|
// rf_pop signal handling
|
680 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
681 |
|
|
begin
|
682 |
|
|
if (wb_rst_i)
|
683 |
|
|
rf_pop <= #1 0;
|
684 |
|
|
else
|
685 |
|
|
if (rf_pop) // restore the signal to 0 after one clock cycle
|
686 |
|
|
rf_pop <= #1 0;
|
687 |
|
|
else
|
688 |
|
|
if (wb_re_i && wb_addr_i == `UART_REG_RB && !dlab)
|
689 |
|
|
rf_pop <= #1 1; // advance read pointer
|
690 |
|
|
end
|
691 |
|
|
|
692 |
|
|
wire lsr_mask_condition;
|
693 |
|
|
wire iir_read;
|
694 |
|
|
wire msr_read;
|
695 |
|
|
wire fifo_read;
|
696 |
|
|
wire fifo_write;
|
697 |
|
|
|
698 |
|
|
assign lsr_mask_condition = (wb_re_i && wb_addr_i == `UART_REG_LS && !dlab);
|
699 |
|
|
assign iir_read = (wb_re_i && wb_addr_i == `UART_REG_II && !dlab);
|
700 |
|
|
assign msr_read = (wb_re_i && wb_addr_i == `UART_REG_MS && !dlab);
|
701 |
|
|
assign fifo_read = (wb_re_i && wb_addr_i == `UART_REG_RB && !dlab);
|
702 |
|
|
assign fifo_write = (wb_we_i && wb_addr_i == `UART_REG_TR && !dlab);
|
703 |
|
|
|
704 |
|
|
// lsr_mask_d delayed signal handling
|
705 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
706 |
|
|
begin
|
707 |
|
|
if (wb_rst_i)
|
708 |
|
|
lsr_mask_d <= #1 0;
|
709 |
|
|
else // reset bits in the Line Status Register
|
710 |
|
|
lsr_mask_d <= #1 lsr_mask_condition;
|
711 |
|
|
end
|
712 |
|
|
|
713 |
|
|
// lsr_mask is rise detected
|
714 |
|
|
assign lsr_mask = lsr_mask_condition && ~lsr_mask_d;
|
715 |
|
|
|
716 |
|
|
// msi_reset signal handling
|
717 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
718 |
|
|
begin
|
719 |
|
|
if (wb_rst_i)
|
720 |
|
|
msi_reset <= #1 1;
|
721 |
|
|
else
|
722 |
|
|
if (msi_reset)
|
723 |
|
|
msi_reset <= #1 0;
|
724 |
|
|
else
|
725 |
|
|
if (msr_read)
|
726 |
|
|
msi_reset <= #1 1; // reset bits in Modem Status Register
|
727 |
|
|
end
|
728 |
|
|
|
729 |
|
|
|
730 |
|
|
//
|
731 |
|
|
// WRITES AND RESETS //
|
732 |
|
|
//
|
733 |
|
|
// Line Control Register
|
734 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
735 |
|
|
if (wb_rst_i)
|
736 |
|
|
lcr <= #1 8'b00000011; // 8n1 setting
|
737 |
|
|
else
|
738 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_LC)
|
739 |
|
|
lcr <= #1 wb_dat_i;
|
740 |
|
|
|
741 |
|
|
// Interrupt Enable Register or UART_DL2
|
742 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
743 |
|
|
if (wb_rst_i)
|
744 |
|
|
begin
|
745 |
|
|
ier <= #1 4'b0000; // no interrupts after reset
|
746 |
|
|
`ifdef UART_FIX_BAUDRATE
|
747 |
|
|
`else
|
748 |
|
|
dl[`UART_DL2] <= #1 8'b0;
|
749 |
|
|
`endif
|
750 |
|
|
end
|
751 |
|
|
else
|
752 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_IE)
|
753 |
|
|
if (dlab)
|
754 |
|
|
begin
|
755 |
|
|
`ifdef UART_FIX_BAUDRATE
|
756 |
|
|
`else
|
757 |
|
|
dl[`UART_DL2] <= #1 wb_dat_i;
|
758 |
|
|
`endif
|
759 |
|
|
end
|
760 |
|
|
else
|
761 |
|
|
ier <= #1 wb_dat_i[3:0]; // ier uses only 4 lsb
|
762 |
|
|
|
763 |
|
|
|
764 |
|
|
// FIFO Control Register and rx_reset, tx_reset signals
|
765 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
766 |
|
|
if (wb_rst_i) begin
|
767 |
|
|
fcr <= #1 2'b11;
|
768 |
|
|
rx_reset <= #1 0;
|
769 |
|
|
tx_reset <= #1 0;
|
770 |
|
|
end else
|
771 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_FC) begin
|
772 |
|
|
fcr <= #1 wb_dat_i[7:6];
|
773 |
|
|
rx_reset <= #1 wb_dat_i[1];
|
774 |
|
|
tx_reset <= #1 wb_dat_i[2];
|
775 |
|
|
end else begin
|
776 |
|
|
rx_reset <= #1 0;
|
777 |
|
|
tx_reset <= #1 0;
|
778 |
|
|
end
|
779 |
|
|
|
780 |
|
|
// Modem Control Register
|
781 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
782 |
|
|
if (wb_rst_i)
|
783 |
|
|
mcr <= #1 5'b0;
|
784 |
|
|
else
|
785 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_MC)
|
786 |
|
|
mcr <= #1 wb_dat_i[4:0];
|
787 |
|
|
|
788 |
|
|
// Scratch register
|
789 |
|
|
// Line Control Register
|
790 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
791 |
|
|
if (wb_rst_i)
|
792 |
|
|
scratch <= #1 0; // 8n1 setting
|
793 |
|
|
else
|
794 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_SR)
|
795 |
|
|
scratch <= #1 wb_dat_i;
|
796 |
|
|
|
797 |
|
|
// TX_FIFO or UART_DL1
|
798 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
799 |
|
|
if (wb_rst_i)
|
800 |
|
|
begin
|
801 |
|
|
`ifdef UART_FIX_BAUDRATE
|
802 |
|
|
`else
|
803 |
|
|
dl[`UART_DL1] <= #1 8'b0;
|
804 |
|
|
`endif
|
805 |
|
|
tf_push <= #1 1'b0;
|
806 |
|
|
start_dlc <= #1 1'b0;
|
807 |
|
|
end
|
808 |
|
|
else
|
809 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_TR)
|
810 |
|
|
if (dlab)
|
811 |
|
|
begin
|
812 |
|
|
`ifdef UART_FIX_BAUDRATE
|
813 |
|
|
`else
|
814 |
|
|
dl[`UART_DL1] <= #1 wb_dat_i;
|
815 |
|
|
`endif
|
816 |
|
|
start_dlc <= #1 1'b1; // enable DL counter
|
817 |
|
|
tf_push <= #1 1'b0;
|
818 |
|
|
end
|
819 |
|
|
else
|
820 |
|
|
begin
|
821 |
|
|
tf_push <= #1 1'b1;
|
822 |
|
|
start_dlc <= #1 1'b0;
|
823 |
|
|
end // else: !if(dlab)
|
824 |
|
|
else
|
825 |
|
|
begin
|
826 |
|
|
start_dlc <= #1 1'b0;
|
827 |
|
|
tf_push <= #1 1'b0;
|
828 |
|
|
end // else: !if(dlab)
|
829 |
|
|
|
830 |
|
|
// Receiver FIFO trigger level selection logic (asynchronous mux)
|
831 |
|
|
always @(fcr)
|
832 |
|
|
case (fcr[`UART_FC_TL])
|
833 |
|
|
2'b00 : trigger_level = 1;
|
834 |
|
|
2'b01 : trigger_level = 4;
|
835 |
|
|
2'b10 : trigger_level = 8;
|
836 |
|
|
2'b11 : trigger_level = 14;
|
837 |
|
|
endcase // case(fcr[`UART_FC_TL])
|
838 |
|
|
|
839 |
|
|
//
|
840 |
|
|
// STATUS REGISTERS //
|
841 |
|
|
//
|
842 |
|
|
|
843 |
|
|
// Modem Status Register
|
844 |
|
|
reg [3:0] delayed_modem_signals;
|
845 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
846 |
|
|
begin
|
847 |
|
|
if (wb_rst_i)
|
848 |
|
|
begin
|
849 |
|
|
msr <= #1 0;
|
850 |
|
|
delayed_modem_signals[3:0] <= #1 0;
|
851 |
|
|
end
|
852 |
|
|
else begin
|
853 |
|
|
msr[`UART_MS_DDCD:`UART_MS_DCTS] <= #1 msi_reset ? 4'b0 :
|
854 |
|
|
msr[`UART_MS_DDCD:`UART_MS_DCTS] | ({dcd, ri, dsr, cts} ^ delayed_modem_signals[3:0]);
|
855 |
|
|
msr[`UART_MS_CDCD:`UART_MS_CCTS] <= #1 {dcd_c, ri_c, dsr_c, cts_c};
|
856 |
|
|
delayed_modem_signals[3:0] <= #1 {dcd, ri, dsr, cts};
|
857 |
|
|
end
|
858 |
|
|
end
|
859 |
|
|
|
860 |
|
|
|
861 |
|
|
// Line Status Register
|
862 |
|
|
|
863 |
|
|
// activation conditions
|
864 |
|
|
assign lsr0 = (rf_count==0 && rf_push_pulse); // data in receiver fifo available set condition
|
865 |
|
|
assign lsr1 = rf_overrun; // Receiver overrun error
|
866 |
|
|
assign lsr2 = rf_data_out[1]; // parity error bit
|
867 |
|
|
assign lsr3 = rf_data_out[0]; // framing error bit
|
868 |
|
|
assign lsr4 = rf_data_out[2]; // break error in the character
|
869 |
|
|
assign lsr5 = (tf_count==5'b0 && thre_set_en); // transmitter fifo is empty
|
870 |
|
|
assign lsr6 = (tf_count==5'b0 && thre_set_en && (tstate == /*`S_IDLE */ 0)); // transmitter empty
|
871 |
|
|
assign lsr7 = rf_error_bit | rf_overrun;
|
872 |
|
|
|
873 |
|
|
// lsr bit0 (receiver data available)
|
874 |
|
|
reg lsr0_d;
|
875 |
|
|
|
876 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
877 |
|
|
if (wb_rst_i) lsr0_d <= #1 0;
|
878 |
|
|
else lsr0_d <= #1 lsr0;
|
879 |
|
|
|
880 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
881 |
|
|
if (wb_rst_i) lsr0r <= #1 0;
|
882 |
|
|
else lsr0r <= #1 (rf_count==1 && rf_pop && !rf_push_pulse || rx_reset) ? 0 : // deassert condition
|
883 |
|
|
lsr0r || (lsr0 && ~lsr0_d); // set on rise of lsr0 and keep asserted until deasserted
|
884 |
|
|
|
885 |
|
|
// lsr bit 1 (receiver overrun)
|
886 |
|
|
reg lsr1_d; // delayed
|
887 |
|
|
|
888 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
889 |
|
|
if (wb_rst_i) lsr1_d <= #1 0;
|
890 |
|
|
else lsr1_d <= #1 lsr1;
|
891 |
|
|
|
892 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
893 |
|
|
if (wb_rst_i) lsr1r <= #1 0;
|
894 |
|
|
else lsr1r <= #1 lsr_mask ? 0 : lsr1r || (lsr1 && ~lsr1_d); // set on rise
|
895 |
|
|
|
896 |
|
|
// lsr bit 2 (parity error)
|
897 |
|
|
reg lsr2_d; // delayed
|
898 |
|
|
|
899 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
900 |
|
|
if (wb_rst_i) lsr2_d <= #1 0;
|
901 |
|
|
else lsr2_d <= #1 lsr2;
|
902 |
|
|
|
903 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
904 |
|
|
if (wb_rst_i) lsr2r <= #1 0;
|
905 |
|
|
else lsr2r <= #1 lsr_mask ? 0 : lsr2r || (lsr2 && ~lsr2_d); // set on rise
|
906 |
|
|
|
907 |
|
|
// lsr bit 3 (framing error)
|
908 |
|
|
reg lsr3_d; // delayed
|
909 |
|
|
|
910 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
911 |
|
|
if (wb_rst_i) lsr3_d <= #1 0;
|
912 |
|
|
else lsr3_d <= #1 lsr3;
|
913 |
|
|
|
914 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
915 |
|
|
if (wb_rst_i) lsr3r <= #1 0;
|
916 |
|
|
else lsr3r <= #1 lsr_mask ? 0 : lsr3r || (lsr3 && ~lsr3_d); // set on rise
|
917 |
|
|
|
918 |
|
|
// lsr bit 4 (break indicator)
|
919 |
|
|
reg lsr4_d; // delayed
|
920 |
|
|
|
921 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
922 |
|
|
if (wb_rst_i) lsr4_d <= #1 0;
|
923 |
|
|
else lsr4_d <= #1 lsr4;
|
924 |
|
|
|
925 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
926 |
|
|
if (wb_rst_i) lsr4r <= #1 0;
|
927 |
|
|
else lsr4r <= #1 lsr_mask ? 0 : lsr4r || (lsr4 && ~lsr4_d);
|
928 |
|
|
|
929 |
|
|
// lsr bit 5 (transmitter fifo is empty)
|
930 |
|
|
reg lsr5_d;
|
931 |
|
|
|
932 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
933 |
|
|
if (wb_rst_i) lsr5_d <= #1 1;
|
934 |
|
|
else lsr5_d <= #1 lsr5;
|
935 |
|
|
|
936 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
937 |
|
|
if (wb_rst_i) lsr5r <= #1 1;
|
938 |
|
|
else lsr5r <= #1 (fifo_write) ? 0 : lsr5r || (lsr5 && ~lsr5_d);
|
939 |
|
|
|
940 |
|
|
// lsr bit 6 (transmitter empty indicator)
|
941 |
|
|
reg lsr6_d;
|
942 |
|
|
|
943 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
944 |
|
|
if (wb_rst_i) lsr6_d <= #1 1;
|
945 |
|
|
else lsr6_d <= #1 lsr6;
|
946 |
|
|
|
947 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
948 |
|
|
if (wb_rst_i) lsr6r <= #1 1;
|
949 |
|
|
else lsr6r <= #1 (fifo_write) ? 0 : lsr6r || (lsr6 && ~lsr6_d);
|
950 |
|
|
|
951 |
|
|
// lsr bit 7 (error in fifo)
|
952 |
|
|
reg lsr7_d;
|
953 |
|
|
|
954 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
955 |
|
|
if (wb_rst_i) lsr7_d <= #1 0;
|
956 |
|
|
else lsr7_d <= #1 lsr7;
|
957 |
|
|
|
958 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
959 |
|
|
if (wb_rst_i) lsr7r <= #1 0;
|
960 |
|
|
else lsr7r <= #1 lsr_mask ? 0 : lsr7r || (lsr7 && ~lsr7_d);
|
961 |
|
|
|
962 |
|
|
// Frequency divider
|
963 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
964 |
|
|
begin
|
965 |
|
|
if (wb_rst_i)
|
966 |
|
|
dlc <= #1 0;
|
967 |
|
|
else
|
968 |
|
|
if (start_dlc | ~ (|dlc))
|
969 |
|
|
dlc <= #1 dl - 1; // preset counter
|
970 |
|
|
else
|
971 |
|
|
dlc <= #1 dlc - 1; // decrement counter
|
972 |
|
|
end
|
973 |
|
|
|
974 |
|
|
// Enable signal generation logic
|
975 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
976 |
|
|
begin
|
977 |
|
|
if (wb_rst_i)
|
978 |
|
|
enable <= #1 1'b0;
|
979 |
|
|
else
|
980 |
|
|
if (|dl & ~(|dlc)) // dl>0 & dlc==0
|
981 |
|
|
enable <= #1 1'b1;
|
982 |
|
|
else
|
983 |
|
|
enable <= #1 1'b0;
|
984 |
|
|
end
|
985 |
|
|
|
986 |
|
|
// Delaying THRE status for one character cycle after a character is written to an empty fifo.
|
987 |
|
|
always @(lcr)
|
988 |
|
|
case (lcr[3:0])
|
989 |
|
|
4'b0000 : block_value = 95; // 6 bits
|
990 |
|
|
4'b0100 : block_value = 103; // 6.5 bits
|
991 |
|
|
4'b0001, 4'b1000 : block_value = 111; // 7 bits
|
992 |
|
|
4'b1100 : block_value = 119; // 7.5 bits
|
993 |
|
|
4'b0010, 4'b0101, 4'b1001 : block_value = 127; // 8 bits
|
994 |
|
|
4'b0011, 4'b0110, 4'b1010, 4'b1101 : block_value = 143; // 9 bits
|
995 |
|
|
4'b0111, 4'b1011, 4'b1110 : block_value = 159; // 10 bits
|
996 |
|
|
4'b1111 : block_value = 175; // 11 bits
|
997 |
|
|
endcase // case(lcr[3:0])
|
998 |
|
|
|
999 |
|
|
// Counting time of one character minus stop bit
|
1000 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1001 |
|
|
begin
|
1002 |
|
|
if (wb_rst_i)
|
1003 |
|
|
block_cnt <= #1 8'd0;
|
1004 |
|
|
else
|
1005 |
|
|
if(lsr5r & fifo_write) // THRE bit set & write to fifo occured
|
1006 |
|
|
block_cnt <= #1 block_value;
|
1007 |
|
|
else
|
1008 |
|
|
if (enable & block_cnt != 8'b0) // only work on enable times
|
1009 |
|
|
block_cnt <= #1 block_cnt - 1; // decrement break counter
|
1010 |
|
|
end // always of break condition detection
|
1011 |
|
|
|
1012 |
|
|
// Generating THRE status enable signal
|
1013 |
|
|
assign thre_set_en = ~(|block_cnt);
|
1014 |
|
|
|
1015 |
|
|
|
1016 |
|
|
//
|
1017 |
|
|
// INTERRUPT LOGIC
|
1018 |
|
|
//
|
1019 |
|
|
|
1020 |
|
|
assign rls_int = ier[`UART_IE_RLS] && (lsr[`UART_LS_OE] || lsr[`UART_LS_PE] || lsr[`UART_LS_FE] || lsr[`UART_LS_BI]);
|
1021 |
|
|
assign rda_int = ier[`UART_IE_RDA] && (rf_count >= {1'b0,trigger_level});
|
1022 |
|
|
assign thre_int = ier[`UART_IE_THRE] && lsr[`UART_LS_TFE];
|
1023 |
|
|
assign ms_int = ier[`UART_IE_MS] && (| msr[3:0]);
|
1024 |
|
|
assign ti_int = ier[`UART_IE_RDA] && (counter_t == 10'b0) && (|rf_count);
|
1025 |
|
|
|
1026 |
|
|
reg rls_int_d;
|
1027 |
|
|
reg thre_int_d;
|
1028 |
|
|
reg ms_int_d;
|
1029 |
|
|
reg ti_int_d;
|
1030 |
|
|
reg rda_int_d;
|
1031 |
|
|
|
1032 |
|
|
// delay lines
|
1033 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1034 |
|
|
if (wb_rst_i) rls_int_d <= #1 0;
|
1035 |
|
|
else rls_int_d <= #1 rls_int;
|
1036 |
|
|
|
1037 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1038 |
|
|
if (wb_rst_i) rda_int_d <= #1 0;
|
1039 |
|
|
else rda_int_d <= #1 rda_int;
|
1040 |
|
|
|
1041 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1042 |
|
|
if (wb_rst_i) thre_int_d <= #1 0;
|
1043 |
|
|
else thre_int_d <= #1 thre_int;
|
1044 |
|
|
|
1045 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1046 |
|
|
if (wb_rst_i) ms_int_d <= #1 0;
|
1047 |
|
|
else ms_int_d <= #1 ms_int;
|
1048 |
|
|
|
1049 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1050 |
|
|
if (wb_rst_i) ti_int_d <= #1 0;
|
1051 |
|
|
else ti_int_d <= #1 ti_int;
|
1052 |
|
|
|
1053 |
|
|
// rise detection signals
|
1054 |
|
|
|
1055 |
|
|
wire rls_int_rise;
|
1056 |
|
|
wire thre_int_rise;
|
1057 |
|
|
wire ms_int_rise;
|
1058 |
|
|
wire ti_int_rise;
|
1059 |
|
|
wire rda_int_rise;
|
1060 |
|
|
|
1061 |
|
|
assign rda_int_rise = rda_int & ~rda_int_d;
|
1062 |
|
|
assign rls_int_rise = rls_int & ~rls_int_d;
|
1063 |
|
|
assign thre_int_rise = thre_int & ~thre_int_d;
|
1064 |
|
|
assign ms_int_rise = ms_int & ~ms_int_d;
|
1065 |
|
|
assign ti_int_rise = ti_int & ~ti_int_d;
|
1066 |
|
|
|
1067 |
|
|
// interrupt pending flags
|
1068 |
|
|
reg rls_int_pnd;
|
1069 |
|
|
reg rda_int_pnd;
|
1070 |
|
|
reg thre_int_pnd;
|
1071 |
|
|
reg ms_int_pnd;
|
1072 |
|
|
reg ti_int_pnd;
|
1073 |
|
|
|
1074 |
|
|
// interrupt pending flags assignments
|
1075 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1076 |
|
|
if (wb_rst_i) rls_int_pnd <= #1 0;
|
1077 |
|
|
else
|
1078 |
|
|
rls_int_pnd <= #1 lsr_mask ? 0 : // reset condition
|
1079 |
|
|
rls_int_rise ? 1 : // latch condition
|
1080 |
|
|
rls_int_pnd && ier[`UART_IE_RLS]; // default operation: remove if masked
|
1081 |
|
|
|
1082 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1083 |
|
|
if (wb_rst_i) rda_int_pnd <= #1 0;
|
1084 |
|
|
else
|
1085 |
|
|
rda_int_pnd <= #1 ((rf_count == {1'b0,trigger_level}) && fifo_read) ? 0 : // reset condition
|
1086 |
|
|
rda_int_rise ? 1 : // latch condition
|
1087 |
|
|
rda_int_pnd && ier[`UART_IE_RDA]; // default operation: remove if masked
|
1088 |
|
|
|
1089 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1090 |
|
|
if (wb_rst_i) thre_int_pnd <= #1 0;
|
1091 |
|
|
else
|
1092 |
|
|
thre_int_pnd <= #1 fifo_write || (iir_read & ~iir[`UART_II_IP] & iir[`UART_II_II] == `UART_II_THRE)? 0 :
|
1093 |
|
|
thre_int_rise ? 1 :
|
1094 |
|
|
thre_int_pnd && ier[`UART_IE_THRE];
|
1095 |
|
|
|
1096 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1097 |
|
|
if (wb_rst_i) ms_int_pnd <= #1 0;
|
1098 |
|
|
else
|
1099 |
|
|
ms_int_pnd <= #1 msr_read ? 0 :
|
1100 |
|
|
ms_int_rise ? 1 :
|
1101 |
|
|
ms_int_pnd && ier[`UART_IE_MS];
|
1102 |
|
|
|
1103 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1104 |
|
|
if (wb_rst_i) ti_int_pnd <= #1 0;
|
1105 |
|
|
else
|
1106 |
|
|
ti_int_pnd <= #1 fifo_read ? 0 :
|
1107 |
|
|
ti_int_rise ? 1 :
|
1108 |
|
|
ti_int_pnd && ier[`UART_IE_RDA];
|
1109 |
|
|
// end of pending flags
|
1110 |
|
|
|
1111 |
|
|
// INT_O logic
|
1112 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1113 |
|
|
begin
|
1114 |
|
|
if (wb_rst_i)
|
1115 |
|
|
int_o <= #1 1'b0;
|
1116 |
|
|
else
|
1117 |
|
|
int_o <= #1
|
1118 |
|
|
rls_int_pnd ? ~lsr_mask :
|
1119 |
|
|
rda_int_pnd ? 1 :
|
1120 |
|
|
ti_int_pnd ? ~fifo_read :
|
1121 |
|
|
thre_int_pnd ? !(fifo_write & iir_read) :
|
1122 |
|
|
ms_int_pnd ? ~msr_read :
|
1123 |
|
|
0; // if no interrupt are pending
|
1124 |
|
|
end
|
1125 |
|
|
|
1126 |
|
|
|
1127 |
|
|
// Interrupt Identification register
|
1128 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
1129 |
|
|
begin
|
1130 |
|
|
if (wb_rst_i)
|
1131 |
|
|
iir <= #1 1;
|
1132 |
|
|
else
|
1133 |
|
|
if (rls_int_pnd) // interrupt is pending
|
1134 |
|
|
begin
|
1135 |
|
|
iir[`UART_II_II] <= #1 `UART_II_RLS; // set identification register to correct value
|
1136 |
|
|
iir[`UART_II_IP] <= #1 1'b0; // and clear the IIR bit 0 (interrupt pending)
|
1137 |
|
|
end else // the sequence of conditions determines priority of interrupt identification
|
1138 |
|
|
if (rda_int)
|
1139 |
|
|
begin
|
1140 |
|
|
iir[`UART_II_II] <= #1 `UART_II_RDA;
|
1141 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
1142 |
|
|
end
|
1143 |
|
|
else if (ti_int_pnd)
|
1144 |
|
|
begin
|
1145 |
|
|
iir[`UART_II_II] <= #1 `UART_II_TI;
|
1146 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
1147 |
|
|
end
|
1148 |
|
|
else if (thre_int_pnd)
|
1149 |
|
|
begin
|
1150 |
|
|
iir[`UART_II_II] <= #1 `UART_II_THRE;
|
1151 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
1152 |
|
|
end
|
1153 |
|
|
else if (ms_int_pnd)
|
1154 |
|
|
begin
|
1155 |
|
|
iir[`UART_II_II] <= #1 `UART_II_MS;
|
1156 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
1157 |
|
|
end else // no interrupt is pending
|
1158 |
|
|
begin
|
1159 |
|
|
iir[`UART_II_II] <= #1 0;
|
1160 |
|
|
iir[`UART_II_IP] <= #1 1'b1;
|
1161 |
|
|
end
|
1162 |
|
|
end
|
1163 |
|
|
|
1164 |
|
|
endmodule
|
1165 |
|
|
//////////////////////////////////////////////////////////////////////
|
1166 |
|
|
//// ////
|
1167 |
|
|
//// uart_rfifo.v (Modified from uart_fifo.v) ////
|
1168 |
|
|
//// ////
|
1169 |
|
|
//// ////
|
1170 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
1171 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
1172 |
|
|
//// ////
|
1173 |
|
|
//// Documentation related to this project: ////
|
1174 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
1175 |
|
|
//// ////
|
1176 |
|
|
//// Projects compatibility: ////
|
1177 |
|
|
//// - WISHBONE ////
|
1178 |
|
|
//// RS232 Protocol ////
|
1179 |
|
|
//// 16550D uart (mostly supported) ////
|
1180 |
|
|
//// ////
|
1181 |
|
|
//// Overview (main Features): ////
|
1182 |
|
|
//// UART core receiver FIFO ////
|
1183 |
|
|
//// ////
|
1184 |
|
|
//// To Do: ////
|
1185 |
|
|
//// Nothing. ////
|
1186 |
|
|
//// ////
|
1187 |
|
|
//// Author(s): ////
|
1188 |
|
|
//// - gorban@opencores.org ////
|
1189 |
|
|
//// - Jacob Gorban ////
|
1190 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
1191 |
|
|
//// ////
|
1192 |
|
|
//// Created: 2001/05/12 ////
|
1193 |
|
|
//// Last Updated: 2002/07/22 ////
|
1194 |
|
|
//// (See log for the revision history) ////
|
1195 |
|
|
//// ////
|
1196 |
|
|
//// ////
|
1197 |
|
|
//////////////////////////////////////////////////////////////////////
|
1198 |
|
|
//// ////
|
1199 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
1200 |
|
|
//// ////
|
1201 |
|
|
//// This source file may be used and distributed without ////
|
1202 |
|
|
//// restriction provided that this copyright statement is not ////
|
1203 |
|
|
//// removed from the file and that any derivative work contains ////
|
1204 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
1205 |
|
|
//// ////
|
1206 |
|
|
//// This source file is free software; you can redistribute it ////
|
1207 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
1208 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
1209 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
1210 |
|
|
//// later version. ////
|
1211 |
|
|
//// ////
|
1212 |
|
|
//// This source is distributed in the hope that it will be ////
|
1213 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
1214 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
1215 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
1216 |
|
|
//// details. ////
|
1217 |
|
|
//// ////
|
1218 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
1219 |
|
|
//// Public License along with this source; if not, download it ////
|
1220 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
1221 |
|
|
//// ////
|
1222 |
|
|
//////////////////////////////////////////////////////////////////////
|
1223 |
|
|
//
|
1224 |
|
|
// CVS Revision History
|
1225 |
|
|
//
|
1226 |
|
|
// $Log: uart_rfifo.v,v $
|
1227 |
|
|
// Revision 1.4 2003/07/11 18:20:26 gorban
|
1228 |
|
|
// added clearing the receiver fifo statuses on resets
|
1229 |
|
|
//
|
1230 |
|
|
// Revision 1.3 2003/06/11 16:37:47 gorban
|
1231 |
|
|
// 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.
|
1232 |
|
|
//
|
1233 |
|
|
// Revision 1.2 2002/07/29 21:16:18 gorban
|
1234 |
|
|
// The uart_defines.v file is included again in sources.
|
1235 |
|
|
//
|
1236 |
|
|
// Revision 1.1 2002/07/22 23:02:23 gorban
|
1237 |
|
|
// Bug Fixes:
|
1238 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
1239 |
|
|
// Problem reported by Kenny.Tung.
|
1240 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
1241 |
|
|
//
|
1242 |
|
|
// Improvements:
|
1243 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
1244 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
1245 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
1246 |
|
|
//
|
1247 |
|
|
// * Added optional baudrate output (baud_o).
|
1248 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
1249 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
1250 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
1251 |
|
|
//
|
1252 |
|
|
// Revision 1.16 2001/12/20 13:25:46 mohor
|
1253 |
|
|
// rx push changed to be only one cycle wide.
|
1254 |
|
|
//
|
1255 |
|
|
// Revision 1.15 2001/12/18 09:01:07 mohor
|
1256 |
|
|
// Bug that was entered in the last update fixed (rx state machine).
|
1257 |
|
|
//
|
1258 |
|
|
// Revision 1.14 2001/12/17 14:46:48 mohor
|
1259 |
|
|
// overrun signal was moved to separate block because many sequential lsr
|
1260 |
|
|
// reads were preventing data from being written to rx fifo.
|
1261 |
|
|
// underrun signal was not used and was removed from the project.
|
1262 |
|
|
//
|
1263 |
|
|
// Revision 1.13 2001/11/26 21:38:54 gorban
|
1264 |
|
|
// Lots of fixes:
|
1265 |
|
|
// Break condition wasn't handled correctly at all.
|
1266 |
|
|
// LSR bits could lose their values.
|
1267 |
|
|
// LSR value after reset was wrong.
|
1268 |
|
|
// Timing of THRE interrupt signal corrected.
|
1269 |
|
|
// LSR bit 0 timing corrected.
|
1270 |
|
|
//
|
1271 |
|
|
// Revision 1.12 2001/11/08 14:54:23 mohor
|
1272 |
|
|
// Comments in Slovene language deleted, few small fixes for better work of
|
1273 |
|
|
// old tools. IRQs need to be fix.
|
1274 |
|
|
//
|
1275 |
|
|
// Revision 1.11 2001/11/07 17:51:52 gorban
|
1276 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
1277 |
|
|
// Many bugs hopefully squashed.
|
1278 |
|
|
//
|
1279 |
|
|
// Revision 1.10 2001/10/20 09:58:40 gorban
|
1280 |
|
|
// Small synopsis fixes
|
1281 |
|
|
//
|
1282 |
|
|
// Revision 1.9 2001/08/24 21:01:12 mohor
|
1283 |
|
|
// Things connected to parity changed.
|
1284 |
|
|
// Clock devider changed.
|
1285 |
|
|
//
|
1286 |
|
|
// Revision 1.8 2001/08/24 08:48:10 mohor
|
1287 |
|
|
// FIFO was not cleared after the data was read bug fixed.
|
1288 |
|
|
//
|
1289 |
|
|
// Revision 1.7 2001/08/23 16:05:05 mohor
|
1290 |
|
|
// Stop bit bug fixed.
|
1291 |
|
|
// Parity bug fixed.
|
1292 |
|
|
// WISHBONE read cycle bug fixed,
|
1293 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
1294 |
|
|
// PE indicator (Parity Error) bug fixed.
|
1295 |
|
|
// Register read bug fixed.
|
1296 |
|
|
//
|
1297 |
|
|
// Revision 1.3 2001/05/31 20:08:01 gorban
|
1298 |
|
|
// FIFO changes and other corrections.
|
1299 |
|
|
//
|
1300 |
|
|
// Revision 1.3 2001/05/27 17:37:48 gorban
|
1301 |
|
|
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
|
1302 |
|
|
//
|
1303 |
|
|
// Revision 1.2 2001/05/17 18:34:18 gorban
|
1304 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
1305 |
|
|
//
|
1306 |
|
|
// Revision 1.0 2001-05-17 21:27:12+02 jacob
|
1307 |
|
|
// Initial revision
|
1308 |
|
|
//
|
1309 |
|
|
//
|
1310 |
|
|
|
1311 |
|
|
// synopsys translate_off
|
1312 |
|
|
`include "timescale.v"
|
1313 |
|
|
// synopsys translate_on
|
1314 |
|
|
|
1315 |
|
|
`include "uart_defines.v"
|
1316 |
|
|
|
1317 |
|
|
module uart_rfifo (clk,
|
1318 |
|
|
wb_rst_i, data_in, data_out,
|
1319 |
|
|
// Control signals
|
1320 |
|
|
push, // push strobe, active high
|
1321 |
|
|
pop, // pop strobe, active high
|
1322 |
|
|
// status signals
|
1323 |
|
|
overrun,
|
1324 |
|
|
count,
|
1325 |
|
|
error_bit,
|
1326 |
|
|
fifo_reset,
|
1327 |
|
|
reset_status
|
1328 |
|
|
);
|
1329 |
|
|
|
1330 |
|
|
|
1331 |
|
|
// FIFO parameters
|
1332 |
|
|
parameter fifo_width = `UART_FIFO_WIDTH;
|
1333 |
|
|
parameter fifo_depth = `UART_FIFO_DEPTH;
|
1334 |
|
|
parameter fifo_pointer_w = `UART_FIFO_POINTER_W;
|
1335 |
|
|
parameter fifo_counter_w = `UART_FIFO_COUNTER_W;
|
1336 |
|
|
|
1337 |
|
|
input clk;
|
1338 |
|
|
input wb_rst_i;
|
1339 |
|
|
input push;
|
1340 |
|
|
input pop;
|
1341 |
|
|
input [fifo_width-1:0] data_in;
|
1342 |
|
|
input fifo_reset;
|
1343 |
|
|
input reset_status;
|
1344 |
|
|
|
1345 |
|
|
output [fifo_width-1:0] data_out;
|
1346 |
|
|
output overrun;
|
1347 |
|
|
output [fifo_counter_w-1:0] count;
|
1348 |
|
|
output error_bit;
|
1349 |
|
|
|
1350 |
|
|
wire [fifo_width-1:0] data_out;
|
1351 |
|
|
wire [7:0] data8_out;
|
1352 |
|
|
// flags FIFO
|
1353 |
|
|
reg [2:0] fifo[fifo_depth-1:0];
|
1354 |
|
|
|
1355 |
|
|
// FIFO pointers
|
1356 |
|
|
reg [fifo_pointer_w-1:0] top;
|
1357 |
|
|
reg [fifo_pointer_w-1:0] bottom;
|
1358 |
|
|
|
1359 |
|
|
reg [fifo_counter_w-1:0] count;
|
1360 |
|
|
reg overrun;
|
1361 |
|
|
|
1362 |
|
|
wire [fifo_pointer_w-1:0] top_plus_1 = top + 1'b1;
|
1363 |
|
|
|
1364 |
|
|
raminfr #(fifo_pointer_w,8,fifo_depth) rfifo
|
1365 |
|
|
(.clk(clk),
|
1366 |
|
|
.we(push),
|
1367 |
|
|
.a(top),
|
1368 |
|
|
.dpra(bottom),
|
1369 |
|
|
.di(data_in[fifo_width-1:fifo_width-8]),
|
1370 |
|
|
.dpo(data8_out)
|
1371 |
|
|
);
|
1372 |
|
|
|
1373 |
|
|
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
|
1374 |
|
|
begin
|
1375 |
|
|
if (wb_rst_i)
|
1376 |
|
|
begin
|
1377 |
|
|
top <= #1 0;
|
1378 |
|
|
bottom <= #1 1'b0;
|
1379 |
|
|
count <= #1 0;
|
1380 |
|
|
fifo[0] <= #1 0;
|
1381 |
|
|
fifo[1] <= #1 0;
|
1382 |
|
|
fifo[2] <= #1 0;
|
1383 |
|
|
fifo[3] <= #1 0;
|
1384 |
|
|
fifo[4] <= #1 0;
|
1385 |
|
|
fifo[5] <= #1 0;
|
1386 |
|
|
fifo[6] <= #1 0;
|
1387 |
|
|
fifo[7] <= #1 0;
|
1388 |
|
|
fifo[8] <= #1 0;
|
1389 |
|
|
fifo[9] <= #1 0;
|
1390 |
|
|
fifo[10] <= #1 0;
|
1391 |
|
|
fifo[11] <= #1 0;
|
1392 |
|
|
fifo[12] <= #1 0;
|
1393 |
|
|
fifo[13] <= #1 0;
|
1394 |
|
|
fifo[14] <= #1 0;
|
1395 |
|
|
fifo[15] <= #1 0;
|
1396 |
|
|
end
|
1397 |
|
|
else
|
1398 |
|
|
if (fifo_reset) begin
|
1399 |
|
|
top <= #1 0;
|
1400 |
|
|
bottom <= #1 1'b0;
|
1401 |
|
|
count <= #1 0;
|
1402 |
|
|
fifo[0] <= #1 0;
|
1403 |
|
|
fifo[1] <= #1 0;
|
1404 |
|
|
fifo[2] <= #1 0;
|
1405 |
|
|
fifo[3] <= #1 0;
|
1406 |
|
|
fifo[4] <= #1 0;
|
1407 |
|
|
fifo[5] <= #1 0;
|
1408 |
|
|
fifo[6] <= #1 0;
|
1409 |
|
|
fifo[7] <= #1 0;
|
1410 |
|
|
fifo[8] <= #1 0;
|
1411 |
|
|
fifo[9] <= #1 0;
|
1412 |
|
|
fifo[10] <= #1 0;
|
1413 |
|
|
fifo[11] <= #1 0;
|
1414 |
|
|
fifo[12] <= #1 0;
|
1415 |
|
|
fifo[13] <= #1 0;
|
1416 |
|
|
fifo[14] <= #1 0;
|
1417 |
|
|
fifo[15] <= #1 0;
|
1418 |
|
|
end
|
1419 |
|
|
else
|
1420 |
|
|
begin
|
1421 |
|
|
case ({push, pop})
|
1422 |
|
|
2'b10 : if (count<fifo_depth) // overrun condition
|
1423 |
|
|
begin
|
1424 |
|
|
top <= #1 top_plus_1;
|
1425 |
|
|
fifo[top] <= #1 data_in[2:0];
|
1426 |
|
|
count <= #1 count + 1'b1;
|
1427 |
|
|
end
|
1428 |
|
|
2'b01 : if(count>0)
|
1429 |
|
|
begin
|
1430 |
|
|
fifo[bottom] <= #1 0;
|
1431 |
|
|
bottom <= #1 bottom + 1'b1;
|
1432 |
|
|
count <= #1 count - 1'b1;
|
1433 |
|
|
end
|
1434 |
|
|
2'b11 : begin
|
1435 |
|
|
bottom <= #1 bottom + 1'b1;
|
1436 |
|
|
top <= #1 top_plus_1;
|
1437 |
|
|
fifo[top] <= #1 data_in[2:0];
|
1438 |
|
|
end
|
1439 |
|
|
default: ;
|
1440 |
|
|
endcase
|
1441 |
|
|
end
|
1442 |
|
|
end // always
|
1443 |
|
|
|
1444 |
|
|
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
|
1445 |
|
|
begin
|
1446 |
|
|
if (wb_rst_i)
|
1447 |
|
|
overrun <= #1 1'b0;
|
1448 |
|
|
else
|
1449 |
|
|
if(fifo_reset | reset_status)
|
1450 |
|
|
overrun <= #1 1'b0;
|
1451 |
|
|
else
|
1452 |
|
|
if(push & ~pop & (count==fifo_depth))
|
1453 |
|
|
overrun <= #1 1'b1;
|
1454 |
|
|
end // always
|
1455 |
|
|
|
1456 |
|
|
|
1457 |
|
|
// please note though that data_out is only valid one clock after pop signal
|
1458 |
|
|
assign data_out = {data8_out,fifo[bottom]};
|
1459 |
|
|
|
1460 |
|
|
// Additional logic for detection of error conditions (parity and framing) inside the FIFO
|
1461 |
|
|
// for the Line Status Register bit 7
|
1462 |
|
|
|
1463 |
|
|
wire [2:0] word0 = fifo[0];
|
1464 |
|
|
wire [2:0] word1 = fifo[1];
|
1465 |
|
|
wire [2:0] word2 = fifo[2];
|
1466 |
|
|
wire [2:0] word3 = fifo[3];
|
1467 |
|
|
wire [2:0] word4 = fifo[4];
|
1468 |
|
|
wire [2:0] word5 = fifo[5];
|
1469 |
|
|
wire [2:0] word6 = fifo[6];
|
1470 |
|
|
wire [2:0] word7 = fifo[7];
|
1471 |
|
|
|
1472 |
|
|
wire [2:0] word8 = fifo[8];
|
1473 |
|
|
wire [2:0] word9 = fifo[9];
|
1474 |
|
|
wire [2:0] word10 = fifo[10];
|
1475 |
|
|
wire [2:0] word11 = fifo[11];
|
1476 |
|
|
wire [2:0] word12 = fifo[12];
|
1477 |
|
|
wire [2:0] word13 = fifo[13];
|
1478 |
|
|
wire [2:0] word14 = fifo[14];
|
1479 |
|
|
wire [2:0] word15 = fifo[15];
|
1480 |
|
|
|
1481 |
|
|
// a 1 is returned if any of the error bits in the fifo is 1
|
1482 |
|
|
assign error_bit = |(word0[2:0] | word1[2:0] | word2[2:0] | word3[2:0] |
|
1483 |
|
|
word4[2:0] | word5[2:0] | word6[2:0] | word7[2:0] |
|
1484 |
|
|
word8[2:0] | word9[2:0] | word10[2:0] | word11[2:0] |
|
1485 |
|
|
word12[2:0] | word13[2:0] | word14[2:0] | word15[2:0] );
|
1486 |
|
|
|
1487 |
|
|
endmodule
|
1488 |
|
|
//////////////////////////////////////////////////////////////////////
|
1489 |
|
|
//// ////
|
1490 |
|
|
//// uart_tfifo.v ////
|
1491 |
|
|
//// ////
|
1492 |
|
|
//// ////
|
1493 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
1494 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
1495 |
|
|
//// ////
|
1496 |
|
|
//// Documentation related to this project: ////
|
1497 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
1498 |
|
|
//// ////
|
1499 |
|
|
//// Projects compatibility: ////
|
1500 |
|
|
//// - WISHBONE ////
|
1501 |
|
|
//// RS232 Protocol ////
|
1502 |
|
|
//// 16550D uart (mostly supported) ////
|
1503 |
|
|
//// ////
|
1504 |
|
|
//// Overview (main Features): ////
|
1505 |
|
|
//// UART core transmitter FIFO ////
|
1506 |
|
|
//// ////
|
1507 |
|
|
//// To Do: ////
|
1508 |
|
|
//// Nothing. ////
|
1509 |
|
|
//// ////
|
1510 |
|
|
//// Author(s): ////
|
1511 |
|
|
//// - gorban@opencores.org ////
|
1512 |
|
|
//// - Jacob Gorban ////
|
1513 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
1514 |
|
|
//// ////
|
1515 |
|
|
//// Created: 2001/05/12 ////
|
1516 |
|
|
//// Last Updated: 2002/07/22 ////
|
1517 |
|
|
//// (See log for the revision history) ////
|
1518 |
|
|
//// ////
|
1519 |
|
|
//// ////
|
1520 |
|
|
//////////////////////////////////////////////////////////////////////
|
1521 |
|
|
//// ////
|
1522 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
1523 |
|
|
//// ////
|
1524 |
|
|
//// This source file may be used and distributed without ////
|
1525 |
|
|
//// restriction provided that this copyright statement is not ////
|
1526 |
|
|
//// removed from the file and that any derivative work contains ////
|
1527 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
1528 |
|
|
//// ////
|
1529 |
|
|
//// This source file is free software; you can redistribute it ////
|
1530 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
1531 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
1532 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
1533 |
|
|
//// later version. ////
|
1534 |
|
|
//// ////
|
1535 |
|
|
//// This source is distributed in the hope that it will be ////
|
1536 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
1537 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
1538 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
1539 |
|
|
//// details. ////
|
1540 |
|
|
//// ////
|
1541 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
1542 |
|
|
//// Public License along with this source; if not, download it ////
|
1543 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
1544 |
|
|
//// ////
|
1545 |
|
|
//////////////////////////////////////////////////////////////////////
|
1546 |
|
|
//
|
1547 |
|
|
// CVS Revision History
|
1548 |
|
|
//
|
1549 |
|
|
// $Log: uart_tfifo.v,v $
|
1550 |
|
|
// Revision 1.2 2002/07/29 21:16:18 gorban
|
1551 |
|
|
// The uart_defines.v file is included again in sources.
|
1552 |
|
|
//
|
1553 |
|
|
// Revision 1.1 2002/07/22 23:02:23 gorban
|
1554 |
|
|
// Bug Fixes:
|
1555 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
1556 |
|
|
// Problem reported by Kenny.Tung.
|
1557 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
1558 |
|
|
//
|
1559 |
|
|
// Improvements:
|
1560 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
1561 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
1562 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
1563 |
|
|
//
|
1564 |
|
|
// * Added optional baudrate output (baud_o).
|
1565 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
1566 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
1567 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
1568 |
|
|
//
|
1569 |
|
|
// Revision 1.16 2001/12/20 13:25:46 mohor
|
1570 |
|
|
// rx push changed to be only one cycle wide.
|
1571 |
|
|
//
|
1572 |
|
|
// Revision 1.15 2001/12/18 09:01:07 mohor
|
1573 |
|
|
// Bug that was entered in the last update fixed (rx state machine).
|
1574 |
|
|
//
|
1575 |
|
|
// Revision 1.14 2001/12/17 14:46:48 mohor
|
1576 |
|
|
// overrun signal was moved to separate block because many sequential lsr
|
1577 |
|
|
// reads were preventing data from being written to rx fifo.
|
1578 |
|
|
// underrun signal was not used and was removed from the project.
|
1579 |
|
|
//
|
1580 |
|
|
// Revision 1.13 2001/11/26 21:38:54 gorban
|
1581 |
|
|
// Lots of fixes:
|
1582 |
|
|
// Break condition wasn't handled correctly at all.
|
1583 |
|
|
// LSR bits could lose their values.
|
1584 |
|
|
// LSR value after reset was wrong.
|
1585 |
|
|
// Timing of THRE interrupt signal corrected.
|
1586 |
|
|
// LSR bit 0 timing corrected.
|
1587 |
|
|
//
|
1588 |
|
|
// Revision 1.12 2001/11/08 14:54:23 mohor
|
1589 |
|
|
// Comments in Slovene language deleted, few small fixes for better work of
|
1590 |
|
|
// old tools. IRQs need to be fix.
|
1591 |
|
|
//
|
1592 |
|
|
// Revision 1.11 2001/11/07 17:51:52 gorban
|
1593 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
1594 |
|
|
// Many bugs hopefully squashed.
|
1595 |
|
|
//
|
1596 |
|
|
// Revision 1.10 2001/10/20 09:58:40 gorban
|
1597 |
|
|
// Small synopsis fixes
|
1598 |
|
|
//
|
1599 |
|
|
// Revision 1.9 2001/08/24 21:01:12 mohor
|
1600 |
|
|
// Things connected to parity changed.
|
1601 |
|
|
// Clock devider changed.
|
1602 |
|
|
//
|
1603 |
|
|
// Revision 1.8 2001/08/24 08:48:10 mohor
|
1604 |
|
|
// FIFO was not cleared after the data was read bug fixed.
|
1605 |
|
|
//
|
1606 |
|
|
// Revision 1.7 2001/08/23 16:05:05 mohor
|
1607 |
|
|
// Stop bit bug fixed.
|
1608 |
|
|
// Parity bug fixed.
|
1609 |
|
|
// WISHBONE read cycle bug fixed,
|
1610 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
1611 |
|
|
// PE indicator (Parity Error) bug fixed.
|
1612 |
|
|
// Register read bug fixed.
|
1613 |
|
|
//
|
1614 |
|
|
// Revision 1.3 2001/05/31 20:08:01 gorban
|
1615 |
|
|
// FIFO changes and other corrections.
|
1616 |
|
|
//
|
1617 |
|
|
// Revision 1.3 2001/05/27 17:37:48 gorban
|
1618 |
|
|
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
|
1619 |
|
|
//
|
1620 |
|
|
// Revision 1.2 2001/05/17 18:34:18 gorban
|
1621 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
1622 |
|
|
//
|
1623 |
|
|
// Revision 1.0 2001-05-17 21:27:12+02 jacob
|
1624 |
|
|
// Initial revision
|
1625 |
|
|
//
|
1626 |
|
|
//
|
1627 |
|
|
|
1628 |
|
|
// synopsys translate_off
|
1629 |
|
|
`include "timescale.v"
|
1630 |
|
|
// synopsys translate_on
|
1631 |
|
|
|
1632 |
|
|
`include "uart_defines.v"
|
1633 |
|
|
|
1634 |
|
|
module uart_tfifo (clk,
|
1635 |
|
|
wb_rst_i, data_in, data_out,
|
1636 |
|
|
// Control signals
|
1637 |
|
|
push, // push strobe, active high
|
1638 |
|
|
pop, // pop strobe, active high
|
1639 |
|
|
// status signals
|
1640 |
|
|
overrun,
|
1641 |
|
|
count,
|
1642 |
|
|
fifo_reset,
|
1643 |
|
|
reset_status
|
1644 |
|
|
);
|
1645 |
|
|
|
1646 |
|
|
|
1647 |
|
|
// FIFO parameters
|
1648 |
|
|
parameter fifo_width = `UART_FIFO_WIDTH;
|
1649 |
|
|
parameter fifo_depth = `UART_FIFO_DEPTH;
|
1650 |
|
|
parameter fifo_pointer_w = `UART_FIFO_POINTER_W;
|
1651 |
|
|
parameter fifo_counter_w = `UART_FIFO_COUNTER_W;
|
1652 |
|
|
|
1653 |
|
|
input clk;
|
1654 |
|
|
input wb_rst_i;
|
1655 |
|
|
input push;
|
1656 |
|
|
input pop;
|
1657 |
|
|
input [fifo_width-1:0] data_in;
|
1658 |
|
|
input fifo_reset;
|
1659 |
|
|
input reset_status;
|
1660 |
|
|
|
1661 |
|
|
output [fifo_width-1:0] data_out;
|
1662 |
|
|
output overrun;
|
1663 |
|
|
output [fifo_counter_w-1:0] count;
|
1664 |
|
|
|
1665 |
|
|
wire [fifo_width-1:0] data_out;
|
1666 |
|
|
|
1667 |
|
|
// FIFO pointers
|
1668 |
|
|
reg [fifo_pointer_w-1:0] top;
|
1669 |
|
|
reg [fifo_pointer_w-1:0] bottom;
|
1670 |
|
|
|
1671 |
|
|
reg [fifo_counter_w-1:0] count;
|
1672 |
|
|
reg overrun;
|
1673 |
|
|
wire [fifo_pointer_w-1:0] top_plus_1 = top + 1'b1;
|
1674 |
|
|
|
1675 |
|
|
raminfr #(fifo_pointer_w,fifo_width,fifo_depth) tfifo
|
1676 |
|
|
(.clk(clk),
|
1677 |
|
|
.we(push),
|
1678 |
|
|
.a(top),
|
1679 |
|
|
.dpra(bottom),
|
1680 |
|
|
.di(data_in),
|
1681 |
|
|
.dpo(data_out)
|
1682 |
|
|
);
|
1683 |
|
|
|
1684 |
|
|
|
1685 |
|
|
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
|
1686 |
|
|
begin
|
1687 |
|
|
if (wb_rst_i)
|
1688 |
|
|
begin
|
1689 |
|
|
top <= #1 0;
|
1690 |
|
|
bottom <= #1 1'b0;
|
1691 |
|
|
count <= #1 0;
|
1692 |
|
|
end
|
1693 |
|
|
else
|
1694 |
|
|
if (fifo_reset) begin
|
1695 |
|
|
top <= #1 0;
|
1696 |
|
|
bottom <= #1 1'b0;
|
1697 |
|
|
count <= #1 0;
|
1698 |
|
|
end
|
1699 |
|
|
else
|
1700 |
|
|
begin
|
1701 |
|
|
case ({push, pop})
|
1702 |
|
|
2'b10 : if (count<fifo_depth) // overrun condition
|
1703 |
|
|
begin
|
1704 |
|
|
top <= #1 top_plus_1;
|
1705 |
|
|
count <= #1 count + 1'b1;
|
1706 |
|
|
end
|
1707 |
|
|
2'b01 : if(count>0)
|
1708 |
|
|
begin
|
1709 |
|
|
bottom <= #1 bottom + 1'b1;
|
1710 |
|
|
count <= #1 count - 1'b1;
|
1711 |
|
|
end
|
1712 |
|
|
2'b11 : begin
|
1713 |
|
|
bottom <= #1 bottom + 1'b1;
|
1714 |
|
|
top <= #1 top_plus_1;
|
1715 |
|
|
end
|
1716 |
|
|
default: ;
|
1717 |
|
|
endcase
|
1718 |
|
|
end
|
1719 |
|
|
end // always
|
1720 |
|
|
|
1721 |
|
|
always @(posedge clk or posedge wb_rst_i) // synchronous FIFO
|
1722 |
|
|
begin
|
1723 |
|
|
if (wb_rst_i)
|
1724 |
|
|
overrun <= #1 1'b0;
|
1725 |
|
|
else
|
1726 |
|
|
if(fifo_reset | reset_status)
|
1727 |
|
|
overrun <= #1 1'b0;
|
1728 |
|
|
else
|
1729 |
|
|
if(push & (count==fifo_depth))
|
1730 |
|
|
overrun <= #1 1'b1;
|
1731 |
|
|
end // always
|
1732 |
|
|
|
1733 |
|
|
endmodule
|
1734 |
|
|
//////////////////////////////////////////////////////////////////////
|
1735 |
|
|
//// ////
|
1736 |
|
|
//// uart_receiver.v ////
|
1737 |
|
|
//// ////
|
1738 |
|
|
//// ////
|
1739 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
1740 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
1741 |
|
|
//// ////
|
1742 |
|
|
//// Documentation related to this project: ////
|
1743 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
1744 |
|
|
//// ////
|
1745 |
|
|
//// Projects compatibility: ////
|
1746 |
|
|
//// - WISHBONE ////
|
1747 |
|
|
//// RS232 Protocol ////
|
1748 |
|
|
//// 16550D uart (mostly supported) ////
|
1749 |
|
|
//// ////
|
1750 |
|
|
//// Overview (main Features): ////
|
1751 |
|
|
//// UART core receiver logic ////
|
1752 |
|
|
//// ////
|
1753 |
|
|
//// Known problems (limits): ////
|
1754 |
|
|
//// None known ////
|
1755 |
|
|
//// ////
|
1756 |
|
|
//// To Do: ////
|
1757 |
|
|
//// Thourough testing. ////
|
1758 |
|
|
//// ////
|
1759 |
|
|
//// Author(s): ////
|
1760 |
|
|
//// - gorban@opencores.org ////
|
1761 |
|
|
//// - Jacob Gorban ////
|
1762 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
1763 |
|
|
//// ////
|
1764 |
|
|
//// Created: 2001/05/12 ////
|
1765 |
|
|
//// Last Updated: 2001/05/17 ////
|
1766 |
|
|
//// (See log for the revision history) ////
|
1767 |
|
|
//// ////
|
1768 |
|
|
//// ////
|
1769 |
|
|
//////////////////////////////////////////////////////////////////////
|
1770 |
|
|
//// ////
|
1771 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
1772 |
|
|
//// ////
|
1773 |
|
|
//// This source file may be used and distributed without ////
|
1774 |
|
|
//// restriction provided that this copyright statement is not ////
|
1775 |
|
|
//// removed from the file and that any derivative work contains ////
|
1776 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
1777 |
|
|
//// ////
|
1778 |
|
|
//// This source file is free software; you can redistribute it ////
|
1779 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
1780 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
1781 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
1782 |
|
|
//// later version. ////
|
1783 |
|
|
//// ////
|
1784 |
|
|
//// This source is distributed in the hope that it will be ////
|
1785 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
1786 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
1787 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
1788 |
|
|
//// details. ////
|
1789 |
|
|
//// ////
|
1790 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
1791 |
|
|
//// Public License along with this source; if not, download it ////
|
1792 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
1793 |
|
|
//// ////
|
1794 |
|
|
//////////////////////////////////////////////////////////////////////
|
1795 |
|
|
//
|
1796 |
|
|
// CVS Revision History
|
1797 |
|
|
//
|
1798 |
|
|
// $Log: uart_receiver.v,v $
|
1799 |
|
|
// Revision 1.31 2004/06/18 14:46:15 tadejm
|
1800 |
|
|
// Brandl Tobias repaired a bug regarding frame error in receiver when brake is received.
|
1801 |
|
|
//
|
1802 |
|
|
// Revision 1.29 2002/07/29 21:16:18 gorban
|
1803 |
|
|
// The uart_defines.v file is included again in sources.
|
1804 |
|
|
//
|
1805 |
|
|
// Revision 1.28 2002/07/22 23:02:23 gorban
|
1806 |
|
|
// Bug Fixes:
|
1807 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
1808 |
|
|
// Problem reported by Kenny.Tung.
|
1809 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
1810 |
|
|
//
|
1811 |
|
|
// Improvements:
|
1812 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
1813 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
1814 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
1815 |
|
|
//
|
1816 |
|
|
// * Added optional baudrate output (baud_o).
|
1817 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
1818 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
1819 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
1820 |
|
|
//
|
1821 |
|
|
// Revision 1.27 2001/12/30 20:39:13 mohor
|
1822 |
|
|
// More than one character was stored in case of break. End of the break
|
1823 |
|
|
// was not detected correctly.
|
1824 |
|
|
//
|
1825 |
|
|
// Revision 1.26 2001/12/20 13:28:27 mohor
|
1826 |
|
|
// Missing declaration of rf_push_q fixed.
|
1827 |
|
|
//
|
1828 |
|
|
// Revision 1.25 2001/12/20 13:25:46 mohor
|
1829 |
|
|
// rx push changed to be only one cycle wide.
|
1830 |
|
|
//
|
1831 |
|
|
// Revision 1.24 2001/12/19 08:03:34 mohor
|
1832 |
|
|
// Warnings cleared.
|
1833 |
|
|
//
|
1834 |
|
|
// Revision 1.23 2001/12/19 07:33:54 mohor
|
1835 |
|
|
// Synplicity was having troubles with the comment.
|
1836 |
|
|
//
|
1837 |
|
|
// Revision 1.22 2001/12/17 14:46:48 mohor
|
1838 |
|
|
// overrun signal was moved to separate block because many sequential lsr
|
1839 |
|
|
// reads were preventing data from being written to rx fifo.
|
1840 |
|
|
// underrun signal was not used and was removed from the project.
|
1841 |
|
|
//
|
1842 |
|
|
// Revision 1.21 2001/12/13 10:31:16 mohor
|
1843 |
|
|
// timeout irq must be set regardless of the rda irq (rda irq does not reset the
|
1844 |
|
|
// timeout counter).
|
1845 |
|
|
//
|
1846 |
|
|
// Revision 1.20 2001/12/10 19:52:05 gorban
|
1847 |
|
|
// Igor fixed break condition bugs
|
1848 |
|
|
//
|
1849 |
|
|
// Revision 1.19 2001/12/06 14:51:04 gorban
|
1850 |
|
|
// Bug in LSR[0] is fixed.
|
1851 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
1852 |
|
|
//
|
1853 |
|
|
// Revision 1.18 2001/12/03 21:44:29 gorban
|
1854 |
|
|
// Updated specification documentation.
|
1855 |
|
|
// Added full 32-bit data bus interface, now as default.
|
1856 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
1857 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
1858 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
1859 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
1860 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
1861 |
|
|
//
|
1862 |
|
|
// Revision 1.17 2001/11/28 19:36:39 gorban
|
1863 |
|
|
// Fixed: timeout and break didn't pay attention to current data format when counting time
|
1864 |
|
|
//
|
1865 |
|
|
// Revision 1.16 2001/11/27 22:17:09 gorban
|
1866 |
|
|
// Fixed bug that prevented synthesis in uart_receiver.v
|
1867 |
|
|
//
|
1868 |
|
|
// Revision 1.15 2001/11/26 21:38:54 gorban
|
1869 |
|
|
// Lots of fixes:
|
1870 |
|
|
// Break condition wasn't handled correctly at all.
|
1871 |
|
|
// LSR bits could lose their values.
|
1872 |
|
|
// LSR value after reset was wrong.
|
1873 |
|
|
// Timing of THRE interrupt signal corrected.
|
1874 |
|
|
// LSR bit 0 timing corrected.
|
1875 |
|
|
//
|
1876 |
|
|
// Revision 1.14 2001/11/10 12:43:21 gorban
|
1877 |
|
|
// Logic Synthesis bugs fixed. Some other minor changes
|
1878 |
|
|
//
|
1879 |
|
|
// Revision 1.13 2001/11/08 14:54:23 mohor
|
1880 |
|
|
// Comments in Slovene language deleted, few small fixes for better work of
|
1881 |
|
|
// old tools. IRQs need to be fix.
|
1882 |
|
|
//
|
1883 |
|
|
// Revision 1.12 2001/11/07 17:51:52 gorban
|
1884 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
1885 |
|
|
// Many bugs hopefully squashed.
|
1886 |
|
|
//
|
1887 |
|
|
// Revision 1.11 2001/10/31 15:19:22 gorban
|
1888 |
|
|
// Fixes to break and timeout conditions
|
1889 |
|
|
//
|
1890 |
|
|
// Revision 1.10 2001/10/20 09:58:40 gorban
|
1891 |
|
|
// Small synopsis fixes
|
1892 |
|
|
//
|
1893 |
|
|
// Revision 1.9 2001/08/24 21:01:12 mohor
|
1894 |
|
|
// Things connected to parity changed.
|
1895 |
|
|
// Clock devider changed.
|
1896 |
|
|
//
|
1897 |
|
|
// Revision 1.8 2001/08/23 16:05:05 mohor
|
1898 |
|
|
// Stop bit bug fixed.
|
1899 |
|
|
// Parity bug fixed.
|
1900 |
|
|
// WISHBONE read cycle bug fixed,
|
1901 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
1902 |
|
|
// PE indicator (Parity Error) bug fixed.
|
1903 |
|
|
// Register read bug fixed.
|
1904 |
|
|
//
|
1905 |
|
|
// Revision 1.6 2001/06/23 11:21:48 gorban
|
1906 |
|
|
// DL made 16-bit long. Fixed transmission/reception bugs.
|
1907 |
|
|
//
|
1908 |
|
|
// Revision 1.5 2001/06/02 14:28:14 gorban
|
1909 |
|
|
// Fixed receiver and transmitter. Major bug fixed.
|
1910 |
|
|
//
|
1911 |
|
|
// Revision 1.4 2001/05/31 20:08:01 gorban
|
1912 |
|
|
// FIFO changes and other corrections.
|
1913 |
|
|
//
|
1914 |
|
|
// Revision 1.3 2001/05/27 17:37:49 gorban
|
1915 |
|
|
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
|
1916 |
|
|
//
|
1917 |
|
|
// Revision 1.2 2001/05/21 19:12:02 gorban
|
1918 |
|
|
// Corrected some Linter messages.
|
1919 |
|
|
//
|
1920 |
|
|
// Revision 1.1 2001/05/17 18:34:18 gorban
|
1921 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
1922 |
|
|
//
|
1923 |
|
|
// Revision 1.0 2001-05-17 21:27:11+02 jacob
|
1924 |
|
|
// Initial revision
|
1925 |
|
|
//
|
1926 |
|
|
//
|
1927 |
|
|
|
1928 |
|
|
// synopsys translate_off
|
1929 |
|
|
`include "timescale.v"
|
1930 |
|
|
// synopsys translate_on
|
1931 |
|
|
|
1932 |
|
|
`include "uart_defines.v"
|
1933 |
|
|
|
1934 |
|
|
module uart_receiver (clk, wb_rst_i, lcr, rf_pop, srx_pad_i, enable,
|
1935 |
|
|
counter_t, rf_count, rf_data_out, rf_error_bit, rf_overrun, rx_reset, lsr_mask, rstate, rf_push_pulse);
|
1936 |
|
|
|
1937 |
|
|
input clk;
|
1938 |
|
|
input wb_rst_i;
|
1939 |
|
|
input [7:0] lcr;
|
1940 |
|
|
input rf_pop;
|
1941 |
|
|
input srx_pad_i;
|
1942 |
|
|
input enable;
|
1943 |
|
|
input rx_reset;
|
1944 |
|
|
input lsr_mask;
|
1945 |
|
|
|
1946 |
|
|
output [9:0] counter_t;
|
1947 |
|
|
output [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
1948 |
|
|
output [`UART_FIFO_REC_WIDTH-1:0] rf_data_out;
|
1949 |
|
|
output rf_overrun;
|
1950 |
|
|
output rf_error_bit;
|
1951 |
|
|
output [3:0] rstate;
|
1952 |
|
|
output rf_push_pulse;
|
1953 |
|
|
|
1954 |
|
|
reg [3:0] rstate;
|
1955 |
|
|
reg [3:0] rcounter16;
|
1956 |
|
|
reg [2:0] rbit_counter;
|
1957 |
|
|
reg [7:0] rshift; // receiver shift register
|
1958 |
|
|
reg rparity; // received parity
|
1959 |
|
|
reg rparity_error;
|
1960 |
|
|
reg rframing_error; // framing error flag
|
1961 |
|
|
reg rbit_in;
|
1962 |
|
|
reg rparity_xor;
|
1963 |
|
|
reg [7:0] counter_b; // counts the 0 (low) signals
|
1964 |
|
|
reg rf_push_q;
|
1965 |
|
|
|
1966 |
|
|
// RX FIFO signals
|
1967 |
|
|
reg [`UART_FIFO_REC_WIDTH-1:0] rf_data_in;
|
1968 |
|
|
wire [`UART_FIFO_REC_WIDTH-1:0] rf_data_out;
|
1969 |
|
|
wire rf_push_pulse;
|
1970 |
|
|
reg rf_push;
|
1971 |
|
|
wire rf_pop;
|
1972 |
|
|
wire rf_overrun;
|
1973 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
1974 |
|
|
wire rf_error_bit; // an error (parity or framing) is inside the fifo
|
1975 |
|
|
wire break_error = (counter_b == 0);
|
1976 |
|
|
|
1977 |
|
|
// RX FIFO instance
|
1978 |
|
|
uart_rfifo #(`UART_FIFO_REC_WIDTH) fifo_rx(
|
1979 |
|
|
.clk( clk ),
|
1980 |
|
|
.wb_rst_i( wb_rst_i ),
|
1981 |
|
|
.data_in( rf_data_in ),
|
1982 |
|
|
.data_out( rf_data_out ),
|
1983 |
|
|
.push( rf_push_pulse ),
|
1984 |
|
|
.pop( rf_pop ),
|
1985 |
|
|
.overrun( rf_overrun ),
|
1986 |
|
|
.count( rf_count ),
|
1987 |
|
|
.error_bit( rf_error_bit ),
|
1988 |
|
|
.fifo_reset( rx_reset ),
|
1989 |
|
|
.reset_status(lsr_mask)
|
1990 |
|
|
);
|
1991 |
|
|
|
1992 |
|
|
wire rcounter16_eq_7 = (rcounter16 == 4'd7);
|
1993 |
|
|
wire rcounter16_eq_0 = (rcounter16 == 4'd0);
|
1994 |
|
|
wire rcounter16_eq_1 = (rcounter16 == 4'd1);
|
1995 |
|
|
|
1996 |
|
|
wire [3:0] rcounter16_minus_1 = rcounter16 - 1'b1;
|
1997 |
|
|
|
1998 |
|
|
parameter sr_idle = 4'd0;
|
1999 |
|
|
parameter sr_rec_start = 4'd1;
|
2000 |
|
|
parameter sr_rec_bit = 4'd2;
|
2001 |
|
|
parameter sr_rec_parity = 4'd3;
|
2002 |
|
|
parameter sr_rec_stop = 4'd4;
|
2003 |
|
|
parameter sr_check_parity = 4'd5;
|
2004 |
|
|
parameter sr_rec_prepare = 4'd6;
|
2005 |
|
|
parameter sr_end_bit = 4'd7;
|
2006 |
|
|
parameter sr_ca_lc_parity = 4'd8;
|
2007 |
|
|
parameter sr_wait1 = 4'd9;
|
2008 |
|
|
parameter sr_push = 4'd10;
|
2009 |
|
|
|
2010 |
|
|
|
2011 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2012 |
|
|
begin
|
2013 |
|
|
if (wb_rst_i)
|
2014 |
|
|
begin
|
2015 |
|
|
rstate <= #1 sr_idle;
|
2016 |
|
|
rbit_in <= #1 1'b0;
|
2017 |
|
|
rcounter16 <= #1 0;
|
2018 |
|
|
rbit_counter <= #1 0;
|
2019 |
|
|
rparity_xor <= #1 1'b0;
|
2020 |
|
|
rframing_error <= #1 1'b0;
|
2021 |
|
|
rparity_error <= #1 1'b0;
|
2022 |
|
|
rparity <= #1 1'b0;
|
2023 |
|
|
rshift <= #1 0;
|
2024 |
|
|
rf_push <= #1 1'b0;
|
2025 |
|
|
rf_data_in <= #1 0;
|
2026 |
|
|
end
|
2027 |
|
|
else
|
2028 |
|
|
if (enable)
|
2029 |
|
|
begin
|
2030 |
|
|
case (rstate)
|
2031 |
|
|
sr_idle : begin
|
2032 |
|
|
rf_push <= #1 1'b0;
|
2033 |
|
|
rf_data_in <= #1 0;
|
2034 |
|
|
rcounter16 <= #1 4'b1110;
|
2035 |
|
|
if (srx_pad_i==1'b0 & ~break_error) // detected a pulse (start bit?)
|
2036 |
|
|
begin
|
2037 |
|
|
rstate <= #1 sr_rec_start;
|
2038 |
|
|
end
|
2039 |
|
|
end
|
2040 |
|
|
sr_rec_start : begin
|
2041 |
|
|
rf_push <= #1 1'b0;
|
2042 |
|
|
if (rcounter16_eq_7) // check the pulse
|
2043 |
|
|
if (srx_pad_i==1'b1) // no start bit
|
2044 |
|
|
rstate <= #1 sr_idle;
|
2045 |
|
|
else // start bit detected
|
2046 |
|
|
rstate <= #1 sr_rec_prepare;
|
2047 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2048 |
|
|
end
|
2049 |
|
|
sr_rec_prepare:begin
|
2050 |
|
|
case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word
|
2051 |
|
|
2'b00 : rbit_counter <= #1 3'b100;
|
2052 |
|
|
2'b01 : rbit_counter <= #1 3'b101;
|
2053 |
|
|
2'b10 : rbit_counter <= #1 3'b110;
|
2054 |
|
|
2'b11 : rbit_counter <= #1 3'b111;
|
2055 |
|
|
endcase
|
2056 |
|
|
if (rcounter16_eq_0)
|
2057 |
|
|
begin
|
2058 |
|
|
rstate <= #1 sr_rec_bit;
|
2059 |
|
|
rcounter16 <= #1 4'b1110;
|
2060 |
|
|
rshift <= #1 0;
|
2061 |
|
|
end
|
2062 |
|
|
else
|
2063 |
|
|
rstate <= #1 sr_rec_prepare;
|
2064 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2065 |
|
|
end
|
2066 |
|
|
sr_rec_bit : begin
|
2067 |
|
|
if (rcounter16_eq_0)
|
2068 |
|
|
rstate <= #1 sr_end_bit;
|
2069 |
|
|
if (rcounter16_eq_7) // read the bit
|
2070 |
|
|
case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word
|
2071 |
|
|
2'b00 : rshift[4:0] <= #1 {srx_pad_i, rshift[4:1]};
|
2072 |
|
|
2'b01 : rshift[5:0] <= #1 {srx_pad_i, rshift[5:1]};
|
2073 |
|
|
2'b10 : rshift[6:0] <= #1 {srx_pad_i, rshift[6:1]};
|
2074 |
|
|
2'b11 : rshift[7:0] <= #1 {srx_pad_i, rshift[7:1]};
|
2075 |
|
|
endcase
|
2076 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2077 |
|
|
end
|
2078 |
|
|
sr_end_bit : begin
|
2079 |
|
|
if (rbit_counter==3'b0) // no more bits in word
|
2080 |
|
|
if (lcr[`UART_LC_PE]) // choose state based on parity
|
2081 |
|
|
rstate <= #1 sr_rec_parity;
|
2082 |
|
|
else
|
2083 |
|
|
begin
|
2084 |
|
|
rstate <= #1 sr_rec_stop;
|
2085 |
|
|
rparity_error <= #1 1'b0; // no parity - no error :)
|
2086 |
|
|
end
|
2087 |
|
|
else // else we have more bits to read
|
2088 |
|
|
begin
|
2089 |
|
|
rstate <= #1 sr_rec_bit;
|
2090 |
|
|
rbit_counter <= #1 rbit_counter - 1'b1;
|
2091 |
|
|
end
|
2092 |
|
|
rcounter16 <= #1 4'b1110;
|
2093 |
|
|
end
|
2094 |
|
|
sr_rec_parity: begin
|
2095 |
|
|
if (rcounter16_eq_7) // read the parity
|
2096 |
|
|
begin
|
2097 |
|
|
rparity <= #1 srx_pad_i;
|
2098 |
|
|
rstate <= #1 sr_ca_lc_parity;
|
2099 |
|
|
end
|
2100 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2101 |
|
|
end
|
2102 |
|
|
sr_ca_lc_parity : begin // rcounter equals 6
|
2103 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2104 |
|
|
rparity_xor <= #1 ^{rshift,rparity}; // calculate parity on all incoming data
|
2105 |
|
|
rstate <= #1 sr_check_parity;
|
2106 |
|
|
end
|
2107 |
|
|
sr_check_parity: begin // rcounter equals 5
|
2108 |
|
|
case ({lcr[`UART_LC_EP],lcr[`UART_LC_SP]})
|
2109 |
|
|
2'b00: rparity_error <= #1 rparity_xor == 0; // no error if parity 1
|
2110 |
|
|
2'b01: rparity_error <= #1 ~rparity; // parity should sticked to 1
|
2111 |
|
|
2'b10: rparity_error <= #1 rparity_xor == 1; // error if parity is odd
|
2112 |
|
|
2'b11: rparity_error <= #1 rparity; // parity should be sticked to 0
|
2113 |
|
|
endcase
|
2114 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2115 |
|
|
rstate <= #1 sr_wait1;
|
2116 |
|
|
end
|
2117 |
|
|
sr_wait1 : if (rcounter16_eq_0)
|
2118 |
|
|
begin
|
2119 |
|
|
rstate <= #1 sr_rec_stop;
|
2120 |
|
|
rcounter16 <= #1 4'b1110;
|
2121 |
|
|
end
|
2122 |
|
|
else
|
2123 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2124 |
|
|
sr_rec_stop : begin
|
2125 |
|
|
if (rcounter16_eq_7) // read the parity
|
2126 |
|
|
begin
|
2127 |
|
|
rframing_error <= #1 !srx_pad_i; // no framing error if input is 1 (stop bit)
|
2128 |
|
|
rstate <= #1 sr_push;
|
2129 |
|
|
end
|
2130 |
|
|
rcounter16 <= #1 rcounter16_minus_1;
|
2131 |
|
|
end
|
2132 |
|
|
sr_push : begin
|
2133 |
|
|
///////////////////////////////////////
|
2134 |
|
|
// $display($time, ": received: %b", rf_data_in);
|
2135 |
|
|
if(srx_pad_i | break_error)
|
2136 |
|
|
begin
|
2137 |
|
|
if(break_error)
|
2138 |
|
|
rf_data_in <= #1 {8'b0, 3'b100}; // break input (empty character) to receiver FIFO
|
2139 |
|
|
else
|
2140 |
|
|
rf_data_in <= #1 {rshift, 1'b0, rparity_error, rframing_error};
|
2141 |
|
|
rf_push <= #1 1'b1;
|
2142 |
|
|
rstate <= #1 sr_idle;
|
2143 |
|
|
end
|
2144 |
|
|
else if(~rframing_error) // There's always a framing before break_error -> wait for break or srx_pad_i
|
2145 |
|
|
begin
|
2146 |
|
|
rf_data_in <= #1 {rshift, 1'b0, rparity_error, rframing_error};
|
2147 |
|
|
rf_push <= #1 1'b1;
|
2148 |
|
|
rcounter16 <= #1 4'b1110;
|
2149 |
|
|
rstate <= #1 sr_rec_start;
|
2150 |
|
|
end
|
2151 |
|
|
|
2152 |
|
|
end
|
2153 |
|
|
default : rstate <= #1 sr_idle;
|
2154 |
|
|
endcase
|
2155 |
|
|
end // if (enable)
|
2156 |
|
|
end // always of receiver
|
2157 |
|
|
|
2158 |
|
|
always @ (posedge clk or posedge wb_rst_i)
|
2159 |
|
|
begin
|
2160 |
|
|
if(wb_rst_i)
|
2161 |
|
|
rf_push_q <= 0;
|
2162 |
|
|
else
|
2163 |
|
|
rf_push_q <= #1 rf_push;
|
2164 |
|
|
end
|
2165 |
|
|
|
2166 |
|
|
assign rf_push_pulse = rf_push & ~rf_push_q;
|
2167 |
|
|
|
2168 |
|
|
|
2169 |
|
|
//
|
2170 |
|
|
// Break condition detection.
|
2171 |
|
|
// Works in conjuction with the receiver state machine
|
2172 |
|
|
|
2173 |
|
|
reg [9:0] toc_value; // value to be set to timeout counter
|
2174 |
|
|
|
2175 |
|
|
always @(lcr)
|
2176 |
|
|
case (lcr[3:0])
|
2177 |
|
|
4'b0000 : toc_value = 447; // 7 bits
|
2178 |
|
|
4'b0100 : toc_value = 479; // 7.5 bits
|
2179 |
|
|
4'b0001, 4'b1000 : toc_value = 511; // 8 bits
|
2180 |
|
|
4'b1100 : toc_value = 543; // 8.5 bits
|
2181 |
|
|
4'b0010, 4'b0101, 4'b1001 : toc_value = 575; // 9 bits
|
2182 |
|
|
4'b0011, 4'b0110, 4'b1010, 4'b1101 : toc_value = 639; // 10 bits
|
2183 |
|
|
4'b0111, 4'b1011, 4'b1110 : toc_value = 703; // 11 bits
|
2184 |
|
|
4'b1111 : toc_value = 767; // 12 bits
|
2185 |
|
|
endcase // case(lcr[3:0])
|
2186 |
|
|
|
2187 |
|
|
wire [7:0] brc_value; // value to be set to break counter
|
2188 |
|
|
assign brc_value = toc_value[9:2]; // the same as timeout but 1 insead of 4 character times
|
2189 |
|
|
|
2190 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2191 |
|
|
begin
|
2192 |
|
|
if (wb_rst_i)
|
2193 |
|
|
counter_b <= #1 8'd159;
|
2194 |
|
|
else
|
2195 |
|
|
if (srx_pad_i)
|
2196 |
|
|
counter_b <= #1 brc_value; // character time length - 1
|
2197 |
|
|
else
|
2198 |
|
|
if(enable & counter_b != 8'b0) // only work on enable times break not reached.
|
2199 |
|
|
counter_b <= #1 counter_b - 1; // decrement break counter
|
2200 |
|
|
end // always of break condition detection
|
2201 |
|
|
|
2202 |
|
|
///
|
2203 |
|
|
/// Timeout condition detection
|
2204 |
|
|
reg [9:0] counter_t; // counts the timeout condition clocks
|
2205 |
|
|
|
2206 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2207 |
|
|
begin
|
2208 |
|
|
if (wb_rst_i)
|
2209 |
|
|
counter_t <= #1 10'd639; // 10 bits for the default 8N1
|
2210 |
|
|
else
|
2211 |
|
|
if(rf_push_pulse || rf_pop || rf_count == 0) // counter is reset when RX FIFO is empty, accessed or above trigger level
|
2212 |
|
|
counter_t <= #1 toc_value;
|
2213 |
|
|
else
|
2214 |
|
|
if (enable && counter_t != 10'b0) // we don't want to underflow
|
2215 |
|
|
counter_t <= #1 counter_t - 1;
|
2216 |
|
|
end
|
2217 |
|
|
|
2218 |
|
|
endmodule
|
2219 |
|
|
//////////////////////////////////////////////////////////////////////
|
2220 |
|
|
//// ////
|
2221 |
|
|
//// uart_transmitter.v ////
|
2222 |
|
|
//// ////
|
2223 |
|
|
//// ////
|
2224 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
2225 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
2226 |
|
|
//// ////
|
2227 |
|
|
//// Documentation related to this project: ////
|
2228 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
2229 |
|
|
//// ////
|
2230 |
|
|
//// Projects compatibility: ////
|
2231 |
|
|
//// - WISHBONE ////
|
2232 |
|
|
//// RS232 Protocol ////
|
2233 |
|
|
//// 16550D uart (mostly supported) ////
|
2234 |
|
|
//// ////
|
2235 |
|
|
//// Overview (main Features): ////
|
2236 |
|
|
//// UART core transmitter logic ////
|
2237 |
|
|
//// ////
|
2238 |
|
|
//// Known problems (limits): ////
|
2239 |
|
|
//// None known ////
|
2240 |
|
|
//// ////
|
2241 |
|
|
//// To Do: ////
|
2242 |
|
|
//// Thourough testing. ////
|
2243 |
|
|
//// ////
|
2244 |
|
|
//// Author(s): ////
|
2245 |
|
|
//// - gorban@opencores.org ////
|
2246 |
|
|
//// - Jacob Gorban ////
|
2247 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
2248 |
|
|
//// ////
|
2249 |
|
|
//// Created: 2001/05/12 ////
|
2250 |
|
|
//// Last Updated: 2001/05/17 ////
|
2251 |
|
|
//// (See log for the revision history) ////
|
2252 |
|
|
//// ////
|
2253 |
|
|
//// ////
|
2254 |
|
|
//////////////////////////////////////////////////////////////////////
|
2255 |
|
|
//// ////
|
2256 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
2257 |
|
|
//// ////
|
2258 |
|
|
//// This source file may be used and distributed without ////
|
2259 |
|
|
//// restriction provided that this copyright statement is not ////
|
2260 |
|
|
//// removed from the file and that any derivative work contains ////
|
2261 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
2262 |
|
|
//// ////
|
2263 |
|
|
//// This source file is free software; you can redistribute it ////
|
2264 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
2265 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
2266 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
2267 |
|
|
//// later version. ////
|
2268 |
|
|
//// ////
|
2269 |
|
|
//// This source is distributed in the hope that it will be ////
|
2270 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
2271 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
2272 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
2273 |
|
|
//// details. ////
|
2274 |
|
|
//// ////
|
2275 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
2276 |
|
|
//// Public License along with this source; if not, download it ////
|
2277 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
2278 |
|
|
//// ////
|
2279 |
|
|
//////////////////////////////////////////////////////////////////////
|
2280 |
|
|
//
|
2281 |
|
|
// CVS Revision History
|
2282 |
|
|
//
|
2283 |
|
|
// $Log: uart_transmitter.v,v $
|
2284 |
|
|
// Revision 1.19 2002/07/29 21:16:18 gorban
|
2285 |
|
|
// The uart_defines.v file is included again in sources.
|
2286 |
|
|
//
|
2287 |
|
|
// Revision 1.18 2002/07/22 23:02:23 gorban
|
2288 |
|
|
// Bug Fixes:
|
2289 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
2290 |
|
|
// Problem reported by Kenny.Tung.
|
2291 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
2292 |
|
|
//
|
2293 |
|
|
// Improvements:
|
2294 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
2295 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
2296 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
2297 |
|
|
//
|
2298 |
|
|
// * Added optional baudrate output (baud_o).
|
2299 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
2300 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
2301 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
2302 |
|
|
//
|
2303 |
|
|
// Revision 1.16 2002/01/08 11:29:40 mohor
|
2304 |
|
|
// tf_pop was too wide. Now it is only 1 clk cycle width.
|
2305 |
|
|
//
|
2306 |
|
|
// Revision 1.15 2001/12/17 14:46:48 mohor
|
2307 |
|
|
// overrun signal was moved to separate block because many sequential lsr
|
2308 |
|
|
// reads were preventing data from being written to rx fifo.
|
2309 |
|
|
// underrun signal was not used and was removed from the project.
|
2310 |
|
|
//
|
2311 |
|
|
// Revision 1.14 2001/12/03 21:44:29 gorban
|
2312 |
|
|
// Updated specification documentation.
|
2313 |
|
|
// Added full 32-bit data bus interface, now as default.
|
2314 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
2315 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
2316 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
2317 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
2318 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
2319 |
|
|
//
|
2320 |
|
|
// Revision 1.13 2001/11/08 14:54:23 mohor
|
2321 |
|
|
// Comments in Slovene language deleted, few small fixes for better work of
|
2322 |
|
|
// old tools. IRQs need to be fix.
|
2323 |
|
|
//
|
2324 |
|
|
// Revision 1.12 2001/11/07 17:51:52 gorban
|
2325 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
2326 |
|
|
// Many bugs hopefully squashed.
|
2327 |
|
|
//
|
2328 |
|
|
// Revision 1.11 2001/10/29 17:00:46 gorban
|
2329 |
|
|
// fixed parity sending and tx_fifo resets over- and underrun
|
2330 |
|
|
//
|
2331 |
|
|
// Revision 1.10 2001/10/20 09:58:40 gorban
|
2332 |
|
|
// Small synopsis fixes
|
2333 |
|
|
//
|
2334 |
|
|
// Revision 1.9 2001/08/24 21:01:12 mohor
|
2335 |
|
|
// Things connected to parity changed.
|
2336 |
|
|
// Clock devider changed.
|
2337 |
|
|
//
|
2338 |
|
|
// Revision 1.8 2001/08/23 16:05:05 mohor
|
2339 |
|
|
// Stop bit bug fixed.
|
2340 |
|
|
// Parity bug fixed.
|
2341 |
|
|
// WISHBONE read cycle bug fixed,
|
2342 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
2343 |
|
|
// PE indicator (Parity Error) bug fixed.
|
2344 |
|
|
// Register read bug fixed.
|
2345 |
|
|
//
|
2346 |
|
|
// Revision 1.6 2001/06/23 11:21:48 gorban
|
2347 |
|
|
// DL made 16-bit long. Fixed transmission/reception bugs.
|
2348 |
|
|
//
|
2349 |
|
|
// Revision 1.5 2001/06/02 14:28:14 gorban
|
2350 |
|
|
// Fixed receiver and transmitter. Major bug fixed.
|
2351 |
|
|
//
|
2352 |
|
|
// Revision 1.4 2001/05/31 20:08:01 gorban
|
2353 |
|
|
// FIFO changes and other corrections.
|
2354 |
|
|
//
|
2355 |
|
|
// Revision 1.3 2001/05/27 17:37:49 gorban
|
2356 |
|
|
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
|
2357 |
|
|
//
|
2358 |
|
|
// Revision 1.2 2001/05/21 19:12:02 gorban
|
2359 |
|
|
// Corrected some Linter messages.
|
2360 |
|
|
//
|
2361 |
|
|
// Revision 1.1 2001/05/17 18:34:18 gorban
|
2362 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
2363 |
|
|
//
|
2364 |
|
|
// Revision 1.0 2001-05-17 21:27:12+02 jacob
|
2365 |
|
|
// Initial revision
|
2366 |
|
|
//
|
2367 |
|
|
//
|
2368 |
|
|
|
2369 |
|
|
// synopsys translate_off
|
2370 |
|
|
`include "timescale.v"
|
2371 |
|
|
// synopsys translate_on
|
2372 |
|
|
|
2373 |
|
|
`include "uart_defines.v"
|
2374 |
|
|
|
2375 |
|
|
module uart_transmitter (clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, stx_pad_o, tstate, tf_count, tx_reset, lsr_mask);
|
2376 |
|
|
|
2377 |
|
|
input clk;
|
2378 |
|
|
input wb_rst_i;
|
2379 |
|
|
input [7:0] lcr;
|
2380 |
|
|
input tf_push;
|
2381 |
|
|
input [7:0] wb_dat_i;
|
2382 |
|
|
input enable;
|
2383 |
|
|
input tx_reset;
|
2384 |
|
|
input lsr_mask; //reset of fifo
|
2385 |
|
|
output stx_pad_o;
|
2386 |
|
|
output [2:0] tstate;
|
2387 |
|
|
output [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
2388 |
|
|
|
2389 |
|
|
reg [2:0] tstate;
|
2390 |
|
|
reg [4:0] counter;
|
2391 |
|
|
reg [2:0] bit_counter; // counts the bits to be sent
|
2392 |
|
|
reg [6:0] shift_out; // output shift register
|
2393 |
|
|
reg stx_o_tmp;
|
2394 |
|
|
reg parity_xor; // parity of the word
|
2395 |
|
|
reg tf_pop;
|
2396 |
|
|
reg bit_out;
|
2397 |
|
|
|
2398 |
|
|
// TX FIFO instance
|
2399 |
|
|
//
|
2400 |
|
|
// Transmitter FIFO signals
|
2401 |
|
|
wire [`UART_FIFO_WIDTH-1:0] tf_data_in;
|
2402 |
|
|
wire [`UART_FIFO_WIDTH-1:0] tf_data_out;
|
2403 |
|
|
wire tf_push;
|
2404 |
|
|
wire tf_overrun;
|
2405 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
2406 |
|
|
|
2407 |
|
|
assign tf_data_in = wb_dat_i;
|
2408 |
|
|
|
2409 |
|
|
uart_tfifo fifo_tx( // error bit signal is not used in transmitter FIFO
|
2410 |
|
|
.clk( clk ),
|
2411 |
|
|
.wb_rst_i( wb_rst_i ),
|
2412 |
|
|
.data_in( tf_data_in ),
|
2413 |
|
|
.data_out( tf_data_out ),
|
2414 |
|
|
.push( tf_push ),
|
2415 |
|
|
.pop( tf_pop ),
|
2416 |
|
|
.overrun( tf_overrun ),
|
2417 |
|
|
.count( tf_count ),
|
2418 |
|
|
.fifo_reset( tx_reset ),
|
2419 |
|
|
.reset_status(lsr_mask)
|
2420 |
|
|
);
|
2421 |
|
|
|
2422 |
|
|
`ifdef UART_LOG_TX
|
2423 |
|
|
integer file_handler;
|
2424 |
|
|
|
2425 |
|
|
initial
|
2426 |
|
|
begin
|
2427 |
|
|
file_handler = $fopen("uart_tx.txt");
|
2428 |
|
|
end
|
2429 |
|
|
|
2430 |
|
|
always @(negedge tf_push)
|
2431 |
|
|
begin
|
2432 |
|
|
$fwrite(file_handler, "%s", tf_data_out);
|
2433 |
|
|
$display("UART: %s", tf_data_out);
|
2434 |
|
|
end
|
2435 |
|
|
`endif
|
2436 |
|
|
|
2437 |
|
|
// TRANSMITTER FINAL STATE MACHINE
|
2438 |
|
|
|
2439 |
|
|
parameter s_idle = 3'd0;
|
2440 |
|
|
parameter s_send_start = 3'd1;
|
2441 |
|
|
parameter s_send_byte = 3'd2;
|
2442 |
|
|
parameter s_send_parity = 3'd3;
|
2443 |
|
|
parameter s_send_stop = 3'd4;
|
2444 |
|
|
parameter s_pop_byte = 3'd5;
|
2445 |
|
|
|
2446 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2447 |
|
|
begin
|
2448 |
|
|
if (wb_rst_i)
|
2449 |
|
|
begin
|
2450 |
|
|
tstate <= #1 s_idle;
|
2451 |
|
|
stx_o_tmp <= #1 1'b1;
|
2452 |
|
|
counter <= #1 5'b0;
|
2453 |
|
|
shift_out <= #1 7'b0;
|
2454 |
|
|
bit_out <= #1 1'b0;
|
2455 |
|
|
parity_xor <= #1 1'b0;
|
2456 |
|
|
tf_pop <= #1 1'b0;
|
2457 |
|
|
bit_counter <= #1 3'b0;
|
2458 |
|
|
end
|
2459 |
|
|
else
|
2460 |
|
|
if (enable)
|
2461 |
|
|
begin
|
2462 |
|
|
case (tstate)
|
2463 |
|
|
s_idle : if (~|tf_count) // if tf_count==0
|
2464 |
|
|
begin
|
2465 |
|
|
tstate <= #1 s_idle;
|
2466 |
|
|
stx_o_tmp <= #1 1'b1;
|
2467 |
|
|
end
|
2468 |
|
|
else
|
2469 |
|
|
begin
|
2470 |
|
|
tf_pop <= #1 1'b0;
|
2471 |
|
|
stx_o_tmp <= #1 1'b1;
|
2472 |
|
|
tstate <= #1 s_pop_byte;
|
2473 |
|
|
end
|
2474 |
|
|
s_pop_byte : begin
|
2475 |
|
|
tf_pop <= #1 1'b1;
|
2476 |
|
|
case (lcr[/*`UART_LC_BITS*/1:0]) // number of bits in a word
|
2477 |
|
|
2'b00 : begin
|
2478 |
|
|
bit_counter <= #1 3'b100;
|
2479 |
|
|
parity_xor <= #1 ^tf_data_out[4:0];
|
2480 |
|
|
end
|
2481 |
|
|
2'b01 : begin
|
2482 |
|
|
bit_counter <= #1 3'b101;
|
2483 |
|
|
parity_xor <= #1 ^tf_data_out[5:0];
|
2484 |
|
|
end
|
2485 |
|
|
2'b10 : begin
|
2486 |
|
|
bit_counter <= #1 3'b110;
|
2487 |
|
|
parity_xor <= #1 ^tf_data_out[6:0];
|
2488 |
|
|
end
|
2489 |
|
|
2'b11 : begin
|
2490 |
|
|
bit_counter <= #1 3'b111;
|
2491 |
|
|
parity_xor <= #1 ^tf_data_out[7:0];
|
2492 |
|
|
end
|
2493 |
|
|
endcase
|
2494 |
|
|
{shift_out[6:0], bit_out} <= #1 tf_data_out;
|
2495 |
|
|
tstate <= #1 s_send_start;
|
2496 |
|
|
end
|
2497 |
|
|
s_send_start : begin
|
2498 |
|
|
tf_pop <= #1 1'b0;
|
2499 |
|
|
if (~|counter)
|
2500 |
|
|
counter <= #1 5'b01111;
|
2501 |
|
|
else
|
2502 |
|
|
if (counter == 5'b00001)
|
2503 |
|
|
begin
|
2504 |
|
|
counter <= #1 0;
|
2505 |
|
|
tstate <= #1 s_send_byte;
|
2506 |
|
|
end
|
2507 |
|
|
else
|
2508 |
|
|
counter <= #1 counter - 1'b1;
|
2509 |
|
|
stx_o_tmp <= #1 1'b0;
|
2510 |
|
|
end
|
2511 |
|
|
s_send_byte : begin
|
2512 |
|
|
if (~|counter)
|
2513 |
|
|
counter <= #1 5'b01111;
|
2514 |
|
|
else
|
2515 |
|
|
if (counter == 5'b00001)
|
2516 |
|
|
begin
|
2517 |
|
|
if (bit_counter > 3'b0)
|
2518 |
|
|
begin
|
2519 |
|
|
bit_counter <= #1 bit_counter - 1'b1;
|
2520 |
|
|
{shift_out[5:0],bit_out } <= #1 {shift_out[6:1], shift_out[0]};
|
2521 |
|
|
tstate <= #1 s_send_byte;
|
2522 |
|
|
end
|
2523 |
|
|
else // end of byte
|
2524 |
|
|
if (~lcr[`UART_LC_PE])
|
2525 |
|
|
begin
|
2526 |
|
|
tstate <= #1 s_send_stop;
|
2527 |
|
|
end
|
2528 |
|
|
else
|
2529 |
|
|
begin
|
2530 |
|
|
case ({lcr[`UART_LC_EP],lcr[`UART_LC_SP]})
|
2531 |
|
|
2'b00: bit_out <= #1 ~parity_xor;
|
2532 |
|
|
2'b01: bit_out <= #1 1'b1;
|
2533 |
|
|
2'b10: bit_out <= #1 parity_xor;
|
2534 |
|
|
2'b11: bit_out <= #1 1'b0;
|
2535 |
|
|
endcase
|
2536 |
|
|
tstate <= #1 s_send_parity;
|
2537 |
|
|
end
|
2538 |
|
|
counter <= #1 0;
|
2539 |
|
|
end
|
2540 |
|
|
else
|
2541 |
|
|
counter <= #1 counter - 1'b1;
|
2542 |
|
|
stx_o_tmp <= #1 bit_out; // set output pin
|
2543 |
|
|
end
|
2544 |
|
|
s_send_parity : begin
|
2545 |
|
|
if (~|counter)
|
2546 |
|
|
counter <= #1 5'b01111;
|
2547 |
|
|
else
|
2548 |
|
|
if (counter == 5'b00001)
|
2549 |
|
|
begin
|
2550 |
|
|
counter <= #1 4'b0;
|
2551 |
|
|
tstate <= #1 s_send_stop;
|
2552 |
|
|
end
|
2553 |
|
|
else
|
2554 |
|
|
counter <= #1 counter - 1'b1;
|
2555 |
|
|
stx_o_tmp <= #1 bit_out;
|
2556 |
|
|
end
|
2557 |
|
|
s_send_stop : begin
|
2558 |
|
|
if (~|counter)
|
2559 |
|
|
begin
|
2560 |
|
|
casex ({lcr[`UART_LC_SB],lcr[`UART_LC_BITS]})
|
2561 |
|
|
3'b0xx: counter <= #1 5'b01101; // 1 stop bit ok igor
|
2562 |
|
|
3'b100: counter <= #1 5'b10101; // 1.5 stop bit
|
2563 |
|
|
default: counter <= #1 5'b11101; // 2 stop bits
|
2564 |
|
|
endcase
|
2565 |
|
|
end
|
2566 |
|
|
else
|
2567 |
|
|
if (counter == 5'b00001)
|
2568 |
|
|
begin
|
2569 |
|
|
counter <= #1 0;
|
2570 |
|
|
tstate <= #1 s_idle;
|
2571 |
|
|
end
|
2572 |
|
|
else
|
2573 |
|
|
counter <= #1 counter - 1'b1;
|
2574 |
|
|
stx_o_tmp <= #1 1'b1;
|
2575 |
|
|
end
|
2576 |
|
|
|
2577 |
|
|
default : // should never get here
|
2578 |
|
|
tstate <= #1 s_idle;
|
2579 |
|
|
endcase
|
2580 |
|
|
end // end if enable
|
2581 |
|
|
else
|
2582 |
|
|
tf_pop <= #1 1'b0; // tf_pop must be 1 cycle width
|
2583 |
|
|
end // transmitter logic
|
2584 |
|
|
|
2585 |
|
|
assign stx_pad_o = lcr[`UART_LC_BC] ? 1'b0 : stx_o_tmp; // Break condition
|
2586 |
|
|
|
2587 |
|
|
endmodule
|
2588 |
|
|
//////////////////////////////////////////////////////////////////////
|
2589 |
|
|
//// ////
|
2590 |
|
|
//// uart_debug_if.v ////
|
2591 |
|
|
//// ////
|
2592 |
|
|
//// ////
|
2593 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
2594 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
2595 |
|
|
//// ////
|
2596 |
|
|
//// Documentation related to this project: ////
|
2597 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
2598 |
|
|
//// ////
|
2599 |
|
|
//// Projects compatibility: ////
|
2600 |
|
|
//// - WISHBONE ////
|
2601 |
|
|
//// RS232 Protocol ////
|
2602 |
|
|
//// 16550D uart (mostly supported) ////
|
2603 |
|
|
//// ////
|
2604 |
|
|
//// Overview (main Features): ////
|
2605 |
|
|
//// UART core debug interface. ////
|
2606 |
|
|
//// ////
|
2607 |
|
|
//// Author(s): ////
|
2608 |
|
|
//// - gorban@opencores.org ////
|
2609 |
|
|
//// - Jacob Gorban ////
|
2610 |
|
|
//// ////
|
2611 |
|
|
//// Created: 2001/12/02 ////
|
2612 |
|
|
//// (See log for the revision history) ////
|
2613 |
|
|
//// ////
|
2614 |
|
|
//////////////////////////////////////////////////////////////////////
|
2615 |
|
|
//// ////
|
2616 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
2617 |
|
|
//// ////
|
2618 |
|
|
//// This source file may be used and distributed without ////
|
2619 |
|
|
//// restriction provided that this copyright statement is not ////
|
2620 |
|
|
//// removed from the file and that any derivative work contains ////
|
2621 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
2622 |
|
|
//// ////
|
2623 |
|
|
//// This source file is free software; you can redistribute it ////
|
2624 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
2625 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
2626 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
2627 |
|
|
//// later version. ////
|
2628 |
|
|
//// ////
|
2629 |
|
|
//// This source is distributed in the hope that it will be ////
|
2630 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
2631 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
2632 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
2633 |
|
|
//// details. ////
|
2634 |
|
|
//// ////
|
2635 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
2636 |
|
|
//// Public License along with this source; if not, download it ////
|
2637 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
2638 |
|
|
//// ////
|
2639 |
|
|
//////////////////////////////////////////////////////////////////////
|
2640 |
|
|
//
|
2641 |
|
|
// CVS Revision History
|
2642 |
|
|
//
|
2643 |
|
|
// $Log: uart_debug_if.v,v $
|
2644 |
|
|
// Revision 1.5 2002/07/29 21:16:18 gorban
|
2645 |
|
|
// The uart_defines.v file is included again in sources.
|
2646 |
|
|
//
|
2647 |
|
|
// Revision 1.4 2002/07/22 23:02:23 gorban
|
2648 |
|
|
// Bug Fixes:
|
2649 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
2650 |
|
|
// Problem reported by Kenny.Tung.
|
2651 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
2652 |
|
|
//
|
2653 |
|
|
// Improvements:
|
2654 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
2655 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
2656 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
2657 |
|
|
//
|
2658 |
|
|
// * Added optional baudrate output (baud_o).
|
2659 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
2660 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
2661 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
2662 |
|
|
//
|
2663 |
|
|
// Revision 1.3 2001/12/19 08:40:03 mohor
|
2664 |
|
|
// Warnings fixed (unused signals removed).
|
2665 |
|
|
//
|
2666 |
|
|
// Revision 1.2 2001/12/12 22:17:30 gorban
|
2667 |
|
|
// some synthesis bugs fixed
|
2668 |
|
|
//
|
2669 |
|
|
// Revision 1.1 2001/12/04 21:14:16 gorban
|
2670 |
|
|
// committed the debug interface file
|
2671 |
|
|
//
|
2672 |
|
|
|
2673 |
|
|
// synopsys translate_off
|
2674 |
|
|
`include "timescale.v"
|
2675 |
|
|
// synopsys translate_on
|
2676 |
|
|
|
2677 |
|
|
`include "uart_defines.v"
|
2678 |
|
|
|
2679 |
|
|
module uart_debug_if (/*AUTOARG*/
|
2680 |
|
|
// Outputs
|
2681 |
|
|
wb_dat32_o,
|
2682 |
|
|
// Inputs
|
2683 |
|
|
wb_adr_i, ier, iir, fcr, mcr, lcr, msr,
|
2684 |
|
|
lsr, rf_count, tf_count, tstate, rstate
|
2685 |
|
|
) ;
|
2686 |
|
|
|
2687 |
|
|
input [`UART_ADDR_WIDTH-1:0] wb_adr_i;
|
2688 |
|
|
output [31:0] wb_dat32_o;
|
2689 |
|
|
input [3:0] ier;
|
2690 |
|
|
input [3:0] iir;
|
2691 |
|
|
input [1:0] fcr; /// bits 7 and 6 of fcr. Other bits are ignored
|
2692 |
|
|
input [4:0] mcr;
|
2693 |
|
|
input [7:0] lcr;
|
2694 |
|
|
input [7:0] msr;
|
2695 |
|
|
input [7:0] lsr;
|
2696 |
|
|
input [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
2697 |
|
|
input [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
2698 |
|
|
input [2:0] tstate;
|
2699 |
|
|
input [3:0] rstate;
|
2700 |
|
|
|
2701 |
|
|
|
2702 |
|
|
wire [`UART_ADDR_WIDTH-1:0] wb_adr_i;
|
2703 |
|
|
reg [31:0] wb_dat32_o;
|
2704 |
|
|
|
2705 |
|
|
always @(/*AUTOSENSE*/fcr or ier or iir or lcr or lsr or mcr or msr
|
2706 |
|
|
or rf_count or rstate or tf_count or tstate or wb_adr_i)
|
2707 |
|
|
case (wb_adr_i)
|
2708 |
|
|
// 8 + 8 + 4 + 4 + 8
|
2709 |
|
|
5'b01000: wb_dat32_o = {msr,lcr,iir,ier,lsr};
|
2710 |
|
|
// 5 + 2 + 5 + 4 + 5 + 3
|
2711 |
|
|
5'b01100: wb_dat32_o = {8'b0, fcr,mcr, rf_count, rstate, tf_count, tstate};
|
2712 |
|
|
default: wb_dat32_o = 0;
|
2713 |
|
|
endcase // case(wb_adr_i)
|
2714 |
|
|
|
2715 |
|
|
endmodule // uart_debug_if
|
2716 |
|
|
|
2717 |
|
|
//////////////////////////////////////////////////////////////////////
|
2718 |
|
|
//// ////
|
2719 |
|
|
//// uart_wb.v ////
|
2720 |
|
|
//// ////
|
2721 |
|
|
//// ////
|
2722 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
2723 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
2724 |
|
|
//// ////
|
2725 |
|
|
//// Documentation related to this project: ////
|
2726 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
2727 |
|
|
//// ////
|
2728 |
|
|
//// Projects compatibility: ////
|
2729 |
|
|
//// - WISHBONE ////
|
2730 |
|
|
//// RS232 Protocol ////
|
2731 |
|
|
//// 16550D uart (mostly supported) ////
|
2732 |
|
|
//// ////
|
2733 |
|
|
//// Overview (main Features): ////
|
2734 |
|
|
//// UART core WISHBONE interface. ////
|
2735 |
|
|
//// ////
|
2736 |
|
|
//// Known problems (limits): ////
|
2737 |
|
|
//// Inserts one wait state on all transfers. ////
|
2738 |
|
|
//// Note affected signals and the way they are affected. ////
|
2739 |
|
|
//// ////
|
2740 |
|
|
//// To Do: ////
|
2741 |
|
|
//// Nothing. ////
|
2742 |
|
|
//// ////
|
2743 |
|
|
//// Author(s): ////
|
2744 |
|
|
//// - gorban@opencores.org ////
|
2745 |
|
|
//// - Jacob Gorban ////
|
2746 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
2747 |
|
|
//// ////
|
2748 |
|
|
//// Created: 2001/05/12 ////
|
2749 |
|
|
//// Last Updated: 2001/05/17 ////
|
2750 |
|
|
//// (See log for the revision history) ////
|
2751 |
|
|
//// ////
|
2752 |
|
|
//// ////
|
2753 |
|
|
//////////////////////////////////////////////////////////////////////
|
2754 |
|
|
//// ////
|
2755 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
2756 |
|
|
//// ////
|
2757 |
|
|
//// This source file may be used and distributed without ////
|
2758 |
|
|
//// restriction provided that this copyright statement is not ////
|
2759 |
|
|
//// removed from the file and that any derivative work contains ////
|
2760 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
2761 |
|
|
//// ////
|
2762 |
|
|
//// This source file is free software; you can redistribute it ////
|
2763 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
2764 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
2765 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
2766 |
|
|
//// later version. ////
|
2767 |
|
|
//// ////
|
2768 |
|
|
//// This source is distributed in the hope that it will be ////
|
2769 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
2770 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
2771 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
2772 |
|
|
//// details. ////
|
2773 |
|
|
//// ////
|
2774 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
2775 |
|
|
//// Public License along with this source; if not, download it ////
|
2776 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
2777 |
|
|
//// ////
|
2778 |
|
|
//////////////////////////////////////////////////////////////////////
|
2779 |
|
|
//
|
2780 |
|
|
// CVS Revision History
|
2781 |
|
|
//
|
2782 |
|
|
// $Log: uart_wb.v,v $
|
2783 |
|
|
// Revision 1.17 2004/05/21 12:35:15 tadejm
|
2784 |
|
|
// Added 2 LSB address generation dependent on select lines and LITLE/BIG endian when UART is in 32-bit mode.
|
2785 |
|
|
//
|
2786 |
|
|
// Revision 1.16 2002/07/29 21:16:18 gorban
|
2787 |
|
|
// The uart_defines.v file is included again in sources.
|
2788 |
|
|
//
|
2789 |
|
|
// Revision 1.15 2002/07/22 23:02:23 gorban
|
2790 |
|
|
// Bug Fixes:
|
2791 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
2792 |
|
|
// Problem reported by Kenny.Tung.
|
2793 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
2794 |
|
|
//
|
2795 |
|
|
// Improvements:
|
2796 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
2797 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
2798 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
2799 |
|
|
//
|
2800 |
|
|
// * Added optional baudrate output (baud_o).
|
2801 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
2802 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
2803 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
2804 |
|
|
//
|
2805 |
|
|
// Revision 1.12 2001/12/19 08:03:34 mohor
|
2806 |
|
|
// Warnings cleared.
|
2807 |
|
|
//
|
2808 |
|
|
// Revision 1.11 2001/12/06 14:51:04 gorban
|
2809 |
|
|
// Bug in LSR[0] is fixed.
|
2810 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
2811 |
|
|
//
|
2812 |
|
|
// Revision 1.10 2001/12/03 21:44:29 gorban
|
2813 |
|
|
// Updated specification documentation.
|
2814 |
|
|
// Added full 32-bit data bus interface, now as default.
|
2815 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
2816 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
2817 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
2818 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
2819 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
2820 |
|
|
//
|
2821 |
|
|
// Revision 1.9 2001/10/20 09:58:40 gorban
|
2822 |
|
|
// Small synopsis fixes
|
2823 |
|
|
//
|
2824 |
|
|
// Revision 1.8 2001/08/24 21:01:12 mohor
|
2825 |
|
|
// Things connected to parity changed.
|
2826 |
|
|
// Clock devider changed.
|
2827 |
|
|
//
|
2828 |
|
|
// Revision 1.7 2001/08/23 16:05:05 mohor
|
2829 |
|
|
// Stop bit bug fixed.
|
2830 |
|
|
// Parity bug fixed.
|
2831 |
|
|
// WISHBONE read cycle bug fixed,
|
2832 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
2833 |
|
|
// PE indicator (Parity Error) bug fixed.
|
2834 |
|
|
// Register read bug fixed.
|
2835 |
|
|
//
|
2836 |
|
|
// Revision 1.4 2001/05/31 20:08:01 gorban
|
2837 |
|
|
// FIFO changes and other corrections.
|
2838 |
|
|
//
|
2839 |
|
|
// Revision 1.3 2001/05/21 19:12:01 gorban
|
2840 |
|
|
// Corrected some Linter messages.
|
2841 |
|
|
//
|
2842 |
|
|
// Revision 1.2 2001/05/17 18:34:18 gorban
|
2843 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
2844 |
|
|
//
|
2845 |
|
|
// Revision 1.0 2001-05-17 21:27:13+02 jacob
|
2846 |
|
|
// Initial revision
|
2847 |
|
|
//
|
2848 |
|
|
//
|
2849 |
|
|
|
2850 |
|
|
// UART core WISHBONE interface
|
2851 |
|
|
//
|
2852 |
|
|
// Author: Jacob Gorban (jacob.gorban@flextronicssemi.com)
|
2853 |
|
|
// Company: Flextronics Semiconductor
|
2854 |
|
|
//
|
2855 |
|
|
|
2856 |
|
|
// synopsys translate_off
|
2857 |
|
|
`include "timescale.v"
|
2858 |
|
|
// synopsys translate_on
|
2859 |
|
|
`include "uart_defines.v"
|
2860 |
|
|
|
2861 |
|
|
module uart_wb (clk, wb_rst_i,
|
2862 |
|
|
wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_adr_i,
|
2863 |
|
|
wb_adr_int, wb_dat_i, wb_dat_o, wb_dat8_i, wb_dat8_o, wb_dat32_o, wb_sel_i,
|
2864 |
|
|
we_o, re_o // Write and read enable output for the core
|
2865 |
|
|
);
|
2866 |
|
|
|
2867 |
|
|
input clk;
|
2868 |
|
|
|
2869 |
|
|
// WISHBONE interface
|
2870 |
|
|
input wb_rst_i;
|
2871 |
|
|
input wb_we_i;
|
2872 |
|
|
input wb_stb_i;
|
2873 |
|
|
input wb_cyc_i;
|
2874 |
|
|
input [3:0] wb_sel_i;
|
2875 |
|
|
input [`UART_ADDR_WIDTH-1:0] wb_adr_i; //WISHBONE address line
|
2876 |
|
|
|
2877 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
2878 |
|
|
input [7:0] wb_dat_i; //input WISHBONE bus
|
2879 |
|
|
output [7:0] wb_dat_o;
|
2880 |
|
|
reg [7:0] wb_dat_o;
|
2881 |
|
|
wire [7:0] wb_dat_i;
|
2882 |
|
|
reg [7:0] wb_dat_is;
|
2883 |
|
|
`else // for 32 data bus mode
|
2884 |
|
|
input [31:0] wb_dat_i; //input WISHBONE bus
|
2885 |
|
|
output [31:0] wb_dat_o;
|
2886 |
|
|
reg [31:0] wb_dat_o;
|
2887 |
|
|
wire [31:0] wb_dat_i;
|
2888 |
|
|
reg [31:0] wb_dat_is;
|
2889 |
|
|
`endif // !`ifdef DATA_BUS_WIDTH_8
|
2890 |
|
|
|
2891 |
|
|
output [`UART_ADDR_WIDTH-1:0] wb_adr_int; // internal signal for address bus
|
2892 |
|
|
input [7:0] wb_dat8_o; // internal 8 bit output to be put into wb_dat_o
|
2893 |
|
|
output [7:0] wb_dat8_i;
|
2894 |
|
|
input [31:0] wb_dat32_o; // 32 bit data output (for debug interface)
|
2895 |
|
|
output wb_ack_o;
|
2896 |
|
|
output we_o;
|
2897 |
|
|
output re_o;
|
2898 |
|
|
|
2899 |
|
|
wire we_o;
|
2900 |
|
|
reg wb_ack_o;
|
2901 |
|
|
reg [7:0] wb_dat8_i;
|
2902 |
|
|
wire [7:0] wb_dat8_o;
|
2903 |
|
|
wire [`UART_ADDR_WIDTH-1:0] wb_adr_int; // internal signal for address bus
|
2904 |
|
|
reg [`UART_ADDR_WIDTH-1:0] wb_adr_is;
|
2905 |
|
|
reg wb_we_is;
|
2906 |
|
|
reg wb_cyc_is;
|
2907 |
|
|
reg wb_stb_is;
|
2908 |
|
|
reg [3:0] wb_sel_is;
|
2909 |
|
|
wire [3:0] wb_sel_i;
|
2910 |
|
|
reg wre ;// timing control signal for write or read enable
|
2911 |
|
|
|
2912 |
|
|
// wb_ack_o FSM
|
2913 |
|
|
reg [1:0] wbstate;
|
2914 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2915 |
|
|
if (wb_rst_i) begin
|
2916 |
|
|
wb_ack_o <= #1 1'b0;
|
2917 |
|
|
wbstate <= #1 0;
|
2918 |
|
|
wre <= #1 1'b1;
|
2919 |
|
|
end else
|
2920 |
|
|
case (wbstate)
|
2921 |
|
|
0: begin
|
2922 |
|
|
if (wb_stb_is & wb_cyc_is) begin
|
2923 |
|
|
wre <= #1 0;
|
2924 |
|
|
wbstate <= #1 1;
|
2925 |
|
|
wb_ack_o <= #1 1;
|
2926 |
|
|
end else begin
|
2927 |
|
|
wre <= #1 1;
|
2928 |
|
|
wb_ack_o <= #1 0;
|
2929 |
|
|
end
|
2930 |
|
|
end
|
2931 |
|
|
1: begin
|
2932 |
|
|
wb_ack_o <= #1 0;
|
2933 |
|
|
wbstate <= #1 2;
|
2934 |
|
|
wre <= #1 0;
|
2935 |
|
|
end
|
2936 |
|
|
2,3: begin
|
2937 |
|
|
wb_ack_o <= #1 0;
|
2938 |
|
|
wbstate <= #1 0;
|
2939 |
|
|
wre <= #1 0;
|
2940 |
|
|
end
|
2941 |
|
|
endcase
|
2942 |
|
|
|
2943 |
|
|
assign we_o = wb_we_is & wb_stb_is & wb_cyc_is & wre ; //WE for registers
|
2944 |
|
|
assign re_o = ~wb_we_is & wb_stb_is & wb_cyc_is & wre ; //RE for registers
|
2945 |
|
|
|
2946 |
|
|
// Sample input signals
|
2947 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2948 |
|
|
if (wb_rst_i) begin
|
2949 |
|
|
wb_adr_is <= #1 0;
|
2950 |
|
|
wb_we_is <= #1 0;
|
2951 |
|
|
wb_cyc_is <= #1 0;
|
2952 |
|
|
wb_stb_is <= #1 0;
|
2953 |
|
|
wb_dat_is <= #1 0;
|
2954 |
|
|
wb_sel_is <= #1 0;
|
2955 |
|
|
end else begin
|
2956 |
|
|
wb_adr_is <= #1 wb_adr_i;
|
2957 |
|
|
wb_we_is <= #1 wb_we_i;
|
2958 |
|
|
wb_cyc_is <= #1 wb_cyc_i;
|
2959 |
|
|
wb_stb_is <= #1 wb_stb_i;
|
2960 |
|
|
wb_dat_is <= #1 wb_dat_i;
|
2961 |
|
|
wb_sel_is <= #1 wb_sel_i;
|
2962 |
|
|
end
|
2963 |
|
|
|
2964 |
|
|
`ifdef DATA_BUS_WIDTH_8 // 8-bit data bus
|
2965 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2966 |
|
|
if (wb_rst_i)
|
2967 |
|
|
wb_dat_o <= #1 0;
|
2968 |
|
|
else
|
2969 |
|
|
wb_dat_o <= #1 wb_dat8_o;
|
2970 |
|
|
|
2971 |
|
|
always @(wb_dat_is)
|
2972 |
|
|
wb_dat8_i = wb_dat_is;
|
2973 |
|
|
|
2974 |
|
|
assign wb_adr_int = wb_adr_is;
|
2975 |
|
|
|
2976 |
|
|
`else // 32-bit bus
|
2977 |
|
|
// put output to the correct byte in 32 bits using select line
|
2978 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
2979 |
|
|
if (wb_rst_i)
|
2980 |
|
|
wb_dat_o <= #1 0;
|
2981 |
|
|
else if (re_o)
|
2982 |
|
|
case (wb_sel_is)
|
2983 |
|
|
4'b0001: wb_dat_o <= #1 {24'b0, wb_dat8_o};
|
2984 |
|
|
4'b0010: wb_dat_o <= #1 {16'b0, wb_dat8_o, 8'b0};
|
2985 |
|
|
4'b0100: wb_dat_o <= #1 {8'b0, wb_dat8_o, 16'b0};
|
2986 |
|
|
4'b1000: wb_dat_o <= #1 {wb_dat8_o, 24'b0};
|
2987 |
|
|
4'b1111: wb_dat_o <= #1 wb_dat32_o; // debug interface output
|
2988 |
|
|
default: wb_dat_o <= #1 0;
|
2989 |
|
|
endcase // case(wb_sel_i)
|
2990 |
|
|
|
2991 |
|
|
reg [1:0] wb_adr_int_lsb;
|
2992 |
|
|
|
2993 |
|
|
always @(wb_sel_is or wb_dat_is)
|
2994 |
|
|
begin
|
2995 |
|
|
case (wb_sel_is)
|
2996 |
|
|
4'b0001 : wb_dat8_i = wb_dat_is[7:0];
|
2997 |
|
|
4'b0010 : wb_dat8_i = wb_dat_is[15:8];
|
2998 |
|
|
4'b0100 : wb_dat8_i = wb_dat_is[23:16];
|
2999 |
|
|
4'b1000 : wb_dat8_i = wb_dat_is[31:24];
|
3000 |
|
|
default : wb_dat8_i = wb_dat_is[7:0];
|
3001 |
|
|
endcase // case(wb_sel_i)
|
3002 |
|
|
|
3003 |
|
|
`ifdef LITLE_ENDIAN
|
3004 |
|
|
case (wb_sel_is)
|
3005 |
|
|
4'b0001 : wb_adr_int_lsb = 2'h0;
|
3006 |
|
|
4'b0010 : wb_adr_int_lsb = 2'h1;
|
3007 |
|
|
4'b0100 : wb_adr_int_lsb = 2'h2;
|
3008 |
|
|
4'b1000 : wb_adr_int_lsb = 2'h3;
|
3009 |
|
|
default : wb_adr_int_lsb = 2'h0;
|
3010 |
|
|
endcase // case(wb_sel_i)
|
3011 |
|
|
`else
|
3012 |
|
|
case (wb_sel_is)
|
3013 |
|
|
4'b0001 : wb_adr_int_lsb = 2'h3;
|
3014 |
|
|
4'b0010 : wb_adr_int_lsb = 2'h2;
|
3015 |
|
|
4'b0100 : wb_adr_int_lsb = 2'h1;
|
3016 |
|
|
4'b1000 : wb_adr_int_lsb = 2'h0;
|
3017 |
|
|
default : wb_adr_int_lsb = 2'h0;
|
3018 |
|
|
endcase // case(wb_sel_i)
|
3019 |
|
|
`endif
|
3020 |
|
|
end
|
3021 |
|
|
|
3022 |
|
|
assign wb_adr_int = {wb_adr_is[`UART_ADDR_WIDTH-1:2], wb_adr_int_lsb};
|
3023 |
|
|
|
3024 |
|
|
`endif // !`ifdef DATA_BUS_WIDTH_8
|
3025 |
|
|
|
3026 |
|
|
endmodule
|
3027 |
|
|
|
3028 |
|
|
|
3029 |
|
|
|
3030 |
|
|
|
3031 |
|
|
|
3032 |
|
|
|
3033 |
|
|
|
3034 |
|
|
|
3035 |
|
|
|
3036 |
|
|
|
3037 |
|
|
//////////////////////////////////////////////////////////////////////
|
3038 |
|
|
//// ////
|
3039 |
|
|
//// uart_top.v ////
|
3040 |
|
|
//// ////
|
3041 |
|
|
//// ////
|
3042 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
3043 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
3044 |
|
|
//// ////
|
3045 |
|
|
//// Documentation related to this project: ////
|
3046 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
3047 |
|
|
//// ////
|
3048 |
|
|
//// Projects compatibility: ////
|
3049 |
|
|
//// - WISHBONE ////
|
3050 |
|
|
//// RS232 Protocol ////
|
3051 |
|
|
//// 16550D uart (mostly supported) ////
|
3052 |
|
|
//// ////
|
3053 |
|
|
//// Overview (main Features): ////
|
3054 |
|
|
//// UART core top level. ////
|
3055 |
|
|
//// ////
|
3056 |
|
|
//// Known problems (limits): ////
|
3057 |
|
|
//// Note that transmitter and receiver instances are inside ////
|
3058 |
|
|
//// the uart_regs.v file. ////
|
3059 |
|
|
//// ////
|
3060 |
|
|
//// To Do: ////
|
3061 |
|
|
//// Nothing so far. ////
|
3062 |
|
|
//// ////
|
3063 |
|
|
//// Author(s): ////
|
3064 |
|
|
//// - gorban@opencores.org ////
|
3065 |
|
|
//// - Jacob Gorban ////
|
3066 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
3067 |
|
|
//// ////
|
3068 |
|
|
//// Created: 2001/05/12 ////
|
3069 |
|
|
//// Last Updated: 2001/05/17 ////
|
3070 |
|
|
//// (See log for the revision history) ////
|
3071 |
|
|
//// ////
|
3072 |
|
|
//// ////
|
3073 |
|
|
//////////////////////////////////////////////////////////////////////
|
3074 |
|
|
//// ////
|
3075 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
3076 |
|
|
//// ////
|
3077 |
|
|
//// This source file may be used and distributed without ////
|
3078 |
|
|
//// restriction provided that this copyright statement is not ////
|
3079 |
|
|
//// removed from the file and that any derivative work contains ////
|
3080 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
3081 |
|
|
//// ////
|
3082 |
|
|
//// This source file is free software; you can redistribute it ////
|
3083 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
3084 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
3085 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
3086 |
|
|
//// later version. ////
|
3087 |
|
|
//// ////
|
3088 |
|
|
//// This source is distributed in the hope that it will be ////
|
3089 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
3090 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
3091 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
3092 |
|
|
//// details. ////
|
3093 |
|
|
//// ////
|
3094 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
3095 |
|
|
//// Public License along with this source; if not, download it ////
|
3096 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
3097 |
|
|
//// ////
|
3098 |
|
|
//////////////////////////////////////////////////////////////////////
|
3099 |
|
|
//
|
3100 |
|
|
// CVS Revision History
|
3101 |
|
|
//
|
3102 |
|
|
// $Log: uart_top.v,v $
|
3103 |
|
|
// Revision 1.19 2002/07/29 21:16:18 gorban
|
3104 |
|
|
// The uart_defines.v file is included again in sources.
|
3105 |
|
|
//
|
3106 |
|
|
// Revision 1.18 2002/07/22 23:02:23 gorban
|
3107 |
|
|
// Bug Fixes:
|
3108 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
3109 |
|
|
// Problem reported by Kenny.Tung.
|
3110 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
3111 |
|
|
//
|
3112 |
|
|
// Improvements:
|
3113 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
3114 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
3115 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
3116 |
|
|
//
|
3117 |
|
|
// * Added optional baudrate output (baud_o).
|
3118 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
3119 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
3120 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
3121 |
|
|
//
|
3122 |
|
|
// Revision 1.17 2001/12/19 08:40:03 mohor
|
3123 |
|
|
// Warnings fixed (unused signals removed).
|
3124 |
|
|
//
|
3125 |
|
|
// Revision 1.16 2001/12/06 14:51:04 gorban
|
3126 |
|
|
// Bug in LSR[0] is fixed.
|
3127 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
3128 |
|
|
//
|
3129 |
|
|
// Revision 1.15 2001/12/03 21:44:29 gorban
|
3130 |
|
|
// Updated specification documentation.
|
3131 |
|
|
// Added full 32-bit data bus interface, now as default.
|
3132 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
3133 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
3134 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
3135 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
3136 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
3137 |
|
|
//
|
3138 |
|
|
// Revision 1.14 2001/11/07 17:51:52 gorban
|
3139 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
3140 |
|
|
// Many bugs hopefully squashed.
|
3141 |
|
|
//
|
3142 |
|
|
// Revision 1.13 2001/10/20 09:58:40 gorban
|
3143 |
|
|
// Small synopsis fixes
|
3144 |
|
|
//
|
3145 |
|
|
// Revision 1.12 2001/08/25 15:46:19 gorban
|
3146 |
|
|
// Modified port names again
|
3147 |
|
|
//
|
3148 |
|
|
// Revision 1.11 2001/08/24 21:01:12 mohor
|
3149 |
|
|
// Things connected to parity changed.
|
3150 |
|
|
// Clock devider changed.
|
3151 |
|
|
//
|
3152 |
|
|
// Revision 1.10 2001/08/23 16:05:05 mohor
|
3153 |
|
|
// Stop bit bug fixed.
|
3154 |
|
|
// Parity bug fixed.
|
3155 |
|
|
// WISHBONE read cycle bug fixed,
|
3156 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
3157 |
|
|
// PE indicator (Parity Error) bug fixed.
|
3158 |
|
|
// Register read bug fixed.
|
3159 |
|
|
//
|
3160 |
|
|
// Revision 1.4 2001/05/31 20:08:01 gorban
|
3161 |
|
|
// FIFO changes and other corrections.
|
3162 |
|
|
//
|
3163 |
|
|
// Revision 1.3 2001/05/21 19:12:02 gorban
|
3164 |
|
|
// Corrected some Linter messages.
|
3165 |
|
|
//
|
3166 |
|
|
// Revision 1.2 2001/05/17 18:34:18 gorban
|
3167 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
3168 |
|
|
//
|
3169 |
|
|
// Revision 1.0 2001-05-17 21:27:12+02 jacob
|
3170 |
|
|
// Initial revision
|
3171 |
|
|
//
|
3172 |
|
|
//
|
3173 |
|
|
// synopsys translate_off
|
3174 |
|
|
`include "timescale.v"
|
3175 |
|
|
// synopsys translate_on
|
3176 |
|
|
|
3177 |
|
|
`include "uart_defines.v"
|
3178 |
|
|
|
3179 |
|
|
module uart_top (
|
3180 |
|
|
wb_clk_i,
|
3181 |
|
|
|
3182 |
|
|
// Wishbone signals
|
3183 |
|
|
wb_rst_i, wb_adr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_sel_i,
|
3184 |
|
|
int_o, // interrupt request
|
3185 |
|
|
|
3186 |
|
|
// UART signals
|
3187 |
|
|
// serial input/output
|
3188 |
|
|
stx_pad_o, srx_pad_i,
|
3189 |
|
|
|
3190 |
|
|
// modem signals
|
3191 |
|
|
rts_pad_o, cts_pad_i, dtr_pad_o, dsr_pad_i, ri_pad_i, dcd_pad_i
|
3192 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
3193 |
|
|
, baud_o
|
3194 |
|
|
`endif
|
3195 |
|
|
);
|
3196 |
|
|
|
3197 |
|
|
parameter uart_data_width = `UART_DATA_WIDTH;
|
3198 |
|
|
parameter uart_addr_width = `UART_ADDR_WIDTH;
|
3199 |
|
|
|
3200 |
|
|
input wb_clk_i;
|
3201 |
|
|
|
3202 |
|
|
// WISHBONE interface
|
3203 |
|
|
input wb_rst_i;
|
3204 |
|
|
input [uart_addr_width-1:0] wb_adr_i;
|
3205 |
|
|
input [uart_data_width-1:0] wb_dat_i;
|
3206 |
|
|
output [uart_data_width-1:0] wb_dat_o;
|
3207 |
|
|
input wb_we_i;
|
3208 |
|
|
input wb_stb_i;
|
3209 |
|
|
input wb_cyc_i;
|
3210 |
|
|
input [3:0] wb_sel_i;
|
3211 |
|
|
output wb_ack_o;
|
3212 |
|
|
output int_o;
|
3213 |
|
|
|
3214 |
|
|
// UART signals
|
3215 |
|
|
input srx_pad_i;
|
3216 |
|
|
output stx_pad_o;
|
3217 |
|
|
output rts_pad_o;
|
3218 |
|
|
input cts_pad_i;
|
3219 |
|
|
output dtr_pad_o;
|
3220 |
|
|
input dsr_pad_i;
|
3221 |
|
|
input ri_pad_i;
|
3222 |
|
|
input dcd_pad_i;
|
3223 |
|
|
|
3224 |
|
|
// optional baudrate output
|
3225 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
3226 |
|
|
output baud_o;
|
3227 |
|
|
`endif
|
3228 |
|
|
|
3229 |
|
|
|
3230 |
|
|
wire stx_pad_o;
|
3231 |
|
|
wire rts_pad_o;
|
3232 |
|
|
wire dtr_pad_o;
|
3233 |
|
|
|
3234 |
|
|
wire [uart_addr_width-1:0] wb_adr_i;
|
3235 |
|
|
wire [uart_data_width-1:0] wb_dat_i;
|
3236 |
|
|
wire [uart_data_width-1:0] wb_dat_o;
|
3237 |
|
|
|
3238 |
|
|
wire [7:0] wb_dat8_i; // 8-bit internal data input
|
3239 |
|
|
wire [7:0] wb_dat8_o; // 8-bit internal data output
|
3240 |
|
|
wire [31:0] wb_dat32_o; // debug interface 32-bit output
|
3241 |
|
|
wire [3:0] wb_sel_i; // WISHBONE select signal
|
3242 |
|
|
wire [uart_addr_width-1:0] wb_adr_int;
|
3243 |
|
|
wire we_o; // Write enable for registers
|
3244 |
|
|
wire re_o; // Read enable for registers
|
3245 |
|
|
//
|
3246 |
|
|
// MODULE INSTANCES
|
3247 |
|
|
//
|
3248 |
|
|
|
3249 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
3250 |
|
|
`else
|
3251 |
|
|
// debug interface wires
|
3252 |
|
|
wire [3:0] ier;
|
3253 |
|
|
wire [3:0] iir;
|
3254 |
|
|
wire [1:0] fcr;
|
3255 |
|
|
wire [4:0] mcr;
|
3256 |
|
|
wire [7:0] lcr;
|
3257 |
|
|
wire [7:0] msr;
|
3258 |
|
|
wire [7:0] lsr;
|
3259 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
3260 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
3261 |
|
|
wire [2:0] tstate;
|
3262 |
|
|
wire [3:0] rstate;
|
3263 |
|
|
`endif
|
3264 |
|
|
|
3265 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
3266 |
|
|
//// WISHBONE interface module
|
3267 |
|
|
uart_wb wb_interface(
|
3268 |
|
|
.clk( wb_clk_i ),
|
3269 |
|
|
.wb_rst_i( wb_rst_i ),
|
3270 |
|
|
.wb_dat_i(wb_dat_i),
|
3271 |
|
|
.wb_dat_o(wb_dat_o),
|
3272 |
|
|
.wb_dat8_i(wb_dat8_i),
|
3273 |
|
|
.wb_dat8_o(wb_dat8_o),
|
3274 |
|
|
.wb_dat32_o(32'b0),
|
3275 |
|
|
.wb_sel_i(4'b0),
|
3276 |
|
|
.wb_we_i( wb_we_i ),
|
3277 |
|
|
.wb_stb_i( wb_stb_i ),
|
3278 |
|
|
.wb_cyc_i( wb_cyc_i ),
|
3279 |
|
|
.wb_ack_o( wb_ack_o ),
|
3280 |
|
|
.wb_adr_i(wb_adr_i),
|
3281 |
|
|
.wb_adr_int(wb_adr_int),
|
3282 |
|
|
.we_o( we_o ),
|
3283 |
|
|
.re_o(re_o)
|
3284 |
|
|
);
|
3285 |
|
|
`else
|
3286 |
|
|
uart_wb wb_interface(
|
3287 |
|
|
.clk( wb_clk_i ),
|
3288 |
|
|
.wb_rst_i( wb_rst_i ),
|
3289 |
|
|
.wb_dat_i(wb_dat_i),
|
3290 |
|
|
.wb_dat_o(wb_dat_o),
|
3291 |
|
|
.wb_dat8_i(wb_dat8_i),
|
3292 |
|
|
.wb_dat8_o(wb_dat8_o),
|
3293 |
|
|
.wb_sel_i(wb_sel_i),
|
3294 |
|
|
.wb_dat32_o(wb_dat32_o),
|
3295 |
|
|
.wb_we_i( wb_we_i ),
|
3296 |
|
|
.wb_stb_i( wb_stb_i ),
|
3297 |
|
|
.wb_cyc_i( wb_cyc_i ),
|
3298 |
|
|
.wb_ack_o( wb_ack_o ),
|
3299 |
|
|
.wb_adr_i(wb_adr_i),
|
3300 |
|
|
.wb_adr_int(wb_adr_int),
|
3301 |
|
|
.we_o( we_o ),
|
3302 |
|
|
.re_o(re_o)
|
3303 |
|
|
);
|
3304 |
|
|
`endif
|
3305 |
|
|
|
3306 |
|
|
// Registers
|
3307 |
|
|
uart_regs regs(
|
3308 |
|
|
.clk( wb_clk_i ),
|
3309 |
|
|
.wb_rst_i( wb_rst_i ),
|
3310 |
|
|
.wb_addr_i( wb_adr_int ),
|
3311 |
|
|
.wb_dat_i( wb_dat8_i ),
|
3312 |
|
|
.wb_dat_o( wb_dat8_o ),
|
3313 |
|
|
.wb_we_i( we_o ),
|
3314 |
|
|
.wb_re_i(re_o),
|
3315 |
|
|
.modem_inputs( {cts_pad_i, dsr_pad_i,
|
3316 |
|
|
ri_pad_i, dcd_pad_i} ),
|
3317 |
|
|
.stx_pad_o( stx_pad_o ),
|
3318 |
|
|
.srx_pad_i( srx_pad_i ),
|
3319 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
3320 |
|
|
`else
|
3321 |
|
|
// debug interface signals enabled
|
3322 |
|
|
.ier(ier),
|
3323 |
|
|
.iir(iir),
|
3324 |
|
|
.fcr(fcr),
|
3325 |
|
|
.mcr(mcr),
|
3326 |
|
|
.lcr(lcr),
|
3327 |
|
|
.msr(msr),
|
3328 |
|
|
.lsr(lsr),
|
3329 |
|
|
.rf_count(rf_count),
|
3330 |
|
|
.tf_count(tf_count),
|
3331 |
|
|
.tstate(tstate),
|
3332 |
|
|
.rstate(rstate),
|
3333 |
|
|
`endif
|
3334 |
|
|
.rts_pad_o( rts_pad_o ),
|
3335 |
|
|
.dtr_pad_o( dtr_pad_o ),
|
3336 |
|
|
.int_o( int_o )
|
3337 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
3338 |
|
|
, .baud_o(baud_o)
|
3339 |
|
|
`endif
|
3340 |
|
|
|
3341 |
|
|
);
|
3342 |
|
|
|
3343 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
3344 |
|
|
`else
|
3345 |
|
|
uart_debug_if dbg(/*AUTOINST*/
|
3346 |
|
|
// Outputs
|
3347 |
|
|
.wb_dat32_o (wb_dat32_o[31:0]),
|
3348 |
|
|
// Inputs
|
3349 |
|
|
.wb_adr_i (wb_adr_int[`UART_ADDR_WIDTH-1:0]),
|
3350 |
|
|
.ier (ier[3:0]),
|
3351 |
|
|
.iir (iir[3:0]),
|
3352 |
|
|
.fcr (fcr[1:0]),
|
3353 |
|
|
.mcr (mcr[4:0]),
|
3354 |
|
|
.lcr (lcr[7:0]),
|
3355 |
|
|
.msr (msr[7:0]),
|
3356 |
|
|
.lsr (lsr[7:0]),
|
3357 |
|
|
.rf_count (rf_count[`UART_FIFO_COUNTER_W-1:0]),
|
3358 |
|
|
.tf_count (tf_count[`UART_FIFO_COUNTER_W-1:0]),
|
3359 |
|
|
.tstate (tstate[2:0]),
|
3360 |
|
|
.rstate (rstate[3:0]));
|
3361 |
|
|
`endif
|
3362 |
|
|
|
3363 |
|
|
initial
|
3364 |
|
|
begin
|
3365 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
3366 |
|
|
$display("(%m) UART INFO: Data bus width is 8. No Debug interface.\n");
|
3367 |
|
|
`else
|
3368 |
|
|
$display("(%m) UART INFO: Data bus width is 32. Debug Interface present.\n");
|
3369 |
|
|
`endif
|
3370 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
3371 |
|
|
$display("(%m) UART INFO: Has baudrate output\n");
|
3372 |
|
|
`else
|
3373 |
|
|
$display("(%m) UART INFO: Doesn't have baudrate output\n");
|
3374 |
|
|
`endif
|
3375 |
|
|
end
|
3376 |
|
|
|
3377 |
|
|
endmodule
|
3378 |
|
|
|
3379 |
|
|
|