AMBA 2 AHB: HBUSREQ, HGRANT, SPLIT and RETRY

Read an AMBA 2 AHB system. Masters request the bus and are granted it, slaves answer RETRY or SPLIT, and HSPLIT brings a split master back.

You Will Be Able To

  • Say when a master owns the address bus in AMBA 2 AHB.
  • Tell RETRY from SPLIT by what the arbiter does afterwards.
  • Trace a SPLIT transaction from the response to HSPLIT and the retried transfer.
  • Explain why AHB-Lite has a one-bit HRESP and no request or grant.
Lesson
P4.16
Time
30 min
Runs on
Your browser
Check
5 questions

A slow flash controller on an old AMBA 2 bus answered long reads with SPLIT. An engineering change tied its HSPLIT output to zero by mistake. The DMA engine kept running, but the processor's first instruction fetch from flash never came back. The arbiter was still waiting to be told the processor could try again.

A SPLIT That Is Never ResumedEdges 3 to 14 with split_never_resumed = 1. hmaster is the owner of the address bus (2 is the default master); mask0 is the arbiter's mask on master 0.
  • Manager
  • Control / FSM
  • Subordinate
HRESPHSPLIT[0]Master 0processor, low priorityMaster 1DMA, high priorityArbitermasks a split masterFlashanswers SPLIT
HRESP→ Master 0HSPLIT[0]→ ArbiterMaster 0processor, low priorityMaster 1DMA, high priorityArbitermasks a split masterFlashanswers SPLIT

The flash fetches the data but never asserts HSPLIT[0].

01234567891011clkhmaster2021hrespOKAYSPLITOKAYmask0hsplit0m0_done
Scroll horizontally ↔
  1. Cycle 0

    The arbiter grants master 0, the only requester. It reads the flash.

  2. Cycle 2

    The flash answers SPLIT: the first cycle, with HREADY low.

  3. Cycle 3

    The second cycle. The arbiter masks master 0 and grants the default master.

  4. Cycle 5

    Master 1, the DMA, gets the bus and runs normally.

  5. Cycle 11

    The data has been ready since edge 12, but HSPLIT[0] never rises. Master 0 waits for ever.

In the correct run the flash pulses HSPLIT[0] at edge 12 and master 0 completes at edge 16.

Request and Grant

AMBA 2 AHB is a shared bus with up to 16 masters and one arbiter. A master raises HBUSREQx when it wants the bus. The arbiter answers with HGRANTx to the highest-priority requester and shows the owner on HMASTER.

SignalFromMeaning
HBUSREQxmasterI want the bus.
HLOCKxmasterMy next transfers are indivisible; asserted a cycle before the address it covers.
HGRANTxarbiterYou are the highest-priority requester.
HMASTER[3:0]arbiterThe number of the master that owns the address bus.
HMASTLOCKarbiterThe current transfer is part of a locked sequence.
HSPLIT[15:0]SPLIT-capable slaveThe master with this bit set may try again.

IHI 0011A 3.11.1.

A master owns the address bus after an edge where its HGRANT and HREADY are both high. A master granted without asking must drive IDLE: when nobody requests, the arbiter grants a default master.

RETRY and SPLIT

AMBA 2 HRESP has two bits: OKAY, ERROR, RETRY and SPLIT. Only OKAY may take one cycle; the others take two, so the master can cancel the transfer behind. RETRY and SPLIT both say "not yet, try again", and a master treats them the same way.

RETRY

the arbiter keeps its priority scheme
only higher-priority masters get in
the master asks again at once
each retry costs bus cycles

Simple for the slave, but a low-priority master can keep the bus busy with retries.

SPLIT

the slave notes HMASTER
the arbiter masks that master's request
any other master may use the bus
HSPLIT[m] unmasks it when data is ready

The bus is completely free meanwhile, at the cost of logic in the slave and the arbiter.

The example runs both with the same traffic. With SPLIT, master 0 tries twice: once to start the fetch, once after HSPLIT. With RETRY it tries three times, and one retry lands while master 1 is waiting.

Why AHB-Lite Left Them Out

Request, grant, RETRY and SPLIT exist so that several masters can share one bus. AHB-Lite has one manager, so it needs none of them. HRESP is a single bit, OKAY or ERROR, and there is no HBUSREQ or HGRANT. Several managers now meet in an interconnect, as lesson P4.15 shows, and a waiting manager just sees HREADY low.

