R6.5.1 Wait for the Receiver

MediumFixIcarus Verilog + Yosys · serverReview the topic

Fix the sending half of an event link. It must hold its events until the receiver is out of reset, and fall back to idle when the receiver goes down.

Hardware context: The sending half of an event link: an event count, a toggle with a gap between flips, and the receiver's up flag from another clock domain. Fix the sender so that it waits for the receiver and loses no event.

A sensor hub reports events to a radio block on another clock. The hub flips a toggle wire once per event. The radio powers up later than the hub, and it can be reset again in the field. Events from the first milliseconds after power-up never arrived, and after a radio reset one extra event sometimes appeared.

The radio already sends a flag, b_up, which is 1 while it is out of reset. The shipped sender ignores it and starts as soon as its own reset is released. This is a Fix problem: make wake_send follow the brief. The tests drive ev, b_up and a reset pulse, and compare tog and pending with a model after every edge.

Brief: rising-edge clk; rst_n asynchronous and active-low. b_up comes from the other domain, so it must pass through two flops before anything uses it. Upstream does not wait: ev may be 1 at any edge, and no event may be lost. Synthesis check: the design must build on the site's synthesis flow with no latch.

Signals in the Timeline

SignalWidthRole
script120input of each check
Full specification
The sender's ports (keep the name and the ports)
module wake_send (
  input  logic       clk,          // the sender's clock
  input  logic       rst_n,        // the sender's reset: asynchronous, active-low
  input  logic       b_up,         // from the receiver's domain: 1 while the receiver is out of reset
  input  logic       ev,           // 1 for one cycle per event to send; may come at any time
  output logic       tog,          // to the receiver: one flip per event
  output logic [3:0] pending       // events taken and not yet sent
);
  ...
endmodule
RuleAt each rising edge out of reset, from the values before the edge
readyready is b_up delayed by two flops. Both flops reset to 0.
sendA send happens when ready is 1, pending is not 0 and the gap has passed.
pendingpending goes up by 1 if ev is 1 and down by 1 if a send happens. Both can happen at one edge.
togA send flips tog. While ready is 0, tog returns to 0.
gapAfter a send, the next send is at least 4 edges later. While ready is 0 the gap is cleared.
resetWhile rst_n is 0: tog 0, pending 0, both flops 0, no gap.

Why tog returns to 0: the receiver's synchronizer flops reset to 0. A toggle left at 1 would look like an event when the receiver wakes.

Each test resets the sender, then runs 40 steps of one edge each. b_up changes between two edges. The result holds tog after every step and pending after every fourth step. The tests never hold more than 15 events.

Examples

Example 1

Three Events Before the Receiver Is Up
Input
b_up=0 x2, b_up=0 ev x3, b_up=0 x7, b_up=1 x28
Output
tog_per_step = 'b1111111111111111110000111100000000000000, pending_step3 = 2, pending_step7 = 3, pending_step11 = 3, pending_step15 = 2, pending_step19 = 1, pending_step23 = 0, pending_step27 = 0, pending_step31 = 0, pending_step35 = 0, pending_step39 = 0

pending counts to 3 while b_up is 0 and tog stays 0. b_up rises before step 12. The first flip is at step 14, after two flops, and the others follow 4 edges apart.

Example 2

The Receiver Is up First
Input
b_up=1 x6, b_up=1 ev, b_up=1 x33
Output
tog_per_step = 'b1111111111111111111111111111111110000000, pending_step3 = 0, pending_step7 = 0, pending_step11 = 0, pending_step15 = 0, pending_step19 = 0, pending_step23 = 0, pending_step27 = 0, pending_step31 = 0, pending_step35 = 0, pending_step39 = 0

ready is already 1 when the event arrives at step 6. pending is 1 for one cycle, and tog flips at step 7.

Example 3

The Receiver Comes up Late
Input
b_up=0 ev, b_up=0 x20, b_up=1 x19
Output
tog_per_step = 'b1111111111111111100000000000000000000000, pending_step3 = 1, pending_step7 = 1, pending_step11 = 1, pending_step15 = 1, pending_step19 = 1, pending_step23 = 0, pending_step27 = 0, pending_step31 = 0, pending_step35 = 0, pending_step39 = 0

The event of step 0 waits in pending until step 23, two edges after b_up rises. A sender that waits a fixed number of edges would have sent it into a sleeping receiver.

Constraints and Contract

  • ev is a known 0/1 value and changes while clk is low. b_up may change at any time.
  • Keep the module name and the ports.

Hints

Hint 1

Start with the flag. Nothing in the sender may read b_up except the first of two flops.

Hint 2

Count events in pending whether the receiver is up or not. Sending is a separate decision.

Hint 3

Give the "receiver is down" case its own branch: it sets tog to 0 and clears the gap. pending keeps counting there.

What the grader checks: Nine directed and eleven seeded scripts of forty edges each drive ev, b_up and a reset pulse. tog after every edge and pending after every fourth are compared with an independent model. Zero-delay simulation has no metastability, so the two flops are checked by their delay, not by a settle time.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

20 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Three Events Before the Receiver Is Up

Input
b_up=0 x2, b_up=0 ev x3, b_up=0 x7, b_up=1 x28
Expected output
tog_per_step = 'b1111111111111111110000111100000000000000, pending_step3 = 2, pending_step7 = 3, pending_step11 = 3, pending_step15 = 2, pending_step19 = 1, pending_step23 = 0, pending_step27 = 0, pending_step31 = 0, pending_step35 = 0, pending_step39 = 0

pending counts to 3 while b_up is 0 and tog stays 0. b_up rises before step 12. The first flip is at step 14, after two flops, and the others follow 4 edges apart.

Run samples executes all 3 public checks. Check all tests runs 20 checks on the server.

Icarus Verilog + Yosys · server