Power at Chip Level: Domains, Isolation and Always-On Logic

A chip saves the most power by switching parts of itself off. A part with no supply drives its outputs to nothing in particular. Its neighbours are still awake, and still reading those wires.

You Will Be Able To

  • Say what a power domain is, and why stopping a clock is not enough.
  • Explain what an isolation cell does, where it sits and which supply feeds it.
  • Put the steps of a power-down and a power-up in order, and name what must stay on.
Lesson
S5.7
Time
26 min
Runs on
Your browser
Check
6 questions

A sensor node spends hours with its timer block switched off. Now and then it starts up for an alarm that was never set. The timer had no power at that moment. So who raised the request?

Before You Start

You need Reset Domain Crossing: the order drain, isolate, reset. This page uses the same order at a border of power. You need Dividers and Clock Gates: a clock gate stops the clock of an idle block.

The block that sleeps here is a timer, and the wire that matters is its service request. The Anatomy of a Peripheral shows what a service request is. Read it first if that is new to you.

The lab uses a file in a standard format called UPF. It says which block has which supply. This page does not teach that format. The Low Power track does: start at UPF in One Picture. You can follow this page without it.

Five questions this page answers
Question
1Why is stopping the clock of an idle block not enough to save its power?
2What does an isolation cell do, and which side powers it?
3In which order do the clamp and the supply change, going down and coming up?
4What happens to the value in a flip-flop whose supply is switched off?
5Which parts of a chip must stay on while the rest sleeps?

The Idea: Switch It off, and Guard the Border

A block with a stopped clock still draws current. Every transistor lets a little current through while it is off. This is leakage, and on a chip with millions of idle gates it adds up. The only way to stop it is to take the supply away.

So a chip is cut into power domains. A power domain is a group of logic that shares one supply and is switched on and off as one. The processor may be one domain, a group of peripherals another.

Switching a domain off makes a new problem at its border. A gate with no supply drives no level. Its output drifts to some voltage between 0 and 1. A neighbour that is still on reads that wire. It may see a 1 that nobody sent: a request, a write, a call to wake up.

The guard is a small gate called an isolation cell. It sits in every wire that leaves a domain which can be off. It is powered by the side that stays on. It has an enable. While the enable is 1, the cell ignores its input and drives a fixed, harmless value. To hold a wire in this way is to clamp it. For a request wire that value is 0, which means "no request".

Two more things follow. The value in a flip-flop is lost when its supply goes. After power returns the block must be reset before anyone trusts it. And some logic can never sleep. It is the controller that does the switching, the isolation cells, and the path by which a wake event comes in. That part is the always-on domain.

New Words

New words on this page
WordMeaning
LeakageThe current that a transistor lets through while it is switched off. It flows whether the clock runs or not.
Power domainA group of logic that shares one supply and is switched on and off as one.
Power switchLarge transistors between a supply and a power domain. Closed, the domain is on. Open, it is off.
Always-on domainThe power domain that keeps its supply for as long as the chip has power.
Isolation cellA gate in a wire that leaves a power domain. On command it holds the wire at a fixed value.
ClampTo hold a wire at a fixed value, whatever drives it. An isolation cell is often called a clamp.
Clamp valueThe value that an isolation cell drives while it clamps: the one that means "nothing is happening".
Isolation enableThe signal that tells an isolation cell to clamp.
Power controllerThe always-on logic that drives the power switches and the isolation enables, in the right order.
Wake eventSomething that happens while a domain sleeps and means: switch it on again.
Wake sourceSomething that can cause a wake event: a button, or the alarm of a clock that stays on.
Power intentA separate file that states the power domains, their supplies and their isolation cells. Its standard format is called UPF.
OpenPAThe tool that reads the power intent and adds power behaviour to our simulation.

One Picture: A Switched Domain and Its Border

One Switched Domain and What Stays on Around ItStep through the picture. It starts with one block that can be switched off and ends with everything that must stay on.
  • Power
  • Peripheral
  • Control / FSM
  • Processor
  • Pads
One Switched Domain and What Stays On Around ItStep through the picture. It starts with one block that can be switched off and ends with everything that must stay on. component Power controller always on: it decideswho sleeps component Power switch connects or cuts thesupply of the timer component Timer the switched domain component Isolation cell always on: holds thewire at 0 when told to component Receiver always on: collectsthe requests ofdevices component Wake pin a button on theboard, on analways-on input on or offsupplyrequestsafe requestisolation enablewake event
  1. component Power controlleralways on: it decides who sleeps
    • on or off → Power switch
    • isolation enable → Isolation cell
  2. component Power switchconnects or cuts the supply of the timer
    • supply → Timer
  3. component Timerthe switched domain
    • request → Isolation cell
  4. component Receiveralways on: collects the requests of devices
  5. component Isolation cellalways on: holds the wire at 0 when told to
    • safe request → Receiver
  6. component Wake pina button on the board, on an always-on input
    • wake event → Power controller
  1. A block with a switch on its supply

    The timer gets its supply through a power switch. A power controller opens the switch when the timer is not needed. The timer then uses no power at all.

  2. Its output still goes somewhere

    The request wire of the timer leaves the domain. It ends at a receiver that is still powered and still listening.

  3. An isolation cell on the border

    A gate sits in that wire, on the side that stays on. While its enable is 1 it ignores the timer and gives the receiver a steady 0.

  4. One controller, two orders

    The power controller drives both the isolation enable and the switch. Going down: clamp first, then switch off. Coming up: switch on, reset the timer, then open the clamp.

  5. The way back

    A sleeping timer cannot ask to be woken. A wake event comes from outside: here a button. Its whole path to the controller is always on.

  6. What must stay on

    Three things never lose power: the controller, the isolation cell with its receiver, and the wake path. Everything else may sleep.

Read the diagram as text
  • Power controller: always on: it decides who sleeps
  • Power switch: connects or cuts the supply of the timer
  • Timer: the switched domain
  • Isolation cell: always on: holds the wire at 0 when told to
  • Receiver: always on: collects the requests of devices
  • Wake pin: a button on the board, on an always-on input
  • Power controller → Power switch: on or off
  • Power switch → Timer: supply
  • Timer → Isolation cell: request
  • Isolation cell → Receiver: safe request
  • Power controller → Isolation cell: isolation enable
  • Wake pin → Power controller: wake event

The power plan of this page. The lab builds the timer, its isolation cell and the receiver wire. The switch, the controller and the wake pin are played by test code or are drawn only.

The Smallest Example, Worked by Hand

One timer sits in a switched domain. Its request wire goes through an isolation cell to an always-on receiver. The clamp value is 0. The timer has raised its request: the wire is 1. Now the power controller puts the timer to sleep and wakes it again.

One sleep of the timer domain, by hand
StepIsolation enableSupply of the timerRequest inside the timerRequest at the receiver
1. Before0on11: the cell passes it
2. Clamp1on10: the clamp value
3. Switch off1offunknown0
4. Switch on1onunknown: not reset yet0
5. Reset the timer1on00
6. Open the clamp0on00: the real wire again

Read the last column from top to bottom. After step 1 the receiver sees only clean values. The unknown values of steps 3 and 4 never reach it.

Now swap two steps: switch off before the clamp. At that moment the enable is still 0, so the cell passes the unknown value straight to the receiver. Swap the last two steps and the same thing happens on the way up.

One more thing is in the table. The request that was 1 before the sleep is 0 after it. The clamp protected the receiver. It did not remember anything.

One Sleep of the Timer Domain, Step by StepStep through the samples. Each column is one step of the sequence, in the order of the run.
0123456steprequest setclamp onsupply offsupply ontimer resetclamp offrequest setisolation enablerequest inside the timerrequest at the receiver
Scroll horizontally ↔
  1. Step 0

    The timer is on and has raised its request. The receiver sees it.

  2. Step 1

    The isolation cell is told to clamp. The timer still drives 1. The receiver already sees 0.

  3. Step 2

    The supply of the timer is switched off. Inside, the value is lost: x. The receiver still sees 0.

  4. Step 3

    The supply is back. The flip-flop of the timer holds no known value yet.

  5. Step 4

    A reset gives the timer a known value again: 0.

  6. Step 5

    Only now the clamp is opened. The receiver sees the real wire, and it is 0.

  7. Step 6

    A new request passes through, as before the sleep.

Drawn from the seven sample rows of the lab. x is the mark of the simulator for a value that is not known.

The Rules

  1. Rule 1: A power domain is switched as one.

    All of its logic loses its values together when the supply goes.

  2. Rule 2: Every wire from a domain that can be off to one that is on passes an isolation cell.

    The receiver must never read a wire that nothing drives.

  3. Rule 3: An isolation cell is powered by the side that stays on.

    A clamp on the supply of the sleeping domain would sleep with it.

  4. Rule 4: The clamp value is the value that means "nothing".

    For an active-high request that is 0.

  5. Rule 5: Going down: clamp first, then switch off.

    Before that, drain the work in progress, as for a local reset.

  6. Rule 6: Coming up: switch on, reset, then open the clamp.

    A domain is trusted only after its reset.

  7. Rule 7: The controller, the isolation cells and the whole wake path are always on.

    A wake event must find a powered path from the pin to the controller.

How a power-intent file states a domain and an isolation cell is taught in the Low Power track: Power Domains and Isolation.

Sources for These Rules

Leakage as static power: Weste and Harris, CMOS VLSI Design, fourth edition, section 5.3. Switching a block off, isolation of its outputs and the loss of its state: section 5.3.2.

Power domain, isolation cell and clamp value as terms: Mehta, ASIC/SoC Functional Design Verification, sections 9.4.1 and 9.5.8.1.

The standard for power intent is IEEE 1801-2024: clause 6.21 for power domains, clause 6.48 for isolation, clause 9.5.3 for what a simulator does to logic without supply.

The orders of rules 5 and 6 are the two sequences that our tool checks and names in its output. Which blocks are always on is a choice of our chip.

Now Run It

The lab at the end of this page has the timer of the hand example in a switched domain. An isolation cell guards its request. Test code plays the power controller. Lines that start with OPENPA come from the power tool. A table below the output explains each kind.

Printed by the lab on Icarus, with power behaviour added by OpenPA. Rows two to eight are samples taken by the test code.
OPENPA-INFO corruption=x seed=1
request set isolate=0 raw=1 receiver=1
clamp on isolate=1 raw=1 receiver=0
supply off isolate=1 raw=x receiver=0
supply on isolate=1 raw=x receiver=0
timer reset isolate=1 raw=0 receiver=0
clamp off isolate=0 raw=0 receiver=0
request set isolate=0 raw=1 receiver=1
OPENPA-SUMMARY D1=0 D2=0 D3=0 D4=0 D5=0 D6=0 D7=0 D8=0 D9=0 D10=0 D11=0 D12=0 D13=0 D14=0
OPENPA-COVER sequence D1 QUIET: PD_PER isolated before power-down 1
OPENPA-COVER sequence D2/D7 QUIET: isolation released only after PD_PER was back and reset 1
OPENPA-COVER-SUMMARY states=0/0 declared_transitions=0/0 sequences=2/2
Lines printed by the power tool
LineMeaning
OPENPA-INFO corruption=xHow the tool marks a value whose supply is off: as x. The seed belongs to another setting, in which lost values become random bits. This run does not use it.
OPENPA-CHECKOne of the checks of the tool has found a fault, at this moment of the run. The number after D says which check.
OPENPA-SUMMARYHow often each of the 14 checks fired in the whole run. All zeros: no fault found.
OPENPA-COVER sequenceDid the run show this good sequence at least once? The last number is 1 for yes and 0 for no.
OPENPA-COVER-SUMMARYHow many of the good sequences the run showed. The two counts of 0/0 are for named power states. This lab declares none.

