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

Project 5, Part 3: The Complete Slave, and the End of the Course

The previous articles defined the five-channel AXI4-Lite protocol and designed the internal register logic. This article integrates the complete slave peripheral and verifies protocol compliance. We validate the interface using directed tests, randomized channel delays, and concurrent SystemVerilog assertions.

Top-Level AXI4-Lite Slave Module

The top-level module implements all five AXI4-Lite channels:

module axi4_lite_slave #(parameter NUM_REGS = 4) (
    input  logic        clk, rst_n,
    // Write address channel
    input  logic [31:0] awaddr, input logic awvalid, output logic awready,
    // Write data channel
    input  logic [31:0] wdata, input logic wvalid, output logic wready,
    // Write response channel
    output logic [1:0]  bresp, output logic bvalid, input logic bready,
    // Read address channel
    input  logic [31:0] araddr, input logic arvalid, output logic arready,
    // Read data channel
    output logic [31:0] rdata, output logic [1:0] rresp, output logic rvalid, input logic rready
);
    logic wr_commit;
    logic awaddr_valid_flag, wdata_valid_flag;
    logic [$clog2(NUM_REGS)-1:0] waddr_internal, raddr_internal;
    logic [31:0] wdata_internal, rdata_internal;

    // Accept address or data only when buffers are empty and no response is pending
    assign awready = !awaddr_valid_flag && !bvalid;
    assign wready  = !wdata_valid_flag  && !bvalid;

    // Internal register file instance
    axi_registers #(.NUM_REGS(NUM_REGS)) regs (
        .clk(clk), .rst_n(rst_n), .waddr(waddr_internal), .raddr(raddr_internal),
        .wdata(wdata_internal), .wr_commit(wr_commit), .rdata(rdata_internal)
    );

    // Write response generation
    always_ff @(posedge clk or negedge rst_n) begin
        if (!rst_n) bvalid <= 1'b0;
        else if (wr_commit) begin
            bvalid <= 1'b1;
            bresp  <= 2'b00;   // OKAY response status
        end else if (bvalid && bready) begin
            bvalid <= 1'b0;
        end
    end

    assign rdata = rdata_internal;
    assign rresp = 2'b00;   // OKAY response status
endmodule

The slave asserts awready and wready only when internal holding registers can accept transfers. When wr_commit pulses, the peripheral asserts bvalid on the subsequent clock cycle with status code 2'b00 (OKAY).

Directed Verification Testbench

The testbench drives write transactions and reads back register contents:

task automatic axi_write(bit [31:0] addr, bit [31:0] data);
    awaddr = addr; awvalid = 1'b1;
    wdata_drv = data; wvalid = 1'b1;
    fork
        begin @(posedge clk iff awready); awvalid = 1'b0; end
        begin @(posedge clk iff wready);  wvalid  = 1'b0; end
    join
    bready = 1'b1;
    @(posedge clk iff bvalid); bready = 1'b0;
endtask

task automatic axi_read(bit [31:0] addr, output bit [31:0] data);
    araddr = addr; arvalid = 1'b1;
    @(posedge clk iff arready); arvalid = 1'b0;
    rready = 1'b1;
    @(posedge clk iff rvalid); data = rdata; rready = 1'b0;
endtask

initial begin
    bit [31:0] readback;
    rst_n = 0; awvalid = 0; wvalid = 0; arvalid = 0; bready = 0; rready = 0;
    repeat (3) @(posedge clk); rst_n = 1;

    axi_write(32'd0, 32'hDEAD_BEEF);
    axi_read(32'd0, readback);

    if (readback == 32'hDEAD_BEEF) $display("PASS: Basic write and read verified");
    else $display("FAIL: Expected 32'hDEAD_BEEF, got %h", readback);
end

The construct @(posedge clk iff awready) synchronizes transfers directly to the clock edge where READY asserts.

Randomized Channel Arrival Timing

Verify decoupled operation by inserting randomized delays on the AW and W channels:

class axi_timing_txn;
    rand int aw_delay;   // Clock cycles before asserting AWVALID
    rand int w_delay;    // Clock cycles before asserting WVALID
    constraint reasonable_delay {
        aw_delay inside {[0:5]};
        w_delay  inside {[0:5]};
    }
endclass

task automatic axi_write_with_delay(bit [31:0] addr, bit [31:0] data, int aw_delay, int w_delay);
    fork
        begin
            repeat (aw_delay) @(posedge clk);
            awaddr = addr; awvalid = 1'b1;
            @(posedge clk iff awready); awvalid = 1'b0;
        end
        begin
            repeat (w_delay) @(posedge clk);
            wdata_drv = data; wvalid = 1'b1;
            @(posedge clk iff wready); wvalid = 1'b0;
        end
    join
    bready = 1'b1;
    @(posedge clk iff bvalid); bready = 1'b0;
endtask

The fork...join construct simulates concurrent, asynchronous arrivals. This validates that the slave handles all timing permutations: AW before W, W before AW, and simultaneous arrivals.

Concurrent Assertion for Write Ordering

Use SystemVerilog Assertions (SVA) to enforce protocol ordering rules continuously:

// Protocol rule: BVALID must not assert before wr_commit fires
property write_response_ordering;
    @(posedge clk) disable iff (!rst_n)
    $rose(bvalid) |-> $past(wr_commit);
endproperty

assert property (write_response_ordering)
else $error("AXI protocol error: BVALID asserted without preceding wr_commit");

The $past(wr_commit) system function evaluates the commit strobe on the previous clock cycle. This assertion runs continuously across all simulation test suites to detect ordering violations instantly.

Course Retrospective

This concludes the Digital Design and Verilog curriculum:

  1. Modules 1–3: Established Boolean logic, combinational adders, sequential flip-flops, and counters.
  2. Modules 4–5: Formulated behavioral modeling, finite state machines, and synthesis coding rules.
  3. Module 6: Implemented self-checking testbenches, reference models, and waveform diagnostics.
  4. Modules 7–8: Applied pipelining, clock domain crossings, timing constraints, and systematic debugging.
  5. Module 9: Introduced SystemVerilog data types, constrained random verification, and formal assertions.
  6. Module 10: Built five complete hardware systems from architectural specifications to verified RTL.

These engineering concepts provide the foundation for modern digital design, ASIC synthesis, and FPGA development.

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