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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [rtl/] [wbuart-insert.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbuart-insert.v
4
//
5
// Project:     wbuart32, a full featured UART with simulator
6
//
7
// Purpose:     This is not a module file.  It is an example of the types of
8
//              lines and connections which can be used to connect this UART
9
//      to a local wishbone bus.  It was drawn from a working file, and
10
//      modified here for show, so ... let me know if I messed anything up
11
//      along the way.
12
//
13
//      Why isn't this a full module file?  Because I tend to lump all of my
14
//      single cycle I/O peripherals into one module file.  It makes the logic
15
//      simpler.  This particular file was extracted from the fastio.v file
16
//      within the openarty project.
17
//
18
// Creator:     Dan Gisselquist, Ph.D.
19
//              Gisselquist Technology, LLC
20
//
21
////////////////////////////////////////////////////////////////////////////////
22
//
23
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
24
//
25
// This program is free software (firmware): you can redistribute it and/or
26
// modify it under the terms of  the GNU General Public License as published
27
// by the Free Software Foundation, either version 3 of the License, or (at
28
// your option) any later version.
29
//
30
// This program is distributed in the hope that it will be useful, but WITHOUT
31
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
32
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
33
// for more details.
34
//
35
// You should have received a copy of the GNU General Public License along
36
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
37
// target there if the PDF file isn't present.)  If not, see
38
// <http://www.gnu.org/licenses/> for a copy.
39
//
40
// License:     GPL, v3, as defined and found on www.gnu.org,
41
//              http://www.gnu.org/licenses/gpl.html
42
//
43
//
44
////////////////////////////////////////////////////////////////////////////////
45
//
46
//
47
 
48
 
49
        // Ideally, UART_SETUP is defined somewhere.  I commonly like to define
50
        // it to CLKRATE / BAUDRATE, to give me 8N1 performance.  4MB is useful
51
        // to me, so 100MHz / 4M = 25 could be the setup.  You can also use
52
        // 200MHz / 4MB = 50 ... it all depends upon your clock.
53 9 dgisselq
`define UART_SETUP      31'd25
54
        reg     [30:0]   uart_setup;
55 2 dgisselq
        initial uart_setup = `UART_SETUP;
56
        always @(posedge i_clk)
57
                if ((i_wb_stb)&&(i_wb_addr == `UART_SETUP_ADDR))
58 9 dgisselq
                        uart_setup[30:0] <= i_wb_data[30:0];
59 2 dgisselq
 
60
        //
61
        // First the UART receiver
62
        //
63
        wire    rx_stb, rx_break, rx_perr, rx_ferr, ck_uart;
64
        wire    [7:0]    rx_data_port;
65 5 dgisselq
        rxuart  #(UART_SETUP) rx(i_clk, 1'b0, uart_setup, i_rx,
66 2 dgisselq
                        rx_stb, rx_data_port, rx_break,
67
                        rx_perr, rx_ferr, ck_uart);
68
 
69
        wire    [31:0]   rx_data;
70
        reg     [11:0]   r_rx_data;
71
        always @(posedge i_clk)
72
                if (rx_stb)
73
                begin
74 5 dgisselq
                        r_rx_data[11] <= (r_rx_data[11])||(rx_break);
75
                        r_rx_data[10] <= (r_rx_data[10])||(rx_ferr);
76
                        r_rx_data[ 9] <= (r_rx_data[ 9])||(rx_perr);
77 2 dgisselq
                        r_rx_data[7:0]<= rx_data_port;
78 5 dgisselq
                end else if ((i_wb_stb)&&(i_wb_we)
79
                                        &&(i_wb_addr == `UART_RX_ADDR))
80
                begin
81
                        r_rx_data[11] <= (rx_break)&& (!i_wb_data[11]);
82
                        r_rx_data[10] <= (rx_ferr) && (!i_wb_data[10]);
83
                        r_rx_data[ 9] <= (rx_perr) && (!i_wb_data[ 9]);
84 2 dgisselq
                end
85
        always @(posedge i_clk)
86 9 dgisselq
                if(((i_wb_stb)&&(!i_wb_we)&&(i_wb_addr == `UART_RX_ADDR))
87 2 dgisselq
                                ||(rx_stb))
88
                        r_rx_data[8] <= !rx_stb;
89 15 dgisselq
        assign  o_rts_n = r_rx_data[8];
90 2 dgisselq
        assign  rx_data = { 20'h00, r_rx_data };
91 5 dgisselq
        assign  rx_int = !r_rx_data[8];
92 2 dgisselq
 
93 15 dgisselq
        // Transmit hardware flow control, the cts line
94
        wire    cts_n;
95
        // Set this cts value to zero if you aren't ever going to use H/W flow
96 9 dgisselq
        // control, otherwise set it to the value coming in from the external
97 15 dgisselq
        // i_cts_n pin.
98
        assign  cts_n = i_cts_n;
99 9 dgisselq
 
100 2 dgisselq
        //
101
        // Then the UART transmitter
102
        //
103 9 dgisselq
        //
104
        //
105
        // Now onto the transmitter itself
106 2 dgisselq
        wire    tx_busy;
107
        reg     [7:0]    r_tx_data;
108
        reg             r_tx_stb, r_tx_break;
109
        wire    [31:0]   tx_data;
110 5 dgisselq
        txuart  #(UART_SETUP) tx(i_clk, 1'b0, uart_setup,
111 2 dgisselq
                        r_tx_break, r_tx_stb, r_tx_data,
112 15 dgisselq
                        cts_n, o_tx, tx_busy);
113 2 dgisselq
        always @(posedge i_clk)
114
                if ((i_wb_stb)&&(i_wb_addr == 5'h0f))
115
                begin
116 9 dgisselq
                        r_tx_stb  <= (!r_tx_break)&&(!i_wb_data[8]);
117 2 dgisselq
                        r_tx_data <= i_wb_data[7:0];
118
                        r_tx_break<= i_wb_data[9];
119 9 dgisselq
                end else if (!tx_busy)
120 2 dgisselq
                begin
121
                        r_tx_stb <= 1'b0;
122
                        r_tx_data <= 8'h0;
123
                end
124 15 dgisselq
        assign  tx_data = { 16'h00, cts_n, 3'h0,
125 2 dgisselq
                ck_uart, o_tx, r_tx_break, tx_busy,
126
                r_tx_data };
127
        assign  tx_int = ~tx_busy;
128
 
129
        always @(posedge i_clk)
130
                case(i_wb_addr)
131 9 dgisselq
                `UART_SETUP_ADDR: o_wb_data <= { 1'b0, uart_setup };
132 2 dgisselq
                `UART_RX_ADDR   : o_wb_data <= rx_data;
133
                `UART_TX_ADDR   : o_wb_data <= tx_data;
134
                // 
135
                // The rest of these address slots are left open here for
136
                // whatever else you might wish to connect to this bus/STB
137
                // line
138
                default: o_wb_data <= 32'h00;
139
                endcase
140
 
141
        assign  o_wb_stall = 1'b0;
142
        always @(posedge i_clk)
143
                o_wb_ack <= (i_wb_stb);
144
 
145
        // Interrupts sent to the board from here
146
        assign  o_board_ints = { rx_int, tx_int /* any other from this module */};
147
 

powered by: WebSVN 2.1.0

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