The Default Subordinate and the Two-Cycle Error

A read of an address nobody owns must still end, and the processor must learn that it failed. One small block gives that answer, and it takes two cycles to give it.

You Will Be Able To

  • Say what the default subordinate is, and what goes wrong without it.
  • Read the two answer wires of AHB, and find both cycles of an error in a capture.
  • Explain why an error takes two cycles, and why an idle bus cannot fail.
Lesson
S4.12
Time
25 min
Runs on
Your browser
Check
5 questions

A program follows a wrong address into a hole of the map. No block lives there, so no block will ever say "done". Unless something else answers, the processor waits on that one read for ever.

Before You Start

You need the address phase, the data phase and HREADY of S0.5. You need the decoder with its wire for "nobody" from Address Decode and Aliases, and the hole of The Memory Map.

Five questions this page answers
Question
1What answers a transfer to an address that no block owns?
2Which two wires carry the answer of an AHB transfer, and what does each combination mean?
3Which clock edges belong to an error, and on which one does the failed transfer end?
4Why does an error take two cycles when a good answer takes one?
5Why does an idle cycle at an unowned address get no error?

The Idea: Every Address Gets an Answer

On AHB, a transfer ends only when a subordinate says so. A hole has no subordinate. So the chip adds one whose only job is to answer for nobody. It is called the default subordinate, and the decoder selects it whenever no region matches.

Its answer has to say more than "done". It must also say "this failed", or the program would carry on with a value that never existed. AHB has a second answer wire for that, next to HREADY. It is called HRESP. Its value 0 is called OKAY, and its value 1 is called ERROR.

An error is given in two cycles, not one. The reason is the overlap you met in S0.5. While one transfer fails, the next one is already on the address wires. The first cycle of the error warns the manager. That gives it time to take the next request back.

One more point keeps the bus quiet. The address wires always show some address, even when the manager wants nothing. An idle cycle that happens to point at a hole is no mistake, so it gets a plain OKAY.

New Words

New words on this page
WordMeaning
Default subordinateThe block that answers every transfer to an address no region owns.
HRESPThe AHB answer wire for success or failure: 0 is OKAY, 1 is ERROR. It is read together with HREADY.
OKAYThe value 0 of HRESP: the transfer has succeeded, or is still waiting.
ERRORThe value 1 of HRESP: the transfer has failed.
CancelTo take back a request whose address phase has not ended, by changing HTRANS to IDLE.

HREADY and HRESP are read as a pair. Together they have four meanings.

The four answers of an AHB data phase
HREADYHRESPMeaning
10Done, and it succeeded.
00Not done yet: a wait state.
01It is failing. This is the first cycle of the error.
11Done, and it failed. This is the second cycle of the error.

One Picture: Who Answers for Nobody

Who Answers for NobodyStep through the picture. It follows one good read, one read of a hole, and an idle cycle.
  • Processor
  • Bus
  • Memory
Who Answers for NobodyStep through the picture. It follows one good read, one read of a hole, and an idle cycle. component Manager starts everytransfer; here, testcode component Decoder one select for eachowner, and one for"nobody" component SRAM owns 0x8000_0000to 0x8000_FFFF component Defaultsubordinate selected by "nobody";it holds no data component Returnmultiplexer passes the answer ofthe selected block addressselectnobodydata, done, OKAYdone, ERRORHRDATA, HREADY,HRESP
  1. component Managerstarts every transfer; here, test code
    • address → Decoder
  2. component Decoderone select for each owner, and one for "nobody"
    • select → SRAM
    • nobody → Default subordinate
  3. component SRAMowns 0x8000_0000 to 0x8000_FFFF
    • data, done, OKAY → Return multiplexer
  4. component Return multiplexerpasses the answer of the selected block
    • HRDATA, HREADY, HRESP → Manager
  5. component Default subordinateselected by "nobody"; it holds no data
    • done, ERROR → Return multiplexer
  1. A read with an owner

    The address lies in SRAM. The decoder selects SRAM, and its answer returns: a value, "done" and OKAY.

  2. A read of a hole

    No region owns the address, so the decoder raises "nobody". That wire selects the default subordinate.

  3. The first cycle of the error

    The default subordinate answers ERROR and "not done yet". The manager now knows the read is failing, one cycle before it ends.

  4. The second cycle of the error

    The default subordinate answers ERROR and "done". The failed read is over. The manager throws its data away.

  5. An idle cycle at the same address

    The address wires point at the hole, but no transfer is asked for. The default subordinate answers OKAY at once. Nothing failed, because nothing was tried.

