W4.1.2 Loop over the Domains

MediumImplementOpenPA + Icarus · serverReview the topic

Three switchable units need the same isolation strategy. Write it once, as a Tcl proc, and call it from a loop.

Hardware context: A power controller with a switchable core, and a hub with three switchable units. Write power intent that tools read the same way, by hand or from a Tcl loop.

The design hub has three units, u_cpu, u_dsp and u_npu, each in its own switchable domain. The given file hub_base.upf creates the domains, the supplies and the switches, and the starter loads it.

Add isolation for the outputs of each unit. Write the strategy once, inside a proc, and call the proc from a foreach loop over the three units.

One enable is different. A name that ends in _n is active low, so its isolation is on while the signal is 0. The others are active high.

Full specification
UnitDomainIsolation enable
u_cpuPD_CPUiso_cpu
u_dspPD_DSPiso_dsp
u_npuPD_NPUiso_npu_n
Every strategyValue
Applies tothe outputs of the unit's domain
Clamp value0
Isolation supplythe always-on nets VDD_N and VSS_N
Locationparent (the cells sit in the always-on top)
Senselow for an enable whose name ends in _n, high otherwise
RuleWhat the grader checks
Same intentDomains, supplies and isolation equal the reference file's. The strategy names are free.
Written as a loopThe file uses proc and foreach, and one set_isolation command runs repeatedly inside the proc and foreach loop.
Safe TclNo refused command: OpenPA runs no exec, source or file access.
The scenarios passA public run, and three hidden runs that switch units off.

What the Grader Checks

OpenPA reads your file. A refusal ends the check with OpenPA's message and line. Otherwise every row below must pass.

RowRule
Switch u_cpu off while the other two runpublic scenario: Run shows it
Switch u_npu offhidden scenario
Switch u_dsp off, then back onhidden scenario
All three units offhidden scenario
Intent equals the referencethe domain of every instance; supply sets and switches; isolation cells (clamp, enable, sense, supply)
Tcl structureuses foreach; uses proc; one set_isolation command executed repeatedly inside the required Tcl constructs

The Design

The power-unaware RTL your UPF describes (top hub). Open a file to read it.

