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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [bench/] [verilog/] [speechfifo.v] - Diff between revs 6 and 10

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 6 Rev 10
Line 43... Line 43...
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
// Uncomment the next line if you want this program to work as a standalone
// One issue with the design is how to set the values of the setup register.
// (not verilated) RTL "program" to test your UART.  You'll also need to set
// (*This is a comment, not a verilator attribute ... )  Verilator needs to
// your i_setup condition properly, though (below).  I recommend setting it to 
// know/set those values in order to work.  However, this design can also be
// the ratio of your onboard clock to your desired baud rate.  For more
// used as a stand-alone top level configuration file.  In this latter case,
// information about how to set this, please see the specification.
// 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
 
// (* Another comment still ...) Verilator and we need to get i_setup from the
 
// external environment.  If not, it must be set internally.
//
//
//`define OPT_STANDALONE
`ifndef VERILATOR
 
`define OPT_STANDALONE
 
`endif
//
//
module  speechfifo(i_clk,
module  speechfifo(i_clk,
`ifndef OPT_STANDALONE
`ifndef OPT_STANDALONE
                        i_setup,
                        i_setup,
`endif
`endif
Line 63... Line 68...
 
 
        // 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 = 30'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    [29:0]   i_setup;
        wire    [30:0]   i_setup;
        assign  i_setup = INITIAL_UART_SETUP;
        assign  i_setup = INITIAL_UART_SETUP;
`else
`else
        input   [29:0]   i_setup;
        input   [30:0]   i_setup;
`endif
`endif
 
 
        reg             restart;
        reg             restart;
        reg             wb_stb;
        reg             wb_stb;
        reg     [1:0]    wb_addr;
        reg     [1:0]    wb_addr;
Line 102... Line 107...
        // element to a space so that if (for some reason) we broadcast past the
        // element to a space so that if (for some reason) we broadcast past the
        // end of our message, we'll at least be sending something useful.
        // end of our message, we'll at least be sending something useful.
        integer i;
        integer i;
        reg     [7:0]    message [0:2047];
        reg     [7:0]    message [0:2047];
        initial begin
        initial begin
 
                // xx Verilator needs this file to be in the directory the file
 
                // is run from.  For that reason, the project builds, makes,
 
                // and keeps speech.hex in bench/cpp.  
 
                //
 
                // Vivado, however, wants speech.hex to be in a project file
 
                // directory, such as bench/verilog.  For that reason, the
 
                // build function in bench/cpp also copies speech.hex to the
 
                // bench/verilog directory.  You may need to make certain the
 
                // file is both built, and copied into a directory where your
 
                // synthesis tool can find it.
 
                //
                $readmemh("speech.hex",message);
                $readmemh("speech.hex",message);
                for(i=1481; i<2048; i=i+1)
                for(i=1481; i<2048; i=i+1)
                        message[i] = 8'h20;
                        message[i] = 8'h20;
 
                //
 
                // The problem with the above approach is Xilinx's ISE program.
 
                // It's broken.  It can't handle HEX files well (at all?) and
 
                // has more problems with HEX's defining ROM's.  For that
 
                // reason, the mkspeech program can be tuned to create an
 
                // include file, speech.inc.  We include that program here.
 
                // It is rather ugly, though, and not a very elegant solution,
 
                // since it walks through every value in our speech, byte by
 
                // byte, with an initial line for each byte declaring what it
 
                // is to be.
 
                //
 
                // If you (need to) use this route, comment out both the 
 
                // readmemh, the for loop, and the message[i] = 8'h20 lines
 
                // above and uncomment the include line below.
 
                //
 
                // `include "speech.inc"
        end
        end
 
 
        // Let's keep track of time, and send our message over and over again.
        // Let's keep track of time, and send our message over and over again.
        // To do this, we'll keep track of a restart counter.  When this counter
        // To do this, we'll keep track of a restart counter.  When this counter
        // rolls over, we restart our message.
        // rolls over, we restart our message.
Line 158... Line 190...
                if (restart)
                if (restart)
                        // The first thing we do is set the baud rate, and
                        // The first thing we do is set the baud rate, and
                        // serial port configuration parameters.  Ideally,
                        // serial port configuration parameters.  Ideally,
                        // we'd only set this once.  But rather than complicate
                        // we'd only set this once.  But rather than complicate
                        // the logic, we set it everytime we start over.
                        // the logic, we set it everytime we start over.
                        wb_data <= { 2'b00, i_setup };
                        wb_data <= { 1'b0, i_setup };
                else if ((wb_stb)&&(!uart_stall))
                else if ((wb_stb)&&(!uart_stall))
                        // Then, if the last thing was received over the bus,
                        // Then, if the last thing was received over the bus,
                        // we move to the next data item.
                        // we move to the next data item.
                        wb_data <= { 24'h00, message[msg_index] };
                        wb_data <= { 24'h00, message[msg_index] };
 
 
Line 206... Line 238...
                        wb_stb <= 1'b1;
                        wb_stb <= 1'b1;
                else if (end_of_message)
                else if (end_of_message)
                        // Stop transmitting when we get to the end of our
                        // Stop transmitting when we get to the end of our
                        // message.
                        // message.
                        wb_stb <= 1'b0;
                        wb_stb <= 1'b0;
                else if (tx_int)
 
                        // If we aren't at the end of the message, and tx_int
 
                        // tells us the FIFO is empty, then start writing into
 
                        // the FIFO>
 
                        wb_stb <= 1'b1;
 
                else if (txfifo_int)
                else if (txfifo_int)
                        // If we are writing into the FIFO, and it's less than
                        // If the FIFO is less than half full, then write to
                        // half full (i.e. txfifo_int is true) then keep going.
                        // it.
                        wb_stb <= wb_stb;
                        wb_stb <= 1'b1;
                else
                else
                        // But once the FIFO gets to half full, stop.
                        // But once the FIFO gets to half full, stop.
                        wb_stb <= 1'b0;
                        wb_stb <= 1'b0;
 
 
        // We aren't using the receive interrupts, so we'll just mark them
        // We aren't using the receive interrupts, so we'll just mark them
        // here as ignored.
        // here as ignored.
        wire    ignored_rx_int, ignored_rxfifo_int;
        wire    ignored_rx_int, ignored_rxfifo_int;
 
 
 
        // The WBUART can handle hardware flow control signals.  This test,
 
        // however, cannot.  The reason?  Simply just to keep things simple.
 
        // If you want to add hardware flow control to your design, simply
 
        // make rts an input to this module.
 
        //
 
        // Since this is an output only module demonstrator, what would be the
 
        // cts output is unused.
 
        wire    rts, cts;
 
        assign  rts = 1'b1;
 
 
        // Finally--the unit under test--now that we've set up all the wires
        // Finally--the unit under test--now that we've set up all the wires
        // to run/test it.
        // to run/test it.
        wbuart  #(INITIAL_UART_SETUP)
        wbuart  #(INITIAL_UART_SETUP)
                wbuarti(i_clk, pwr_reset,
                wbuarti(i_clk, pwr_reset,
                        wb_stb, wb_stb, 1'b1, wb_addr, wb_data,
                        wb_stb, wb_stb, 1'b1, wb_addr, wb_data,
                        uart_stall, uart_ack, uart_data,
                        uart_ack, uart_stall, uart_data,
                        1'b1, o_uart_tx,
                        1'b1, o_uart_tx, rts, cts,
                        ignored_rx_int, tx_int,
                        ignored_rx_int, tx_int,
                        ignored_rxfifo_int, txfifo_int);
                        ignored_rxfifo_int, txfifo_int);
 
 
endmodule
endmodule
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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