| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- `timescale 1ns/1ps
- module bmc_ascii_snapshot_tb;
- reg clk = 0;
- reg rst_n = 0;
- reg tick = 0;
- reg rx_valid = 0;
- reg [7:0] rx_data = 0;
- reg framing = 0;
- wire commit;
- wire error;
- wire [15:0] epoch;
- wire [15:0] age;
- wire stale;
- wire active_bank;
- wire [23:0] valid_mask;
- reg control_bank;
- reg [4:0] control_index;
- wire [15:0] control_raw;
- wire control_valid;
- reg snapshot_bank;
- reg [4:0] snapshot_index;
- wire [15:0] snapshot_raw;
- wire snapshot_valid;
- reg saw_commit = 0;
- reg saw_error = 0;
- integer i;
- always #5 clk = ~clk;
- always @(posedge clk) begin
- if (commit) saw_commit <= 1;
- if (error) saw_error <= 1;
- end
- bmc_ascii_snapshot #(.STALE_SECONDS(2)) dut (
- .clk(clk), .rst_n(rst_n), .tick_1s(tick), .rx_valid(rx_valid),
- .rx_data(rx_data), .rx_framing_error(framing), .snapshot_lock(1'b0),
- .snapshot_lock_bank(1'b0), .snapshot_commit(commit),
- .parser_error(error), .epoch(epoch), .age_seconds(age), .stale(stale),
- .active_bank(active_bank), .active_valid_mask(valid_mask),
- .control_bank(control_bank), .control_index(control_index), .control_raw(control_raw),
- .control_valid(control_valid), .snapshot_bank(snapshot_bank),
- .snapshot_index(snapshot_index), .snapshot_raw(snapshot_raw), .snapshot_valid(snapshot_valid)
- );
- task send_char;
- input [7:0] value;
- begin
- @(negedge clk); rx_data = value; rx_valid = 1;
- @(negedge clk); rx_valid = 0;
- end
- endtask
- function [7:0] hex_char;
- input [3:0] value;
- input lower;
- begin
- if (value < 10) hex_char = "0" + value;
- else if (lower) hex_char = "a" + value - 10;
- else hex_char = "A" + value - 10;
- end
- endfunction
- task send_byte;
- input [7:0] value;
- input lower;
- begin
- send_char(hex_char(value[7:4], lower));
- send_char(hex_char(value[3:0], lower));
- send_char(" ");
- end
- endtask
- initial begin
- control_bank = 0;
- control_index = 0;
- snapshot_bank = 0;
- snapshot_index = 0;
- repeat (3) @(negedge clk);
- rst_n = 1;
- repeat (26) @(negedge clk);
- for (i = 0; i < 23; i = i + 1) begin
- send_byte(8'd25 + i, i[0]);
- send_byte(8'd50, !i[0]);
- end
- send_byte(8'hff, 1);
- send_byte(8'hff, 0);
- send_char(8'h0d);
- repeat (2) @(negedge clk);
- if (epoch !== 1 || !saw_commit || valid_mask !== 24'h7fffff) begin
- $display("commit mismatch epoch=%0d valid=%h", epoch, valid_mask);
- $fatal;
- end
- control_bank = active_bank;
- control_index = 0;
- @(posedge clk); #1;
- if (!control_valid || control_raw !== 16'h1932) $fatal;
- control_index = 23;
- @(posedge clk); #1;
- if (control_valid || control_raw !== 16'hffff) $fatal;
- send_byte(8'd30, 0);
- send_byte(8'd100, 0);
- for (i = 1; i < 24; i = i + 1) begin send_byte(8'd30, 0); send_byte(8'd0, 0); end
- send_char(8'h0a);
- repeat (2) @(negedge clk);
- if (epoch !== 1 || !saw_error) $fatal;
- tick = 1; @(negedge clk); tick = 0;
- tick = 1; @(negedge clk); tick = 0;
- if (!stale) $fatal;
- $display("PASS: bmc_ascii_snapshot_tb");
- $finish;
- end
- endmodule
|