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

Subversion Repositories steelcore

[/] [soc/] [uart_tx.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
//////////////////////////////////////////////////////////////////////////////////
2
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com) 
3
// 
4
// Create Date: 05.08.2020 13:52:21
5
// Module Name: uart_tx
6
// Project Name: Steel SoC 
7
// Description: UART transmitter (9600 baud, 1 stop bit, no parity, no control)
8
// 
9
// Dependencies: -
10
// 
11
// Version 0.01
12
// 
13
//////////////////////////////////////////////////////////////////////////////////
14
 
15
/*********************************************************************************
16
 
17
MIT License
18
 
19
Copyright (c) 2020 Rafael de Oliveira Calçada
20
 
21
Permission is hereby granted, free of charge, to any person obtaining a copy
22
of this software and associated documentation files (the "Software"), to deal
23
in the Software without restriction, including without limitation the rights
24
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
copies of the Software, and to permit persons to whom the Software is
26
furnished to do so, subject to the following conditions:
27
 
28
The above copyright notice and this permission notice shall be included in all
29
copies or substantial portions of the Software.
30
 
31
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
SOFTWARE.
38
 
39
********************************************************************************/
40
 
41
 
42
`timescale 1ns / 1ps
43
 
44
module uart_tx(
45
 
46
    input wire CLK,
47
    input wire [7:0] WDATA,
48
    input wire WR_EN,
49
    output wire [31:0] RDATA,
50
    output reg TX
51
 
52
    );
53
 
54
    // Regs and wires
55
    wire done;
56
    reg [9:0] data;
57
    reg [14:0] timer;
58
    reg [3:0] index;
59
 
60
    // States
61
    parameter STATE_READY   = 2'b01;
62
    parameter STATE_LOAD    = 2'b10;
63
    parameter STATE_SEND    = 2'b00;
64
 
65
    // State registers
66
    reg [2:0] tx_state;
67
 
68
    // State update    
69
    always @(posedge CLK)
70
    begin
71
        case (tx_state)
72
            STATE_READY:
73
            begin
74
                if(WR_EN == 1'b1) tx_state <= STATE_LOAD;
75
                else tx_state <= STATE_READY;
76
            end
77
            STATE_LOAD: tx_state <= STATE_SEND;
78
            STATE_SEND:
79
            begin
80
                if(done)
81
                begin
82
                    if(index == 10) tx_state <= STATE_READY;
83
                    else tx_state <= STATE_LOAD;
84
                end
85
            end
86
            default: tx_state <= STATE_READY;
87
        endcase
88
    end
89
 
90
    // Timer
91
    always @(posedge CLK)
92
    begin
93
        if(tx_state == STATE_READY) timer <= 15'b0;
94
        else if(done) timer <= 15'b0;
95
        else timer <= timer + 1;
96
    end
97
 
98
    assign done = (timer == 5208) ? 1'b1 : 1'b0;
99
 
100
    // Data index update    
101
    always @(posedge CLK)
102
    begin
103
        if(tx_state == STATE_READY) index <= 1'b0;
104
        else if(tx_state == STATE_LOAD) index <= index + 1;
105
    end
106
 
107
    // Data update
108
    always @(posedge CLK)
109
    begin
110
        if(tx_state == STATE_READY && WR_EN == 1'b1) data <= {1'b1, WDATA, 1'b0};
111
    end
112
 
113
    // Output generation
114
    always @(posedge CLK)
115
    begin
116
        if(tx_state == STATE_READY) TX <= 1'b1;
117
        else if(tx_state == STATE_LOAD) TX <= data[index];
118
        else TX <= TX;
119
    end
120
 
121
    // Output assignments
122
    assign RDATA = {31'b0, tx_state[0]};
123
 
124
endmodule

powered by: WebSVN 2.1.0

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