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

Subversion Repositories uart6551

[/] [uart6551/] [trunk/] [trunk/] [rtl/] [uart6551.sv] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
//        __
3 8 robfinch
//   \\__/ o\    (C) 2005-2022  Robert Finch, Waterloo
4 2 robfinch
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//
9 8 robfinch
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12 2 robfinch
//
13 8 robfinch
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35 2 robfinch
// ============================================================================
36
//
37
`define UART_TRB                2'd0    // transmit/receive buffer
38
`define UART_STAT               2'd1
39
`define UART_CMD                2'd2
40
`define UART_CTRL               2'd3
41
 
42
module uart6551(rst_i, clk_i, cs_i, irq_o,
43
        cyc_i, stb_i, ack_o, we_i, sel_i, adr_i, dat_i, dat_o,
44
        cts_ni, rts_no, dsr_ni, dcd_ni, dtr_no, ri_ni,
45
        rxd_i, txd_o, data_present,
46
        rxDRQ_o, txDRQ_o,
47
        xclk_i, RxC_i
48
);
49 9 robfinch
parameter pClkFreq = 100;
50 2 robfinch
parameter pCounterBits = 24;
51
parameter pFifoSize = 1024;
52
parameter pClkDiv = 24'd1302;   // 9.6k baud, 200.000MHz clock
53
parameter HIGH = 1'b1;
54
parameter LOW = 1'b0;
55
input rst_i;
56
input clk_i;                    // eg 50.000MHz
57
input cs_i;             // circuit select
58
// WISHBONE -------------------------------
59
input cyc_i;            // bus cycle valid
60
input stb_i;
61
output ack_o;
62
input we_i;                     // 1 = write
63
input [3:0] sel_i;
64
input [3:2] adr_i;      // register address
65
input [31:0] dat_i;     // data input bus
66
output reg [31:0] dat_o;        // data output bus
67
//------------------------------------------
68
output reg irq_o;               // interrupt request
69
input cts_ni;                   // clear to send - (flow control) active low
70
output reg rts_no;              // request to send - (flow control) active low
71
input dsr_ni;   // data set ready - active low
72
input dcd_ni;   // data carrier detect - active low
73
output reg dtr_no;      // data terminal ready - active low
74
input ri_ni;            // ring indicator
75
input rxd_i;            // serial data in
76
output txd_o;           // serial data out
77
output data_present;
78
output rxDRQ_o; // reciever DMA request
79
output txDRQ_o; // transmitter DMA request
80
input xclk_i;           // external clock source
81
input RxC_i;            // external receiver clock source
82
 
83
reg accessCD;           // clock multiplier access flag
84
reg llb;                        // local loopback mode
85
reg dmaEnable;
86
// baud rate clock control
87
reg [4:0] baudRateSel;
88
reg selCD;                              // Use clock multiplier register
89
reg [pCounterBits-1:0] c;       // current count
90
reg [pCounterBits-1:0] ckdiv;   // baud rate clock divider
91
reg [pCounterBits-1:0] clkdiv;  // clock multiplier register
92
reg [1:0] xclks;        // synchronized external clock
93
reg [1:0] RxCs;         // synchronized external receiver clock
94
reg baud16;                     // 16x baud rate clock
95
wire baud16rx;          // reciever clock
96
reg xClkSrc;            // uart baud clock is external
97
reg rxClkSrc;           // receiver clock is external
98
 
99
// frame format registers
100
reg [3:0] wordLength;
101
reg stopBit;
102
reg [2:0] stopBits;
103
reg [2:0] parityCtrl;
104
wire [7:0] frameSize;
105
 
106
reg txBreak;            // transmit a break
107
 
