Add a simple watchdog timeout

This commit is contained in:
Koray Yanik 2023-10-03 22:31:39 +01:00
parent 9cc63a248e
commit bfcdec1d83
1 changed files with 39 additions and 0 deletions

View File

@ -102,5 +102,44 @@ assign selected_memory_implemented = hiram_sel | vram_sel | ppu_sel;
current_pc, last_write_address, last_write_value)
);
// Watchdog timer
localparam HIST_SIZE = 8;
localparam MAX_COUNT = 10000;
logic [15:0] pc_history [$];
int unsigned pc_history_count [$];
always @(posedge clk iff instr_valid) begin
automatic int unsigned current_pc_count = 0;
foreach (pc_history[i]) begin
if (current_pc == pc_history[i]) begin
// History contains current PC, remove from history but keep counter
current_pc_count = pc_history_count[i];
pc_history.delete(i);
pc_history_count.delete(i);
break;
end
end
// Put in front of history queue
pc_history.push_front(current_pc);
pc_history_count.push_front(current_pc_count + 1);
// Prune back of history
if (pc_history.size() > HIST_SIZE) begin
void'(pc_history.pop_back());
void'(pc_history_count.pop_back());
end
assert (current_pc_count < MAX_COUNT) else begin
$display($sformatf("[%0t] Watchdog timeout", $time));
$display("History:");
foreach (pc_history[i]) begin
$display($sformatf("0x%X: %d", pc_history[i], pc_history_count[i]));
end
$fatal();
end
end
`endif /* SVA_ENABLE */
endmodule : tb_top