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

Subversion Repositories wbuart32

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

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
        // The i_setup wires are input when run under Verilator, but need to
65
        // be set internally if this is going to run as a standalone top level
66
        // test configuration.
67
`ifdef  OPT_STANDALONE
68
        wire    [29:0]   i_setup;
69
 
70
        // Here we set i_setup to something appropriate to create a 115200 Baud
71
        // UART system from a 100MHz clock.  This also sets us to an 8-bit data
72
        // word, 1-stop bit, and no parity.
73
        assign  i_setup = 30'd868;
74
`else
75
        input   [29:0]   i_setup;
76
`endif
77
 
78
        reg             wb_stb;
79
        reg     [1:0]    wb_addr;
80
        reg     [31:0]   wb_data;
81
 
82
        wire            uart_stall, uart_ack;
83
        wire    [31:0]   uart_data;
84
 
85
        wire            tx_int, txfifo_int;
86
 
87
        // The next four lines create a strobe signal that is true on the first
88
        // clock, but never after.  This makes for a decent power-on reset
89
        // signal.
90
        reg     pwr_reset;
91
        initial pwr_reset = 1'b1;
92
        always @(posedge i_clk)
93
                pwr_reset <= 1'b0;
94
 
95
        // The message we wish to transmit is kept in "message".  It needs to be
96
        // set initially.  Do so here.
97
        //
98
        // Since the message has fewer than 2048 elements in it, we preset every
99
        // element to a space so that if (for some reason) we broadcast past the
100
        // end of our message, we'll at least be sending something useful.
101
        integer i;
102
        reg     [7:0]    message [0:2047];
103
        initial begin
104
                for(i=0; i<2048; i=i+1)
105
                        message[i] = 8'h20;
106
                $readmemh("speech.hex",message);
107
        end
108
 
109
        // Let's keep track of time, and send our message over and over again.
110
        // To do this, we'll keep track of a restart counter.  When this counter
111
        // rolls over, we restart our message.
112
        reg     [30:0]   restart_counter;
113
        // Since we want to start our message just a couple clocks after power
114
        // up, we'll set the reset counter just a couple clocks shy of a roll
115
        // over.
116
        initial restart_counter = -31'd16;
117
        always @(posedge i_clk)
118
                restart_counter <= restart_counter+1'b1;
119
 
120
        // Ok, now that we have a counter that tells us when to start over,
121
        // let's build a set of signals that we can use to get things started
122
        // again.  This will be the restart signal.  On this signal, we just
123
        // restart everything.
124
        reg     restart;
125
        initial restart = 0;
126
        always @(posedge i_clk)
127
        begin
128
                restart <= (restart_counter == 0);
129
        end
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
        // The wb_stb signal indicates that we wish to write, using the wishbone
179
        // to our peripheral.  We have two separate types of writes.  First,
180
        // we wish to write our setup.  Then we want to drop STB and write
181
        // our data.  Once we've filled half of the FIFO, we wait for the FIFO
182
        // to empty before issuing a STB again and then fill up half the FIFO
183
        // again.
184
        initial wb_stb = 1'b0;
185
        always @(posedge i_clk)
186
                if (restart)
187
                        wb_stb <= 1'b1;
188
                else if (msg_index >= 1481)
189
                        wb_stb <= 1'b0;
190
                else if (tx_int)
191
                        wb_stb <= 1'b1;
192
                else if (txfifo_int)
193
                        wb_stb <= wb_stb;
194
                else
195
                        wb_stb <= 1'b0;
196
 
197
        // We aren't using the receive interrupts, so we'll just mark them
198
        // here as ignored.
199
        wire    ignored_rx_int, ignored_rxfifo_int;
200
 
201
        // Finally--the unit under test--now that we've set up all the wires
202
        // to run/test it.
203
        wbuart  #(30'h868)
204
                wbuarti(i_clk, pwr_reset,
205
                        wb_stb, wb_stb, 1'b1, wb_addr, wb_data,
206
                        uart_stall, uart_ack, uart_data,
207
                        1'b1, o_uart_tx,
208
                        ignored_rx_int, tx_int,
209
                        ignored_rxfifo_int, txfifo_int);
210
 
211
endmodule

powered by: WebSVN 2.1.0

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