Parameters, Wrappers and Subsystems
One block description becomes many copies on a chip. Learn how each copy is configured, how a wrapper makes it fit, and how copies are grouped.
You Will Be Able To
- Tell a block description from its instances, and set a parameter for each instance.
- Say what a wrapper may change, and what it must not.
- Read the hierarchy of a chip as a tree of subsystems and instances.
- Lesson
- S1.7
- Time
- 24 min
- Runs on
- Your browser
- Check
- 5 questions
Three timers are built from one description. Two fire on time. The third never fires, and no tool prints a warning. One number was never passed.
Before You Start
You need IP blocks and the integration guide from S1.3. You need the blocks of ap_soc from S1.1.
The lab uses simple Verilog: a counter, and blocks placed inside other blocks.
| Question | |
|---|---|
| 1 | What is the difference between a block description and an instance? |
| 2 | What is a parameter, and when is its value fixed? |
| 3 | What happens when an instance passes no value for a parameter? |
| 4 | What is a wrapper allowed to change? |
| 5 | What is a subsystem, and where does it sit in the hierarchy? |
The Idea: One Description, Many Copies
S1.3 treated a block as one thing that arrives. A chip often needs the same block several times. A phone chip has many UARTs and many timers. Nobody writes the timer many times.
The RTL of a block is a description. Each use of it on the chip is a copy, called an instance. Every instance has its own name, its own wires and its own flip-flops.
Copies are rarely identical. One timer must count to 10 and another to 200. So a description leaves some numbers open. Each such number is a parameter, and each instance fills it in.
Two more ideas complete the page. A wrapper makes a block fit a chip without editing the block. A subsystem groups instances, so a large chip stays readable.
New Words
| Word | Meaning |
|---|---|
| Instance | One copy of a block description, placed inside another block under its own name. |
| Parameter | A number that a block description leaves open. Each instance fixes it when the chip is built. |
| Default value | The value a parameter takes when an instance passes none. |
| Top level | The outermost block of a chip. It holds every other instance. |
| Wrapper | A thin block around another block. It changes names, widths or the sense of a signal, and adds no behaviour. |
| Subsystem | A group of instances that is joined and tested together, then used as one block. |
Verilog writes a block description as a module. Each input or output of a module is a port. The tree of instances is the hierarchy of the chip.
The sense of a signal says which level means "active". A reset that is active at 0 and one that is active at 1 differ in sense.
One Picture: The Tree
- Bus
- Processor
- Memory
- Peripheral
- Clock / reset
- The top level
The top of the tree is the chip. It contains instances and the wires between them.
- Four groups
Each group is a subsystem: blocks that are joined and tested together, then used as one block.
- Instances inside a group
UART0 and GPIO are instances inside the device group. Each has exactly one parent.
- A wrapper
The SRAM sits inside a wrapper. The wrapper gives it the port names that the bus expects.
Read the diagram as text
- ap_soc: the top level: instances and wires, no logic of its own
- Processor group: ap_rv32, with its timer and its interrupt controller
- Memory group: Boot ROM and SRAM
- Device group: the bridge, UART0, GPIO and five more devices
- Chip services: clock and reset, power control, debug, pads
- UART0: one instance inside the device group
- GPIO: another instance, with the same parent
- SRAM in its wrapper: a wrapper around a memory block
- ap_soc → Processor group: holds
- ap_soc → Memory group: holds
- ap_soc → Device group: holds
- ap_soc → Chip services: holds
- Device group → UART0: holds
- Device group → GPIO: holds
- Memory group → SRAM in its wrapper: holds
The grouping into four is a choice of this page. A real team draws its groups along the lines of its teams.
Read any signal name of a chip against this tree. The name u_fast.u_ip.count in the lab below is a path: instance, then instance, then signal.
The Smallest Example, Worked by Hand: How Many Bits
A timer counts clock edges and raises a signal named done when its count reaches a limit. Its counter has WIDTH bits, and WIDTH is a parameter.
A counter of WIDTH bits counts from 0 to one less than two to the power WIDTH. Then it wraps to 0. So the limit must fit in the counter.
| Timer | Limit | Largest count with 4 bits | Bits needed | Does 4 bits work? |
|---|---|---|---|---|
| fast | 10 | 15 | 4 | yes |
| slow | 200 | 15 | 8 (largest count 255) | no |
| watch | 20 | 15 | 5 (largest count 31) | no |
The description sets a default value of 4 for WIDTH. An instance that passes nothing is built with 4 bits. For the first timer that is right. For the other two it is wrong.
The Rules
Rule 1: An instance is one copy, with its own state.
Two instances of one module share a description and nothing else. Each has its own name in the hierarchy.
Rule 2: A parameter is fixed when the chip is built.
It changes the circuit itself, such as the number of flip-flops. Software cannot change it later, as it can change a register.
Rule 3: An instance that passes no value gets the default.
That is legal, so no tool objects. The default must be safe, or every instance must pass a value.
Rule 4: A wrapper changes how a block connects, never what it does.
Names, widths and the sense of a signal belong in the wrapper. The block inside stays as delivered.
Rule 5: Every instance has one parent.
The top level is the root of the tree. A subsystem is a branch that can be tested alone.
Sources for These Rules
Parameters and their default values: IEEE Std 1800-2023, clause 6.20. Passing a value to an instance: clause 23.10. Instances: clause 23.3.2.
Wrappers and subsystems are common practice. They are not taken from a library source.
The four groups of ap_soc are a choice of this page.
Now Run It: Three Timers from One Description
The lab at the end of this page holds one timer module, one wrapper and a top level. The top level makes three instances, with the limits of the table above.
| Instance | WIDTH passed | Limit |
|---|---|---|
| u_fast | 4 | 10 |
| u_slow | 8 | 200 |
| u_watch | nothing, so the default of 4 | 20 |
u_fast counter bits=4 limit=10 done at edge 11
u_slow counter bits=8 limit=200 done at edge 201
u_watch counter bits=4 limit=20 not done after 260 edges
timers done: 2 of 3Rule 1 at work: three instances, three separate counters. The path u_fast.u_ip.count names one of them. u_fast is the wrapper, and u_ip is the timer inside it.
Rule 2 at work: the first two rows show counters of 4 and 8 bits. One description built two different circuits.
Rule 3 at work: u_watch has 4 bits. It counts to 15, wraps to 0 and never meets 20. The simulator printed no warning.
Why edge 11 and not 10? The count reaches 10 after ten edges. The signal done is a flip-flop, and it takes that fact on the next edge.
Rule 4 at work: this chip names its clock pclk and uses a reset that is active at 0. The timer wants clk and a reset active at 1. The wrapper joins the two, and the timer is not edited.
The lab leaves things out. A real wrapper may also hold registers on a bus. S3.15 builds one around a memory.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| One module with a parameter | A separate copy of the RTL for each size | One description to test and repair. A wrong value fails without a warning. |
| A wrapper around the block | Edit the delivered block | A new version of the block drops in unchanged. One more level in every signal path. |
| Group instances into subsystems | Every instance directly in the top level | Each group can be tested alone, by its own team. The boundaries must be agreed early. |
The Trap: The Parameter Nobody Passed
Look at u_watch again. Its line in the top level is shorter than the other two, and it compiles. A test that only checks u_fast passes. The fault ships.
On a chip, u_watch could be the timer that must restart a stuck system. It would be found on the day it was needed.
Pass every parameter
Many teams require each instance to name every parameter, even when the default would do.
Print what was built
The lab prints the bits of each counter. One line for each instance makes a wrong default visible.
Test each instance
A test of the module alone cannot see how the top level configured it.
At Scale
This section looks ahead. The lab has three instances. The phone chip of module S10 has 200, in six subsystems.
One team for each subsystem
Each of the six subsystems has one team that joins and tests it. The chip team then joins six blocks, not 200.
A top level written by a tool
Nobody types 200 instances by hand. A table lists every instance, parameter and wire, and a tool writes the top level from it.
The table is the design
A wrong row builds a wrong chip, without a warning. S10.12 shows how teams check such a table.
Try It
Run the lab. Find the row of u_watch, and say why it differs from the other two.
Pass a WIDTH of 5 to u_watch. Predict the edge of its done before you run it.
Change the default value in ip_timer to 16 and remove every WIDTH from the top level. Count the flip-flops you have added.
u_fast counter bits=4 limit=10 done at edge 11 u_slow counter bits=8 limit=200 done at edge 201 u_watch counter bits=4 limit=20 not done after 260 edges timers done: 2 of 3Check Yourself
Common Mistakes
Wrong Leave a parameter out because the block compiles.
The default value is used, and no tool objects.
Fix Pass every parameter of every instance, and print what was built.
Wrong Edit the delivered block to rename its reset.
The next version of the block will arrive without your edit.
Fix Put the change in a wrapper and leave the block as delivered.
Wrong Treat a parameter like a register.
A parameter changes the circuit and is fixed when the chip is built.
Fix Use a register for anything software must change while the chip runs.
Remember
- A module is a description; each instance is one copy with its own state.
- A parameter is fixed for each instance when the chip is built.
- A parameter that is not passed takes its default, without a warning.
- A wrapper changes names, widths and sense, and never behaviour.
- The hierarchy is a tree; a subsystem is a branch that is tested alone.