set_level_shifter: Rules, Thresholds and Combined Cells

A host and its lane exchange the right bits at the wrong voltages. Use the legal modes to find every path needing translation.

You Will Be Able To

  • Read each crossing from driver to receiver in every powered mode.
  • Select direction, threshold and exceptions without adding cells on a local rail.
  • Distinguish simulated shifting and isolation from a request for one combined library cell.
Lesson
W4.10
Time
34 min
Runs on
Your browser
Check
5 questions
One Lane, Three DestinationsStep through the untreated output, the host boundary and the local monitor.
  • Datapath
  • Data
One Lane, Three DestinationsStep through the untreated output, the host boundary and the local monitor. component pmu_soc/d host data on HOST datapath IN incoming shifter component u_lane switchable UNIT datapath SEND outgoing shifter isolation GUARD clamp on HOST component result read on HOST component u_watch/pin read on UNIT raw resultdlane inputresulttranslated datasafe resultecho
  1. component u_laneswitchable UNIT
    • raw result → result
    • result → SEND
    • echo → u_watch/pin
  2. component resultread on HOST
  3. component pmu_soc/dhost data on HOST
    • d → IN
  4. datapath INincoming shifter
    • lane input → u_lane
  5. datapath SENDoutgoing shifter
    • translated data → GUARD
  6. isolation GUARDclamp on HOST
    • safe result → result
  7. component u_watch/pinread on UNIT
  1. Before

    The lane drives result directly. Its host receiver cannot follow the lane supply up and down.

  2. Incoming data

    IN covers d on the way into UNIT. The host drives this path.

  3. Outgoing result

    SEND covers the return path. GUARD also protects result when the lane sleeps.

  4. Local monitor

    echo stays on UNIT all the way to u_watch. The two domain names still describe one voltage.

Read the diagram as text
  • pmu_soc/d: host data on HOST
  • IN: incoming shifter
  • u_lane: switchable UNIT
  • SEND: outgoing shifter
  • GUARD: clamp on HOST
  • result: read on HOST
  • u_watch/pin: read on UNIT
  • u_lane → result: raw result
  • pmu_soc/d → IN: d
  • IN → u_lane: lane input
  • u_lane → SEND: result
  • SEND → GUARD: translated data
  • GUARD → result: safe result
  • u_lane → u_watch/pin: echo

Drawn functional paths. The flags output also shifts, with no clamp in this experiment.

In ECO, pmu_soc reads result=5 even with a missing shifter.

Recorded without strategies

eco unit=0.80 host=1.00 sent=5 result=5 flags=a tap=5

The bits arrive. OpenPA also reports a voltage mismatch.

Recorded with strategies

eco unit=0.80 host=1.00 sent=5 result=5 flags=a tap=5

The same bits arrive with both voltage directions covered.

MODES rowresult → hostd → laneecho → watcher
ECO0.80 → 1.00 V · ■ Shift up1.00 → 0.80 V · ■ Shift down0.80 → 0.80 V · □ Equal
MATCH1.00 → 1.00 V · □ Equal1.00 → 1.00 V · □ Equal1.00 → 1.00 V · □ Equal
BOOST1.20 → 1.00 V · ■ Shift down1.00 → 1.20 V · ■ Shift up1.20 → 1.20 V · □ Equal

Drawn from recorded mode voltages. Filled squares mark voltage pairs beyond 0.10 V. Read each cell from driver to receiver.

Read across ECO and BOOST. Which ports cross into HOST?

Choose the Boundary and Its Ports

In pmu_soc, d enters u_lane. result and flags return to HOST, while echo feeds a local watcher.

In the recorded ECO row, result and tap both carry 5. Only result crosses to HOST. Select PD_UNIT because it owns the interface. Use -elements for candidate ports or instances (IEEE 1801-2024 6.49).

SEND starts with the ports of u_lane. A later update restricts its supply pair.
set_level_shifter SEND -domain PD_UNIT -elements {u_lane} -applies_to outputs -rule both -threshold 0.10 -force_shift -location parent

Here -applies_to inputs follows d. outputs follows the return paths.

Recorded crossings. Follow each arrow.
  u_lane/flags [PD_UNIT] -> pmu_soc output flags [PD_TOP]: no isolation; level shifter SEND
  u_lane/result [PD_UNIT] -> pmu_soc output result [PD_TOP]: isolation GUARD; level shifter SEND
  pmu_soc input d [PD_TOP] -> u_lane/d [PD_UNIT]: no isolation; level shifter IN

The d crossing names IN, while the result crossing names SEND and GUARD.

OptionStart here in pmu_socWhy the choice matters
-domain PD_UNITThe power interface of the laneAnother domain can have its own view of the same connection.
-elements {u_lane}Ports on the named instanceThis includes echo before path filters narrow it.
-elements {u_lane/result}One named portUse this granularity when one output needs its own policy.
-applies_to inputs or outputsDirection relative to the domaind enters the upper boundary. result and flags leave it.

At a lower boundary, parent outputs enter a child. The default admits both directions. Inout ports are excluded.

GUARD supplies the sleep value. Which voltage direction must SEND cover?

In ECO, u_lane drives the host from 0.80 V. BOOST raises that same driver to 1.20 V.

Recorded live data in the three powered modes.
match unit=1.00 host=1.00 sent=3 result=3 flags=c tap=3
eco unit=0.80 host=1.00 sent=5 result=5 flags=a tap=5
boost unit=1.20 host=1.00 sent=9 result=9 flags=6 tap=9

In BOOST, SEND translates down while IN translates up.

The boost row returns result=9 at a 1.00 V host from a 1.20 V lane.

Choose low_to_high for upward translation, high_to_low for downward translation, or both when the order reverses (6.49).

MODES lists the supply pairs the static check can consider together.
create_pst MODES -supplies {VHOST VUNIT}
add_pst_state ECO -pst MODES -state {NOM ECO}
add_pst_state MATCH -pst MODES -state {NOM MATCH}
add_pst_state BOOST -pst MODES -state {NOM BOOST}
add_pst_state SLEEP -pst MODES -state {NOM SLEEP}
Recorded with the strategies removed. L2 checks the declared voltage pairs before simulation.
  answer.upf:4: L2: PD_UNIT -> PD_TOP (2 port(s)) can run at 0.8 V -> 1 V (row ECO), 1.2 V -> 1 V (row BOOST), beyond the 0 V threshold, with no level shifter for that direction (power state table MODES)
  answer.upf:3: L2: PD_TOP -> PD_UNIT (1 port(s)) can run at 1 V -> 0.8 V (row ECO), 1 V -> 1.2 V (row BOOST), beyond the 0 V threshold, with no level shifter for that direction (power state table MODES)

L2 lists ECO and BOOST because their powered endpoints differ.

OpenPA uses MODES here. Without jointly defined states, it may consider all known voltage combinations.

How large must that gap be?

Test the Threshold at Equality

The ECO and BOOST return paths each span 0.20 V.

Both gaps exceed the lab’s 0.10 V limit.

Allow only low_to_high to expose an uncovered downward direction.

Trial thresholdCompare with 0.20 VRecorded D11 count
0.199999 VThe gap is larger.3
0.200000 VThe gap is equal.0
0.200001 VThe gap is smaller.0

Recorded with one direction enabled.

At a threshold of 0.200000 V, D11 counts zero because the gap equals the limit.

Clause 6.49 requires a gap above the threshold, which defaults to zero.

Recorded just below equality. Read the two voltages.
OPENPA-CHECK D11 @ 3000: PD_TOP (1000000 uV) drives PD_UNIT (800000 uV) on 1 port(s) with no level shifter for this direction
OPENPA-CHECK D11 @ 6000: PD_UNIT (1200000 uV) drives PD_TOP (1000000 uV) on 2 port(s) with no level shifter for this direction
OPENPA-CHECK D11 @ 9000: PD_TOP (1000000 uV) drives PD_UNIT (800000 uV) on 1 port(s) with no level shifter for this direction

Suppose VUNIT can rise five percent above nominal. In BOOST it could reach 1.26 V, opening a 0.26 V gap.

The standard uses the specified variation when testing the threshold (6.49, 6.57).

Recorded in OpenPA 0.3.0 with a 0.20 V threshold, five percent variation and no -force_shift.
  u_lane/result [PD_UNIT] -> pmu_soc output result [PD_TOP]: isolation GUARD; level shifter SEND
  answer.upf:36: set_variation is recorded with no effect in simulation: supply variation (6.57) only feeds level-shifter inference; the static L2 check uses nominal voltages

OpenPA records the variation but checks nominal voltages. The result path still names SEND even at nominal equality.

Now follow echo, whose gap stays zero.

Leave the Local Monitor Unshifted

u_watch receives echo in PD_WATCH. Does a different domain need a shifter?

Both domains use UNIT, so raising the lane voltage also raises the watcher voltage.

Name echo with -no_shift to suppress translation there (6.49).

A direct port exception. It requests no cell, so it needs no placement.
set_level_shifter LOCAL -domain PD_UNIT -elements {u_lane/echo} -no_shift

Recorded with broad selection

u_lane/echo [PD_UNIT] -> u_watch/pin [PD_WATCH]: no isolation; level shifter SEND

Before the supply filter or local exception.

Recorded with the exception

u_lane/echo [PD_UNIT] -> u_watch/pin [PD_WATCH]: no isolation

The local crossing has no level-shifter entry.

In ECO, tap=5 even with the shifter removed. The local watcher still sees the lane data.

Recorded for a broad strategy without the local exception.
  answer.upf:31: L2: the level shifter DEFAULT on PD_UNIT -> PD_WATCH (1 port(s)) never sees two different voltages in any known state (power state table MODES); it may be redundant

