V12.6.1 The Timer's Interrupt Agreement

HardVerify35 minap_soc v1.5 · interrupt wires + fast APB checker · serverReview the topic

Write a chip-level assertion at two boundaries of ap_soc: the fast APB bus and the interrupt wires. It relates what software wrote to the timer with what the timer's request wire does. It stays silent on the good chip and reports on hidden faulty chips.

Hardware context: The protocol checkers bound into the chip bench at its bus boundaries, and a learner checker at two sites. A chip-level assertion relating the bus and an interrupt wire.

A block bench proves the timer against its own specification. The chip can still break the agreement between software and the interrupt wire. A register may not reach the block, a clock may not reach it, a request may never leave it. A checker on the chip's boundaries sees that agreement whole, without knowing anything inside the block.

The bench builds your checker into soc_tb with two sites. The first is the interrupt wires; your checker runs on clk_sys, and its resetn is the system reset. The second is the fast APB bus; its ports carry the prefix peer_. Write the body of the module, and report when one of two rules breaks.

Rule 1: the timer's request is never high while IRQ_ENABLE bit 0, as last written, is 0. Rule 2: keep RUN and IRQ_ENABLE as last written. While both are 1 and the request is low, it must rise within 4 × (DIV_TOP + 1) + 16 edges of clk_sys. Count from the latest write to any timer register, or from the edge the request fell.

Each check runs one table on the bus-manager seat. Every table programs one or more timer periods, each with its own divider and compare. Some leave the timer stopped, or its interrupt off, for a while. Your checker must stay silent on the good chip. It must report on each hidden faulty chip.

Full specification
The module the server wraps around your body (you write only the body)
module learner_checker(input logic clk, resetn, timer_irq, peer_psel, peer_penable, peer_pwrite,
    input logic [31:0] peer_paddr, peer_pwdata, input logic peer_pready, output logic report);
  // your body
endmodule
PortSignalNote
clk, resetnclk_sys and resetn_sysThe bench counts report at each rising edge while resetn is 1
timer_irqthe timer's request, before ap_plicHigh while the match flag and IRQ_ENABLE bit 0 are both set
peer_psel, peer_penable, peer_pwrite, peer_preadythe fast APB buspsel is the bus select before decoding; a write completes at an edge with all four high
peer_paddr, peer_pwdatathe full 32-bit address and the write dataThe timer's page is 0x1000_2000 to 0x1000_2FFF
RegisterAddressWhat the agreement uses
RUN0x1000_2000Bit 0: the timer counts
DIV_TOP0x1000_200CBits 7:0: a slot lasts DIV_TOP + 1 cycles
COMPARE0x1000_2010Bits 1:0: the match is the slot equal to COMPARE; four slots make a period
IRQ_CLEAR0x1000_2014A written 1 clears the match flag, so the request falls
IRQ_ENABLE0x1000_2018Bit 0: the match may raise the request

Every table writes whole words. A write takes effect at the edge it completes, so a request can rise one edge after the write that enabled it.

Given Files

Read-only files supplied by the bench.

