OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [host/] [common/] [uart.v] - Blame information for rev 15

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

Line No. Rev Author Line
1 8 gdevic
// Simple transmit-only UART model
2
 
3
module uart #(
4
    parameter BAUD = 115200,
5
    parameter IN_CLOCK = 50000000)
6
(
7
    // Outputs
8
    output wire busy,          // Set when busy transmitting
9
    output reg uart_tx,        // UART transmit wire
10
    // Inputs
11
    input wire wr,             // Write a new byte to transmit
12
    input wire [7:0] data,     // 8-bit data
13
    input wire clk,
14
    input wire reset
15
);
16
 
17
reg [3:0] bitcount;
18
reg [8:0] shifter;
19
 
20
assign busy = |bitcount[3:1];
21
wire sending = |bitcount;
22
 
23
// Calculate UART clock based on the input clock
24
reg [28:0] d;
25 14 gdevic
wire [28:0] inc = d[28] ? 29'(BAUD) : 29'(BAUD - IN_CLOCK);
26 8 gdevic
wire [28:0] delta = d + inc;
27
 
28
always @(posedge clk)
29
begin
30
    if (reset)
31
    begin
32
        d = 0;
33
    end else
34
    begin
35
        d = delta;
36
    end
37
end
38
 
39
wire ser_clk = ~d[28]; // UART clock
40
 
41
always @(posedge clk) begin
42
    if (reset)
43
    begin
44
        uart_tx <= 1;
45
        bitcount <= 0;
46
        shifter <= 0;
47
    end else
48
    begin
49
        if (wr & ~busy)
50
        begin
51 14 gdevic
            // synopsys translate_off
52 8 gdevic
            $strobe("[UART] %c", data[7:0]);
53 14 gdevic
            // synopsys translate_on
54 8 gdevic
            shifter <= { data[7:0], 1'h0 };
55
            bitcount <= 4'd11; // 1 + 8 + 2
56
        end
57
 
58
        if (sending & ser_clk)
59
        begin
60
            { shifter, uart_tx } <= { 1'h1, shifter };
61
            bitcount <= bitcount - 4'd1;
62
        end
63
    end
64
end
65
 
66
endmodule

powered by: WebSVN 2.1.0

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