108
wire rxFull;
109
wire rxEmpty;
110
wire txFull;
111
wire txEmpty;
112
reg hwfc;                       // hardware flow control enable
113
wire [7:0] lineStatusReg;
114
wire [7:0] modemStatusReg;
115
wire [7:0] irqStatusReg;
116
// interrupt
117
reg rxIe;
118
reg txIe;
119
reg modemStatusChangeIe;
120
wire modemStatusChange;
121
reg lineStatusChangeIe;
122
wire lineStatusChange;
123
reg rxToutIe;           // receiver timeout interrupt enable
124
reg [3:0] rxThres;      // receiver threshold for interrupt
125
reg [3:0] txThres;      // transmitter threshold for interrupt
126
reg rxTout;                     // receiver timeout
127 3 robfinch
wire [9:0] rxCnt;       // reciever counter value
128 2 robfinch
reg [7:0] rxToutMax;
129
reg [2:0] irqenc;       // encoded irq cause
130
wire rxITrig;           // receiver interrupt trigger level
131
wire txITrig;           // transmitter interrupt trigger level
132
// reciever errors
133
wire parityErr;         // reciever detected a parity error
134
wire frameErr;          // receiver char framing error
135
wire overrun;           // receiver over run
136
wire rxBreak;           // reciever detected a break
137
wire rxGErr;            // global error: there is at least one error in the reciever fifo
138
// modem controls
139
reg [1:0] ctsx;         // cts_n sampling
140
reg [1:0] dcdx;
141
reg [1:0] dsrx;
142
reg [1:0] rix;
143
reg deltaCts;
144
reg deltaDcd;
145
reg deltaDsr;
146
reg deltaRi;
147
 
148
// fifo
149
reg rxFifoClear;
150
reg txFifoClear;
151 8 robfinch
reg txClear;
152 2 robfinch
reg fifoEnable;
153
wire [3:0] rxQued;
154
wire [3:0] txQued;
155
 
156
// test
157
wire txd1;
158
 
159
assign data_present = ~rxEmpty;
160
 
161
assign rxITrig = rxQued >= rxThres;
162
assign txITrig = txQued <= txThres;
163
wire rxDRQ1 = (fifoEnable ? rxITrig : ~rxEmpty);
164
wire txDRQ1 = (fifoEnable ? txITrig : txEmpty);
165 3 robfinch
assign rxDRQ_o = dmaEnable & rxDRQ1;
166
assign txDRQ_o = dmaEnable & txDRQ1;
167 2 robfinch
wire rxIRQ = rxIe & rxDRQ1;
168
wire txIRQ = txIe & txDRQ1;
169
 
170
reg [7:0] cmd0, cmd1, cmd2, cmd3;
171
reg [7:0] ctrl0, ctrl1, ctrl2, ctrl3;
172
 
173
always @(posedge clk_i)
174
        irq_o <=
175
          rxIRQ
176
        | txIRQ
177
        | (rxTout & rxToutIe)
178
        | (lineStatusChange & lineStatusChangeIe)
179
        | (modemStatusChange & modemStatusChangeIe)
180
        ;
181
 
182
// Hold onto address and data an extra cycle.
183
// The extra cycle updates or reads the serial transmit / receive.
184
reg [31:0] dati;
185
always @(posedge clk_i)
186
        dati <= dat_i;
187
reg [3:2] adr_h;
188
always @(posedge clk_i)
189
        adr_h <= adr_i;
190
reg we;
191
always @(posedge clk_i)
192
        we <= we_i;
193
reg [3:0] sel;
194
always @(posedge clk_i)
195
        sel <= sel_i;
196
 
197
wire [7:0] rx_do;
198
wire rdrx = ack_o && adr_h==`UART_TRB && ~we && !accessCD;
199
wire txrx = ack_o && adr_h==`UART_TRB && !accessCD;
200
 
201
wire cs = cs_i & cyc_i & stb_i;
202
 
203
ack_gen #(
204
        .READ_STAGES(1),
205
        .WRITE_STAGES(0),
206
        .REGISTER_OUTPUT(1)