Every line that starts with OPENPA comes from OpenPA. The numbers D1 to D14 are the names of the checks inside this tool. They are not part of any standard.

Rules 2 and 4 at work, in the row "clamp on". The timer still drives raw=1. The receiver already reads 0.

Rule 1 at work, in the row "supply off": raw=x. The value in the timer is lost. Rule 3 keeps the receiver at 0 in the same row. The cell is on the always-on supply.

Rule 6 at work, in the next three rows. With the supply back, raw is still x. The reset makes it 0. Only then is the clamp opened.

The tool agrees. Its summary line shows 0 for all of its checks. Its two "sequence" lines end in 1: the run showed both good orders, down and up.

This lab leaves things out. The power switch is one statement of test code, with no ramp of the supply. A real supply takes time to come up, and a real output drifts slowly. The x of a simulator stands for both. The wake pin and the power controller are not built: rule 7 is drawn, not run.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
Switch idle blocks offOnly stop their clocksLeakage stops too. State is lost, and going down and up takes time and energy.
An isolation cell at the borderTrust every receiver to ignore a sleeping senderOne small gate guards each wire. Every such wire must be found, and its safe value chosen.
The cell on the side that stays onThe cell inside the sleeping domainThe clamp keeps working through the sleep. The always-on supply must reach the border.
A small always-on domainKeep much of the chip on, to be safeLittle leakage in sleep. Every wake source needs a checked path of always-on logic.

The Trap: The Alarm That Nobody Set

Back to the sensor node. Its timer had an isolation cell, and its power controller drove the enable. The order was wrong by one step: the switch opened first and the clamp closed a moment later.

In that moment the request wire had no driver. Most nights it drifted low. Some nights it drifted high for long enough, and the receiver took it as a request. The node woke up for an alarm that nobody had set.

A second trap is on the wake path. The button pin has an always-on input cell, and the controller is always on. Between them the signal passes one mux that sits in the sleeping domain. The button now works only while the chip is awake.

A third trap is at the end. The supply is back, the clamp is opened, and the reset comes a moment later. For that moment the receiver reads a flip-flop that holds anything.

At Scale

This page2 domains, 1 isolation cell
A phone chipdozens of domains, thousands of cells

This section looks ahead. One timer and one wire become dozens of domains and many thousands of border wires.

  1. The tool places the cells

    Nobody adds isolation cells by hand. The power intent states a rule, and tools add a cell to every wire that the rule covers.

  2. State that must survive

    A special flip-flop can keep its value on a small always-on supply while the rest of its domain is off. Retention is taught in the Low Power track.

  3. Different voltages

    Two domains may run at different voltages. A wire between them then needs a cell that changes the level, as well as a clamp.

  4. Which mode, and when

    A chip has several depths of sleep. The next page works out which one pays.

Try It

Run the lab. Test code plays the power controller: it sets the isolation enable and switches the supply of the timer, step by step.

Move the line "isolate=0" to just after the supply comes back, before the reset. Which row of the receiver changes, and which tool line?

Leave "isolate" at 0 for the whole run. The quiz below asks what the receiver sees.

