V9.5.1 The Slow Side of the Always-On Bridge

MediumImplement25 minIcarus · browser samples / server checksReview the topic

Write the receiving side of a handshake crossing, the pattern ap_soc's always-on bridge uses. Synchronize the request, take the payload once for each request, and answer with an acknowledge, at any ratio of the two clocks.

Hardware context: The crossings of ap_soc v1.5 between clk_sys, clk_aon, TCK and the pads, and the always-on bridge. The slow side of a handshake crossing.

ap_soc reaches its always-on blocks through a bridge between two unrelated clocks. Only two signals pass synchronizers: a request level and an acknowledge level. The payload, address and data, does not. It is held still while the request is high, and the receiver copies it only after the synchronized request says so.

Write hs_rx, the receiving side, on clk_a. Pass req through the given sync_cell. When the synchronized request is up and not yet answered, capture the payload into data. Raise valid for one cycle. Make ack follow the synchronized request: up after it rises, down after it falls.

The sender holds the payload still from before req rises until it sees ack. Then it drops req and waits for ack to fall. Between transfers the payload is unknown. The bench runs eight transfers at several clock ratios, each with its own random draws in sync_cell.

Signals in the Timeline

SignalWidthRole
scenario4input of each check
Full specification
The ports
// The slow side of a four-phase handshake crossing, as in ap_apb_async_bridge.
module hs_rx (
  input  logic       clk_a,     // the receiving clock
  input  logic       resetn_a,  // its reset, active low
  input  logic       req,       // the request level, from another clock: not synchronized
  input  logic [7:0] payload,   // held still by the sender while req is high
  output logic       ack,       // the acknowledge level, back to the sender
  output logic [7:0] data,      // the payload, captured once for each request
  output logic       valid      // high for one cycle of clk_a when data is new
);
  ...
endmodule
The synchronizer cell (given; instantiate it for req)
// sync_cell: two flip-flops on clk, as ap_sync2 of ap_soc. A model of metastability: when d changed less than
// WINDOW ns before a rising edge of clk, the first flip-flop takes the old or the new value at random. The seed is
// set by the bench. Real metastability is analog; this models only its effect on the value and the latency.
module sync_cell #(parameter real WINDOW = 1.5) (input logic clk, resetn, d, output logic q);
  logic meta;
  realtime changed = -1000.0;
  int draw;
  always @(d) changed = $realtime;
  always @(posedge clk or negedge resetn)
    if (!resetn) begin meta <= 1'b0; q <= 1'b0; end
    else begin
      draw = $random(tb.seed);
      if ($realtime - changed < WINDOW && draw[3]) meta <= meta;   // inside the window: the old value, at random
      else meta <= d;
      q <= meta;
    end
endmodule
PhaseSender (10 ns clock)Receiver (your hs_rx)
1payload still, then req = 1the synchronized req rises: data <= payload, valid for one cycle
2waits for ack (through its own two flops)ack = 1
3req = 0the synchronized req falls
4waits for ack to fall; the payload may changeack = 0

The model in sync_cell is not physics: a real flip-flop can hang between 0 and 1 for a time. Here the cell only chooses the old or the new value at random. That moves the moment a change is seen by one edge.

Examples

Example 1

The Chip's Ratio
Input
half period 7 ns, seed 11, 8 transfers from 0x10
Output
delivered = 8, wrong_data = 0, long_valid = 0, ack_rule = 0, data_moved = 0, finished = yes

Eight requests, eight valid pulses, each with the payload the sender held; ack rose and fell only after req did.

Example 2

A Slower Receiver
Input
half period 11 ns, seed 12, 8 transfers from 0x21
Output
delivered = 8, wrong_data = 0, long_valid = 0, ack_rule = 0, data_moved = 0, finished = yes

Each transfer takes longer, and the protocol does not care: every phase waits for the other side.

Example 3

A Faster Receiver
Input
half period 3 ns, seed 13, 8 transfers from 0x32
Output
delivered = 8, wrong_data = 0, long_valid = 0, ack_rule = 0, data_moved = 0, finished = yes

Here an ack that lasts one receiver cycle would be shorter than one sender cycle, and the sender could miss it. A level that waits for req to fall cannot be missed.

Constraints and Contract

  • Keep the module name and the ports. Instantiate sync_cell for req; use no other path from req.
  • Reset (resetn_a low) clears ack, valid and data.
  • valid is high for exactly one cycle of clk_a for each request. data changes only in the cycle valid rises, and then holds.

Hints

Hint 1

Which signal tells you a request is new: the synchronized req alone, or the synchronized req and your own ack?

Hint 2

Why is it safe to copy the payload without a synchronizer? When does the sender change it?

Hint 3

Try a clock faster than the sender's. What does an ack of one cycle look like from its side?

What the grader checks: Seven runs of eight transfers each, at seven clock ratios and seeds. Each counts the valid pulses, those with wrong data and those longer than a cycle. It also counts moves of ack against the rule and changes of data without a valid pulse. It says whether every transfer finished. A source rule checks that req passes sync_cell. The grader cannot see whether you would also survive real metastability, which no simulator shows.

7 checks on Icarus · browser samples / server checks. 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 3 problems on this path

Report a problem with this page

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

The Chip's Ratio

Input
half period 7 ns, seed 11, 8 transfers from 0x10
Expected output
delivered = 8, wrong_data = 0, long_valid = 0, ack_rule = 0, data_moved = 0, finished = yes

Eight requests, eight valid pulses, each with the payload the sender held; ack rose and fell only after req did.

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

Icarus · browser samples / server checks