Design a level-sensitive SR latch with an enable input. When enabled, it behaves like an active-high SR latch with deterministic handling of the illegal input combination; when disabled, it holds its current state.
Requirements
sr_latch_enableENSRQQnEN=1:S=1, R=0 → Set: Q=1, Qn=0S=0, R=1 → Reset: Q=0, Qn=1S=1, R=1 → Illegal; treat as Reset: Q=0, Qn=1S=0, R=0 → HoldEN=0:S/R and hold previous statealways @(*)) to infer level-sensitive storage.EN=1, use priority reset > set > hold.Behaviour / Worked Example
From a reset state (Q=0,Qn=1):
EN=1,S=0,R=0 → hold Q=0,Qn=1EN=1,S=1,R=0 → set Q=1,Qn=0EN=0,S=0,R=1 → hold (enable low) Q=1,Qn=0EN=1,S=0,R=1 → reset Q=0,Qn=1EN=1,S=1,R=1 → illegal; treated as reset Q=0,Qn=1EN=1,S=0,R=0 → hold Q=0,Qn=1