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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [bench/] [verilog/] [helloworld.v] - Blame information for rev 10

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

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    helloworld.v
4
//
5
// Project:     wbuart32, a full featured UART with simulator
6
//
7
// Purpose:     To create a *very* simple UART test program, which can be used
8
//              as the top level design file of any FPGA program.
9
//
10
//      With some modifications (discussed below), this RTL should be able to
11
//      run as a top-level testing file, requiring only the UART and clock pin
12
//      to work.
13
//
14
// Creator:     Dan Gisselquist, Ph.D.
15
//              Gisselquist Technology, LLC
16
//
17
////////////////////////////////////////////////////////////////////////////////
18
//
19
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
20
//
21
// This program is free software (firmware): you can redistribute it and/or
22
// modify it under the terms of  the GNU General Public License as published
23
// by the Free Software Foundation, either version 3 of the License, or (at
24
// your option) any later version.
25
//
26
// This program is distributed in the hope that it will be useful, but WITHOUT
27
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
28
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29
// for more details.
30
//
31
// You should have received a copy of the GNU General Public License along
32
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
33
// target there if the PDF file isn't present.)  If not, see
34
// <http://www.gnu.org/licenses/> for a copy.
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
// Uncomment the next line if you want this program to work as a standalone
44
// (not verilated) RTL "program" to test your UART.  You'll also need to set
45
// your setup condition properly, though.  I recommend setting it to the 
46
// ratio of your onboard clock to your desired baud rate.  For more information
47
// about how to set this, please see the specification.
48
//
49
//`define OPT_STANDALONE
50
//
51
module  helloworld(i_clk,
52
`ifndef OPT_STANDALONE
53
                        i_setup,
54
`endif
55
                        o_uart_tx);
56
        //
57
        input           i_clk;
58
        output  wire    o_uart_tx;
59
`ifndef OPT_STANDALONE
60 10 dgisselq
        input   [30:0]   i_setup;
61 5 dgisselq
`endif
62
 
63
        // If i_setup isnt set up as an input parameter, it needs to be set.
64
        // We do so here, to a setting appropriate to create a 115200 Baud
65
        // comms system from a 100MHz clock.  This also sets us to an 8-bit
66
        // data word, 1-stop bit, and no parity.
67
`ifdef  OPT_STANDALONE
68 10 dgisselq
        wire    [30:0]   i_setup;
69
        assign          i_setup = 31'd868;      // 115200 Baud, if clk @ 100MHz
70 5 dgisselq
`endif
71
 
72
        reg     pwr_reset;
73
        initial pwr_reset = 1'b1;
74
        always @(posedge i_clk)
75
                pwr_reset <= 1'b0;
76
 
77
        reg     [7:0]    message [0:15];
78
 
79
        initial begin
80
                message[ 0] = "H";
81
                message[ 1] = "e";
82
                message[ 2] = "l";
83
                message[ 3] = "l";
84
                message[ 4] = "o";
85
                message[ 5] = ",";
86
                message[ 6] = " ";
87
                message[ 7] = "W";
88
                message[ 8] = "o";
89
                message[ 9] = "r";
90
                message[10] = "l";
91
                message[11] = "d";
92
                message[12] = "!";
93
                message[13] = " ";
94
                message[14] = "\r";
95
                message[15] = "\n";
96
        end
97
 
98
        reg     [27:0]   counter;
99
        initial counter = 28'hffffff0;
100
        always @(posedge i_clk)
101
                counter <= counter + 1'b1;
102
 
103
        wire            tx_break, tx_busy;
104
        reg             tx_stb;
105
        reg     [3:0]    tx_index;
106
        reg     [7:0]    tx_data;
107
 
108
        assign  tx_break = 1'b0;
109
 
110
        initial tx_index = 4'h0;
111
        always @(posedge i_clk)
112
                if ((tx_stb)&&(!tx_busy))
113
                        tx_index <= tx_index + 1'b1;
114
        always @(posedge i_clk)
115
                tx_data <= message[tx_index];
116
 
117
        initial tx_stb = 1'b0;
118
        always @(posedge i_clk)
119
                if (&counter)
120
                        tx_stb <= 1'b1;
121
                else if ((tx_stb)&&(!tx_busy)&&(tx_index==4'hf))
122
                        tx_stb <= 1'b0;
123
 
124 10 dgisselq
        // Bypass any hardware flow control
125
        wire    rts;
126
        assign  rts = 1'b1;
127
 
128 5 dgisselq
        txuart  transmitter(i_clk, pwr_reset, i_setup, tx_break,
129 10 dgisselq
                        tx_stb, tx_data, rts, o_uart_tx, tx_busy);
130 5 dgisselq
 
131
endmodule

powered by: WebSVN 2.1.0

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