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 |
|
|
// Uncomment the next line if you want this program to work as a standalone
|
61 |
|
|
// (not verilated) RTL "program" to test your UART. You'll also need to set
|
62 |
|
|
// your setup condition properly, though. I recommend setting it to the
|
63 |
|
|
// ratio of your onboard clock to your desired baud rate. For more information
|
64 |
|
|
// about how to set this, please see the specification.
|
65 |
|
|
//
|
66 |
|
|
`define OPT_STANDALONE
|
67 |
|
|
//
|
68 |
|
|
module echotest(i_clk,
|
69 |
|
|
`ifndef OPT_STANDALONE
|
70 |
|
|
i_setup,
|
71 |
|
|
`endif
|
72 |
|
|
i_uart_rx, o_uart_tx);
|
73 |
|
|
input i_clk;
|
74 |
|
|
`ifndef OPT_STANDALONE
|
75 |
10 |
dgisselq |
input [30:0] i_setup;
|
76 |
6 |
dgisselq |
`endif
|
77 |
|
|
input i_uart_rx;
|
78 |
|
|
output wire o_uart_tx;
|
79 |
|
|
|
80 |
|
|
`ifdef OPT_DUMBECHO
|
81 |
|
|
reg r_uart_tx;
|
82 |
|
|
|
83 |
|
|
initial r_uart_tx = 1'b1;
|
84 |
|
|
always @(posedge i_clk)
|
85 |
|
|
r_uart_tx <= i_uart_rx;
|
86 |
|
|
assign o_uart_tx = r_uart_tx;
|
87 |
|
|
`else
|
88 |
|
|
// This is the "smart" echo verion--one that decodes, and then
|
89 |
|
|
// re-encodes, values over the UART. There is a risk, though, doing
|
90 |
|
|
// things in this manner that the receive UART might run *just* a touch
|
91 |
|
|
// faster than the transmitter, and hence drop a bit every now and
|
92 |
|
|
// then. Hence, it works nicely for hand-testing, but not as nicely
|
93 |
|
|
// for high-speed UART testing.
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
// If i_setup isnt set up as an input parameter, it needs to be set.
|
98 |
|
|
// We do so here, to a setting appropriate to create a 115200 Baud
|
99 |
|
|
// comms system from a 100MHz clock. This also sets us to an 8-bit
|
100 |
|
|
// data word, 1-stop bit, and no parity.
|
101 |
|
|
//
|
102 |
|
|
// This code only applies if OPT_DUMBECHO is not defined.
|
103 |
|
|
`ifdef OPT_STANDALONE
|
104 |
|
|
wire [29:0] i_setup;
|
105 |
10 |
dgisselq |
assign i_setup = 31'd868; // 115200 Baud, if clk @ 100MHz
|
106 |
6 |
dgisselq |
`endif
|
107 |
|
|
|
108 |
|
|
// Create a reset line that will always be true on a power on reset
|
109 |
|
|
reg pwr_reset;
|
110 |
|
|
initial pwr_reset = 1'b1;
|
111 |
|
|
always @(posedge i_clk)
|
112 |
|
|
pwr_reset = 1'b0;
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
// The UART Receiver
|
117 |
|
|
//
|
118 |
|
|
// This is where everything begins, by reading data from the UART.
|
119 |
|
|
//
|
120 |
|
|
// Data (rx_data) is present when rx_stb is true. Any parity or
|
121 |
|
|
// frame errors will also be valid at that time. Finally, we'll ignore
|
122 |
|
|
// errors, and even the clocked uart input distributed from here.
|
123 |
|
|
//
|
124 |
|
|
// This code only applies if OPT_DUMBECHO is not defined.
|
125 |
|
|
wire rx_stb, rx_break, rx_perr, rx_ferr, rx_ignored;
|
126 |
|
|
wire [7:0] rx_data;
|
127 |
|
|
|
128 |
|
|
rxuart receiver(i_clk, pwr_reset, i_setup, i_uart_rx, rx_stb, rx_data,
|
129 |
|
|
rx_break, rx_perr, rx_ferr, rx_ignored);
|
130 |
|
|
|
131 |
10 |
dgisselq |
// Bypass any transmit hardware flow control.
|
132 |
|
|
wire rts;
|
133 |
|
|
assign rts = 1'b1;
|
134 |
|
|
|
135 |
6 |
dgisselq |
wire tx_busy;
|
136 |
|
|
txuart transmitter(i_clk, pwr_reset, i_setup, rx_break,
|
137 |
10 |
dgisselq |
rx_stb, rx_data, rts, o_uart_tx, tx_busy);
|
138 |
6 |
dgisselq |
|
139 |
|
|
`endif
|
140 |
|
|
|
141 |
|
|
endmodule
|
142 |
|
|
|