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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [bench/] [verilog/] [linetest.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:    linetest.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
//              buffering one line's worth of input, and then piping that line
9
//      to the transmitter while (possibly) receiving a new line.
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
//
40
module  linetest(i_clk, i_setup, i_uart, o_uart);
41
        input           i_clk;
42
        input   [29:0]   i_setup;
43
        input           i_uart;
44
        output  wire    o_uart;
45
 
46
        reg     [7:0]    buffer  [0:255];
47
        reg     [7:0]    head, tail;
48
 
49
        reg     pwr_reset;
50
        initial pwr_reset = 1'b1;
51
        always @(posedge i_clk)
52
                pwr_reset = 1'b0;
53
 
54
        wire    rx_stb, rx_break, rx_perr, rx_ferr, rx_ignored;
55
        wire    [7:0]    rx_data;
56
 
57
        rxuart  receiver(i_clk, pwr_reset, i_setup, i_uart, rx_stb, rx_data,
58
                        rx_break, rx_perr, rx_ferr, rx_ignored);
59
 
60
 
61
        wire    [7:0]    nxt_head;
62
        assign  nxt_head = head + 8'h01;
63
        always @(posedge i_clk)
64
                buffer[head] <= rx_data;
65
        initial head= 8'h00;
66
        always @(posedge i_clk)
67
                if (pwr_reset)
68
                        head <= 8'h00;
69
                else if ((rx_stb)&&(!rx_break)&&(!rx_perr)&&(!rx_ferr)&&(nxt_head != tail))
70
                        head <= nxt_head;
71
 
72
        wire    [7:0]    nused;
73
        reg     [7:0]    lineend;
74
        reg             run_tx;
75
 
76
        assign  nused = head-tail;
77
 
78
        initial run_tx = 0;
79
        initial lineend = 0;
80
        always @(posedge i_clk)
81
                if (pwr_reset)
82
                begin
83
                        run_tx <= 1'b0;
84
                        lineend <= 8'h00;
85
                end else if ((rx_data == 8'h0a)&&(rx_stb))
86
                begin
87
                        lineend <= head+8'h1;
88
                        run_tx <= 1'b1;
89
                end else if ((!run_tx)&&(nused>8'd80)&&(head != tail))
90
                begin
91
                        lineend <= head;
92
                        run_tx <= 1'b1;
93
                end else if (tail == lineend)
94
                        run_tx <= 1'b0;
95
 
96
        wire    tx_break, tx_busy;
97
        assign  tx_break = 1'b0;
98
        reg     [7:0]    tx_data;
99
        reg             tx_stb;
100
 
101
        always @(posedge i_clk)
102
                tx_data <= buffer[tail];
103
        initial tx_stb = 1'b0;
104
        always @(posedge i_clk)
105
                tx_stb <= run_tx;
106
        initial tail = 8'h00;
107
        always @(posedge i_clk)
108
                if(pwr_reset)
109
                        tail <= 8'h00;
110
                else if ((tx_stb)&&(!tx_busy))
111
                        tail <= tail + 8'h01;
112
 
113
        txuart  transmitter(i_clk, pwr_reset, i_setup, tx_break,
114
                        tx_stb, tx_data, o_uart, tx_busy);
115
 
116
endmodule

powered by: WebSVN 2.1.0

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