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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
///////////////////////////////////////////////////////////////////
//
// Copyright 2018 Ettus Research, A National Instruments Company
//
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// Module: rh_tb
// Simple testbench for rhodium_top
// This creates a rudimentary stimulus only, to allow results to be viewed
// in the waveform viewer
//////////////////////////////////////////////////////////////////////
`timescale 1ns/1ps
module rh_tb;
reg ADC_A_Over_Range_18, ADC_B_Over_Range_18;
wire [13:0] usrpio_io; // TODO: use one of these as pl_spi_addr[3]
wire CPLD_PS_SPI_LE_25, CPLD_PS_SPI_CLK_25,
CPLD_PS_ADDR0_25, CPLD_PS_ADDR1_25, CPLD_PS_SPI_SDI_25;
wire CPLD_PS_SPI_SDO_25;
wire CPLD_PL_SPI_SDO_18;
wire CPLD_PL_SPI_LE_18, CPLD_PL_SPI_SCLK_18,
CPLD_PL_SPI_SDI_18,
CPLD_PL_SPI_ADDR0_18, CPLD_PL_SPI_ADDR1_18,
CPLD_PL_SPI_ADDR2_18,
CPLD_ATR_TX_18, CPLD_ATR_RX_18;
// NOTE: TxRx front-end switches are driven direct from the motherboard, so these ATR
// lines have no function at this time.
wire ADC_SPI_CS_L_18, ADC_SPI_SCLK_18;
wire ADC_SPI_SDIO_18;
wire DAC_SPI_CS_L_18, DAC_SPI_SCLK_18;
wire DAC_SPI_SDIO_18;
reg DAC_Alarm_18; // TODO: drive to gpio?
wire PHDAC_SPI_CS_L, PHDAC_SPI_SCLK, PHDAC_SPI_SDI;
reg LO_SYNC;
wire CLKDIST_SPI_CS_L,
CLKDIST_SPI_SCLK;
wire CLKDIST_SPI_SDIO;
wire Tx_DSA_C1,
Tx_DSA_C2,
Tx_DSA_C4,
Tx_DSA_C8,
Tx_DSA_C16;
wire Tx_DSA1_LE,
Tx_DSA2_LE;
wire Tx_Sw1_Ctrl_1,
Tx_Sw1_Ctrl_2,
Tx_Sw2_Ctrl_1,
Tx_Sw2_Ctrl_2,
Tx_Sw3_Ctrl_1,
Tx_Sw3_Ctrl_2,
Tx_Sw3_Ctrl_3,
Tx_Sw3_Ctrl_4,
Rx_LO_Input_Select,
Rx_LO_Filter_Sw_1,
Rx_LO_Filter_Sw_2,
Tx_LO_Input_Select,
Tx_LO_Filter_Sw_1,
Tx_LO_Filter_Sw_2;
wire CLKDIST_Status_LD1,
CLKDIST_Status_LD2;
wire LOSYNTH_RX_MUXOUT,
LOSYNTH_TX_MUXOUT;
wire LO_SPI_SCLK,
LO_SPI_SDI,
LO_TX_CS_L,
LO_RX_CS_L,
Rx_Sw1_Ctrl_1,
Rx_Sw1_Ctrl_2,
Rx_DSA_C1,
Rx_DSA_C2,
Rx_DSA_C4,
Rx_DSA_C8,
Rx_DSA_C16;
wire Rx_DSA1_LE,
Rx_DSA2_LE;
wire Rx_Sw2_Ctrl,
Rx_Sw3_Ctrl_1,
Rx_Sw3_Ctrl_2,
Rx_Sw4_Ctrl_1,
Rx_Sw4_Ctrl_2,
Rx_Sw4_Ctrl_3,
Rx_Sw4_Ctrl_4,
Rx_Demod_ADJ_1,
Rx_Demod_ADJ_2;
wire LO_DSA_C1,
LO_DSA_C2,
LO_DSA_C4,
LO_DSA_C8,
LO_DSA_C16;
wire RxLO_DSA_LE,
TxLO_DSA_LE;
wire LODIST_Bd_SPI_CS_L,
LODIST_Bd_SPI_SDI,
LODIST_Bd_SPI_SCLK,
Tx_Sw5_Ctrl_1,
Tx_Sw5_Ctrl_2,
Rx_Sw6_Ctrl_1,
Rx_Sw6_Ctrl_2;
wire LODIST_Bd_IO1;
wire Tx_HB_LB_Select,
Rx_HB_LB_Select,
Cal_iso_Sw_Ctrl;
parameter dly = 20;
integer scnt;
integer acnt;
integer ccnt;
integer ccnt_max;
reg ps_sck;
reg ps_mosi;
reg clkdis_cs_b;
reg cpld_ps_cs_b;
reg phdac_cs_b;
reg adc_cs_b;
reg dac_cs_b;
reg pl_sck;
reg pl_mosi;
reg txlo_cs_b;
reg rxlo_cs_b;
reg lodis_cs_b;
reg cpld_pl_cs_b;
task ps_cpld_xfer;
input [1:0] tbl;
input [5:0] cmd;
input [15:0] data;
reg [23:0] shiftreg;
integer i;
begin
ps_sck <= 1'b0;
clkdis_cs_b <= 1'b1;
cpld_ps_cs_b <= 1'b1;
phdac_cs_b <= 1'b1;
adc_cs_b <= 1'b1;
dac_cs_b <= 1'b1;
txlo_cs_b <= 1'b1;
rxlo_cs_b <= 1'b1;
lodis_cs_b <= 1'b1;
cpld_pl_cs_b <= 1'b1;
shiftreg <= {tbl,cmd,data};
#(dly);
cpld_ps_cs_b <= 1'b0;
#(dly);
for (i = 0; i < 24; i = i + 1) begin
ps_sck <= 1'b0;
ps_mosi <= shiftreg[23-i];
#(dly);
ps_sck <= 1'b1;
#(dly);
end
ps_sck <= 1'b0;
#(dly);
cpld_ps_cs_b <= 1'b1;
#(dly);
end
endtask
task pl_cpld_xfer;
input [1:0] tbl;
input [5:0] cmd;
input [15:0] data;
reg [23:0] shiftreg;
integer i;
begin
pl_sck <= 1'b0;
clkdis_cs_b <= 1'b1;
cpld_ps_cs_b <= 1'b1;
phdac_cs_b <= 1'b1;
adc_cs_b <= 1'b1;
dac_cs_b <= 1'b1;
txlo_cs_b <= 1'b1;
rxlo_cs_b <= 1'b1;
lodis_cs_b <= 1'b1;
cpld_pl_cs_b <= 1'b1;
shiftreg <= {tbl,cmd,data};
#(dly);
cpld_pl_cs_b <= 1'b0;
#(dly);
for (i = 0; i < 24; i = i + 1) begin
pl_sck <= 1'b0;
pl_mosi <= shiftreg[23-i];
#(dly);
pl_sck <= 1'b1;
#(dly);
end
pl_sck <= 1'b0;
#(dly);
cpld_pl_cs_b <= 1'b1;
#(dly);
end
endtask
assign CPLD_PS_SPI_LE_25 = clkdis_cs_b;
assign CPLD_PS_ADDR0_25 = cpld_ps_cs_b;
assign CPLD_PS_ADDR1_25 = phdac_cs_b;
assign usrpio_io[12] = adc_cs_b;
assign usrpio_io[13] = dac_cs_b;
assign CPLD_PS_SPI_CLK_25 = ps_sck;
assign CPLD_PS_SPI_SDI_25 = ps_mosi;
assign CPLD_PL_SPI_LE_18 = txlo_cs_b;
assign CPLD_PL_SPI_ADDR1_18 = rxlo_cs_b;
assign CPLD_PL_SPI_ADDR2_18 = lodis_cs_b;
assign CPLD_PL_SPI_ADDR0_18 = cpld_pl_cs_b;
assign CPLD_PL_SPI_SCLK_18 = pl_sck;
assign CPLD_PL_SPI_SDI_18 = pl_mosi;
assign CLKDIST_Status_LD1 = 1'b0;
assign LOSYNTH_RX_MUXOUT = 1'b1;
assign LOSYNTH_TX_MUXOUT = 1'b1;
initial
begin
$dumpfile("rh_cpld.vcd");
$dumpvars;
// Check Signature register read-back
#(dly) ps_cpld_xfer(2'b00, {5'b00000, 1'b1}, 16'h0000);
// Check Signature register is read-only
#(dly) ps_cpld_xfer(2'b00, {5'b00000, 1'b0}, 16'h1234);
#(dly) ps_cpld_xfer(2'b00, {5'b00000, 1'b1}, 16'h0000);
// Load portions of lower RX gain table with some values
#(dly) ps_cpld_xfer(2'b00, {5'b00110, 1'b0}, 16'h0000); /* Write GAIN_BAND_SEL for lower table */
#(dly) ps_cpld_xfer(2'b01, 6'd0, {2'd0, 5'd0, 5'd1, 1'b1, 3'd0});
#(dly) ps_cpld_xfer(2'b01, 6'd1, {2'd0, 5'd0, 5'd2, 1'b1, 3'd0});
#(dly) ps_cpld_xfer(2'b01, 6'd2, {2'd0, 5'd1, 5'd2, 1'b1, 3'd0});
#(dly) ps_cpld_xfer(2'b01, 6'd3, {2'd0, 5'd1, 5'd3, 1'b1, 3'd0});
// Load portions of upper RX gain table with some values
#(dly) ps_cpld_xfer(2'b00, {5'b00110, 1'b0}, 16'h0101); /* Write GAIN_BAND_SEL for upper table */
#(dly) ps_cpld_xfer(2'b01, 6'd4, {2'd0, 5'd2, 5'd3, 1'b1, 3'd0});
#(dly) ps_cpld_xfer(2'b01, 6'd5, {2'd0, 5'd2, 5'd4, 1'b1, 3'd0});
#(dly) ps_cpld_xfer(2'b01, 6'd6, {2'd0, 5'd3, 5'd4, 1'b1, 3'd0});
#(dly) ps_cpld_xfer(2'b01, 6'd7, {2'd0, 5'd3, 5'd5, 1'b1, 3'd0});
// Check RX gain table readback
#(dly) ps_cpld_xfer(2'b01, 6'd0, 16'h0);
#(dly) ps_cpld_xfer(2'b01, 6'd1, 16'h0);
#(dly) ps_cpld_xfer(2'b01, 6'd2, 16'h0);
#(dly) ps_cpld_xfer(2'b01, 6'd3, 16'h0);
#(dly) ps_cpld_xfer(2'b01, 6'd4, 16'h0);
#(dly) ps_cpld_xfer(2'b01, 6'd5, 16'h0);
#(dly) ps_cpld_xfer(2'b01, 6'd6, 16'h0);
// Check can write a couple registers on PL side
// (Also make sure we're looking at the lower gain tables)
#(dly) pl_cpld_xfer(2'b00, {5'd6, 1'b0}, 16'h0000);
#(dly) pl_cpld_xfer(2'b00, {5'd7, 1'b0}, 16'h0000);
// Check retrieval of gain values for RX table and program DSAs
#(dly) pl_cpld_xfer(2'b01, 6'd2, {2'b0, 1'b1, 6'b0, 1'b1, 6'b0});
#(dly) pl_cpld_xfer(2'b01, 6'd3, {2'b0, 1'b0, 6'b0, 1'b1, 6'b0});
#(dly) pl_cpld_xfer(2'b01, 6'd1, {2'b0, 1'b1, 6'b0, 1'b0, 6'b0});
// Check writes to RXBS and TXBS registers
#(dly) pl_cpld_xfer(2'b00, {5'd6, 1'b0}, 16'h1ABC);
#(dly) pl_cpld_xfer(2'b00, {5'd7, 1'b0}, 16'h1CAB);
// Check TX DSA programming is independent of RX DSA programming
#(dly) pl_cpld_xfer(2'b10, 6'd4, {2'b0, 1'b1, 6'b0, 1'b0, 6'b0});
// Check LO gain programming works
#(dly) pl_cpld_xfer(2'b11, 6'd5, {2'b0, 1'b1, 6'b0, 1'b0, 6'b0});
#(dly) pl_cpld_xfer(2'b11, 6'd7, {2'b0, 1'b0, 6'b0, 1'b1, 6'b0});
#(dly) pl_cpld_xfer(2'b11, 6'd0, {2'b0, 1'b0, 6'b0, 1'b0, 6'b0});
// More checks for PL register writes
#(dly) pl_cpld_xfer(2'b00, {5'd6, 1'b0}, 16'h0ABC);
#(dly) pl_cpld_xfer(2'b00, {5'd7, 1'b0}, 16'h0CAB);
#(dly) pl_cpld_xfer(2'b00, {5'd8, 1'b0}, 16'hAA5C);
#(dly) pl_cpld_xfer(2'b00, {5'd8, 1'b0}, 16'h5A5C);
#(dly) pl_cpld_xfer(2'b00, {5'd6, 1'b0}, 16'h1C42);
// Check low/high gain tables and independence of RX vs. TX
#(dly) pl_cpld_xfer(2'b01, 6'd0, 16'h2040);
#(dly) pl_cpld_xfer(2'b00, {5'd7, 1'b0}, 16'h104C);
#(dly) pl_cpld_xfer(2'b10, 6'd0, 16'h2040);
#(dly) pl_cpld_xfer(2'b00, {5'd7, 1'b0}, 16'h0C80);
#(dly) pl_cpld_xfer(2'b10, 6'd5, 16'h2040);
$finish;
end
rhodium_top toplevel_inst(usrpio_io, // bank 1A, 1B and 6
ADC_A_Over_Range_18, ADC_B_Over_Range_18, // bank 1A
// bank 6
CPLD_PS_SPI_LE_25,
CPLD_PS_SPI_CLK_25,
CPLD_PS_ADDR0_25,
CPLD_PS_ADDR1_25,
CPLD_PS_SPI_SDI_25,
CPLD_PS_SPI_SDO_25,
PHDAC_SPI_CS_L, PHDAC_SPI_SCLK, PHDAC_SPI_SDI,
LO_SYNC,
// bank 2
CPLD_PL_SPI_SDO_18,
CPLD_PL_SPI_LE_18,
CPLD_PL_SPI_SCLK_18,
CPLD_PL_SPI_SDI_18,
CPLD_PL_SPI_ADDR0_18,
CPLD_PL_SPI_ADDR1_18,
CPLD_PL_SPI_ADDR2_18,
CPLD_ATR_TX_18,
CPLD_ATR_RX_18,
ADC_SPI_CS_L_18,
ADC_SPI_SCLK_18,
ADC_SPI_SDIO_18,
DAC_SPI_CS_L_18,
DAC_SPI_SCLK_18,
DAC_SPI_SDIO_18,
DAC_Alarm_18,
// bank 3
CLKDIST_SPI_CS_L,
CLKDIST_SPI_SCLK,
CLKDIST_SPI_SDIO,
Tx_DSA_C1,
Tx_DSA_C2,
Tx_DSA_C4,
Tx_DSA_C8,
Tx_DSA_C16,
Tx_DSA1_LE,
Tx_DSA2_LE,
Tx_Sw1_Ctrl_1,
Tx_Sw1_Ctrl_2,
Tx_Sw2_Ctrl_1,
Tx_Sw2_Ctrl_2,
Tx_Sw3_Ctrl_1,
Tx_Sw3_Ctrl_2,
Tx_Sw3_Ctrl_3,
Tx_Sw3_Ctrl_4,
Rx_LO_Input_Select,
Rx_LO_Filter_Sw_1,
Rx_LO_Filter_Sw_2,
Tx_LO_Input_Select,
Tx_LO_Filter_Sw_1,
Tx_LO_Filter_Sw_2,
CLKDIST_Status_LD1,
CLKDIST_Status_LD2,
LOSYNTH_RX_MUXOUT,
LOSYNTH_TX_MUXOUT,
// bank 8
LO_SPI_SCLK, // fans out to both rx & tx synths
LO_SPI_SDI,
LO_TX_CS_L,
LO_RX_CS_L,
Rx_Sw1_Ctrl_1,
Rx_Sw1_Ctrl_2,
Rx_DSA_C1,
Rx_DSA_C2,
Rx_DSA_C4,
Rx_DSA_C8,
Rx_DSA_C16,
Rx_DSA1_LE,
Rx_DSA2_LE,
Rx_Sw2_Ctrl,
Rx_Sw3_Ctrl_1,
Rx_Sw3_Ctrl_2,
Rx_Sw4_Ctrl_1,
Rx_Sw4_Ctrl_2,
Rx_Sw4_Ctrl_3,
Rx_Sw4_Ctrl_4,
Rx_Demod_ADJ_1,
Rx_Demod_ADJ_2,
// bank 5
LO_DSA_C1,
LO_DSA_C2,
LO_DSA_C4,
LO_DSA_C8,
LO_DSA_C16,
RxLO_DSA_LE,
TxLO_DSA_LE,
LODIST_Bd_SPI_CS_L,
LODIST_Bd_SPI_SDI,
LODIST_Bd_SPI_SCLK,
LODIST_Bd_IO1,
Tx_Sw5_Ctrl_1,
Tx_Sw5_Ctrl_2,
Rx_Sw6_Ctrl_1,
Rx_Sw6_Ctrl_2,
Tx_HB_LB_Select,
Rx_HB_LB_Select,
Cal_iso_Sw_Ctrl
);
endmodule // rh_tb
|