| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- `timescale 1ns/1ps
- // Public-interface regression for the synchronous round buffer. No force of
- // parser or RAM internals. Exercises complete/empty/short rounds and timeout
- // flushing of the very first pair (read-before-write risk) without a delimiter.
- module bmc_round_bram_tb;
- reg clk=0;
- always #20 clk=~clk;
- reg rst_n=0,rx_valid=0;
- reg [7:0] rx_data=0;
- wire tx_valid,wr_en,round_failed,poll_start,poll_done,raw_rx_valid;
- wire [7:0] tx_data,wr_data,raw_rx_data;
- wire [5:0] wr_addr;
- wire [15:0] poll_count;
- wire [1:0] eol_mode;
- wire [4:0] valid_count;
- bmc_ascii_poll #(.CLOCK_HZ(115200),.POLL_SECONDS(1),
- .ROUND_TIMEOUT_CLKS(2000)) dut(
- .clk(clk),.rst_n(rst_n),.tx_valid(tx_valid),.tx_data(tx_data),.tx_ready(1'b1),
- .rx_valid(rx_valid),.rx_data(rx_data),.wr_en(wr_en),.wr_addr(wr_addr),.wr_data(wr_data),
- .poll_count(poll_count),.round_failed(round_failed),.eol_mode(eol_mode),
- .poll_start(poll_start),.poll_done(poll_done),.valid_count(valid_count),
- .raw_rx_valid(raw_rx_valid),.raw_rx_data(raw_rx_data));
- reg [7:0] captured[0:23],expected[0:23];
- integer writes=0,rounds=0,i;
- always @(negedge clk) if(rst_n && wr_en) begin
- if(wr_addr !== writes[5:0] || writes>=24) begin
- $display("FAIL BMC write ordering round=%0d addr=%0d expected=%0d",rounds,wr_addr,writes);
- $fatal(1);
- end
- captured[wr_addr]=wr_data;
- writes=writes+1;
- end
- function [7:0] hexchar;
- input [3:0] nibble;
- begin hexchar=(nibble<10) ? "0"+nibble : "a"+nibble-10; end
- endfunction
- task byte_in;
- input [7:0] value;
- begin
- @(negedge clk);rx_data=value;rx_valid=1;
- @(negedge clk);rx_valid=0;
- end
- endtask
- task token;
- input [7:0] value;
- input delimiter;
- begin
- byte_in(hexchar(value[7:4]));byte_in(hexchar(value[3:0]));
- if(delimiter)byte_in(" ");
- end
- endtask
- task pair;
- input [7:0] first,second;
- input delimiter;
- begin token(first,1'b1);token(second,delimiter); end
- endtask
- task begin_round;
- begin
- @(posedge poll_start);
- writes=0;
- for(i=0;i<24;i=i+1)expected[i]=8'hff;
- // 43 command bytes plus fixed 10-clock drain have completed.
- repeat(60)@(posedge clk);
- end
- endtask
- task check_round;
- input integer good;
- begin
- @(posedge poll_done);
- @(negedge clk);#1;
- if(writes!==24 || valid_count!==good[4:0] || round_failed!==(good==0) || poll_count!==rounds+1) begin
- $display("FAIL BMC metadata r=%0d writes=%0d valid=%0d fail=%b count=%0d",rounds,writes,valid_count,round_failed,poll_count);
- $fatal(1);
- end
- for(i=0;i<24;i=i+1)if(captured[i]!==expected[i])begin
- $display("FAIL BMC round=%0d index=%0d got=%02x want=%02x",rounds,i,captured[i],expected[i]);
- $fatal(1);
- end
- rounds=rounds+1;
- end
- endtask
- initial begin
- repeat(5)@(posedge clk);@(negedge clk);rst_n=1;
- // Full normal round fills every address, making stale tail reuse visible.
- begin_round;
- for(i=0;i<24;i=i+1)begin expected[i]=30+i;pair(30+i,0,1);end
- check_round(24);
- // No response must replace all previous values with FF.
- begin_round;check_round(0);
- // First complete pair ends at timeout, without any trailing delimiter.
- begin_round;expected[0]=8'd77;pair(77,0,0);check_round(1);
- // Short response plus empty/out-of-range DIMMs; unwritten tail stays FF.
- begin_round;
- expected[0]=8'd25;pair(25,0,1);
- pair(8'hff,8'hff,1);
- pair(126,0,1);
- expected[3]=8'd125;pair(125,99,1);
- check_round(2);
- // Unmatched first token is not a completed pair.
- begin_round;token(55,1);check_round(0);
- // Full range with final pair flushed by timeout, rather than delimiter.
- begin_round;
- for(i=0;i<24;i=i+1)begin expected[i]=80+i;pair(80+i,0,i!=23);end
- check_round(24);
- // Another empty round proves previous full data is masked again.
- begin_round;check_round(0);
- // Zero Celsius remains a valid sample.
- begin_round;expected[0]=0;pair(0,0,1);check_round(1);
- $display("PASS bmc_round_bram_tb rounds=%0d",rounds);
- $finish;
- end
- initial begin
- repeat(2000000)@(posedge clk);
- $display("FAIL BMC test timeout");$fatal(1);
- end
- endmodule
|