Module 10: Capstone Projects · Project 5 — AXI4-Lite Slave Interface

Project 5, Part 2: A Register File Behind Five Handshakes

The previous article defined the five AXI4-Lite communication channels. This article designs the internal register storage and channel synchronization logic. The slave peripheral buffers write address and data packets independently, committing the transaction once both arrive.

The Memory-Mapped Register File

The peripheral implements four 32-bit registers mapped to consecutive word boundaries:

module axi_registers #(parameter NUM_REGS = 4) (
    input  logic                        clk, rst_n,
    input  logic [$clog2(NUM_REGS)-1:0] waddr, raddr,
    input  logic [31:0]                 wdata,
    input  logic                        wr_commit,   // Strobe to latch write data
    output logic [31:0]                 rdata
);
    logic [31:0] regs [0:NUM_REGS-1];

    always_ff @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            for (int i = 0; i < NUM_REGS; i++) regs[i] <= 32'b0;
        end else if (wr_commit) begin
            regs[waddr] <= wdata;
        end
    end

    assign rdata = regs[raddr];   // Combinational read path
endmodule

The register array provides asynchronous reads and synchronous write access. The control unit asserts wr_commit for one cycle when both address and data transfers complete.

Independent Write Address and Data Capture

Because the AW and W channels operate independently, the slave uses synchronization flags:

logic        awaddr_valid_flag, wdata_valid_flag;
logic [1:0]  waddr_captured;
logic [31:0] wdata_captured;

assign wr_commit = awaddr_valid_flag && wdata_valid_flag;

always_ff @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        awaddr_valid_flag <= 1'b0;
        wdata_valid_flag  <= 1'b0;
    end else begin
        // Capture write address upon AW handshake completion
        if (awvalid && awready) begin
            waddr_captured    <= awaddr[3:2];   // Word address index
            awaddr_valid_flag <= 1'b1;
        end
        // Capture write data upon W handshake completion
        if (wvalid && wready) begin
            wdata_captured   <= wdata;
            wdata_valid_flag <= 1'b1;
        end
        // Clear flags upon write commit
        if (wr_commit) begin
            awaddr_valid_flag <= 1'b0;
            wdata_valid_flag  <= 1'b0;
        end
    end
end

assign waddr        = waddr_captured;
assign wdata_reg_in = wdata_captured;

If write data arrives before the address, the slave asserts wdata_valid_flag and holds it high. When the write address handshake completes on a later cycle, wr_commit asserts for one clock cycle. This dual-flag architecture enforces the AXI ordering dependency.

Read Channel State Machine

The read interface sequences across two states: AXI_R_IDLE and AXI_R_DATA:

typedef enum logic [1:0] {AXI_R_IDLE, AXI_R_DATA} axi_r_state_t;
axi_r_state_t r_state, r_next_state;

always_ff @(posedge clk or negedge rst_n) begin
    if (!rst_n) r_state <= AXI_R_IDLE;
    else        r_state <= r_next_state;
end

always_comb begin
    r_next_state = r_state;
    arready      = 1'b0;
    rvalid       = 1'b0;

    unique case (r_state)
        AXI_R_IDLE: begin
            arready = 1'b1;
            if (arvalid) r_next_state = AXI_R_DATA;
        end
        AXI_R_DATA: begin
            rvalid = 1'b1;
            if (rready) r_next_state = AXI_R_IDLE;
        end
        default: r_next_state = AXI_R_IDLE;
    endcase
end

always_ff @(posedge clk) begin
    if (r_state == AXI_R_IDLE && arvalid && arready)
        raddr <= araddr[3:2];   // Latch word address
end

Read FSM: idle accepts the address handshake, data state presents the response
Figure 1: The read-side FSM

In state AXI_R_IDLE, the slave asserts arready. When arvalid arrives, the FSM transitions to AXI_R_DATA, asserting rvalid until the master acknowledges with rready.

Practice Exercise

Write data arrives on cycle 2 (wvalid && wready = 1). Write address arrives on cycle 5 (awvalid && awready = 1). Determine the clock cycle where wr_commit pulses high.

Solution
  • On cycle 2, wdata_valid_flag asserts high.
  • Because awaddr_valid_flag remains low, wr_commit evaluates to 0.
  • On cycle 5, the address handshake completes, asserting awaddr_valid_flag on cycle 6.
  • On cycle 6, both awaddr_valid_flag and wdata_valid_flag evaluate to logic 1.
  • Signal wr_commit pulses high during cycle 6 to write data into the target register.
  • Both synchronization flags clear to 0 on cycle 7.

The AXI4-Lite slave coordinates independent write channels using dual synchronization flags. Writes commit only after both address and data handshakes complete. The next article completes the top-level slave implementation and verifies protocol compliance with SVA assertions.

← Project 5, Part 1: AXI4-Lite, Five Independent Handshakes Project 5, Part 3: The Complete Slave, and the End of the Course →