P1.12.1 A Word Bridge Between Clocks

HardImplementIcarus · browser samples / server checksReview the topic

Build a bridge that carries words from one clock to another. It has valid/ready on each side, a four-phase handshake in between, and backpressure from the far consumer.

Hardware context: A request/acknowledge crossing between two unrelated clock domains. Implement a valid/ready-to-four-phase word bridge between two clocks with backpressure on the far side.

Lesson P1.12 sent words across two clocks with a four-phase handshake, and its receiver always had room. Real receivers do not. The block behind them stalls, and the bridge must hold the handshake until there is somewhere to put the word.

Write module cdc_bridge. On clock A it takes words on in_valid and in_ready. It holds each word on xdata and raises req. On clock B it sees req through two flops, puts the word on out_valid and out_data, and answers with ack.

The fixture runs pairs of clocks with different ratios, gaps in the source and stalls on the consumer. It counts the words delivered and checks their order. It also watches the crossing in every nanosecond for broken handshake rules and moving data.

Signals in the Timeline

SignalWidthRole
words4input of each check
Full specification
The module you write (keep these ports)
module cdc_bridge (
  // clock A side: words come in on valid/ready
  input  logic       clk_a,
  input  logic       rst_a_n,
  input  logic       in_valid,
  output logic       in_ready,
  input  logic [7:0] in_data,
  // clock B side: words go out on valid/ready
  input  logic       clk_b,
  input  logic       rst_b_n,
  output logic       out_valid,
  input  logic       out_ready,
  output logic [7:0] out_data,
  // the crossing, visible for checking: req and xdata from A, ack from B
  output logic       req,
  output logic       ack,
  output logic [7:0] xdata
);
  // your bridge
endmodule
RuleWhat the fixture checks
Valid/ready on each sideA word moves at a rising edge of its clock where valid and ready are both 1. The source holds an offer until it is taken.
reqMay change only while ack is at the same level as req.
ackMay change only while req is at the other level.
Bundled dataxdata does not change while req is 1 and ack is 0.
SynchronizersEach clock reads the other domain's wire through two flops of its own.
DeliveryEvery word arrives once, in order, even when out_ready stalls.

Each case runs 3000 ns. Clock A and clock B each spend the first half of their period low. Resets are released at 1 ns.

The result is {received[7:0], misordered[7:0], rule_errors[7:0], data_errors[7:0], 16 zero bits, first[31:0]}, with the first four words received, word 0 in the low byte.

Examples

Example 1

Clock A Faster, No Stalls
Input
clock A 10 ns, clock B 14 ns, 6 words; source offers by 16'hffff, consumer ready by 16'hffff (bit = edge mod 16)
Output
received = 6, misordered = 0, rule_errors = 0, data_errors = 0, first_words = 0x33323130

Six words arrive in order, 30 to 35. No handshake rule breaks and xdata never moves under a waiting req.

Example 2

Clock B Faster
Input
clock A 14 ns, clock B 10 ns, 6 words; source offers by 16'hffff, consumer ready by 16'hffff (bit = edge mod 16)
Output
received = 6, misordered = 0, rule_errors = 0, data_errors = 0, first_words = 0x33323130

Now the receiving clock is the faster one. The six words still arrive once each and in order, with no broken rule.

Example 3

A Slow Consumer
Input
clock A 10 ns, clock B 14 ns, 6 words; source offers by 16'hffff, consumer ready by 16'h1111 (bit = edge mod 16)
Output
received = 6, misordered = 0, rule_errors = 0, data_errors = 0, first_words = 0x33323130

The consumer is ready one edge in four. The bridge must keep ack low until its output register has room, so req stays up longer.

Constraints and Contract

  • Keep the module name and the ports. Drive req and xdata only from clock A flops, and ack only from a clock B flop.
  • Use one output register on clock B. Do not reach outside your ports.

Hints

Hint 1

Clock A: three states. Idle and ready; req up, waiting for ack; req down, waiting for ack to fall.

Hint 2

Clock B: raise ack only when the output register can take the word. It must be empty, or being emptied at this edge.

Hint 3

Lower ack only after req has fallen, as seen through your synchronizer. Lowering it when the word leaves breaks the handshake rules.

What the grader checks: Your bridge runs nine clock pairs and traffic patterns for 3000 ns each. Deliveries, order and the crossing are checked every nanosecond. RTL simulation cannot show metastability, so the synchronizers are checked by structure, not by timing.

9 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 2 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

Clock A Faster, No Stalls

Input
clock A 10 ns, clock B 14 ns, 6 words; source offers by 16'hffff, consumer ready by 16'hffff (bit = edge mod 16)
Expected output
received = 6, misordered = 0, rule_errors = 0, data_errors = 0, first_words = 0x33323130

Six words arrive in order, 30 to 35. No handshake rule breaks and xdata never moves under a waiting req.

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

Icarus · browser samples / server checks