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.

Five questions this page answers
Question
1What is the difference between a block description and an instance?
2What is a parameter, and when is its value fixed?
3What happens when an instance passes no value for a parameter?
4What is a wrapper allowed to change?
5What 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

New words on this page
WordMeaning
InstanceOne copy of a block description, placed inside another block under its own name.
ParameterA number that a block description leaves open. Each instance fixes it when the chip is built.
Default valueThe value a parameter takes when an instance passes none.
Top levelThe outermost block of a chip. It holds every other instance.
WrapperA thin block around another block. It changes names, widths or the sense of a signal, and adds no behaviour.
SubsystemA 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

ap_soc as a Tree of BlocksStep from the top level down. Each box on the right is one group of blocks.
  • Bus
  • Processor
  • Memory
  • Peripheral
  • Clock / reset
ap_soc as a Tree of BlocksStep from the top level down. Each box on the right is one group of blocks. component ap_soc the top level:instances and wires,no logic of its own component Processor group ap_rv32, with itstimer and itsinterrupt controller component Memory group Boot ROM and SRAM component Device group the bridge, UART0,GPIO and five moredevices component Chip services clock and reset,power control, debug,pads component UART0 one instance insidethe device group component GPIO another instance,with the same parent component SRAM in itswrapper a wrapper around amemory block holdsholdsholdsholdsholdsholdsholds
  1. component ap_socthe top level: instances and wires, no logic of its own
    • holds → Processor group
    • holds → Memory group
    • holds → Device group
    • holds → Chip services
  2. component Processor groupap_rv32, with its timer and its interrupt controller
  3. component Memory groupBoot ROM and SRAM
    • holds → SRAM in its wrapper
  4. component Device groupthe bridge, UART0, GPIO and five more devices
    • holds → UART0
    • holds → GPIO
  5. component Chip servicesclock and reset, power control, debug, pads
  6. component UART0one instance inside the device group
  7. component GPIOanother instance, with the same parent
  8. component SRAM in its wrappera wrapper around a memory block
  1. The top level

    The top of the tree is the chip. It contains instances and the wires between them.

  2. Four groups

    Each group is a subsystem: blocks that are joined and tested together, then used as one block.

  3. Instances inside a group

    UART0 and GPIO are instances inside the device group. Each has exactly one parent.

  4. 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.

Three timers, three limits
TimerLimitLargest count with 4 bitsBits neededDoes 4 bits work?
fast10154yes
slow200158 (largest count 255)no
watch20155 (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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

What the top level passes
InstanceWIDTH passedLimit
u_fast410
u_slow8200
u_watchnothing, so the default of 420
Recorded from the lab on Icarus. The run lasts 260 clock edges after reset.
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 3

Rule 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 choiceThe alternativeWhat the choice buys, and costs
One module with a parameterA separate copy of the RTL for each sizeOne description to test and repair. A wrong value fails without a warning.
A wrapper around the blockEdit the delivered blockA new version of the block drops in unchanged. One more level in every signal path.
Group instances into subsystemsEvery instance directly in the top levelEach 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.

  1. Pass every parameter

    Many teams require each instance to name every parameter, even when the default would do.

  2. Print what was built

    The lab prints the bits of each counter. One line for each instance makes a wrong default visible.

  3. Test each instance

    A test of the module alone cannot see how the top level configured it.

At Scale

This page3 instances
A phone chip200 instances, 6 subsystems

This section looks ahead. The lab has three instances. The phone chip of module S10 has 200, in six subsystems.

  1. 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.

  2. 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.

  3. 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.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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 3

Check Yourself

Predict the outputThe top level now passes a WIDTH of 5 to u_watch. What is the last line the lab prints?
// One timer block, used three times. Each use is an instance with its own parameter value.
// ---- The IP: a timer. WIDTH is a parameter: the number of bits of its counter. ----
module ip_timer #(parameter WIDTH = 4) (
  input  logic        clk,
  input  logic        rst,        // reset, active at 1
  input  logic [15:0] limit,      // raise done when the counter reaches this number
  output logic        done
);
  logic [WIDTH-1:0] count;
  always @(posedge clk)
    if (rst) begin count <= 0; done <= 0; end
    else begin
      count <= count + 1'b1;
      if (count == limit) done <= 1;    // a counter of WIDTH bits can never reach a larger limit
    end
endmodule

// ---- The wrapper: it holds the IP and changes only names and the sense of the reset ----
module timer_wrap #(parameter WIDTH = 4) (
  input  logic        pclk,       // the clock name this chip uses
  input  logic        presetn,    // this chip's reset is active at 0
  input  logic [15:0] limit,
  output logic        done
);
  ip_timer #(.WIDTH(WIDTH)) u_ip (.clk(pclk), .rst(!presetn), .limit(limit), .done(done));
endmodule

// ---- The top level: three instances and the wires between them ----
module tb;
  logic pclk = 0;
  always #5 pclk = ~pclk;
  logic presetn = 0;
  wire  done_fast, done_slow, done_watch;

  timer_wrap #(.WIDTH(4)) u_fast  (.pclk(pclk), .presetn(presetn), .limit(16'd10),  .done(done_fast));
  timer_wrap #(.WIDTH(8)) u_slow  (.pclk(pclk), .presetn(presetn), .limit(16'd200), .done(done_slow));
  timer_wrap #(.WIDTH(5)) u_watch (.pclk(pclk), .presetn(presetn), .limit(16'd20),  .done(done_watch));

  int edge_no = 0;
  always @(posedge pclk) if (presetn) edge_no++;
  always @(posedge done_fast)  $display("u_fast  counter bits=%0d limit=10  done at edge %0d", $bits(u_fast.u_ip.count),  edge_no);
  always @(posedge done_slow)  $display("u_slow  counter bits=%0d limit=200 done at edge %0d", $bits(u_slow.u_ip.count),  edge_no);
  always @(posedge done_watch) $display("u_watch counter bits=%0d limit=20  done at edge %0d", $bits(u_watch.u_ip.count), edge_no);

  initial begin
    repeat (2) @(posedge pclk);
    #1 presetn = 1;                 // release the reset
    repeat (260) @(posedge pclk);
    #1;
    if (!done_watch) $display("u_watch counter bits=%0d limit=20  not done after %0d edges", $bits(u_watch.u_ip.count), edge_no);
    $display("timers done: %0d of 3", int'(done_fast) + int'(done_slow) + int'(done_watch));
    $finish;                        // $finish ends the simulation
  end
endmodule
ConceptWhat do two instances of one module share?
ConceptWhen is the value of a parameter fixed?
ConceptAn instance passes no value for WIDTH. What happens?
ConceptWhich change belongs in a wrapper?

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.

Practice

Report a problem with this page