hub.sv
// hub: an always-on top with three switchable units. Power-unaware RTL: no supply, no isolation cell.
module hub (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       en,
  input  logic [7:0] d,
  input  logic       pwr_cpu,
  input  logic       pwr_dsp,
  input  logic       pwr_npu,
  input  logic       iso_cpu,
  input  logic       iso_dsp,
  input  logic       iso_npu_n,
  output logic [7:0] q_cpu,
  output logic [7:0] q_dsp,
  output logic [7:0] q_npu,
  output logic [7:0] seen
);
  unit u_cpu (.clk(clk), .rst_n(rst_n), .en(en), .d(d),         .q(q_cpu));
  unit u_dsp (.clk(clk), .rst_n(rst_n), .en(en), .d(d + 8'd1),  .q(q_dsp));
  unit u_npu (.clk(clk), .rst_n(rst_n), .en(en), .d(d + 8'd2),  .q(q_npu));
  // Always on: the OR of the three results, registered.
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) seen <= '0;
    else        seen <= q_cpu | q_dsp | q_npu;
endmodule
unit.sv
// unit: an 8-bit accumulator. Power-unaware RTL.
module unit (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       en,
  input  logic [7:0] d,
  output logic [7:0] q
);
  logic [7:0] acc;
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n)  acc <= '0;
    else if (en) acc <= acc + d;
  assign q = acc;
endmodule

Given UPF Files

Your file may load these with load_upf. The grader uses the same text.

hub_base.upf
upf_version 4.0
set_design_top hub

# Always-on top domain and its supply ports
create_power_domain PD_TOP -include_scope
create_supply_port VDD -direction in
create_supply_port VSS -direction in
create_supply_net VDD_N
create_supply_net VSS_N
connect_supply_net VDD_N -ports {VDD}
connect_supply_net VSS_N -ports {VSS}
set_domain_supply_net PD_TOP -primary_power_net VDD_N -primary_ground_net VSS_N

# One switchable domain per unit
create_power_domain PD_CPU -elements {u_cpu}
create_supply_net VDD_CPU
create_power_switch SW_CPU -domain PD_CPU -input_supply_port {i VDD_N} -output_supply_port {o VDD_CPU} \
    -control_port {c pwr_cpu} -on_state {on i {c}} -off_state {off {!c}}
set_domain_supply_net PD_CPU -primary_power_net VDD_CPU -primary_ground_net VSS_N

create_power_domain PD_DSP -elements {u_dsp}
create_supply_net VDD_DSP
create_power_switch SW_DSP -domain PD_DSP -input_supply_port {i VDD_N} -output_supply_port {o VDD_DSP} \
    -control_port {c pwr_dsp} -on_state {on i {c}} -off_state {off {!c}}
set_domain_supply_net PD_DSP -primary_power_net VDD_DSP -primary_ground_net VSS_N

create_power_domain PD_NPU -elements {u_npu}
create_supply_net VDD_NPU
create_power_switch SW_NPU -domain PD_NPU -input_supply_port {i VDD_N} -output_supply_port {o VDD_NPU} \
    -control_port {c pwr_npu} -on_state {on i {c}} -off_state {off {!c}}
set_domain_supply_net PD_NPU -primary_power_net VDD_NPU -primary_ground_net VSS_N

The Public Scenario

Switch u_cpu off while the other two run. Run checks its output and shows the expected lines and any failure.

tb.sv (public scenario)
`timescale 1ns/1ps
module tb;
  import UPF::*;
  logic clk = 0, rst_n = 0, en = 0;
  logic pwr_cpu = 1, pwr_dsp = 1, pwr_npu = 1, iso_cpu = 0, iso_dsp = 0, iso_npu_n = 1;
  logic [7:0] d = 0;
  wire [7:0] q_cpu, q_dsp, q_npu, seen;
  hub dut (.*);
  always #5 clk = ~clk;
  task show(string what);
    $display("%-10s q_cpu=%0h q_dsp=%0h q_npu=%0h seen=%0h", what, q_cpu, q_dsp, q_npu, seen);
  endtask
  task beat(input logic [7:0] x); en = 1; d = x; @(posedge clk); #1 en = 0; endtask
  initial begin
    void'(supply_on("VDD", 1.0));
    void'(supply_on("VSS", 0.0));
    @(posedge clk); #1 rst_n = 1;
    beat(8'h10); beat(8'h10); show("run");
    iso_cpu = 1; #1 pwr_cpu = 0; #1;
    beat(8'h01); show("cpu off");
    #20 $finish;
  end
endmodule

Examples

Example 1

The Starter: Three Unprotected Outputs
Input
The starter, read by OpenPA (crossings out of the units)
OpenPA reports (recorded)
Crossings
  u_cpu/q [PD_CPU] -> logic in hub [PD_TOP]: no isolation
  u_cpu/q [PD_CPU] -> hub output q_cpu [PD_TOP]: no isolation
  u_dsp/q [PD_DSP] -> logic in hub [PD_TOP]: no isolation
  u_dsp/q [PD_DSP] -> hub output q_dsp [PD_TOP]: no isolation
  u_npu/q [PD_NPU] -> logic in hub [PD_TOP]: no isolation
  u_npu/q [PD_NPU] -> hub output q_npu [PD_TOP]: no isolation

Each unit's output crosses into the always-on top with no isolation. That is what your proc must fix, three times.

Example 2

One Strategy Written by Hand
Input
set_isolation ISO_CPU -domain PD_CPU -applies_to outputs -clamp_value 0 -isolation_power_net VDD_N -isolation_ground_net VSS_N -isolation_signal iso_cpu -isolation_sense high -location parent
OpenPA reports (recorded)
Crossings
  u_cpu/q [PD_CPU] -> logic in hub [PD_TOP]: isolation ISO_CPU
  u_cpu/q [PD_CPU] -> hub output q_cpu [PD_TOP]: isolation ISO_CPU
  u_dsp/q [PD_DSP] -> logic in hub [PD_TOP]: no isolation
  u_dsp/q [PD_DSP] -> hub output q_dsp [PD_TOP]: no isolation
  u_npu/q [PD_NPU] -> logic in hub [PD_TOP]: no isolation
  u_npu/q [PD_NPU] -> hub output q_npu [PD_TOP]: no isolation

One hand-written line isolates u_cpu only. The values follow the statement's table; the grader also wants proc and foreach.

Example 3

The Sample Run: Switch u_cpu off While the Other Two Run
Input
The reference file, run on the public scenario
The bench prints (recorded)
run        q_cpu=20 q_dsp=22 q_npu=24 seen=13
cpu off    q_cpu=0 q_dsp=24 q_npu=27 seen=26

u_cpu is switched off with its enable raised first. q_cpu reads the clamp value 0, while u_dsp and u_npu keep counting.

Constraints and Contract

  • Submit the whole UPF file. Keep the line that loads hub_base.upf; the grader gives OpenPA the same hub_base.upf you see.
  • The always-on top domain PD_TOP gets no isolation strategy.
  • The bench drives the supply ports VDD and VSS, the switch controls and the isolation enables.

Hints

Hint 1

A Tcl array or a list of pairs can map each unit to its enable signal.

Hint 2

Inside a proc, string toupper turns cpu into CPU, and string match tests a name against a pattern.

Hint 3

Use Run with a small change first: one unit, then the loop.

What the grader checks: OpenPA reads your file. The grader compares domains, supplies and isolation with the reference file. It also checks that one strategy command runs repeatedly inside proc and foreach. Then it runs a public and three hidden power scenarios.

Run checks the public scenario only and never accepts. Submit runs every row. OpenPA is our open power-aware tool: it reads the UPF, writes a power-aware copy of the RTL, and Icarus runs that copy.

See all 2 problems on this path
Your UPF file UPFSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs
Not run yet

Run checks the public scenario. Submit checks every row in the description.

OpenPA + Icarus · server