Part of Curriculum: Protocol RTL Design (Module 4: APB Wait States & PSLVERR Handling)
View Full Roadmap →
Level 3 Hard ★ Flagship #29 50 pts ✓ Solved

APB Wait-State Handling — PREADY Behavior

On-Chip Protocols · memory, fifo, protocols, apb, uart, hard, amba-apb

Extend an APB slave to insert exactly 1 wait state (PREADY=0 for one cycle during ACCESS phase) before completing any transfer.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
pselpenablepwritepready>clkrst_nAPB WAIT-STATE HANDLPROTOCOL INTERFACE
⚡ Timing & Synthesizability Constraints

Timing Contract: When a transfer enters ACCESS phase (`psel && penable`), slave drives `pready=0` on the first cycle and `pready=1` on the second cycle.

RTL Constraints: Every read or write transaction must take exactly 2 clock cycles in the ACCESS phase (1 wait state).

Objective: Understand bus flow control with wait states, extending transactions, and slave pacing with PREADY.

Prerequisites: APB protocol, FSM state tracking, PREADY handshake.
NameDirWidthDescription
pclkinput1APB clock
preset_ninput1Active-low reset
pselinput1Slave select
penableinput1Enable strobe
pwriteinput1Write control
preadyoutput1Wait state control (0 = wait, 1 = ready)
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Use a toggle register `wait_done` that goes from 0 to 1 during the ACCESS phase.
Hint 2: Implementation Architecture & Approach
When `psel && penable`, invert `wait_done <= ~wait_done;`.
Hint 3: Edge Cases, Timing & Verilog Syntax
Drive `assign pready = wait_done;`.
🔒 Reveal Verified Reference RTL Solution (Click to expand)
⚠️ Self-Discovery Warning: Try solving and simulating first! Viewing the verified reference implementation will bypass the real debugging experience.
Verified Synthesizable RTL
module top_module(
  input   pclk,
  input   preset_n,
  input   psel,
  input   penable,
  input   pwrite,
  output  pready
);
  reg wait_done;

  always @(posedge pclk or negedge preset_n) begin
    if (!preset_n)
      wait_done <= 1'b0;
    else if (psel && penable)
      wait_done <= ~wait_done;
    else
      wait_done <= 1'b0;
  end

  assign pready = wait_done;
endmodule
Verilog-2001 / SV Saved
Font: |
// Click Run Tests (or press Ctrl+Enter) to compile your RTL and simulate against hidden testbenches.
Simulation Timing Diagram (VCD Waveform)
100%
No simulation waveform yet. Run tests to simulate and generate VCD traces.
No compilation run yet. Syntax warnings and elaboration messages will appear here.
No simulation output yet. Raw stdout from vvp will appear here.

RTL Problems / Level 3 · On-Chip Protocols

What You Will Learn

By solving APB Wait-State Handling — PREADY Behavior, 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

Extend an APB slave to insert exactly 1 wait state (PREADY=0 for one cycle during ACCESS phase) before completing any transfer.

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.

Objective: Understand bus flow control with wait states, extending transactions, and slave pacing with PREADY.

Prerequisites: APB protocol, FSM state tracking, PREADY handshake.

Port List & Interface Timing

The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:

NameDirWidthDescription
pclkinput1APB clock
preset_ninput1Active-low reset
pselinput1Slave select
penableinput1Enable strobe
pwriteinput1Write control
preadyoutput1Wait state control (0 = wait, 1 = ready)

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: When a transfer enters ACCESS phase (`psel && penable`), slave drives `pready=0` on the first cycle and `pready=1` on the second cycle.

Synthesis Constraints: Every read or write transaction must take exactly 2 clock cycles in the ACCESS phase (1 wait state).

Architectural Deep Dive & Implementation Walkthrough

In the AMBA 3 APB specification, slaves can extend the ACCESS phase by driving `pready = 0`. The APB bridge master is obligated to hold all control signals (`psel, penable, paddr, pwrite, pwdata`) completely static until the cycle where the slave returns `pready = 1`.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Deasserting `penable` before `pready` goes high, violating AMBA protocol rules.', 'Leaving `wait_done` asserted when entering IDLE.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

Wait states allow slow peripherals (e.g. analog ADCs, flash memory, EEPROMs) to interface with high-speed processors without needing asynchronous FIFOs.

Starter RTL Code

module top_module(
  input   pclk,
  input   preset_n,
  input   psel,
  input   penable,
  input   pwrite,
  output  pready
);

  // APB slave generating 1 wait-state per transfer

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input   pclk,
  input   preset_n,
  input   psel,
  input   penable,
  input   pwrite,
  output  pready
);
  reg wait_done;

  always @(posedge pclk or negedge preset_n) begin
    if (!preset_n)
      wait_done <= 1'b0;
    else if (psel && penable)
      wait_done <= ~wait_done;
    else
      wait_done <= 1'b0;
  end

  assign pready = wait_done;
endmodule

Related RTL Problems in Level 3

Frequently Asked Questions

What does APB Wait-State Handling — PREADY Behavior require?

Extend an APB slave to insert exactly 1 wait state (PREADY=0 for one cycle during ACCESS phase) before completing any transfer. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: memory, fifo, protocols, apb, uart, hard, amba-apb. 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 APB Wait-State Handling — PREADY Behavior to assess real-world synthesizability and race-condition awareness.