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

Subversion Repositories rtfsimpleuart

[/] [rtfsimpleuart/] [trunk/] [rtl/] [verilog/] [rtfSimpleUartTx.v] - Blame information for rev 14

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

Line No. Rev Author Line
1 13 robfinch
// ============================================================================
2
//      (C) 2011,2013  Robert Finch
3
//  All rights reserved.
4
//      robfinch@<remove>finitron.ca
5
//
6
//      rtfSimpleUartTx.v
7
//
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are met:
10
//     * Redistributions of source code must retain the above copyright
11
//       notice, this list of conditions and the following disclaimer.
12
//     * Redistributions in binary form must reproduce the above copyright
13
//       notice, this list of conditions and the following disclaimer in the
14
//       documentation and/or other materials provided with the distribution.
15
//     * Neither the name of the <organization> nor the
16
//       names of its contributors may be used to endorse or promote products
17
//       derived from this software without specific prior written permission.
18
//
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
23
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
//
30
//              Simple uart transmitter core.
31
//              Features:
32
//                      Fixed format 1 start - 8 data - 1 stop bits
33
//
34
//
35
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36
//      |WISHBONE Datasheet
37
//      |WISHBONE SoC Architecture Specification, Revision B.3
38
//      |
39
//      |Description:                                           Specifications:
40
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41
//      |General Description:                           simple serial UART transmitter
42
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43
//      |Supported Cycles:                                      SLAVE,WRITE
44
//      |                                                                       SLAVE,BLOCK WRITE
45
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46
//      |Data port, size:                                       8 bit
47
//      |Data port, granularity:                        8 bit
48
//      |Data port, maximum operand size:       8 bit
49
//      |Data transfer ordering:                        Undefined
50
//      |Data transfer sequencing:                      Undefined
51
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52
//      |Clock frequency constraints:           none
53
//  |      Baud Generates by X16 or X8 CLK_I depends on baud8x pin
54
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55
//      |Supported signal list and                      Signal Name             WISHBONE equiv.
56
//      |cross reference to equivalent          ack_o                   ACK_O
57
//      |WISHBONE signals                                       
58
//      |                                                                       clk_i                   CLK_I
59
//      |                                   rst_i           RST_I 
60
//      |                                                                       dat_i[7:0]              DAT_I()
61
//      |                                                                       cyc_i                   CYC_I
62
//      |                                                                       stb_i                   STB_I
63
//      |                                                                       we_i                    WE_I
64
//      |
65
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66
//      |Special requirements:
67
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68
//
69
//
70
//      REF: Spartan3 - 4
71
//      30 LUTs / 23 slices / 165MHz
72
//============================================================================ */
73 4 robfinch
 
74
module rtfSimpleUartTx(
75
        // WISHBONE SoC bus interface
76
        input rst_i,            // reset
77
        input clk_i,            // clock
78
        input cyc_i,            // cycle valid
79
        input stb_i,            // strobe
80
        output ack_o,           // transfer done
81
        input we_i,                     // write transmitter
82
        input [7:0] dat_i,       // data in
83
        //--------------------
84
        input cs_i,                     // chip select
85
        input baud16x_ce,       // baud rate clock enable
86 12 AlexRayne
    input tri0 baud8x,       // switches to mode baudX8
87 4 robfinch
        input cts,                      // clear to send
88
        output txd,                     // external serial output
89 12 AlexRayne
        output reg empty,       // buffer is empty
90
    output reg txc          // tx complete flag
91 4 robfinch
);
92
 
93
reg [9:0] tx_data;       // transmit data working reg (raw)
94
reg [7:0] fdo;           // data output
95
reg [7:0] cnt;           // baud clock counter
96
reg rd;
97
 
98 12 AlexRayne
wire isX8;
99
buf(isX8, baud8x);
100
reg  modeX8;
101
 
102 4 robfinch
assign ack_o = cyc_i & stb_i & cs_i;
103
assign txd = tx_data[0];
104
 
105
always @(posedge clk_i)
106
        if (ack_o & we_i) fdo <= dat_i;
107
 
108
// set full / empty status
109
always @(posedge clk_i)
110
        if (rst_i) empty <= 1;
111
        else begin
112
        if (ack_o & we_i) empty <= 0;
113
        else if (rd) empty <= 1;
114
        end
115
 
116 12 AlexRayne
`define CNT_FINISH (8'h9F)
117 4 robfinch
always @(posedge clk_i)
118
        if (rst_i) begin
119 12 AlexRayne
                cnt <= `CNT_FINISH;
120 4 robfinch
                rd <= 0;
121
                tx_data <= 10'h3FF;
122 12 AlexRayne
        txc <= 1'b1;
123
        modeX8 <= 1'b0;
124 4 robfinch
        end
125
        else begin
126
 
127
                rd <= 0;
128
 
129
                if (baud16x_ce) begin
130
 
131
                        // Load next data ?
132 12 AlexRayne
                        if (cnt==`CNT_FINISH) begin
133
                modeX8 <= isX8;
134 4 robfinch
                                if (!empty && cts) begin
135
                                        tx_data <= {1'b1,fdo,1'b0};
136
                                        rd <= 1;
137 12 AlexRayne
                    cnt <= modeX8;
138
                    txc <= 1'b0;
139 4 robfinch
                                end
140 12 AlexRayne
                else
141
                    txc <= 1'b1;
142 4 robfinch
                        end
143
                        // Shift the data out. LSB first.
144 12 AlexRayne
                        else begin
145
                cnt[7:1] <= cnt[7:1] + cnt[0];
146
                cnt[0] <= ~cnt[0] | (modeX8);
147 4 robfinch
 
148 12 AlexRayne
                if (cnt[3:0]==4'hF)
149
                    tx_data <= {1'b1,tx_data[9:1]};
150
            end
151 4 robfinch
                end
152
        end
153
 
154
endmodule

powered by: WebSVN 2.1.0

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