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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [bench/] [verilog/] [helloworld.v] - Diff between revs 13 and 15

Only display areas with differences | Details | Blame | View Log

Rev 13 Rev 15
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    helloworld.v
// Filename:    helloworld.v
//
//
// Project:     wbuart32, a full featured UART with simulator
// Project:     wbuart32, a full featured UART with simulator
//
//
// Purpose:     To create a *very* simple UART test program, which can be used
// Purpose:     To create a *very* simple UART test program, which can be used
//              as the top level design file of any FPGA program.
//              as the top level design file of any FPGA program.
//
//
//      With some modifications (discussed below), this RTL should be able to
//      With some modifications (discussed below), this RTL should be able to
//      run as a top-level testing file, requiring only the UART and clock pin
//      run as a top-level testing file, requiring only the UART and clock pin
//      to work.
//      to work.
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// You should have received a copy of the GNU General Public License along
// You should have received a copy of the GNU General Public License along
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// target there if the PDF file isn't present.)  If not, see
// target there if the PDF file isn't present.)  If not, see
// <http://www.gnu.org/licenses/> for a copy.
// <http://www.gnu.org/licenses/> for a copy.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
// One issue with the design is how to set the values of the setup register.
// One issue with the design is how to set the values of the setup register.
// (*This is a comment, not a verilator attribute ... )  Verilator needs to
// (*This is a comment, not a verilator attribute ... )  Verilator needs to
// know/set those values in order to work.  However, this design can also be
// know/set those values in order to work.  However, this design can also be
// used as a stand-alone top level configuration file.  In this latter case,
// used as a stand-alone top level configuration file.  In this latter case,
// the setup register needs to be set internal to the file.  Here, we use
// the setup register needs to be set internal to the file.  Here, we use
// OPT_STANDALONE to distinguish between the two.  If set, the file runs under
// OPT_STANDALONE to distinguish between the two.  If set, the file runs under
// (* Another comment still ...) Verilator and we need to get i_setup from the
// (* Another comment still ...) Verilator and we need to get i_setup from the
// external environment.  If not, it must be set internally.
// external environment.  If not, it must be set internally.
//
//
`ifndef VERILATOR
`ifndef VERILATOR
`define OPT_STANDALONE
`define OPT_STANDALONE
`endif
`endif
//
//
 
//
 
// Two versions of the UART can be found in the rtl directory: a full featured
 
// UART, and a LITE UART that only handles 8N1 -- no break sending, break
 
// detection, parity error detection, etc.  If we set USE_LITE_UART here, those
 
// simplified UART modules will be used.
 
//
 
// `define      USE_LITE_UART
 
//
 
//
module  helloworld(i_clk,
module  helloworld(i_clk,
`ifndef OPT_STANDALONE
`ifndef OPT_STANDALONE
                        i_setup,
                        i_setup,
`endif
`endif
                        o_uart_tx);
                        o_uart_tx);
        input           i_clk;
        input           i_clk;
        output  wire    o_uart_tx;
        output  wire    o_uart_tx;
 
 
        // Here we set i_setup to something appropriate to create a 115200 Baud
        // Here we set i_setup to something appropriate to create a 115200 Baud
        // UART system from a 100MHz clock.  This also sets us to an 8-bit data
        // UART system from a 100MHz clock.  This also sets us to an 8-bit data
        // word, 1-stop bit, and no parity.  This will be overwritten by
        // word, 1-stop bit, and no parity.  This will be overwritten by
        // i_setup, but at least it gives us something to start with/from.
        // i_setup, but at least it gives us something to start with/from.
        parameter       INITIAL_UART_SETUP = 31'd868;
        parameter       INITIAL_UART_SETUP = 31'd868;
 
 
        // The i_setup wires are input when run under Verilator, but need to
        // The i_setup wires are input when run under Verilator, but need to
        // be set internally if this is going to run as a standalone top level
        // be set internally if this is going to run as a standalone top level
        // test configuration.
        // test configuration.
`ifdef  OPT_STANDALONE
`ifdef  OPT_STANDALONE
        wire    [30:0]   i_setup;
        wire    [30:0]   i_setup;
        assign  i_setup = INITIAL_UART_SETUP;
        assign  i_setup = INITIAL_UART_SETUP;
