Turn a stream of accepted beats into transactions, using the last flag to find where each one ends.
Hardware context: A burst of beats delimited by last on a valid/ready link. Fold a monitor's stream of accepted beats into transactions delimited by last, so a scoreboard gets one item per transaction.
A monitor reports one item per handshake, and the scoreboard expects one item per transaction. Write the piece between them: a class txn_folder that receives every accepted beat in order and folds the beats into transactions, as lesson P1.4 describes.
Call beat(data, last) once per accepted beat. A transaction ends at the beat whose last is 1; the next beat starts a new one. report() returns what the scoreboard needs: how many transactions completed, how many beats arrived in total, the longest and shortest completed burst in beats, the first and last data of the latest completed transaction, and whether a transaction is still open, with the number of beats it has so far.
Each case creates a fresh folder, feeds it a stream, and reads the report. The streams are single beats, long bursts, back-to-back lasts, an empty stream, a stream that ends mid-transaction, and seeded mixes of all of these.
Signals in the timeline
| Signal | Width | Role |
|---|---|---|
beats_in | 5 | input of each check |
Full specification
class txn_folder;
function void beat(input bit [7:0] data, input bit last);
function logic [79:0] report();
endclass
| Field of report() | Bits | Meaning |
|---|---|---|
| transactions | 79:64 | completed transactions: beats whose last was 1 |
| beats | 63:48 | every beat received |
| longest | 47:40 | beats in the longest completed transaction; 0 when none completed |
| shortest | 39:32 | beats in the shortest completed transaction; 0 when none completed |
| first_data | 31:24 | data of the first beat of the latest completed transaction; 0 when none |
| last_data | 23:16 | data of its last beat; 0 when none |
| open_beats | 15:8 | beats received since the last completed transaction |
| open | 0 | 1 when a transaction is still open at the time of the report |
Bits 7 to 1 are 0. A transaction with one beat has that beat as both its first and its last data.
Examples
Example 1
Four beats, one transaction- Input
a0 a1 a2 a3* (* marks last)
- Output
transactions = 1, beats = 4, longest = 4, shortest = 4, first_data = 0xa0, last_data = 0xa3, open = no
Only the fourth beat carries last, so one transaction of four beats completes: longest and shortest are both 4, first_data a0, last_data a3, nothing open.
Example 2
Every beat is its own transaction- Input
10* 11* 12*
- Output
transactions = 3, beats = 3, longest = 1, shortest = 1, first_data = 0x12, last_data = 0x12, open = no
Three beats with last on each: three transactions of one beat. The latest one is 12, so first_data and last_data are both 12.
Example 3
A transaction still open at the report- Input
c0 c1* d0* e0 e1
- Output
transactions = 2, beats = 5, longest = 2, shortest = 1, first_data = 0xd0, last_data = 0xd0, open_beats = 2, open = yes
Two transactions complete (c0 c1, then d0 alone), so longest is 2 and shortest 1. Beats e0 and e1 have no last yet: open is 1 with two open beats, and the latest completed transaction is still d0.
Constraints and contract
- Data is 8 bits and last is 0 or 1; both are always known.
- Streams hold at most 24 beats. Each case uses a new folder.
- Keep the class name and both function signatures. Write counter updates as x = x + 1: the browser simulator mishandles ++ on class fields.
Hints
Hint 1
Count the beats of the current transaction in one field and clear it only after the beat with last, once the longest and shortest have been updated.
Hint 2
Remember the first data of the current transaction when its beat count is zero; copy it to first_data when the transaction ends.
Hint 3
The open flag is just whether the current beat count is non-zero; shortest needs a special first value, because 0 would never be beaten.
What the grader checks: Your folder is fed five directed streams and twelve seeded ones of up to 24 beats, and every field of its report is compared with an independent fold. Passing shows the delimiting by last is right on these streams.
17 checks on Icarus Verilog · browser. Run the examples first, then check the full regression. The suite is local and inspectable. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 steps and the final capstone