Hardware interview practice
Prove retention across a power cycle
A four-bit retained register can be written while powered, saved before shutdown, clamped to zero while off, and restored after power returns. Write SystemVerilog assertions and minimal reference state for the retention protocol.
Starting point
Question code
input logic clk,rst_n,power_on,save,restore,wr_en;
input logic [3:0] wr_data,q;Reviewed example
Work through one case
Input
q is written to 4'hA, save is accepted, power turns off with q clamped to zero, power returns, and restore is accepted.Expected output
On the following edge q must equal 4'hA and all saved/off/restore-pending flags clear.The checker snapshots q at save time and performs the required one-cycle-later comparison only after a valid shutdown and restore sequence.
What to cover
Requirements
- Reset clears saved_valid, off_seen, and restore_pending. save is legal only while power_on=1 with all three clear and wr_en=0; it captures q and sets saved_valid. Any other save fails and changes no reference state.
- On the first sampled power_on=0 while off_seen=0, require saved_valid and set off_seen. On every off edge require q=0 and save=restore=wr_en=0.
- restore is legal only with power_on, saved_valid, off_seen, and no restore_pending. It sets restore_pending; on the next edge q must equal the saved value, then clear all three flags. Any other restore fails and preserves state.
- wr_en is legal only while power_on=1 before a save and before shutdown. A write after save, a save after shutdown, or a power-off transition without a saved value must assert-fail.
