Every access the core makes outside the TCM leaves the CPU subsystem through one door: the AXI4-Lite manager port. Its job sounds simple, turning "read this address" or "write this word" into a bus transaction and reporting when it is done, but it is where the bus's rules first meet your logic: valid and ready on five channels, an address and its data that may be accepted in different cycles, and responses that can say something went wrong. This article explains those rules from the manager's side, shows a write and a read cycle by cycle, and describes the request interface the CPU subsystem uses. You build the port in two exercises: S03 for reads, S04 for writes.

11 min read | Intermediate

What You'll Learn

  • Apply the AXI4-Lite valid/ready rules on all five channels from the manager's side
  • Turn one held request into one read or write transaction and signal its end
  • Track the write address and write data handshakes independently
  • Read a transaction cycle by cycle and explain why an SRAM access takes four cycles

Before You Start

This section needs Verilog: see the Verilog Tutorial. Buses and Transactions introduces AXI4-Lite, its five channels, the valid/ready handshake and the response codes; this article assumes it. Your Core Learns to Wait explains how the core waits for an access to finish. No earlier exercise is needed.

The Five Channels, From the Manager's Side

An AXI4-Lite bus has five independent channels. Three belong to writes and two to reads:

ChannelCarriesSent bySignals of the manager port
AW, write addressthe address of a writemanagerm_awaddr, m_awvalid, m_awready
W, write datathe data and its byte enablesmanagerm_wdata, m_wstrb, m_wvalid, m_wready
B, write responseOKAY or an errorsubordinatem_bresp, m_bvalid, m_bready
AR, read addressthe address of a readmanagerm_araddr, m_arvalid, m_arready
R, read datathe data and a responsesubordinatem_rdata, m_rresp, m_rvalid, m_rready

On each channel the sender raises VALID when it has something to send, and the receiver raises READY when it can take it. The transfer, a handshake, happens at a rising clock edge where both are 1. Three rules follow, and every one of them is checked by the tests:

  • VALID stays up. Once a sender has raised VALID, it keeps it at 1 until the handshake. It may not take it back because READY took a while.
  • The payload stays still. While VALID is 1 and the handshake has not happened, the address or data on that channel does not change.
  • One handshake per transfer. After the handshake, VALID goes down (unless a new transfer follows). A manager that keeps AWVALID up one cycle too long has sent a second write address.

For the response channels the manager is the receiver: it raises BREADY or RREADY when it can take the response. A manager that is waiting for nothing else can simply hold its READY at 1 while it waits.

The Request Side

On the other side of the port is the CPU subsystem. It does not speak AXI; it hands over one request and waits for it to finish. These are the ports, as the exercise gives them:

module cvsoc_axil_master (
    input  logic        clk,
    input  logic        rst_n,

    // request from the CPU subsystem: held unchanged until done is 1
    input  logic [31:0] req_addr,
    input  logic [31:0] req_wdata,
    input  logic [3:0]  req_wstrb,
    input  logic        req_we,     // a write is requested
    input  logic        req_re,     // a read is requested
    output logic        done,       // 1 for one cycle when the transaction has finished
    output logic [31:0] rdata,      // read data, valid while done is 1
    output logic        err,        // the response was not OKAY, valid while done is 1

    // AXI4-Lite manager port
    output logic [31:0] m_awaddr,
    output logic        m_awvalid,
    input  logic        m_awready,
    output logic [31:0] m_wdata,
    output logic [3:0]  m_wstrb,
    output logic        m_wvalid,
    input  logic        m_wready,
    input  logic [1:0]  m_bresp,
    input  logic        m_bvalid,
    output logic        m_bready,
    output logic [31:0] m_araddr,
    output logic        m_arvalid,
    input  logic        m_arready,
    input  logic [31:0] m_rdata,
    input  logic [1:0]  m_rresp,
    input  logic        m_rvalid,
    output logic        m_rready
);

The contract with the CPU subsystem is short:

  • A request is req_we = 1 or req_re = 1, with its address and, for a write, its data and byte enables. It stays exactly as it is until done is 1. That is natural: the request comes from the core's W stage, which holds while it waits.
  • done is 1 for exactly one cycle, when the response has been accepted. In that cycle rdata holds the read data and err says whether the response was an error. The core takes them in that same cycle and moves on.
  • One transaction at a time. The next request can start in the cycle after done.

Because the request is held, the address and data outputs can simply be the request's: m_awaddr and m_araddr are req_addr, m_wdata and m_wstrb are the request's data and byte enables. The port's own logic is all in the VALID and READY signals and in knowing where it is in the transaction.

A Write and a Read, Cycle by Cycle

This is a write followed by a read, from the manager port to the SRAM, as the reference design does them. The SRAM accepts address and data together and answers in the next cycle; An AXI4-Lite SRAM explains its side.

Waveform of a write and a read: the write request in cycles 1 to 4 with AWVALID, WVALID, AWREADY and WREADY in cycle 2, BVALID and BREADY in cycle 3 and done in cycle 4; the read request in cycles 5 to 8 with ARVALID and ARREADY in cycle 6, RVALID and RREADY in cycle 7 and done in cycle 8.
  • Cycle 1: the request appears. The port is idle and sees it at the end of the cycle.
  • Cycle 2: the port offers AWVALID and WVALID. The SRAM has both and raises AWREADY and WREADY: both handshakes happen at the end of this cycle. BREADY is up, ready for the response.
  • Cycle 3: AWVALID and WVALID are down again. The SRAM answers with BVALID and OKAY; with BREADY up, the response is accepted at the end of the cycle.
  • Cycle 4: done is 1. The core's store completes.

