diff --git a/dds_test.srcs/sim_1/new/axis_differentiator_test.sv b/dds_test.srcs/sim_1/new/axis_differentiator_test.sv index 7653f12..54a21a1 100644 --- a/dds_test.srcs/sim_1/new/axis_differentiator_test.sv +++ b/dds_test.srcs/sim_1/new/axis_differentiator_test.sv @@ -1,3 +1,5 @@ +import sim_util_pkg::*; + `timescale 1ns / 1ps module axis_differentiator_test(); @@ -20,6 +22,8 @@ int_t received[$]; int_t expected[$]; int_t sent[$]; +sim_util_pkg::generic #(int_t) util; + always @(posedge clk) begin if (reset) begin data_in_if.data <= '0; @@ -45,10 +49,6 @@ always @(posedge clk) begin end end -function int_t abs(input int_t x); - return (x < 0) ? -x : x; -endfunction - task check_results(); $display("received.size() = %0d", received.size()); $display("expected.size() = %0d", expected.size()); @@ -59,7 +59,7 @@ task check_results(); // check the values match, like with axis_x2_test, the rounding could lead // to an off-by-one error while (received.size() > 0 && expected.size() > 0) begin - if (abs(expected[$] - received[$]) > 1) begin + if (util.abs(expected[$] - received[$]) > 1) begin $warning("mismatch: got %x, expected %x", received[$], expected[$]); error_count = error_count + 1; end diff --git a/dds_test.srcs/sim_1/new/axis_width_converter_test.sv b/dds_test.srcs/sim_1/new/axis_width_converter_test.sv index 465a562..aaae838 100644 --- a/dds_test.srcs/sim_1/new/axis_width_converter_test.sv +++ b/dds_test.srcs/sim_1/new/axis_width_converter_test.sv @@ -1,3 +1,5 @@ +import sim_util_pkg::*; + `timescale 1ns / 1ps module axis_width_converter_test(); @@ -16,8 +18,8 @@ localparam int UP = 8; localparam int COMB_UP = 4; localparam int COMB_DOWN = 3; -`define MAX(A,B) (A > B) ? A : B -localparam int DWIDTH = `MAX(`MAX(`MAX(DWIDTH_DOWN_IN, DWIDTH_UP_IN*UP), (DWIDTH_COMB_IN*COMB_UP)/COMB_DOWN), DWIDTH_COMB_IN); +sim_util_pkg::sample_discriminator_util util; +localparam int DWIDTH = util.max(util.max(util.max(DWIDTH_DOWN_IN, DWIDTH_UP_IN*UP), (DWIDTH_COMB_IN*COMB_UP)/COMB_DOWN), DWIDTH_COMB_IN); Axis_If #(.DWIDTH(DWIDTH_DOWN_IN)) downsizer_in (); Axis_If #(.DWIDTH(DWIDTH_DOWN_IN/DOWN)) downsizer_out (); @@ -107,7 +109,7 @@ localparam [2:0][31:0] WORD_SIZE = '{ DWIDTH_DOWN_IN/DOWN // downsizer }; -localparam MAX_WORD_SIZE = `MAX(`MAX(WORD_SIZE[0],WORD_SIZE[1]),WORD_SIZE[2]); +localparam MAX_WORD_SIZE = util.max(util.max(WORD_SIZE[0],WORD_SIZE[1]),WORD_SIZE[2]); logic [MAX_WORD_SIZE-1:0] sent_word, received_word; // update data and track sent/received samples diff --git a/dds_test.srcs/sim_1/new/axis_x2_test.sv b/dds_test.srcs/sim_1/new/axis_x2_test.sv index 7ca8eba..83eabb4 100644 --- a/dds_test.srcs/sim_1/new/axis_x2_test.sv +++ b/dds_test.srcs/sim_1/new/axis_x2_test.sv @@ -1,6 +1,7 @@ `timescale 1ns / 1ps module axis_x2_test(); + int error_count = 0; logic reset; @@ -21,6 +22,8 @@ real d_in; int_t received[$]; int_t expected[$]; +sim_util_pkg::generic #(int_t) util; + always @(posedge clk) begin if (reset) begin data_in_if.data <= '0; @@ -42,10 +45,6 @@ always @(posedge clk) begin end end -function int_t abs(input int_t x); - return (x < 0) ? -x : x; -endfunction - task check_results(); $display("received.size() = %0d", received.size()); $display("expected.size() = %0d", expected.size()); @@ -56,7 +55,7 @@ task check_results(); // check the values match // casting to uint_t seems to perform a rounding operation, so the test data may be slightly too large while (received.size() > 0 && expected.size() > 0) begin - if (abs(expected[$] - received[$]) > 1) begin + if (util.abs(expected[$] - received[$]) > 1) begin $warning("mismatch: got %x, expected %x", received[$], expected[$]); error_count = error_count + 1; end diff --git a/dds_test.srcs/sim_1/new/sample_discriminator_test.sv b/dds_test.srcs/sim_1/new/sample_discriminator_test.sv index c6ad7bb..453a888 100644 --- a/dds_test.srcs/sim_1/new/sample_discriminator_test.sv +++ b/dds_test.srcs/sim_1/new/sample_discriminator_test.sv @@ -17,6 +17,8 @@ localparam int PARALLEL_SAMPLES = 4; localparam int SAMPLE_INDEX_WIDTH = 14; localparam int CLOCK_WIDTH = 50; +sim_util_pkg::sample_discriminator_util #(.SAMPLE_WIDTH(SAMPLE_WIDTH), .PARALLEL_SAMPLES(PARALLEL_SAMPLES)) util; + Axis_If #(.DWIDTH(N_CHANNELS*SAMPLE_WIDTH*2)) config_in(); Axis_Parallel_If #(.DWIDTH(SAMPLE_WIDTH*PARALLEL_SAMPLES), .PARALLEL_CHANNELS(N_CHANNELS)) data_in(); Axis_Parallel_If #(.DWIDTH(SAMPLE_WIDTH*PARALLEL_SAMPLES), .PARALLEL_CHANNELS(N_CHANNELS)) data_out(); @@ -87,7 +89,6 @@ task check_results ( inout logic [N_CHANNELS-1:0][SAMPLE_INDEX_WIDTH-1:0] sample_index, inout logic [N_CHANNELS-1:0] is_high ); - sim_util_pkg::sample_discriminator_util #(.SAMPLE_WIDTH(SAMPLE_WIDTH), .PARALLEL_SAMPLES(PARALLEL_SAMPLES)) util; for (int i = 0; i < N_CHANNELS; i++) begin // process each channel, first check that we received an appropriate amount of data $display("data_sent[%0d].size() = %0d", i, data_sent[i].size()); diff --git a/dds_test.srcs/sim_1/new/sim_util_pkg.sv b/dds_test.srcs/sim_1/new/sim_util_pkg.sv index 3d8aae7..9184be3 100644 --- a/dds_test.srcs/sim_1/new/sim_util_pkg.sv +++ b/dds_test.srcs/sim_1/new/sim_util_pkg.sv @@ -40,4 +40,16 @@ package sim_util_pkg; endclass + class generic #(type T=int); + + function T max(input T A, input T B); + return (A > B) ? A : B; + endfunction + + function T abs(input T x); + return (x < 0) ? -x : x; + endfunction + + endclass + endpackage