Request and Acknowledge: Four Phases and Two

Run a request/acknowledge handshake across two unrelated clocks. Keep its two rules, choose four phases or two, and see why a short request gets lost.

You Will Be Able To

  • Explain the two rules of a four-phase handshake and when each side may change its wire.
  • Predict the levels and the number of changes of req and ack in four-phase and two-phase signalling.
  • Find the bug when a request is a one-cycle pulse that a slower clock can miss.
Lesson
P1.12
Time
30 min
Runs on
Your browser
Check
5 questions

A power controller asked a block to stop its clock by pulsing a request for one cycle of its own clock. The block ran on a slower clock. Most days the pulse fell on one of the block's edges and everything worked. Some days it fell between two edges, the block never saw it, and the controller waited for an answer that never came.

One Word, Four Phases, Two ClocksValues at the sender's rising edges (clock A) from 35 to 175 ns. ack_seen is ack after the sender's two synchronizer flops.
  • Manager
  • Subordinate
reqdataackSenderclock A, 10 nsReceiverclock B, 14 ns
req→ Receiverdata→ Receiverack→ SenderSenderclock A, 10 nsReceiverclock B, 14 ns

Each wire crosses into the other clock through two flops, so every phase costs about two cycles of the receiving clock.

01234567891011121314clkreqackack_seendata11busy
Scroll horizontally ↔
  1. Cycle 0

    Phase 1: req is high and the word 11 is on data. The receiver has not seen it yet.

  2. Cycle 4

    Phase 2: the receiver saw req through its two flops, took the word and raised ack.

  3. Cycle 6

    The sender sees ack, two of its own cycles after ack rose.

  4. Cycle 7

    Phase 3: the sender lowers req. Only now may it change, because ack is at the same level.

  5. Cycle 11

    Phase 4: the receiver saw req low and lowered ack.

  6. Cycle 14

    The sender sees ack low and is free: back where it started, 150 ns after the request.

Four changes per word, each crossing a clock boundary. Data stays put from the rise of req until ack returns.

Pulses Get Lost Between Clocks

A valid/ready handshake assumes one clock. Both sides sample at the same edge, so a pulse of one cycle is a complete message. Across two unrelated clocks that breaks. A signal may change at any moment of the other side's cycle. A one-cycle pulse can fall between two of its edges.

The cure is to talk in levels, not pulses. A request stays up until the other side has answered, however long that takes. That is the request/acknowledge handshake: req from the initiator, ack from the responder.

Four Phases

  1. 1. req rises

    The initiator raises req, with the data already on its wires.

  2. 2. ack rises

    The responder sees req, takes the data and raises ack.

  3. 3. req falls

    The initiator sees ack and lowers req. The data may now change.

  4. 4. ack falls

    The responder sees req low and lowers ack. Both wires are back at 0.

Two rules hold the whole scheme together. The initiator may change req only while ack is at the same level as req. The responder may change ack only while req is at the other level. AXI writes exactly these rules for its coherency connection, SYSCOREQ and SYSCOACK.

reqackStateWho may move next
00IdleThe initiator: raise req
10RequestedThe responder: raise ack
11GrantedThe initiator: lower req
01ReleasingThe responder: lower ack

In every state exactly one side may move. That is why the handshake never races, whatever the clocks.

Crossing a Clock Boundary

Each side reads the other's wire through two flops of its own clock, a synchronizer. The first flop may catch the wire as it changes. The second gives it a full cycle to settle. So each phase costs about two cycles of the receiving clock, as the opening trace shows.

Three details make the crossing safe. First, req comes straight from a flop, never from logic, or a glitch could look like a request. Second, req stays up until ack arrives. Third, the data stays still from the rise of req until the answer, because only req is synchronized. This is called bundled data.

Two Phases

Four phases spend two of their four crossings returning to zero. Two-phase signalling, also called transition signalling, skips them. Every change of req is a request, and every change of ack is its answer. The levels themselves mean nothing.