The read takes the same shape on two channels: ARVALID and ARREADY in its second cycle, RVALID and RREADY in its third, done in its fourth with the data in rdata. That is where the 4 cycles per SRAM access in the system report come from: one to see the request, one for the address, one for the response, one to hand it to the core. Each could be shaved with more logic; Outstanding Transactions and Bursts describes how fast interfaces hide this latency instead.

One Way to Organize It

A state machine with four states covers the whole port:

State machine of the manager port: IDLE goes to WRITE on a write request and to READ on a read request; WRITE and READ go to DONE when the response is valid; DONE returns to IDLE in the next cycle.

In READ, offer ARVALID until the address handshake has happened, then stop offering it; keep RREADY at 1 until RVALID comes, take m_rdata and the response, and go to DONE. Because ARVALID must drop after its handshake but the state does not change yet, the port needs to remember that the handshake happened: a one-bit flag, cleared when a new transaction starts.

In WRITE there are two such handshakes, and they are independent. The SRAM in the diagram happens to accept the address and the data in the same cycle, but AXI allows a subordinate to accept them in different cycles, or in either order, and the interconnect in front of a slow subordinate may do exactly that. So keep one flag for AW and one for W, drop each VALID after its own handshake, and wait for BVALID with BREADY at 1. A port that drops WVALID when the address is accepted, or offers the address again after its handshake, breaks the rules on the first subordinate that does not take both together.

DONE lasts one cycle: done is 1, then the port is idle again.

Quick Check

Q: A subordinate raises AWREADY in cycle 2 but WREADY only in cycle 4. What must AWVALID and WVALID do in cycles 2 to 4?

Show Answer

AWVALID is 1 in cycle 2, when its handshake happens, and 0 from cycle 3 on. WVALID stays 1, with the same data and byte enables, through cycles 2, 3 and 4, and goes to 0 after its handshake at the end of cycle 4. Only then can the write response come.

Errors

A response is OKAY (00) or an error: SLVERR (10) from a subordinate that could not do the access, or DECERR (11) from the interconnect when no subordinate owns the address. The port does not try to recover. It reports the error with err = 1 in the done cycle and returns whatever read data came with it; in cvsoc that is 0. The core in this section has no exceptions, so the program never learns about the error: it reads 0 and goes on. In a core with exceptions, err would raise a bus-error exception; Traps and Precise Exceptions explains what happens next.

Two Exercises

S03, reads. Every request is a read. Write the IDLE, READ and DONE behavior and keep the write outputs (m_awvalid, m_wvalid, m_bready) at 0. The test runs 300 reads against a subordinate that raises ARREADY at random and answers after 0 to 3 cycles with OKAY, SLVERR or DECERR, and checks the rules and the done, rdata and err of every read.

S04, writes. Start from your S03 solution and add WRITE. The test mixes reads and writes against a subordinate that sets AWREADY and WREADY independently and at random, and runs the S03 test again. A monitor checks the rules at every clock edge: VALID held until READY with a stable payload, one handshake per channel, nothing offered without a request, done exactly once per request and only after the response was accepted.

Where Is This Used?

Every CPU that sits on an AXI bus has an adapter like this one, between its own simple load/store interface and the five channels; the same is true for DMA engines and accelerators. Industrial versions add outstanding transactions, several reads in flight at once, but the rule that causes the most bugs is the same here and there: AW and W are independent, and VALID may never wait for READY. Protocol checkers that run in every simulation, like the monitor in the S04 test, exist mainly to catch that.

Common Mistakes

Mistake #1: Making VALID wait for READY

Raising ARVALID only when ARREADY is already 1 can deadlock: a subordinate is allowed to wait for VALID before it raises READY. The rule is one-way: READY may depend on VALID, never the other way round.

Mistake #2: One flag for both write handshakes

Treating the write as done with the address once AWREADY comes, and withdrawing WVALID, loses the data whenever the subordinate takes the address first. Track AW and W separately.

Mistake #3: done for more than one cycle

The core moves on in the cycle done is 1. If it stays 1 a second cycle, the next load or store in W is told it finished before it started, and the program reads stale data.

Your Turn in the Lab

Exercise S03: write cvsoc_axil_master for reads. Then S04: extend the same module with writes. Both use the ports above; save the S04 version in your lab project for S08.

Open exercise S03 in ChipVerify Lab Open exercise S04 in ChipVerify Lab

Summary

  • The manager port turns one held request from the CPU subsystem into one AXI4-Lite transaction and raises done for one cycle when the response has been accepted, with rdata and err.
  • On every channel VALID stays up with a stable payload until the handshake, then drops; READY may wait for VALID, VALID never waits for READY.
  • A write's address and data handshakes are independent and may happen in either order, so each needs its own flag.
  • With the SRAM, a write or read takes 4 cycles: see the request, address handshake, response handshake, done.
  • Error responses are reported with err; the core in this section reads 0 and goes on.
Did you find what you were looking for?

Quiz

No quiz questions available for this article.