Names Printed by the Lab
NameMeaning
isolateThe isolation enable. 1 tells the isolation cell to clamp.
rawThe request inside the timer, before the isolation cell.
receiverThe same request after the isolation cell, in the always-on domain.
xThe mark of the simulator for a value that is not known.
PD_PERThe name that the power-intent file gives the switched domain of the timer.
PD_AONThe name that it gives the always-on domain.
QUIETThe name that it gives its one isolation rule.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: OPENPA-INFO corruption=x seed=1 request set isolate=0 raw=1 receiver=1 clamp on isolate=1 raw=1 receiver=0 supply off isolate=1 raw=x receiver=0 supply on isolate=1 raw=x receiver=0 timer reset isolate=1 raw=0 receiver=0 clamp off isolate=0 raw=0 receiver=0 request set isolate=0 raw=1 receiver=1 OPENPA-SUMMARY D1=0 D2=0 D3=0 D4=0 D5=0 D6=0 D7=0 D8=0 D9=0 D10=0 D11=0 D12=0 D13=0 D14=0 OPENPA-COVER sequence D1 QUIET: PD_PER isolated before power-down 1 OPENPA-COVER sequence D2/D7 QUIET: isolation released only after PD_PER was back and reset 1 OPENPA-COVER-SUMMARY states=0/0 declared_transitions=0/0 sequences=2/2
Read the power intent: ap_power_slice.upf
upf_version 4.0
set_design_top ap_power_slice
create_power_domain PD_AON -include_scope
create_power_domain PD_PER -elements {u_timer}
create_supply_port VA
create_supply_port VP
create_supply_port VG
create_supply_net NA
create_supply_net NP
create_supply_net NG
connect_supply_net NA -ports {VA}
connect_supply_net NP -ports {VP}
connect_supply_net NG -ports {VG}
create_supply_set AON -function {power NA} -function {ground NG}
create_supply_set PER -function {power NP} -function {ground NG}
associate_supply_set AON -handle PD_AON.primary
associate_supply_set PER -handle PD_PER.primary
set_isolation QUIET -domain PD_PER -applies_to outputs -clamp_value 0 -isolation_signal isolate -isolation_supply AON -location parent
Read the power-unaware RTL: ap_peripheral_irq.sv
// One register from the teaching slice of the timer. A write posts or clears
// a diagnostic request so the receiver can be observed across a rail change.
module ap_peripheral_irq (
  input logic pclk, reset_n, psel, penable, pwrite,
  input logic [31:0] paddr, pwdata,
  output logic irq
);
  always_ff @(posedge pclk or negedge reset_n) begin
    if (!reset_n)
      irq <= 1'b0;
    else if (psel && penable && pwrite && paddr == 32'h1000_2000)
      irq <= pwdata[0];
  end
endmodule

module ap_power_slice (
  input logic pclk, reset_n, psel, penable, pwrite, isolate,
  input logic [31:0] paddr, pwdata,
  output wire timer_irq
);
  ap_peripheral_irq u_timer (
    .pclk(pclk), .reset_n(reset_n), .psel(psel), .penable(penable),
    .pwrite(pwrite), .paddr(paddr), .pwdata(pwdata), .irq(timer_irq)
  );
endmodule
What UPF added: 29 objects

3 supply port, 3 supply net, 8 output corruption, 1 isolation cell, 2 supply set, 1 register corruption, 11 dynamic check.

ObjectWhereDetailRuleUPF line
Supply portVAap_power_slice.upf:5
Supply portVPap_power_slice.upf:6
Supply portVGap_power_slice.upf:7
Supply netNAap_power_slice.upf:5
Supply netNPap_power_slice.upf:6
Supply netNGap_power_slice.upf:7
Output corruptionu_timer/irqC2ap_power_slice.upf:4
Isolation cellu_timer/irqQUIET · clamp 0I1-I5ap_power_slice.upf:18
Output corruptionu_timer/paddrC2ap_power_slice.upf:3
Output corruptionu_timer/pclkC2ap_power_slice.upf:3
Output corruptionu_timer/penableC2ap_power_slice.upf:3
Output corruptionu_timer/pselC2ap_power_slice.upf:3
Output corruptionu_timer/pwdataC2ap_power_slice.upf:3
Output corruptionu_timer/pwriteC2ap_power_slice.upf:3
Output corruptionu_timer/reset_nC2ap_power_slice.upf:3
Supply setAONap_power_slice.upf:14
Supply setPERap_power_slice.upf:15
Register corruptionu_timer.irqC1ap_power_slice.upf:4
Dynamic checkD1/D2/D7/D6 QUIETD1, D2, D7, D6ap_power_slice.upf:18
Dynamic checkD9 crossing 1D9ap_power_slice.upf:4
Dynamic checkD9 crossing 2D9ap_power_slice.upf:3
Dynamic checkD9 crossing 3D9ap_power_slice.upf:3
Dynamic checkD9 crossing 4D9ap_power_slice.upf:3
Dynamic checkD9 crossing 5D9ap_power_slice.upf:3
Dynamic checkD9 crossing 6D9ap_power_slice.upf:3
Dynamic checkD9 crossing 7D9ap_power_slice.upf:3
Dynamic checkD9 crossing 8D9ap_power_slice.upf:3
Dynamic checkD11 PD_PER->PD_AOND11ap_power_slice.upf:4
Dynamic checkD11 PD_AON->PD_PERD11ap_power_slice.upf:3

OpenPA warnings:

  • no `timescale in the design and no --timescale: OpenPA messages print time in the design top's default unit
Read the power-aware copy that runs (generated by OpenPA 0.3.1): pa_ap_power_slice.sv
// pa_ap_power_slice.sv: power-aware copy of ap_power_slice, generated by OpenPA from ap_power_slice.upf.
// Do not edit: regenerate. Simulators: Icarus 12 (4-state, X corruption) or Verilator 5 with --timing (2-state).
// Build with -Wno-fatal on Verilator: forced registers raise MULTIDRIVEN warnings.
// ---------------------------------------------------------------------------
// package UPF: generated by OpenPA. Supply types, supply_on/supply_off and the power
// state of the design. Names starting with openpa_ are internal.
// ---------------------------------------------------------------------------
package UPF;
  typedef string upfStringT; typedef int upfIntegerT; typedef bit upfBooleanT; typedef logic upfLogicT; typedef real upfRealT; typedef int upfHandleT;
  typedef enum { OFF, FULL_ON, PARTIAL_ON, UNDETERMINED } upfSupplyStateE;
  typedef struct packed { upfSupplyStateE state; int voltage; } upfSupplyTypeT;  // voltage in microvolts
  typedef upfSupplyTypeT supply_net_type;
  bit openpa_armed;        // set by the first call that drives a supply
  bit openpa_kick;         // pulsed once at time 0 to evaluate everything
  bit openpa_xmode;        // 1: corrupt to X; 0: seeded 2-state values
  int unsigned openpa_seed = 1;
  int openpa_cmode;        // 2-state corruption: 0 random, 1 all zero, 2 all one
  supply_net_type openpa_port_VA;   // supply port VA (ap_power_slice.upf:5)
  supply_net_type openpa_port_VP;   // supply port VP (ap_power_slice.upf:6)
  supply_net_type openpa_port_VG;   // supply port VG (ap_power_slice.upf:7)
  supply_net_type openpa_net_NA;   // supply net NA
  supply_net_type openpa_net_NP;   // supply net NP
  supply_net_type openpa_net_NG;   // supply net NG
  bit openpa_ss_AON_ok; int unsigned openpa_ss_AON_ep; int openpa_ss_AON_st = -1; bit openpa_ss_AON_multi; int openpa_ss_AON_sim = 5;   // supply set AON
  bit openpa_ss_PER_ok; int unsigned openpa_ss_PER_ep; int openpa_ss_PER_st = -1; bit openpa_ss_PER_multi; int openpa_ss_PER_sim = 5;   // supply set PER
  bit openpa_dom_PD_AON_ok; int unsigned openpa_dom_PD_AON_ep; int openpa_dom_PD_AON_sim = 5;   // power domain PD_AON: ok = powered (simstate not CORRUPT); sim = simstate code (ap_power_slice.upf:3)
  bit openpa_dom_PD_PER_ok; int unsigned openpa_dom_PD_PER_ep; int openpa_dom_PD_PER_sim = 5;   // power domain PD_PER: ok = powered (simstate not CORRUPT); sim = simstate code (ap_power_slice.upf:4)
  // simstate codes, by IEEE 1801-2024 4.8 precedence: 0 NORMAL, 1 CORRUPT_STATE_ON_CHANGE, 2 CORRUPT_STATE_ON_ACTIVITY,
  // 3 CORRUPT_ON_CHANGE, 4 CORRUPT_ON_ACTIVITY, 5 CORRUPT (and NOT_NORMAL, 9.5.8); README "Simstates"
  logic openpa_ctl_0_isolate;   // copy of isolate (isolation QUIET)
  function automatic logic [63:0] openpa_mix(int unsigned id, int unsigned ep, int unsigned lane);
    logic [63:0] z;
    if (openpa_cmode == 1) return 64'd0;
    if (openpa_cmode == 2) return ~64'd0;
    z = {32'd0, openpa_seed} * 64'h9E3779B97F4A7C15 + {32'd0, id} * 64'hC2B2AE3D27D4EB4F + {32'd0, ep} * 64'h165667B19E3779F9 + {32'd0, lane} * 64'hD6E8FEB86659FD93;
    z = (z ^ (z >> 30)) * 64'hBF58476D1CE4E5B9;
    z = (z ^ (z >> 27)) * 64'h94D049BB133111EB;
    return z ^ (z >> 31);
  endfunction
  function automatic bit openpa_bit(int unsigned id, int unsigned ep); logic [63:0] z; z = openpa_mix(id, ep, 0); return z[0]; endfunction
  function automatic int openpa_uv(real v); return $rtoi(v * 1.0e6 + (v < 0.0 ? -0.5 : 0.5)); endfunction
  // supply_on: FULL_ON at the given voltage (11.2.4; default 1.0 V)
  function automatic upfBooleanT supply_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = FULL_ON; openpa_port_VA.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = FULL_ON; openpa_port_VP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = FULL_ON; openpa_port_VG.voltage = openpa_uv(value); return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR supply_on(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR supply_on(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR supply_on(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR supply_on(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // supply_off: OFF, voltage unchanged (9.3.1); a second argument is accepted and ignored
  function automatic upfBooleanT supply_off(string pad_name, real value = 0.0);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = OFF; return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = OFF; return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = OFF; return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR supply_off(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR supply_off(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR supply_off(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR supply_off(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // supply_partial_on: PARTIAL_ON at the given voltage (11.2.4)
  function automatic upfBooleanT supply_partial_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = PARTIAL_ON; openpa_port_VA.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = PARTIAL_ON; openpa_port_VP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = PARTIAL_ON; openpa_port_VG.voltage = openpa_uv(value); return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR supply_partial_on(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // set_supply_state: the state only, voltage unchanged (9.3.1)
  function automatic upfBooleanT set_supply_state(string pad_name, upfSupplyStateE supply_state);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = supply_state; return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = supply_state; return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = supply_state; return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR set_supply_state(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // set_power_state (9.3.1) is not supported: OpenPA has no deferred power states. A call is reported, never ignored.
  function automatic upfBooleanT set_power_state(string object_name, string power_state);
    $display("OPENPA-ERROR set_power_state(\"%s\", \"%s\"): not supported by OpenPA; drive the supplies with supply_on, supply_off or set_supply_state", object_name, power_state);
    return 0;
  endfunction
  // Supply queries (11.2.4). Names: supply ports, supply nets and supply set functions as the UPF wrote them.
  function automatic upfSupplyTypeT get_supply_value(string name);
    if (name == "VA" || name == "NA" || name == "AON.power" || name == "PD_AON.primary.power") return openpa_net_NA;
    if (name == "VP" || name == "NP" || name == "PER.power" || name == "PD_PER.primary.power") return openpa_net_NP;
    if (name == "VG" || name == "NG" || name == "AON.ground" || name == "PER.ground" || name == "PD_AON.primary.ground" || name == "PD_PER.primary.ground") return openpa_net_NG;
    $display("OPENPA-ERROR get_supply_value(\"%s\"): no supply net, port or supply set function of that name", name);
    return 0;
  endfunction
  function automatic upfRealT get_supply_voltage(upfSupplyTypeT arg); return arg.voltage / 1.0e6; endfunction
  // 11.2.4: 1 for FULL_ON; 0 otherwise.
  function automatic upfBooleanT get_supply_on_state(upfSupplyTypeT arg); return arg.state == FULL_ON; endfunction
  function automatic upfSupplyStateE get_supply_state(upfSupplyTypeT arg); return arg.state; endfunction
endpackage
// ---------------------------------------------------------------------------
// OpenPA cells (generated; do not edit)
// ---------------------------------------------------------------------------
// openpa_corrupt: rule C2. Passes d while the driving domain is NORMAL; otherwise drives X (4-state)
// or a seeded value (2-state). The value is computed ahead for the episode the next power-down starts
// (ep + 1 while ok), so at power-down the output goes straight from d to the new value: no delta glitch
// through the previous episode's value (Icarus would turn one into a clock edge).
module openpa_corrupt #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  assign q = ok ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_corrupt_sim: rule C2 for a domain that has intermediate simstates (IEEE 1801-2024 9.5). As
// openpa_corrupt, and also corrupt while lhit is set (CORRUPT_ON_ACTIVITY after input activity), or after d
// changed while coc is set (CORRUPT_ON_CHANGE); leaving CORRUPT_ON_CHANGE clears that.
module openpa_corrupt_sim #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep,
  input  bit           lhit,
  input  bit           coc
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  bit chg;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  // verilator lint_off MULTIDRIVEN
  for (genvar i = 0; i < W; i++) begin : g_chg
    always @(posedge d[i] or negedge d[i]) if (coc && ok) chg = 1'b1;
  end
  always @(negedge coc) chg = 1'b0;
  // verilator lint_on MULTIDRIVEN
  assign q = (ok && !lhit && !chg) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_iso: rules I1-I4 (IEEE 1801-2024 9.8). CLAMP 0, 1, 2 (latch: the value the input had while the enable
// was inactive) or 3 (Z: high impedance on 4-state; 0 on 2-state backends, which cannot represent Z).
// sup_ok is 1 while the isolation supply is NORMAL (always, for a strategy with no supply); otherwise the output,
// and a latched value, are corrupt. An enable at X or Z corrupts the output and the latched value.
module openpa_iso #(parameter int W = 1, parameter int CLAMP = 0, parameter bit SENSE = 1'b1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  logic         en,
  input  bit           sup_ok,
  input  int unsigned  sup_ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  logic [W-1:0] held;
  always @(sup_ep or sup_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h4000_0000, sup_ok ? sup_ep + 1 : sup_ep, i);
  wire active   = (en === SENSE);
  wire inactive = (en === !SENSE);
  wire [W-1:0] bad    = UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0];
  if (CLAMP == 2) begin : g_latch
    always @(d or en or sup_ok or bad) if (!sup_ok || !(active || inactive)) held = bad; else if (inactive) held = d;
  end
  wire [W-1:0] clampv = (CLAMP == 3) ? (UPF::openpa_xmode ? {W{1'bz}} : {W{1'b0}}) : (CLAMP == 2) ? held : (CLAMP == 1) ? {W{1'b1}} : {W{1'b0}};
  assign q = !sup_ok ? bad : active ? clampv : inactive ? d : bad;
endmodule

// openpa_ls: rule L1 (IEEE 1801-2024 9.9). Passes d while every supply set of the cell is NORMAL; otherwise corrupt.
module openpa_ls #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           src_ok,
  input  bit           dst_ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or src_ok or dst_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h8000_0000, (src_ok && dst_ok) ? ep + 1 : ep, i);
  assign q = (src_ok && dst_ok) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

`line 1 "ap_peripheral_irq.sv" 0
// One register from the teaching slice of the timer. A write posts or clears
// a diagnostic request so the receiver can be observed across a rail change.
module ap_peripheral_irq (
  input logic pclk, reset_n, psel, penable, pwrite,
  input logic [31:0] paddr, pwdata,
  output logic irq
);
  always_ff @(posedge pclk or negedge reset_n) begin
    if (!reset_n)
      irq <= 1'b0;
    else if (psel && penable && pwrite && paddr == 32'h1000_2000)
      irq <= pwdata[0];
  end
endmodule

module ap_power_slice (
  input logic pclk, reset_n, psel, penable, pwrite, isolate,
  input logic [31:0] paddr, pwdata,
  output wire timer_irq
);
  wire [0:0] openpa_u_timer_irq_raw, openpa_u_timer_irq_s1; wire [31:0] openpa_u_timer_paddr_s1; wire [0:0] openpa_u_timer_pclk_s1; wire [0:0] openpa_u_timer_penable_s1; wire [0:0] openpa_u_timer_psel_s1; wire [31:0] openpa_u_timer_pwdata_s1; wire [0:0] openpa_u_timer_pwrite_s1; wire [0:0] openpa_u_timer_reset_n_s1; ap_peripheral_irq u_timer (
    .pclk(openpa_u_timer_pclk_s1), .reset_n(openpa_u_timer_reset_n_s1), .psel(openpa_u_timer_psel_s1), .penable(openpa_u_timer_penable_s1),
    .pwrite(openpa_u_timer_pwrite_s1), .paddr(openpa_u_timer_paddr_s1), .pwdata(openpa_u_timer_pwdata_s1), .irq(openpa_u_timer_irq_raw)
  ); openpa_corrupt #(.W(1), .ID(268435456)) openpa_u_timer_irq_cor (.d(openpa_u_timer_irq_raw), .q(openpa_u_timer_irq_s1), .ok(UPF::openpa_dom_PD_PER_ok), .ep(UPF::openpa_dom_PD_PER_ep)); openpa_iso #(.W(1), .CLAMP(0), .SENSE(1'b1), .ID(268435457)) openpa_u_timer_irq_iso (.d(openpa_u_timer_irq_s1), .q(timer_irq), .en(UPF::openpa_ctl_0_isolate), .sup_ok((UPF::openpa_ss_AON_sim == 0)), .sup_ep(UPF::openpa_ss_AON_ep)); openpa_corrupt #(.W(32), .ID(268435464)) openpa_u_timer_paddr_cor (.d(paddr), .q(openpa_u_timer_paddr_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435472)) openpa_u_timer_pclk_cor (.d(pclk), .q(openpa_u_timer_pclk_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435480)) openpa_u_timer_penable_cor (.d(penable), .q(openpa_u_timer_penable_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435488)) openpa_u_timer_psel_cor (.d(psel), .q(openpa_u_timer_psel_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(32), .ID(268435496)) openpa_u_timer_pwdata_cor (.d(pwdata), .q(openpa_u_timer_pwdata_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435504)) openpa_u_timer_pwrite_cor (.d(pwrite), .q(openpa_u_timer_pwrite_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435512)) openpa_u_timer_reset_n_cor (.d(reset_n), .q(openpa_u_timer_reset_n_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep));

`line 1 "openpa_overlay.sv" 0
  // ===================================================================================
  // OpenPA overlay for ap_power_slice: generated from ap_power_slice.upf. Do not edit.
  // ===================================================================================
  // verilator lint_off MULTIDRIVEN
  // verilator lint_off ENUMVALUE
  // verilator lint_off WIDTHTRUNC
  // verilator lint_off WIDTHEXPAND
  // verilator lint_off BLKSEQ
  // verilator lint_off IGNOREDRETURN
  import UPF::openpa_cmode;
  import UPF::openpa_ctl_0_isolate;
  import UPF::openpa_dom_PD_AON_ep;
  import UPF::openpa_dom_PD_AON_ok;
  import UPF::openpa_dom_PD_AON_sim;
  import UPF::openpa_dom_PD_PER_ep;
  import UPF::openpa_dom_PD_PER_ok;
  import UPF::openpa_dom_PD_PER_sim;
  import UPF::openpa_kick;
  import UPF::openpa_net_NA;
  import UPF::openpa_net_NG;
  import UPF::openpa_net_NP;
  import UPF::openpa_seed;
  import UPF::openpa_ss_AON_ep;
  import UPF::openpa_ss_AON_multi;
  import UPF::openpa_ss_AON_ok;
  import UPF::openpa_ss_AON_sim;
  import UPF::openpa_ss_AON_st;
  import UPF::openpa_ss_PER_ep;
  import UPF::openpa_ss_PER_multi;
  import UPF::openpa_ss_PER_ok;
  import UPF::openpa_ss_PER_sim;
  import UPF::openpa_ss_PER_st;
  import UPF::openpa_xmode;
  // ---- mode, seed, trace
  bit openpa_tr, openpa_obs;
  int openpa_n [1:14];
  int openpa_seq [1:2];   // good-form sequence bins (coverage)
  bit openpa_sreq; bit openpa_sp [1:14];   // deferred checks: request and pending flags
  string openpa_mode_arg;
  initial begin
  `ifdef VERILATOR
    openpa_xmode = 1'b0;
  `else
    openpa_xmode = 1'b1;
  `endif
    openpa_cmode = 0;
    if ($value$plusargs("openpa_corrupt=%s", openpa_mode_arg)) begin
      if (openpa_mode_arg == "x") openpa_xmode = 1'b1;
      else if (openpa_mode_arg == "random") openpa_xmode = 1'b0;
      else if (openpa_mode_arg == "zero") begin openpa_xmode = 1'b0; openpa_cmode = 1; end
      else if (openpa_mode_arg == "one") begin openpa_xmode = 1'b0; openpa_cmode = 2; end
      else $display("OPENPA-ERROR +openpa_corrupt=%s: use x, random, zero or one", openpa_mode_arg);
    end
    if (!$value$plusargs("openpa_seed=%d", openpa_seed)) openpa_seed = 1;
    openpa_tr = $test$plusargs("openpa_trace");
    openpa_obs = $test$plusargs("openpa_obs");
    $display("OPENPA-INFO corruption=%0s seed=%0d", openpa_xmode ? "x" : (openpa_cmode == 1 ? "zero" : openpa_cmode == 2 ? "one" : "random"), openpa_seed);
    #0 openpa_kick = 1'b1;
  end
  task automatic openpa_check(input int id, input string msg);
    openpa_n[id] = openpa_n[id] + 1;
    $display("OPENPA-CHECK D%0d @ %0t: %s", id, $time, msg);
  endtask
  task automatic openpa_t(input string msg);
    if (openpa_tr) $display("OPENPA-TRACE @ %0t: %s", $time, msg);
  endtask

  // ---- copies of the design signals the UPF names (4-state, so X is visible)
  always @(isolate or openpa_kick) openpa_ctl_0_isolate = isolate;

  // ---- supply network, switches, supply sets, simstates, power states (one block, evaluated in order)
  always @(openpa_kick or UPF::openpa_port_VA or UPF::openpa_port_VP or UPF::openpa_port_VG) begin : openpa_network
    openpa_net_NA = UPF::openpa_port_VA;   // NA <- port VA
    openpa_net_NP = UPF::openpa_port_VP;   // NP <- port VP
    openpa_net_NG = UPF::openpa_port_VG;   // NG <- port VG
    // supply set AON (also PD_AON.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_AON
      bit nx; int sm;
      sm = (UPF::openpa_net_NA.state == UPF::FULL_ON && UPF::openpa_net_NG.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_AON_sim = sm;
      nx = sm < 5;
      if (openpa_ss_AON_ok && !nx) openpa_ss_AON_ep = openpa_ss_AON_ep + 1;
      openpa_ss_AON_ok = nx;
    end
    // supply set PER (also PD_PER.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_PER
      bit nx; int sm;
      sm = (UPF::openpa_net_NP.state == UPF::FULL_ON && UPF::openpa_net_NG.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_PER_sim = sm;
      nx = sm < 5;
      if (openpa_ss_PER_ok && !nx) openpa_ss_PER_ep = openpa_ss_PER_ep + 1;
      openpa_ss_PER_ok = nx;
    end
    // domain PD_AON: simstate of its primary supply set AON
    if (openpa_dom_PD_AON_ok && !UPF::openpa_ss_AON_ok) openpa_dom_PD_AON_ep = openpa_dom_PD_AON_ep + 1;
    openpa_dom_PD_AON_ok = UPF::openpa_ss_AON_ok;
    openpa_dom_PD_AON_sim = openpa_ss_AON_sim;
    // domain PD_PER: simstate of its primary supply set PER
    if (openpa_dom_PD_PER_ok && !UPF::openpa_ss_PER_ok) openpa_dom_PD_PER_ep = openpa_dom_PD_PER_ep + 1;
    openpa_dom_PD_PER_ok = UPF::openpa_ss_PER_ok;
    openpa_dom_PD_PER_sim = openpa_ss_PER_sim;
  end

  // ---- corruption: registers forced, memories overwritten (rules C1, C3)
  // domain PD_AON (ap_power_slice.upf:3): 0 register(s), 0 memory(ies)
  bit openpa_PD_AON_applied, openpa_PD_AON_valid;
  // The first evaluation counts as a power-up from OFF: registers take the corruption value even when the
  // supplies are already on at time 0 (rule C3), so 4-state and 2-state runs start alike.
  always @(UPF::openpa_dom_PD_AON_ok or openpa_kick) if (!openpa_PD_AON_valid || openpa_PD_AON_applied != UPF::openpa_dom_PD_AON_ok) begin
    openpa_t({"PD_AON ", UPF::openpa_dom_PD_AON_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_AON_ok || !openpa_PD_AON_valid) begin
    end
    if (UPF::openpa_dom_PD_AON_ok) begin
    end
    openpa_PD_AON_valid = 1'b1; openpa_PD_AON_applied = UPF::openpa_dom_PD_AON_ok;
  end
  // domain PD_PER (ap_power_slice.upf:4): 1 register(s), 0 memory(ies)
  bit openpa_PD_PER_applied, openpa_PD_PER_valid;
  logic [0:0] openpa_cv1;   // corruption value for u_timer.irq
  // The first evaluation counts as a power-up from OFF: registers take the corruption value even when the
  // supplies are already on at time 0 (rule C3), so 4-state and 2-state runs start alike.
  always @(UPF::openpa_dom_PD_PER_ok or openpa_kick) if (!openpa_PD_PER_valid || openpa_PD_PER_applied != UPF::openpa_dom_PD_PER_ok) begin
    openpa_t({"PD_PER ", UPF::openpa_dom_PD_PER_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_PER_ok || !openpa_PD_PER_valid) begin
      if (openpa_xmode) openpa_cv1 = 'x; else openpa_cv1 = UPF::openpa_mix(1, UPF::openpa_dom_PD_PER_ep, 0);
      force u_timer.irq = openpa_cv1;
    end
    if (UPF::openpa_dom_PD_PER_ok) begin
      release u_timer.irq;
    end
    openpa_PD_PER_valid = 1'b1; openpa_PD_PER_applied = UPF::openpa_dom_PD_PER_ok;
  end

  // D7 reset check for PD_PER: resets u_timer.reset_n active 0
  bit openpa_PD_PER_rprev, openpa_PD_PER_rp0;
  always @(posedge UPF::openpa_dom_PD_PER_ok or negedge UPF::openpa_dom_PD_PER_ok or posedge u_timer.reset_n or negedge u_timer.reset_n) begin
    if (UPF::openpa_dom_PD_PER_ok && !openpa_PD_PER_rprev) openpa_PD_PER_rp0 = 1'b1;
    if (!UPF::openpa_dom_PD_PER_ok || u_timer.reset_n === 1'b0) openpa_PD_PER_rp0 = 1'b0;
    openpa_PD_PER_rprev = UPF::openpa_dom_PD_PER_ok;
  end

  // ---- checks for set_isolation QUIET (ap_power_slice.upf:18): PD_PER -> PD_AON on 1 port(s)
  bit openpa_ig1_act, openpa_ig1_cyc;
  always @(negedge UPF::openpa_dom_PD_PER_ok) if (!UPF::openpa_dom_PD_PER_ok)
    begin openpa_sp[1] = 1'b1; openpa_sreq = 1'b1; end
  always @(posedge UPF::openpa_ctl_0_isolate or negedge UPF::openpa_ctl_0_isolate or posedge openpa_kick) begin
    if (openpa_ig1_act && !(UPF::openpa_ctl_0_isolate === 1'b1))
      begin openpa_sp[2] = 1'b1; openpa_sreq = 1'b1; end
    if (openpa_ig1_act != (UPF::openpa_ctl_0_isolate === 1'b1)) openpa_t({"QUIET enable ", (UPF::openpa_ctl_0_isolate === 1'b1) ? "active" : "inactive"});
    openpa_ig1_act = (UPF::openpa_ctl_0_isolate === 1'b1);
  end
  always @(negedge UPF::openpa_ss_AON_ok) if (!UPF::openpa_ss_AON_ok)
    begin openpa_sp[3] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 1: u_timer/irq (PD_PER) -> ap_power_slice output timer_irq (PD_AON), isolated by QUIET
  bit openpa_x1_t;
  always @(UPF::openpa_dom_PD_PER_ok or UPF::openpa_dom_PD_AON_ok or UPF::openpa_ctl_0_isolate or UPF::openpa_ss_AON_sim or UPF::openpa_net_NP or UPF::openpa_net_NG) openpa_x1_t = !UPF::openpa_dom_PD_PER_ok && UPF::openpa_dom_PD_AON_ok && !(((UPF::openpa_ctl_0_isolate === 1'b1) && (UPF::openpa_ss_AON_sim == 0))) && !(UPF::openpa_net_NP.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x1_t)
    begin openpa_sp[4] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 2: ap_power_slice input paddr (PD_AON) -> u_timer/paddr (PD_PER), not isolated
  bit openpa_x2_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x2_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x2_t)
    begin openpa_sp[5] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 3: ap_power_slice input pclk (PD_AON) -> u_timer/pclk (PD_PER), not isolated
  bit openpa_x3_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x3_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x3_t)
    begin openpa_sp[6] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 4: ap_power_slice input penable (PD_AON) -> u_timer/penable (PD_PER), not isolated
  bit openpa_x4_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x4_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x4_t)
    begin openpa_sp[7] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 5: ap_power_slice input psel (PD_AON) -> u_timer/psel (PD_PER), not isolated
  bit openpa_x5_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x5_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x5_t)
    begin openpa_sp[8] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 6: ap_power_slice input pwdata (PD_AON) -> u_timer/pwdata (PD_PER), not isolated
  bit openpa_x6_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x6_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x6_t)
    begin openpa_sp[9] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 7: ap_power_slice input pwrite (PD_AON) -> u_timer/pwrite (PD_PER), not isolated
  bit openpa_x7_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x7_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x7_t)
    begin openpa_sp[10] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 8: ap_power_slice input reset_n (PD_AON) -> u_timer/reset_n (PD_PER), not isolated
  bit openpa_x8_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x8_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x8_t)
    begin openpa_sp[11] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 1: PD_PER -> PD_AON (no level shifter strategy, threshold 0)
  bit openpa_l1_t;
  always @(UPF::openpa_dom_PD_PER_ok or UPF::openpa_dom_PD_AON_ok or UPF::openpa_net_NP or UPF::openpa_net_NA) openpa_l1_t = UPF::openpa_dom_PD_PER_ok && UPF::openpa_dom_PD_AON_ok && (UPF::openpa_net_NP.voltage - UPF::openpa_net_NA.voltage > 0 || UPF::openpa_net_NA.voltage - UPF::openpa_net_NP.voltage > 0) && !1'b0;
  always @(posedge openpa_l1_t)
    begin openpa_sp[12] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 2: PD_AON -> PD_PER (no level shifter strategy, threshold 0)
  bit openpa_l2_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NP) openpa_l2_t = UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && (UPF::openpa_net_NA.voltage - UPF::openpa_net_NP.voltage > 0 || UPF::openpa_net_NP.voltage - UPF::openpa_net_NA.voltage > 0) && !1'b0;
  always @(posedge openpa_l2_t)
    begin openpa_sp[13] = 1'b1; openpa_sreq = 1'b1; end
  always @(negedge UPF::openpa_dom_PD_AON_ok) if (!UPF::openpa_dom_PD_AON_ok)
    begin openpa_sp[14] = 1'b1; openpa_sreq = 1'b1; end

  // ---- observation for differential corruption (+openpa_obs): design-top outputs while the top domain is on
  `ifdef OPENPA_OBS
  longint openpa_obs_after;
  initial if (!$value$plusargs("openpa_obs_after=%d", openpa_obs_after)) openpa_obs_after = 0;
  always @(timer_irq) if (openpa_obs && UPF::openpa_dom_PD_AON_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: timer_irq=%h", $time, timer_irq);
  `else
  initial if ($test$plusargs("openpa_obs")) $display("OPENPA-ERROR +openpa_obs needs the copy compiled with OPENPA_OBS defined (-DOPENPA_OBS or +define+OPENPA_OBS)");
  `endif

  // Icarus 12 runs no named block inside a final block, so the report is a function.
  function automatic void openpa_cover_report();
      int hs, ht, hq;
      hs = 0; ht = 0; hq = 0;
      $display("OPENPA-COVER sequence D1 QUIET: PD_PER isolated before power-down %0d", openpa_seq[1]);
      $display("OPENPA-COVER sequence D2/D7 QUIET: isolation released only after PD_PER was back and reset %0d", openpa_seq[2]);
      if (openpa_seq[1]) hq = hq + 1;
      if (openpa_seq[2]) hq = hq + 1;
      $display("OPENPA-COVER-SUMMARY states=%0d/0 declared_transitions=%0d/0 sequences=%0d/2", hs, ht, hq);
  endfunction

  // ---- settle process: 14 deferred check(s), run after one #0 in a fixed order
  initial forever begin
    wait (openpa_sreq && openpa_kick);
    #0;
    openpa_sreq = 1'b0;
    if (openpa_sp[1]) begin
      openpa_sp[1] = 1'b0;
        if (!UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok) && !(UPF::openpa_ctl_0_isolate === 1'b1)) openpa_check(1, "set_isolation QUIET (ap_power_slice.upf:18): PD_PER went off while the isolation enable isolate was inactive");
        else if (!UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok) && (UPF::openpa_ctl_0_isolate === 1'b1)) begin openpa_seq[1] = openpa_seq[1] + 1; openpa_ig1_cyc = 1'b1; end
    end
    if (openpa_sp[2]) begin
      openpa_sp[2] = 1'b0;
          if (!UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok)) openpa_check(2, "set_isolation QUIET (ap_power_slice.upf:18): isolation released while PD_PER is still off");
          else if (openpa_PD_PER_rp0) openpa_check(7, "set_isolation QUIET (ap_power_slice.upf:18): isolation released after PD_PER powered up but before its reset u_timer.reset_n was asserted");
          else if (openpa_ig1_cyc) openpa_seq[2] = openpa_seq[2] + 1;
          openpa_ig1_cyc = 1'b0;
    end
    if (openpa_sp[3]) begin
      openpa_sp[3] = 1'b0;
      if ((UPF::openpa_ctl_0_isolate === 1'b1) && !UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok)) openpa_check(6, "set_isolation QUIET (ap_power_slice.upf:18): isolation supply AON lost while clamping");
    end
    if (openpa_sp[4]) begin
      openpa_sp[4] = 1'b0;
      if (openpa_x1_t) openpa_check(9, "u_timer/irq of PD_PER (off) is read by ap_power_slice output timer_irq in PD_AON (on) with no active isolation");
    end
    if (openpa_sp[5]) begin
      openpa_sp[5] = 1'b0;
      if (openpa_x2_t) openpa_check(9, "ap_power_slice input paddr of PD_AON (off) is read by u_timer/paddr in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[6]) begin
      openpa_sp[6] = 1'b0;
      if (openpa_x3_t) openpa_check(9, "ap_power_slice input pclk of PD_AON (off) is read by u_timer/pclk in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[7]) begin
      openpa_sp[7] = 1'b0;
      if (openpa_x4_t) openpa_check(9, "ap_power_slice input penable of PD_AON (off) is read by u_timer/penable in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[8]) begin
      openpa_sp[8] = 1'b0;
      if (openpa_x5_t) openpa_check(9, "ap_power_slice input psel of PD_AON (off) is read by u_timer/psel in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[9]) begin
      openpa_sp[9] = 1'b0;
      if (openpa_x6_t) openpa_check(9, "ap_power_slice input pwdata of PD_AON (off) is read by u_timer/pwdata in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[10]) begin
      openpa_sp[10] = 1'b0;
      if (openpa_x7_t) openpa_check(9, "ap_power_slice input pwrite of PD_AON (off) is read by u_timer/pwrite in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[11]) begin
      openpa_sp[11] = 1'b0;
      if (openpa_x8_t) openpa_check(9, "ap_power_slice input reset_n of PD_AON (off) is read by u_timer/reset_n in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[12]) begin
      openpa_sp[12] = 1'b0;
      if (openpa_l1_t) openpa_check(11, $sformatf("PD_PER (%0d uV) drives PD_AON (%0d uV) on 1 port(s) with no level shifter for this direction", UPF::openpa_net_NP.voltage, UPF::openpa_net_NA.voltage));
    end
    if (openpa_sp[13]) begin
      openpa_sp[13] = 1'b0;
      if (openpa_l2_t) openpa_check(11, $sformatf("PD_AON (%0d uV) drives PD_PER (%0d uV) on 7 port(s) with no level shifter for this direction", UPF::openpa_net_NA.voltage, UPF::openpa_net_NP.voltage));
    end
    if (openpa_sp[14]) begin
      openpa_sp[14] = 1'b0;
      if (!UPF::openpa_dom_PD_AON_ok && (UPF::openpa_dom_PD_PER_ok)) openpa_check(12, "isolate (isolation QUIET) comes from PD_AON, which is off while other domains are on");
    end
  end
  final begin
    $display("OPENPA-SUMMARY D1=%0d D2=%0d D3=%0d D4=%0d D5=%0d D6=%0d D7=%0d D8=%0d D9=%0d D10=%0d D11=%0d D12=%0d D13=%0d D14=%0d", openpa_n[1], openpa_n[2], openpa_n[3], openpa_n[4], openpa_n[5], openpa_n[6], openpa_n[7], openpa_n[8], openpa_n[9], openpa_n[10], openpa_n[11], openpa_n[12], openpa_n[13], openpa_n[14]);
    openpa_cover_report();
    if (!UPF::openpa_armed) $display("OPENPA-WARNING no supply was driven (supply_on/supply_off never called): every domain stayed CORRUPT");
  end
  // verilator lint_on MULTIDRIVEN
`line 25 "ap_peripheral_irq.sv" 0
endmodule

Check Yourself

Predict the outputIn this run the isolation enable stays 0 for the whole run. The supply of the timer is switched off while its request is 1. Which row does the lab print at "supply off"?
`timescale 1ns/1ns
module tb;
  import UPF::*;
  logic pclk=0, reset_n=0, psel=0, penable=0, pwrite=0, isolate=0;
  logic [31:0] paddr=0, pwdata=0;
  wire timer_irq;
  ap_power_slice dut(.*);
  always #5 pclk = ~pclk;

  // raw: the request inside the timer. receiver: the same wire after the clamp, in the always-on domain.
  task automatic sample(input string phase);
    $display("%s isolate=%b raw=%b receiver=%b", phase, isolate, dut.u_timer.irq, timer_irq);
  endtask

  // Test code that plays the processor: one APB write that sets the request of the timer.
  task automatic post_request;
    @(negedge pclk);
    psel=1; pwrite=1; paddr=32'h1000_2000; pwdata=1;
    @(negedge pclk);
    penable=1;
    @(negedge pclk);
    psel=0; penable=0; pwrite=0;
  endtask

  initial begin
    void'(supply_on("VA", 1.0));               // the always-on supply
    void'(supply_on("VG", 0.0));               // ground
    void'(supply_on("VP", 1.0));               // the switched supply of the timer
    repeat (2) @(negedge pclk);
    reset_n=1;
    post_request();
    sample("request set");
    isolate=0; #1; sample("clamp on");
    void'(supply_off("VP")); #1; sample("supply off");
    void'(supply_on("VP", 1.0)); #1; sample("supply on");
    reset_n=0; @(negedge pclk); reset_n=1; #1; sample("timer reset");
    isolate=0; #1; sample("clamp off");
    post_request();
    sample("request set");
    $finish;
  end
endmodule
Read included file: pa_ap_power_slice.sv
// pa_ap_power_slice.sv: power-aware copy of ap_power_slice, generated by OpenPA from ap_power_slice.upf.
// Do not edit: regenerate. Simulators: Icarus 12 (4-state, X corruption) or Verilator 5 with --timing (2-state).
// Build with -Wno-fatal on Verilator: forced registers raise MULTIDRIVEN warnings.
// ---------------------------------------------------------------------------
// package UPF: generated by OpenPA. Supply types, supply_on/supply_off and the power
// state of the design. Names starting with openpa_ are internal.
// ---------------------------------------------------------------------------
package UPF;
  typedef string upfStringT; typedef int upfIntegerT; typedef bit upfBooleanT; typedef logic upfLogicT; typedef real upfRealT; typedef int upfHandleT;
  typedef enum { OFF, FULL_ON, PARTIAL_ON, UNDETERMINED } upfSupplyStateE;
  typedef struct packed { upfSupplyStateE state; int voltage; } upfSupplyTypeT;  // voltage in microvolts
  typedef upfSupplyTypeT supply_net_type;
  bit openpa_armed;        // set by the first call that drives a supply
  bit openpa_kick;         // pulsed once at time 0 to evaluate everything
  bit openpa_xmode;        // 1: corrupt to X; 0: seeded 2-state values
  int unsigned openpa_seed = 1;
  int openpa_cmode;        // 2-state corruption: 0 random, 1 all zero, 2 all one
  supply_net_type openpa_port_VA;   // supply port VA (ap_power_slice.upf:5)
  supply_net_type openpa_port_VP;   // supply port VP (ap_power_slice.upf:6)
  supply_net_type openpa_port_VG;   // supply port VG (ap_power_slice.upf:7)
  supply_net_type openpa_net_NA;   // supply net NA
  supply_net_type openpa_net_NP;   // supply net NP
  supply_net_type openpa_net_NG;   // supply net NG
  bit openpa_ss_AON_ok; int unsigned openpa_ss_AON_ep; int openpa_ss_AON_st = -1; bit openpa_ss_AON_multi; int openpa_ss_AON_sim = 5;   // supply set AON
  bit openpa_ss_PER_ok; int unsigned openpa_ss_PER_ep; int openpa_ss_PER_st = -1; bit openpa_ss_PER_multi; int openpa_ss_PER_sim = 5;   // supply set PER
  bit openpa_dom_PD_AON_ok; int unsigned openpa_dom_PD_AON_ep; int openpa_dom_PD_AON_sim = 5;   // power domain PD_AON: ok = powered (simstate not CORRUPT); sim = simstate code (ap_power_slice.upf:3)
  bit openpa_dom_PD_PER_ok; int unsigned openpa_dom_PD_PER_ep; int openpa_dom_PD_PER_sim = 5;   // power domain PD_PER: ok = powered (simstate not CORRUPT); sim = simstate code (ap_power_slice.upf:4)
  // simstate codes, by IEEE 1801-2024 4.8 precedence: 0 NORMAL, 1 CORRUPT_STATE_ON_CHANGE, 2 CORRUPT_STATE_ON_ACTIVITY,
  // 3 CORRUPT_ON_CHANGE, 4 CORRUPT_ON_ACTIVITY, 5 CORRUPT (and NOT_NORMAL, 9.5.8); README "Simstates"
  logic openpa_ctl_0_isolate;   // copy of isolate (isolation QUIET)
  function automatic logic [63:0] openpa_mix(int unsigned id, int unsigned ep, int unsigned lane);
    logic [63:0] z;
    if (openpa_cmode == 1) return 64'd0;
    if (openpa_cmode == 2) return ~64'd0;
    z = {32'd0, openpa_seed} * 64'h9E3779B97F4A7C15 + {32'd0, id} * 64'hC2B2AE3D27D4EB4F + {32'd0, ep} * 64'h165667B19E3779F9 + {32'd0, lane} * 64'hD6E8FEB86659FD93;
    z = (z ^ (z >> 30)) * 64'hBF58476D1CE4E5B9;
    z = (z ^ (z >> 27)) * 64'h94D049BB133111EB;
    return z ^ (z >> 31);
  endfunction
  function automatic bit openpa_bit(int unsigned id, int unsigned ep); logic [63:0] z; z = openpa_mix(id, ep, 0); return z[0]; endfunction
  function automatic int openpa_uv(real v); return $rtoi(v * 1.0e6 + (v < 0.0 ? -0.5 : 0.5)); endfunction
  // supply_on: FULL_ON at the given voltage (11.2.4; default 1.0 V)
  function automatic upfBooleanT supply_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = FULL_ON; openpa_port_VA.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = FULL_ON; openpa_port_VP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = FULL_ON; openpa_port_VG.voltage = openpa_uv(value); return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR supply_on(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR supply_on(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR supply_on(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR supply_on(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // supply_off: OFF, voltage unchanged (9.3.1); a second argument is accepted and ignored
  function automatic upfBooleanT supply_off(string pad_name, real value = 0.0);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = OFF; return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = OFF; return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = OFF; return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR supply_off(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR supply_off(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR supply_off(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR supply_off(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // supply_partial_on: PARTIAL_ON at the given voltage (11.2.4)
  function automatic upfBooleanT supply_partial_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = PARTIAL_ON; openpa_port_VA.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = PARTIAL_ON; openpa_port_VP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = PARTIAL_ON; openpa_port_VG.voltage = openpa_uv(value); return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR supply_partial_on(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // set_supply_state: the state only, voltage unchanged (9.3.1)
  function automatic upfBooleanT set_supply_state(string pad_name, upfSupplyStateE supply_state);
    openpa_armed = 1;
    if (pad_name == "VA") begin openpa_port_VA.state = supply_state; return 1; end
    if (pad_name == "VP") begin openpa_port_VP.state = supply_state; return 1; end
    if (pad_name == "VG") begin openpa_port_VG.state = supply_state; return 1; end
    if (pad_name == "NA") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): NA already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): AON.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_AON.primary.power already has a driver (port VA); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NP") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): NP already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PER.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_PER.primary.power already has a driver (port VP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "NG") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): NG already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "AON.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): AON.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PER.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PER.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_AON.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_AON.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_PER.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_PER.primary.ground already has a driver (port VG); drive its root supply instead", pad_name); return 0; end
    $display("OPENPA-ERROR set_supply_state(\"%s\"): no supply port or root supply net of that name (writable: VA VP VG)", pad_name);
    return 0;
  endfunction
  // set_power_state (9.3.1) is not supported: OpenPA has no deferred power states. A call is reported, never ignored.
  function automatic upfBooleanT set_power_state(string object_name, string power_state);
    $display("OPENPA-ERROR set_power_state(\"%s\", \"%s\"): not supported by OpenPA; drive the supplies with supply_on, supply_off or set_supply_state", object_name, power_state);
    return 0;
  endfunction
  // Supply queries (11.2.4). Names: supply ports, supply nets and supply set functions as the UPF wrote them.
  function automatic upfSupplyTypeT get_supply_value(string name);
    if (name == "VA" || name == "NA" || name == "AON.power" || name == "PD_AON.primary.power") return openpa_net_NA;
    if (name == "VP" || name == "NP" || name == "PER.power" || name == "PD_PER.primary.power") return openpa_net_NP;
    if (name == "VG" || name == "NG" || name == "AON.ground" || name == "PER.ground" || name == "PD_AON.primary.ground" || name == "PD_PER.primary.ground") return openpa_net_NG;
    $display("OPENPA-ERROR get_supply_value(\"%s\"): no supply net, port or supply set function of that name", name);
    return 0;
  endfunction
  function automatic upfRealT get_supply_voltage(upfSupplyTypeT arg); return arg.voltage / 1.0e6; endfunction
  // 11.2.4: 1 for FULL_ON; 0 otherwise.
  function automatic upfBooleanT get_supply_on_state(upfSupplyTypeT arg); return arg.state == FULL_ON; endfunction
  function automatic upfSupplyStateE get_supply_state(upfSupplyTypeT arg); return arg.state; endfunction
endpackage
// ---------------------------------------------------------------------------
// OpenPA cells (generated; do not edit)
// ---------------------------------------------------------------------------
// openpa_corrupt: rule C2. Passes d while the driving domain is NORMAL; otherwise drives X (4-state)
// or a seeded value (2-state). The value is computed ahead for the episode the next power-down starts
// (ep + 1 while ok), so at power-down the output goes straight from d to the new value: no delta glitch
// through the previous episode's value (Icarus would turn one into a clock edge).
module openpa_corrupt #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  assign q = ok ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_corrupt_sim: rule C2 for a domain that has intermediate simstates (IEEE 1801-2024 9.5). As
// openpa_corrupt, and also corrupt while lhit is set (CORRUPT_ON_ACTIVITY after input activity), or after d
// changed while coc is set (CORRUPT_ON_CHANGE); leaving CORRUPT_ON_CHANGE clears that.
module openpa_corrupt_sim #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep,
  input  bit           lhit,
  input  bit           coc
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  bit chg;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  // verilator lint_off MULTIDRIVEN
  for (genvar i = 0; i < W; i++) begin : g_chg
    always @(posedge d[i] or negedge d[i]) if (coc && ok) chg = 1'b1;
  end
  always @(negedge coc) chg = 1'b0;
  // verilator lint_on MULTIDRIVEN
  assign q = (ok && !lhit && !chg) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_iso: rules I1-I4 (IEEE 1801-2024 9.8). CLAMP 0, 1, 2 (latch: the value the input had while the enable
// was inactive) or 3 (Z: high impedance on 4-state; 0 on 2-state backends, which cannot represent Z).
// sup_ok is 1 while the isolation supply is NORMAL (always, for a strategy with no supply); otherwise the output,
// and a latched value, are corrupt. An enable at X or Z corrupts the output and the latched value.
module openpa_iso #(parameter int W = 1, parameter int CLAMP = 0, parameter bit SENSE = 1'b1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  logic         en,
  input  bit           sup_ok,
  input  int unsigned  sup_ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  logic [W-1:0] held;
  always @(sup_ep or sup_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h4000_0000, sup_ok ? sup_ep + 1 : sup_ep, i);
  wire active   = (en === SENSE);
  wire inactive = (en === !SENSE);
  wire [W-1:0] bad    = UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0];
  if (CLAMP == 2) begin : g_latch
    always @(d or en or sup_ok or bad) if (!sup_ok || !(active || inactive)) held = bad; else if (inactive) held = d;
  end
  wire [W-1:0] clampv = (CLAMP == 3) ? (UPF::openpa_xmode ? {W{1'bz}} : {W{1'b0}}) : (CLAMP == 2) ? held : (CLAMP == 1) ? {W{1'b1}} : {W{1'b0}};
  assign q = !sup_ok ? bad : active ? clampv : inactive ? d : bad;
endmodule

// openpa_ls: rule L1 (IEEE 1801-2024 9.9). Passes d while every supply set of the cell is NORMAL; otherwise corrupt.
module openpa_ls #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           src_ok,
  input  bit           dst_ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or src_ok or dst_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h8000_0000, (src_ok && dst_ok) ? ep + 1 : ep, i);
  assign q = (src_ok && dst_ok) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

`line 1 "ap_peripheral_irq.sv" 0
// One register from the teaching slice of the timer. A write posts or clears
// a diagnostic request so the receiver can be observed across a rail change.
module ap_peripheral_irq (
  input logic pclk, reset_n, psel, penable, pwrite,
  input logic [31:0] paddr, pwdata,
  output logic irq
);
  always_ff @(posedge pclk or negedge reset_n) begin
    if (!reset_n)
      irq <= 1'b0;
    else if (psel && penable && pwrite && paddr == 32'h1000_2000)
      irq <= pwdata[0];
  end
endmodule

module ap_power_slice (
  input logic pclk, reset_n, psel, penable, pwrite, isolate,
  input logic [31:0] paddr, pwdata,
  output wire timer_irq
);
  wire [0:0] openpa_u_timer_irq_raw, openpa_u_timer_irq_s1; wire [31:0] openpa_u_timer_paddr_s1; wire [0:0] openpa_u_timer_pclk_s1; wire [0:0] openpa_u_timer_penable_s1; wire [0:0] openpa_u_timer_psel_s1; wire [31:0] openpa_u_timer_pwdata_s1; wire [0:0] openpa_u_timer_pwrite_s1; wire [0:0] openpa_u_timer_reset_n_s1; ap_peripheral_irq u_timer (
    .pclk(openpa_u_timer_pclk_s1), .reset_n(openpa_u_timer_reset_n_s1), .psel(openpa_u_timer_psel_s1), .penable(openpa_u_timer_penable_s1),
    .pwrite(openpa_u_timer_pwrite_s1), .paddr(openpa_u_timer_paddr_s1), .pwdata(openpa_u_timer_pwdata_s1), .irq(openpa_u_timer_irq_raw)
  ); openpa_corrupt #(.W(1), .ID(268435456)) openpa_u_timer_irq_cor (.d(openpa_u_timer_irq_raw), .q(openpa_u_timer_irq_s1), .ok(UPF::openpa_dom_PD_PER_ok), .ep(UPF::openpa_dom_PD_PER_ep)); openpa_iso #(.W(1), .CLAMP(0), .SENSE(1'b1), .ID(268435457)) openpa_u_timer_irq_iso (.d(openpa_u_timer_irq_s1), .q(timer_irq), .en(UPF::openpa_ctl_0_isolate), .sup_ok((UPF::openpa_ss_AON_sim == 0)), .sup_ep(UPF::openpa_ss_AON_ep)); openpa_corrupt #(.W(32), .ID(268435464)) openpa_u_timer_paddr_cor (.d(paddr), .q(openpa_u_timer_paddr_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435472)) openpa_u_timer_pclk_cor (.d(pclk), .q(openpa_u_timer_pclk_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435480)) openpa_u_timer_penable_cor (.d(penable), .q(openpa_u_timer_penable_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435488)) openpa_u_timer_psel_cor (.d(psel), .q(openpa_u_timer_psel_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(32), .ID(268435496)) openpa_u_timer_pwdata_cor (.d(pwdata), .q(openpa_u_timer_pwdata_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435504)) openpa_u_timer_pwrite_cor (.d(pwrite), .q(openpa_u_timer_pwrite_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep)); openpa_corrupt #(.W(1), .ID(268435512)) openpa_u_timer_reset_n_cor (.d(reset_n), .q(openpa_u_timer_reset_n_s1), .ok(UPF::openpa_dom_PD_AON_ok), .ep(UPF::openpa_dom_PD_AON_ep));

`line 1 "openpa_overlay.sv" 0
  // ===================================================================================
  // OpenPA overlay for ap_power_slice: generated from ap_power_slice.upf. Do not edit.
  // ===================================================================================
  // verilator lint_off MULTIDRIVEN
  // verilator lint_off ENUMVALUE
  // verilator lint_off WIDTHTRUNC
  // verilator lint_off WIDTHEXPAND
  // verilator lint_off BLKSEQ
  // verilator lint_off IGNOREDRETURN
  import UPF::openpa_cmode;
  import UPF::openpa_ctl_0_isolate;
  import UPF::openpa_dom_PD_AON_ep;
  import UPF::openpa_dom_PD_AON_ok;
  import UPF::openpa_dom_PD_AON_sim;
  import UPF::openpa_dom_PD_PER_ep;
  import UPF::openpa_dom_PD_PER_ok;
  import UPF::openpa_dom_PD_PER_sim;
  import UPF::openpa_kick;
  import UPF::openpa_net_NA;
  import UPF::openpa_net_NG;
  import UPF::openpa_net_NP;
  import UPF::openpa_seed;
  import UPF::openpa_ss_AON_ep;
  import UPF::openpa_ss_AON_multi;
  import UPF::openpa_ss_AON_ok;
  import UPF::openpa_ss_AON_sim;
  import UPF::openpa_ss_AON_st;
  import UPF::openpa_ss_PER_ep;
  import UPF::openpa_ss_PER_multi;
  import UPF::openpa_ss_PER_ok;
  import UPF::openpa_ss_PER_sim;
  import UPF::openpa_ss_PER_st;
  import UPF::openpa_xmode;
  // ---- mode, seed, trace
  bit openpa_tr, openpa_obs;
  int openpa_n [1:14];
  int openpa_seq [1:2];   // good-form sequence bins (coverage)
  bit openpa_sreq; bit openpa_sp [1:14];   // deferred checks: request and pending flags
  string openpa_mode_arg;
  initial begin
  `ifdef VERILATOR
    openpa_xmode = 1'b0;
  `else
    openpa_xmode = 1'b1;
  `endif
    openpa_cmode = 0;
    if ($value$plusargs("openpa_corrupt=%s", openpa_mode_arg)) begin
      if (openpa_mode_arg == "x") openpa_xmode = 1'b1;
      else if (openpa_mode_arg == "random") openpa_xmode = 1'b0;
      else if (openpa_mode_arg == "zero") begin openpa_xmode = 1'b0; openpa_cmode = 1; end
      else if (openpa_mode_arg == "one") begin openpa_xmode = 1'b0; openpa_cmode = 2; end
      else $display("OPENPA-ERROR +openpa_corrupt=%s: use x, random, zero or one", openpa_mode_arg);
    end
    if (!$value$plusargs("openpa_seed=%d", openpa_seed)) openpa_seed = 1;
    openpa_tr = $test$plusargs("openpa_trace");
    openpa_obs = $test$plusargs("openpa_obs");
    $display("OPENPA-INFO corruption=%0s seed=%0d", openpa_xmode ? "x" : (openpa_cmode == 1 ? "zero" : openpa_cmode == 2 ? "one" : "random"), openpa_seed);
    #0 openpa_kick = 1'b1;
  end
  task automatic openpa_check(input int id, input string msg);
    openpa_n[id] = openpa_n[id] + 1;
    $display("OPENPA-CHECK D%0d @ %0t: %s", id, $time, msg);
  endtask
  task automatic openpa_t(input string msg);
    if (openpa_tr) $display("OPENPA-TRACE @ %0t: %s", $time, msg);
  endtask

  // ---- copies of the design signals the UPF names (4-state, so X is visible)
  always @(isolate or openpa_kick) openpa_ctl_0_isolate = isolate;

  // ---- supply network, switches, supply sets, simstates, power states (one block, evaluated in order)
  always @(openpa_kick or UPF::openpa_port_VA or UPF::openpa_port_VP or UPF::openpa_port_VG) begin : openpa_network
    openpa_net_NA = UPF::openpa_port_VA;   // NA <- port VA
    openpa_net_NP = UPF::openpa_port_VP;   // NP <- port VP
    openpa_net_NG = UPF::openpa_port_VG;   // NG <- port VG
    // supply set AON (also PD_AON.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_AON
      bit nx; int sm;
      sm = (UPF::openpa_net_NA.state == UPF::FULL_ON && UPF::openpa_net_NG.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_AON_sim = sm;
      nx = sm < 5;
      if (openpa_ss_AON_ok && !nx) openpa_ss_AON_ep = openpa_ss_AON_ep + 1;
      openpa_ss_AON_ok = nx;
    end
    // supply set PER (also PD_PER.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_PER
      bit nx; int sm;
      sm = (UPF::openpa_net_NP.state == UPF::FULL_ON && UPF::openpa_net_NG.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_PER_sim = sm;
      nx = sm < 5;
      if (openpa_ss_PER_ok && !nx) openpa_ss_PER_ep = openpa_ss_PER_ep + 1;
      openpa_ss_PER_ok = nx;
    end
    // domain PD_AON: simstate of its primary supply set AON
    if (openpa_dom_PD_AON_ok && !UPF::openpa_ss_AON_ok) openpa_dom_PD_AON_ep = openpa_dom_PD_AON_ep + 1;
    openpa_dom_PD_AON_ok = UPF::openpa_ss_AON_ok;
    openpa_dom_PD_AON_sim = openpa_ss_AON_sim;
    // domain PD_PER: simstate of its primary supply set PER
    if (openpa_dom_PD_PER_ok && !UPF::openpa_ss_PER_ok) openpa_dom_PD_PER_ep = openpa_dom_PD_PER_ep + 1;
    openpa_dom_PD_PER_ok = UPF::openpa_ss_PER_ok;
    openpa_dom_PD_PER_sim = openpa_ss_PER_sim;
  end

  // ---- corruption: registers forced, memories overwritten (rules C1, C3)
  // domain PD_AON (ap_power_slice.upf:3): 0 register(s), 0 memory(ies)
  bit openpa_PD_AON_applied, openpa_PD_AON_valid;
  // The first evaluation counts as a power-up from OFF: registers take the corruption value even when the
  // supplies are already on at time 0 (rule C3), so 4-state and 2-state runs start alike.
  always @(UPF::openpa_dom_PD_AON_ok or openpa_kick) if (!openpa_PD_AON_valid || openpa_PD_AON_applied != UPF::openpa_dom_PD_AON_ok) begin
    openpa_t({"PD_AON ", UPF::openpa_dom_PD_AON_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_AON_ok || !openpa_PD_AON_valid) begin
    end
    if (UPF::openpa_dom_PD_AON_ok) begin
    end
    openpa_PD_AON_valid = 1'b1; openpa_PD_AON_applied = UPF::openpa_dom_PD_AON_ok;
  end
  // domain PD_PER (ap_power_slice.upf:4): 1 register(s), 0 memory(ies)
  bit openpa_PD_PER_applied, openpa_PD_PER_valid;
  logic [0:0] openpa_cv1;   // corruption value for u_timer.irq
  // The first evaluation counts as a power-up from OFF: registers take the corruption value even when the
  // supplies are already on at time 0 (rule C3), so 4-state and 2-state runs start alike.
  always @(UPF::openpa_dom_PD_PER_ok or openpa_kick) if (!openpa_PD_PER_valid || openpa_PD_PER_applied != UPF::openpa_dom_PD_PER_ok) begin
    openpa_t({"PD_PER ", UPF::openpa_dom_PD_PER_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_PER_ok || !openpa_PD_PER_valid) begin
      if (openpa_xmode) openpa_cv1 = 'x; else openpa_cv1 = UPF::openpa_mix(1, UPF::openpa_dom_PD_PER_ep, 0);
      force u_timer.irq = openpa_cv1;
    end
    if (UPF::openpa_dom_PD_PER_ok) begin
      release u_timer.irq;
    end
    openpa_PD_PER_valid = 1'b1; openpa_PD_PER_applied = UPF::openpa_dom_PD_PER_ok;
  end

  // D7 reset check for PD_PER: resets u_timer.reset_n active 0
  bit openpa_PD_PER_rprev, openpa_PD_PER_rp0;
  always @(posedge UPF::openpa_dom_PD_PER_ok or negedge UPF::openpa_dom_PD_PER_ok or posedge u_timer.reset_n or negedge u_timer.reset_n) begin
    if (UPF::openpa_dom_PD_PER_ok && !openpa_PD_PER_rprev) openpa_PD_PER_rp0 = 1'b1;
    if (!UPF::openpa_dom_PD_PER_ok || u_timer.reset_n === 1'b0) openpa_PD_PER_rp0 = 1'b0;
    openpa_PD_PER_rprev = UPF::openpa_dom_PD_PER_ok;
  end

  // ---- checks for set_isolation QUIET (ap_power_slice.upf:18): PD_PER -> PD_AON on 1 port(s)
  bit openpa_ig1_act, openpa_ig1_cyc;
  always @(negedge UPF::openpa_dom_PD_PER_ok) if (!UPF::openpa_dom_PD_PER_ok)
    begin openpa_sp[1] = 1'b1; openpa_sreq = 1'b1; end
  always @(posedge UPF::openpa_ctl_0_isolate or negedge UPF::openpa_ctl_0_isolate or posedge openpa_kick) begin
    if (openpa_ig1_act && !(UPF::openpa_ctl_0_isolate === 1'b1))
      begin openpa_sp[2] = 1'b1; openpa_sreq = 1'b1; end
    if (openpa_ig1_act != (UPF::openpa_ctl_0_isolate === 1'b1)) openpa_t({"QUIET enable ", (UPF::openpa_ctl_0_isolate === 1'b1) ? "active" : "inactive"});
    openpa_ig1_act = (UPF::openpa_ctl_0_isolate === 1'b1);
  end
  always @(negedge UPF::openpa_ss_AON_ok) if (!UPF::openpa_ss_AON_ok)
    begin openpa_sp[3] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 1: u_timer/irq (PD_PER) -> ap_power_slice output timer_irq (PD_AON), isolated by QUIET
  bit openpa_x1_t;
  always @(UPF::openpa_dom_PD_PER_ok or UPF::openpa_dom_PD_AON_ok or UPF::openpa_ctl_0_isolate or UPF::openpa_ss_AON_sim or UPF::openpa_net_NP or UPF::openpa_net_NG) openpa_x1_t = !UPF::openpa_dom_PD_PER_ok && UPF::openpa_dom_PD_AON_ok && !(((UPF::openpa_ctl_0_isolate === 1'b1) && (UPF::openpa_ss_AON_sim == 0))) && !(UPF::openpa_net_NP.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x1_t)
    begin openpa_sp[4] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 2: ap_power_slice input paddr (PD_AON) -> u_timer/paddr (PD_PER), not isolated
  bit openpa_x2_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x2_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x2_t)
    begin openpa_sp[5] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 3: ap_power_slice input pclk (PD_AON) -> u_timer/pclk (PD_PER), not isolated
  bit openpa_x3_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x3_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x3_t)
    begin openpa_sp[6] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 4: ap_power_slice input penable (PD_AON) -> u_timer/penable (PD_PER), not isolated
  bit openpa_x4_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x4_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x4_t)
    begin openpa_sp[7] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 5: ap_power_slice input psel (PD_AON) -> u_timer/psel (PD_PER), not isolated
  bit openpa_x5_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x5_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x5_t)
    begin openpa_sp[8] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 6: ap_power_slice input pwdata (PD_AON) -> u_timer/pwdata (PD_PER), not isolated
  bit openpa_x6_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x6_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x6_t)
    begin openpa_sp[9] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 7: ap_power_slice input pwrite (PD_AON) -> u_timer/pwrite (PD_PER), not isolated
  bit openpa_x7_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x7_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x7_t)
    begin openpa_sp[10] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 8: ap_power_slice input reset_n (PD_AON) -> u_timer/reset_n (PD_PER), not isolated
  bit openpa_x8_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NG) openpa_x8_t = !UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && !(1'b0) && !(UPF::openpa_net_NA.state == UPF::UNDETERMINED || UPF::openpa_net_NG.state == UPF::UNDETERMINED);
  always @(posedge openpa_x8_t)
    begin openpa_sp[11] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 1: PD_PER -> PD_AON (no level shifter strategy, threshold 0)
  bit openpa_l1_t;
  always @(UPF::openpa_dom_PD_PER_ok or UPF::openpa_dom_PD_AON_ok or UPF::openpa_net_NP or UPF::openpa_net_NA) openpa_l1_t = UPF::openpa_dom_PD_PER_ok && UPF::openpa_dom_PD_AON_ok && (UPF::openpa_net_NP.voltage - UPF::openpa_net_NA.voltage > 0 || UPF::openpa_net_NA.voltage - UPF::openpa_net_NP.voltage > 0) && !1'b0;
  always @(posedge openpa_l1_t)
    begin openpa_sp[12] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 2: PD_AON -> PD_PER (no level shifter strategy, threshold 0)
  bit openpa_l2_t;
  always @(UPF::openpa_dom_PD_AON_ok or UPF::openpa_dom_PD_PER_ok or UPF::openpa_net_NA or UPF::openpa_net_NP) openpa_l2_t = UPF::openpa_dom_PD_AON_ok && UPF::openpa_dom_PD_PER_ok && (UPF::openpa_net_NA.voltage - UPF::openpa_net_NP.voltage > 0 || UPF::openpa_net_NP.voltage - UPF::openpa_net_NA.voltage > 0) && !1'b0;
  always @(posedge openpa_l2_t)
    begin openpa_sp[13] = 1'b1; openpa_sreq = 1'b1; end
  always @(negedge UPF::openpa_dom_PD_AON_ok) if (!UPF::openpa_dom_PD_AON_ok)
    begin openpa_sp[14] = 1'b1; openpa_sreq = 1'b1; end

  // ---- observation for differential corruption (+openpa_obs): design-top outputs while the top domain is on
  `ifdef OPENPA_OBS
  longint openpa_obs_after;
  initial if (!$value$plusargs("openpa_obs_after=%d", openpa_obs_after)) openpa_obs_after = 0;
  always @(timer_irq) if (openpa_obs && UPF::openpa_dom_PD_AON_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: timer_irq=%h", $time, timer_irq);
  `else
  initial if ($test$plusargs("openpa_obs")) $display("OPENPA-ERROR +openpa_obs needs the copy compiled with OPENPA_OBS defined (-DOPENPA_OBS or +define+OPENPA_OBS)");
  `endif

  // Icarus 12 runs no named block inside a final block, so the report is a function.
  function automatic void openpa_cover_report();
      int hs, ht, hq;
      hs = 0; ht = 0; hq = 0;
      $display("OPENPA-COVER sequence D1 QUIET: PD_PER isolated before power-down %0d", openpa_seq[1]);
      $display("OPENPA-COVER sequence D2/D7 QUIET: isolation released only after PD_PER was back and reset %0d", openpa_seq[2]);
      if (openpa_seq[1]) hq = hq + 1;
      if (openpa_seq[2]) hq = hq + 1;
      $display("OPENPA-COVER-SUMMARY states=%0d/0 declared_transitions=%0d/0 sequences=%0d/2", hs, ht, hq);
  endfunction

  // ---- settle process: 14 deferred check(s), run after one #0 in a fixed order
  initial forever begin
    wait (openpa_sreq && openpa_kick);
    #0;
    openpa_sreq = 1'b0;
    if (openpa_sp[1]) begin
      openpa_sp[1] = 1'b0;
        if (!UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok) && !(UPF::openpa_ctl_0_isolate === 1'b1)) openpa_check(1, "set_isolation QUIET (ap_power_slice.upf:18): PD_PER went off while the isolation enable isolate was inactive");
        else if (!UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok) && (UPF::openpa_ctl_0_isolate === 1'b1)) begin openpa_seq[1] = openpa_seq[1] + 1; openpa_ig1_cyc = 1'b1; end
    end
    if (openpa_sp[2]) begin
      openpa_sp[2] = 1'b0;
          if (!UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok)) openpa_check(2, "set_isolation QUIET (ap_power_slice.upf:18): isolation released while PD_PER is still off");
          else if (openpa_PD_PER_rp0) openpa_check(7, "set_isolation QUIET (ap_power_slice.upf:18): isolation released after PD_PER powered up but before its reset u_timer.reset_n was asserted");
          else if (openpa_ig1_cyc) openpa_seq[2] = openpa_seq[2] + 1;
          openpa_ig1_cyc = 1'b0;
    end
    if (openpa_sp[3]) begin
      openpa_sp[3] = 1'b0;
      if ((UPF::openpa_ctl_0_isolate === 1'b1) && !UPF::openpa_dom_PD_PER_ok && (UPF::openpa_dom_PD_AON_ok)) openpa_check(6, "set_isolation QUIET (ap_power_slice.upf:18): isolation supply AON lost while clamping");
    end
    if (openpa_sp[4]) begin
      openpa_sp[4] = 1'b0;
      if (openpa_x1_t) openpa_check(9, "u_timer/irq of PD_PER (off) is read by ap_power_slice output timer_irq in PD_AON (on) with no active isolation");
    end
    if (openpa_sp[5]) begin
      openpa_sp[5] = 1'b0;
      if (openpa_x2_t) openpa_check(9, "ap_power_slice input paddr of PD_AON (off) is read by u_timer/paddr in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[6]) begin
      openpa_sp[6] = 1'b0;
      if (openpa_x3_t) openpa_check(9, "ap_power_slice input pclk of PD_AON (off) is read by u_timer/pclk in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[7]) begin
      openpa_sp[7] = 1'b0;
      if (openpa_x4_t) openpa_check(9, "ap_power_slice input penable of PD_AON (off) is read by u_timer/penable in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[8]) begin
      openpa_sp[8] = 1'b0;
      if (openpa_x5_t) openpa_check(9, "ap_power_slice input psel of PD_AON (off) is read by u_timer/psel in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[9]) begin
      openpa_sp[9] = 1'b0;
      if (openpa_x6_t) openpa_check(9, "ap_power_slice input pwdata of PD_AON (off) is read by u_timer/pwdata in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[10]) begin
      openpa_sp[10] = 1'b0;
      if (openpa_x7_t) openpa_check(9, "ap_power_slice input pwrite of PD_AON (off) is read by u_timer/pwrite in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[11]) begin
      openpa_sp[11] = 1'b0;
      if (openpa_x8_t) openpa_check(9, "ap_power_slice input reset_n of PD_AON (off) is read by u_timer/reset_n in PD_PER (on) with no active isolation");
    end
    if (openpa_sp[12]) begin
      openpa_sp[12] = 1'b0;
      if (openpa_l1_t) openpa_check(11, $sformatf("PD_PER (%0d uV) drives PD_AON (%0d uV) on 1 port(s) with no level shifter for this direction", UPF::openpa_net_NP.voltage, UPF::openpa_net_NA.voltage));
    end
    if (openpa_sp[13]) begin
      openpa_sp[13] = 1'b0;
      if (openpa_l2_t) openpa_check(11, $sformatf("PD_AON (%0d uV) drives PD_PER (%0d uV) on 7 port(s) with no level shifter for this direction", UPF::openpa_net_NA.voltage, UPF::openpa_net_NP.voltage));
    end
    if (openpa_sp[14]) begin
      openpa_sp[14] = 1'b0;
      if (!UPF::openpa_dom_PD_AON_ok && (UPF::openpa_dom_PD_PER_ok)) openpa_check(12, "isolate (isolation QUIET) comes from PD_AON, which is off while other domains are on");
    end
  end
  final begin
    $display("OPENPA-SUMMARY D1=%0d D2=%0d D3=%0d D4=%0d D5=%0d D6=%0d D7=%0d D8=%0d D9=%0d D10=%0d D11=%0d D12=%0d D13=%0d D14=%0d", openpa_n[1], openpa_n[2], openpa_n[3], openpa_n[4], openpa_n[5], openpa_n[6], openpa_n[7], openpa_n[8], openpa_n[9], openpa_n[10], openpa_n[11], openpa_n[12], openpa_n[13], openpa_n[14]);
    openpa_cover_report();
    if (!UPF::openpa_armed) $display("OPENPA-WARNING no supply was driven (supply_on/supply_off never called): every domain stayed CORRUPT");
  end
  // verilator lint_on MULTIDRIVEN
`line 25 "ap_peripheral_irq.sv" 0
endmodule

ConceptWhy is stopping the clock of an idle block not enough to save its power?
ConceptWhat does an isolation cell do, and which side powers it?
ConceptGoing down, which comes first?
ConceptWhat happens to the value in a flip-flop whose supply is switched off?
ConceptWhich parts of a chip must stay on while the rest sleeps?

Common Mistakes

Wrong Stop the clock of an idle block and count its power as zero.

Leakage flows whether the clock runs or not.

Fix Switch the supply off, and guard the border.

Wrong Open the clamp as soon as the supply is back.

The flip-flops of the domain hold no known value until they are reset.

Fix Switch on, reset, then open the clamp.

Wrong Route a wake signal through logic of the sleeping domain.

That logic has no power when the event comes.

Fix Keep the whole path from the pin to the controller always on.

Remember

  • A power domain is logic that shares a supply and is switched as one. Switching it off stops leakage and loses its values.
  • An isolation cell, powered by the side that stays on, holds each border wire at a harmless value.
  • Going down: clamp, then switch off. Coming up: switch on, reset, then open the clamp.
  • The power controller, the isolation cells and the whole wake path are always on.

Practice

Report a problem with this page