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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [bench/] [verilog/] [echotest.v] - Blame information for rev 13

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

Line No. Rev Author Line
1 6 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    echotest.v
4
//
5
// Project:     wbuart32, a full featured UART with simulator
6
//
7
// Purpose:     To test that the txuart and rxuart modules work properly, by
8
//              echoing the input directly to the output.
9
//
10
//      This module may be run as either a DUMBECHO, simply forwarding the input
11
//      wire to the output with a touch of clock in between, or it can run as
12
//      a smarter echo routine that decodes text before returning it.  The
13
//      difference depends upon whether or not OPT_DUMBECHO is defined, as 
14
//      discussed below.
15
//
16
//      With some modifications (discussed below), this RTL should be able to
17
//      run as a top-level testing file, requiring only the transmit and receive
18
//      UART pins and the clock to work.
19
//
20
//      DON'T FORGET TO TURN OFF HARDWARE FLOW CONTROL!  ... or this'll never
21
//      work.  If you want to run with hardware flow control on, add another
22
//      wire to this module in order to set o_cts to 1'b1.
23
//
24
//
25
// Creator:     Dan Gisselquist, Ph.D.
26
//              Gisselquist Technology, LLC
27
//
28
////////////////////////////////////////////////////////////////////////////////
29
//
30
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
31
//
32
// This program is free software (firmware): you can redistribute it and/or
33
// modify it under the terms of  the GNU General Public License as published
34
// by the Free Software Foundation, either version 3 of the License, or (at
35
// your option) any later version.
36
//
37
// This program is distributed in the hope that it will be useful, but WITHOUT
38
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
39
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
40
// for more details.
41
//
42
// You should have received a copy of the GNU General Public License along
43
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
44
// target there if the PDF file isn't present.)  If not, see
45
// <http://www.gnu.org/licenses/> for a copy.
46
//
47
// License:     GPL, v3, as defined and found on www.gnu.org,
48
//              http://www.gnu.org/licenses/gpl.html
49
//
50
//
51
////////////////////////////////////////////////////////////////////////////////
52
//
53
//
54
// Uncomment the next line defining OPT_DUMBECHO in order to test the wires
55
// and external functionality of any UART, independent of the UART protocol.
56
//
57
`define OPT_DUMBECHO
58
//
59
//
60 13 dgisselq
// One issue with the design is how to set the values of the setup register.
61
// (*This is a comment, not a verilator attribute ... )  Verilator needs to
62
// know/set those values in order to work.  However, this design can also be
63
// used as a stand-alone top level configuration file.  In this latter case,
64
// the setup register needs to be set internal to the file.  Here, we use
65
// OPT_STANDALONE to distinguish between the two.  If set, the file runs under
66
// (* Another comment still ...) Verilator and we need to get i_setup from the
67
// external environment.  If not, it must be set internally.
68 6 dgisselq
//
69 13 dgisselq
`ifndef VERILATOR
70 6 dgisselq
`define OPT_STANDALONE
71 13 dgisselq
`endif
72 6 dgisselq
//
73
module  echotest(i_clk,
74
`ifndef OPT_STANDALONE
75
                        i_setup,
76
`endif
77
                        i_uart_rx, o_uart_tx);
78
        input           i_clk;
79
`ifndef OPT_STANDALONE
80 10 dgisselq
        input   [30:0]   i_setup;
81 6 dgisselq
`endif
82
        input           i_uart_rx;
83
        output  wire    o_uart_tx;
84
 
85
`ifdef  OPT_DUMBECHO
86
        reg     r_uart_tx;
87
 
88
        initial r_uart_tx = 1'b1;
89
        always @(posedge i_clk)
90
                r_uart_tx <= i_uart_rx;
91
        assign  o_uart_tx = r_uart_tx;
92
`else
93
        // This is the "smart" echo verion--one that decodes, and then
94
        // re-encodes, values over the UART.  There is a risk, though, doing
95
        // things in this manner that the receive UART might run *just* a touch
96
        // faster than the transmitter, and hence drop a bit every now and
97
        // then.  Hence, it works nicely for hand-testing, but not as nicely
98
        // for high-speed UART testing.
99
 
100
 
101
 
102
        // If i_setup isnt set up as an input parameter, it needs to be set.
103
        // We do so here, to a setting appropriate to create a 115200 Baud
104
        // comms system from a 100MHz clock.  This also sets us to an 8-bit
105
        // data word, 1-stop bit, and no parity.
106
        //
107
        // This code only applies if OPT_DUMBECHO is not defined.
108
`ifdef  OPT_STANDALONE
109 13 dgisselq
        wire    [30:0]   i_setup;
110 10 dgisselq
        assign          i_setup = 31'd868;      // 115200 Baud, if clk @ 100MHz
111 6 dgisselq
`endif
112
 
113
        // Create a reset line that will always be true on a power on reset
114
        reg     pwr_reset;
115
        initial pwr_reset = 1'b1;
116
        always @(posedge i_clk)
117
                pwr_reset = 1'b0;
118
 
119
 
120
 
121
        // The UART Receiver
122
        //
123
        // This is where everything begins, by reading data from the UART.
124
        //
125
        // Data (rx_data) is present when rx_stb is true.  Any parity or
126
        // frame errors will also be valid at that time.  Finally, we'll ignore
127
        // errors, and even the clocked uart input distributed from here.
128
        //
129
        // This code only applies if OPT_DUMBECHO is not defined.
130
        wire    rx_stb, rx_break, rx_perr, rx_ferr, rx_ignored;
131
        wire    [7:0]    rx_data;
132
 
133
        rxuart  receiver(i_clk, pwr_reset, i_setup, i_uart_rx, rx_stb, rx_data,
134
                        rx_break, rx_perr, rx_ferr, rx_ignored);
135
 
136 10 dgisselq
        // Bypass any transmit hardware flow control.
137
        wire    rts;
138
        assign rts = 1'b1;
139
 
140 6 dgisselq
        wire    tx_busy;
141
        txuart  transmitter(i_clk, pwr_reset, i_setup, rx_break,
142 10 dgisselq
                        rx_stb, rx_data, rts, o_uart_tx, tx_busy);
143 6 dgisselq
 
144
`endif
145
 
146
endmodule
147
 

powered by: WebSVN 2.1.0

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