Read the diagram as text
  • Manager: starts every transfer; here, test code
  • Decoder: one select for each owner, and one for "nobody"
  • SRAM: owns 0x8000_0000 to 0x8000_FFFF
  • Default subordinate: selected by "nobody"; it holds no data
  • Return multiplexer: passes the answer of the selected block
  • Manager → Decoder: address
  • Decoder → SRAM: select
  • Decoder → Default subordinate: nobody
  • SRAM → Return multiplexer: data, done, OKAY
  • Default subordinate → Return multiplexer: done, ERROR
  • Return multiplexer → Manager: HRDATA, HREADY, HRESP

Each arrow stands for a group of wires. The default subordinate is a few gates and one flip-flop.

The manager cannot tell which block answered. It sees one HREADY and one HRESP, exactly as it sees one HRDATA.

The Smallest Example, Worked by Hand: A Failed Read as Bars

Draw transfers as bars, as in S0.5. Transfer A reads a hole. Transfer B, a read of SRAM, comes right behind it. This manager cancels B when it sees the error, and asks again.

An error stretches one bar and breaks the next
Cycle 1Cycle 2Cycle 3Cycle 4Cycle 5
A: read a holeaddress phasedata phase: error, first cycledata phase: error, second cycle
B: read SRAMaddress phase (held)cancelled: IDLEaddress phase againdata phase
HREADY10111
HRESP01100

In cycle 2, HREADY is 0, so B is not taken. It is the same hold as a wait state. But HRESP is 1, and that tells the manager something a wait state does not: A is lost. In cycle 3 the manager shows IDLE, and B starts again in cycle 4.

Without the error, B would have ended in cycle 3. Here it ends in cycle 5. A failed read cost this manager two extra cycles.

The Rules

  1. Rule 1: Every transfer gets an answer.

    If no region owns the address, the decoder selects the default subordinate, and it answers.

  2. Rule 2: The answer is HREADY and HRESP together.

    HREADY says whether the data phase ends at this edge. HRESP says whether it succeeds.

  3. Rule 3: An error takes two cycles.

    First cycle: HRESP 1 and HREADY 0. Second cycle: HRESP 1 and HREADY 1. The transfer ends at the second.

  4. Rule 4: The first cycle is the manager's chance to cancel.

    It may change the waiting request to IDLE. It may also let it go ahead. Both are allowed.

  5. Rule 5: Only a transfer can fail.

    An idle cycle at an unowned address gets OKAY with no wait.

Sources for These Rules

Arm AMBA AHB Protocol Specification, document IHI 0033, issue C. The default subordinate, and its answers to real transfers and to idle ones: section 4.2.1. The two answer wires and their four combinations: section 5.1, Tables 5-1 and 5-2. The two cycles of ERROR and the reason for them: section 5.1.3. The answer to an IDLE transfer: section 3.2.

What the manager may do with the transfer behind an error: section 5.1.3. The same for a run of related transfers: section 3.6.2.

The default subordinate in the lab is our own. It is the smallest one that obeys these rules.

Now Run It

The lab at the end of this page has one AHB bus with SRAM and a default subordinate. The manager is test code, a bus-functional model, and it only reads. It reads SRAM, then the hole at 0x1000_7000, then SRAM again. Last, it shows the hole address once more with no transfer.

