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

Subversion Repositories wbuart32

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

Go to most recent revision | 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
`define UART_SETUP      30'd25
54
        reg     [29:0]   uart_setup;
55
        initial uart_setup = `UART_SETUP;
56
        always @(posedge i_clk)
57
                if ((i_wb_stb)&&(i_wb_addr == `UART_SETUP_ADDR))
58
                        uart_setup[29:0] <= i_wb_data[29:0];
59
 
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
                if(((i_wb_stb)&&(~i_wb_we)&&(i_wb_addr == `UART_RX_ADDR))
87
                                ||(rx_stb))
88
                        r_rx_data[8] <= !rx_stb;
89 5 dgisselq
        assign  o_cts = !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
        //
94
        // Then the UART transmitter
95
        //
96
        wire    tx_busy;
97
        reg     [7:0]    r_tx_data;
98
        reg             r_tx_stb, r_tx_break;
99
        wire    [31:0]   tx_data;
100 5 dgisselq
        txuart  #(UART_SETUP) tx(i_clk, 1'b0, uart_setup,
101 2 dgisselq
                        r_tx_break, r_tx_stb, r_tx_data,
102
                        o_tx, tx_busy);
103
        always @(posedge i_clk)
104
                if ((i_wb_stb)&&(i_wb_addr == 5'h0f))
105
                begin
106
                        r_tx_stb <= (!r_tx_break)&&(!i_wb_data[8]);
107
                        r_tx_data <= i_wb_data[7:0];
108
                        r_tx_break<= i_wb_data[9];
109
                end else if (~tx_busy)
110
                begin
111
                        r_tx_stb <= 1'b0;
112
                        r_tx_data <= 8'h0;
113
                end
114
        assign  tx_data = { 20'h00,
115
                ck_uart, o_tx, r_tx_break, tx_busy,
116
                r_tx_data };
117
        assign  tx_int = ~tx_busy;
118
 
119
        always @(posedge i_clk)
120
                case(i_wb_addr)
121
                `UART_SETUP_ADDR: o_wb_data <= { 2'b00, uart_setup };
122
                `UART_RX_ADDR   : o_wb_data <= rx_data;
123
                `UART_TX_ADDR   : o_wb_data <= tx_data;
124
                // 
125
                // The rest of these address slots are left open here for
126
                // whatever else you might wish to connect to this bus/STB
127
                // line
128
                default: o_wb_data <= 32'h00;
129
                endcase
130
 
131
        assign  o_wb_stall = 1'b0;
132
        always @(posedge i_clk)
133
                o_wb_ack <= (i_wb_stb);
134
 
135
        // Interrupts sent to the board from here
136
        assign  o_board_ints = { rx_int, tx_int /* any other from this module */};
137
 

powered by: WebSVN 2.1.0

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