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

Subversion Repositories uart16550

[/] [uart16550/] [trunk/] [rtl/] [verilog/] [uart_regs.v] - Blame information for rev 58

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

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

powered by: WebSVN 2.1.0

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