cfar_ca: reset detect_count per frame (AUDIT-C6)

Bug: 16-bit detect_count was reset only on power-on; increments at three
sites (ST_IDLE/ST_BUFFER simple-threshold paths and ST_CFAR_CMP) accumulate
across frames. At 178 fps with even 2-3 average detections per frame the
counter wraps in 100-180 seconds, breaking any rate-based host telemetry
or health check that reads it.

Fix: add `detect_count <= 16'd0` in ST_DONE so the counter represents
"detections this frame" instead of cumulative-since-boot. Updated $display
wording from "total detections" to "frame detections".

T13 flipped from "count keeps growing" to "identical-scene frames produce
identical counts" (the actual contract a per-frame counter must satisfy).
TB snapshots detect_count during ST_DONE because cfar_busy only goes low
on ST_IDLE entry — after the reset has fired.

Verification: tb_cfar_ca 24/24 PASS, quick regression 31/31 PASS.

Note: detect_count output port is now "live" (accumulates during frame,
0 between frames). Audit confirmed no current host telemetry consumes
this port. If future host code needs a stable last-frame total, add a
detect_count_last_frame snapshot register then.
This commit is contained in:
Jason
2026-04-29 18:09:28 +05:45
parent e67368d621
commit 53c7f416a7
2 changed files with 36 additions and 8 deletions
+9 -1
View File
@@ -575,13 +575,21 @@ always @(posedge clk or negedge reset_n) begin
// ================================================================
// ST_DONE: Frame complete, return to idle
// ================================================================
// AUDIT-C6 fix: reset detect_count per-frame so it represents
// "detections this frame" instead of "total since power-on". The
// 16-bit counter saturates after ~6500 frames at typical detection
// rates (tens of seconds of real traffic), breaking any rate-based
// host telemetry that reads it.
// ================================================================
ST_DONE: begin
cfar_status <= 8'd0;
state <= ST_IDLE;
`ifdef SIMULATION
$display("[CFAR] Frame complete: %0d total detections", detect_count);
$display("[CFAR] Frame complete: %0d frame detections", detect_count);
`endif
detect_count <= 16'd0;
end
default: state <= ST_IDLE;