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

Subversion Repositories uart16550

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

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

powered by: WebSVN 2.1.0

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