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.
| Question | |
|---|---|
| 1 | What answers a transfer to an address that no block owns? |
| 2 | Which two wires carry the answer of an AHB transfer, and what does each combination mean? |
| 3 | Which clock edges belong to an error, and on which one does the failed transfer end? |
| 4 | Why does an error take two cycles when a good answer takes one? |
| 5 | Why 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
| Word | Meaning |
|---|---|
| Default subordinate | The block that answers every transfer to an address no region owns. |
| HRESP | The AHB answer wire for success or failure: 0 is OKAY, 1 is ERROR. It is read together with HREADY. |
| OKAY | The value 0 of HRESP: the transfer has succeeded, or is still waiting. |
| ERROR | The value 1 of HRESP: the transfer has failed. |
| Cancel | To 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.
| HREADY | HRESP | Meaning |
|---|---|---|
| 1 | 0 | Done, and it succeeded. |
| 0 | 0 | Not done yet: a wait state. |
| 0 | 1 | It is failing. This is the first cycle of the error. |
| 1 | 1 | Done, and it failed. This is the second cycle of the error. |
One Picture: Who Answers for Nobody
- Processor
- Bus
- Memory
- A read with an owner
The address lies in SRAM. The decoder selects SRAM, and its answer returns: a value, "done" and OKAY.
- A read of a hole
No region owns the address, so the decoder raises "nobody". That wire selects the default subordinate.
- 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.
- The second cycle of the error
The default subordinate answers ERROR and "done". The failed read is over. The manager throws its data away.
- 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.
| Cycle 1 | Cycle 2 | Cycle 3 | Cycle 4 | Cycle 5 | |
|---|---|---|---|---|---|
| A: read a hole | address phase | data phase: error, first cycle | data phase: error, second cycle | ||
| B: read SRAM | address phase (held) | cancelled: IDLE | address phase again | data phase | |
| HREADY | 1 | 0 | 1 | 1 | 1 |
| HRESP | 0 | 1 | 1 | 0 | 0 |
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
Rule 1: Every transfer gets an answer.
If no region owns the address, the decoder selects the default subordinate, and it answers.
Rule 2: The answer is HREADY and HRESP together.
HREADY says whether the data phase ends at this edge. HRESP says whether it succeeds.
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.
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.
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.
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- Cycle 1
The address phase of a read of SRAM. Nothing is in its data phase yet.
- Cycle 2
SRAM answers: HREADY 1, HRESP 0. HADDR already shows the hole, and this edge takes that address.
- Cycle 3
The first cycle of the error: HRESP is 1 and HREADY is 0. HADDR shows the read that waits behind.
- 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.
- Cycle 5
The manager asks again for the read it cancelled.
- Cycle 6
That read happens. HADDR points at the hole again, but HTRANS is IDLE.
- 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 choice | The alternative | What the choice buys, and costs |
|---|---|---|
| A default subordinate | No answer for a hole | A wrong address ends in two cycles. Without it, the manager waits for ever and the chip stops. |
| Answer a hole with ERROR | Answer with OKAY and a value of zero | The processor learns of the wrong address at once. The quiet zero would hide the fault until much later. |
| Two cycles for an error | One cycle | The manager has a cycle to cancel the request behind. Every error costs one more cycle. |
| OKAY for an idle cycle | ERROR whenever the address is unowned | The 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 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.
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.
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.
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.
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.
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 e8Check Yourself
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.