Between the manager port and the blocks it reaches sits the interconnect. For every transaction it answers one question, which block owns this address, and then connects the manager to that block until the transaction is over. When no block owns the address, it must answer by itself, or the manager waits forever. This article explains address decoding with windows given as parameters, how an interconnect routes the five channels and remembers where a transaction went, and the decode error it sends for addresses nobody owns. You build it in two exercises: S06 for reads, S07 for writes.
9 min read | Intermediate
What You'll Learn
- Decode an address against subordinate windows given as BASE and SIZE parameters
- Route a transaction's channels to one subordinate and its responses back to the manager
- Remember a transaction's target until its response has been accepted
- Answer DECERR for an unowned address without involving any subordinate
Before You Start
This section needs Verilog: see the Verilog Tutorial. Memory Maps and Address Decoding explains windows, decoding and holes in a memory map, and Buses, Crossbars and Networks-on-Chip puts this one-manager interconnect among its bigger relatives. An AXI4-Lite Manager Port and An AXI4-Lite SRAM describe the two sides it connects. No earlier exercise is needed.
What an Interconnect Does
An interconnect joins managers to subordinates. The one in cvsoc is the simplest kind: one manager, the CPU subsystem, and N subordinates, two in cvsoc: the SRAM and the APB bridge. Its manager side looks like a subordinate to the CPU subsystem (ports s_), and its subordinate side looks like a manager to each block (ports m_, one set per subordinate, packed side by side in wide vectors):
module cvsoc_axil_xbar #(
parameter int N = 2,
parameter logic [63:0] BASE = {32'h4000_0000, 32'h2000_0000}, // subordinate 1, subordinate 0
parameter logic [63:0] SIZE = {32'h0001_0000, 32'h0000_4000}
) (
input logic clk,
input logic rst_n,
// from the manager: s_awaddr, s_awvalid, s_awready, s_wdata, s_wstrb, s_wvalid, s_wready,
// s_bresp, s_bvalid, s_bready, s_araddr, s_arvalid, s_arready, s_rdata, s_rresp, s_rvalid, s_rready
// to the subordinates, packed: subordinate i uses [32*i +: 32], [4*i +: 4], [2*i +: 2] and [i]
output logic [32*N-1:0] m_awaddr,
output logic [N-1:0] m_awvalid,
input logic [N-1:0] m_awready,
// ... the same for every channel: m_wdata, m_wstrb, m_wvalid, m_wready, m_bresp, m_bvalid,
// m_bready, m_araddr, m_arvalid, m_arready, m_rdata, m_rresp, m_rvalid, m_rready
);
The exercise's starter has the full port list. The packing rule is the one thing to get used to: subordinate 0's write address is m_awaddr[31:0], subordinate 1's is m_awaddr[63:32], and in general subordinate i's is m_awaddr[32*i +: 32]. The same holds for the parameters: BASE[32*i +: 32] is the start of subordinate i's window.
Decoding With Windows
Each subordinate owns one window: the addresses from its BASE to BASE + SIZE - 1. An address a belongs to subordinate i when
a >= BASE[i] and a - BASE[i] < SIZE[i]
Written that way, the test works for any base and any size, and it does not overflow at the top of the address space the way a < BASE + SIZE could. In cvsoc that gives:
| Address | Owner | Why |
|---|---|---|
| 0x2000_0000 | subordinate 0, SRAM | first byte of its window |
| 0x2000_3FFC | subordinate 0, SRAM | last word: 0x3FFC < 0x4000 |
| 0x2000_4000 | none | first byte past the SRAM: 0x4000 is not < 0x4000 |
| 0x4000_2000 | subordinate 1, APB bridge | inside the 64 KB peripheral window |
| 0x3000_0000 | none | a hole in the memory map |
Use the parameters in the logic and do not write the cvsoc addresses into it. The same interconnect then works for any memory map, which is what makes it a reusable block rather than part of one design. A small function that returns a one-hot select, one bit per subordinate, keeps the decode in one place for both the read and the write address.
Routing and Remembering
Once the owner is known, the interconnect connects the manager to it:
- The address, data and byte enables can go to every subordinate; only the owner sees VALID. The others see VALID = 0 and ignore the rest.
- The owner's READY goes back to the manager, so the handshake happens between the manager and the owner, in the same cycle, with no extra delay.
- The owner's response (BVALID and BRESP, or RVALID, RDATA and RRESP) goes back to the manager, and the manager's BREADY or RREADY goes to the owner. Error codes pass through unchanged.
There is a catch. The address is only on the manager's address channel until its handshake; after that the manager drops it, but the response is still to come, and the interconnect must still know whose response to forward. So it remembers the target: when a transaction starts, it stores the select in a register and uses that register until the response has been accepted. In the first cycle, before anything is stored, it uses the live decode, so that a subordinate can accept in that very cycle. Writes and reads each have their own register, because the two directions are independent.
Quick Check
Q: An interconnect routes the read response with the live decode of s_araddr instead of a stored target. The manager drops ARVALID after the handshake and its address changes to the next request's. What can go wrong?
Show Answer
The read data comes one or more cycles after the address handshake. By then s_araddr may no longer be the read's address, so the decode may pick another subordinate, or none, and the response of the real target never reaches the manager: the read hangs or returns another block's data. The target has to be stored when the transaction starts.
Nobody Owns the Address: DECERR
A program can use any address, including ones no block owns: a bad pointer, a buffer that runs past the end of the SRAM, a register in a block that was left out of this chip. Without an owner nobody would raise READY or send a response, and the manager would wait forever, with the core frozen behind it. An interconnect therefore answers such transactions itself, with a decode error, DECERR (11):
- Read: accept the address (ARREADY = ARVALID), and in the next cycle answer RVALID with RRESP = 11 and RDATA = 0, held until RREADY.
- Write: accept the address and the data, and answer BVALID with BRESP = 11 once the data has arrived. The order matters: a manager may send the data after the address, and a response before the data would end the transaction while the manager still holds WVALID.
- No subordinate sees anything of it.
The program badaddr reads three addresses no block should answer: 0x2000_4000 just past the SRAM, 0x3000_0000 in a hole, and 0x4000_3000, an empty slot behind the APB bridge. The first two get DECERR from the interconnect, 4 cycles each; the third reaches the bridge, which answers SLVERR for its empty slot after one more cycle (chapter 13 explains why). All three return 0, and the program checks exactly that.
Where Does This Matter?
The AXI specification defines DECERR for exactly this case, and interconnects usually produce it from a small built-in "default subordinate" like the one described here. Leaving it out is a well-known way to hang a chip: one stray pointer and the bus never answers. Interconnect generators include one by default, and SoC verification plans include "access every hole in the memory map" for this reason; SoC-Level Verification Strategy lists such tests.
Two Exercises
S06, reads. Decode, read routing with the stored target, and the DECERR read. Keep the write outputs to the subordinates (m_awvalid, m_wvalid, m_bready) and to the manager (s_awready, s_wready, s_bvalid) at 0. The test uses the cvsoc windows and two subordinate models that answer after random delays with OKAY or SLVERR; every read checks which subordinate received it (exactly once), the response code and the data. It reads the edges of both windows and addresses in holes, then 300 random addresses.
S07, writes. Start from S06 and add the write path: routing of AW, W and B with its own stored target, and the DECERR write that waits for the data. The test writes and reads the same addresses, checks that the owner received the address, data and byte enables exactly once, and runs the S06 test again.
Common Mistakes
Mistake #1: Including the end of the window
Comparing with <= instead of < gives each window one extra byte, the first address of whatever comes next. The test reads 0x2000_4000, the first byte past the SRAM, and expects DECERR.
Mistake #2: Never answering an unowned write
It is easy to remember the DECERR read and forget the write, or to answer the write before its data has arrived. Either way the manager hangs or ends a transaction it has not finished sending; the test gives up after 60 cycles and reports which address got no response.
Mistake #3: Answering SLVERR for an unowned address
SLVERR means a subordinate received the transaction and could not do it; DECERR means no subordinate received it. Software and debuggers use the difference to tell a bad address from a failing device, so the codes are not interchangeable.
Your Turn in the Lab
Exercise S06: write cvsoc_axil_xbar for reads. Then S07: add writes to the same module. Save the S07 version in your lab project for S08.
Summary
- The interconnect decodes each address against windows given as BASE and SIZE parameters: a is in window i when a >= BASE and a - BASE < SIZE.
- It routes VALID to the owner only and the owner's READY and responses back, in the same cycle, error codes unchanged.
- It stores the target when a transaction starts and uses it until the response is accepted, separately for reads and writes.
- An address no window holds gets DECERR from the interconnect itself: a read gets RDATA = 0, a write is answered only after its data has arrived.
badaddrreads past the SRAM and into a hole (DECERR, 4 cycles each) and an empty APB slot (SLVERR), and gets 0 each time.