formatting

This commit is contained in:
Brendan Haines 2022-12-01 01:07:15 -07:00
parent f12d3be0bd
commit 5d3d9b222f
3 changed files with 145 additions and 150 deletions

View File

@ -1,69 +1,67 @@
`timescale 1ns/1ps `timescale 1ns/1ps
package bh_assert; package bh_assert;
int bh_assert_pass_count = 0;
int bh_assert_fail_count = 0;
int bh_assert_warn_count = 0;
int bh_assert_pass_count = 0; localparam BH_ASSERT_LOG_LEVEL_FAIL = 0;
int bh_assert_fail_count = 0; localparam BH_ASSERT_LOG_LEVEL_ASSERT = 1;
int bh_assert_warn_count = 0; localparam BH_ASSERT_LOG_LEVEL_WARN = 2;
localparam BH_ASSERT_LOG_LEVEL_INFO = 3;
localparam BH_ASSERT_LOG_LEVEL_FAIL = 0; logic bh_assert_log_level = BH_ASSERT_LOG_LEVEL_WARN; // 0 = errors only, 1 = all assertions, 2 = warnings, 3 = info
localparam BH_ASSERT_LOG_LEVEL_ASSERT = 1;
localparam BH_ASSERT_LOG_LEVEL_WARN = 2;
localparam BH_ASSERT_LOG_LEVEL_INFO = 3;
logic bh_assert_log_level = BH_ASSERT_LOG_LEVEL_WARN; // 0 = errors only, 1 = all assertions, 2 = warnings, 3 = info localparam COLOR_RED = "\033[31m";
localparam COLOR_YELLOW = "\033[33m";
localparam COLOR_GREEN = "\033[32m";
localparam COLOR_NORMAL = "\033[0;39m";
localparam COLOR_RED = "\033[31m"; task bh_assert_equal(int val, int expected, string description);
localparam COLOR_YELLOW = "\033[33m"; // display results
localparam COLOR_GREEN = "\033[32m"; $timeformat(-9, 2, " ns", 20);
localparam COLOR_NORMAL = "\033[0;39m"; $display(
"%t: %s: %d %s %d - %s",
$time,
val == expected ? {COLOR_GREEN, "PASS", COLOR_NORMAL} : {COLOR_RED, "FAIL", COLOR_NORMAL},
val,
val == expected ? "==" : "!=",
expected,
description
);
task bh_assert_equal(int val, int expected, string description); // update statistics
// display results if (val == expected) begin
$timeformat(-9, 2, " ns", 20); bh_assert_pass_count = bh_assert_pass_count + 1;
$display( end else begin
"%t: %s: %d %s %d - %s", bh_assert_fail_count = bh_assert_fail_count + 1;
$time, end
val == expected ? {COLOR_GREEN, "PASS", COLOR_NORMAL} : {COLOR_RED, "FAIL", COLOR_NORMAL}, endtask
val,
val == expected ? "==" : "!=",
expected,
description
);
// update statistics task bh_assert_stats;
if (val == expected) begin $timeformat(-9, 2, " ns", 20);
bh_assert_pass_count = bh_assert_pass_count + 1; $display("%t: DONE: %1d pass, %1d fail, %1d warn", $time, bh_assert_pass_count, bh_assert_fail_count, bh_assert_warn_count);
end else begin if (bh_assert_pass_count + bh_assert_fail_count == 0) begin
bh_assert_fail_count = bh_assert_fail_count + 1; $display("%sERROR%s: no assertions found", COLOR_YELLOW, COLOR_NORMAL);
end // TODO: error in a better way?
endtask end else if (bh_assert_fail_count > 0) begin
$display("%sERROR%s: some tests failed", COLOR_RED, COLOR_NORMAL);
end else begin
$display("%sSUCCESS%s: all tests passed", COLOR_GREEN, COLOR_NORMAL);
end
endtask
task bh_assert_stats; task bh_info(string description);
$timeformat(-9, 2, " ns", 20); if (bh_assert_log_level >= BH_ASSERT_LOG_LEVEL_INFO) begin
$display("%t: DONE: %1d pass, %1d fail, %1d warn", $time, bh_assert_pass_count, bh_assert_fail_count, bh_assert_warn_count); $display("%t: INFO: %s", $time, description);
if (bh_assert_pass_count + bh_assert_fail_count == 0) begin end
$display("%sERROR%s: no assertions found", COLOR_YELLOW, COLOR_NORMAL); endtask
// TODO: error in a better way?
end else if (bh_assert_fail_count > 0) begin
$display("%sERROR%s: some tests failed", COLOR_RED, COLOR_NORMAL);
end else begin
$display("%sSUCCESS%s: all tests passed", COLOR_GREEN, COLOR_NORMAL);
end
endtask
task bh_info(string description);
if (bh_assert_log_level >= BH_ASSERT_LOG_LEVEL_INFO) begin
$display("%t: INFO: %s", $time, description);
end
endtask
task bh_warn(string description);
if (bh_assert_log_level >= BH_ASSERT_LOG_LEVEL_WARN) begin
$display("%t: %sWARN%s: %s", $time, COLOR_YELLOW, COLOR_NORMAL, description);
end
bh_assert_warn_count = bh_assert_warn_count + 1;
endtask
task bh_warn(string description);
if (bh_assert_log_level >= BH_ASSERT_LOG_LEVEL_WARN) begin
$display("%t: %sWARN%s: %s", $time, COLOR_YELLOW, COLOR_NORMAL, description);
end
bh_assert_warn_count = bh_assert_warn_count + 1;
endtask
endpackage endpackage

View File

