Skip to content

One distinguished header, three different kinds of persistent state

write-from-scratch / cross-call-state / lifecycle-hook / multi-constraint

A frame stream where each frame has a header, an id, a payload and a size. The rules only bite for frames whose header is the distinguished value XYZ:

  • XYZ frames carry a payload counting up from 100. That count has to survive across freshly constructed objects, which is why next_xyz_payload and frames_since_last_xyz are already static.
  • XYZ frames can’t come too close together or too far apart. That’s about when a frame may be XYZ, so constrain header itself against frames_since_last_xyz rather than checking afterward.
  • ids are a separate rule: no frame reuses an earlier frame’s id. randc looks right, but its cycling isn’t reliable on this toolchain once you exclude more than the last value (see the README, “Real, current tool limitations”). Use a plain rand field and a queue of used ids with inside {}.

Fix the class below.

RequirementsAcross many randomize() calls on freshly constructed objects

  1. Every frame’s id differs from every earlier frame’s id.
  2. header may equal XYZ (8’hAB) only if at least 5 frames have passed since the last XYZ frame (or there hasn’t been one), and must equal XYZ once 9 have passed, so no run of 10 frames is XYZ-free.
  3. When header == XYZ, payload is 100 for the first such frame, 101 for the second, and so on, counting only XYZ frames.

Source on GitHub

tagged_frame_sequence.sv