V3.5.1 Bind an APB Phase Checker into the Chip

MediumImplement30 minap_soc v1.5 · fast APB checker · serverReview the topic

Write a passive checker of the APB phase order and have it built into the chip bench at the fast APB bus. It must stay silent on every legal transfer the chip makes and report on hidden faulty chips.

Hardware context: Checkers bound onto the fast APB bus of ap_soc v1.5. Writing an APB phase checker built into the chip bench.

A block bench owns its bus. At chip level the bus belongs to the chip, so a checker can only listen. The bench builds your checker into soc_tb, wired to the fast APB bus after the AHB-to-APB bridge. Your checker drives one thing, report, and the bench counts the clock edges at which it is high.

Write the checker body. Report when a transfer breaks the phase order of APB. Four rules: an access cycle needs its select, and a setup cycle is followed by an access cycle. An access cycle follows a setup cycle or another access cycle (a wait). The direction holds inside a transfer.

A fifth rule is this chip's, not APB's. APB allows any pattern of write strobes, but ap_soc's bridge makes them from the size of the AHB write. So a write shows one byte, an aligned half-word or the whole word, and nothing else.

Each check runs a table of bus transfers through the bus-manager seat. On the good chip your checker must stay silent; on each hidden faulty chip it must report. The chip makes every legal shape of APB transfer: no wait, many waits, two transfers back to back, and an error answer.

Full specification
The module the server wraps around your body (you write only the body)
module learner_checker(input logic clk, resetn, psel, penable, pwrite, input logic [3:0] pstrb, output logic report);
  // your body
endmodule
PortSignal of the chipNote
clk, resetnclk_sys and the bus resetThe bench samples report at each rising edge while resetn is 1
pselthe bridge's select, before the slot decoder1 from the setup cycle to the end of the access
penablethe bridge's enable1 in access cycles
pwritethe direction1 for a write
pstrbthe four byte-lane write strobesbit n set: byte n of the write data is written; 0 on a read
Writepstrb
A byte in lane 0, 1, 2 or 30001, 0010, 0100 or 1000
A half-word, low or high0011 or 1100
A word1111
CyclepselpenableNext cycle may be
idle00idle or setup
setup10access only
access11access (a wait), setup (back to back) or idle

PREADY is not a port, so the checker cannot see where a wait ends. A transfer that waits 14 cycles is legal: the slow bridge does exactly that.

Given Files

Read-only files supplied by the bench.

ports.sv
// Observation site: soc_tb.fast_apb
module learner_checker(input logic clk, input logic resetn, input logic psel, input logic penable, input logic pwrite, input logic [3:0] pstrb, output logic report);
// Supply the module body only.
endmodule
report.txt
soc_tb samples report on each rising edge of clk with resetn high. Assert report for a sampled violation. The bench counts reports.
The sequence table · bench manual

One row a line: who op address data mask expect delay repeat. Two words, four hex numbers, two decimal numbers. delay: cycles to wait before the row. repeat: how often the row runs. A line that starts with # is a comment. With +core=bfm the table is the test: the bench writes TB_STATUS = 2 before the first row and the pass or fail word after the last. With +core=cpu a table holds the bench's side of a firmware test.

whoopMeaning
corew wh wbWrite a word, a half, a byte of data at address; the answer must be OKAY
corer rh rbRead; (value & mask) must equal (expect & mask)
corewe reWrite or read that must answer ERROR
corewq rqAs w and r, with the next row's address phase on this row's data phase (back to back)
corepollRead until the masked value is the expected one; data = the most reads (0: 1,000)
coreirqThe interrupt pins now (bit 0 software, 1 timer, 2 external) against mask and expect
corewait_irqWait until a pin of mask is high; data = the most cycles
coreidleEnd a back-to-back run
dmacopyOne job from address to data of mask bytes; STATUS must be expect (2 DONE, 4 FAULT)
jtagidcodeTAP reset, read IDCODE, compare
jtaghalt resume stepDebug control (a halt waits for the core)
jtagrr rwRead or write the register numbered address (0x1000 + n, a CSR, 0x7b0, 0x7b1)
jtagstreamStart background word reads at address A, count D, maximum random gap M, expected word E
tbwait_releaseWait for the system bus and core resets to release. Seat tables also hold each row at dispatch during reset.
tbwatchdogSet the seat stall limit to data system clocks (zero disables it). A stalled request reports its row, address and direction.
tbgapsMaximum random gap D before each seat row, in system cycles (0 disables gaps)
jtagmr mwRead or write a word of memory through the debug manager
jtagarm status"Halt at reset" = data; {halted, error, busy} against mask and expect
jtagcmdCommand number address (0 to 7, facts 27.10) with the word data; its reply against mask and expect
tbuart_sendSend the byte data to the chip
tbuart_expectThe next byte from the chip must be expect; address = the most bit times to wait
tbgpio_set gpio_pulsePad address to level data; a pulse of data cycles of CLK
tbgpio_expectThe sixteen pads against mask and expect
tbreset supplyThe reset pin, or the supply, for data cycles of CLK
tbwait_eventWait until the test writes address to TB_EVENT
tbargDeposit data in TB_ARG
tbwait_statusWait until (TB_STATUS & mask) equals (expect & mask)
tbpoke peekBack-door write of mask bytes (0: 4) of data; back-door read against mask, expect
tbwaitOnly the delay
syma symbol nameBack-door write of data to that C variable, with the symbol's size