@ -12,43 +12,42 @@ module skidbuffer #(
output logic out_valid, output logic out_valid,
input logic out_ready input logic out_ready
); );
logic buffer_filled = 0;
logic [WIDTH-1:0] buffer_val;
logic buffer_filled = 0; always_ff @(posedge clk) begin
logic [WIDTH-1:0] buffer_val; if (reset) begin
buffer_filled <= 0;
always_ff @(posedge clk) begin
if (reset) begin
buffer_filled <= 0;
end else begin
if (in_valid && in_ready) begin
// input always gets stored whether it needs to be or not
buffer_val <= in;
end
if (buffer_filled) begin
if ((out_valid && out_ready) && !(in_valid && in_ready)) begin
// out_valid = 1 since buffer is full
buffer_filled <= 0;
end
end else begin end else begin
if ((in_valid && in_ready) && !(out_valid && out_ready)) begin if (in_valid && in_ready) begin
// in_ready = 1 since buffer is empty // input always gets stored whether it needs to be or not
buffer_filled <= 1; buffer_val <= in;
end
if (buffer_filled) begin
if ((out_valid && out_ready) && !(in_valid && in_ready)) begin
// out_valid = 1 since buffer is full
buffer_filled <= 0;
end
end else begin
if ((in_valid && in_ready) && !(out_valid && out_ready)) begin
// in_ready = 1 since buffer is empty
buffer_filled <= 1;
end
end end
end end
end end
end
always_comb begin always_comb begin
if (buffer_filled) begin if (buffer_filled) begin
in_ready = out_ready; in_ready = out_ready;
out_valid = 1; out_valid = 1;
out = buffer_val; out = buffer_val;
end else begin end else begin
in_ready = 1; in_ready = 1;
out_valid = in_valid; out_valid = in_valid;
out = in; out = in;
end
end end
end
endmodule endmodule

View File

@ -5,79 +5,77 @@ import bh_assert::bh_assert_equal;
import bh_assert::bh_assert_stats; import bh_assert::bh_assert_stats;
module skidbuffer_tb(); module skidbuffer_tb();
parameter WIDTH = 15;
parameter TEST_LIST_LENGTH = 256;
parameter WIDTH = 15; logic clk = 0;
parameter TEST_LIST_LENGTH = 256; logic reset = 1;
logic [WIDTH-1:0] in;
logic in_valid = 0;
wire in_ready;
wire [WIDTH-1:0] out;
wire out_valid;
logic out_ready = 0;
logic clk = 0; skidbuffer #(
logic reset = 1; .WIDTH(WIDTH)
logic [WIDTH-1:0] in; ) dut (
logic in_valid = 0; .clk(clk),
wire in_ready; .reset(reset),
wire [WIDTH-1:0] out; .in(in),
wire out_valid; .in_valid(in_valid),
logic out_ready = 0; .in_ready(in_ready),
.out(out),
.out_valid(out_valid),
.out_ready(out_ready)
);
skidbuffer #( integer i = 0;
.WIDTH(WIDTH) integer in_count = 0;
) dut ( integer out_count = 0;
.clk(clk), logic [WIDTH-1:0] in_list [0:TEST_LIST_LENGTH-1];
.reset(reset),
.in(in),
.in_valid(in_valid),
.in_ready(in_ready),
.out(out),
.out_valid(out_valid),
.out_ready(out_ready)
);
integer i = 0; assign in = in_list[in_count];
integer in_count = 0;
integer out_count = 0;
logic [WIDTH-1:0] in_list [0:TEST_LIST_LENGTH-1];
assign in = in_list[in_count]; always #5 clk = !clk;
always #5 clk = !clk; initial begin
$dumpfile("skidbuffer_tb.vcd");
$dumpvars(0, skidbuffer_tb);
initial begin for (i=0; i<TEST_LIST_LENGTH; i=i+1) begin
$dumpfile("skidbuffer_tb.vcd"); in_list[i] = $urandom();
$dumpvars(0, skidbuffer_tb); end
for (i=0; i<TEST_LIST_LENGTH; i=i+1) begin
in_list[i] = $urandom();
end
#10
reset = 0;
while (out_count < TEST_LIST_LENGTH) begin
#10 #10
if (!in_valid || (in_valid && in_ready)) begin reset = 0;
in_valid = $urandom_range(1);
while (out_count < TEST_LIST_LENGTH) begin
#10
if (!in_valid || (in_valid && in_ready)) begin
in_valid = $urandom_range(1);
end
if (!out_ready || (out_ready && out_valid)) begin
out_ready = $urandom_range(1);
end
end end
if (!out_ready || (out_ready && out_valid)) begin
out_ready = $urandom_range(1); bh_assert_stats();
$finish;
end
always @(posedge clk) begin
if (reset == 0 && in_valid && in_ready) begin
in_count <= in_count + 1;
end
if (reset == 0 && out_valid && out_ready) begin
bh_assert_equal(out, in_list[out_count], $sformatf("Output value [%3d]", out_count));
out_count <= out_count + 1;
end end
end end
bh_assert_stats(); wire [WIDTH-1:0] out_correct;
$finish; assign out_correct = in_list[out_count];
end
always @(posedge clk) begin
if (reset == 0 && in_valid && in_ready) begin
in_count <= in_count + 1;
end
if (reset == 0 && out_valid && out_ready) begin
bh_assert_equal(out, in_list[out_count], $sformatf("Output value [%3d]", out_count));
out_count <= out_count + 1;
end
end
wire [WIDTH-1:0] out_correct;
assign out_correct = in_list[out_count];
endmodule endmodule