Printed by the lab at each rising clock edge. The left group is the address phase. The middle group is the answer. The right end names the transfer in its data phase.
e0 htrans=IDLE haddr=00000000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none
e1 htrans=NONSEQ haddr=80000000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none
e2 htrans=NONSEQ haddr=10007000 | hready=1 hresp=0 hrdata=000000a0 | data phase: read 80000000  <- transfer
e3 htrans=NONSEQ haddr=80000004 | hready=0 hresp=1 hrdata=xxxxxxxx | data phase: read 10007000  (ERROR, first cycle)
e4 htrans=IDLE haddr=80000004 | hready=1 hresp=1 hrdata=xxxxxxxx | data phase: read 10007000  <- ends with ERROR
e5 htrans=NONSEQ haddr=80000004 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none
e6 htrans=IDLE haddr=10007000 | hready=1 hresp=0 hrdata=000000a1 | data phase: read 80000004  <- transfer
e7 htrans=IDLE haddr=10007000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none
e8 htrans=IDLE haddr=10007000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none
reads done=2 failed=1 cancelled=1, last edge e8
One Failed Read, RecordedThe lab reads SRAM, then a hole, then SRAM again. Step through the clock edges.
01234567clkhtransIDLENONSEQIDLENONSEQIDLEhaddr0000000080000000100070008000000410007000hreadyhresp
Scroll horizontally ↔
  1. Cycle 1

    The address phase of a read of SRAM. Nothing is in its data phase yet.

  2. Cycle 2

    SRAM answers: HREADY 1, HRESP 0. HADDR already shows the hole, and this edge takes that address.

  3. Cycle 3

    The first cycle of the error: HRESP is 1 and HREADY is 0. HADDR shows the read that waits behind.

  4. Cycle 4

    The second cycle: HRESP 1 and HREADY 1. The failed read ends here. The manager has changed HTRANS to IDLE, so nothing new is taken.

  5. Cycle 5

    The manager asks again for the read it cancelled.

  6. Cycle 6

    That read happens. HADDR points at the hole again, but HTRANS is IDLE.

  7. Cycle 7

    The answer to the idle cycle: HREADY 1 and HRESP 0. No error, and no wait.

Recorded from the lab. Each column is what one rising clock edge sees.

Rule 3 at work: e3 sees HRESP 1 with HREADY 0, and e4 sees both at 1. The read of 10007000 ends at e4, as an error. Rule 4 at work: at e4 the manager shows IDLE, so the read of 80000004 is not taken there. It is taken at e5.

Rule 5 at work: at e6 the address wires point at the hole with HTRANS at IDLE. The next row, e7, sees HREADY 1 and HRESP 0.

Now look at e2, and take care. HADDR shows the hole, and HRESP is 0. That 0 is the answer to the SRAM read in its data phase. It says nothing about the hole. The answer to the hole comes in the next two rows.

This lab leaves things out. It has one real subordinate, so its return multiplexer is one line. The manager only reads. A real default subordinate fails a write to a hole in the same way.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
A default subordinateNo answer for a holeA wrong address ends in two cycles. Without it, the manager waits for ever and the chip stops.
Answer a hole with ERRORAnswer with OKAY and a value of zeroThe processor learns of the wrong address at once. The quiet zero would hide the fault until much later.
Two cycles for an errorOne cycleThe manager has a cycle to cancel the request behind. Every error costs one more cycle.
OKAY for an idle cycleERROR whenever the address is unownedThe address wires may rest anywhere. The default subordinate must look at HTRANS, not only at its select.

What does a processor do with an error? Most treat it much like an interrupt: they stop the program and jump to a handler. Later lessons on the processor cover that.

The Trap: Reading HRESP One Transfer Early

An engineer suspects that a program reads a wrong address. The capture shows that address on HADDR, and HRESP at 0 in the same column. The report says the read succeeded, so the address must be fine.

It is row e2 of the lab. The address in a column is in its address phase. HRESP in that column answers the transfer before it. To check an address, find the edge that takes it, then read HRESP at the edge where its data phase ends.

The opposite slip is as common. Someone sees HRESP rise and treats that edge as the end. At the first cycle of an error, HREADY is 0, and nothing has ended yet.

At Scale

This page1 bus, 1 default subordinate
ap_socAHB, and APB behind the bridge