The L2 row calls the broad shifter redundant because UNIT powers both ends. A named port outranks an instance. At equal granularity, -no_shift wins (5.7.4).

What distinguishes the remaining host paths?

Trace the Driving and Receiving Supplies

u_lane drives three outputs, but only result and flags reach HOST.

Follow each arrow because -source tests the driver supply and -sink tests the receiver supply (6.49).

PathDriver → receiverFit for UNIT → HOST
u_lane/result → hostUNIT → HOSTYes. result sends data back to the host.
u_lane/flags → hostUNIT → HOSTYes. flags makes a second return path.
u_lane/echo → u_watch/pinUNIT → UNITNo. The monitor receives on UNIT.
pmu_soc/d → u_lane/dHOST → UNITNo. This path needs the incoming strategy.

The supply names stay fixed across modes.

The wrong-sink report leaves result with GUARD alone because HOST no longer matches SEND.

Recorded after changing SEND’s sink to UNIT.
  u_lane/result [PD_UNIT] -> pmu_soc output result [PD_TOP]: isolation GUARD
  answer.upf:4: L2: PD_UNIT -> PD_TOP (2 port(s)) can run at 0.8 V -> 1 V (row ECO), 1.2 V -> 1 V (row BOOST), beyond the 0 V threshold, with no level shifter for that direction (power state table MODES)

OpenPA resolves these endpoints through their power and ground nets.

When does the team know enough to add that receiver filter?

Refine an Existing Strategy

The lane team writes SEND before it knows the board’s receiver supply.

Block file

set_level_shifter SEND -domain PD_UNIT -elements {u_lane} -applies_to outputs -rule both -threshold 0.10 -force_shift -location parent

Select lane outputs.

Integration addition

set_level_shifter SEND -domain PD_UNIT -update -source UNIT -sink HOST

Keep UNIT driving HOST.

Before refinement, SEND includes echo.

Recorded before both the supply-pair refinement and the local exception.
  u_lane/echo [PD_UNIT] -> u_watch/pin [PD_WATCH]: no isolation; level shifter SEND
  u_lane/result [PD_UNIT] -> pmu_soc output result [PD_TOP]: isolation GUARD; level shifter SEND
Recorded for the completed policy.
  u_lane/echo [PD_UNIT] -> u_watch/pin [PD_WATCH]: no isolation
  u_lane/result [PD_UNIT] -> pmu_soc output result [PD_TOP]: isolation GUARD; level shifter SEND

Use -update on SEND in PD_UNIT to add the two supply filters (6.49).

The update removes echo from SEND. LOCAL also preserves the bypass if SEND broadens again.

An element update grows the list instead. If SEND starts with result, adding flags keeps both ports selected (6.49).

Where does SEND sit?

Place the Translator and Power Its Two Sides

SEND receives result on UNIT because u_lane drives it. HOST powers the receiving interface. Follow the return arrow into the parent.

Request in 6.49Position in the drawn hierarchyRead it on this design
selfInside the selected domainIN requests the PD_UNIT side. This is the 2024 default.
parentIn the parent for an upper boundarySEND requests the pmu_soc side of the lane boundary.
fanoutIn each receiving fanout domainDraw the path separately for each receiving domain.
otherAcross the interface from the selected domainAt an upper boundary this means its parent.

Drawn placement choices. OpenPA simulates the connections.

Input request

set_level_shifter IN -domain PD_UNIT -applies_to inputs -rule both -threshold 0.10 -force_shift -location self

self puts the intended input translator inside the lane domain.

Return request

set_level_shifter SEND -domain PD_UNIT -elements {u_lane} -applies_to outputs -rule both -threshold 0.10 -force_shift -location parent

parent requests a host-side location for the output translator.

Selected portStrategyOpenPA emission site
u_lane/flagsSENDparent connection
u_lane/resultSENDparent connection
u_lane/dINparent connection

Recorded OpenPA map. Even self is simulated on a parent connection.

In the sleep row, result stays 0 while flags becomes x.

Recorded run. GUARD protects result alone.
guard unit=0.80 host=1.00 sent=7 result=0 flags=8 tap=7
OPENPA-CHECK D9 @ 12000: u_lane/flags of PD_UNIT (off) is read by pmu_soc output flags in PD_TOP (on) with no active isolation
sleep result=0 flags=x

Driver and receiver supply the two sides by default. A cell can request -input_supply, -output_supply and -internal_supply (6.49).

The model corrupts a translator on a failed supply (9.9). The lab uses -force_shift to keep the shifters during optimization.

GUARD holds result at zero. D9 identifies the exposed flags path.

Parent is invalid at design-top and lower-boundary ports (6.49). What happens if an older file omits location?

Read the Defaults and Diagnose a Missing Shifter

An older pmu_soc file names PD_UNIT but omits the shifter options.

Recorded in 4.0 mode

  answer.upf:31: set_level_shifter DEFAULT (domain PD_UNIT) -location: not given; the default is "self" (IEEE 1801-2024 6.49)

The report supplies self.

Recorded in 1.0 mode

  answer.upf:31: set_level_shifter DEFAULT (domain PD_UNIT) -location: not given; UPF 1.0 default "automatic" (UPF 1.0 6.27)

The same omission supplies automatic in OpenPA’s 1.0 mode.

Current defaults admit both port directions, with rule both, threshold zero and location self (6.49).

The 1.0 report gives automatic for location and both for the voltage rule.

The 1.0 threshold also defaults to zero. OpenPA 0.3.0 uses upf_version to select this compatibility behavior (6.61).

Remove the strategies. L2 names both uncovered modes before simulation.

Recorded live checks on the unshifted paths. The quiz can rerun this bench.
OPENPA-CHECK D11 @ 3000: PD_UNIT (800000 uV) drives PD_TOP (1000000 uV) on 2 port(s) with no level shifter for this direction
OPENPA-CHECK D11 @ 3000: PD_TOP (1000000 uV) drives PD_UNIT (800000 uV) on 1 port(s) with no level shifter for this direction

D11 reports both live directions at the same instant, despite ordinary-looking data.

What did you inspect?What can you conclude?What remains to check?
L2 names a pair in MODESAt least one declared powered mode lacks direction coverage.Does the bench actually visit that mode?
D11 names an uncovered pairThe bench reached a live mismatched crossing.Read its two domains and the direction.
D11 stays silentThis run produced no such event.Compare static coverage and cell count too.
The receiver has the right bitsThe digital data arrived for that sample.Check the voltage policy independently.

L2 is OpenPA’s static analysis. D11 is its run-time check.

Return to the shifted run. It visits all four MODES rows. D11 stays at zero while D9 reports the exposed flags path.

Could one library cell implement both functions on result?

Request One Cell for Isolation and Shifting

When u_lane sleeps, result needs a clamp. In BOOST, result needs translation.

The guard row reads result=0 while flags still carries 8. GUARD clamps just one translated path.

Recorded functional strategies

u_lane/result [PD_UNIT] -> pmu_soc output result [PD_TOP]: isolation GUARD; level shifter SEND

The recorded path has GUARD and SEND.

Drawn implementation request

use_interface_cell RESULT_IF -domain PD_UNIT \
  -strategy {GUARD SEND} -elements {u_lane/result} \
  -lib_cells {LS_ISO}

LS_ISO is an illustrative combined-cell name.

use_interface_cell associates a library choice with an isolation strategy, a shifter strategy, or a compatible pair in one domain (6.62).

LS_ISO must have the library definitions for both functions. Use -port_map when its control or supply pins need explicit connections (6.62).

Test of the drawn cellInput and controlReceiver requirement
TranslateLane live, clamp inactivePass the data at the receiving voltage.
IsolateLane sleeping, clamp activeHold the specified clamp with a surviving supply.
Check resourcesRead the library functions and pinsA plain isolation cell alone cannot establish translation.

Drawn library checks.

OpenPA simulates SEND followed by GUARD.

Recorded OpenPA refusal of the drawn mapping.
Refused: answer.upf:36: use_interface_cell is not supported (IEEE 1801-2024 6.62): it replaces the simulation model of isolation and level-shifter cells (9.8, 9.9)

In W4.10.1, check the paths before considering a library mapping.

Try It

Run MATCH, ECO and BOOST. Compare each return path with the incoming d path using the voltage matrix.

Change the data word in ECO. Predict result, flags and tap. D11 checks the voltage direction independently of those values.

Find the sleep row and read the D9 line above it. The powered host loses flags while GUARD keeps result safe.