`else
`else
        input   [30:0]   i_setup;
        input   [30:0]   i_setup;
`endif
`endif
 
 
        reg     pwr_reset;
        reg     pwr_reset;
        initial pwr_reset = 1'b1;
        initial pwr_reset = 1'b1;
        always @(posedge i_clk)
        always @(posedge i_clk)
                pwr_reset <= 1'b0;
                pwr_reset <= 1'b0;
 
 
        reg     [7:0]    message [0:15];
        reg     [7:0]    message [0:15];
 
 
        initial begin
        initial begin
                message[ 0] = "H";
                message[ 0] = "H";
                message[ 1] = "e";
                message[ 1] = "e";
                message[ 2] = "l";
                message[ 2] = "l";
                message[ 3] = "l";
                message[ 3] = "l";
                message[ 4] = "o";
                message[ 4] = "o";
                message[ 5] = ",";
                message[ 5] = ",";
                message[ 6] = " ";
                message[ 6] = " ";
                message[ 7] = "W";
                message[ 7] = "W";
                message[ 8] = "o";
                message[ 8] = "o";
                message[ 9] = "r";
                message[ 9] = "r";
                message[10] = "l";
                message[10] = "l";
                message[11] = "d";
                message[11] = "d";
                message[12] = "!";
                message[12] = "!";
                message[13] = " ";
                message[13] = " ";
                message[14] = "\r";
                message[14] = "\r";
                message[15] = "\n";
                message[15] = "\n";
        end
        end
 
 
        reg     [27:0]   counter;
        reg     [27:0]   counter;
        initial counter = 28'hffffff0;
        initial counter = 28'hffffff0;
        always @(posedge i_clk)
        always @(posedge i_clk)
                counter <= counter + 1'b1;
                counter <= counter + 1'b1;
 
 
        wire            tx_break, tx_busy;
        wire            tx_break, tx_busy;
        reg             tx_stb;
        reg             tx_stb;
        reg     [3:0]    tx_index;
        reg     [3:0]    tx_index;
        reg     [7:0]    tx_data;
        reg     [7:0]    tx_data;
 
 
        assign  tx_break = 1'b0;
        assign  tx_break = 1'b0;
 
 
        initial tx_index = 4'h0;
        initial tx_index = 4'h0;
        always @(posedge i_clk)
        always @(posedge i_clk)
                if ((tx_stb)&&(!tx_busy))
                if ((tx_stb)&&(!tx_busy))
                        tx_index <= tx_index + 1'b1;
                        tx_index <= tx_index + 1'b1;
        always @(posedge i_clk)
        always @(posedge i_clk)
                tx_data <= message[tx_index];
                tx_data <= message[tx_index];
 
 
        initial tx_stb = 1'b0;
        initial tx_stb = 1'b0;
        always @(posedge i_clk)
        always @(posedge i_clk)
                if (&counter)
                if (&counter)
                        tx_stb <= 1'b1;
                        tx_stb <= 1'b1;
                else if ((tx_stb)&&(!tx_busy)&&(tx_index==4'hf))
                else if ((tx_stb)&&(!tx_busy)&&(tx_index==4'hf))
                        tx_stb <= 1'b0;
                        tx_stb <= 1'b0;
 
 
        // Bypass any hardware flow control
        // Bypass any hardware flow control
        wire    rts;
        wire    cts_n;
        assign  rts = 1'b1;
        assign  cts_n = 1'b0;
 
 
 
`ifdef  USE_LITE_UART
 
        txuartlite
 
                #(24'd868)
 
                transmitter(i_clk, tx_stb, tx_data, o_uart_tx, tx_busy);
 
`else
        txuart  transmitter(i_clk, pwr_reset, i_setup, tx_break,
        txuart  transmitter(i_clk, pwr_reset, i_setup, tx_break,
                        tx_stb, tx_data, rts, o_uart_tx, tx_busy);
                        tx_stb, tx_data, cts_n, o_uart_tx, tx_busy);
 
`endif
 
 
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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