Hardware interview practice
Bridge a sticky memory-error alarm across clocks
A fast memory-test clock may detect an error while a slower service clock is busy. The alarm must not be lost and only one alarm may be pending. Implement the request/acknowledge alarm bridge in SystemVerilog.
Starting point
Question code
input logic src_clk, dst_clk, rst_n;
input logic src_error; output logic src_pending;
output logic dst_alarm; input logic dst_clear;Reviewed example
Work through one case
Input
Pulse src_error once and leave dst_clear low.Expected output
req and src_pending stay high, dst_alarm becomes and remains high, and ack stays low.The four-phase request remains pending until the destination explicitly clears the sticky alarm and raises acknowledgement.
What to cover
Requirements
- Implement internal four-phase req/ack levels. In the source domain, src_error sets req=1 and src_pending=1; later src_error pulses while pending are coalesced into that request.
- Synchronize req through two destination flops. When a new synchronized req=1 is seen with ack=0, set dst_alarm. A dst_clear on that same edge loses to the set. On a later edge with dst_alarm=1, req=1, and dst_clear=1, clear dst_alarm and set ack=1.
- Synchronize ack through two source flops. When synchronized ack becomes 1, lower req but keep src_pending=1. The destination holds ack=1 until synchronized req becomes 0, then lowers ack; only after synchronized ack returns to 0 may the source clear src_pending.
- rst_n asynchronously clears req, ack, both synchronizer chains, src_pending, and dst_alarm. Reset has priority; no combinational path crosses domains, and dst_clear while dst_alarm=0 has no effect.
