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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [bench/] [verilog/] [speechfifo.v] - Blame information for rev 6

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

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    speechfifo.v
4
//
5
// Project:     wbuart32, a full featured UART with simulator
6
//
7
// Purpose:     To test/demonstrate/prove the wishbone access to the FIFO'd
8
//              UART via sending more information than the FIFO can hold,
9
//      and then verifying that this was the value received.
10
//
11
//      To do this, we "borrow" a copy of Abraham Lincolns Gettysburg address,
12
//      make that the FIFO isn't large enough to hold it, and then try
13
//      to send this address every couple of minutes.
14
//
15
//      With some minor modifications (discussed below), this RTL should be
16
//      able to be run as a top-level testing file, requiring only that the
17
//      clock and the transmit UART pins be working.
18
//
19
// Creator:     Dan Gisselquist, Ph.D.
20
//              Gisselquist Technology, LLC
21
//
22
////////////////////////////////////////////////////////////////////////////////
23
//
24
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
25
//
26
// This program is free software (firmware): you can redistribute it and/or
27
// modify it under the terms of  the GNU General Public License as published
28
// by the Free Software Foundation, either version 3 of the License, or (at
29
// your option) any later version.
30
//
31
// This program is distributed in the hope that it will be useful, but WITHOUT
32
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
33
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
34
// for more details.
35
//
36
// You should have received a copy of the GNU General Public License along
37
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
38
// target there if the PDF file isn't present.)  If not, see
39
// <http://www.gnu.org/licenses/> for a copy.
40
//
41
// License:     GPL, v3, as defined and found on www.gnu.org,
42
//              http://www.gnu.org/licenses/gpl.html
43
//
44
//
45
////////////////////////////////////////////////////////////////////////////////
46
//
47
//
48
// Uncomment the next line if you want this program to work as a standalone
49
// (not verilated) RTL "program" to test your UART.  You'll also need to set
50
// your i_setup condition properly, though (below).  I recommend setting it to 
51
// the ratio of your onboard clock to your desired baud rate.  For more
52
// information about how to set this, please see the specification.
53
//
54
//`define OPT_STANDALONE
55
//
56
module  speechfifo(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 6 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 = 30'd868;
69
 
70 5 dgisselq
        // 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
`ifdef  OPT_STANDALONE
74
        wire    [29:0]   i_setup;
75 6 dgisselq
        assign  i_setup = INITIAL_UART_SETUP;
76 5 dgisselq
`else
77
        input   [29:0]   i_setup;
78
`endif
79
 
80 6 dgisselq
        reg             restart;
81 5 dgisselq
        reg             wb_stb;
82
        reg     [1:0]    wb_addr;
83
        reg     [31:0]   wb_data;
84
 
85
        wire            uart_stall, uart_ack;
86
        wire    [31:0]   uart_data;
87
 
88
        wire            tx_int, txfifo_int;
89
 
90
        // The next four lines create a strobe signal that is true on the first
91
        // clock, but never after.  This makes for a decent power-on reset
92
        // signal.
93
        reg     pwr_reset;
94
        initial pwr_reset = 1'b1;
95
        always @(posedge i_clk)
96
                pwr_reset <= 1'b0;
97
 
98
        // The message we wish to transmit is kept in "message".  It needs to be
99
        // set initially.  Do so here.
100
        //
101
        // Since the message has fewer than 2048 elements in it, we preset every
102
        // element to a space so that if (for some reason) we broadcast past the
103
        // end of our message, we'll at least be sending something useful.
104
        integer i;
105
        reg     [7:0]    message [0:2047];
106
        initial begin
107 6 dgisselq
                $readmemh("speech.hex",message);
108
                for(i=1481; i<2048; i=i+1)
109 5 dgisselq
                        message[i] = 8'h20;
110
        end
111
 
112
        // Let's keep track of time, and send our message over and over again.
113
        // To do this, we'll keep track of a restart counter.  When this counter
114
        // rolls over, we restart our message.
115
        reg     [30:0]   restart_counter;
116
        // Since we want to start our message just a couple clocks after power
117
        // up, we'll set the reset counter just a couple clocks shy of a roll
118
        // over.
119
        initial restart_counter = -31'd16;
120
        always @(posedge i_clk)
121
                restart_counter <= restart_counter+1'b1;
122
 
123
        // Ok, now that we have a counter that tells us when to start over,
124
        // let's build a set of signals that we can use to get things started
125
        // again.  This will be the restart signal.  On this signal, we just
126
        // restart everything.
127
        initial restart = 0;
128
        always @(posedge i_clk)
129
                restart <= (restart_counter == 0);
130
 
131
        // Our message index.  This is the address of the character we wish to
132
        // transmit next.  Note, there's a clock delay between setting this 
133
        // index and when the wb_data is valid.  Hence, we set the index on
134
        // restart[0] to zero.
135
        reg     [10:0]   msg_index;
136
        initial msg_index = 11'd2040;
137
        always @(posedge i_clk)
138
        begin
139
                if (restart)
140
                        msg_index <= 0;
141
                else if ((wb_stb)&&(!uart_stall))
142
                        // We only advance the index if a port operation on the
143
                        // wbuart has taken place.  That's what the
144
                        // (wb_stb)&&(!uart_stall) is about.  (wb_stb) is the
145
                        // request for a transaction on the bus, uart_stall
146
                        // tells us to wait 'cause the peripheral isn't ready. 
147
                        // In our case, it's always ready, uart_stall == 0, but
148
                        // we keep/maintain this logic for good form.
149
                        //
150
                        // Note also, we only advance when restart[0] is zero.
151
                        // This keeps us from advancing prior to the setup
152
                        // word.
153
                        msg_index <= msg_index + 1'b1;
154
        end
155
 
156
        // What data will we be sending to the port?
157
        always @(posedge i_clk)
158
                if (restart)
159
                        // The first thing we do is set the baud rate, and
160
                        // serial port configuration parameters.  Ideally,
161
                        // we'd only set this once.  But rather than complicate
162
                        // the logic, we set it everytime we start over.
163
                        wb_data <= { 2'b00, i_setup };
164
                else if ((wb_stb)&&(!uart_stall))
165
                        // Then, if the last thing was received over the bus,
166
                        // we move to the next data item.
167
                        wb_data <= { 24'h00, message[msg_index] };
168
 
169
        // We send our first value to the SETUP address (all zeros), all other
170
        // values we send to the transmitters address.  We should really be
171
        // double checking that stall remains low, but its not required here.
172
        always @(posedge i_clk)
173
                if (restart)
174
                        wb_addr <= 2'b00;
175
                else // if (!uart_stall)??
176
                        wb_addr <= 2'b11;
177
 
178 6 dgisselq
        // Knowing when to stop sending the speech is important, but depends
179
        // upon an 11 bit comparison.  Since FPGA logic is best measured by the
180
        // number of inputs to an always block, we pull those 11-bits out of
181
        // the always block for wb_stb, and place them here on the clock prior.
182
        // If end_of_message is true, then we need to stop transmitting, and
183
        // wait for the next (restart) to get us started again.  We set that
184
        // flag hee.
185
        reg     end_of_message;
186
        initial end_of_message = 1'b1;
187
        always @(posedge i_clk)
188
                if (restart)
189
                        end_of_message <= 1'b0;
190
                else
191
                        end_of_message <= (msg_index >= 1481);
192
 
193 5 dgisselq
        // The wb_stb signal indicates that we wish to write, using the wishbone
194
        // to our peripheral.  We have two separate types of writes.  First,
195
        // we wish to write our setup.  Then we want to drop STB and write
196
        // our data.  Once we've filled half of the FIFO, we wait for the FIFO
197
        // to empty before issuing a STB again and then fill up half the FIFO
198
        // again.
199
        initial wb_stb = 1'b0;
200
        always @(posedge i_clk)
201
                if (restart)
202 6 dgisselq
                        // Start sending to the UART on a reset.  The first
203
                        // thing we'll send will be the configuration, but
204
                        // that's done elsewhere.  This just starts up the
205
                        // writes to the peripheral wbuart.
206 5 dgisselq
                        wb_stb <= 1'b1;
207 6 dgisselq
                else if (end_of_message)
208
                        // Stop transmitting when we get to the end of our
209
                        // message.
210 5 dgisselq
                        wb_stb <= 1'b0;
211
                else if (tx_int)
212 6 dgisselq
                        // If we aren't at the end of the message, and tx_int
213
                        // tells us the FIFO is empty, then start writing into
214
                        // the FIFO>
215 5 dgisselq
                        wb_stb <= 1'b1;
216
                else if (txfifo_int)
217 6 dgisselq
                        // If we are writing into the FIFO, and it's less than
218
                        // half full (i.e. txfifo_int is true) then keep going.
219 5 dgisselq
                        wb_stb <= wb_stb;
220
                else
221 6 dgisselq
                        // But once the FIFO gets to half full, stop.
222 5 dgisselq
                        wb_stb <= 1'b0;
223
 
224
        // We aren't using the receive interrupts, so we'll just mark them
225
        // here as ignored.
226
        wire    ignored_rx_int, ignored_rxfifo_int;
227
 
228
        // Finally--the unit under test--now that we've set up all the wires
229
        // to run/test it.
230 6 dgisselq
        wbuart  #(INITIAL_UART_SETUP)
231 5 dgisselq
                wbuarti(i_clk, pwr_reset,
232
                        wb_stb, wb_stb, 1'b1, wb_addr, wb_data,
233
                        uart_stall, uart_ack, uart_data,
234
                        1'b1, o_uart_tx,
235
                        ignored_rx_int, tx_int,
236
                        ignored_rxfifo_int, txfifo_int);
237
 
238
endmodule

powered by: WebSVN 2.1.0

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