207
) uag1
208
(
209
        .clk_i(clk_i),
210
        .ce_i(1'b1),
211 8 robfinch
        .rid_i('d0),
212
        .wid_i('d0),
213
        .i(cs & ~we_i),
214 2 robfinch
        .we_i(cs & we_i),
215 8 robfinch
        .o(ack_o),
216
        .rid_o(),
217
        .wid_o()
218 2 robfinch
);
219
 
220
uart6551Rx uart_rx0
221
(
222
        .rst(rst_i),
223
        .clk(clk_i),
224
        .cyc(cyc_i),
225
        .cs(rdrx),
226
        .wr(we),
227
        .dout(rx_do),
228
        .ack(),
229
        .fifoEnable(fifoEnable),
230
        .fifoClear(rxFifoClear),
231
        .clearGErr(1'b0),
232
        .wordLength(wordLength),
233
        .parityCtrl(parityCtrl),
234
        .frameSize(frameSize),
235
        .stop_bits(stopBits),
236
        .baud16x_ce(baud16rx),
237
        .clear(1'b0),
238
        .rxd(llb ? txd1 : rxd_i),
239
        .full(),
240
        .empty(rxEmpty),
241
        .frameErr(frameErr),
242
        .overrun(overrun),
243
        .parityErr(parityErr),
244
        .break_o(rxBreak),
245
        .gerr(rxGErr),
246
        .qcnt(rxQued),
247
        .cnt(rxCnt)
248
);
249
 
250
uart6551Tx uart_tx0
251
(
252
        .rst(rst_i),
253
        .clk(clk_i),
254
        .cyc(cyc_i),
255
        .cs(txrx),
256
        .wr(we),
257
        .din(dati[7:0]),
258
        .ack(),
259
        .fifoEnable(fifoEnable),
260
        .fifoClear(txFifoClear),
261
        .txBreak(txBreak),
262
        .frameSize(frameSize),  // 16 x 10 bits
263
        .wordLength(wordLength),// 8 bits
264
        .parityCtrl(parityCtrl),// no parity
265
        .baud16x_ce(baud16),
266
        .cts(ctsx[1]|~hwfc),
267 8 robfinch
        .clear(txClear),
268 2 robfinch
        .txd(txd1),
269
        .full(txFull),
270
        .empty(txEmpty),
271
        .qcnt(txQued)
272
);
273
 
274
assign txd_o = llb ? 1'b1 : txd1;
275
 
276
assign lineStatusReg = {rxGErr,1'b0,txFull,rxBreak,1'b0,1'b0,1'b0,1'b0};
277
assign modemStatusChange = deltaDcd|deltaRi|deltaDsr|deltaCts;  // modem status delta
278
assign modemStatusReg = {1'b0,~rix[1],1'b0,~ctsx[1],deltaDcd, deltaRi, deltaDsr, deltaCts};
279
assign irqStatusReg = {irq_o,2'b00,irqenc,2'b00};
280
 
281
// mux the reg outputs
282
always @(posedge clk_i)
283 10 robfinch
if (cs) begin
284 2 robfinch
        case(adr_i)
285
        `UART_TRB:      dat_o <= accessCD ? {8'h0,clkdiv} : {24'h0,rx_do};      // receiver holding register
286
        `UART_STAT:     dat_o <= {irqStatusReg,modemStatusReg,lineStatusReg,irq_o,dsrx[1],dcdx[1],fifoEnable ? ~txFull : txEmpty,~rxEmpty,overrun,frameErr,parityErr};
287
        `UART_CMD:      dat_o <= {cmd3,cmd2,cmd1,cmd0};
288
        `UART_CTRL:     dat_o <= {ctrl3,ctrl2,ctrl1,ctrl0};
289
        endcase
290
end
291 10 robfinch
else
292
        dat_o <= 'd0;
293 2 robfinch
 
294
 
295
// register updates
296
always @(posedge clk_i)
297
if (rst_i) begin
298
        rts_no <= HIGH;
299
        dtr_no <= HIGH;
300
        // interrupts
301
        rxIe                            <= 1'b0;
302
        txIe                            <= 1'b0;
303
        modemStatusChangeIe     <= 1'b0;
304
        lineStatusChangeIe      <= 1'b0;
305
        hwfc                            <= 1'b0;
306
        modemStatusChangeIe     <= 1'b0;
307
        lineStatusChangeIe      <= 1'b0;
308
        dmaEnable                       <= 1'b0;
309
        // clock control
310
        baudRateSel <= 5'h0;
311
        rxClkSrc        <= 1'b0;                // ** 6551 defaults to zero (external receiver clock)
312
        clkdiv <= pClkDiv;
313
        // frame format
314
        wordLength      <= 4'd8;        // 8 bits
315
        stopBit         <= 1'b0;                // 1 stop bit
316
        parityCtrl      <= 3'd0;        // no parity
317
 
318
        txBreak         <= 1'b0;
319
        // Fifo control
320
        txFifoClear     <= 1'b1;
321
        rxFifoClear <= 1'b1;
322 8 robfinch
        txClear <= 1'b1;
323 2 robfinch
        fifoEnable      <= 1'b1;
324
        // Test
325
        llb                     <= 1'b0;
326
        selCD           <= 1'b0;
327
        accessCD   <= 1'b0;
328
end
329
else begin
330
 
331
        //llb <= 1'b1;
332
        rxFifoClear <= 1'b0;
333
        txFifoClear <= 1'b0;
334 8 robfinch
        txClear <= 1'b0;
335 2 robfinch
        ctrl2[1] <= 1'b0;
336
        ctrl2[2] <= 1'b0;
337
 
338
        if (ack_o & we) begin
339
                case (adr_h)    // synopsys full_case parallel_case
340
 
341
                `UART_TRB:
342
                        if (accessCD) begin
343
                                clkdiv <= dati;
344
                                accessCD <= 1'b0;
345
                                ctrl3[7] <= 1'b0;
346
                        end
347
 
348
                // Writing to the status register does a software reset of some bits.
349
                `UART_STAT:
350
                        begin
351
                                dtr_no <= HIGH;
352
                                rxIe <= 1'b0;
353
                                rts_no <= HIGH;
354
                                txIe <= 1'b0;
355
                                txBreak <= 1'b0;
356
                                llb <= 1'b0;
357
                        end
358
                `UART_CMD:
359
      begin
360
        if (sel[0]) begin
361
                cmd0 <= dati[7:0];
362
                                        dtr_no <= ~dati[0];
363
                rxIe   <= ~dati[1];
364
                case(dati[3:2])
365
                2'd0:   begin rts_no <= 1'b1; txIe <= 1'b0; txBreak <= 1'b0; end
366
                2'd1: begin rts_no <= 1'b0; txIe <= 1'b1; txBreak <= 1'b0; end
367
                2'd2: begin rts_no <= 1'b0; txIe <= 1'b0; txBreak <= 1'b0; end
368
                2'd3: begin rts_no <= 1'b0; txIe <= 1'b0; txBreak <= 1'b1; end
369
                endcase
370
                llb <= dati[4];
371
          parityCtrl <= dati[7:5];    //000=none,001=odd,011=even,101=force 1,111 = force 0
372
        end
373
        if (sel[1]) begin
374
                cmd1 <= dati[15:8];
375
                lineStatusChangeIe  <= dati[8];
376
                modemStatusChangeIe <= dati[9];
377
                rxToutIe <= dati[10];
378
        end
379
        if (sel[2])
380
                cmd2 <= dati[23:16];
381
        if (sel[3])
382
                cmd3 <= dati[31:24];
383
      end
384
 
385
    `UART_CTRL:
386
        begin
387
                if (sel[0]) begin
388
                        ctrl0 <= dati[7:0];
389
                baudRateSel[3:0] <= dati[3:0];
390
                                        rxClkSrc <= dati[4];                            // 1 = baud rate generator, 0 = external
391
          //11=5,10=6,01=7,00=8
392
          case(dati[6:5])
393
          2'd0: wordLength <= 6'd8;
394
          2'd1: wordLength <= 6'd7;
395
          2'd2: wordLength <= 6'd6;
396
          2'd3: wordLength <= 6'd5;
397
                endcase
398
          stopBit    <= dati[7];      //0=1,1=1.5 or 2
399
        end
400
                // Extended word length, values beyond 11 not supported.
401
        if (sel[1]) begin
402
                ctrl1 <= dati[15:8];
403
        end
404
        if (sel[2]) begin
405
                ctrl2 <= dati[23:16];
406
                fifoEnable <= dati[16];
407
                rxFifoClear <= dati[17];
408
                txFifoClear <= dati[18];
409
                case (dati[21:20])
410
                2'd0:   txThres <= 4'd1;                // one-byte
411
                2'd1:   txThres <= pFifoSize / 4;       // one-quarter full
412
                2'd2:   txThres <= pFifoSize / 2;       // one-half full
413
                2'd3:   txThres <= pFifoSize * 3 / 4;   // three-quarters full
414
                endcase
415
                case (dati[23:22])
416
                2'd0:   rxThres <= 4'd1;                // one-byte
417
                2'd1:   rxThres <= pFifoSize / 4;       // one-quarter full
418
                2'd2:   rxThres <= pFifoSize / 2;       // one-half full
419
                2'd3:   rxThres <= pFifoSize * 3 / 4;   // three quarters full
420
                endcase
421
        end
422
        if (sel[3]) begin
423
                ctrl3 <= dati[31:24];
424
                                        hwfc <= dati[24];
425
                                        dmaEnable <= dati[26];
426
                baudRateSel[4] <= dati[27];
427 8 robfinch
                txClear <= dati[29];
428 2 robfinch
                selCD <= dati[30];
429
                accessCD <= dati[31];
430
        end
431
      end
432
 
433
                default:
434
                        ;
435
                endcase
436
        end
437
end
438
 
439
// ----------------------------------------------------------------------------
440
// Baud rate control.
441
// ----------------------------------------------------------------------------
442
 
443
always @(posedge clk_i)
444
        xClkSrc <= baudRateSel==5'd0;
445
 
446
wire [pCounterBits-1:0] bclkdiv;
447 8 robfinch
uart6551BaudLUT #(.pClkFreq(pClkFreq), .pCounterBits(pCounterBits)) ublt1 (.a(baudRateSel), .o(bclkdiv));
448 2 robfinch
 
449
reg [pCounterBits-1:0] clkdiv2;
450
always @(posedge clk_i)
451
        clkdiv2 <= selCD ? clkdiv : bclkdiv;
452
 
453
always @(posedge clk_i)
454
if (rst_i)
455 9 robfinch
        c <= 24'd1;
456 2 robfinch
else begin
457
        c <= c + 2'd1;
458
        if (c >= clkdiv2)
459
                c <= 2'd1;
460
end
461
 
462
// for detecting an edge on the baud clock
463
wire ibaud16 = c == 2'd1;
464
 
465
// Detect an edge on the external clock
466
wire xclkEdge;
467
edge_det ed1(.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(xclks[1]), .pe(xclkEdge), .ne() );
468
 
469
// Detect an edge on the external clock
470
wire rxClkEdge;
471
edge_det ed2(.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(RxCs[1]), .pe(rxClkEdge), .ne() );
472
 
473 9 robfinch
always_comb
474 2 robfinch
if (xClkSrc)            // 16x external clock (xclk)
475
        baud16 <= xclkEdge;
476
else
477
        baud16 <= ibaud16;
478
 
479
assign baud16rx = rxClkSrc ? baud16 : rxClkEdge;
480
 
481
//------------------------------------------------------------
482
// external signal synchronization
483
//------------------------------------------------------------
484
 
485
// External receiver clock
486
always @(posedge clk_i)
487
        RxCs <= {RxCs[1:0],RxC_i};
488
 
489
// External baud clock
490
always @(posedge clk_i)
491
        xclks <= {xclks[1:0],xclk_i};
492
 
493
 
494
always @(posedge clk_i)
495
        ctsx <= {ctsx[0],llb?~rts_no:~cts_ni};
496
 
497
always @(posedge clk_i)
498
        dcdx <= {dcdx[0],~dcd_ni};
499
 
500
always @(posedge clk_i)
501
        dsrx <= {dsrx[0],llb?~dtr_no:~dsr_ni};
502
 
503
always @(posedge clk_i)
504
        rix <= {rix[0],~ri_ni};
505
 
506
//------------------------------------------------------------
507
// state change detectors
508
//------------------------------------------------------------
509
 
510
wire ne_stat;
511
edge_det ued3 (
512
        .rst(rst_i),
513
        .clk(clk_i),
514
        .ce(1'b1),
515
        .i(ack_o && adr_i==`UART_STAT && ~we_i && sel_i[2]),
516
        .pe(),
517
        .ne(ne_stat),
518
        .ee()
519
);
520
 
521
// detect a change on the dsr signal
522
always @(posedge clk_i)
523
if (rst_i)
524
        deltaDsr <= 1'b0;
525
else begin
526
        if (ne_stat)
527
                deltaDsr <= 0;
528
        else if (~deltaDsr)
529
                deltaDsr <= dsrx[1] ^ dsrx[0];
530
end
531
 
532
// detect a change on the dcd signal
533
always @(posedge clk_i)
534
if (rst_i)
535
        deltaDcd <= 1'b0;
536
else begin
537
        if (ne_stat)
538
                deltaDcd <= 0;
539
        else if (~deltaDcd)
540
                deltaDcd <= dcdx[1] ^ dcdx[0];
541
end
542
 
543
// detect a change on the cts signal
544
always @(posedge clk_i)
545
if (rst_i)
546
        deltaCts <= 1'b0;
547
else begin
548
        if (ne_stat)
549
                deltaCts <= 0;
550
        else if (~deltaCts)
551
                deltaCts <= ctsx[1] ^ ctsx[0];
552
end
553
 
554
// detect a change on the ri signal
555
always @(posedge clk_i)
556
if (rst_i)
557
        deltaRi <= 1'b0;
558
else begin
559
        if (ne_stat)
560
                deltaRi <= 0;
561
        else if (~deltaRi)
562
                deltaRi <= rix[1] ^ rix[0];
563
end
564
 
565
// detect a change in line status
566
reg [7:0] pLineStatusReg;
567
always @(posedge clk_i)
568
        pLineStatusReg <= lineStatusReg;
569
 
570
assign lineStatusChange = pLineStatusReg != lineStatusReg;
571
 
572
//-----------------------------------------------------
573
 
574
// compute recieve timeout
575
always @(wordLength)
576
        rxToutMax <= (wordLength << 2) + 6'd12;
577
 
578
always @(posedge clk_i)
579
if (rst_i)
580
        rxTout <= 1'b0;
581
else begin
582
        // read of receiver clears timeout counter
583
        if (rdrx)
584
                rxTout <= 1'b0;
585
        // Don't time out if the fifo is empty
586
        else if (rxCnt[9:4]==rxToutMax && ~rxEmpty)
587
                rxTout <= 1'b1;
588
end
589
 
590
 
591
//-----------------------------------------------------
592
// compute the 2x number of stop bits
593
always @*
594
if (stopBit==1'b0)          // one stop bit
595
        stopBits <= 3'd2;
596
else if (wordLength==6'd8 && parityCtrl != 3'd0)
597
        stopBits <= 3'd2;
598
else if (wordLength==6'd5 && parityCtrl == 3'd0)        // 5 bits - 1 1/2 stop bit
599
        stopBits <= 3'd3;
600
else
601
        stopBits <= 3'd4;          // two stop bits
602
 
603
 
604
// compute frame size
605
// frame size is one less
606
assign frameSize = {wordLength + 4'd1 + stopBits[2:1] + parityCtrl[0], stopBits[0],3'b0} - 1;
607
 
608
//-----------------------------------------------------
609
// encode IRQ mailbox
610 3 robfinch
always @(rxDRQ_o or rxTout or txDRQ_o or lineStatusChange or modemStatusChange)
611 2 robfinch
        irqenc <=
612
                lineStatusChange ? 3'd0 :
613 3 robfinch
                ~rxDRQ_o ? 3'd1 :
614 2 robfinch
                rxTout ? 3'd2 :
615 3 robfinch
                ~txDRQ_o ? 3'd3 :
616 2 robfinch
                modemStatusChange ? 3'd4 :
617
                3'd0;
618
 
619
endmodule

powered by: WebSVN 2.1.0

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