Four phasesTwo phases
Changes of req per word21
Crossings per word42
Measured in the example130 to 150 ns per word70 to 80 ns per word
Idle statereq = ack = 0req = ack, at either level
CostSimple: levels have a meaningEach side keeps a phase bit and detects changes

Set TWO_PHASE to 1 in the example to measure the second column.

Where You Will Meet It

Four-phase handshakes control the slow, important moments of a chip, where a lost pulse would hang the system.

InterfaceRequestAcknowledgeWhat it controls
AMBA LPI Q-ChannelQREQn (active low)QACCEPTn, or QDENY to refuseStopping a clock or power domain
AXI coherency connectionSYSCOREQSYSCOACKJoining the stream of DVM messages
CHI linkLINKACTIVEREQLINKACTIVEACKBringing a link up and down, with its credits
Clock domain crossingreq toggle or levelack toggle or levelPassing one word between clocks

The LPI signals are active low: the four phases run in the other direction.

Asked in interviews: request and acknowledge
  1. Why not send a one-cycle pulse across clocks?

    The receiving clock may have no edge inside the pulse. A level that stays up until it is acknowledged is always seen.

  2. What are the rules of a four-phase handshake?

    The requester changes req only when ack equals req. The responder changes ack only when req differs from ack.

  3. Four phases or two?

    Two phases halve the crossings, so they are faster. Four phases are simpler, because the levels mean idle or busy.

  4. How do you pass a data word with it?

    Hold the word still from the request until the answer, and synchronize only req and ack. The receiver samples the word after it sees req.

  5. Why must req come from a flop?

    The other side samples it at any moment. A glitch from logic could be seen as a request.

Try It

The sender raises req with the word on data and waits for ack. Every word costs four changes, each seen through two flops of the other clock. The first word takes 150 ns and the others 130 ns. The two clocks drift against each other, so each crossing waits a little differently.

Set TWO_PHASE to 1 in both instances and run again. Each word now takes 70 or 80 ns, about half, because only two crossings are left. Then go back to four phases and add snd.drop_early = 1; before the first send. The first request is lost, and the sender is still waiting when the run ends.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: t=80: receiver took 11 word 11: 150 ns from request to a free sender t=234: receiver took 22 word 22: 130 ns from request to a free sender t=374: receiver took 33 word 33: 130 ns from request to a free sender
Read included file: reqack.sv
// reqack.sv: a request/acknowledge link between two clock domains (read-only).
// The sender puts a word on data and changes req; the receiver takes the word and answers on ack.
// Each side sees the other's signal through two flops of its own clock (a synchronizer).
//   TWO_PHASE = 0, four phases: req rises, ack rises, req falls, ack falls. One word per round.
//   TWO_PHASE = 1, two phases: every change of req is a request, every change of ack its answer.
// The data is held from the change of req until the sender sees the answer (bundled data).
// Twins, set from the bench: snd.drop_early = 1 makes the four-phase sender drop req one cycle
// after raising it, without waiting for ack; rcv.ack_early = 1 makes the receiver raise ack
// as soon as it leaves reset, before any request.
module ra_sender #(parameter bit TWO_PHASE = 0) (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       start,        // send word (only while busy is 0)
  input  logic [7:0] word,
  output logic       busy,
  output logic       req,
  output logic [7:0] data,
  input  logic       ack           // from the other clock domain
);
  bit   drop_early = 0;
  logic s1, s2, seen;
  int   st;
  always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      req <= 0; busy <= 0; data <= 0; s1 <= 0; s2 <= 0; seen <= 0; st = 0;
    end else begin
      s1 <= ack; s2 <= s1;                                   // ack, two flops late
      if (TWO_PHASE) begin
        if (!busy && start) begin data <= word; req <= ~req; busy <= 1; end
        else if (busy && s2 == req) busy <= 0;               // the answer: ack caught up with req
      end else begin
        case (st)
          0: if (start) begin data <= word; req <= 1; busy <= 1; seen <= 0; st = 1; end
          1: if (s2 || drop_early) begin req <= 0; seen <= s2; st = 2; end
          2: begin
               if (s2) seen <= 1;
               if (!s2 && (seen || !drop_early)) begin busy <= 0; st = 0; end
             end
        endcase
      end
    end
  end
