Part of Curriculum: Protocol RTL Design (Module 5: Memory-Mapped APB Register Bank)
View Full Roadmap →
Level 6 Advanced ★ Advanced #43 50 pts ✓ Solved

Configurable APB Memory-Mapped Register Bank with Masking

Advanced RTL & Protocol Design · advanced-rtl, apb-protocol, systemverilog, asic, fpga

Design a production-grade APB register bank featuring control, status, scratchpad, and interrupt-enable registers with read-only protections.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
PSELPADDR[7:0]PWDATA[31:0]ext_status[31:0]PRDATA[31:0]PREADYctrl_out[31:0]>clkrst_nCONFIGURABLE APB MEMPROTOCOL INTERFACE
⚡ Timing & Synthesizability Constraints

Timing Contract: Clocked on PCLK with active-low PRESETn. All registers update on posedge PCLK during active ACCESS phase (PSEL && PENABLE && PWRITE && PREADY).

RTL Constraints: Synthesizable Verilog-2001. No latches. Clean default address decode multiplexing.

Objective: Implement a memory-mapped register block connected to an APB bus. Implement exact register semantics: Control (R/W), Status (Read-Only from external input), Scratchpad (R/W with default reset pattern), and Interrupt Enable (R/W).

Prerequisites: AMBA APB protocol, memory-mapped I/O, address decoding, register banks.
PortDirWidthDescription
PCLK, PRESETninput1Clock and active-low reset
PSEL, PENABLE, PWRITEinput1Standard APB control
PADDR[7:0]input8Register address (0x00=CTRL, 0x04=STATUS, 0x08=SCRATCH, 0x0C=IEN)
PWDATA[31:0]input32Incoming write data
PRDATA[31:0]output32Outgoing read data
PREADY, PSLVERRoutput1Ready and error indicator
ext_status[31:0]input32Hardware status wired to Read-Only 0x04
ctrl_out[31:0]output32Current content of Control Register (0x00)
ien_out[31:0]output32Current content of Interrupt Enable Register (0x0C)
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Decode the byte address: PADDR == 8'h00, 8'h04, 8'h08, 8'h0C.
Hint 2: Implementation Architecture & Approach
For write operations, write only on PSEL && PENABLE && PWRITE.
Hint 3: Edge Cases, Timing & Verilog Syntax
For 0x04 (STATUS), write operations must NOT overwrite the external status input.
🔒 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  wire        PCLK,
  input  wire        PRESETn,
  input  wire        PSEL,
  input  wire        PENABLE,
  input  wire        PWRITE,
  input  wire [7:0]  PADDR,
  input  wire [31:0] PWDATA,
  output reg  [31:0] PRDATA,
  output wire        PREADY,
  output reg         PSLVERR,
  input  wire [31:0] ext_status,
  output reg  [31:0] ctrl_out,
  output reg  [31:0] ien_out
);

  assign PREADY = 1'b1;
  reg [31:0] scratch_reg;

  wire wr_en = PSEL && PENABLE && PWRITE;
  wire rd_en = PSEL && PENABLE && !PWRITE;

  always @(posedge PCLK or negedge PRESETn) begin
    if (!PRESETn) begin
      ctrl_out    <= 32'h00000000;
      ien_out     <= 32'h00000000;
      scratch_reg <= 32'hA5A50001;
      PRDATA      <= 32'h00000000;
      PSLVERR     <= 1'b0;
    end else begin
      PSLVERR <= 1'b0;
      if (wr_en) begin
        case (PADDR)
          8'h00: ctrl_out    <= PWDATA;
          8'h04: ; // Status register is Read-Only; writes ignored without error or with error per design
          8'h08: scratch_reg <= PWDATA;
          8'h0C: ien_out     <= PWDATA;
          default: PSLVERR   <= 1'b1;
        endcase
      end

      if (rd_en) begin
        case (PADDR)
          8'h00: PRDATA <= ctrl_out;
          8'h04: PRDATA <= ext_status;
          8'h08: PRDATA <= scratch_reg;
          8'h0C: PRDATA <= ien_out;
          default: begin
            PRDATA  <= 32'h00000000;
            PSLVERR <= 1'b1;
          end
        endcase
      end
    end
  end

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 6 · Advanced RTL & Protocol Design

What You Will Learn

By solving Configurable APB Memory-Mapped Register Bank with Masking, 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 production-grade APB register bank featuring control, status, scratchpad, and interrupt-enable registers with read-only protections.

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: Implement a memory-mapped register block connected to an APB bus. Implement exact register semantics: Control (R/W), Status (Read-Only from external input), Scratchpad (R/W with default reset pattern), and Interrupt Enable (R/W).

Prerequisites: AMBA APB protocol, memory-mapped I/O, address decoding, register banks.

