root / usrp2 / vrt / vita_rx_tb.v @ 42a98490
History | View | Annotate | Download (6.4 kB)
| 1 |
|
|---|---|
| 2 |
|
| 3 |
module vita_rx_tb; |
| 4 |
|
| 5 |
localparam DECIM = 8'd4; |
| 6 |
localparam MAXCHAN=1; |
| 7 |
localparam NUMCHAN=1; |
| 8 |
|
| 9 |
reg clk = 0; |
| 10 |
reg reset = 1; |
| 11 |
|
| 12 |
initial #1000 reset = 0; |
| 13 |
always #50 clk = ~clk; |
| 14 |
|
| 15 |
initial $dumpfile("vita_rx_tb.vcd");
|
| 16 |
initial $dumpvars(0,vita_rx_tb); |
| 17 |
|
| 18 |
wire [(MAXCHAN*32)-1:0] sample; |
| 19 |
wire strobe, run; |
| 20 |
wire [35:0] data_o; |
| 21 |
wire src_rdy; |
| 22 |
reg dst_rdy = 1; |
| 23 |
wire [63:0] vita_time; |
| 24 |
|
| 25 |
reg set_stb = 0; |
| 26 |
reg [7:0] set_addr; |
| 27 |
reg [31:0] set_data; |
| 28 |
wire set_stb_dsp; |
| 29 |
wire [7:0] set_addr_dsp; |
| 30 |
wire [31:0] set_data_dsp; |
| 31 |
|
| 32 |
/* |
| 33 |
settings_bus_crossclock settings_bus_xclk_dsp |
| 34 |
(.clk_i(clk), .rst_i(reset), .set_stb_i(set_stb), .set_addr_i(set_addr), .set_data_i(set_data), |
| 35 |
.clk_o(clk), .rst_o(reset), .set_stb_o(set_stb_dsp), .set_addr_o(set_addr_dsp), .set_data_o(set_data_dsp)); |
| 36 |
*/ |
| 37 |
|
| 38 |
wire sample_dst_rdy, sample_src_rdy; |
| 39 |
//wire [99:0] sample_data_o; |
| 40 |
wire [64+4+(MAXCHAN*32)-1:0] sample_data_o; |
| 41 |
|
| 42 |
vita_rx_control #(.BASE(0), .WIDTH(32*MAXCHAN)) vita_rx_control |
| 43 |
(.clk(clk), .reset(reset), .clear(0), |
| 44 |
.set_stb(set_stb), .set_addr(set_addr), .set_data(set_data), |
| 45 |
.vita_time(vita_time), .overrun(overrun), |
| 46 |
.sample_fifo_o(sample_data_o), .sample_fifo_dst_rdy_i(sample_dst_rdy), .sample_fifo_src_rdy_o(sample_src_rdy), |
| 47 |
.sample(sample), .run(run), .strobe(strobe)); |
| 48 |
|
| 49 |
vita_rx_framer #(.BASE(0), .MAXCHAN(MAXCHAN)) vita_rx_framer |
| 50 |
(.clk(clk), .reset(reset), .clear(0), |
| 51 |
.set_stb(set_stb), .set_addr(set_addr), .set_data(set_data), |
| 52 |
.data_o(data_o), .dst_rdy_i(dst_rdy), .src_rdy_o(src_rdy), |
| 53 |
.sample_fifo_i(sample_data_o), .sample_fifo_dst_rdy_o(sample_dst_rdy), .sample_fifo_src_rdy_i(sample_src_rdy), |
| 54 |
.fifo_occupied(), .fifo_full(), .fifo_empty() ); |
| 55 |
|
| 56 |
rx_dsp_model rx_dsp_model |
| 57 |
(.clk(clk), .reset(reset), .run(run), .decim(DECIM), .strobe(strobe), .sample(sample[31:0])); |
| 58 |
|
| 59 |
generate |
| 60 |
if(MAXCHAN>1) |
| 61 |
assign sample[(MAXCHAN*32)-1:32] = 0; |
| 62 |
endgenerate |
| 63 |
|
| 64 |
time_64bit #(.TICKS_PER_SEC(120000000), .BASE(0)) time_64bit |
| 65 |
(.clk(clk), .rst(reset), |
| 66 |
.set_stb(set_stb), .set_addr(set_addr), .set_data(set_data), |
| 67 |
.pps(0), .vita_time(vita_time)); |
| 68 |
|
| 69 |
always @(posedge clk) |
| 70 |
if(src_rdy & dst_rdy) |
| 71 |
begin |
| 72 |
if(data_o[32] & ~data_o[33]) |
| 73 |
begin |
| 74 |
$display("RX-PKT-START %d",$time);
|
| 75 |
$display(" RX-PKT-DAT %x",data_o[31:0]);
|
| 76 |
end |
| 77 |
else if(data_o[32] & data_o[33]) |
| 78 |
begin |
| 79 |
$display(" RX-PKT-DAT %x -- With ERR",data_o[31:0]);
|
| 80 |
$display("RX-PKT-ERR %d",$time);
|
| 81 |
end |
| 82 |
else if(~data_o[32] & data_o[33]) |
| 83 |
begin |
| 84 |
$display(" RX-PKT-DAT %x",data_o[31:0]);
|
| 85 |
$display("RX-PKT-END %d",$time);
|
| 86 |
end |
| 87 |
else |
| 88 |
$display(" RX-PKT DAT %x",data_o[31:0]);
|
| 89 |
end |
| 90 |
|
| 91 |
initial |
| 92 |
begin |
| 93 |
@(negedge reset); |
| 94 |
@(posedge clk); |
| 95 |
write_setting(4,32'hDEADBEEF); // VITA header |
| 96 |
write_setting(5,32'hF00D1234); // VITA streamid |
| 97 |
write_setting(6,32'hF0000000); // VITA trailer |
| 98 |
write_setting(7,8); // Samples per VITA packet |
| 99 |
write_setting(8,NUMCHAN); // Samples per VITA packet |
| 100 |
queue_rx_cmd(1,0,8,32'h0,32'h0); // send imm, single packet |
| 101 |
queue_rx_cmd(1,0,16,32'h0,32'h0); // send imm, 2 packets worth |
| 102 |
queue_rx_cmd(1,0,7,32'h0,32'h0); // send imm, 1 short packet worth |
| 103 |
queue_rx_cmd(1,0,9,32'h0,32'h0); // send imm, just longer than 1 packet |
| 104 |
|
| 105 |
queue_rx_cmd(1,1,16,32'h0,32'h0); // chained |
| 106 |
queue_rx_cmd(0,0,8,32'h0,32'h0); // 2nd in chain |
| 107 |
|
| 108 |
queue_rx_cmd(1,1,17,32'h0,32'h0); // chained, odd length |
| 109 |
queue_rx_cmd(0,0,9,32'h0,32'h0); // 2nd in chain, also odd length |
| 110 |
|
| 111 |
queue_rx_cmd(0,0,8,32'h0,32'h340); // send at, on time |
| 112 |
queue_rx_cmd(0,0,8,32'h0,32'h100); // send at, but late |
| 113 |
|
| 114 |
#100000; |
| 115 |
$display("\nChained, break chain\n");
|
| 116 |
queue_rx_cmd(1,1,8,32'h0,32'h0); // chained, but break chain |
| 117 |
#100000; |
| 118 |
$display("\nSingle packet\n");
|
| 119 |
queue_rx_cmd(1,0,8,32'h0,32'h0); // send imm, single packet |
| 120 |
#100000; |
| 121 |
$display("\nEnd chain with zero samples, shouldn't error\n");
|
| 122 |
queue_rx_cmd(1,1,8,32'h0,32'h0); // chained |
| 123 |
queue_rx_cmd(0,0,0,32'h0,32'h0); // end chain with zero samples, should keep us out of error |
| 124 |
#100000; |
| 125 |
|
| 126 |
$display("\nEnd chain with zero samples on odd-length, shouldn't error\n");
|
| 127 |
queue_rx_cmd(1,1,14,32'h0,32'h0); // chained |
| 128 |
queue_rx_cmd(0,0,0,32'h0,32'h0); // end chain with zero samples, should keep us out of error |
| 129 |
#100000; |
| 130 |
$display("Should have gotten 14 samples and EOF by now\n");
|
| 131 |
|
| 132 |
queue_rx_cmd(1,1,9,32'h0,32'h0); // chained, but break chain, odd length |
| 133 |
#100000; |
| 134 |
dst_rdy <= 0; // stop pulling out of fifo so we can get an overrun |
| 135 |
queue_rx_cmd(1,0,100,32'h0,32'h0); // long enough to fill the fifos |
| 136 |
queue_rx_cmd(1,0,5,32'h0,32'h0); // this command waits until the previous error packet is sent |
| 137 |
#100000; |
| 138 |
dst_rdy <= 1; // restart the reads so we can see what we got |
| 139 |
#100000; |
| 140 |
dst_rdy <= 0; // stop pulling out of fifo so we can get an overrun |
| 141 |
queue_rx_cmd(1,1,100,32'h0,32'h0); // long enough to fill the fifos |
| 142 |
//queue_rx_cmd(1,0,5,32'h0,32'h0); // this command waits until the previous error packet is sent |
| 143 |
#100000; |
| 144 |
@(posedge clk); |
| 145 |
dst_rdy <= 1; |
| 146 |
|
| 147 |
#100000 $finish; |
| 148 |
end |
| 149 |
|
| 150 |
task write_setting; |
| 151 |
input [7:0] addr; |
| 152 |
input [31:0] data; |
| 153 |
begin |
| 154 |
set_stb <= 0; |
| 155 |
@(posedge clk); |
| 156 |
set_addr <= addr; |
| 157 |
set_data <= data; |
| 158 |
set_stb <= 1; |
| 159 |
@(posedge clk); |
| 160 |
set_stb <= 0; |
| 161 |
end |
| 162 |
endtask // write_setting |
| 163 |
|
| 164 |
task queue_rx_cmd; |
| 165 |
input send_imm; |
| 166 |
input chain; |
| 167 |
input [29:0] lines; |
| 168 |
input [31:0] secs; |
| 169 |
input [31:0] tics; |
| 170 |
begin |
| 171 |
write_setting(0,{send_imm,chain,lines});
|
| 172 |
write_setting(1,secs); |
| 173 |
write_setting(2,tics); |
| 174 |
end |
| 175 |
endtask // queue_rx_cmd |
| 176 |
|
| 177 |
endmodule // rx_control_tb |
| 178 |
|
| 179 |
module rx_dsp_model |
| 180 |
(input clk, input reset, |
| 181 |
input run, |
| 182 |
input [7:0] decim, |
| 183 |
output strobe, |
| 184 |
output [31:0] sample); |
| 185 |
|
| 186 |
reg [15:0] pktnum = 0; |
| 187 |
reg [15:0] counter = 0; |
| 188 |
|
| 189 |
reg run_d1; |
| 190 |
always @(posedge clk) run_d1 <= run; |
| 191 |
|
| 192 |
always @(posedge clk) |
| 193 |
if(run & ~run_d1) |
| 194 |
begin |
| 195 |
counter <= 0; |
| 196 |
pktnum <= pktnum + 1; |
| 197 |
end |
| 198 |
else if(run & strobe) |
| 199 |
counter <= counter + 1; |
| 200 |
|
| 201 |
assign sample = {pktnum,counter};
|
| 202 |
|
| 203 |
reg [7:0] stb_ctr = 0; |
| 204 |
|
| 205 |
always @(posedge clk) |
| 206 |
if(reset) |
| 207 |
stb_ctr <= 0; |
| 208 |
else if(run & ~run_d1) |
| 209 |
stb_ctr <= 1; |
| 210 |
else if(run) |
| 211 |
if(stb_ctr == decim-1) |
| 212 |
stb_ctr <= 0; |
| 213 |
else |
| 214 |
stb_ctr <= stb_ctr + 1; |
| 215 |
|
| 216 |
assign strobe = stb_ctr == decim-1; |
| 217 |
|
| 218 |
endmodule // rx_dsp_model |