Count what an APB link spends its cycles on: completed reads and writes, wait states, idle cycles, back-to-back transfers and errors.
Hardware context: One APB completer select observed by a bus meter. Implement a bus meter that counts transfers, waits, idle cycles, back-to-back pairs and errors.
Lesson P3.1 claimed that APB spends two cycles per transfer and runs one transfer at a time. A bus meter turns that claim into numbers for a real run. A performance engineer reads them before moving a block off APB.
Write module apb_meter. It watches one completer's select and samples the bus at every rising edge. Each edge outside reset is exactly one of four things: idle, a setup cycle, a wait, or the completion of a transfer.
The bus is legal but not tidy. While PENABLE is low, PREADY and PSLVERR may hold any value, and this fixture uses that freedom. PWRITE is random while PSEL is low. Only the completion edge decides what a transfer was.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
pclk | 1 | stimulus, the same for every design |
presetn | 1 | stimulus, the same for every design |
psel | 1 | stimulus, the same for every design |
penable | 1 | stimulus, the same for every design |
pwrite | 1 | stimulus, the same for every design |
pready | 1 | stimulus, the same for every design |
pslverr | 1 | stimulus, the same for every design |
your writes | 8 | stimulus, the same for every design |
your reads | 8 | stimulus, the same for every design |
your waits | 8 | stimulus, the same for every design |
Full specification
module apb_meter (
input logic pclk,
input logic presetn, // active low
input logic psel,
input logic penable,
input logic pwrite,
input logic pready,
input logic pslverr,
output logic [7:0] writes, // completed write transfers
output logic [7:0] reads, // completed read transfers
output logic [7:0] waits, // access cycles with PREADY low
output logic [7:0] idles, // cycles with PSEL low, outside reset
output logic [7:0] b2b, // setup cycles that directly follow a completion
output logic [7:0] errors // completed transfers with PSLVERR
);
// your meter
endmodule
| Count | Adds one at an edge where |
|---|---|
| idles | PRESETn is 1 and PSEL is 0. |
| waits | PSEL and PENABLE are 1 and PREADY is 0. |
| writes, reads | PSEL, PENABLE and PREADY are all 1: the transfer completes. PWRITE at that edge gives the direction. |
| errors | A transfer completes with PSLVERR = 1. |
| b2b | A setup cycle (PSEL 1, PENABLE 0) comes at the edge right after a completion: PSEL never went low. |
While PRESETn is 0, every count is 0 and nothing is counted. The result is {writes, reads, waits, idles, b2b, errors} in bits 47 to 0, read after the last edge. Each trace has two reset edges and 62 more.
Examples
Example 1
Two Transfers and the Idle Around Them- Input
1 idle, write; 2 idle, read; then idle to edge 64 Outside the access phase PREADY and PSLVERR carry random values; PWRITE is random while PSEL is low.
- Output
writes = 1, reads = 1, waits = 0, idles = 58, b2b = 0, errors = 0
One idle edge, a write in two edges, two idle edges, a read in two edges, then idle to the end. Neither setup follows a completion, so b2b is 0.
Example 2
Back to Back- Input
1 idle, write; write; read; then idle to edge 64 Outside the access phase PREADY and PSLVERR carry random values; PWRITE is random while PSEL is low.
- Output
writes = 2, reads = 1, waits = 0, idles = 56, b2b = 2, errors = 0
After the write completes, PSEL stays high and the next setup follows at once. That happens twice, so b2b is 2.
Example 3
PREADY in the Setup Cycle- Input
1 idle, write; read; write; read; 1 idle, write; then idle to edge 64 Outside the access phase PREADY and PSLVERR carry random values; PWRITE is random while PSEL is low.
- Output
writes = 3, reads = 2, waits = 0, idles = 52, b2b = 3, errors = 0
The fixture drives PREADY high in some setup cycles. A transfer completes only when PENABLE is also 1, so those edges are setups, not completions.
Constraints and Contract
- Keep the module name and the ports. Counts never exceed 255 here.
- The fixture changes the pins between edges and reads your counts after the last edge.
- Every input is always 0 or 1.
Hints
Hint 1
Test the cases in order: PSEL low, then PENABLE low, then PREADY low. What is left is a completion.
Hint 2
Back to back needs one bit of memory: did the previous edge complete a transfer?
Hint 3
A value of PREADY or PSLVERR in a setup cycle means nothing. Do not let it reach a count.
What the grader checks: Your meter replays nine traces of 64 edges, five directed and four seeded. They carry random PREADY, PSLVERR and PWRITE wherever the protocol allows them. Its counts are compared with an independent model of the transfer rules.
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