In W4.10.1, edit the UPF and rerun the checks. A complete solution covers incoming and outgoing data without shifting the local monitor.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: OPENPA-INFO corruption=x seed=1 match unit=1.00 host=1.00 sent=3 result=3 flags=c tap=3 eco unit=0.80 host=1.00 sent=5 result=5 flags=a tap=5 boost unit=1.20 host=1.00 sent=9 result=9 flags=6 tap=9 guard unit=0.80 host=1.00 sent=7 result=0 flags=8 tap=7 OPENPA-CHECK D9 @ 12000: u_lane/flags of PD_UNIT (off) is read by pmu_soc output flags in PD_TOP (on) with no active isolation sleep result=0 flags=x OPENPA-SUMMARY D1=0 D2=0 D3=0 D4=0 D5=0 D6=0 D7=0 D8=0 D9=1 D10=0 D11=0 D12=0 D13=0 D14=0 OPENPA-COVER state pst MODES ECO 2 OPENPA-COVER state pst MODES MATCH 1 OPENPA-COVER state pst MODES BOOST 1 OPENPA-COVER state pst MODES SLEEP 1 OPENPA-COVER transition pst MODES ECO -> BOOST 1 OPENPA-COVER transition pst MODES ECO -> SLEEP 1 OPENPA-COVER transition pst MODES MATCH -> ECO 1 OPENPA-COVER transition pst MODES BOOST -> ECO 1 OPENPA-COVER sequence D1 GUARD: PD_UNIT isolated before power-down 1 OPENPA-COVER sequence D2 GUARD: isolation released only after PD_UNIT was back 0 OPENPA-COVER-SUMMARY states=4/4 declared_transitions=0/0 sequences=1/2
Read the power intent: lesson.upf
upf_version 4.0
set_design_top pmu_soc
create_power_domain PD_TOP -include_scope
create_power_domain PD_UNIT -elements {u_lane}
create_supply_port VHOST -direction in
create_supply_net HOST_N
connect_supply_net HOST_N -ports {VHOST}
create_supply_port VUNIT -direction in
create_supply_net UNIT_N
connect_supply_net UNIT_N -ports {VUNIT}
create_supply_port VKEEP -direction in
create_supply_net KEEP_N
connect_supply_net KEEP_N -ports {VKEEP}
create_supply_port VSS -direction in
create_supply_net GND_N
connect_supply_net GND_N -ports {VSS}
create_supply_set HOST -function {power HOST_N} -function {ground GND_N}
create_supply_set UNIT -function {power UNIT_N} -function {ground GND_N}
create_supply_set KEEP -function {power KEEP_N} -function {ground GND_N}
associate_supply_set HOST -handle PD_TOP.primary
associate_supply_set UNIT -handle PD_UNIT.primary
create_power_domain PD_WATCH -elements {u_watch}
associate_supply_set UNIT -handle PD_WATCH.primary
add_port_state VHOST -state {NOM 1.0}
add_port_state VUNIT -state {ECO 0.8} -state {MATCH 1.0} -state {BOOST 1.2} -state {SLEEP off}
create_pst MODES -supplies {VHOST VUNIT}
add_pst_state ECO -pst MODES -state {NOM ECO}
add_pst_state MATCH -pst MODES -state {NOM MATCH}
add_pst_state BOOST -pst MODES -state {NOM BOOST}
add_pst_state SLEEP -pst MODES -state {NOM SLEEP}
set_level_shifter IN -domain PD_UNIT -applies_to inputs -rule both -threshold 0.10 -force_shift -location self
set_level_shifter SEND -domain PD_UNIT -elements {u_lane} -applies_to outputs -rule both -threshold 0.10 -force_shift -location parent
set_level_shifter SEND -domain PD_UNIT -update -source UNIT -sink HOST
set_level_shifter LOCAL -domain PD_UNIT -elements {u_lane/echo} -no_shift
set_isolation GUARD -domain PD_UNIT -elements {u_lane/result} -applies_to outputs -clamp_value 0 -isolation_signal clamp -isolation_supply HOST -location parent
Read the power-unaware RTL: bridge.sv
module sender(input logic [3:0] d, output wire [3:0] result, flags, echo);
  assign result=d;
  assign flags=~d;
  assign echo=d;
endmodule
module observer(input wire [3:0] pin);
  wire [3:0] sample = pin;
endmodule
module pmu_soc(input logic [3:0] d, input logic clamp, output wire [3:0] result, flags);
  wire [3:0] local_bus;
  sender u_lane(.d(d), .result(result), .flags(flags), .echo(local_bus));
  observer u_watch(.pin(local_bus));
endmodule
What UPF added: 26 objects

4 supply port, 4 supply net, 4 output corruption, 3 level shifter, 1 isolation cell, 2 supply set, 8 dynamic check.

ObjectWhereDetailRuleUPF line
Supply portVHOSTlesson.upf:5
Supply portVUNITlesson.upf:8
Supply portVKEEPlesson.upf:11
Supply portVSSlesson.upf:14
Supply netHOST_Nlesson.upf:5
Supply netUNIT_Nlesson.upf:8
Supply netKEEP_Nlesson.upf:11
Supply netGND_Nlesson.upf:14
Output corruptionu_lane/echofolded away: it can never act where anything can see itC2lesson.upf:4
Output corruptionu_lane/flagsC2lesson.upf:4
Level shifteru_lane/flagsSENDbothlesson.upf:32
Output corruptionu_lane/resultC2lesson.upf:4
Level shifteru_lane/resultSENDbothlesson.upf:32
Isolation cellu_lane/resultGUARD · clamp 0I1-I5lesson.upf:35
Output corruptionu_lane/dC2lesson.upf:3
Level shifteru_lane/dINbothlesson.upf:31
Supply setHOSTlesson.upf:17
Supply setUNITlesson.upf:18
Dynamic checkD1/D2/D6 GUARDD1, D2, D6lesson.upf:35
Dynamic checkD9 crossing 1D9lesson.upf:4
Dynamic checkD9 crossing 2D9lesson.upf:4
Dynamic checkD9 crossing 3D9lesson.upf:4
Dynamic checkD9 crossing 4D9lesson.upf:3
Dynamic checkD11 PD_UNIT->PD_WATCHLOCAL · D11lesson.upf:34
Dynamic checkD11 PD_UNIT->PD_TOPSEND · D11lesson.upf:32
Dynamic checkD11 PD_TOP->PD_UNITIN · D11lesson.upf:31

OpenPA warnings:

  • lesson.upf:4 no isolation on u_lane/echo -> u_watch/pin: domain PD_UNIT can be switched off and PD_WATCH receives its output (check D9 watches this at run time)
  • lesson.upf:4 no isolation on u_lane/flags -> pmu_soc output flags: domain PD_UNIT can be switched off and PD_TOP receives its output (check D9 watches this at run time)
  • D7 does not check PD_UNIT for reset before isolation release: no asynchronous reset found on its registers
