|
|
@@ -0,0 +1,56 @@
|
|
|
+`timescale 1ns/1ps
|
|
|
+module thermal_safety_contract_tb;
|
|
|
+ reg clk=0;always #20 clk=~clk;
|
|
|
+ reg rst_n=0,tick=0,wr=0,commit=0,keepalive=0;
|
|
|
+ reg [4:0] addr=0,read_addr=0;
|
|
|
+ reg [7:0] value=0;
|
|
|
+ reg [15:0] epoch=0;
|
|
|
+ reg stale=1;
|
|
|
+ reg [7:0] temps[0:23];
|
|
|
+ wire [4:0] bi;reg[15:0] braw;
|
|
|
+ wire done,ok,active_bank,ready,manual,wd,hard;
|
|
|
+ wire [7:0] remaining,requested,applied;
|
|
|
+ wire [23:0] safety;wire[3:0] lanes;
|
|
|
+ always @(posedge clk)braw<={temps[bi],8'd0};
|
|
|
+ thermal_control_core dut(.clk(clk),.rst_n(rst_n),.tick_1s(tick),.manual_wr_en(wr),.manual_wr_addr(addr),
|
|
|
+ .manual_wr_data(value),.manual_commit(commit),.manual_commit_done(done),.manual_commit_ok(ok),
|
|
|
+ .watchdog_keepalive(keepalive),.bmc_epoch(epoch),.bmc_stale(stale),.bmc_valid_mask(24'hFFFFFF),
|
|
|
+ .bmc_rd_index(bi),.bmc_rd_raw(braw),.bmc_rd_valid(1'b1),.ct_epoch(16'd0),.ct_stale(1'b1),.ct_valid_mask(27'd0),
|
|
|
+ .snapshot_lock(1'b0),.snapshot_lock_bank(1'b0),.pwm_rd_addr(5'd0),.pwm_rd_data(),
|
|
|
+ .snapshot_output_bank(active_bank),.snapshot_rd_addr(read_addr),.snapshot_requested_data(requested),
|
|
|
+ .snapshot_applied_data(applied),.active_output_bank(active_bank),.control_state(),.current_target_celsius(),
|
|
|
+ .control_epoch(),.safety_override_mask(safety),.lane_fault_mask(lanes),.global_fault(),.output_commit(),
|
|
|
+ .watchdog_active(wd),.watchdog_remaining(remaining),.manual_mode(manual),.hard_protect(hard),
|
|
|
+ .pwm_phase_boundary(1'b1),.pwm_scan_idle(1'b1),.boot_init_complete(ready));
|
|
|
+ integer i;
|
|
|
+ task set_all;
|
|
|
+ begin
|
|
|
+ for(i=0;i<32;i=i+1)begin @(negedge clk);wr=1;addr=i;value=i<24 ? 40 : 30;end
|
|
|
+ @(negedge clk);wr=0;commit=1;@(negedge clk);commit=0;
|
|
|
+ wait(done);if(!ok)$fatal(1,"SET_ALL rejected");@(negedge clk);
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+ task expect_output(input integer a,input integer req,input integer app);
|
|
|
+ begin read_addr=a;repeat(3)@(negedge clk);
|
|
|
+ if(requested!==req || applied!==app)$fatal(1,"channel %0d request/applied=%0d/%0d expected%0d/%0d",a,requested,applied,req,app);
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+ initial begin
|
|
|
+ for(i=0;i<24;i=i+1)temps[i]=50;
|
|
|
+ repeat(4)@(negedge clk);rst_n=1;wait(ready);repeat(5)@(negedge clk);
|
|
|
+ set_all();if(!manual || remaining!=30)$fatal(1,"manual without BMC");
|
|
|
+ stale=0;epoch=1;repeat(300)@(negedge clk);
|
|
|
+ if(!manual || !wd || remaining!=30)$fatal(1,"sensor scan cancelled manual lease");
|
|
|
+ expect_output(0,40,40);expect_output(24,30,30);
|
|
|
+ temps[7]=76;epoch=2;repeat(300)@(negedge clk);
|
|
|
+ expect_output(7,40,0);expect_output(6,40,40);expect_output(25,30,30);
|
|
|
+ temps[7]=77;epoch=3;repeat(300)@(negedge clk);
|
|
|
+ if(lanes!==4'b0010)$fatal(1,"77C lane mapping");
|
|
|
+ for(i=0;i<24;i=i+1)expect_output(i,40,(i>=6&&i<12)?0:40);
|
|
|
+ expect_output(25,30,100);expect_output(29,30,100);expect_output(24,30,30);
|
|
|
+ for(i=0;i<30;i=i+1)begin tick=1;@(negedge clk);tick=0;@(negedge clk);end
|
|
|
+ repeat(300)@(negedge clk);expect_output(0,0,0);expect_output(24,20,20);
|
|
|
+ $display("thermal_safety_contract_tb PASS");$finish;
|
|
|
+ end
|
|
|
+ initial begin #1000000;$fatal(1,"thermal test deadline");end
|
|
|
+endmodule
|