This section looks ahead. The lab has one bus and one default subordinate. A real chip gives every bus its own way to answer for nobody.

  1. Whose answer is on the wires

    With many subordinates, the return multiplexer must pick the block whose transfer is in its data phase. The next lesson, One Manager, Many Subordinates, builds it.

  2. Holes behind the bridge

    The bridge owns every address that starts 0x1000, and some of those have no device. An access there must also come back as an AHB error. The lesson on bridges follows an APB error back across the bridge.

  3. Remember what failed

    A chip can store the address of the last failed transfer in a register, so software can report it. Problem S4.2.2 builds that.

  4. The manager's side

    The Protocols lesson The two-cycle error response shows every choice the manager has.

Try It

Run the lab. For every row, name the transfer in its address phase and the transfer in its data phase.

Set CANCEL to 0. Predict the edge where the read of 80000004 now happens.

Change the hole to 0x8001_0000, the first address after the end of SRAM. Predict the answer.

Break rule 3: make def_ready always 1. Find the transfer that the manager can no longer cancel.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: e0 htrans=IDLE haddr=00000000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none e1 htrans=NONSEQ haddr=80000000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none e2 htrans=NONSEQ haddr=10007000 | hready=1 hresp=0 hrdata=000000a0 | data phase: read 80000000 <- transfer e3 htrans=NONSEQ haddr=80000004 | hready=0 hresp=1 hrdata=xxxxxxxx | data phase: read 10007000 (ERROR, first cycle) e4 htrans=IDLE haddr=80000004 | hready=1 hresp=1 hrdata=xxxxxxxx | data phase: read 10007000 <- ends with ERROR e5 htrans=NONSEQ haddr=80000004 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none e6 htrans=IDLE haddr=10007000 | hready=1 hresp=0 hrdata=000000a1 | data phase: read 80000004 <- transfer e7 htrans=IDLE haddr=10007000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none e8 htrans=IDLE haddr=10007000 | hready=1 hresp=0 hrdata=xxxxxxxx | data phase: none reads done=2 failed=1 cancelled=1, last edge e8

Check Yourself