Port List & Interface Timing

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

PortDirWidthDescription
PCLK, PRESETninput1Clock and active-low reset
PSEL, PENABLE, PWRITEinput1Standard APB control
PADDR[7:0]input8Register address (0x00=CTRL, 0x04=STATUS, 0x08=SCRATCH, 0x0C=IEN)
PWDATA[31:0]input32Incoming write data
PRDATA[31:0]output32Outgoing read data
PREADY, PSLVERRoutput1Ready and error indicator
ext_status[31:0]input32Hardware status wired to Read-Only 0x04
ctrl_out[31:0]output32Current content of Control Register (0x00)
ien_out[31:0]output32Current content of Interrupt Enable Register (0x0C)

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Clocked on PCLK with active-low PRESETn. All registers update on posedge PCLK during active ACCESS phase (PSEL && PENABLE && PWRITE && PREADY).

Synthesis Constraints: Synthesizable Verilog-2001. No latches. Clean default address decode multiplexing.

Architectural Deep Dive & Implementation Walkthrough

Memory-Mapped Register Banks in Modern SoCs

Every peripheral core in an SoC (timers, UARTs, I2C controllers, GPU dispatchers) exposes an addressable register bank over APB or AXI-Lite.

Key Architecture Rules

  • Read-Only Registers: Registers reflecting hardware conditions (status, FIFO levels, error flags) ignore CPU writes.
  • Reset Value Management: Certain registers (like scratchpads or hardware IDs) must wake up with nonzero values to allow software drivers to identify the IP version.
  • Address Decoding: Word-aligned addresses step in multiples of 4 bytes (0x00, 0x04, 0x08, 0x0C). Unmapped accesses must flag PSLVERR to trap rogue firmware pointers.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

Allowing writes to modify read-only status registers or failing to clear PSLVERR on valid transfers.

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

Registers can consume significant gate count. For wide register sets, register sharing or RAM-based register files are employed.

Starter RTL Code

module top_module (
  input  wire        PCLK,
  input  wire        PRESETn,
  input  wire        PSEL,
  input  wire        PENABLE,
  input  wire        PWRITE,
  input  wire [7:0]  PADDR,
  input  wire [31:0] PWDATA,
  output reg  [31:0] PRDATA,
  output wire        PREADY,
  output reg         PSLVERR,
  input  wire [31:0] ext_status,
  output reg  [31:0] ctrl_out,
  output reg  [31:0] ien_out
);

  // Address Map:
  // 0x00: CTRL    (R/W, reset=0x00000000) -> drives ctrl_out

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module (
  input  wire        PCLK,
  input  wire        PRESETn,
  input  wire        PSEL,
  input  wire        PENABLE,
  input  wire        PWRITE,
  input  wire [7:0]  PADDR,
  input  wire [31:0] PWDATA,
  output reg  [31:0] PRDATA,
  output wire        PREADY,
  output reg         PSLVERR,
  input  wire [31:0] ext_status,
  output reg  [31:0] ctrl_out,
  output reg  [31:0] ien_out
);

  assign PREADY = 1'b1;
  reg [31:0] scratch_reg;

  wire wr_en = PSEL && PENABLE && PWRITE;
  wire rd_en = PSEL && PENABLE && !PWRITE;

  always @(posedge PCLK or negedge PRESETn) begin
    if (!PRESETn) begin
      ctrl_out    <= 32'h00000000;
      ien_out     <= 32'h00000000;
      scratch_reg <= 32'hA5A50001;
      PRDATA      <= 32'h00000000;
      PSLVERR     <= 1'b0;
    end else begin
      PSLVERR <= 1'b0;
      if (wr_en) begin
        case (PADDR)
          8'h00: ctrl_out    <= PWDATA;
          8'h04: ; // Status register is Read-Only; writes ignored without error or with error per design
          8'h08: scratch_reg <= PWDATA;
          8'h0C: ien_out     <= PWDATA;
          default: PSLVERR   <= 1'b1;
        endcase
      end

      if (rd_en) begin
        case (PADDR)
          8'h00: PRDATA <= ctrl_out;
          8'h04: PRDATA <= ext_status;
          8'h08: PRDATA <= scratch_reg;
          8'h0C: PRDATA <= ien_out;
          default: begin
            PRDATA  <= 32'h00000000;
            PSLVERR <= 1'b1;
          end
        endcase
      end
    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.

Frequently Asked Questions

What does Configurable APB Memory-Mapped Register Bank with Masking require?

Design a production-grade APB register bank featuring control, status, scratchpad, and interrupt-enable registers with read-only protections. 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 Configurable APB Memory-Mapped Register Bank with Masking to assess real-world synthesizability and race-condition awareness.