Asked in interviews: AMBA 2 AHB
  1. What is the difference between RETRY and SPLIT?

    After RETRY the arbiter keeps its priorities. After SPLIT it masks the master until the slave asserts its HSPLIT bit, so any other master may use the bus.

  2. Why are ERROR, RETRY and SPLIT two-cycle responses?

    The first cycle, with HREADY low, gives the master time to cancel the transfer already in its address phase.

  3. What happens if a SPLIT slave never asserts HSPLIT?

    The arbiter never unmasks that master, which never completes: a hang that looks like a busy bus.

  4. Does AHB-Lite support SPLIT?

    No. AHB-Lite has a one-bit HRESP, OKAY or ERROR, and no request or grant signals.

Try It

Master 0 is alone at first, so it gets the bus and reads the slow slave, which answers SPLIT and starts fetching. The arbiter masks master 0 and grants the default master, then master 1 when it asks. Master 1 reads at full speed while the fetch runs. HSPLIT[0] at edge 12 unmasks master 0, which wins the bus after master 1 and completes.

Add bus.use_retry = 1; for RETRY: master 0 is told to try again twice and completes at edge 17. Add bus.split_never_resumed = 1; for the opening story: master 0 never completes.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: e3: bus to master 0 e6: master 0 got SPLIT e6: bus to the default master e7: bus to master 1 e9: master 1 read 0x10 = d0000010 e11: master 1 read 0x14 = d0000014 e12: slow slave asserts HSPLIT for master 0 e13: master 1 read 0x18 = d0000018 e14: bus to master 0 e16: master 0 read 0x1040 = 5d001040 after 1 SPLIT e17: bus to the default master
Read included file: ahb2_bus.sv
`timescale 1ns/1ns
// ahb2_bus.sv: two AMBA 2 bus masters, an arbiter, a fast slave and a SPLIT-capable slow slave (read-only).
// Masters (M0 low priority, M1 high) each run a list of single NONSEQ reads, set from the stimulus:
// n_rd[m] reads at rd_addr[m][i]. A master raises HBUSREQ while it has a read to do, drives the address
// when HGRANT and HREADY have both been high at an edge (it owns the address bus), then drives IDLE. On
// SPLIT or RETRY it tries the same read again later; on OKAY it moves on.
// The arbiter grants the highest-priority requester whose request is not masked; with no requester it
// grants a default master (number 2) that only drives IDLE. A SPLIT masks the master's request until the
// slave asserts its bit of HSPLIT.
// Slaves: addresses below 0x1000 are the fast slave (zero wait, OKAY). From 0x1000 the slow slave: a
// read it has not prepared gets the two-cycle SPLIT; it notes HMASTER, fetches for LATENCY cycles, then
// pulses HSPLIT for that master; the retried read then completes with OKAY. Read data is the address
// with its top half set to 0xd0 (fast) or 0x5d (slow).
// Switches: latency (default 6); use_retry (answer RETRY, and never mask); split_never_resumed (the
// broken twin: the slave never asserts HSPLIT); trace; quiet (no completion lines). attempts[m] counts tries.
module ahb2_bus (input logic hclk, input logic hresetn);
  int latency = 6;
  bit use_retry = 0, split_never_resumed = 0, trace = 0, quiet = 0;
  localparam logic [1:0] OKAY = 2'b00, ERROR = 2'b01, RETRY = 2'b10, SPLIT = 2'b11;
  int cycle = -1;
  // ---- the masters' scripts and progress ----
  int          n_rd [0:1], next [0:1], tries [0:1], attempts [0:1];   // attempts counts every try
  logic [31:0] rd_addr [0:1][0:7];
  logic [31:0] got [0:1][0:7];
  int          done_at [0:1][0:7];
  initial for (int m = 0; m < 2; m++) begin n_rd[m] = 0; next[m] = 0; tries[m] = 0; attempts[m] = 0; end
  // ---- the bus ----
  logic [1:0]  hbusreq, hgrant;
  logic [1:0]  hmaster = 2;              // 0, 1 or the default master 2
  logic [1:0]  htrans;
  logic [31:0] haddr, hrdata;
  logic        hready = 1;
  logic [1:0]  hresp = OKAY;
  logic [1:0]  hsplit = 0, mask = 0;
  // the data phase in progress
  logic        d_on = 0;
  logic [1:0]  d_m = 0;
  logic [31:0] d_a = 0;
  // the slow slave
  logic        s_second = 0;              // the second cycle of a SPLIT or RETRY
  logic [1:0]  s_pend_m = 0;              // the fetch in progress: for which master, which address
  logic [31:0] s_pend_a = 0;
  bit          s_busy = 0;
  logic        prep_v = 0;                // a fetched word waits for its master's retry
  logic [1:0]  prep_m = 0;
  logic [31:0] prep_a = 0;
  int          s_count = 0;
  // what each master asks for
  int next0 = 0, next1 = 0, nrd0 = 0, nrd1 = 0;   // copies of next[] and n_rd[] for the wires below
  assign hbusreq = {next1 < nrd1, next0 < nrd0};
  // the owner drives NONSEQ only when it has a read and none in flight
  logic [1:0] in_flight = 0;
  logic [31:0] want0 = 0, want1 = 0;      // each master's next read address
  always @* begin
    htrans = 2'b00; haddr = 0;
    if (hmaster < 2 && hbusreq[hmaster] && !in_flight[hmaster]) begin htrans = 2'b10; haddr = (hmaster == 1) ? want1 : want0; end
  end
  // the arbiter: the highest-priority unmasked requester, else the default master
  // A SPLIT in its second cycle masks the master at once, so the arbiter never regrants it there.
  wire [1:0] masked = mask | ((d_on && hready && hresp == SPLIT) ? (2'b01 << d_m) : 2'b00);
  always @* begin
    if (hbusreq[1] && !masked[1]) hgrant = 2'b10;
    else if (hbusreq[0] && !masked[0]) hgrant = 2'b01;
    else hgrant = 2'b00;
  end
  // responses
  wire slow     = d_on && d_a >= 32'h1000;
  wire prepared = prep_v && prep_m == d_m && prep_a == d_a;
  always @* begin
    hready = 1; hresp = OKAY; hrdata = 0;
    if (d_on && !slow) hrdata = {16'hd000, d_a[15:0]};
    else if (slow) begin
      if (s_second) begin hready = 1; hresp = use_retry ? RETRY : SPLIT; end
      else if (!prepared) begin hready = 0; hresp = use_retry ? RETRY : SPLIT; end
      else hrdata = {16'h5d00, d_a[15:0]};
    end
  end
  always @(posedge hclk) begin
    cycle = cycle + 1;
    want0 = rd_addr[0][next[0]]; want1 = rd_addr[1][next[1]];
    next0 = next[0]; next1 = next[1]; nrd0 = n_rd[0]; nrd1 = n_rd[1];
    if (!hresetn) begin
      hmaster <= 2; d_on <= 0; in_flight <= 0; mask <= 0; hsplit <= 0; s_second <= 0; prep_v <= 0;
    end else begin
      // the slow slave fetches, then tells the arbiter which master may come back
      hsplit <= 0;
      if (s_busy) begin
        if (s_count > 0) s_count = s_count - 1;
        else begin
          s_busy = 0; prep_v <= 1; prep_m <= s_pend_m; prep_a <= s_pend_a;
          if (!split_never_resumed && !use_retry) begin
            hsplit[s_pend_m] <= 1;
            if (trace) $display("e%0d: slow slave asserts HSPLIT for master %0d", cycle, s_pend_m);
          end
        end
      end
      if (hsplit[0]) mask[0] <= 0;
      if (hsplit[1]) mask[1] <= 0;
      // the data phase
      if (slow && !s_second) begin
        if (prepared) prep_v <= 0;                                   // the retried read completes now
        else begin
          s_second <= 1;                                             // the second cycle follows
          if (!s_busy && !prep_v) begin s_busy = 1; s_pend_m = d_m; s_pend_a = d_a; s_count = latency; end
        end
      end else if (s_second) s_second <= 0;
      if (d_on && hready) begin
        attempts[d_m] = attempts[d_m] + 1;
        if (hresp == OKAY) begin
          got[d_m][next[d_m]] = hrdata; done_at[d_m][next[d_m]] = cycle;
          if (quiet) ;
          else if (tries[d_m]) $display("e%0d: master %0d read 0x%0h = %h after %0d %0s", cycle, d_m, d_a, hrdata, tries[d_m], use_retry ? "RETRY" : "SPLIT");
          else $display("e%0d: master %0d read 0x%0h = %h", cycle, d_m, d_a, hrdata);
          next[d_m] = next[d_m] + 1; tries[d_m] = 0;
          want0 = rd_addr[0][next[0]]; want1 = rd_addr[1][next[1]];
          next0 = next[0]; next1 = next[1];
        end else begin
          tries[d_m] = tries[d_m] + 1;
          if (hresp == SPLIT) mask[d_m] <= 1;
          if (trace) $display("e%0d: master %0d got %0s", cycle, d_m, hresp == SPLIT ? "SPLIT" : "RETRY");
        end
        in_flight[d_m] <= 0;
      end
      // the address phase
      if (hready) begin
        d_on <= htrans[1]; d_m <= hmaster; d_a <= haddr;
        if (htrans[1]) in_flight[hmaster] <= 1;
        // A master owns the address bus after an edge where its HGRANT and HREADY are both high.
        if (hgrant == 2'b10 && hmaster != 1) begin hmaster <= 1; if (trace) $display("e%0d: bus to master 1", cycle); end
        else if (hgrant == 2'b01 && hmaster != 0) begin hmaster <= 0; if (trace) $display("e%0d: bus to master 0", cycle); end
        else if (hgrant == 2'b00 && hmaster != 2) begin hmaster <= 2; if (trace) $display("e%0d: bus to the default master", cycle); end
      end
    end
  end
endmodule

Check Yourself

Predict the outputMaster 0 is alone and reads the slow slave, which answers RETRY and needs 9 cycles to fetch. The program prints how many times master 0 tried and the edge where the read completed. What is the line?
`timescale 1ns/1ps
module tb;
  logic hclk = 0, hresetn = 0;
  always #5 hclk = ~hclk;                 // rising edges at 5, 15, 25, ...
  ahb2_bus bus (.hclk(hclk), .hresetn(hresetn));
  initial begin
    bus.quiet = 1; bus.use_retry = 1; bus.latency = 9;
    repeat (2) @(posedge hclk); #1 hresetn = 1;   // reset released after edge 1
    bus.rd_addr[0][0] = 32'h1040; bus.n_rd[0] = 1;
    repeat (30) @(posedge hclk);
    $display("master 0 tried %0d times; the read completed at edge %0d", bus.attempts[0], bus.done_at[0][0]);
    repeat (40) @(posedge hclk);
    for (int m = 0; m < 2; m++)
      if (bus.next[m] < bus.n_rd[m]) $display("master %0d is still waiting for read %0d", m, bus.next[m]);
    $finish;
  end
