1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
// -*- verilog -*-
//
// USRP - Universal Software Radio Peripheral
//
// Copyright (C) 2007 Corgan Enterprises LLC
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
//
`timescale 1ns/100ps
`include "../lib/sounder.v"
`define FR_MODE 7'd64
`define bmFR_MODE_RESET 32'h0001
`define bmFR_MODE_TX 32'h0002
`define bmFR_MODE_RX 32'h0004
`define bmFR_MODE_LP 32'h0008
`define FR_DEGREE 7'd65
`define FR_AMPL 7'd66
module sounder_tb;
// System bus
reg clk;
reg rst;
reg ena;
// Configuration bus
reg [6:0] saddr;
reg [31:0] sdata;
reg s_strobe;
// DAC bus
wire tx_strobe;
wire [13:0] tx_dac_i;
wire [13:0] tx_dac_q;
// ADC bus
reg [15:0] rx_adc_i;
reg [15:0] rx_adc_q;
// FIFO bus
wire fifo_strobe;
wire [15:0] fifo_i;
wire [15:0] fifo_q;
// Configuration shadow registers
reg [31:0] mode;
reg [31:0] degree;
sounder uut
(.clk_i(clk),.saddr_i(saddr),.sdata_i(sdata),.s_strobe_i(s_strobe),
.tx_strobe_o(tx_strobe),.tx_dac_i_o(tx_dac_i),.tx_dac_q_o(tx_dac_q),
.rx_strobe_o(fifo_strobe),.rx_adc_i_i(rx_adc_i),.rx_adc_q_i(rx_adc_q),
.rx_imp_i_o(fifo_i),.rx_imp_q_o(fifo_q));
// Start up initialization
initial
begin
clk = 0;
rst = 0;
ena = 0;
saddr = 0;
sdata = 0;
s_strobe = 0;
rx_adc_i = 0;
rx_adc_q = 0;
mode = 0;
degree = 0;
@(posedge clk);
rst = 1;
@(posedge clk);
rst = 0;
@(posedge clk);
ena = 1;
end
always
#5 clk <= ~clk;
initial
begin
$monitor($time, " c=%b r=%b phs=%d txs=%b rfs=%b rxs=%b sms=%b pn=%b pnr=%b prd=%x sum=%x tot=%x",
clk, rst, uut.master.phase, uut.tx_strobe_o, uut.ref_strobe, uut.rx_strobe_o,
uut.sum_strobe, uut.transmitter.pn, uut.receiver.pn_ref, uut.receiver.prod_i,
uut.receiver.sum_i, uut.receiver.total_i);
$dumpfile("sounder_tb.vcd");
$dumpvars(0, sounder_tb);
end
// Test tasks
task write_cfg_register;
input [6:0] regno;
input [31:0] value;
begin
@(posedge clk);
saddr <= #5 regno;
sdata <= #5 value;
s_strobe <= #5 1'b1;
@(posedge clk);
s_strobe <= #5 0;
end
endtask // write_cfg_register
// Application reset line
task set_reset;
input reset;
begin
mode = reset ? (mode | `bmFR_MODE_RESET) : (mode & ~`bmFR_MODE_RESET);
write_cfg_register(`FR_MODE, mode);
end
endtask // reset
// Set the PN code degree
task set_degree;
input [5:0] degree;
begin
write_cfg_register(`FR_DEGREE, degree);
end
endtask // set_degree
// Set the PN amplitude
task set_amplitude;
input [13:0] ampl;
begin
write_cfg_register(`FR_AMPL, ampl);
end
endtask // set_ampl
// Turn on or off the transmitter
task enable_tx;
input tx;
begin
mode = tx ? (mode | `bmFR_MODE_TX) : (mode & ~`bmFR_MODE_TX);
write_cfg_register(`FR_MODE, mode);
end
endtask // enable_tx
// Turn on or off the receiver
task enable_rx;
input rx;
begin
mode = rx ? (mode | `bmFR_MODE_RX) : (mode & ~`bmFR_MODE_RX);
write_cfg_register(`FR_MODE, mode);
end
endtask // enable_rx
// Turn on or off digital loopback
task enable_lp;
input lp;
begin
mode = lp ? (mode | `bmFR_MODE_LP) : (mode & ~`bmFR_MODE_LP);
write_cfg_register(`FR_MODE, mode);
end
endtask // enable_lp
// Test transmitter functionality
task test_tx;
input [5:0] degree;
input [31:0] test_len;
begin
#20 set_reset(1);
#20 set_degree(degree);
#20 set_amplitude(14'h1000);
#20 enable_tx(1);
#20 enable_rx(0);
#20 enable_lp(0);
#20 set_reset(0);
#(test_len);
end
endtask // test_tx
// Test loopback functionality
task test_lp;
input [5:0] degree;
input [31:0] test_len;
begin
#20 set_reset(1);
#20 set_degree(degree);
#20 enable_tx(1);
#20 enable_rx(1);
#20 enable_lp(1);
#20 set_reset(0);
#(test_len);
end
endtask // test_lp
// Test receiver only functionality
task test_rx;
input [5:0] degree;
input [31:0] test_len;
begin
#20 set_reset(1);
#20 set_degree(degree);
#20 enable_tx(0);
#20 enable_rx(1);
#20 enable_lp(0);
#20 set_reset(0);
#(test_len);
end
endtask // test_rx
// Execute tests
initial
begin
#20 test_tx(8,255*20);
#20 test_lp(8,255*255*20*5);
//#20 test_rx(8,255*255*20*5);
#500 $finish;
end
endmodule
|