core and dma rows need +core=bfm. soc-rows.mjs turns a list of core and tb rows into both forms: a table for the seat, or a table in SRAM for an interpreter in ROM, with a hand-shake wherever the list goes from one side to the other.

ap_sysctl · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000CHIP_ID31:0valuero0x2A5310C5constThe chip's identity: the IDCODE of the TAP. Fixed number.
0x004RESET_CAUSE0power_onroblockSticky record of reset sources since power-on. Power-on reset.
0x004RESET_CAUSE1pinroblockReset pin.
0x004RESET_CAUSE2watchdogroblockWatchdog.
0x004RESET_CAUSE3softwareroblockSoftware request.
0x004RESET_CAUSE4debugroblockDebug request.
0x008SOFT_RESET0timerwonot storedReset requests from software. 1 arms one restart of the timer.
0x008SOFT_RESET1chipwonot stored1 requests the software reset (new in v1.5).
0x00CSTRAPS0bootroblockStraps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM.
0x010PINMUX31:0selectrw0x00000000regsTwo bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n.
0x014CLK_GATE0uart0rw0x1regs1 lets that block's clock run (new in v1.5). UART0.
0x014CLK_GATE1gpiorw0x1regsGPIO.
0x014CLK_GATE2timerrw0x1regsTimer and PWM.
0x014CLK_GATE3spirw0x1regsSPI.
0x014CLK_GATE4dmarw0x1regsDMA.
0x018LOCK0pinmuxw1s0x0regsWrite-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes.
0x018LOCK1clk_gatew1s0x0regs1: CLK_GATE ignores writes.
0x018LOCK2debugw1s0x0regs1: the debug lock is closed.
0x020TB_STATUS31:0valuerw0x00000000regs (power-on reset only)Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage.
0x024TB_PUTC31:0valuerw0x00000000regs (power-on reset only)Scratch word 1. The firmware kit writes one character here. Plain storage.
0x028TB_EVENT31:0valuerw0x00000000regs (power-on reset only)Scratch word 2. The firmware kit writes an event number here. Plain storage.
0x02CTB_ARG31:0valuerw0x00000000regs (power-on reset only)Scratch word 3. A bench leaves a word for the firmware here. Plain storage.

Examples

Example 1

Register Blocks: No Wait
Input
tb wait (30 cycles); core r 0x10004000; core w 0x10000010 = 0x8; core r 0x10000010; core w 0x10001008 = 0x40; core r 0x10001000
Output
silent on the good chip; reports on every hidden chip

A register block of ap_soc never waits: setup, then one access cycle. Your checker must stay silent here.

Example 2

Back to Back
Input
tb wait (30 cycles); core rq 0x10004000; core rq 0x10004010; core rq 0x10000004; core wq 0x1000402c = 0x55; core idle 0x00000000; core r 0x1000402c
Output
silent on the good chip

With the q rows the seat puts the next address phase on the data phase. On the APB bus an access is followed straight by the next setup, and select never drops.

Example 3

Waits Across the Slow Bridge
Input
tb wait (30 cycles); core r 0x10008004; core w 0x10008008 = 0x1; core r 0x10008008; core w 0x10008008 = 0x0
Output
silent on the good chip

A read of ap_pwrctl holds the access for 10 cycles and a write for 14. Meanwhile the slow bus does its own transfer.

Constraints and Contract

  • Use assign, always_comb or always_ff @(posedge clk), with if, else and begin/end. Local state is bit or logic, up to 32 bits a variable. Nothing else of SystemVerilog is accepted: no system tasks, no hierarchy, no directives.
  • Report only on a broken rule: a report on the good chip fails the case.
  • Each check builds the chip bench once. That took about 11 s on the laptop (measured); expect an estimated 40 s on the live server.

Hints

Hint 1

Keep three flops: did the last edge see a setup cycle, an access cycle, and which direction.

Hint 2

Back to back means access, then setup, with psel still 1. That is legal.

Hint 3

The case that waits is the one that catches a checker written for a block that never waits.

What the grader checks: Six tables of transfers. Each runs on the good chip, where your checker stays silent, and on each hidden faulty chip, where it reports. The grader sees only whether your checker reported, not when or how often, and not which rule fired. Between them the hidden chips need two different rules: no single rule catches both. They break none of the other three, so an accepted checker has not proved each of those. The good-chip tables prove that none of your rules reports falsely. Your checker cannot see PREADY, the address or the data.

6 checks on ap_soc v1.5 · fast APB checker · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 problems on this path

Report a problem with this page

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

Register Blocks: No Wait

Input
tb wait (30 cycles); core r 0x10004000; core w 0x10000010 = 0x8; core r 0x10000010; core w 0x10001008 = 0x40; core r 0x10001000
Expected output
silent on the good chip; reports on every hidden chip

A register block of ap_soc never waits: setup, then one access cycle. Your checker must stay silent here.

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

ap_soc v1.5 · fast APB checker · server