ports.sv
// Observation site: soc_tb.interrupts,soc_tb.fast_apb
module learner_checker(input logic clk, input logic resetn, input logic timer_irq, input logic peer_psel, input logic peer_penable, input logic peer_pwrite, input logic [31:0] peer_paddr, input logic [31:0] peer_pwdata, input logic peer_pready, 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.

Timer and PWM · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000RUN0runrw0x0regsStarts and stops the counter. 1: the counter runs.
0x004DUTY2:0slotsrw0x0regsHow many of the four slots drive the PWM pin high. 0 to 4.
0x008CAPTURED1:0slotroblockThe slot number saved when the capture input fired. Slot number.
0x00CDIV_TOP7:0toprw0x00regsPrescaler: the last count before the slot number steps. A write restarts the prescaler. Last prescaler count.
0x010COMPARE1:0slotrw0x0regsThe slot number that raises match. Slot number.
0x014IRQ_CLEAR0matchwonot storedWriting 1 to bit 0 clears the stored match flag. 1 clears the flag.
0x018IRQ_ENABLE0matchrw0x0regsLets the stored match flag raise interrupt source 3. 1 enables the request.
0x020EVENT0enablerw0x0regsSix teaching fields (S6.8). Plain read and write.
0x020EVENT1onlineroblockA level from the hardware.
0x020EVENT2kickwonot storedA written 1 makes one pulse.
0x020EVENT3pendingw1cblockSet by an event; a written 1 clears it.
0x020EVENT4seenrcblockSet by an event; a read clears it.
0x020EVENT5routerw0x0blockTakes the first write only.
0x024EVENT_COUNT_LOW31:0valueroblockLow 32 bits of the 64-bit event counter. Count, low word.
0x028EVENT_COUNT_HIGH31:0valueroblockHigh 32 bits of the event counter. Count, high word.
ap_plic · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x004 + 4 × (n − 1), n = 1 to 16PRIORITY2:0levelrw0x0blockPriority of source n, 0 to 7. 0 never competes. Priority.
0x001000PENDING16:1sourcesroblockPending bits; bit number = source ID. One bit for each source.
0x002000ENABLE16:1sourcesrw0x0000blockEnable bits; bit number = source ID. One bit for each source.
0x200000THRESHOLD2:0levelrw0x0blockThe core sees a request only above this priority. Threshold.
0x200004CLAIM4:0idrw0x00blockRead: claim, returns the winner's ID and clears its pending bit. Write: complete, names the ID that is done. Source ID.

Examples

Example 1

One Period, Then the Interrupt Off
Input
wait 10; w 0x10002018 = 1; w 0x1000200c = 3; w 0x10002010 = 1; w 0x10002000 = 1; wait 160; r 0x0c001000; w 0x10002000 = 0; w 0x10002014 = 1; w 0x10002018 = 0; w 0x1000200c = 3; w 0x10002010 = 1; w 0x10002000 = 1; wait 160; w 0x10002000 = 0; w 0x10002014 = 1
Output
silent on the good chip; reports on every hidden chip

With divider 3 and compare 1 the match comes 4 cycles into the period, well inside 4 × 4 + 16 = 32 edges. With the interrupt off the match still sets its flag, but no request may rise, and none is owed.

Example 2

A Stopped Timer with Its Interrupt On
Input
wait 10; w 0x10002018 = 1; w 0x1000200c = 5; w 0x10002010 = 3; w 0x10002000 = 1; wait 200; r 0x0c001000; w 0x10002000 = 0; w 0x10002014 = 1; w 0x10002018 = 1; w 0x10002000 = 0; wait 300; w 0x10002018 = 0
Output
silent on the good chip

IRQ_ENABLE is 1 for 300 cycles while RUN is 0. A stopped timer owes no request, so rule 2 must not count.

Example 3

What a Report Means
Input
a hidden chip
Output
your checker reports at least once

The bench counts the edges at which report is 1 while resetn is 1. The grader asks only whether that count is above 0.

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. 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 at stage E13); expect an estimated 40 s on the live server.

Hints

Hint 1

Rule 2 needs three facts from the bus: RUN, IRQ_ENABLE and DIV_TOP. Keep each in a flop, written when a write to its address completes.

Hint 2

Count edges only while the timer runs, its interrupt is on and the request is low. What should start the count again?

Hint 3

What is the longest wait on a good chip? A match comes when the slot reaches COMPARE, and a slot lasts DIV_TOP + 1 cycles.

What the grader checks: Five tables. Each runs on the good chip, where your checker stays silent and the bench passes. Each also runs on every hidden faulty chip, where your checker must report. The grader sees only whether your checker reported, not when or which rule fired. No hidden chip raises a request with the enable off, so the grade does not prove rule 1. A stimulus with the interrupt off still checks that it stays silent.

5 checks on ap_soc v1.5 · interrupt wires + 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

One Period, Then the Interrupt Off

Input
wait 10; w 0x10002018 = 1; w 0x1000200c = 3; w 0x10002010 = 1; w 0x10002000 = 1; wait 160; r 0x0c001000; w 0x10002000 = 0; w 0x10002014 = 1; w 0x10002018 = 0; w 0x1000200c = 3; w 0x10002010 = 1; w 0x10002000 = 1; wait 160; w 0x10002000 = 0; w 0x10002014 = 1
Expected output
silent on the good chip; reports on every hidden chip

With divider 3 and compare 1 the match comes 4 cycles into the period, well inside 4 × 4 + 16 = 32 edges. With the interrupt off the match still sets its flag, but no request may rise, and none is owed.

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

ap_soc v1.5 · interrupt wires + fast APB checker · server