aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/usrp3/lib/sim/packet_proc
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-01-23 16:10:22 -0800
committerMartin Braun <martin.braun@ettus.com>2020-01-28 09:35:36 -0800
commitbafa9d95453387814ef25e6b6256ba8db2df612f (patch)
tree39ba24b5b67072d354775272e687796bb511848d /fpga/usrp3/lib/sim/packet_proc
parent3075b981503002df3115d5f1d0b97d2619ba30f2 (diff)
downloaduhd-bafa9d95453387814ef25e6b6256ba8db2df612f.tar.gz
uhd-bafa9d95453387814ef25e6b6256ba8db2df612f.tar.bz2
uhd-bafa9d95453387814ef25e6b6256ba8db2df612f.zip
Merge FPGA repository back into UHD repository
The FPGA codebase was removed from the UHD repository in 2014 to reduce the size of the repository. However, over the last half-decade, the split between the repositories has proven more burdensome than it has been helpful. By merging the FPGA code back, it will be possible to create atomic commits that touch both FPGA and UHD codebases. Continuous integration testing is also simplified by merging the repositories, because it was previously difficult to automatically derive the correct UHD branch when testing a feature branch on the FPGA repository. This commit also updates the license files and paths therein. We are therefore merging the repositories again. Future development for FPGA code will happen in the same repository as the UHD host code and MPM code. == Original Codebase and Rebasing == The original FPGA repository will be hosted for the foreseeable future at its original local location: https://github.com/EttusResearch/fpga/ It can be used for bisecting, reference, and a more detailed history. The final commit from said repository to be merged here is 05003794e2da61cabf64dd278c45685a7abad7ec. This commit is tagged as v4.0.0.0-pre-uhd-merge. If you have changes in the FPGA repository that you want to rebase onto the UHD repository, simply run the following commands: - Create a directory to store patches (this should be an empty directory): mkdir ~/patches - Now make sure that your FPGA codebase is based on the same state as the code that was merged: cd src/fpga # Or wherever your FPGA code is stored git rebase v4.0.0.0-pre-uhd-merge Note: The rebase command may look slightly different depending on what exactly you're trying to rebase. - Create a patch set for your changes versus v4.0.0.0-pre-uhd-merge: git format-patch v4.0.0.0-pre-uhd-merge -o ~/patches Note: Make sure that only patches are stored in your output directory. It should otherwise be empty. Make sure that you picked the correct range of commits, and only commits you wanted to rebase were exported as patch files. - Go to the UHD repository and apply the patches: cd src/uhd # Or wherever your UHD repository is stored git am --directory fpga ~/patches/* rm -rf ~/patches # This is for cleanup == Contributors == The following people have contributed mainly to these files (this list is not complete): Co-authored-by: Alex Williams <alex.williams@ni.com> Co-authored-by: Andrej Rode <andrej.rode@ettus.com> Co-authored-by: Ashish Chaudhari <ashish@ettus.com> Co-authored-by: Ben Hilburn <ben.hilburn@ettus.com> Co-authored-by: Ciro Nishiguchi <ciro.nishiguchi@ni.com> Co-authored-by: Daniel Jepson <daniel.jepson@ni.com> Co-authored-by: Derek Kozel <derek.kozel@ettus.com> Co-authored-by: EJ Kreinar <ej@he360.com> Co-authored-by: Humberto Jimenez <humberto.jimenez@ni.com> Co-authored-by: Ian Buckley <ian.buckley@gmail.com> Co-authored-by: Jörg Hofrichter <joerg.hofrichter@ni.com> Co-authored-by: Jon Kiser <jon.kiser@ni.com> Co-authored-by: Josh Blum <josh@joshknows.com> Co-authored-by: Jonathon Pendlum <jonathan.pendlum@ettus.com> Co-authored-by: Martin Braun <martin.braun@ettus.com> Co-authored-by: Matt Ettus <matt@ettus.com> Co-authored-by: Michael West <michael.west@ettus.com> Co-authored-by: Moritz Fischer <moritz.fischer@ettus.com> Co-authored-by: Nick Foster <nick@ettus.com> Co-authored-by: Nicolas Cuervo <nicolas.cuervo@ettus.com> Co-authored-by: Paul Butler <paul.butler@ni.com> Co-authored-by: Paul David <paul.david@ettus.com> Co-authored-by: Ryan Marlow <ryan.marlow@ettus.com> Co-authored-by: Sugandha Gupta <sugandha.gupta@ettus.com> Co-authored-by: Sylvain Munaut <tnt@246tNt.com> Co-authored-by: Trung Tran <trung.tran@ettus.com> Co-authored-by: Vidush Vishwanath <vidush.vishwanath@ettus.com> Co-authored-by: Wade Fife <wade.fife@ettus.com>
Diffstat (limited to 'fpga/usrp3/lib/sim/packet_proc')
-rw-r--r--fpga/usrp3/lib/sim/packet_proc/chdr_chunker/chdr_chunker_tb.v190
-rw-r--r--fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/Makefile33
-rw-r--r--fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/chdr_dechunker_tb.sv200
-rw-r--r--fpga/usrp3/lib/sim/packet_proc/ip_hdr_checksum/ip_hdr_checksum_tb.v43
4 files changed, 466 insertions, 0 deletions
diff --git a/fpga/usrp3/lib/sim/packet_proc/chdr_chunker/chdr_chunker_tb.v b/fpga/usrp3/lib/sim/packet_proc/chdr_chunker/chdr_chunker_tb.v
new file mode 100644
index 000000000..9e80f9c15
--- /dev/null
+++ b/fpga/usrp3/lib/sim/packet_proc/chdr_chunker/chdr_chunker_tb.v
@@ -0,0 +1,190 @@
+//
+// Copyright 2013 Ettus Research LLC
+// Copyright 2018 Ettus Research, a National Instruments Company
+//
+// SPDX-License-Identifier: LGPL-3.0-or-later
+//
+
+
+`timescale 1ns/10ps
+
+module chdr_chunker_tb();
+
+ // TB stimulus
+ reg clk = 0;
+ reg reset = 1;
+ reg clear = 0;
+ reg [15:0] quantum;
+
+ // Check vars
+ reg [31:0] o_xfer_count = 0, i_xfer_count = 0;
+ reg [63:0] o_last_tdata = 0;
+
+
+ always #10 clk = ~clk;
+
+ initial $dumpfile("chdr_chunker_tb.vcd");
+ initial $dumpvars(0,chdr_chunker_tb);
+
+ function check_result;
+ input [31:0] o_xfer_count_arg;
+ input [31:0] i_xfer_count_arg;
+ input [63:0] o_last_tdata_arg;
+ input error_arg;
+ begin
+ //Check vars
+ check_result = 1;
+ check_result = check_result & ((o_xfer_count_arg == o_xfer_count) !== 0);
+ check_result = check_result & ((i_xfer_count_arg == i_xfer_count) !== 0);
+ check_result = check_result & ((o_last_tdata_arg == o_last_tdata) !== 0);
+ check_result = check_result & ((error_arg == error) != 0);
+
+ if (check_result) begin
+ $display ("... Passed");
+ end else begin
+ $display ("... FAILED!!!");
+ $display ("o_xfer_count = %d (Expected %d)",o_xfer_count,o_xfer_count_arg);
+ $display ("i_xfer_count = %d (Expected %d)",i_xfer_count,i_xfer_count_arg);
+ $display ("o_last_tdata = %h (Expected %h)",o_last_tdata,o_last_tdata_arg);
+ $display ("error = %d (Expected %d)",error,error_arg);
+ end
+
+ //Reset vars
+ o_xfer_count = 0;
+ i_xfer_count = 0;
+ o_last_tdata = 64'h0;
+ end
+ endfunction
+
+ task send_packet;
+ input [63:0] data_start;
+ input [31:0] len;
+
+ begin
+ if(len < 9) begin
+ {i_tlast, i_tdata} <= { 1'b1, data_start[63:32], len[15:0], data_start[15:0] };
+ i_tvalid <= 1;
+ @(posedge clk);
+ i_tvalid <= 0;
+ end else begin
+ {i_tlast, i_tdata} <= { 1'b0, data_start[63:32], len[15:0], data_start[15:0] };
+ i_tvalid <= 1;
+ @(posedge clk);
+ repeat(((len-1)/8)-1) begin
+ i_tdata <= i_tdata + 64'h0000_0002_0000_0002;
+ @(posedge clk);
+ end
+ i_tdata <= i_tdata + 64'h0000_0002_0000_0002;
+ i_tlast <= 1;
+ @(posedge clk);
+ i_tvalid <= 0;
+ end // else: !if(len < 9)
+ end
+ endtask // send_packet
+
+ task reset_quantum_atomic;
+ input [15:0] quant;
+ begin
+ quantum <= quant;
+ clear <= 1;
+ @(posedge clk);
+ clear <= 0;
+ @(posedge clk);
+ end
+ endtask // reset_quantum_atomic
+
+
+ initial begin
+ #100 reset = 0;
+ #200000;
+ $finish;
+ end
+
+ reg [63:0] i_tdata;
+ reg i_tlast;
+ reg i_tvalid;
+ wire i_tready;
+
+ wire [63:0] o_tdata;
+ wire o_tlast, o_tvalid, o_tready;
+ wire error;
+
+ initial begin
+ quantum <= 256;
+ i_tvalid <= 0;
+ while(reset) @(posedge clk);
+
+ $write ("Running test case: First packet after reset");
+ send_packet(64'h00000001_00000000, 128);
+ while(o_tvalid) @(posedge clk);
+ check_result(256,16,64'hFFFFFFFF_FFFFFFFF,0);
+
+ reset_quantum_atomic(8);
+
+ $write ("Running test case: sizeof(packet) < quantum");
+ send_packet(64'h00000001_00000000, 40);
+ while(o_tvalid) @(posedge clk);
+ check_result(8,5,64'hFFFFFFFF_FFFFFFFF,0);
+
+ reset_quantum_atomic(5);
+
+ $write ("Running test case: sizeof(packet) == quantum");
+ send_packet(64'h00000001_00000000, 40);
+ while(o_tvalid) @(posedge clk);
+ check_result(5,5,64'h00000030_00000008,0);
+
+ $write ("Running test case: sizeof(packet) == quantum - 64bits");
+ send_packet(64'h00000001_00000000, 32);
+ while(o_tvalid) @(posedge clk);
+ check_result(5,4,64'hFFFFFFFF_FFFFFFFF,0);
+
+ $write ("Running test case: sizeof(packet) == quantum + 64bits");
+ send_packet(64'h00000001_00000000, 48);
+ while(o_tvalid) @(posedge clk);
+ check_result(32'hxxxxxxxx,32'hxxxxxxxx,64'hxxxxxxxx_xxxxxxxx,1);
+
+ $write ("Running test case: Error reset");
+ reset_quantum_atomic(8);
+ check_result(32'hxxxxxxxx,32'hxxxxxxxx,64'hxxxxxxxx_xxxxxxxx,0);
+
+ $write ("Running test case: sizeof(packet) > quantum");
+ send_packet(64'h00000001_00000000, 80);
+ while(o_tvalid) @(posedge clk);
+ check_result(32'hxxxxxxxx,32'hxxxxxxxx,64'hxxxxxxxx_xxxxxxxx,1);
+
+ reset_quantum_atomic(8);
+
+ $write ("Running test case: sizeof(packet) == 2");
+ send_packet(64'h00000001_00000000, 8);
+ while(o_tvalid) @(posedge clk);
+ check_result(8,1,64'hFFFFFFFF_FFFFFFFF,0);
+
+ $write ("Running test case: Multiple packets back-to-back");
+ send_packet(64'h00000001_00000000, 40);
+ while(o_tvalid) @(posedge clk);
+ send_packet(64'h00000001_00000000, 16);
+ while(o_tvalid) @(posedge clk);
+ send_packet(64'h00000001_00000000, 64);
+ while(o_tvalid) @(posedge clk);
+ check_result(24,15,64'h0000004e0000000e,0);
+
+ end // initial begin
+
+
+ chdr_chunker dut (
+ .clk(clk), .reset(reset), .clear(clear), .frame_size(quantum),
+ .i_tdata(i_tdata), .i_tlast(i_tlast), .i_tvalid(i_tvalid), .i_tready(i_tready),
+ .o_tdata(o_tdata), .o_tlast(o_tlast), .o_tvalid(o_tvalid), .o_tready(o_tready),
+ .error(error));
+
+ assign o_tready = 1;
+
+ always @(posedge clk) begin
+ if (o_tvalid & o_tready) begin
+ o_xfer_count <= o_xfer_count + 1;
+ o_last_tdata <= o_tdata;
+ end
+ if (i_tvalid & i_tready) i_xfer_count <= i_xfer_count + 1;
+ end
+
+endmodule // chdr_chunker_tb
diff --git a/fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/Makefile b/fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/Makefile
new file mode 100644
index 000000000..f73cbdae9
--- /dev/null
+++ b/fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/Makefile
@@ -0,0 +1,33 @@
+#
+# Copyright 2016 Ettus Research
+#
+
+#-------------------------------------------------
+# Top-of-Makefile
+#-------------------------------------------------
+# Define BASE_DIR to point to the "top" dir
+BASE_DIR = $(abspath ../../../../top)
+# Include viv_sim_preample after defining BASE_DIR
+include $(BASE_DIR)/../tools/make/viv_sim_preamble.mak
+
+#-------------------------------------------------
+# Testbench Specific
+#-------------------------------------------------
+# Define only one toplevel module
+SIM_TOP = chdr_dechunker_tb
+
+# Add test bench, user design under test, and
+# additional user created files
+SIM_SRCS = $(abspath \
+chdr_dechunker_tb.sv \
+)
+
+MODELSIM_USER_DO = $(abspath wave.do)
+
+#-------------------------------------------------
+# Bottom-of-Makefile
+#-------------------------------------------------
+# Include all simulator specific makefiles here
+# Each should define a unique target to simulate
+# e.g. xsim, vsim, etc and a common "clean" target
+include $(BASE_DIR)/../tools/make/viv_simulator.mak
diff --git a/fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/chdr_dechunker_tb.sv b/fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/chdr_dechunker_tb.sv
new file mode 100644
index 000000000..38664c20f
--- /dev/null
+++ b/fpga/usrp3/lib/sim/packet_proc/chdr_dechunker/chdr_dechunker_tb.sv
@@ -0,0 +1,200 @@
+//
+// Copyright 2013 Ettus Research LLC
+// Copyright 2018 Ettus Research, a National Instruments Company
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: LGPL-3.0-or-later
+//
+
+
+`timescale 1ns/10ps
+
+`define NS_PER_TICK 1
+`define NUM_TEST_CASES 8
+
+`include "sim_exec_report.vh"
+
+
+module chdr_dechunker_tb();
+ `TEST_BENCH_INIT("chdr_dechunker_tb", `NUM_TEST_CASES, `NS_PER_TICK)
+
+ // TB stimulus
+ reg clk = 0;
+ reg reset = 1;
+ reg clear = 0;
+ reg [15:0] quantum;
+ wire error;
+
+ // Check vars
+ reg [31:0] o_xfer_count = 0, i_xfer_count = 0;
+ reg [63:0] o_last_tdata = 0;
+
+
+ always #10 clk = ~clk;
+
+ initial $dumpfile("chdr_dechunker_tb.vcd");
+ initial $dumpvars(0,chdr_dechunker_tb);
+
+ function check_result;
+ input [31:0] o_xfer_count_arg;
+ input [31:0] i_xfer_count_arg;
+ input [63:0] o_last_tdata_arg;
+ input error_arg;
+ begin
+ //Check vars
+ check_result = 1;
+ check_result = check_result & ((o_xfer_count_arg == o_xfer_count) !== 0);
+ check_result = check_result & ((i_xfer_count_arg == i_xfer_count) !== 0);
+ check_result = check_result & ((o_last_tdata_arg == o_last_tdata) !== 0);
+ check_result = check_result & ((error_arg == error) != 0);
+
+ if (!check_result) begin
+ $display ("o_xfer_count = %d (Expected %d)",o_xfer_count,o_xfer_count_arg);
+ $display ("i_xfer_count = %d (Expected %d)",i_xfer_count,i_xfer_count_arg);
+ $display ("o_last_tdata = %h (Expected %h)",o_last_tdata,o_last_tdata_arg);
+ $display ("error = %d (Expected %d)",error,error_arg);
+ `ASSERT_ERROR(0, "Result did not match expected value");
+ end
+
+ //Reset vars
+ o_xfer_count = 0;
+ i_xfer_count = 0;
+ o_last_tdata = 64'h0;
+ end
+ endfunction
+
+ task send_packet;
+ input [63:0] data_start;
+ input [31:0] len;
+ input [31:0] quant;
+
+ begin
+ if(quant < 2) begin
+ {i_tlast, i_tdata} <= { 1'b1, data_start[63:32], len[15:0], data_start[15:0] };
+ i_tvalid <= 1;
+ @(posedge clk);
+ i_tvalid <= 0;
+ end else begin
+ {i_tlast, i_tdata} <= { 1'b0, data_start[63:32], len[15:0], data_start[15:0] };
+ i_tvalid <= 1;
+ @(posedge clk);
+ repeat(quant - 2) begin
+ i_tdata <= i_tdata + 64'h0000_0002_0000_0002;
+ @(posedge clk);
+ end
+ i_tdata <= i_tdata + 64'h0000_0002_0000_0002;
+ i_tlast <= 1;
+ @(posedge clk);
+ i_tvalid <= 1'b0;
+ end // else: !if(quant < 2)
+ end
+ endtask // send_packet
+
+ task reset_quantum_atomic;
+ input [15:0] quant;
+ begin
+ quantum <= quant;
+ clear <= 1;
+ @(posedge clk);
+ clear <= 0;
+ @(posedge clk);
+ end
+ endtask // reset_quantum_atomic
+
+
+ initial begin
+ #100 reset = 0;
+ end
+
+ reg [63:0] i_tdata;
+ reg i_tlast;
+ reg i_tvalid;
+ wire i_tready;
+
+ wire [63:0] o_tdata;
+ wire o_tlast, o_tvalid, o_tready;
+
+ reg result;
+ initial begin
+ quantum <= 8;
+ i_tvalid <= 0;
+ while(reset) @(posedge clk);
+
+ `TEST_CASE_START("Running test case: First packet after reset");
+ send_packet(64'h00000001_00000000, 32, 8);
+ @(posedge clk);
+ result = check_result(4,8,64'hxxxxxxxx_xxxxxx06, 0);
+ `TEST_CASE_DONE(result);
+
+ reset_quantum_atomic(10);
+
+ `TEST_CASE_START("Running test case: sizeof(packet) < quantum");
+ send_packet(64'h00000001_00000000, 64, 10);
+ @(posedge clk);
+ result = check_result(8,10,64'hxxxxxxxx_xxxxxx0e, 0);
+ `TEST_CASE_DONE(result);
+
+ `TEST_CASE_START("Running test case: sizeof(packet) == quantum");
+ send_packet(64'h00000001_00000000, 80, 10);
+ @(posedge clk);
+ result = check_result(10,10,64'hxxxxxxxx_xxxxxx12, 0);
+ `TEST_CASE_DONE(result);
+
+ `TEST_CASE_START("Running test case: sizeof(packet) == quantum - 64bits");
+ send_packet(64'h00000001_00000000, 72, 10);
+ @(posedge clk);
+ result = check_result(9,10,64'hxxxxxxxx_xxxxxx10, 0);
+ `TEST_CASE_DONE(result);
+
+ `TEST_CASE_START("Running test case: sizeof(packet) == quantum + 64bits");
+ send_packet(64'h00000001_00000000, 88, 10);
+ @(posedge clk);
+ result = check_result(32'hxxxxxxxx,10,64'hxxxxxxxx_xxxxxxxx, 1);
+ `TEST_CASE_DONE(result);
+
+ reset_quantum_atomic(10);
+
+ `TEST_CASE_START("Running test case: sizeof(packet) > quantum");
+ send_packet(64'h00000001_00000000, 88, 10);
+ @(posedge clk);
+ result = check_result(32'hxxxxxxxx,10,64'hxxxxxxxx_xxxxxxxx, 1);
+ `TEST_CASE_DONE(result);
+
+ reset_quantum_atomic(8);
+
+ `TEST_CASE_START("Running test case: sizeof(packet) == 2");
+ send_packet(64'h00000001_00000000, 8, 8);
+ @(posedge clk);
+ result = check_result(1,8,64'hxxxxxxxx_xxxxxx00, 0);
+ `TEST_CASE_DONE(result);
+
+ `TEST_CASE_START("Running test case: Multiple packets");
+ send_packet(64'h00000001_00000000, 8, 8);
+ send_packet(64'h00000001_00000000, 16, 8);
+ send_packet(64'h00000001_00000000, 24, 8);
+ send_packet(64'h00000001_00000000, 32, 8);
+ @(posedge clk);
+ result = check_result(10,32,64'hxxxxxxxx_xxxxxx06, 0);
+ `TEST_CASE_DONE(result);
+
+ `TEST_BENCH_DONE;
+ end // initial begin
+
+
+ chdr_dechunker dut (
+ .clk(clk), .reset(reset), .clear(clear), .frame_size(quantum),
+ .i_tdata(i_tdata), .i_tvalid(i_tvalid), .i_tready(i_tready),
+ .o_tdata(o_tdata), .o_tlast(o_tlast), .o_tvalid(o_tvalid), .o_tready(o_tready),
+ .error(error));
+
+ assign o_tready = 1;
+
+ always @(posedge clk) begin
+ if (o_tvalid & o_tready) begin
+ o_xfer_count <= o_xfer_count + 1;
+ o_last_tdata <= o_tdata;
+ end
+ if (i_tvalid & i_tready) i_xfer_count <= i_xfer_count + 1;
+ end
+
+endmodule // chdr_dechunker_tb
diff --git a/fpga/usrp3/lib/sim/packet_proc/ip_hdr_checksum/ip_hdr_checksum_tb.v b/fpga/usrp3/lib/sim/packet_proc/ip_hdr_checksum/ip_hdr_checksum_tb.v
new file mode 100644
index 000000000..82deca656
--- /dev/null
+++ b/fpga/usrp3/lib/sim/packet_proc/ip_hdr_checksum/ip_hdr_checksum_tb.v
@@ -0,0 +1,43 @@
+//
+// Copyright 2014 Ettus Research LLC
+// Copyright 2018 Ettus Research, a National Instruments Company
+//
+// SPDX-License-Identifier: LGPL-3.0-or-later
+//
+module ip_hdr_checksum_tb();
+
+ initial $dumpfile("ip_hdr_checksum_tb.vcd");
+ initial $dumpvars(0,ip_hdr_checksum_tb);
+
+ reg clk;
+
+ wire [159:0] in = {
+ 16'h4500,
+ 16'h0030,
+ 16'h4422,
+ 16'h4000,
+ 16'h8006,
+ 16'h0000,
+ 16'h8c7c,
+ 16'h19ac,
+ 16'hae24,
+ 16'h1e2b
+ };
+
+ wire [15:0] out;
+ ip_hdr_checksum ip_hdr_checksum
+ (.clk(clk),
+ .in(in),
+ .out(out));
+
+ initial
+ begin
+ clk <= 0;
+ #100 clk <= 1;
+ #100 clk <= 0;
+ #100 clk <= 1;
+ #100 $display("Computed 0x%x, should be 0x442e", out);
+ #100 $finish;
+ end
+
+endmodule // ip_hdr_checksum_tb