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

Subversion Repositories pss

[/] [pss/] [trunk/] [pss/] [hdl/] [pss/] [udm/] [uart_tx.v] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 AlexAntono
/*
2
 PSS
3
 
4
 Copyright (c) 2016 Alexander Antonov <153287@niuitmo.ru>
5
 All rights reserved.
6
 
7
 Version 0.9
8
 
9
 The FreeBSD license
10
 
11
 Redistribution and use in source and binary forms, with or without
12
 modification, are permitted provided that the following conditions
13
 are met:
14
 
15
 1. Redistributions of source code must retain the above copyright
16
    notice, this list of conditions and the following disclaimer.
17
 2. Redistributions in binary form must reproduce the above
18
    copyright notice, this list of conditions and the following
19
    disclaimer in the documentation and/or other materials
20
    provided with the distribution.
21
 
22
 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
23
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
 PSS PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
 
36
 
37
module uart_tx
38
(
39
        input clk_i, rst_i,
40
 
41
        input tx_start_i,
42
        input [7:0] din_bi,
43
 
44
        input locked_i,
45
        input [28:0] bitperiod_i,
46
 
47
        output reg tx_done_tick_o,
48
    output reg tx_o
49
);
50
 
51
reg [7:0]        databuf;
52
reg [3:0]        state;
53
reg [31:0]       clk_counter;
54
reg [2:0]        bit_counter;
55
 
56
localparam ST_IDLE              = 8'h0;
57
localparam ST_START     = 8'h1;
58
localparam ST_TX_DATA   = 8'h2;
59
localparam ST_STOP              = 8'h3;
60
 
61
always @(posedge clk_i)
62
        begin
63
        if (rst_i)
64
                begin
65
                state <= ST_IDLE;
66
                databuf <= 8'h0;
67
                clk_counter <= 32'h0;
68
                tx_o <= 1'b1;
69
                tx_done_tick_o <= 1'b0;
70
                end
71
        else
72
                begin
73
 
74
                tx_done_tick_o <= 1'b0;
75
 
76
                case (state)
77
 
78
                        ST_IDLE:
79
                                begin
80
                                tx_o <= 1'b1;
81
                                if ((tx_start_i == 1'b1) && (locked_i == 1'b1))
82
                                        begin
83
                                        tx_o <= 1'b0;
84
                                        state <= ST_START;
85
                                        databuf <= din_bi;
86
                                        clk_counter <= 32'h0;
87
                                        end
88
                                end
89
 
90
                        ST_START:
91
                                begin
92
                                clk_counter <= clk_counter + 32'h1;
93
                                if (clk_counter == {3'h0, bitperiod_i})
94
                                        begin
95
                                        state <= ST_TX_DATA;
96
                                        clk_counter <= 32'h0;
97
                                        bit_counter <= 3'h0;
98
                                        tx_o <= databuf[0];
99
                                        databuf <= {1'b0, databuf[7:1]};
100
                                        end
101
                                end
102
 
103
                        ST_TX_DATA:
104
                                begin
105
                                clk_counter <= clk_counter + 32'h1;
106
                                if (clk_counter == {3'h0, bitperiod_i})
107
                                        begin
108
                                        clk_counter <= 32'h0;
109
                                        bit_counter <= bit_counter + 3'h1;
110
                                        if (bit_counter == 3'h7)
111
                                                begin
112
                                                tx_o <= 1'b1;
113
                                                state <= ST_STOP;
114
                                                end
115
                                        else
116
                                                begin
117
                                                tx_o <= databuf[0];
118
                                                databuf <= {1'b0, databuf[7:1]};
119
                                                end
120
                                        end
121
                                end
122
 
123
                        ST_STOP:
124
                                begin
125
                                clk_counter <= clk_counter + 32'h1;
126
                                if (clk_counter == {2'h0, bitperiod_i, 1'b0})           // 2 * bit
127
                                        begin
128
                                        tx_o <= 1'b1;
129
                                        tx_done_tick_o <= 1'b1;
130
                                        state <= ST_IDLE;
131
                                        end
132
                                end
133
 
134
                endcase
135
 
136
                end
137
        end
138
 
139
endmodule

powered by: WebSVN 2.1.0

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