H4.6 Setup-to-Access Transaction Recorder

MediumFixVerilator · serverReview the topic

Fix an APB transaction recorder whose stored history shows the same transfer in every entry.

Hardware context: APB control/status peripheral using the declared teaching subset. Reconstruct complete APB transactions from setup through the actual acceptance edge.

A transaction recorder kept a history of every APB transfer. At the end, every entry showed the same transfer: the last one. Each transfer was recorded, but the history still came out wrong.

The class apb_recorder watches one APB bus. sample() is called once per edge with the sampled pins. At each setup edge it starts a pending apb_record with a new serial number. At the completion edge it fills in the result and appends the record to records. A reset cancels the pending record.

progress() reports the counters after every edge. manifest() lists every stored record at the end. The tests drive 64 edges of real APB traffic, with waits, errors and resets, and compare both.

Find the bug and fix it. A stored record must never change after it is stored.

Signals in the Timeline

SignalWidthRole
command_count5input of each check
outside_noise1input of each check
hardware_fault4input of each check
Full specification
The classes (keep these names, fields and methods)
class apb_record;
  int serial, start_cycle, end_cycle, waits;
  bit write, error;
  bit [7:0] address; bit [3:0] strobe;
  bit [31:0] data, read_data;
endclass
class apb_recorder;
  apb_record pending, records[$];
  int issued = 0, canceled = 0;
  function void sample(input int cycle, input apb_sample sampled);
  function string progress();
  function string manifest();
endclass
EdgeWhat the recorder does
SetupCreate a pending record. serial = issued, then add 1 to issued. Store start_cycle, write, address, strobe and the full write data.
WaitAn access edge with PREADY = 0 adds 1 to waits.
CompletionStore end_cycle and error. read_data is the read data of a successful read, else 0. Append the record and clear pending.
Error completionAn error still completes the transfer and makes a record.
ResetIf a record is pending, add 1 to canceled and drop it. Serials, counters and stored records survive.
BalanceAfter every edge, issued = stored records + canceled, plus 1 if a record is pending.
The formats of progress() and of one manifest() entry
M=<issued>,<stored>,<canceled>,<pending serial in hex, or ff>,<pending waits>;
T<serial>:<start>-<end>:W<waits>:<write>:<address>:<strobe>:<data>:R<read_data>:E<error>;
APB ruleMeaning here
SamplingEvery pin is sampled just before the rising edge of the clock.
SetupThe first edge of a transfer has PSEL = 1 and PENABLE = 0.
AccessThe edges after the setup have PSEL = 1 and PENABLE = 1.
CompletionA transfer ends at the one edge where PSEL, PENABLE and PREADY are all 1.
WaitAn access edge with PREADY = 0 is a wait. The request stays the same.
Back to backA new transfer may follow with PSEL still 1. It always starts with its own setup edge.
Ignored pinsPREADY outside an access and PSLVERR outside a completion mean nothing. Some tests drive noise on them.
SourceArm IHI 0024E, sections 3.1 to 3.4 and 4.1. This is a 32-bit subset with one completer and byte strobes.
AddressRegisterBehaviour
00CTRLRead and write. Only bytes whose strobe bit is 1 change.
04WRITE_COUNTRead only. Adds 1 for each successful write to CTRL, even with all strobes 0.
08STATUSWrite 1 to clear (W1C). Each 1 bit in a strobed byte of the write data clears that bit.
0cEVENTSRead only and read to clear. A successful read returns the value, then clears the whole word.
10IDRead only. Always reads c001c0de.
ErrorAny other address, a write to a read-only word, or deny = 1. PSLVERR = 1, read data 0 and no register change.
Part of a transcript rowMeaning
C12Edge number, counting from 0.
N1resetn.
S111PSEL, PENABLE and PWRITE.
00:11223344:f:0Address, write data, strobes and deny, in hex.
W2wait_cycles for this transfer.
R10:a5a50000PREADY, PSLVERR and read data, sampled before the edge.
I01irq before and after the edge.
M=1,0,0,00,1Your progress() after this edge.
RECORDS=T0:0-3:...Your manifest() at the end, after END.
END=1,3,0,0At the end: all commands done, completed, canceled and timed out.

Each test runs 64 edges and builds a text transcript, one row per edge. Your transcript is compared with the expected one as a whole. The result shows both lengths and exact_equal. Equal lengths alone do not pass.

Examples

Example 1

Three Back-to-Back Transfers, Three Records
Input
Noise on. Write 11223344 to CTRL with 2 waits, read CTRL with 1 wait, read WRITE_COUNT, all back to back.
Output
actual_length = 4031, expected_length = 4031, exact_equal = yes

Serial 0 runs from edge 0 to 3 with 2 waits. Serial 1 runs from edge 4 to 6 with 1 wait and reads 11223344. Serial 2 runs from edge 7 to 8 and reads 1. Each record keeps its own values.

Example 2

Errors Still Make Records
Input
Noise on. Write ffffffff to CTRL with deny = 1 and 1 wait, read address 20 with 2 waits, read ID.
Output
actual_length = 4031, expected_length = 4031, exact_equal = yes

The denied write and the read of address 20 both end with an error. Each still makes a record, with read_data 0 and E1. The ID read makes a third record holding c001c0de.

Example 3

Canceled Serials Leave Gaps
Input
Noise on. Write ffffffff with a reset right after the setup, write aabbccdd with 3 waits and a reset after 1 wait, write 55aa55aa, read WRITE_COUNT.
Output
actual_length = 3992, expected_length = 3992, exact_equal = yes

Serials 0 and 1 are canceled by the two resets. Serial 2 is the 55aa55aa write, and serial 3 reads a count of 1. The manifest lists only serials 2 and 3, and canceled is 2.

Constraints and Contract

  • The requester in these tests always follows the APB rules. Checking those rules is not this class's job.
  • One test uses a peripheral that is never ready. The test driver then resets the bus. The recorder must count that as a cancel, not a completion.
  • Keep the class names, the fields and the method signatures.

Hints

Hint 1

Look at the manifest of the first example. Do the three records hold three different transfers?

Hint 2

A queue of class handles stores handles, not copies. If two entries point to one object, a change through either shows in both.

Hint 3

The setup branch reuses the object in shared. Call new() for every setup instead, and remove shared.

What the grader checks: The recorder watches a real clocked APB peripheral with waits, errors, back-to-back transfers and resets. One test uses a peripheral that is never ready. Every progress line and the final manifest are compared.

36 checks on Verilator · server. 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 7 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

Three Back-to-Back Transfers, Three Records

Input
Noise on. Write 11223344 to CTRL with 2 waits, read CTRL with 1 wait, read WRITE_COUNT, all back to back.
Expected output
actual_length = 4031, expected_length = 4031, exact_equal = yes

Serial 0 runs from edge 0 to 3 with 2 waits. Serial 1 runs from edge 4 to 6 with 1 wait and reads 11223344. Serial 2 runs from edge 7 to 8 and reads 1. Each record keeps its own values.

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

Verilator · server