Predict the outputThe manager reads a hole, then SRAM, then another hole, then SRAM. It cancels and asks again, as before. The last line counts the reads. What is that line?
// One AHB bus with one memory and a default subordinate. The manager is test code and only reads.
module tb;
  logic hclk = 0;
  always #5 hclk = ~hclk;

  // ---- AHB wires driven by the manager ----
  localparam IDLE = 0, NONSEQ = 2;   // two values of htrans: no transfer, or one transfer
  logic [1:0]  htrans = IDLE;   // address phase: is a transfer asked for?
  logic [31:0] haddr  = 0;      // address phase: which address
  // ---- AHB wires driven back to the manager ----
  logic        hready;          // data phase: 1 = this edge ends the phase
  logic        hresp;           // data phase: 0 = OKAY, 1 = ERROR
  logic [31:0] hrdata;          // data phase: the value read

  // What the bus remembers from the address phase, as in S0.5.
  logic        d_busy = 0;      // a transfer is in its data phase
  logic [31:0] d_addr = 0;      // the address of that transfer
  always @(posedge hclk) if (hready) begin
    d_busy <= (htrans == NONSEQ);  d_addr <= haddr;
  end

  // ---- The decoder: this small bus has one real subordinate, the SRAM of ap_soc ----
  wire sel_sram = (d_addr[31:16] == 16'h8000);   // 0x8000_0000 to 0x8000_FFFF
  wire sel_none = !sel_sram;                     // every other address: the default subordinate is selected

  // ---- SRAM: its data phase always takes one cycle ----
  logic [31:0] sram [0:3];      // four words are enough here

  // ---- The default subordinate ----
  // A real transfer to an address nobody owns gets ERROR, and ERROR takes two cycles.
  wire  miss = d_busy && sel_none;   // a transfer that nobody owns is in its data phase
  logic second = 0;                  // 1 during the second cycle of the error
  always @(posedge hclk) second <= miss && !second;
  wire  def_ready = !miss || second;   // first cycle: 0 (wait). second cycle: 1 (done)
  wire  def_resp  = miss;              // ERROR in both cycles. With no transfer: OKAY, and no wait

  // ---- The way back: the same select chooses whose answer the manager sees ----
  assign hready = sel_none ? def_ready : 1;
  assign hresp  = sel_none ? def_resp  : 0;
  assign hrdata = (d_busy && sel_sram) ? sram[d_addr[3:2]] : 32'hxxxx_xxxx;   // x: unknown unless SRAM is read

  // ---- The manager: test code that plays the processor (a bus-functional model) ----
  localparam CANCEL = 1;       // 1: on an error, cancel the request that is waiting behind it
  int done = 0, failed = 0, cancelled = 0;
  task read(input logic [31:0] a);
    bit again;                  // "bit" is a variable that holds 0 or 1
    again = 1;
    while (again) begin
      again = 0;
      htrans = NONSEQ; haddr = a;                  // the address phase
      @(posedge hclk);
      while (!hready) begin                        // the transfer in front is still in its data phase
        if (hresp && CANCEL) begin                 // ... and it is failing: this is the first error cycle
          #1 htrans = IDLE;                        // cancel this request ("#1": just after the edge)
          again = 1;  cancelled++;                 // and ask again afterwards
        end
        @(posedge hclk);
      end
      #1 htrans = IDLE;                            // the address was taken, or the cancelled cycle is over
    end
  endtask
  task idle_at(input logic [31:0] a);              // show an address with no transfer, for one cycle
    htrans = IDLE; haddr = a;
    @(posedge hclk); #1;
  endtask

  // Print what each rising clock edge sees.
  int    edge_no = 0;
  string kind;                  // a text variable, for printing only
  always @(posedge hclk) begin
    kind = (htrans == NONSEQ) ? "NONSEQ" : "IDLE";
    // $write prints without ending the line. $display ends it.
    $write("e%0d htrans=%s haddr=%h | hready=%b hresp=%b hrdata=%h | data phase: ", edge_no, kind, haddr, hready, hresp, hrdata);
    if (!d_busy)                 $display("none");
    else if (!hready && hresp)   $display("read %h  (ERROR, first cycle)", d_addr);
    else if (hresp)              $display("read %h  <- ends with ERROR", d_addr);
    else                         $display("read %h  <- transfer", d_addr);
    if (d_busy && hready) begin if (hresp) failed++; else done++; end
    edge_no++;
  end

  initial begin
    sram[0] = 32'h0000_00A0; sram[1] = 32'h0000_00A1; sram[2] = 32'h0000_00A2; sram[3] = 32'h0000_00A3;
    @(posedge hclk); #1;
    read(32'h4000_0000);               // a hole
    read(32'h8000_0008);               // SRAM, word 2
    read(32'h1000_7000);               // a hole
    read(32'h8000_000C);               // SRAM, word 3
    repeat (2) @(posedge hclk);        // let the last data phase finish
    #1 $display("reads done=%0d failed=%0d cancelled=%0d, last edge e%0d", done, failed, cancelled, edge_no - 1);
    $finish;                           // $finish ends the simulation
  end
endmodule
ConceptWhat does the default subordinate do?
ConceptAt one edge, HREADY is 1 and HRESP is 1. What does that edge see?
ConceptWhy is an error given in two cycles?
ConceptHADDR points at a hole and HTRANS is IDLE. What does the default subordinate answer?

Common Mistakes

Wrong Read HRESP in the column where the address appears.

That column is the address phase. HRESP there answers the transfer before.

Fix Read HRESP where the data phase of that address ends.

Wrong Treat the first edge with HRESP at 1 as the end of the transfer.

HREADY is 0 there. It is the first cycle of the error.

Fix The transfer ends at the edge with HREADY and HRESP both at 1.

Wrong Answer ERROR whenever the address is unowned.

The address wires rest on some address even when no transfer is asked for.

Fix Fail only a real transfer. Answer an idle cycle with OKAY and no wait.

Remember

  • The default subordinate answers every transfer to an address that no region owns.
  • An AHB answer is HREADY and HRESP read together: four combinations, four meanings.
  • An error takes two cycles: HRESP 1 with HREADY 0, then HRESP 1 with HREADY 1.
  • The first error cycle lets the manager cancel the request waiting behind.
  • An idle cycle at an unowned address gets OKAY with no wait.

Practice

Report a problem with this page