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

Subversion Repositories xulalx25soc

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

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 57 dgisselq
        parameter       DEFAULT_SETUP = { 2'b00, 1'b0, 1'b0, 2'b00, 24'd8333 };
48 2 dgisselq
        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 9 dgisselq
                if ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_we)&&(~i_wb_addr[1]))
64
                        r_setup <= i_wb_data[29:0];
65
 
66
        initial r_tx_stb = 1'b0;
67
        always @(posedge i_clk)
68 57 dgisselq
                if ((i_wb_cyc)&&(i_wb_stb)&&(i_wb_we)&&(i_wb_addr == 2'b11))
69 2 dgisselq
                begin
70 9 dgisselq
                        // Note: there's no check for overflow here.
71
                        // You're on your own: verify that the device
72
                        // isn't busy first.
73
                        r_tx_data <= i_wb_data[7:0];
74
                        r_tx_stb <= 1'b1;
75 2 dgisselq
                end else
76
                        r_tx_stb <= 1'b0;
77
 
78 9 dgisselq
        wire    rx_stb, rx_break, rx_parity_err, rx_frame_err;
79 2 dgisselq
        wire    [7:0]    rx_data;
80
        rxuart  rxmod(i_clk, 1'b0, r_setup, i_rx_uart,
81
                        rx_stb, rx_data, rx_break,
82 9 dgisselq
                        rx_parity_err, rx_frame_err);
83 2 dgisselq
 
84
        wire    tx_break, tx_busy;
85
        assign  tx_break = 1'b0;
86
        txuart  txmod(i_clk, 1'b0, r_setup, tx_break, r_tx_stb, r_tx_data,
87
                        o_tx_uart, tx_busy);
88
 
89
        reg     [7:0]    r_data;
90
        always @(posedge i_clk)
91
                if (rx_stb)
92
                        r_data <= rx_data;
93 9 dgisselq
 
94
        initial o_wb_data = 32'h00;
95 2 dgisselq
        always @(posedge i_clk)
96
        begin
97
                if (rx_stb)
98
                        rx_rdy <= (rx_rdy | rx_stb);
99
 
100
                case(i_wb_addr)
101
                2'b00: o_wb_data <= { 2'b00, r_setup };
102
                2'b01: o_wb_data <= { 2'b00, r_setup };
103 57 dgisselq
                2'b10: begin
104 2 dgisselq
                        if ((i_wb_cyc)&&(i_wb_stb)&&(~i_wb_we))
105 9 dgisselq
                                rx_rdy <= rx_stb;
106 2 dgisselq
                        o_wb_data <= { 20'h00, rx_break, rx_frame_err, rx_parity_err, ~rx_rdy, r_data };
107
                        end
108 57 dgisselq
                2'b11: o_wb_data <= { 31'h00,tx_busy };
109 2 dgisselq
                endcase
110 9 dgisselq
                o_wb_ack <= (i_wb_cyc)&&(i_wb_stb); // Read or write, we ack
111 2 dgisselq
        end
112
 
113
        assign  o_wb_stall = 1'b0;
114
        assign  o_rx_int = rx_stb;
115
        assign  o_tx_int = ~tx_busy;
116
 
117
endmodule

powered by: WebSVN 2.1.0

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