P3.11.1 The APB4-to-APB3 Adapter

HardImplementIcarus · browser samples / server checksReview the topic

Put an old APB3 peripheral behind an APB4 bus without losing a byte. Turn every sparse write into a read, a merge and a write.

Hardware context: An APB4 requester in front of an APB3 completer with no PSTRB and no PPROT. Implement an APB4-to-APB3 adapter that turns sparse writes into read, merge and write.

Lesson P3.11 showed an APB3 completer wiping three bytes of a word because it never saw PSTRB. The specification calls the pair compatible, as long as nobody expects sparse writes. This team needs byte writes to work, so they asked for an adapter.

Write module apb_rmw_adapter. Upstream it is an APB4 completer port; downstream it is an APB3 requester. Reads and full-word writes pass through as one downstream transfer each. A write with no strobe set does nothing downstream.

Every other write becomes two downstream transfers. First read the word, then write it back with the strobed bytes replaced. If the read fails, nothing is written. Hold the upstream transfer with PREADY low until the downstream work is done, and report the right PSLVERR.

Signals in the Timeline

SignalWidthRole
transfers4input of each check
Full specification
The module you write (keep these ports)
module apb_rmw_adapter (
  input  logic        pclk,
  input  logic        presetn,     // active low
  // upstream: the completer port an APB4 requester drives
  input  logic        psel,
  input  logic        penable,
  input  logic        pwrite,
  input  logic [7:0]  paddr,
  input  logic [31:0] pwdata,
  input  logic [3:0]  pstrb,
  input  logic [2:0]  pprot,
  output logic        pready,
  output logic [31:0] prdata,
  output logic        pslverr,
  // downstream: the requester port to an APB3 completer (no PSTRB, no PPROT)
  output logic        m_psel,
  output logic        m_penable,
  output logic        m_pwrite,
  output logic [7:0]  m_paddr,
  output logic [31:0] m_pwdata,
  input  logic        m_pready,
  input  logic [31:0] m_prdata,
  input  logic        m_pslverr
);
  // your adapter
endmodule
Upstream transferDownstreamUpstream response
readone read of the wordits PRDATA and PSLVERR
write, PSTRB 1111one write of PWDATAits PSLVERR
write, PSTRB 0000noneOKAY
any other writea read; if it is OKAY, a write of the merged wordPSLVERR if the read or the write failed

Downstream transfers keep every APB rule: a setup cycle, then access until m_pready, with address, direction and data stable. m_paddr is the word address, paddr with bits 1 and 0 cleared. PPROT is dropped, because an APB3 completer has none.

The fixture checks the downstream link at every edge and counts the downstream reads and writes. The result is {done, errs, ds_reads, ds_writes, bad, last_read, ram_sum}. errs has bit i set when upstream transfer i ended with PSLVERR. ram_sum adds the low 24 bits of all sixteen words after the run.

Examples

Example 1

Straight Through
Input
read 0x04; write 0x04 = cafef00d strb 1111; read 0x04
The APB3 completer: word j at 0x4j starts as 10203040 + 01010101 x j; 0 wait states per transfer; 0x38 refuses reads, 0x3c refuses writes, 0x40 and up refuse both
Output
done = 3, errs = 'b00000000, ds_reads = 2, ds_writes = 1, bad = 0, last_read = 0xcafef00d, ram_sum = 0x593b44

Two reads and one full write: three downstream transfers, one for each. The second read returns cafef00d.

Example 2

One Byte
Input
write 0x08 = 0000aa00 strb 0010; read 0x08
The APB3 completer: word j at 0x4j starts as 10203040 + 01010101 x j; 0 wait states per transfer; 0x38 refuses reads, 0x3c refuses writes, 0x40 and up refuse both
Output
done = 2, errs = 'b00000000, ds_reads = 2, ds_writes = 1, bad = 0, last_read = 0x1222aa42, ram_sum = 0x7bf478

The write carries aa in lane 1. The adapter reads 12223242, puts aa in lane 1 and writes the word back. The read then returns 1222aa42.

Example 3

The Read Fails
Input
write 0x38 = 0000bb00 strb 0010; write 0x38 = 77777777 strb 1111; read 0x34
The APB3 completer: word j at 0x4j starts as 10203040 + 01010101 x j; 0 wait states per transfer; 0x38 refuses reads, 0x3c refuses writes, 0x40 and up refuse both
Output
done = 3, errs = 'b00000001, ds_reads = 2, ds_writes = 1, bad = 0, last_read = 0x1d2d3d4d, ram_sum = 0xc4b5a1

Word 0x38 refuses reads. The sparse write ends with PSLVERR and no downstream write. The full write that follows goes through.

Constraints and Contract

  • Keep the module name and the ports. The upstream requester is correct; it waits as long as you hold PREADY low.
  • The fixture drives its outputs after each rising edge and samples yours just before the next one.
  • Do not reach outside your ports.

Hints

Hint 1

Start on the upstream access phase: PSEL and PENABLE both 1. The upstream signals stay stable until you raise PREADY.

Hint 2

A small state machine: idle, read setup, read access, write setup, write access, done. PREADY is 1 only in done.

Hint 3

Merge lane by lane: the strobed lanes from PWDATA, the others from the word you read.

What the grader checks: Your adapter runs nine scripts of up to eight transfers. The APB3 completer inserts zero to two wait states, and some words refuse reads or writes. Responses, downstream counts and data are compared with a model. Passing shows the adapter is right on these scripts.

9 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Straight Through

Input
read 0x04; write 0x04 = cafef00d strb 1111; read 0x04
The APB3 completer: word j at 0x4j starts as 10203040 + 01010101 x j; 0 wait states per transfer; 0x38 refuses reads, 0x3c refuses writes, 0x40 and up refuse both
Expected output
done = 3, errs = 'b00000000, ds_reads = 2, ds_writes = 1, bad = 0, last_read = 0xcafef00d, ram_sum = 0x593b44

Two reads and one full write: three downstream transfers, one for each. The second read returns cafef00d.

Run samples executes all 3 public checks. Check all tests runs 9 checks on the server.

Icarus · browser samples / server checks