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

Subversion Repositories wbuart32

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

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 13 dgisselq
// One issue with the design is how to set the values of the setup register.
44
// (*This is a comment, not a verilator attribute ... )  Verilator needs to
45
// know/set those values in order to work.  However, this design can also be
46
// used as a stand-alone top level configuration file.  In this latter case,
47
// the setup register needs to be set internal to the file.  Here, we use
48
// OPT_STANDALONE to distinguish between the two.  If set, the file runs under
49
// (* Another comment still ...) Verilator and we need to get i_setup from the
50
// external environment.  If not, it must be set internally.
51 5 dgisselq
//
52 13 dgisselq
`ifndef VERILATOR
53
`define OPT_STANDALONE
54
`endif
55 5 dgisselq
//
56
module  helloworld(i_clk,
57
`ifndef OPT_STANDALONE
58
                        i_setup,
59
`endif
60
                        o_uart_tx);
61
        input           i_clk;
62
        output  wire    o_uart_tx;
63
 
64 13 dgisselq
        // Here we set i_setup to something appropriate to create a 115200 Baud
65
        // UART system from a 100MHz clock.  This also sets us to an 8-bit data
66
        // word, 1-stop bit, and no parity.  This will be overwritten by
67
        // i_setup, but at least it gives us something to start with/from.
68
        parameter       INITIAL_UART_SETUP = 31'd868;
69
 
70
        // The i_setup wires are input when run under Verilator, but need to
71
        // be set internally if this is going to run as a standalone top level
72
        // test configuration.
73 5 dgisselq
`ifdef  OPT_STANDALONE
74 10 dgisselq
        wire    [30:0]   i_setup;
75 13 dgisselq
        assign  i_setup = INITIAL_UART_SETUP;
76
`else
77
        input   [30:0]   i_setup;
78 5 dgisselq
`endif
79
 
80
        reg     pwr_reset;
81
        initial pwr_reset = 1'b1;
82
        always @(posedge i_clk)
83
                pwr_reset <= 1'b0;
84
 
85
        reg     [7:0]    message [0:15];
86
 
87
        initial begin
88
                message[ 0] = "H";
89
                message[ 1] = "e";
90
                message[ 2] = "l";
91
                message[ 3] = "l";
92
                message[ 4] = "o";
93
                message[ 5] = ",";
94
                message[ 6] = " ";
95
                message[ 7] = "W";
96
                message[ 8] = "o";
97
                message[ 9] = "r";
98
                message[10] = "l";
99
                message[11] = "d";
100
                message[12] = "!";
101
                message[13] = " ";
102
                message[14] = "\r";
103
                message[15] = "\n";
104
        end
105
 
106
        reg     [27:0]   counter;
107
        initial counter = 28'hffffff0;
108
        always @(posedge i_clk)
109
                counter <= counter + 1'b1;
110
 
111
        wire            tx_break, tx_busy;
112
        reg             tx_stb;
113
        reg     [3:0]    tx_index;
114
        reg     [7:0]    tx_data;
115
 
116
        assign  tx_break = 1'b0;
117
 
118
        initial tx_index = 4'h0;
119
        always @(posedge i_clk)
120
                if ((tx_stb)&&(!tx_busy))
121
                        tx_index <= tx_index + 1'b1;
122
        always @(posedge i_clk)
123
                tx_data <= message[tx_index];
124
 
125
        initial tx_stb = 1'b0;
126
        always @(posedge i_clk)
127
                if (&counter)
128
                        tx_stb <= 1'b1;
129
                else if ((tx_stb)&&(!tx_busy)&&(tx_index==4'hf))
130
                        tx_stb <= 1'b0;
131
 
132 10 dgisselq
        // Bypass any hardware flow control
133
        wire    rts;
134
        assign  rts = 1'b1;
135
 
136 5 dgisselq
        txuart  transmitter(i_clk, pwr_reset, i_setup, tx_break,
137 10 dgisselq
                        tx_stb, tx_data, rts, o_uart_tx, tx_busy);
138 5 dgisselq
 
139
endmodule

powered by: WebSVN 2.1.0

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