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

Subversion Repositories wbuart32

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

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
        rxuart  rx(i_clk, 1'b0, uart_setup, i_rx,
66
                        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
                        r_rx_data[11] <= rx_break;
75
                        r_rx_data[10] <= rx_ferr;
76
                        r_rx_data[ 9] <= rx_perr;
77
                        r_rx_data[7:0]<= rx_data_port;
78
                end
79
        always @(posedge i_clk)
80
                if(((i_wb_stb)&&(~i_wb_we)&&(i_wb_addr == `UART_RX_ADDR))
81
                                ||(rx_stb))
82
                        r_rx_data[8] <= !rx_stb;
83
        assign  o_cts = rx_stb;
84
        assign  rx_data = { 20'h00, r_rx_data };
85
        assign  rx_int = r_rx_data[8];
86
 
87
        //
88
        // Then the UART transmitter
89
        //
90
        wire    tx_busy;
91
        reg     [7:0]    r_tx_data;
92
        reg             r_tx_stb, r_tx_break;
93
        wire    [31:0]   tx_data;
94
        txuart  tx(i_clk, 1'b0, uart_setup,
95
                        r_tx_break, r_tx_stb, r_tx_data,
96
                        o_tx, tx_busy);
97
        always @(posedge i_clk)
98
                if ((i_wb_stb)&&(i_wb_addr == 5'h0f))
99
                begin
100
                        r_tx_stb <= (!r_tx_break)&&(!i_wb_data[8]);
101
                        r_tx_data <= i_wb_data[7:0];
102
                        r_tx_break<= i_wb_data[9];
103
                end else if (~tx_busy)
104
                begin
105
                        r_tx_stb <= 1'b0;
106
                        r_tx_data <= 8'h0;
107
                end
108
        assign  tx_data = { 20'h00,
109
                ck_uart, o_tx, r_tx_break, tx_busy,
110
                r_tx_data };
111
        assign  tx_int = ~tx_busy;
112
 
113
        always @(posedge i_clk)
114
                case(i_wb_addr)
115
                `UART_SETUP_ADDR: o_wb_data <= { 2'b00, uart_setup };
116
                `UART_RX_ADDR   : o_wb_data <= rx_data;
117
                `UART_TX_ADDR   : o_wb_data <= tx_data;
118
                // 
119
                // The rest of these address slots are left open here for
120
                // whatever else you might wish to connect to this bus/STB
121
                // line
122
                default: o_wb_data <= 32'h00;
123
                endcase
124
 
125
        assign  o_wb_stall = 1'b0;
126
        always @(posedge i_clk)
127
                o_wb_ack <= (i_wb_stb);
128
 
129
        // Interrupts sent to the board from here
130
        assign  o_board_ints = { rx_int, tx_int /* any other from this module */};
131
 

powered by: WebSVN 2.1.0

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