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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [uartdev.v] - Blame information for rev 7

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

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    uartdev.v
4
//
5
// Project:     XuLA2 board
6
//
7 7 dgisselq
// Purpose:     This is a simple wrapper around the txuart and rxuart
8
//              modules.  The purpose is to make both of those modules
9
//      configurable from a single wishbone address, and capable of receiving
10
//      (or transmitting) via reads (writes) from two other addresses.
11 2 dgisselq
//
12 7 dgisselq
//      It also generates interrupts: a receive interrupt strobe on the clock
13
//      when data is made available, and a transmit not busy level interrupt
14
//      which is held high as long as the transmitter is idle.  Both should be
15
//      able to work nicely with the programmable interrupt controllers found
16
//      in the ZipCPU project.
17 2 dgisselq
//
18 7 dgisselq
//
19 2 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
20
//              Gisselquist Technology, LLC
21
//
22
////////////////////////////////////////////////////////////////////////////////
23
//
24
// Copyright (C) 2015, Gisselquist Technology, LLC
25
//
26
// This program is free software (firmware): you can redistribute it and/or
27
// modify it under the terms of  the GNU General Public License as published
28
// by the Free Software Foundation, either version 3 of the License, or (at
29
// your option) any later version.
30
//
31
// This program is distributed in the hope that it will be useful, but WITHOUT
32
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
33
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
34
// for more details.
35
//
36
// License:     GPL, v3, as defined and found on www.gnu.org,
37
//              http://www.gnu.org/licenses/gpl.html
38
//
39
//
40
////////////////////////////////////////////////////////////////////////////////
41
//
42
//
43
module  uartdev(i_clk, i_rx_uart, o_tx_uart,
44
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
45
                        o_wb_ack, o_wb_stall, o_wb_data,
46
                o_rx_int, o_tx_int);
47
        parameter       DEFAULT_SETUP = { 2'b00, 1'b0, 1'b0, 2'b00, 24'd10417 };
48
        input                   i_clk, i_rx_uart;
49
        output  wire            o_tx_uart;
50
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
51
        input           [1:0]    i_wb_addr;
52
        input           [31:0]   i_wb_data;
53
        output  reg             o_wb_ack;
54
        output  wire            o_wb_stall;
55
        output  reg     [31:0]   o_wb_data;
56
        output  wire            o_rx_int, o_tx_int;
57
 
58
        reg     [29:0]   r_setup;
59
        reg             r_tx_stb, rx_rdy;
60
        reg     [7:0]    r_tx_data;
61
        initial r_setup = DEFAULT_SETUP;
62
        always @(posedge i_clk)
63
                if ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_we))
64
                begin
65
                        case(i_wb_addr)
66
                        2'b00: r_setup <= i_wb_data[29:0];
67
                        2'b10: begin
68
                                r_tx_data <= i_wb_data[7:0];
69
                                r_tx_stb <= 1'b1;
70
                                end
71
                        default: begin end
72
                        endcase
73
                end else
74
                        r_tx_stb <= 1'b0;
75
 
76
        wire    rx_stb, rx_break, rx_parity_err, rx_frame_err, rx_ignored;
77
        wire    [7:0]    rx_data;
78
        rxuart  rxmod(i_clk, 1'b0, r_setup, i_rx_uart,
79
                        rx_stb, rx_data, rx_break,
80
                        rx_parity_err, rx_frame_err, rx_ignored);
81
 
82
        wire    tx_break, tx_busy;
83
        assign  tx_break = 1'b0;
84
        txuart  txmod(i_clk, 1'b0, r_setup, tx_break, r_tx_stb, r_tx_data,
85
                        o_tx_uart, tx_busy);
86
 
87
        reg     [7:0]    r_data;
88
        always @(posedge i_clk)
89
                if (rx_stb)
90
                        r_data <= rx_data;
91
        always @(posedge i_clk)
92
        begin
93
                if (rx_stb)
94
                        rx_rdy <= (rx_rdy | rx_stb);
95
 
96
                case(i_wb_addr)
97
                2'b00: o_wb_data <= { 2'b00, r_setup };
98
                2'b01: o_wb_data <= { 2'b00, r_setup };
99
                2'b10: o_wb_data <= { 31'h00,tx_busy };
100
                2'b11: begin
101
                        if ((i_wb_cyc)&&(i_wb_stb)&&(~i_wb_we))
102
                                rx_rdy <= 1'b0;
103
                        o_wb_data <= { 20'h00, rx_break, rx_frame_err, rx_parity_err, ~rx_rdy, r_data };
104
                        end
105
                endcase
106
                o_wb_ack <= (i_wb_cyc)&&(i_wb_stb);
107
        end
108
 
109
        assign  o_wb_stall = 1'b0;
110
        assign  o_rx_int = rx_stb;
111
        assign  o_tx_int = ~tx_busy;
112
 
113
endmodule

powered by: WebSVN 2.1.0

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