1 |
13 |
gorban |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// uart_regs.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 |
|
|
//// Registers of the uart 16550 core ////
|
19 |
|
|
//// ////
|
20 |
|
|
//// Known problems (limits): ////
|
21 |
|
|
//// Inserts 1 wait state in all WISHBONE transfers ////
|
22 |
|
|
//// ////
|
23 |
|
|
//// To Do: ////
|
24 |
|
|
//// Nothing or verification. ////
|
25 |
|
|
//// ////
|
26 |
|
|
//// Author(s): ////
|
27 |
|
|
//// - gorban@opencores.org ////
|
28 |
|
|
//// - Jacob Gorban ////
|
29 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
30 |
|
|
//// ////
|
31 |
|
|
//// Created: 2001/05/12 ////
|
32 |
|
|
//// Last Updated: (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: not supported by cvs2svn $
|
65 |
|
|
// Revision 1.39 2002/07/29 21:16:18 gorban
|
66 |
|
|
// The uart_for_irda_defines.v file is included again in sources.
|
67 |
|
|
//
|
68 |
|
|
// Revision 1.38 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 |
|
|
// Revision 1.37 2001/12/27 13:24:09 mohor
|
85 |
|
|
// lsr[7] was not showing overrun errors.
|
86 |
|
|
//
|
87 |
|
|
// Revision 1.36 2001/12/20 13:25:46 mohor
|
88 |
|
|
// rx push changed to be only one cycle wide.
|
89 |
|
|
//
|
90 |
|
|
// Revision 1.35 2001/12/19 08:03:34 mohor
|
91 |
|
|
// Warnings cleared.
|
92 |
|
|
//
|
93 |
|
|
// Revision 1.34 2001/12/19 07:33:54 mohor
|
94 |
|
|
// Synplicity was having troubles with the comment.
|
95 |
|
|
//
|
96 |
|
|
// Revision 1.33 2001/12/17 10:14:43 mohor
|
97 |
|
|
// Things related to msr register changed. After THRE IRQ occurs, and one
|
98 |
|
|
// character is written to the transmit fifo, the detection of the THRE bit in the
|
99 |
|
|
// LSR is delayed for one character time.
|
100 |
|
|
//
|
101 |
|
|
// Revision 1.32 2001/12/14 13:19:24 mohor
|
102 |
|
|
// MSR register fixed.
|
103 |
|
|
//
|
104 |
|
|
// Revision 1.31 2001/12/14 10:06:58 mohor
|
105 |
|
|
// After reset modem status register MSR should be reset.
|
106 |
|
|
//
|
107 |
|
|
// Revision 1.30 2001/12/13 10:09:13 mohor
|
108 |
|
|
// thre irq should be cleared only when being source of interrupt.
|
109 |
|
|
//
|
110 |
|
|
// Revision 1.29 2001/12/12 09:05:46 mohor
|
111 |
|
|
// LSR status bit 0 was not cleared correctly in case of reseting the FCR (rx fifo).
|
112 |
|
|
//
|
113 |
|
|
// Revision 1.28 2001/12/10 19:52:41 gorban
|
114 |
|
|
// Scratch register added
|
115 |
|
|
//
|
116 |
|
|
// Revision 1.27 2001/12/06 14:51:04 gorban
|
117 |
|
|
// Bug in LSR[0] is fixed.
|
118 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
119 |
|
|
//
|
120 |
|
|
// Revision 1.26 2001/12/03 21:44:29 gorban
|
121 |
|
|
// Updated specification documentation.
|
122 |
|
|
// Added full 32-bit data bus interface, now as default.
|
123 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
124 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
125 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
126 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
127 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
128 |
|
|
//
|
129 |
|
|
// Revision 1.25 2001/11/28 19:36:39 gorban
|
130 |
|
|
// Fixed: timeout and break didn't pay attention to current data format when counting time
|
131 |
|
|
//
|
132 |
|
|
// Revision 1.24 2001/11/26 21:38:54 gorban
|
133 |
|
|
// Lots of fixes:
|
134 |
|
|
// Break condition wasn't handled correctly at all.
|
135 |
|
|
// LSR bits could lose their values.
|
136 |
|
|
// LSR value after reset was wrong.
|
137 |
|
|
// Timing of THRE interrupt signal corrected.
|
138 |
|
|
// LSR bit 0 timing corrected.
|
139 |
|
|
//
|
140 |
|
|
// Revision 1.23 2001/11/12 21:57:29 gorban
|
141 |
|
|
// fixed more typo bugs
|
142 |
|
|
//
|
143 |
|
|
// Revision 1.22 2001/11/12 15:02:28 mohor
|
144 |
|
|
// lsr1r error fixed.
|
145 |
|
|
//
|
146 |
|
|
// Revision 1.21 2001/11/12 14:57:27 mohor
|
147 |
|
|
// ti_int_pnd error fixed.
|
148 |
|
|
//
|
149 |
|
|
// Revision 1.20 2001/11/12 14:50:27 mohor
|
150 |
|
|
// ti_int_d error fixed.
|
151 |
|
|
//
|
152 |
|
|
// Revision 1.19 2001/11/10 12:43:21 gorban
|
153 |
|
|
// Logic Synthesis bugs fixed. Some other minor changes
|
154 |
|
|
//
|
155 |
|
|
// Revision 1.18 2001/11/08 14:54:23 mohor
|
156 |
|
|
// Comments in Slovene language deleted, few small fixes for better work of
|
157 |
|
|
// old tools. IRQs need to be fix.
|
158 |
|
|
//
|
159 |
|
|
// Revision 1.17 2001/11/07 17:51:52 gorban
|
160 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
161 |
|
|
// Many bugs hopefully squashed.
|
162 |
|
|
//
|
163 |
|
|
// Revision 1.16 2001/11/02 09:55:16 mohor
|
164 |
|
|
// no message
|
165 |
|
|
//
|
166 |
|
|
// Revision 1.15 2001/10/31 15:19:22 gorban
|
167 |
|
|
// Fixes to break and timeout conditions
|
168 |
|
|
//
|
169 |
|
|
// Revision 1.14 2001/10/29 17:00:46 gorban
|
170 |
|
|
// fixed parity sending and tx_fifo resets over- and underrun
|
171 |
|
|
//
|
172 |
|
|
// Revision 1.13 2001/10/20 09:58:40 gorban
|
173 |
|
|
// Small synopsis fixes
|
174 |
|
|
//
|
175 |
|
|
// Revision 1.12 2001/10/19 16:21:40 gorban
|
176 |
|
|
// Changes data_out to be synchronous again as it should have been.
|
177 |
|
|
//
|
178 |
|
|
// Revision 1.11 2001/10/18 20:35:45 gorban
|
179 |
|
|
// small fix
|
180 |
|
|
//
|
181 |
|
|
// Revision 1.10 2001/08/24 21:01:12 mohor
|
182 |
|
|
// Things connected to parity changed.
|
183 |
|
|
// Clock devider changed.
|
184 |
|
|
//
|
185 |
|
|
// Revision 1.9 2001/08/23 16:05:05 mohor
|
186 |
|
|
// Stop bit bug fixed.
|
187 |
|
|
// Parity bug fixed.
|
188 |
|
|
// WISHBONE read cycle bug fixed,
|
189 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
190 |
|
|
// PE indicator (Parity Error) bug fixed.
|
191 |
|
|
// Register read bug fixed.
|
192 |
|
|
//
|
193 |
|
|
// Revision 1.10 2001/06/23 11:21:48 gorban
|
194 |
|
|
// DL made 16-bit long. Fixed transmission/reception bugs.
|
195 |
|
|
//
|
196 |
|
|
// Revision 1.9 2001/05/31 20:08:01 gorban
|
197 |
|
|
// FIFO changes and other corrections.
|
198 |
|
|
//
|
199 |
|
|
// Revision 1.8 2001/05/29 20:05:04 gorban
|
200 |
|
|
// Fixed some bugs and synthesis problems.
|
201 |
|
|
//
|
202 |
|
|
// Revision 1.7 2001/05/27 17:37:49 gorban
|
203 |
|
|
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
|
204 |
|
|
//
|
205 |
|
|
// Revision 1.6 2001/05/21 19:12:02 gorban
|
206 |
|
|
// Corrected some Linter messages.
|
207 |
|
|
//
|
208 |
|
|
// Revision 1.5 2001/05/17 18:34:18 gorban
|
209 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
210 |
|
|
//
|
211 |
|
|
// Revision 1.0 2001-05-17 21:27:11+02 jacob
|
212 |
|
|
// Initial revision
|
213 |
|
|
//
|
214 |
|
|
//
|
215 |
|
|
|
216 |
|
|
// synopsys translate_off
|
217 |
|
|
`include "timescale.v"
|
218 |
|
|
// synopsys translate_on
|
219 |
|
|
|
220 |
|
|
`include "uart_for_irda_defines.v"
|
221 |
|
|
|
222 |
|
|
`define UART_DL1 7:0
|
223 |
|
|
`define UART_DL2 15:8
|
224 |
|
|
|
225 |
|
|
module uart_regs (clk,
|
226 |
|
|
wb_rst_i, wb_addr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_re_i,
|
227 |
|
|
|
228 |
|
|
// additional signals
|
229 |
|
|
modem_inputs,
|
230 |
|
|
stx_pad_o, srx_pad_i,
|
231 |
|
|
|
232 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
233 |
|
|
`else
|
234 |
|
|
// debug interface signals enabled
|
235 |
|
|
ier, iir, fcr, mcr, lcr, msr, lsr, rf_count, tf_count, tstate, rstate,
|
236 |
|
|
`endif
|
237 |
|
|
rts_pad_o, dtr_pad_o, int_o
|
238 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
239 |
|
|
, baud_o
|
240 |
|
|
`endif
|
241 |
|
|
|
242 |
|
|
);
|
243 |
|
|
|
244 |
|
|
input clk;
|
245 |
|
|
input wb_rst_i;
|
246 |
|
|
input [`UART_ADDR_WIDTH-1:0] wb_addr_i;
|
247 |
|
|
input [7:0] wb_dat_i;
|
248 |
|
|
output [7:0] wb_dat_o;
|
249 |
|
|
input wb_we_i;
|
250 |
|
|
input wb_re_i;
|
251 |
|
|
|
252 |
|
|
output stx_pad_o;
|
253 |
|
|
input srx_pad_i;
|
254 |
|
|
|
255 |
|
|
input [3:0] modem_inputs;
|
256 |
|
|
output rts_pad_o;
|
257 |
|
|
output dtr_pad_o;
|
258 |
|
|
output int_o;
|
259 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
260 |
|
|
output baud_o;
|
261 |
|
|
`endif
|
262 |
|
|
|
263 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
264 |
|
|
`else
|
265 |
|
|
// if 32-bit databus and debug interface are enabled
|
266 |
|
|
output [3:0] ier;
|
267 |
|
|
output [3:0] iir;
|
268 |
|
|
output [1:0] fcr; /// bits 7 and 6 of fcr. Other bits are ignored
|
269 |
|
|
output [4:0] mcr;
|
270 |
|
|
output [7:0] lcr;
|
271 |
|
|
output [7:0] msr;
|
272 |
|
|
output [7:0] lsr;
|
273 |
|
|
output [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
274 |
|
|
output [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
275 |
|
|
output [2:0] tstate;
|
276 |
|
|
output [3:0] rstate;
|
277 |
|
|
|
278 |
|
|
`endif
|
279 |
|
|
|
280 |
|
|
wire [3:0] modem_inputs;
|
281 |
|
|
reg enable;
|
282 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
283 |
|
|
assign baud_o = enable; // baud_o is actually the enable signal
|
284 |
|
|
`endif
|
285 |
|
|
|
286 |
|
|
|
287 |
|
|
wire stx_pad_o; // received from transmitter module
|
288 |
|
|
wire srx_pad_i;
|
289 |
|
|
|
290 |
|
|
reg [7:0] wb_dat_o;
|
291 |
|
|
|
292 |
|
|
wire [`UART_ADDR_WIDTH-1:0] wb_addr_i;
|
293 |
|
|
wire [7:0] wb_dat_i;
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
reg [3:0] ier;
|
297 |
|
|
reg [3:0] iir;
|
298 |
|
|
reg [1:0] fcr; /// bits 7 and 6 of fcr. Other bits are ignored
|
299 |
|
|
reg [4:0] mcr;
|
300 |
|
|
reg [7:0] lcr;
|
301 |
|
|
reg [7:0] msr;
|
302 |
|
|
reg [15:0] dl; // 32-bit divisor latch
|
303 |
|
|
reg [7:0] scratch; // UART scratch register
|
304 |
|
|
reg start_dlc; // activate dlc on writing to UART_DL1
|
305 |
|
|
reg lsr_mask_d; // delay for lsr_mask condition
|
306 |
|
|
reg msi_reset; // reset MSR 4 lower bits indicator
|
307 |
|
|
//reg threi_clear; // THRE interrupt clear flag
|
308 |
|
|
reg [15:0] dlc; // 32-bit divisor latch counter
|
309 |
|
|
reg int_o;
|
310 |
|
|
|
311 |
|
|
reg [3:0] trigger_level; // trigger level of the receiver FIFO
|
312 |
|
|
reg rx_reset;
|
313 |
|
|
reg tx_reset;
|
314 |
|
|
|
315 |
|
|
wire dlab; // divisor latch access bit
|
316 |
|
|
wire cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i; // modem status bits
|
317 |
|
|
wire loopback; // loopback bit (MCR bit 4)
|
318 |
|
|
wire cts, dsr, ri, dcd; // effective signals
|
319 |
|
|
wire cts_c, dsr_c, ri_c, dcd_c; // Complement effective signals (considering loopback)
|
320 |
|
|
wire rts_pad_o, dtr_pad_o; // modem control outputs
|
321 |
|
|
|
322 |
|
|
// LSR bits wires and regs
|
323 |
|
|
wire [7:0] lsr;
|
324 |
|
|
wire lsr0, lsr1, lsr2, lsr3, lsr4, lsr5, lsr6, lsr7;
|
325 |
|
|
reg lsr0r, lsr1r, lsr2r, lsr3r, lsr4r, lsr5r, lsr6r, lsr7r;
|
326 |
|
|
wire lsr_mask; // lsr_mask
|
327 |
|
|
|
328 |
|
|
//
|
329 |
|
|
// ASSINGS
|
330 |
|
|
//
|
331 |
|
|
|
332 |
|
|
assign lsr[7:0] = { lsr7r, lsr6r, lsr5r, lsr4r, lsr3r, lsr2r, lsr1r, lsr0r };
|
333 |
|
|
|
334 |
|
|
assign {cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i} = modem_inputs;
|
335 |
|
|
assign {cts, dsr, ri, dcd} = ~{cts_pad_i,dsr_pad_i,ri_pad_i,dcd_pad_i};
|
336 |
|
|
|
337 |
|
|
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]}
|
338 |
|
|
: {cts_pad_i,dsr_pad_i,ri_pad_i,dcd_pad_i};
|
339 |
|
|
|
340 |
|
|
assign dlab = lcr[`UART_LC_DL];
|
341 |
|
|
assign loopback = mcr[4];
|
342 |
|
|
|
343 |
|
|
// assign modem outputs
|
344 |
|
|
assign rts_pad_o = mcr[`UART_MC_RTS];
|
345 |
|
|
assign dtr_pad_o = mcr[`UART_MC_DTR];
|
346 |
|
|
|
347 |
|
|
// Interrupt signals
|
348 |
|
|
wire rls_int; // receiver line status interrupt
|
349 |
|
|
wire rda_int; // receiver data available interrupt
|
350 |
|
|
wire ti_int; // timeout indicator interrupt
|
351 |
|
|
wire thre_int; // transmitter holding register empty interrupt
|
352 |
|
|
wire ms_int; // modem status interrupt
|
353 |
|
|
|
354 |
|
|
// FIFO signals
|
355 |
|
|
reg tf_push;
|
356 |
|
|
reg rf_pop;
|
357 |
|
|
wire [`UART_FIFO_REC_WIDTH-1:0] rf_data_out;
|
358 |
|
|
wire rf_error_bit; // an error (parity or framing) is inside the fifo
|
359 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
360 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
361 |
|
|
wire [2:0] tstate;
|
362 |
|
|
wire [3:0] rstate;
|
363 |
|
|
wire [9:0] counter_t;
|
364 |
|
|
|
365 |
|
|
wire thre_set_en; // THRE status is delayed one character time when a character is written to fifo.
|
366 |
|
|
reg [7:0] block_cnt; // While counter counts, THRE status is blocked (delayed one character cycle)
|
367 |
|
|
reg [7:0] block_value; // One character length minus stop bit
|
368 |
|
|
|
369 |
|
|
// Transmitter Instance
|
370 |
|
|
wire serial_out;
|
371 |
|
|
|
372 |
|
|
uart_transmitter transmitter(clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, serial_out, tstate, tf_count, tx_reset, lsr_mask);
|
373 |
|
|
|
374 |
|
|
// handle loopback
|
375 |
|
|
wire serial_in = loopback ? serial_out : srx_pad_i;
|
376 |
|
|
assign stx_pad_o = loopback ? 1'b1 : serial_out;
|
377 |
|
|
|
378 |
|
|
// Receiver Instance
|
379 |
|
|
uart_receiver receiver(clk, wb_rst_i, lcr, rf_pop, serial_in, enable,
|
380 |
|
|
counter_t, rf_count, rf_data_out, rf_error_bit, rf_overrun, rx_reset, lsr_mask, rstate, rf_push_pulse);
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
// Asynchronous reading here because the outputs are sampled in uart_wb.v file
|
384 |
|
|
always @(dl or dlab or ier or iir or scratch
|
385 |
|
|
or lcr or lsr or msr or rf_data_out or wb_addr_i or wb_re_i) // asynchrounous reading
|
386 |
|
|
begin
|
387 |
|
|
case (wb_addr_i)
|
388 |
|
|
`UART_REG_RB : wb_dat_o = dlab ? dl[`UART_DL1] : rf_data_out[10:3];
|
389 |
|
|
`UART_REG_IE : wb_dat_o = dlab ? dl[`UART_DL2] : ier;
|
390 |
|
|
`UART_REG_II : wb_dat_o = {4'b1100,iir};
|
391 |
|
|
`UART_REG_LC : wb_dat_o = lcr;
|
392 |
|
|
`UART_REG_LS : wb_dat_o = lsr;
|
393 |
|
|
`UART_REG_MS : wb_dat_o = msr;
|
394 |
|
|
`UART_REG_SR : wb_dat_o = scratch;
|
395 |
|
|
default: wb_dat_o = 8'b0; // ??
|
396 |
|
|
endcase // case(wb_addr_i)
|
397 |
|
|
end // always @ (dl or dlab or ier or iir or scratch...
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
// rf_pop signal handling
|
401 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
402 |
|
|
begin
|
403 |
|
|
if (wb_rst_i)
|
404 |
|
|
rf_pop <= #1 0;
|
405 |
|
|
else
|
406 |
|
|
if (rf_pop) // restore the signal to 0 after one clock cycle
|
407 |
|
|
rf_pop <= #1 0;
|
408 |
|
|
else
|
409 |
|
|
if (wb_re_i && wb_addr_i == `UART_REG_RB && !dlab)
|
410 |
|
|
rf_pop <= #1 1; // advance read pointer
|
411 |
|
|
end
|
412 |
|
|
|
413 |
|
|
wire lsr_mask_condition;
|
414 |
|
|
wire iir_read;
|
415 |
|
|
wire msr_read;
|
416 |
|
|
wire fifo_read;
|
417 |
|
|
wire fifo_write;
|
418 |
|
|
|
419 |
|
|
assign lsr_mask_condition = (wb_re_i && wb_addr_i == `UART_REG_LS && !dlab);
|
420 |
|
|
assign iir_read = (wb_re_i && wb_addr_i == `UART_REG_II && !dlab);
|
421 |
|
|
assign msr_read = (wb_re_i && wb_addr_i == `UART_REG_MS && !dlab);
|
422 |
|
|
assign fifo_read = (wb_re_i && wb_addr_i == `UART_REG_RB && !dlab);
|
423 |
|
|
assign fifo_write = (wb_we_i && wb_addr_i == `UART_REG_TR && !dlab);
|
424 |
|
|
|
425 |
|
|
// lsr_mask_d delayed signal handling
|
426 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
427 |
|
|
begin
|
428 |
|
|
if (wb_rst_i)
|
429 |
|
|
lsr_mask_d <= #1 0;
|
430 |
|
|
else // reset bits in the Line Status Register
|
431 |
|
|
lsr_mask_d <= #1 lsr_mask_condition;
|
432 |
|
|
end
|
433 |
|
|
|
434 |
|
|
// lsr_mask is rise detected
|
435 |
|
|
assign lsr_mask = lsr_mask_condition && ~lsr_mask_d;
|
436 |
|
|
|
437 |
|
|
// msi_reset signal handling
|
438 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
439 |
|
|
begin
|
440 |
|
|
if (wb_rst_i)
|
441 |
|
|
msi_reset <= #1 1;
|
442 |
|
|
else
|
443 |
|
|
if (msi_reset)
|
444 |
|
|
msi_reset <= #1 0;
|
445 |
|
|
else
|
446 |
|
|
if (msr_read)
|
447 |
|
|
msi_reset <= #1 1; // reset bits in Modem Status Register
|
448 |
|
|
end
|
449 |
|
|
|
450 |
|
|
|
451 |
|
|
//
|
452 |
|
|
// WRITES AND RESETS //
|
453 |
|
|
//
|
454 |
|
|
// Line Control Register
|
455 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
456 |
|
|
if (wb_rst_i)
|
457 |
|
|
lcr <= #1 8'b00000011; // 8n1 setting
|
458 |
|
|
else
|
459 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_LC)
|
460 |
|
|
lcr <= #1 wb_dat_i;
|
461 |
|
|
|
462 |
|
|
// Interrupt Enable Register or UART_DL2
|
463 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
464 |
|
|
if (wb_rst_i)
|
465 |
|
|
begin
|
466 |
|
|
ier <= #1 4'b0000; // no interrupts after reset
|
467 |
|
|
dl[`UART_DL2] <= #1 8'b0;
|
468 |
|
|
end
|
469 |
|
|
else
|
470 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_IE)
|
471 |
|
|
if (dlab)
|
472 |
|
|
begin
|
473 |
|
|
dl[`UART_DL2] <= #1 wb_dat_i;
|
474 |
|
|
end
|
475 |
|
|
else
|
476 |
|
|
ier <= #1 wb_dat_i[3:0]; // ier uses only 4 lsb
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
// FIFO Control Register and rx_reset, tx_reset signals
|
480 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
481 |
|
|
if (wb_rst_i) begin
|
482 |
|
|
fcr <= #1 2'b11;
|
483 |
|
|
rx_reset <= #1 0;
|
484 |
|
|
tx_reset <= #1 0;
|
485 |
|
|
end else
|
486 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_FC) begin
|
487 |
|
|
fcr <= #1 wb_dat_i[7:6];
|
488 |
|
|
rx_reset <= #1 wb_dat_i[1];
|
489 |
|
|
tx_reset <= #1 wb_dat_i[2];
|
490 |
|
|
end else begin
|
491 |
|
|
rx_reset <= #1 0;
|
492 |
|
|
tx_reset <= #1 0;
|
493 |
|
|
end
|
494 |
|
|
|
495 |
|
|
// Modem Control Register
|
496 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
497 |
|
|
if (wb_rst_i)
|
498 |
|
|
mcr <= #1 5'b0;
|
499 |
|
|
else
|
500 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_MC)
|
501 |
|
|
mcr <= #1 wb_dat_i[4:0];
|
502 |
|
|
|
503 |
|
|
// Scratch register
|
504 |
|
|
// Line Control Register
|
505 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
506 |
|
|
if (wb_rst_i)
|
507 |
|
|
scratch <= #1 0; // 8n1 setting
|
508 |
|
|
else
|
509 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_SR)
|
510 |
|
|
scratch <= #1 wb_dat_i;
|
511 |
|
|
|
512 |
|
|
// TX_FIFO or UART_DL1
|
513 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
514 |
|
|
if (wb_rst_i)
|
515 |
|
|
begin
|
516 |
|
|
dl[`UART_DL1] <= #1 8'b0;
|
517 |
|
|
tf_push <= #1 1'b0;
|
518 |
|
|
start_dlc <= #1 1'b0;
|
519 |
|
|
end
|
520 |
|
|
else
|
521 |
|
|
if (wb_we_i && wb_addr_i==`UART_REG_TR)
|
522 |
|
|
if (dlab)
|
523 |
|
|
begin
|
524 |
|
|
dl[`UART_DL1] <= #1 wb_dat_i;
|
525 |
|
|
start_dlc <= #1 1'b1; // enable DL counter
|
526 |
|
|
tf_push <= #1 1'b0;
|
527 |
|
|
end
|
528 |
|
|
else
|
529 |
|
|
begin
|
530 |
|
|
tf_push <= #1 1'b1;
|
531 |
|
|
start_dlc <= #1 1'b0;
|
532 |
|
|
end // else: !if(dlab)
|
533 |
|
|
else
|
534 |
|
|
begin
|
535 |
|
|
start_dlc <= #1 1'b0;
|
536 |
|
|
tf_push <= #1 1'b0;
|
537 |
|
|
end // else: !if(dlab)
|
538 |
|
|
|
539 |
|
|
// Receiver FIFO trigger level selection logic (asynchronous mux)
|
540 |
|
|
always @(fcr)
|
541 |
|
|
case (fcr[`UART_FC_TL])
|
542 |
|
|
2'b00 : trigger_level = 1;
|
543 |
|
|
2'b01 : trigger_level = 4;
|
544 |
|
|
2'b10 : trigger_level = 8;
|
545 |
|
|
2'b11 : trigger_level = 14;
|
546 |
|
|
endcase // case(fcr[`UART_FC_TL])
|
547 |
|
|
|
548 |
|
|
//
|
549 |
|
|
// STATUS REGISTERS //
|
550 |
|
|
//
|
551 |
|
|
|
552 |
|
|
// Modem Status Register
|
553 |
|
|
reg [3:0] delayed_modem_signals;
|
554 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
555 |
|
|
begin
|
556 |
|
|
if (wb_rst_i)
|
557 |
|
|
begin
|
558 |
|
|
msr <= #1 0;
|
559 |
|
|
delayed_modem_signals[3:0] <= #1 0;
|
560 |
|
|
end
|
561 |
|
|
else begin
|
562 |
|
|
msr[`UART_MS_DDCD:`UART_MS_DCTS] <= #1 msi_reset ? 4'b0 :
|
563 |
|
|
msr[`UART_MS_DDCD:`UART_MS_DCTS] | ({dcd, ri, dsr, cts} ^ delayed_modem_signals[3:0]);
|
564 |
|
|
msr[`UART_MS_CDCD:`UART_MS_CCTS] <= #1 {dcd_c, ri_c, dsr_c, cts_c};
|
565 |
|
|
delayed_modem_signals[3:0] <= #1 {dcd, ri, dsr, cts};
|
566 |
|
|
end
|
567 |
|
|
end
|
568 |
|
|
|
569 |
|
|
|
570 |
|
|
// Line Status Register
|
571 |
|
|
|
572 |
|
|
// activation conditions
|
573 |
|
|
assign lsr0 = (rf_count==0 && rf_push_pulse); // data in receiver fifo available set condition
|
574 |
|
|
assign lsr1 = rf_overrun; // Receiver overrun error
|
575 |
|
|
assign lsr2 = rf_data_out[1]; // parity error bit
|
576 |
|
|
assign lsr3 = rf_data_out[0]; // framing error bit
|
577 |
|
|
assign lsr4 = rf_data_out[2]; // break error in the character
|
578 |
|
|
assign lsr5 = (tf_count==5'b0 && thre_set_en); // transmitter fifo is empty
|
579 |
|
|
assign lsr6 = (tf_count==5'b0 && thre_set_en && (tstate == /*`S_IDLE */ 0)); // transmitter empty
|
580 |
|
|
assign lsr7 = rf_error_bit | rf_overrun;
|
581 |
|
|
|
582 |
|
|
// lsr bit0 (receiver data available)
|
583 |
|
|
reg lsr0_d;
|
584 |
|
|
|
585 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
586 |
|
|
if (wb_rst_i) lsr0_d <= #1 0;
|
587 |
|
|
else lsr0_d <= #1 lsr0;
|
588 |
|
|
|
589 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
590 |
|
|
if (wb_rst_i) lsr0r <= #1 0;
|
591 |
|
|
else lsr0r <= #1 (rf_count==1 && fifo_read || rx_reset) ? 0 : // deassert condition
|
592 |
|
|
lsr0r || (lsr0 && ~lsr0_d); // set on rise of lsr0 and keep asserted until deasserted
|
593 |
|
|
|
594 |
|
|
// lsr bit 1 (receiver overrun)
|
595 |
|
|
reg lsr1_d; // delayed
|
596 |
|
|
|
597 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
598 |
|
|
if (wb_rst_i) lsr1_d <= #1 0;
|
599 |
|
|
else lsr1_d <= #1 lsr1;
|
600 |
|
|
|
601 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
602 |
|
|
if (wb_rst_i) lsr1r <= #1 0;
|
603 |
|
|
else lsr1r <= #1 lsr_mask ? 0 : lsr1r || (lsr1 && ~lsr1_d); // set on rise
|
604 |
|
|
|
605 |
|
|
// lsr bit 2 (parity error)
|
606 |
|
|
reg lsr2_d; // delayed
|
607 |
|
|
|
608 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
609 |
|
|
if (wb_rst_i) lsr2_d <= #1 0;
|
610 |
|
|
else lsr2_d <= #1 lsr2;
|
611 |
|
|
|
612 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
613 |
|
|
if (wb_rst_i) lsr2r <= #1 0;
|
614 |
|
|
else lsr2r <= #1 lsr_mask ? 0 : lsr2r || (lsr2 && ~lsr2_d); // set on rise
|
615 |
|
|
|
616 |
|
|
// lsr bit 3 (framing error)
|
617 |
|
|
reg lsr3_d; // delayed
|
618 |
|
|
|
619 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
620 |
|
|
if (wb_rst_i) lsr3_d <= #1 0;
|
621 |
|
|
else lsr3_d <= #1 lsr3;
|
622 |
|
|
|
623 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
624 |
|
|
if (wb_rst_i) lsr3r <= #1 0;
|
625 |
|
|
else lsr3r <= #1 lsr_mask ? 0 : lsr3r || (lsr3 && ~lsr3_d); // set on rise
|
626 |
|
|
|
627 |
|
|
// lsr bit 4 (break indicator)
|
628 |
|
|
reg lsr4_d; // delayed
|
629 |
|
|
|
630 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
631 |
|
|
if (wb_rst_i) lsr4_d <= #1 0;
|
632 |
|
|
else lsr4_d <= #1 lsr4;
|
633 |
|
|
|
634 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
635 |
|
|
if (wb_rst_i) lsr4r <= #1 0;
|
636 |
|
|
else lsr4r <= #1 lsr_mask ? 0 : lsr4r || (lsr4 && ~lsr4_d);
|
637 |
|
|
|
638 |
|
|
// lsr bit 5 (transmitter fifo is empty)
|
639 |
|
|
reg lsr5_d;
|
640 |
|
|
|
641 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
642 |
|
|
if (wb_rst_i) lsr5_d <= #1 1;
|
643 |
|
|
else lsr5_d <= #1 lsr5;
|
644 |
|
|
|
645 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
646 |
|
|
if (wb_rst_i) lsr5r <= #1 1;
|
647 |
|
|
else lsr5r <= #1 (fifo_write) ? 0 : lsr5r || (lsr5 && ~lsr5_d);
|
648 |
|
|
|
649 |
|
|
// lsr bit 6 (transmitter empty indicator)
|
650 |
|
|
reg lsr6_d;
|
651 |
|
|
|
652 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
653 |
|
|
if (wb_rst_i) lsr6_d <= #1 1;
|
654 |
|
|
else lsr6_d <= #1 lsr6;
|
655 |
|
|
|
656 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
657 |
|
|
if (wb_rst_i) lsr6r <= #1 1;
|
658 |
|
|
else lsr6r <= #1 (fifo_write) ? 0 : lsr6r || (lsr6 && ~lsr6_d);
|
659 |
|
|
|
660 |
|
|
// lsr bit 7 (error in fifo)
|
661 |
|
|
reg lsr7_d;
|
662 |
|
|
|
663 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
664 |
|
|
if (wb_rst_i) lsr7_d <= #1 0;
|
665 |
|
|
else lsr7_d <= #1 lsr7;
|
666 |
|
|
|
667 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
668 |
|
|
if (wb_rst_i) lsr7r <= #1 0;
|
669 |
|
|
else lsr7r <= #1 lsr_mask ? 0 : lsr7r || (lsr7 && ~lsr7_d);
|
670 |
|
|
|
671 |
|
|
// Frequency divider
|
672 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
673 |
|
|
begin
|
674 |
|
|
if (wb_rst_i)
|
675 |
|
|
dlc <= #1 0;
|
676 |
|
|
else
|
677 |
|
|
if (start_dlc | ~ (|dlc))
|
678 |
|
|
dlc <= #1 dl - 1; // preset counter
|
679 |
|
|
else
|
680 |
|
|
dlc <= #1 dlc - 1; // decrement counter
|
681 |
|
|
end
|
682 |
|
|
|
683 |
|
|
// Enable signal generation logic
|
684 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
685 |
|
|
begin
|
686 |
|
|
if (wb_rst_i)
|
687 |
|
|
enable <= #1 1'b0;
|
688 |
|
|
else
|
689 |
|
|
if (|dl & ~(|dlc)) // dl>0 & dlc==0
|
690 |
|
|
enable <= #1 1'b1;
|
691 |
|
|
else
|
692 |
|
|
enable <= #1 1'b0;
|
693 |
|
|
end
|
694 |
|
|
|
695 |
|
|
// Delaying THRE status for one character cycle after a character is written to an empty fifo.
|
696 |
|
|
always @(lcr)
|
697 |
|
|
case (lcr[3:0])
|
698 |
|
|
4'b0000 : block_value = 95; // 6 bits
|
699 |
|
|
4'b0100 : block_value = 103; // 6.5 bits
|
700 |
|
|
4'b0001, 4'b1000 : block_value = 111; // 7 bits
|
701 |
|
|
4'b1100 : block_value = 119; // 7.5 bits
|
702 |
|
|
4'b0010, 4'b0101, 4'b1001 : block_value = 127; // 8 bits
|
703 |
|
|
4'b0011, 4'b0110, 4'b1010, 4'b1101 : block_value = 143; // 9 bits
|
704 |
|
|
4'b0111, 4'b1011, 4'b1110 : block_value = 159; // 10 bits
|
705 |
|
|
4'b1111 : block_value = 175; // 11 bits
|
706 |
|
|
endcase // case(lcr[3:0])
|
707 |
|
|
|
708 |
|
|
// Counting time of one character minus stop bit
|
709 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
710 |
|
|
begin
|
711 |
|
|
if (wb_rst_i)
|
712 |
|
|
block_cnt <= #1 8'd0;
|
713 |
|
|
else
|
714 |
|
|
if(lsr5r & fifo_write) // THRE bit set & write to fifo occured
|
715 |
|
|
block_cnt <= #1 block_value;
|
716 |
|
|
else
|
717 |
|
|
if (enable & block_cnt != 8'b0) // only work on enable times
|
718 |
|
|
block_cnt <= #1 block_cnt - 1; // decrement break counter
|
719 |
|
|
end // always of break condition detection
|
720 |
|
|
|
721 |
|
|
// Generating THRE status enable signal
|
722 |
|
|
assign thre_set_en = ~(|block_cnt);
|
723 |
|
|
|
724 |
|
|
|
725 |
|
|
//
|
726 |
|
|
// INTERRUPT LOGIC
|
727 |
|
|
//
|
728 |
|
|
|
729 |
|
|
assign rls_int = ier[`UART_IE_RLS] && (lsr[`UART_LS_OE] || lsr[`UART_LS_PE] || lsr[`UART_LS_FE] || lsr[`UART_LS_BI]);
|
730 |
|
|
assign rda_int = ier[`UART_IE_RDA] && (rf_count >= {1'b0,trigger_level});
|
731 |
|
|
assign thre_int = ier[`UART_IE_THRE] && lsr[`UART_LS_TFE];
|
732 |
|
|
assign ms_int = ier[`UART_IE_MS] && (| msr[3:0]);
|
733 |
|
|
assign ti_int = ier[`UART_IE_RDA] && (counter_t == 10'b0);
|
734 |
|
|
|
735 |
|
|
reg rls_int_d;
|
736 |
|
|
reg thre_int_d;
|
737 |
|
|
reg ms_int_d;
|
738 |
|
|
reg ti_int_d;
|
739 |
|
|
reg rda_int_d;
|
740 |
|
|
|
741 |
|
|
// delay lines
|
742 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
743 |
|
|
if (wb_rst_i) rls_int_d <= #1 0;
|
744 |
|
|
else rls_int_d <= #1 rls_int;
|
745 |
|
|
|
746 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
747 |
|
|
if (wb_rst_i) rda_int_d <= #1 0;
|
748 |
|
|
else rda_int_d <= #1 rda_int;
|
749 |
|
|
|
750 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
751 |
|
|
if (wb_rst_i) thre_int_d <= #1 0;
|
752 |
|
|
else thre_int_d <= #1 thre_int;
|
753 |
|
|
|
754 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
755 |
|
|
if (wb_rst_i) ms_int_d <= #1 0;
|
756 |
|
|
else ms_int_d <= #1 ms_int;
|
757 |
|
|
|
758 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
759 |
|
|
if (wb_rst_i) ti_int_d <= #1 0;
|
760 |
|
|
else ti_int_d <= #1 ti_int;
|
761 |
|
|
|
762 |
|
|
// rise detection signals
|
763 |
|
|
|
764 |
|
|
wire rls_int_rise;
|
765 |
|
|
wire thre_int_rise;
|
766 |
|
|
wire ms_int_rise;
|
767 |
|
|
wire ti_int_rise;
|
768 |
|
|
wire rda_int_rise;
|
769 |
|
|
|
770 |
|
|
assign rda_int_rise = rda_int & ~rda_int_d;
|
771 |
|
|
assign rls_int_rise = rls_int & ~rls_int_d;
|
772 |
|
|
assign thre_int_rise = thre_int & ~thre_int_d;
|
773 |
|
|
assign ms_int_rise = ms_int & ~ms_int_d;
|
774 |
|
|
assign ti_int_rise = ti_int & ~ti_int_d;
|
775 |
|
|
|
776 |
|
|
// interrupt pending flags
|
777 |
|
|
reg rls_int_pnd;
|
778 |
|
|
reg rda_int_pnd;
|
779 |
|
|
reg thre_int_pnd;
|
780 |
|
|
reg ms_int_pnd;
|
781 |
|
|
reg ti_int_pnd;
|
782 |
|
|
|
783 |
|
|
// interrupt pending flags assignments
|
784 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
785 |
|
|
if (wb_rst_i) rls_int_pnd <= #1 0;
|
786 |
|
|
else
|
787 |
|
|
rls_int_pnd <= #1 lsr_mask ? 0 : // reset condition
|
788 |
|
|
rls_int_rise ? 1 : // latch condition
|
789 |
|
|
rls_int_pnd && ier[`UART_IE_RLS]; // default operation: remove if masked
|
790 |
|
|
|
791 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
792 |
|
|
if (wb_rst_i) rda_int_pnd <= #1 0;
|
793 |
|
|
else
|
794 |
|
|
rda_int_pnd <= #1 ((rf_count == {1'b0,trigger_level}) && fifo_read) ? 0 : // reset condition
|
795 |
|
|
rda_int_rise ? 1 : // latch condition
|
796 |
|
|
rda_int_pnd && ier[`UART_IE_RDA]; // default operation: remove if masked
|
797 |
|
|
|
798 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
799 |
|
|
if (wb_rst_i) thre_int_pnd <= #1 0;
|
800 |
|
|
else
|
801 |
|
|
thre_int_pnd <= #1 fifo_write || (iir_read & ~iir[`UART_II_IP] & iir[`UART_II_II] == `UART_II_THRE)? 0 :
|
802 |
|
|
thre_int_rise ? 1 :
|
803 |
|
|
thre_int_pnd && ier[`UART_IE_THRE];
|
804 |
|
|
|
805 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
806 |
|
|
if (wb_rst_i) ms_int_pnd <= #1 0;
|
807 |
|
|
else
|
808 |
|
|
ms_int_pnd <= #1 msr_read ? 0 :
|
809 |
|
|
ms_int_rise ? 1 :
|
810 |
|
|
ms_int_pnd && ier[`UART_IE_MS];
|
811 |
|
|
|
812 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
813 |
|
|
if (wb_rst_i) ti_int_pnd <= #1 0;
|
814 |
|
|
else
|
815 |
|
|
ti_int_pnd <= #1 fifo_read ? 0 :
|
816 |
|
|
ti_int_rise ? 1 :
|
817 |
|
|
ti_int_pnd && ier[`UART_IE_RDA];
|
818 |
|
|
// end of pending flags
|
819 |
|
|
|
820 |
|
|
// INT_O logic
|
821 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
822 |
|
|
begin
|
823 |
|
|
if (wb_rst_i)
|
824 |
|
|
int_o <= #1 1'b0;
|
825 |
|
|
else
|
826 |
|
|
int_o <= #1
|
827 |
|
|
rls_int_pnd ? ~lsr_mask :
|
828 |
|
|
rda_int_pnd ? 1 :
|
829 |
|
|
ti_int_pnd ? ~fifo_read :
|
830 |
|
|
thre_int_pnd ? !(fifo_write & iir_read) :
|
831 |
|
|
ms_int_pnd ? ~msr_read :
|
832 |
|
|
0; // if no interrupt are pending
|
833 |
|
|
end
|
834 |
|
|
|
835 |
|
|
|
836 |
|
|
// Interrupt Identification register
|
837 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
838 |
|
|
begin
|
839 |
|
|
if (wb_rst_i)
|
840 |
|
|
iir <= #1 1;
|
841 |
|
|
else
|
842 |
|
|
if (rls_int_pnd) // interrupt is pending
|
843 |
|
|
begin
|
844 |
|
|
iir[`UART_II_II] <= #1 `UART_II_RLS; // set identification register to correct value
|
845 |
|
|
iir[`UART_II_IP] <= #1 1'b0; // and clear the IIR bit 0 (interrupt pending)
|
846 |
|
|
end else // the sequence of conditions determines priority of interrupt identification
|
847 |
|
|
if (rda_int)
|
848 |
|
|
begin
|
849 |
|
|
iir[`UART_II_II] <= #1 `UART_II_RDA;
|
850 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
851 |
|
|
end
|
852 |
|
|
else if (ti_int_pnd)
|
853 |
|
|
begin
|
854 |
|
|
iir[`UART_II_II] <= #1 `UART_II_TI;
|
855 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
856 |
|
|
end
|
857 |
|
|
else if (thre_int_pnd)
|
858 |
|
|
begin
|
859 |
|
|
iir[`UART_II_II] <= #1 `UART_II_THRE;
|
860 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
861 |
|
|
end
|
862 |
|
|
else if (ms_int_pnd)
|
863 |
|
|
begin
|
864 |
|
|
iir[`UART_II_II] <= #1 `UART_II_MS;
|
865 |
|
|
iir[`UART_II_IP] <= #1 1'b0;
|
866 |
|
|
end else // no interrupt is pending
|
867 |
|
|
begin
|
868 |
|
|
iir[`UART_II_II] <= #1 0;
|
869 |
|
|
iir[`UART_II_IP] <= #1 1'b1;
|
870 |
|
|
end
|
871 |
|
|
end
|
872 |
|
|
|
873 |
|
|
endmodule
|