endmodule
Read included file: ahb2_bus.sv
`timescale 1ns/1ns
// ahb2_bus.sv: two AMBA 2 bus masters, an arbiter, a fast slave and a SPLIT-capable slow slave (read-only).
// Masters (M0 low priority, M1 high) each run a list of single NONSEQ reads, set from the stimulus:
// n_rd[m] reads at rd_addr[m][i]. A master raises HBUSREQ while it has a read to do, drives the address
// when HGRANT and HREADY have both been high at an edge (it owns the address bus), then drives IDLE. On
// SPLIT or RETRY it tries the same read again later; on OKAY it moves on.
// The arbiter grants the highest-priority requester whose request is not masked; with no requester it
// grants a default master (number 2) that only drives IDLE. A SPLIT masks the master's request until the
// slave asserts its bit of HSPLIT.
// Slaves: addresses below 0x1000 are the fast slave (zero wait, OKAY). From 0x1000 the slow slave: a
// read it has not prepared gets the two-cycle SPLIT; it notes HMASTER, fetches for LATENCY cycles, then
// pulses HSPLIT for that master; the retried read then completes with OKAY. Read data is the address
// with its top half set to 0xd0 (fast) or 0x5d (slow).
// Switches: latency (default 6); use_retry (answer RETRY, and never mask); split_never_resumed (the
// broken twin: the slave never asserts HSPLIT); trace; quiet (no completion lines). attempts[m] counts tries.
module ahb2_bus (input logic hclk, input logic hresetn);
  int latency = 6;
  bit use_retry = 0, split_never_resumed = 0, trace = 0, quiet = 0;
  localparam logic [1:0] OKAY = 2'b00, ERROR = 2'b01, RETRY = 2'b10, SPLIT = 2'b11;
  int cycle = -1;
  // ---- the masters' scripts and progress ----
  int          n_rd [0:1], next [0:1], tries [0:1], attempts [0:1];   // attempts counts every try
  logic [31:0] rd_addr [0:1][0:7];
  logic [31:0] got [0:1][0:7];
  int          done_at [0:1][0:7];
  initial for (int m = 0; m < 2; m++) begin n_rd[m] = 0; next[m] = 0; tries[m] = 0; attempts[m] = 0; end
  // ---- the bus ----
  logic [1:0]  hbusreq, hgrant;
  logic [1:0]  hmaster = 2;              // 0, 1 or the default master 2
  logic [1:0]  htrans;
  logic [31:0] haddr, hrdata;
  logic        hready = 1;
  logic [1:0]  hresp = OKAY;
  logic [1:0]  hsplit = 0, mask = 0;
  // the data phase in progress
  logic        d_on = 0;
  logic [1:0]  d_m = 0;
  logic [31:0] d_a = 0;
  // the slow slave
  logic        s_second = 0;              // the second cycle of a SPLIT or RETRY
  logic [1:0]  s_pend_m = 0;              // the fetch in progress: for which master, which address
  logic [31:0] s_pend_a = 0;
  bit          s_busy = 0;
  logic        prep_v = 0;                // a fetched word waits for its master's retry
  logic [1:0]  prep_m = 0;
  logic [31:0] prep_a = 0;
  int          s_count = 0;
  // what each master asks for
  int next0 = 0, next1 = 0, nrd0 = 0, nrd1 = 0;   // copies of next[] and n_rd[] for the wires below
  assign hbusreq = {next1 < nrd1, next0 < nrd0};
  // the owner drives NONSEQ only when it has a read and none in flight
  logic [1:0] in_flight = 0;
  logic [31:0] want0 = 0, want1 = 0;      // each master's next read address
  always @* begin
    htrans = 2'b00; haddr = 0;
    if (hmaster < 2 && hbusreq[hmaster] && !in_flight[hmaster]) begin htrans = 2'b10; haddr = (hmaster == 1) ? want1 : want0; end
  end
  // the arbiter: the highest-priority unmasked requester, else the default master
  // A SPLIT in its second cycle masks the master at once, so the arbiter never regrants it there.
  wire [1:0] masked = mask | ((d_on && hready && hresp == SPLIT) ? (2'b01 << d_m) : 2'b00);
  always @* begin
    if (hbusreq[1] && !masked[1]) hgrant = 2'b10;
    else if (hbusreq[0] && !masked[0]) hgrant = 2'b01;
    else hgrant = 2'b00;
  end
  // responses
  wire slow     = d_on && d_a >= 32'h1000;
  wire prepared = prep_v && prep_m == d_m && prep_a == d_a;
  always @* begin
    hready = 1; hresp = OKAY; hrdata = 0;
    if (d_on && !slow) hrdata = {16'hd000, d_a[15:0]};
    else if (slow) begin
      if (s_second) begin hready = 1; hresp = use_retry ? RETRY : SPLIT; end
      else if (!prepared) begin hready = 0; hresp = use_retry ? RETRY : SPLIT; end
      else hrdata = {16'h5d00, d_a[15:0]};
    end
  end
  always @(posedge hclk) begin
    cycle = cycle + 1;
    want0 = rd_addr[0][next[0]]; want1 = rd_addr[1][next[1]];
    next0 = next[0]; next1 = next[1]; nrd0 = n_rd[0]; nrd1 = n_rd[1];
    if (!hresetn) begin
      hmaster <= 2; d_on <= 0; in_flight <= 0; mask <= 0; hsplit <= 0; s_second <= 0; prep_v <= 0;
    end else begin
      // the slow slave fetches, then tells the arbiter which master may come back
      hsplit <= 0;
      if (s_busy) begin
        if (s_count > 0) s_count = s_count - 1;
        else begin
          s_busy = 0; prep_v <= 1; prep_m <= s_pend_m; prep_a <= s_pend_a;
          if (!split_never_resumed && !use_retry) begin
            hsplit[s_pend_m] <= 1;
            if (trace) $display("e%0d: slow slave asserts HSPLIT for master %0d", cycle, s_pend_m);
          end
        end
      end
      if (hsplit[0]) mask[0] <= 0;
      if (hsplit[1]) mask[1] <= 0;
      // the data phase
      if (slow && !s_second) begin
        if (prepared) prep_v <= 0;                                   // the retried read completes now
        else begin
          s_second <= 1;                                             // the second cycle follows
          if (!s_busy && !prep_v) begin s_busy = 1; s_pend_m = d_m; s_pend_a = d_a; s_count = latency; end
        end
      end else if (s_second) s_second <= 0;
      if (d_on && hready) begin
        attempts[d_m] = attempts[d_m] + 1;
        if (hresp == OKAY) begin
          got[d_m][next[d_m]] = hrdata; done_at[d_m][next[d_m]] = cycle;
          if (quiet) ;
          else if (tries[d_m]) $display("e%0d: master %0d read 0x%0h = %h after %0d %0s", cycle, d_m, d_a, hrdata, tries[d_m], use_retry ? "RETRY" : "SPLIT");
          else $display("e%0d: master %0d read 0x%0h = %h", cycle, d_m, d_a, hrdata);
          next[d_m] = next[d_m] + 1; tries[d_m] = 0;
          want0 = rd_addr[0][next[0]]; want1 = rd_addr[1][next[1]];
          next0 = next[0]; next1 = next[1];
        end else begin
          tries[d_m] = tries[d_m] + 1;
          if (hresp == SPLIT) mask[d_m] <= 1;
          if (trace) $display("e%0d: master %0d got %0s", cycle, d_m, hresp == SPLIT ? "SPLIT" : "RETRY");
        end
        in_flight[d_m] <= 0;
      end
      // the address phase
      if (hready) begin
        d_on <= htrans[1]; d_m <= hmaster; d_a <= haddr;
        if (htrans[1]) in_flight[hmaster] <= 1;
        // A master owns the address bus after an edge where its HGRANT and HREADY are both high.
        if (hgrant == 2'b10 && hmaster != 1) begin hmaster <= 1; if (trace) $display("e%0d: bus to master 1", cycle); end
        else if (hgrant == 2'b01 && hmaster != 0) begin hmaster <= 0; if (trace) $display("e%0d: bus to master 0", cycle); end
        else if (hgrant == 2'b00 && hmaster != 2) begin hmaster <= 2; if (trace) $display("e%0d: bus to the default master", cycle); end
      end
    end
  end
endmodule
ConceptWhen does a master own the AMBA 2 address bus?
ConceptA low-priority master gets RETRY from a slow slave. A higher-priority master is idle. What happens on the bus?
ConceptWhy must ERROR, RETRY and SPLIT take two cycles?
ConceptWhich statement about AHB-Lite is right?

Common Mistakes

Wrong Treat RETRY as an error and give up the transfer.

RETRY means the transfer has not completed yet; the master must keep trying until OKAY or ERROR.

Fix Handle RETRY and SPLIT the same way: request the bus again and repeat the transfer.

Wrong Hold HSPLIT[m] high until master m owns the bus again.

The arbiter samples HSPLIT every cycle, so one cycle unmasks the master; a long pulse adds nothing.

Fix Pulse the master's HSPLIT bit for one cycle when the data is ready.

Wrong Record the master number from HMASTER in the data phase of the SPLIT.

HMASTER belongs to the address phase, and it can change before the data phase ends.

Fix Note HMASTER together with the address of the transfer you are going to SPLIT.

Remember

  • AMBA 2 masters request with HBUSREQx; the arbiter grants with HGRANTx and shows the owner on HMASTER.
  • A master owns the address bus after an edge with its HGRANTx and HREADY high.
  • ERROR, RETRY and SPLIT are two-cycle responses; RETRY keeps the priorities, SPLIT masks the master.
  • A SPLIT slave pulses HSPLIT[m] when ready; without it the master never comes back.
  • AHB-Lite has one manager, a one-bit HRESP and no arbitration signals.

Report a problem with this page