RTL Problems / Level 6 · Advanced RTL & Protocol Design
What You Will Learn
By solving AMBA APB Master State Machine Controller, you will acquire core industry skills:
- Synthesizable hardware modeling in standard Verilog-2001 / SystemVerilog.
- Correct handling of interface port contracts, edge-triggered clocks, and active-low/high resets.
- Simulation waveform interpretation and debugging using timing diagrams (VCD traces).
- Architectural avoidance of timing violations, glitching hazards, and synthesis warnings.
Problem Statement & Requirements
Design a synthesizable AMBA APB master finite state machine that accepts internal core commands and drives standard APB bus transactions.
Hardware design teams at leading semiconductor firms evaluate these exact port contracts, race-condition assertions, and corner cases during technical design reviews and ASIC engineer interviews.
Prerequisites: Finite state machines, AMBA 3 APB master timing, handshaking protocols.
Port List & Interface Timing
The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:
| Port | Dir | Width | Description |
|---|---|---|---|
clk, rst_n | input | 1 | Clock and active-low synchronous reset |
req | input | 1 | Internal transfer trigger |
req_write | input | 1 | 1 = Write, 0 = Read |
req_addr[7:0] | input | 8 | Requested memory address |
req_wdata[31:0] | input | 32 | Requested write data |
ready | output | 1 | High when master is idle and can accept requests |
rdata[31:0] | output | 32 | Captured read data valid when ready pulses high |
err | output | 1 | Asserted if slave returned PSLVERR=1 |
PSEL, PENABLE, PWRITE | output | 1 | APB control signals |
PADDR[7:0], PWDATA[31:0] | output | 8, 32 | APB address and write data lines |
PRDATA[31:0], PREADY, PSLVERR | input | 32, 1, 1 | APB slave feedback signals |
Timing Constraints & Synthesizable RTL Rules
Timing Contract: Clocked on rising edge of clk with active-low synchronous reset rst_n. Master must assert PSEL during SETUP and add PENABLE in ACCESS, holding PADDR/PWDATA stable until PREADY=1.
Synthesis Constraints: Synthesizable Verilog-2001. No # delays. Clean Moore/Mealy FSM implementation.
Architectural Deep Dive & Implementation Walkthrough
APB Master Controller Architecture
An APB Master translates transaction requests from processor cores, DMA engines, or debug bridges into valid APB bus waveforms.
State Machine Execution
- IDLE: The master asserts
ready = 1. Whenreq = 1is received, the master captures address, write-enable, and payload, assertsPSEL = 1, and enters SETUP. - SETUP:
PSEL = 1andPENABLE = 0. Address and control signals are stable. The state machine transitions unconditionally to ACCESS on the next clock edge. - ACCESS: The master asserts
PENABLE = 1. If the slave assertsPREADY = 0, the master remains in ACCESS indefinitely without changing any control or data signals. OncePREADY = 1is sampled, the transfer completes, read data is latched, and the master returns to IDLE (or restarts SETUP for back-to-back operations).
Common RTL Designer Pitfalls
Deasserting PENABLE or changing PADDR/PWDATA when PREADY=0. The APB specification strictly requires all signals to remain stable throughout wait states.
Silicon & Hardware Engineering Notes
APB masters in safety-critical SoCs (ISO 26262) incorporate a timeout counter in the ACCESS state to abort hung transactions if a peripheral never asserts PREADY.
Starter RTL Code
module top_module (
input wire clk,
input wire rst_n,
input wire req,
input wire req_write,
input wire [7:0] req_addr,
input wire [31:0] req_wdata,
output reg ready,
output reg [31:0] rdata,
output reg err,
output reg PSEL,
output reg PENABLE,
output reg PWRITE,
output reg [7:0] PADDR,
output reg [31:0] PWDATA,
input wire [31:0] PRDATA,
input wire PREADY,
input wire PSLVERR
Verified Reference Solution
🔒 Reveal Verified Reference RTL Solution
module top_module (
input wire clk,
input wire rst_n,
input wire req,
input wire req_write,
input wire [7:0] req_addr,
input wire [31:0] req_wdata,
output reg ready,
output reg [31:0] rdata,
output reg err,
output reg PSEL,
output reg PENABLE,
output reg PWRITE,
output reg [7:0] PADDR,
output reg [31:0] PWDATA,
input wire [31:0] PRDATA,
input wire PREADY,
input wire PSLVERR
);
localparam IDLE = 2'b00;
localparam SETUP = 2'b01;
localparam ACCESS = 2'b10;
reg [1:0] state;
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
state <= IDLE;
ready <= 1'b1;
rdata <= 32'h0;
err <= 1'b0;
PSEL <= 1'b0;
PENABLE <= 1'b0;
PWRITE <= 1'b0;
PADDR <= 8'h0;
PWDATA <= 32'h0;
end else begin
case (state)
IDLE: begin
PENABLE <= 1'b0;
if (req) begin
state <= SETUP;
ready <= 1'b0;
PSEL <= 1'b1;
PWRITE <= req_write;
PADDR <= req_addr;
PWDATA <= req_wdata;
err <= 1'b0;
end else begin
PSEL <= 1'b0;
ready <= 1'b1;
end
end
SETUP: begin
state <= ACCESS;
PENABLE <= 1'b1;
end
ACCESS: begin
if (PREADY) begin
err <= PSLVERR;
if (!PWRITE) begin
rdata <= PRDATA;
end
if (req) begin
state <= SETUP;
PSEL <= 1'b1;
PENABLE <= 1'b0;
PWRITE <= req_write;
PADDR <= req_addr;
PWDATA <= req_wdata;
ready <= 1'b0;
end else begin
state <= IDLE;
PSEL <= 1'b0;
PENABLE <= 1'b0;
ready <= 1'b1;
end
end
end
default: state <= IDLE;
endcase
end
end
endmodule
Related RTL Problems in Level 6
- Manchester Encoder — Combine a data bit with the clock to produce a Manchester-encoded line signal — the self-clocking encoding used in classic Ethernet and RFID.
- Manchester Decoder — Recover the original data bit from a Manchester-encoded line signal — the exact inverse of the Manchester Encoder problem.
- Quadrature Rotary Encoder Decoder — Decode the two-phase A/B signal from a real rotary knob or mouse wheel into a direction and position count — sample B on every rising edge of A.
Connected EcrioniX Learning Resources
Accelerate your VLSI engineering knowledge with these curated learning materials:
Progress through step-by-step verified modules from fundamentals to advanced silicon design.
Benchmark your hardware knowledge across 10 semiconductor domains and receive study roadmaps.
Explore foundational circuit theory, waveform timing, and physical hardware implementation.
Frequently Asked Questions
What does AMBA APB Master State Machine Controller require?
Design a synthesizable AMBA APB master finite state machine that accepts internal core commands and drives standard APB bus transactions. Implement it as Verilog module top_module matching the listed ports.
Is this design combinational or sequential?
Tags: advanced-rtl, apb-protocol, systemverilog, asic, fpga. If a clock signal is present in the port table, implement it as sequential logic; otherwise, use continuous assignments or combinational blocks.
How is my solution graded?
A hidden SystemVerilog testbench simulates your module in the cloud judge. You pass when all directed corner cases match the golden model and the VCD timing waveform matches the contract.
How does this challenge help with semiconductor interviews?
Technical interviewers at NVIDIA, Qualcomm, Apple, and Intel routinely ask candidates to code, debug, and explain the timing waveforms of AMBA APB Master State Machine Controller to assess real-world synthesizability and race-condition awareness.