Imported Upstream version 3.0
[debian/gnuradio] / usrp / fpga / tb / fullchip_tb.v
1 // -*- verilog -*-
2 //
3 //  USRP - Universal Software Radio Peripheral
4 //
5 //  Copyright (C) 2003 Matt Ettus
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 2 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
20 //
21
22
23 // testbench for fullchip
24
25 `timescale 1ns/1ns
26
27 module fullchip_tb();
28
29 `include "usrp_tasks.v"
30
31 fullchip fullchip
32   (
33    .clk_120mhz(clk_120mhz),
34    .reset(reset),
35    .enable_rx(enable_rx),
36    .enable_tx(enable_tx),
37    .SLD(serload),
38    .SEN(serenable),
39    .clear_status(),
40    .SDI(serdata),
41    .SCLK(serclk),
42           
43    .adc1_data(adc1_data),
44    .adc2_data(adc2_data),
45    .adc3_data(adc1_data),
46    .adc4_data(adc2_data),
47    
48    .dac1_data(dac1_data),
49    .dac2_data(dac2_data),
50    .dac3_data(),.dac4_data(),
51    
52    .adclk0(adclk),.adclk1(),
53    
54    .adc_oeb(),.adc_otr(4'b0),
55    
56    .clk_out(clk_out),
57    
58    .misc_pins(),
59    
60    // USB interface
61    .usbclk(usbclk),.usbctl(usbctl),
62    .usbrdy(usbrdy),.usbdata(usbdata)
63    );   
64         
65         reg clk_120mhz;
66         reg usbclk;
67         reg reset;
68
69         reg [11:0] adc1_data, adc2_data;
70         wire [13:0] dac1_data, dac2_data;
71
72         wire [5:0] usbctl;
73         wire [5:0] usbrdy;
74
75         wire [15:0] usbdata;
76
77         reg WE, RD, OE;
78
79         assign usbctl[0] = WE;
80         assign usbctl[1] = RD;
81         assign usbctl[2] = OE;
82         assign usbctl[5:3] = 0;
83
84         wire have_packet_rdy = usbrdy[1];
85    
86         reg tb_oe;
87    initial tb_oe=1'b1;
88    
89         assign usbdata = tb_oe ? usbdatareg : 16'hxxxx;
90         reg serload, serenable, serclk, serdata;
91         reg enable_tx, enable_rx;
92         reg [15:0] usbdatareg;
93
94 ///////////////////////////////////////////////
95 //  Simulation Control
96 initial
97 begin
98         $dumpfile("fullchip_tb.vcd");
99         $dumpvars(0, fullchip_tb);
100 end
101
102 //initial #1000000 $finish;
103
104 ///////////////////////////////////////////////
105 //  Monitors
106
107 //initial $monitor(dac1_data);
108
109 ///////////////////////////////////////////////
110 // Clock and reset
111
112 initial clk_120mhz = 0;
113 initial usbclk = 0;
114 always #24 clk_120mhz = ~clk_120mhz;
115 always #60 usbclk = ~usbclk;
116
117 initial reset = 1'b1;
118 initial #500 reset = 1'b0;
119
120 /////////////////////////////////////////////////
121 // Run AD input
122
123 always @(posedge adclk)  adc1_data <= #1 12'd1234;
124 always @(posedge adclk)  adc2_data <= #1 12'd1234;
125
126 /////////////////////////////////////////////////
127 // USB interface
128
129   initial 
130     begin
131        initialize_usb;
132        #30000 @(posedge usbclk);
133        burst_usb_write(257);
134        
135        #30000 burst_usb_read(256);
136        #10000 $finish;
137    
138 //      repeat(30)
139 //      begin
140 //              write_from_usb;
141 //              read_from_usb;
142 //      end
143 end
144
145 /////////////////////////////////////////////////
146 // TX and RX enable
147
148 initial enable_tx = 1'b0;
149 initial #40000 enable_tx = 1'b1;
150 initial enable_rx = 1'b0;
151 initial #40000 enable_rx = 1'b1;
152
153 //////////////////////////////////////////////////
154 // Set up control bus
155
156 initial 
157 begin
158         #1000 send_config_word(`ch1in_freq,32'h0); // 1 MHz on 60 MHz clock
159         send_config_word(`ch2in_freq,32'h0);
160         send_config_word(`ch3in_freq,32'h0);
161         send_config_word(`ch4in_freq,32'h0);
162         send_config_word(`ch1out_freq,32'h01234567);
163         send_config_word(`ch2out_freq,32'h0);
164         send_config_word(`ch3out_freq,32'h0);
165         send_config_word(`ch4out_freq,32'h0);
166         send_config_word(`misc,32'h0);
167         send_config_word(`rates,{8'd2,8'd12,8'h0f,8'h07});
168         // adc, ext, interp, decim
169 end
170
171 /////////////////////////////////////////////////////////
172
173 endmodule
174