Read the power-aware copy that runs (generated by OpenPA 0.3.0): pa_pmu_soc.sv
// pa_pmu_soc.sv: power-aware copy of pmu_soc, generated by OpenPA from lesson.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.
`timescale 1ns/1ps
// ---------------------------------------------------------------------------
// 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_VHOST;   // supply port VHOST (lesson.upf:5)
  supply_net_type openpa_port_VUNIT;   // supply port VUNIT (lesson.upf:8)
  supply_net_type openpa_port_VKEEP;   // supply port VKEEP (lesson.upf:11)
  supply_net_type openpa_port_VSS;   // supply port VSS (lesson.upf:14)
  supply_net_type openpa_net_HOST_N;   // supply net HOST_N
  supply_net_type openpa_net_UNIT_N;   // supply net UNIT_N
  supply_net_type openpa_net_KEEP_N;   // supply net KEEP_N
  supply_net_type openpa_net_GND_N;   // supply net GND_N
  bit openpa_ss_HOST_ok; int unsigned openpa_ss_HOST_ep; int openpa_ss_HOST_st = -1; bit openpa_ss_HOST_multi; int openpa_ss_HOST_sim = 5;   // supply set HOST
  bit openpa_ss_UNIT_ok; int unsigned openpa_ss_UNIT_ep; int openpa_ss_UNIT_st = -1; bit openpa_ss_UNIT_multi; int openpa_ss_UNIT_sim = 5;   // supply set UNIT
  bit openpa_dom_PD_TOP_ok; int unsigned openpa_dom_PD_TOP_ep; int openpa_dom_PD_TOP_sim = 5;   // power domain PD_TOP: ok = powered (simstate not CORRUPT); sim = simstate code (lesson.upf:3)
  bit openpa_dom_PD_UNIT_ok; int unsigned openpa_dom_PD_UNIT_ep; int openpa_dom_PD_UNIT_sim = 5;   // power domain PD_UNIT: ok = powered (simstate not CORRUPT); sim = simstate code (lesson.upf:4)
  bit openpa_dom_PD_WATCH_ok; int unsigned openpa_dom_PD_WATCH_ep; int openpa_dom_PD_WATCH_sim = 5;   // power domain PD_WATCH: ok = powered (simstate not CORRUPT); sim = simstate code (lesson.upf:22)
  // 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"
  int openpa_pst_MODES_row = -1;   // PST MODES (lesson.upf:26)
  logic openpa_ctl_0_clamp;   // copy of clamp (isolation GUARD)
  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 == "VHOST") begin openpa_port_VHOST.state = FULL_ON; openpa_port_VHOST.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = FULL_ON; openpa_port_VUNIT.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = FULL_ON; openpa_port_VKEEP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = FULL_ON; openpa_port_VSS.voltage = openpa_uv(value); return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST") begin openpa_port_VHOST.state = OFF; return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = OFF; return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = OFF; return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = OFF; return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST") begin openpa_port_VHOST.state = PARTIAL_ON; openpa_port_VHOST.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = PARTIAL_ON; openpa_port_VUNIT.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = PARTIAL_ON; openpa_port_VKEEP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = PARTIAL_ON; openpa_port_VSS.voltage = openpa_uv(value); return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST") begin openpa_port_VHOST.state = supply_state; return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = supply_state; return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = supply_state; return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = supply_state; return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST" || name == "HOST_N" || name == "HOST.power" || name == "PD_TOP.primary.power") return openpa_net_HOST_N;
    if (name == "VUNIT" || name == "UNIT_N" || name == "UNIT.power" || name == "PD_UNIT.primary.power" || name == "PD_WATCH.primary.power") return openpa_net_UNIT_N;
    if (name == "VKEEP" || name == "KEEP_N" || name == "KEEP.power") return openpa_net_KEEP_N;
    if (name == "VSS" || name == "GND_N" || name == "HOST.ground" || name == "UNIT.ground" || name == "KEEP.ground" || name == "PD_TOP.primary.ground" || name == "PD_UNIT.primary.ground" || name == "PD_WATCH.primary.ground") return openpa_net_GND_N;
    $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 "bridge.sv" 0
module sender(input logic [3:0] d, output wire [3:0] result, flags, echo);
  assign result=d;
  assign flags=~d;
  assign echo=d;
endmodule
module observer(input wire [3:0] pin);
  wire [3:0] sample = pin;
endmodule
module pmu_soc(input logic [3:0] d, input logic clamp, output wire [3:0] result, flags);
  wire [3:0] local_bus;
  wire [3:0] openpa_u_lane_flags_raw, openpa_u_lane_flags_s1; wire [3:0] openpa_u_lane_result_raw, openpa_u_lane_result_s1, openpa_u_lane_result_s2; wire [3:0] openpa_u_lane_d_s1, openpa_u_lane_d_s2; sender u_lane(.d(openpa_u_lane_d_s2), .result(openpa_u_lane_result_raw), .flags(openpa_u_lane_flags_raw), .echo(local_bus)); openpa_corrupt #(.W(4), .ID(268435464)) openpa_u_lane_flags_cor (.d(openpa_u_lane_flags_raw), .q(openpa_u_lane_flags_s1), .ok(UPF::openpa_dom_PD_UNIT_ok), .ep(UPF::openpa_dom_PD_UNIT_ep)); openpa_ls #(.W(4), .ID(268435465)) openpa_u_lane_flags_ls (.d(openpa_u_lane_flags_s1), .q(flags), .src_ok((UPF::openpa_ss_UNIT_sim == 0)), .dst_ok((UPF::openpa_ss_HOST_sim == 0)), .ep(UPF::openpa_ss_UNIT_ep + UPF::openpa_ss_HOST_ep)); openpa_corrupt #(.W(4), .ID(268435472)) openpa_u_lane_result_cor (.d(openpa_u_lane_result_raw), .q(openpa_u_lane_result_s1), .ok(UPF::openpa_dom_PD_UNIT_ok), .ep(UPF::openpa_dom_PD_UNIT_ep)); openpa_ls #(.W(4), .ID(268435473)) openpa_u_lane_result_ls (.d(openpa_u_lane_result_s1), .q(openpa_u_lane_result_s2), .src_ok((UPF::openpa_ss_UNIT_sim == 0)), .dst_ok((UPF::openpa_ss_HOST_sim == 0)), .ep(UPF::openpa_ss_UNIT_ep + UPF::openpa_ss_HOST_ep)); openpa_iso #(.W(4), .CLAMP(0), .SENSE(1'b1), .ID(268435474)) openpa_u_lane_result_iso (.d(openpa_u_lane_result_s2), .q(result), .en(UPF::openpa_ctl_0_clamp), .sup_ok((UPF::openpa_ss_HOST_sim == 0)), .sup_ep(UPF::openpa_ss_HOST_ep)); openpa_corrupt #(.W(4), .ID(268435480)) openpa_u_lane_d_cor (.d(d), .q(openpa_u_lane_d_s1), .ok(UPF::openpa_dom_PD_TOP_ok), .ep(UPF::openpa_dom_PD_TOP_ep)); openpa_ls #(.W(4), .ID(268435481)) openpa_u_lane_d_ls (.d(openpa_u_lane_d_s1), .q(openpa_u_lane_d_s2), .src_ok((UPF::openpa_ss_HOST_sim == 0)), .dst_ok((UPF::openpa_ss_UNIT_sim == 0)), .ep(UPF::openpa_ss_HOST_ep + UPF::openpa_ss_UNIT_ep));
  observer u_watch(.pin(local_bus));

`line 1 "openpa_overlay.sv" 0
  // ===================================================================================
  // OpenPA overlay for pmu_soc: generated from lesson.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_clamp;
  import UPF::openpa_dom_PD_TOP_ep;
  import UPF::openpa_dom_PD_TOP_ok;
  import UPF::openpa_dom_PD_TOP_sim;
  import UPF::openpa_dom_PD_UNIT_ep;
  import UPF::openpa_dom_PD_UNIT_ok;
  import UPF::openpa_dom_PD_UNIT_sim;
  import UPF::openpa_dom_PD_WATCH_ep;
  import UPF::openpa_dom_PD_WATCH_ok;
  import UPF::openpa_dom_PD_WATCH_sim;
  import UPF::openpa_kick;
  import UPF::openpa_net_GND_N;
  import UPF::openpa_net_HOST_N;
  import UPF::openpa_net_KEEP_N;
  import UPF::openpa_net_UNIT_N;
  import UPF::openpa_pst_MODES_row;
  import UPF::openpa_seed;
  import UPF::openpa_ss_HOST_ep;
  import UPF::openpa_ss_HOST_multi;
  import UPF::openpa_ss_HOST_ok;
  import UPF::openpa_ss_HOST_sim;
  import UPF::openpa_ss_HOST_st;
  import UPF::openpa_ss_UNIT_ep;
  import UPF::openpa_ss_UNIT_multi;
  import UPF::openpa_ss_UNIT_ok;
  import UPF::openpa_ss_UNIT_sim;
  import UPF::openpa_ss_UNIT_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:13];   // 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 @(clamp or openpa_kick) openpa_ctl_0_clamp = clamp;

  // ---- supply network, switches, supply sets, simstates, power states (one block, evaluated in order)
  bit openpa_tg_pst_MODES_row; int openpa_pv_pst_MODES_row = -2;
  always @(openpa_kick or UPF::openpa_port_VHOST or UPF::openpa_port_VUNIT or UPF::openpa_port_VKEEP or UPF::openpa_port_VSS) begin : openpa_network
    openpa_net_HOST_N = UPF::openpa_port_VHOST;   // HOST_N <- port VHOST
    openpa_net_UNIT_N = UPF::openpa_port_VUNIT;   // UNIT_N <- port VUNIT
    openpa_net_KEEP_N = UPF::openpa_port_VKEEP;   // KEEP_N <- port VKEEP
    openpa_net_GND_N = UPF::openpa_port_VSS;   // GND_N <- port VSS
    // supply set HOST (also PD_TOP.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_HOST
      bit nx; int sm;
      sm = (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_GND_N.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_HOST_sim = sm;
      nx = sm < 5;
      if (openpa_ss_HOST_ok && !nx) openpa_ss_HOST_ep = openpa_ss_HOST_ep + 1;
      openpa_ss_HOST_ok = nx;
    end
    // supply set UNIT (also PD_UNIT.primary, PD_WATCH.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_UNIT
      bit nx; int sm;
      sm = (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_GND_N.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_UNIT_sim = sm;
      nx = sm < 5;
      if (openpa_ss_UNIT_ok && !nx) openpa_ss_UNIT_ep = openpa_ss_UNIT_ep + 1;
      openpa_ss_UNIT_ok = nx;
    end
    // domain PD_TOP: simstate of its primary supply set HOST
    if (openpa_dom_PD_TOP_ok && !UPF::openpa_ss_HOST_ok) openpa_dom_PD_TOP_ep = openpa_dom_PD_TOP_ep + 1;
    openpa_dom_PD_TOP_ok = UPF::openpa_ss_HOST_ok;
    openpa_dom_PD_TOP_sim = openpa_ss_HOST_sim;
    // domain PD_UNIT: simstate of its primary supply set UNIT
    if (openpa_dom_PD_UNIT_ok && !UPF::openpa_ss_UNIT_ok) openpa_dom_PD_UNIT_ep = openpa_dom_PD_UNIT_ep + 1;
    openpa_dom_PD_UNIT_ok = UPF::openpa_ss_UNIT_ok;
    openpa_dom_PD_UNIT_sim = openpa_ss_UNIT_sim;
    // domain PD_WATCH: simstate of its primary supply set UNIT
    if (openpa_dom_PD_WATCH_ok && !UPF::openpa_ss_UNIT_ok) openpa_dom_PD_WATCH_ep = openpa_dom_PD_WATCH_ep + 1;
    openpa_dom_PD_WATCH_ok = UPF::openpa_ss_UNIT_ok;
    openpa_dom_PD_WATCH_sim = openpa_ss_UNIT_sim;
    // power state table MODES (lesson.upf:26): rule P4
    openpa_pst_MODES_row = -1;
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_UNIT_N.voltage == 800000)) openpa_pst_MODES_row = 0;   // ECO
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_UNIT_N.voltage == 1000000)) openpa_pst_MODES_row = 1;   // MATCH
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_UNIT_N.voltage == 1200000)) openpa_pst_MODES_row = 2;   // BOOST
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::OFF)) openpa_pst_MODES_row = 3;   // SLEEP
    if (openpa_pst_MODES_row != openpa_pv_pst_MODES_row) begin openpa_tg_pst_MODES_row = ~openpa_tg_pst_MODES_row; openpa_pv_pst_MODES_row = openpa_pst_MODES_row; end
  end

  // ---- corruption: registers forced, memories overwritten (rules C1, C3)
  // domain PD_TOP (lesson.upf:3): 0 register(s), 0 memory(ies)
  bit openpa_PD_TOP_applied, openpa_PD_TOP_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_TOP_ok or openpa_kick) if (!openpa_PD_TOP_valid || openpa_PD_TOP_applied != UPF::openpa_dom_PD_TOP_ok) begin
    openpa_t({"PD_TOP ", UPF::openpa_dom_PD_TOP_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_TOP_ok || !openpa_PD_TOP_valid) begin
    end
    if (UPF::openpa_dom_PD_TOP_ok) begin
    end
    openpa_PD_TOP_valid = 1'b1; openpa_PD_TOP_applied = UPF::openpa_dom_PD_TOP_ok;
  end
  // domain PD_UNIT (lesson.upf:4): 0 register(s), 0 memory(ies)
  bit openpa_PD_UNIT_applied, openpa_PD_UNIT_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_UNIT_ok or openpa_kick) if (!openpa_PD_UNIT_valid || openpa_PD_UNIT_applied != UPF::openpa_dom_PD_UNIT_ok) begin
    openpa_t({"PD_UNIT ", UPF::openpa_dom_PD_UNIT_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_UNIT_ok || !openpa_PD_UNIT_valid) begin
    end
    if (UPF::openpa_dom_PD_UNIT_ok) begin
    end
    openpa_PD_UNIT_valid = 1'b1; openpa_PD_UNIT_applied = UPF::openpa_dom_PD_UNIT_ok;
  end
  // domain PD_WATCH (lesson.upf:22): 0 register(s), 0 memory(ies)
  bit openpa_PD_WATCH_applied, openpa_PD_WATCH_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_WATCH_ok or openpa_kick) if (!openpa_PD_WATCH_valid || openpa_PD_WATCH_applied != UPF::openpa_dom_PD_WATCH_ok) begin
    openpa_t({"PD_WATCH ", UPF::openpa_dom_PD_WATCH_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_WATCH_ok || !openpa_PD_WATCH_valid) begin
    end
    if (UPF::openpa_dom_PD_WATCH_ok) begin
    end
    openpa_PD_WATCH_valid = 1'b1; openpa_PD_WATCH_applied = UPF::openpa_dom_PD_WATCH_ok;
  end

  // ---- checks for set_isolation GUARD (lesson.upf:35): PD_UNIT -> PD_TOP on 1 port(s)
  bit openpa_ig1_act, openpa_ig1_cyc;
  always @(negedge UPF::openpa_dom_PD_UNIT_ok) if (!UPF::openpa_dom_PD_UNIT_ok)
    begin openpa_sp[1] = 1'b1; openpa_sreq = 1'b1; end
  always @(posedge UPF::openpa_ctl_0_clamp or negedge UPF::openpa_ctl_0_clamp or posedge openpa_kick) begin
    if (openpa_ig1_act && !(UPF::openpa_ctl_0_clamp === 1'b1))
      begin openpa_sp[2] = 1'b1; openpa_sreq = 1'b1; end
    if (openpa_ig1_act != (UPF::openpa_ctl_0_clamp === 1'b1)) openpa_t({"GUARD enable ", (UPF::openpa_ctl_0_clamp === 1'b1) ? "active" : "inactive"});
    openpa_ig1_act = (UPF::openpa_ctl_0_clamp === 1'b1);
  end
  always @(negedge UPF::openpa_ss_HOST_ok) if (!UPF::openpa_ss_HOST_ok)
    begin openpa_sp[3] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 1: u_lane/echo (PD_UNIT) -> u_watch/pin (PD_WATCH), not isolated
  bit openpa_x1_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_WATCH_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_GND_N) openpa_x1_t = !UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_WATCH_ok && !(1'b0) && !(UPF::openpa_net_UNIT_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x1_t)
    begin openpa_sp[4] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 2: u_lane/flags (PD_UNIT) -> pmu_soc output flags (PD_TOP), not isolated
  bit openpa_x2_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_TOP_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_GND_N) openpa_x2_t = !UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_TOP_ok && !(1'b0) && !(UPF::openpa_net_UNIT_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x2_t)
    begin openpa_sp[5] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 3: u_lane/result (PD_UNIT) -> pmu_soc output result (PD_TOP), isolated by GUARD
  bit openpa_x3_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_TOP_ok or UPF::openpa_ctl_0_clamp or UPF::openpa_ss_HOST_sim or UPF::openpa_net_UNIT_N or UPF::openpa_net_GND_N) openpa_x3_t = !UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_TOP_ok && !(((UPF::openpa_ctl_0_clamp === 1'b1) && (UPF::openpa_ss_HOST_sim == 0))) && !(UPF::openpa_net_UNIT_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x3_t)
    begin openpa_sp[6] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 4: pmu_soc input d (PD_TOP) -> u_lane/d (PD_UNIT), not isolated
  bit openpa_x4_t;
  always @(UPF::openpa_dom_PD_TOP_ok or UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_net_HOST_N or UPF::openpa_net_GND_N) openpa_x4_t = !UPF::openpa_dom_PD_TOP_ok && UPF::openpa_dom_PD_UNIT_ok && !(1'b0) && !(UPF::openpa_net_HOST_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x4_t)
    begin openpa_sp[7] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 1: PD_UNIT -> PD_WATCH (set_level_shifter LOCAL -no_shift, rule both, threshold 0 uV)
  bit openpa_l1_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_WATCH_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_UNIT_N) openpa_l1_t = UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_WATCH_ok && (UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_UNIT_N.voltage > 0 || UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_UNIT_N.voltage > 0) && !1'b0;
  always @(posedge openpa_l1_t)
    begin openpa_sp[8] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 2: PD_UNIT -> PD_TOP (set_level_shifter SEND, rule both, threshold 100000 uV)
  bit openpa_l2_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_TOP_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_HOST_N) openpa_l2_t = UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_TOP_ok && (UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_HOST_N.voltage > 100000 || UPF::openpa_net_HOST_N.voltage - UPF::openpa_net_UNIT_N.voltage > 100000) && !1'b1;
  always @(posedge openpa_l2_t)
    begin openpa_sp[9] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 3: PD_TOP -> PD_UNIT (set_level_shifter IN, rule both, threshold 100000 uV)
  bit openpa_l3_t;
  always @(UPF::openpa_dom_PD_TOP_ok or UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_net_HOST_N or UPF::openpa_net_UNIT_N) openpa_l3_t = UPF::openpa_dom_PD_TOP_ok && UPF::openpa_dom_PD_UNIT_ok && (UPF::openpa_net_HOST_N.voltage - UPF::openpa_net_UNIT_N.voltage > 100000 || UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_HOST_N.voltage > 100000) && !1'b1;
  always @(posedge openpa_l3_t)
    begin openpa_sp[10] = 1'b1; openpa_sreq = 1'b1; end

  // ---- power states (D8): checked once the bench has driven a supply, after the time step settles
  always @(posedge openpa_tg_pst_MODES_row or negedge openpa_tg_pst_MODES_row or posedge UPF::openpa_armed) if (UPF::openpa_armed)
    begin openpa_sp[11] = 1'b1; openpa_sreq = 1'b1; end
  int openpa_cs1 [0:4]; int openpa_ct1 [0:4][0:4]; int openpa_cp1 = -1, openpa_cc1;   // coverage of pst MODES
  function automatic string openpa_cn1(int i); case (i) 0: return "ECO"; 1: return "MATCH"; 2: return "BOOST"; 3: return "SLEEP"; default: return "<none>"; endcase endfunction
  always @(posedge openpa_tg_pst_MODES_row or negedge openpa_tg_pst_MODES_row or posedge UPF::openpa_armed) if (UPF::openpa_armed)
    begin openpa_sp[12] = 1'b1; openpa_sreq = 1'b1; end
  always @(negedge UPF::openpa_dom_PD_TOP_ok) if (!UPF::openpa_dom_PD_TOP_ok)
    begin openpa_sp[13] = 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 @(result) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: result=%h", $time, result);
  always @(flags) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: flags=%h", $time, flags);
  `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 state pst MODES ECO %0d", openpa_cs1[0]);
      $display("OPENPA-COVER state pst MODES MATCH %0d", openpa_cs1[1]);
      $display("OPENPA-COVER state pst MODES BOOST %0d", openpa_cs1[2]);
      $display("OPENPA-COVER state pst MODES SLEEP %0d", openpa_cs1[3]);
      if (openpa_cs1[4]) $display("OPENPA-COVER state pst MODES <none> %0d", openpa_cs1[4]);
      for (int i = 0; i <= 4; i++) for (int j = 0; j <= 4; j++) if (openpa_ct1[i][j]) $display("OPENPA-COVER transition pst MODES %0s -> %0s %0d", openpa_cn1(i), openpa_cn1(j), openpa_ct1[i][j]);
      $display("OPENPA-COVER sequence D1 GUARD: PD_UNIT isolated before power-down %0d", openpa_seq[1]);
      $display("OPENPA-COVER sequence D2 GUARD: isolation released only after PD_UNIT was back %0d", openpa_seq[2]);
      if (openpa_cs1[0]) hs = hs + 1;
      if (openpa_cs1[1]) hs = hs + 1;
      if (openpa_cs1[2]) hs = hs + 1;
      if (openpa_cs1[3]) hs = hs + 1;
      if (openpa_seq[1]) hq = hq + 1;
      if (openpa_seq[2]) hq = hq + 1;
      $display("OPENPA-COVER-SUMMARY states=%0d/4 declared_transitions=%0d/0 sequences=%0d/2", hs, ht, hq);
  endfunction

  // ---- settle process: 13 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_UNIT_ok && (UPF::openpa_dom_PD_TOP_ok) && !(UPF::openpa_ctl_0_clamp === 1'b1)) openpa_check(1, "set_isolation GUARD (lesson.upf:35): PD_UNIT went off while the isolation enable clamp was inactive");
        else if (!UPF::openpa_dom_PD_UNIT_ok && (UPF::openpa_dom_PD_TOP_ok) && (UPF::openpa_ctl_0_clamp === 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_UNIT_ok && (UPF::openpa_dom_PD_TOP_ok)) openpa_check(2, "set_isolation GUARD (lesson.upf:35): isolation released while PD_UNIT is still off");
          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_clamp === 1'b1) && !UPF::openpa_dom_PD_UNIT_ok && (UPF::openpa_dom_PD_TOP_ok)) openpa_check(6, "set_isolation GUARD (lesson.upf:35): isolation supply HOST lost while clamping");
    end
    if (openpa_sp[4]) begin
      openpa_sp[4] = 1'b0;
      if (openpa_x1_t) openpa_check(9, "u_lane/echo of PD_UNIT (off) is read by u_watch/pin in PD_WATCH (on) with no active isolation");
    end
    if (openpa_sp[5]) begin
      openpa_sp[5] = 1'b0;
      if (openpa_x2_t) openpa_check(9, "u_lane/flags of PD_UNIT (off) is read by pmu_soc output flags in PD_TOP (on) with no active isolation");
    end
    if (openpa_sp[6]) begin
      openpa_sp[6] = 1'b0;
      if (openpa_x3_t) openpa_check(9, "u_lane/result of PD_UNIT (off) is read by pmu_soc output result in PD_TOP (on) with no active isolation");
    end
    if (openpa_sp[7]) begin
      openpa_sp[7] = 1'b0;
      if (openpa_x4_t) openpa_check(9, "pmu_soc input d of PD_TOP (off) is read by u_lane/d in PD_UNIT (on) with no active isolation");
    end
    if (openpa_sp[8]) begin
      openpa_sp[8] = 1'b0;
      if (openpa_l1_t) openpa_check(11, $sformatf("PD_UNIT (%0d uV) drives PD_WATCH (%0d uV) on 1 port(s) with no level shifter for this direction", UPF::openpa_net_UNIT_N.voltage, UPF::openpa_net_UNIT_N.voltage));
    end
    if (openpa_sp[9]) begin
      openpa_sp[9] = 1'b0;
      if (openpa_l2_t) openpa_check(11, $sformatf("PD_UNIT (%0d uV) drives PD_TOP (%0d uV) on 2 port(s) with no level shifter for this direction", UPF::openpa_net_UNIT_N.voltage, UPF::openpa_net_HOST_N.voltage));
    end
    if (openpa_sp[10]) begin
      openpa_sp[10] = 1'b0;
      if (openpa_l3_t) openpa_check(11, $sformatf("PD_TOP (%0d uV) drives PD_UNIT (%0d uV) on 1 port(s) with no level shifter for this direction", UPF::openpa_net_HOST_N.voltage, UPF::openpa_net_UNIT_N.voltage));
    end
    if (openpa_sp[11]) begin
      openpa_sp[11] = 1'b0;
        if (!1'b0)   // suspended while a power switch is undetermined (D10 reports that)
        begin
          if (UPF::openpa_pst_MODES_row == -1) openpa_check(8, "supplies VHOST VUNIT match no row of power state table MODES (lesson.upf:26)");
        end
    end
    if (openpa_sp[12]) begin
      openpa_sp[12] = 1'b0;
        if (!1'b0) begin
          openpa_cc1 = (UPF::openpa_pst_MODES_row < 0) ? 4 : UPF::openpa_pst_MODES_row;
          if (openpa_cc1 != openpa_cp1) begin
            openpa_cs1[openpa_cc1] = openpa_cs1[openpa_cc1] + 1;
            if (openpa_cp1 >= 0) openpa_ct1[openpa_cp1][openpa_cc1] = openpa_ct1[openpa_cp1][openpa_cc1] + 1;
            openpa_cp1 = openpa_cc1;
          end
        end
    end
    if (openpa_sp[13]) begin
      openpa_sp[13] = 1'b0;
      if (!UPF::openpa_dom_PD_TOP_ok && (UPF::openpa_dom_PD_UNIT_ok || UPF::openpa_dom_PD_WATCH_ok)) openpa_check(12, "clamp (isolation GUARD) comes from PD_TOP, 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 13 "bridge.sv" 0
endmodule

Check Yourself

Predict the outputWithout either boundary strategy, what does guard print?
`timescale 1ns/1ps
module tb;
  import UPF::*;
  logic [3:0] d=0; logic clamp=0;
  wire [3:0] result, flags;
  pmu_soc dut(.*);
  task sample(input string mode_name, input real voltage, input logic [3:0] word);
    void'(supply_on("VUNIT",voltage)); d=word; #3;
    $display("%s unit=%0.2f host=1.00 sent=%h result=%h flags=%h tap=%h",mode_name,voltage,d,result,flags,dut.u_watch.pin);
  endtask
  initial begin
    void'(supply_on("VHOST",1.0)); void'(supply_on("VSS",0.0));
    sample("match",1.0,4'h3); sample("eco",0.8,4'h5);
    sample("boost",1.2,4'h9); clamp=1; sample("guard",0.8,4'h7);
    void'(supply_off("VUNIT")); #2; $display("sleep result=%h flags=%h", result,flags);
    #2; $finish;
  end
endmodule
Read included file: pa_pmu_soc.sv
// pa_pmu_soc.sv: power-aware copy of pmu_soc, generated by OpenPA from lesson.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.
`timescale 1ns/1ps
// ---------------------------------------------------------------------------
// 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_VHOST;   // supply port VHOST (lesson.upf:5)
  supply_net_type openpa_port_VUNIT;   // supply port VUNIT (lesson.upf:8)
  supply_net_type openpa_port_VKEEP;   // supply port VKEEP (lesson.upf:11)
  supply_net_type openpa_port_VSS;   // supply port VSS (lesson.upf:14)
  supply_net_type openpa_net_HOST_N;   // supply net HOST_N
  supply_net_type openpa_net_UNIT_N;   // supply net UNIT_N
  supply_net_type openpa_net_KEEP_N;   // supply net KEEP_N
  supply_net_type openpa_net_GND_N;   // supply net GND_N
  bit openpa_ss_HOST_ok; int unsigned openpa_ss_HOST_ep; int openpa_ss_HOST_st = -1; bit openpa_ss_HOST_multi; int openpa_ss_HOST_sim = 5;   // supply set HOST
  bit openpa_ss_UNIT_ok; int unsigned openpa_ss_UNIT_ep; int openpa_ss_UNIT_st = -1; bit openpa_ss_UNIT_multi; int openpa_ss_UNIT_sim = 5;   // supply set UNIT
  bit openpa_dom_PD_TOP_ok; int unsigned openpa_dom_PD_TOP_ep; int openpa_dom_PD_TOP_sim = 5;   // power domain PD_TOP: ok = powered (simstate not CORRUPT); sim = simstate code (lesson.upf:3)
  bit openpa_dom_PD_UNIT_ok; int unsigned openpa_dom_PD_UNIT_ep; int openpa_dom_PD_UNIT_sim = 5;   // power domain PD_UNIT: ok = powered (simstate not CORRUPT); sim = simstate code (lesson.upf:4)
  bit openpa_dom_PD_WATCH_ok; int unsigned openpa_dom_PD_WATCH_ep; int openpa_dom_PD_WATCH_sim = 5;   // power domain PD_WATCH: ok = powered (simstate not CORRUPT); sim = simstate code (lesson.upf:22)
  // 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"
  int openpa_pst_MODES_row = -1;   // PST MODES (lesson.upf:26)
  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 == "VHOST") begin openpa_port_VHOST.state = FULL_ON; openpa_port_VHOST.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = FULL_ON; openpa_port_VUNIT.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = FULL_ON; openpa_port_VKEEP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = FULL_ON; openpa_port_VSS.voltage = openpa_uv(value); return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR supply_on(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR supply_on(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR supply_on(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST") begin openpa_port_VHOST.state = OFF; return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = OFF; return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = OFF; return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = OFF; return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR supply_off(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR supply_off(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR supply_off(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST") begin openpa_port_VHOST.state = PARTIAL_ON; openpa_port_VHOST.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = PARTIAL_ON; openpa_port_VUNIT.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = PARTIAL_ON; openpa_port_VKEEP.voltage = openpa_uv(value); return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = PARTIAL_ON; openpa_port_VSS.voltage = openpa_uv(value); return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR supply_partial_on(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST") begin openpa_port_VHOST.state = supply_state; return 1; end
    if (pad_name == "VUNIT") begin openpa_port_VUNIT.state = supply_state; return 1; end
    if (pad_name == "VKEEP") begin openpa_port_VKEEP.state = supply_state; return 1; end
    if (pad_name == "VSS") begin openpa_port_VSS.state = supply_state; return 1; end
    if (pad_name == "HOST_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): HOST_N already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): HOST.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_TOP.primary.power already has a driver (port VHOST); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): UNIT_N already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): UNIT.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_UNIT.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_WATCH.primary.power already has a driver (port VUNIT); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): KEEP_N already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.power") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): KEEP.power already has a driver (port VKEEP); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "GND_N") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): GND_N already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "HOST.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): HOST.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "UNIT.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): UNIT.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "KEEP.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): KEEP.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_TOP.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_TOP.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_UNIT.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_UNIT.primary.ground already has a driver (port VSS); drive its root supply instead", pad_name); return 0; end
    if (pad_name == "PD_WATCH.primary.ground") begin $display("OPENPA-ERROR set_supply_state(\"%s\"): PD_WATCH.primary.ground already has a driver (port VSS); 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: VHOST VUNIT VKEEP VSS)", 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 == "VHOST" || name == "HOST_N" || name == "HOST.power" || name == "PD_TOP.primary.power") return openpa_net_HOST_N;
    if (name == "VUNIT" || name == "UNIT_N" || name == "UNIT.power" || name == "PD_UNIT.primary.power" || name == "PD_WATCH.primary.power") return openpa_net_UNIT_N;
    if (name == "VKEEP" || name == "KEEP_N" || name == "KEEP.power") return openpa_net_KEEP_N;
    if (name == "VSS" || name == "GND_N" || name == "HOST.ground" || name == "UNIT.ground" || name == "KEEP.ground" || name == "PD_TOP.primary.ground" || name == "PD_UNIT.primary.ground" || name == "PD_WATCH.primary.ground") return openpa_net_GND_N;
    $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 "bridge.sv" 0
module sender(input logic [3:0] d, output wire [3:0] result, flags, echo);
  assign result=d;
  assign flags=~d;
  assign echo=d;
endmodule
module observer(input wire [3:0] pin);
  wire [3:0] sample = pin;
endmodule
module pmu_soc(input logic [3:0] d, input logic clamp, output wire [3:0] result, flags);
  wire [3:0] local_bus;
  wire [3:0] openpa_u_lane_flags_raw; wire [3:0] openpa_u_lane_result_raw; wire [3:0] openpa_u_lane_d_s1; sender u_lane(.d(openpa_u_lane_d_s1), .result(openpa_u_lane_result_raw), .flags(openpa_u_lane_flags_raw), .echo(local_bus)); openpa_corrupt #(.W(4), .ID(268435464)) openpa_u_lane_flags_cor (.d(openpa_u_lane_flags_raw), .q(flags), .ok(UPF::openpa_dom_PD_UNIT_ok), .ep(UPF::openpa_dom_PD_UNIT_ep)); openpa_corrupt #(.W(4), .ID(268435472)) openpa_u_lane_result_cor (.d(openpa_u_lane_result_raw), .q(result), .ok(UPF::openpa_dom_PD_UNIT_ok), .ep(UPF::openpa_dom_PD_UNIT_ep)); openpa_corrupt #(.W(4), .ID(268435480)) openpa_u_lane_d_cor (.d(d), .q(openpa_u_lane_d_s1), .ok(UPF::openpa_dom_PD_TOP_ok), .ep(UPF::openpa_dom_PD_TOP_ep));
  observer u_watch(.pin(local_bus));

`line 1 "openpa_overlay.sv" 0
  // ===================================================================================
  // OpenPA overlay for pmu_soc: generated from lesson.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_dom_PD_TOP_ep;
  import UPF::openpa_dom_PD_TOP_ok;
  import UPF::openpa_dom_PD_TOP_sim;
  import UPF::openpa_dom_PD_UNIT_ep;
  import UPF::openpa_dom_PD_UNIT_ok;
  import UPF::openpa_dom_PD_UNIT_sim;
  import UPF::openpa_dom_PD_WATCH_ep;
  import UPF::openpa_dom_PD_WATCH_ok;
  import UPF::openpa_dom_PD_WATCH_sim;
  import UPF::openpa_kick;
  import UPF::openpa_net_GND_N;
  import UPF::openpa_net_HOST_N;
  import UPF::openpa_net_KEEP_N;
  import UPF::openpa_net_UNIT_N;
  import UPF::openpa_pst_MODES_row;
  import UPF::openpa_seed;
  import UPF::openpa_ss_HOST_ep;
  import UPF::openpa_ss_HOST_multi;
  import UPF::openpa_ss_HOST_ok;
  import UPF::openpa_ss_HOST_sim;
  import UPF::openpa_ss_HOST_st;
  import UPF::openpa_ss_UNIT_ep;
  import UPF::openpa_ss_UNIT_multi;
  import UPF::openpa_ss_UNIT_ok;
  import UPF::openpa_ss_UNIT_sim;
  import UPF::openpa_ss_UNIT_st;
  import UPF::openpa_xmode;
  // ---- mode, seed, trace
  bit openpa_tr, openpa_obs;
  int openpa_n [1:14];
  int openpa_seq [1:1];   // good-form sequence bins (coverage)
  bit openpa_sreq; bit openpa_sp [1:9];   // 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)

  // ---- supply network, switches, supply sets, simstates, power states (one block, evaluated in order)
  bit openpa_tg_pst_MODES_row; int openpa_pv_pst_MODES_row = -2;
  always @(openpa_kick or UPF::openpa_port_VHOST or UPF::openpa_port_VUNIT or UPF::openpa_port_VKEEP or UPF::openpa_port_VSS) begin : openpa_network
    openpa_net_HOST_N = UPF::openpa_port_VHOST;   // HOST_N <- port VHOST
    openpa_net_UNIT_N = UPF::openpa_port_VUNIT;   // UNIT_N <- port VUNIT
    openpa_net_KEEP_N = UPF::openpa_port_VKEEP;   // KEEP_N <- port VKEEP
    openpa_net_GND_N = UPF::openpa_port_VSS;   // GND_N <- port VSS
    // supply set HOST (also PD_TOP.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_HOST
      bit nx; int sm;
      sm = (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_GND_N.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_HOST_sim = sm;
      nx = sm < 5;
      if (openpa_ss_HOST_ok && !nx) openpa_ss_HOST_ep = openpa_ss_HOST_ep + 1;
      openpa_ss_HOST_ok = nx;
    end
    // supply set UNIT (also PD_UNIT.primary, PD_WATCH.primary): IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_UNIT
      bit nx; int sm;
      sm = (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_GND_N.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_UNIT_sim = sm;
      nx = sm < 5;
      if (openpa_ss_UNIT_ok && !nx) openpa_ss_UNIT_ep = openpa_ss_UNIT_ep + 1;
      openpa_ss_UNIT_ok = nx;
    end
    // domain PD_TOP: simstate of its primary supply set HOST
    if (openpa_dom_PD_TOP_ok && !UPF::openpa_ss_HOST_ok) openpa_dom_PD_TOP_ep = openpa_dom_PD_TOP_ep + 1;
    openpa_dom_PD_TOP_ok = UPF::openpa_ss_HOST_ok;
    openpa_dom_PD_TOP_sim = openpa_ss_HOST_sim;
    // domain PD_UNIT: simstate of its primary supply set UNIT
    if (openpa_dom_PD_UNIT_ok && !UPF::openpa_ss_UNIT_ok) openpa_dom_PD_UNIT_ep = openpa_dom_PD_UNIT_ep + 1;
    openpa_dom_PD_UNIT_ok = UPF::openpa_ss_UNIT_ok;
    openpa_dom_PD_UNIT_sim = openpa_ss_UNIT_sim;
    // domain PD_WATCH: simstate of its primary supply set UNIT
    if (openpa_dom_PD_WATCH_ok && !UPF::openpa_ss_UNIT_ok) openpa_dom_PD_WATCH_ep = openpa_dom_PD_WATCH_ep + 1;
    openpa_dom_PD_WATCH_ok = UPF::openpa_ss_UNIT_ok;
    openpa_dom_PD_WATCH_sim = openpa_ss_UNIT_sim;
    // power state table MODES (lesson.upf:26): rule P4
    openpa_pst_MODES_row = -1;
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_UNIT_N.voltage == 800000)) openpa_pst_MODES_row = 0;   // ECO
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_UNIT_N.voltage == 1000000)) openpa_pst_MODES_row = 1;   // MATCH
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::FULL_ON && UPF::openpa_net_UNIT_N.voltage == 1200000)) openpa_pst_MODES_row = 2;   // BOOST
    if (openpa_pst_MODES_row == -1 && (UPF::openpa_net_HOST_N.state == UPF::FULL_ON && UPF::openpa_net_HOST_N.voltage == 1000000) && (UPF::openpa_net_UNIT_N.state == UPF::OFF)) openpa_pst_MODES_row = 3;   // SLEEP
    if (openpa_pst_MODES_row != openpa_pv_pst_MODES_row) begin openpa_tg_pst_MODES_row = ~openpa_tg_pst_MODES_row; openpa_pv_pst_MODES_row = openpa_pst_MODES_row; end
  end

  // ---- corruption: registers forced, memories overwritten (rules C1, C3)
  // domain PD_TOP (lesson.upf:3): 0 register(s), 0 memory(ies)
  bit openpa_PD_TOP_applied, openpa_PD_TOP_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_TOP_ok or openpa_kick) if (!openpa_PD_TOP_valid || openpa_PD_TOP_applied != UPF::openpa_dom_PD_TOP_ok) begin
    openpa_t({"PD_TOP ", UPF::openpa_dom_PD_TOP_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_TOP_ok || !openpa_PD_TOP_valid) begin
    end
    if (UPF::openpa_dom_PD_TOP_ok) begin
    end
    openpa_PD_TOP_valid = 1'b1; openpa_PD_TOP_applied = UPF::openpa_dom_PD_TOP_ok;
  end
  // domain PD_UNIT (lesson.upf:4): 0 register(s), 0 memory(ies)
  bit openpa_PD_UNIT_applied, openpa_PD_UNIT_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_UNIT_ok or openpa_kick) if (!openpa_PD_UNIT_valid || openpa_PD_UNIT_applied != UPF::openpa_dom_PD_UNIT_ok) begin
    openpa_t({"PD_UNIT ", UPF::openpa_dom_PD_UNIT_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_UNIT_ok || !openpa_PD_UNIT_valid) begin
    end
    if (UPF::openpa_dom_PD_UNIT_ok) begin
    end
    openpa_PD_UNIT_valid = 1'b1; openpa_PD_UNIT_applied = UPF::openpa_dom_PD_UNIT_ok;
  end
  // domain PD_WATCH (lesson.upf:22): 0 register(s), 0 memory(ies)
  bit openpa_PD_WATCH_applied, openpa_PD_WATCH_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_WATCH_ok or openpa_kick) if (!openpa_PD_WATCH_valid || openpa_PD_WATCH_applied != UPF::openpa_dom_PD_WATCH_ok) begin
    openpa_t({"PD_WATCH ", UPF::openpa_dom_PD_WATCH_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_WATCH_ok || !openpa_PD_WATCH_valid) begin
    end
    if (UPF::openpa_dom_PD_WATCH_ok) begin
    end
    openpa_PD_WATCH_valid = 1'b1; openpa_PD_WATCH_applied = UPF::openpa_dom_PD_WATCH_ok;
  end
  // crossing 1: u_lane/echo (PD_UNIT) -> u_watch/pin (PD_WATCH), not isolated
  bit openpa_x1_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_WATCH_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_GND_N) openpa_x1_t = !UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_WATCH_ok && !(1'b0) && !(UPF::openpa_net_UNIT_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x1_t)
    begin openpa_sp[1] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 2: u_lane/flags (PD_UNIT) -> pmu_soc output flags (PD_TOP), not isolated
  bit openpa_x2_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_TOP_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_GND_N) openpa_x2_t = !UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_TOP_ok && !(1'b0) && !(UPF::openpa_net_UNIT_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x2_t)
    begin openpa_sp[2] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 3: u_lane/result (PD_UNIT) -> pmu_soc output result (PD_TOP), not isolated
  bit openpa_x3_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_TOP_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_GND_N) openpa_x3_t = !UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_TOP_ok && !(1'b0) && !(UPF::openpa_net_UNIT_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x3_t)
    begin openpa_sp[3] = 1'b1; openpa_sreq = 1'b1; end
  // crossing 4: pmu_soc input d (PD_TOP) -> u_lane/d (PD_UNIT), not isolated
  bit openpa_x4_t;
  always @(UPF::openpa_dom_PD_TOP_ok or UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_net_HOST_N or UPF::openpa_net_GND_N) openpa_x4_t = !UPF::openpa_dom_PD_TOP_ok && UPF::openpa_dom_PD_UNIT_ok && !(1'b0) && !(UPF::openpa_net_HOST_N.state == UPF::UNDETERMINED || UPF::openpa_net_GND_N.state == UPF::UNDETERMINED);
  always @(posedge openpa_x4_t)
    begin openpa_sp[4] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 1: PD_UNIT -> PD_WATCH (no level shifter strategy, threshold 0)
  bit openpa_l1_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_WATCH_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_UNIT_N) openpa_l1_t = UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_WATCH_ok && (UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_UNIT_N.voltage > 0 || UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_UNIT_N.voltage > 0) && !1'b0;
  always @(posedge openpa_l1_t)
    begin openpa_sp[5] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 2: PD_UNIT -> PD_TOP (no level shifter strategy, threshold 0)
  bit openpa_l2_t;
  always @(UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_dom_PD_TOP_ok or UPF::openpa_net_UNIT_N or UPF::openpa_net_HOST_N) openpa_l2_t = UPF::openpa_dom_PD_UNIT_ok && UPF::openpa_dom_PD_TOP_ok && (UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_HOST_N.voltage > 0 || UPF::openpa_net_HOST_N.voltage - UPF::openpa_net_UNIT_N.voltage > 0) && !1'b0;
  always @(posedge openpa_l2_t)
    begin openpa_sp[6] = 1'b1; openpa_sreq = 1'b1; end
  // level shifter check 3: PD_TOP -> PD_UNIT (no level shifter strategy, threshold 0)
  bit openpa_l3_t;
  always @(UPF::openpa_dom_PD_TOP_ok or UPF::openpa_dom_PD_UNIT_ok or UPF::openpa_net_HOST_N or UPF::openpa_net_UNIT_N) openpa_l3_t = UPF::openpa_dom_PD_TOP_ok && UPF::openpa_dom_PD_UNIT_ok && (UPF::openpa_net_HOST_N.voltage - UPF::openpa_net_UNIT_N.voltage > 0 || UPF::openpa_net_UNIT_N.voltage - UPF::openpa_net_HOST_N.voltage > 0) && !1'b0;
  always @(posedge openpa_l3_t)
    begin openpa_sp[7] = 1'b1; openpa_sreq = 1'b1; end

  // ---- power states (D8): checked once the bench has driven a supply, after the time step settles
  always @(posedge openpa_tg_pst_MODES_row or negedge openpa_tg_pst_MODES_row or posedge UPF::openpa_armed) if (UPF::openpa_armed)
    begin openpa_sp[8] = 1'b1; openpa_sreq = 1'b1; end
  int openpa_cs1 [0:4]; int openpa_ct1 [0:4][0:4]; int openpa_cp1 = -1, openpa_cc1;   // coverage of pst MODES
  function automatic string openpa_cn1(int i); case (i) 0: return "ECO"; 1: return "MATCH"; 2: return "BOOST"; 3: return "SLEEP"; default: return "<none>"; endcase endfunction
  always @(posedge openpa_tg_pst_MODES_row or negedge openpa_tg_pst_MODES_row or posedge UPF::openpa_armed) if (UPF::openpa_armed)
    begin openpa_sp[9] = 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 @(result) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: result=%h", $time, result);
  always @(flags) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: flags=%h", $time, flags);
  `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 state pst MODES ECO %0d", openpa_cs1[0]);
      $display("OPENPA-COVER state pst MODES MATCH %0d", openpa_cs1[1]);
      $display("OPENPA-COVER state pst MODES BOOST %0d", openpa_cs1[2]);
      $display("OPENPA-COVER state pst MODES SLEEP %0d", openpa_cs1[3]);
      if (openpa_cs1[4]) $display("OPENPA-COVER state pst MODES <none> %0d", openpa_cs1[4]);
      for (int i = 0; i <= 4; i++) for (int j = 0; j <= 4; j++) if (openpa_ct1[i][j]) $display("OPENPA-COVER transition pst MODES %0s -> %0s %0d", openpa_cn1(i), openpa_cn1(j), openpa_ct1[i][j]);
      if (openpa_cs1[0]) hs = hs + 1;
      if (openpa_cs1[1]) hs = hs + 1;
      if (openpa_cs1[2]) hs = hs + 1;
      if (openpa_cs1[3]) hs = hs + 1;
      $display("OPENPA-COVER-SUMMARY states=%0d/4 declared_transitions=%0d/0 sequences=%0d/0", hs, ht, hq);
  endfunction

  // ---- settle process: 9 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 (openpa_x1_t) openpa_check(9, "u_lane/echo of PD_UNIT (off) is read by u_watch/pin in PD_WATCH (on) with no active isolation");
    end
    if (openpa_sp[2]) begin
      openpa_sp[2] = 1'b0;
      if (openpa_x2_t) openpa_check(9, "u_lane/flags of PD_UNIT (off) is read by pmu_soc output flags in PD_TOP (on) with no active isolation");
    end
    if (openpa_sp[3]) begin
      openpa_sp[3] = 1'b0;
      if (openpa_x3_t) openpa_check(9, "u_lane/result of PD_UNIT (off) is read by pmu_soc output result in PD_TOP (on) with no active isolation");
    end
    if (openpa_sp[4]) begin
      openpa_sp[4] = 1'b0;
      if (openpa_x4_t) openpa_check(9, "pmu_soc input d of PD_TOP (off) is read by u_lane/d in PD_UNIT (on) with no active isolation");
    end
    if (openpa_sp[5]) begin
      openpa_sp[5] = 1'b0;
      if (openpa_l1_t) openpa_check(11, $sformatf("PD_UNIT (%0d uV) drives PD_WATCH (%0d uV) on 1 port(s) with no level shifter for this direction", UPF::openpa_net_UNIT_N.voltage, UPF::openpa_net_UNIT_N.voltage));
    end
    if (openpa_sp[6]) begin
      openpa_sp[6] = 1'b0;
      if (openpa_l2_t) openpa_check(11, $sformatf("PD_UNIT (%0d uV) drives PD_TOP (%0d uV) on 2 port(s) with no level shifter for this direction", UPF::openpa_net_UNIT_N.voltage, UPF::openpa_net_HOST_N.voltage));
    end
    if (openpa_sp[7]) begin
      openpa_sp[7] = 1'b0;
      if (openpa_l3_t) openpa_check(11, $sformatf("PD_TOP (%0d uV) drives PD_UNIT (%0d uV) on 1 port(s) with no level shifter for this direction", UPF::openpa_net_HOST_N.voltage, UPF::openpa_net_UNIT_N.voltage));
    end
    if (openpa_sp[8]) begin
      openpa_sp[8] = 1'b0;
        if (!1'b0)   // suspended while a power switch is undetermined (D10 reports that)
        begin
          if (UPF::openpa_pst_MODES_row == -1) openpa_check(8, "supplies VHOST VUNIT match no row of power state table MODES (lesson.upf:26)");
        end
    end
    if (openpa_sp[9]) begin
      openpa_sp[9] = 1'b0;
        if (!1'b0) begin
          openpa_cc1 = (UPF::openpa_pst_MODES_row < 0) ? 4 : UPF::openpa_pst_MODES_row;
          if (openpa_cc1 != openpa_cp1) begin
            openpa_cs1[openpa_cc1] = openpa_cs1[openpa_cc1] + 1;
            if (openpa_cp1 >= 0) openpa_ct1[openpa_cp1][openpa_cc1] = openpa_ct1[openpa_cp1][openpa_cc1] + 1;
            openpa_cp1 = openpa_cc1;
          end
        end
    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 13 "bridge.sv" 0
endmodule

ConceptWhich check can identify an uncovered BOOST pair before simulation starts?
ConceptThe watcher moves from UNIT to HOST. Which assumption behind the echo exception needs checking?
ConceptWhat can a zero D11 count establish for the shifted run?
ConceptWhat establishes a particular combined library implementation?

Common Mistakes

Wrong Look for wrong data to prove that a shifter is missing.

A digital wire can pass the expected bits between domains even when their supplies differ.

Fix Check static voltage pairs and the run-time D11 report.

Wrong Use low_to_high on every outgoing port.

An outgoing signal can drive a lower voltage after a mode change.

Fix Compare the driver and receiver in each legal state.

Wrong Count a working clamp as evidence of a combined library cell.

Separate behavioral strategies can produce exactly the same clamped value.

Fix Read the mapping request and distinguish it from the simulation result.

Remember

  • Trace each path from driver to receiver in every legal powered mode.
  • Test the direction and the threshold separately. Equality falls outside a strict above-threshold requirement.
  • Use source, sink and exceptions to distinguish real crossings from same-rail paths.
  • Read the static report, live checks and library mapping as different kinds of evidence.

Practice

Report a problem with this page