endmodule

module ra_receiver #(parameter bit TWO_PHASE = 0) (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       req,          // from the other clock domain
  input  logic [7:0] data,
  output logic       ack,
  output logic       got,          // 1 for one cycle when a word is taken
  output logic [7:0] word
);
  bit   ack_early = 0;
  logic r1, r2;
  always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      ack <= 0; got <= 0; word <= 0; r1 <= 0; r2 <= 0;
    end else begin
      r1 <= req; r2 <= r1; got <= 0;                         // req, two flops late
      if (TWO_PHASE) begin
        if (r2 != ack) begin word <= data; got <= 1; ack <= r2; end
      end else if (ack_early && !r2 && !ack && !got) begin
        ack <= 1;                                            // the twin: an answer nobody asked for
      end else begin
        if (r2 && !ack) begin word <= data; got <= 1; ack <= 1; end
        else if (!r2 && ack) ack <= 0;
      end
    end
  end
endmodule

Check Yourself

Predict the outputThe link runs with four phases and sends two words, each after the previous one has been answered. Then it prints how many times each wire changed after reset. What does it print?
`timescale 1ns/1ps
module tb;
  logic clk_a = 0, clk_b = 0, rst_n = 0;
  always #5 clk_a = ~clk_a;                            // the sender's clock: rising edges at 5, 15, 25, ... ns
  initial begin #3; forever #7 clk_b = ~clk_b; end     // the receiver's clock: rising edges at 10, 24, 38, ... ns
  logic       start = 0;
  logic [7:0] word = 0;
  wire        busy, req, ack, got;
  wire  [7:0] data, rx_word;
  // TWO_PHASE = 0: four phases; 1: two phases.
  ra_sender   #(.TWO_PHASE(0)) snd (.clk(clk_a), .rst_n(rst_n), .start(start), .word(word), .busy(busy), .req(req), .data(data), .ack(ack));
  ra_receiver #(.TWO_PHASE(0)) rcv (.clk(clk_b), .rst_n(rst_n), .req(req), .data(data), .ack(ack), .got(got), .word(rx_word));
  // Send one word and wait until the sender is free again.
  task automatic send(input logic [7:0] w);
    realtime t0;
    @(posedge clk_a); #1 start = 1; word = w; t0 = $realtime;
    @(posedge clk_a); #1 start = 0;
    while (busy) begin @(posedge clk_a); #1; end
  endtask
  int req_changes = 0, ack_changes = 0;
  always @(req) if (rst_n) req_changes++;
  always @(ack) if (rst_n) ack_changes++;
  initial begin
    #12 rst_n = 1;                                     // reset released between edges
    send(8'h11); send(8'h22);
    #60 $display("req changed %0d times, ack changed %0d times", req_changes, ack_changes);
    #50 $finish;
  end
endmodule
Read included file: reqack.sv
// reqack.sv: a request/acknowledge link between two clock domains (read-only).
// The sender puts a word on data and changes req; the receiver takes the word and answers on ack.
// Each side sees the other's signal through two flops of its own clock (a synchronizer).
//   TWO_PHASE = 0, four phases: req rises, ack rises, req falls, ack falls. One word per round.
//   TWO_PHASE = 1, two phases: every change of req is a request, every change of ack its answer.
// The data is held from the change of req until the sender sees the answer (bundled data).
// Twins, set from the bench: snd.drop_early = 1 makes the four-phase sender drop req one cycle
// after raising it, without waiting for ack; rcv.ack_early = 1 makes the receiver raise ack
// as soon as it leaves reset, before any request.
module ra_sender #(parameter bit TWO_PHASE = 0) (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       start,        // send word (only while busy is 0)
  input  logic [7:0] word,
  output logic       busy,
  output logic       req,
  output logic [7:0] data,
  input  logic       ack           // from the other clock domain
);
  bit   drop_early = 0;
  logic s1, s2, seen;
  int   st;
  always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      req <= 0; busy <= 0; data <= 0; s1 <= 0; s2 <= 0; seen <= 0; st = 0;
    end else begin
      s1 <= ack; s2 <= s1;                                   // ack, two flops late
      if (TWO_PHASE) begin
        if (!busy && start) begin data <= word; req <= ~req; busy <= 1; end
        else if (busy && s2 == req) busy <= 0;               // the answer: ack caught up with req
      end else begin
        case (st)
          0: if (start) begin data <= word; req <= 1; busy <= 1; seen <= 0; st = 1; end
          1: if (s2 || drop_early) begin req <= 0; seen <= s2; st = 2; end
          2: begin
               if (s2) seen <= 1;
               if (!s2 && (seen || !drop_early)) begin busy <= 0; st = 0; end
             end
        endcase
      end
    end
  end
endmodule

module ra_receiver #(parameter bit TWO_PHASE = 0) (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       req,          // from the other clock domain
  input  logic [7:0] data,
  output logic       ack,
  output logic       got,          // 1 for one cycle when a word is taken
  output logic [7:0] word
);
  bit   ack_early = 0;
  logic r1, r2;
  always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      ack <= 0; got <= 0; word <= 0; r1 <= 0; r2 <= 0;
    end else begin
      r1 <= req; r2 <= r1; got <= 0;                         // req, two flops late
      if (TWO_PHASE) begin
        if (r2 != ack) begin word <= data; got <= 1; ack <= r2; end
      end else if (ack_early && !r2 && !ack && !got) begin
        ack <= 1;                                            // the twin: an answer nobody asked for
      end else begin
        if (r2 && !ack) begin word <= data; got <= 1; ack <= 1; end
        else if (!r2 && ack) ack <= 0;
      end
    end
  end
endmodule
ConceptIn a four-phase handshake, req and ack are both 1. Who may change a wire next, and to what?
ConceptA request crosses into a clock domain through two flops. Why does the data bus next to it not need its own two-flop synchronizer per bit?
Read the waveformA four-phase handshake, one value per cycle. In which cycle does a side break a rule?
req and ack, one value per cycle
0123456reqack
Scroll horizontally ↔

Cycles 0 to 6.

ConceptWhat does two-phase signalling cost compared with four phases?

Common Mistakes

Wrong Send a request across clocks as a one-cycle pulse.

The receiving clock may have no edge inside the pulse, so the request is lost and the sender waits for ever.

Fix Hold req until ack arrives, as the four-phase rules require.

Wrong Drive req from combinational logic.

The other domain samples req at any moment, so a glitch can be taken as a request.

Fix Drive req straight from a flop in the sender's clock.

Before
assign req = start && !busy;
After
always_ff @(posedge clk_a)
  if (start && !busy) req <= 1;

Wrong Pass a data bus through a two-flop synchronizer on every bit.

Bits may settle on different cycles, so the receiver can see half of one word and half of the next.

Fix Hold the data still under the handshake and synchronize only req and ack.

Remember

  • Across unrelated clocks, send levels, not pulses. A request stays up until it is acknowledged.
  • Four phases: req up, ack up, req down, ack down. The initiator moves when ack equals req; the responder moves when they differ.
  • Each side synchronizes the other's wire through two flops, so each phase costs about two cycles of the receiving clock.
  • Only req and ack are synchronized. The data stays still from the request to the answer.
  • Two-phase signalling treats every change as a message: half the crossings, but levels lose their meaning.

Practice

Report a problem with this page