mirror of
https://github.com/diodeinc/pcb.git
synced 2026-09-14 20:17:19 +08:00
4413c9d4d9
* Hydrate V2 deps during migrate * Fix mixed hydrated package resolution * Simplify workspace discovery * Clean up workspace package discovery naming * Update stdlib formatting paths
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
load("units.zen", "Voltage")
|
|
|
|
Severity = enum("error", "warning", "advice")
|
|
|
|
|
|
def voltage_within(
|
|
within: str | Voltage, name: str = "voltage_check", severity: Severity = Severity("error")
|
|
) -> typing.Callable:
|
|
def ensure_voltage_within(_module, net_name: str, voltage: Voltage, within: str | Voltage):
|
|
within = Voltage(within)
|
|
# drop nominal in within:
|
|
within = Voltage(min=within.min, max=within.max)
|
|
# ensure voltage is within within
|
|
err_msg = "Voltage range " + str(voltage) + " of " + net_name + " is not within " + str(within)
|
|
check(voltage in within, err_msg)
|
|
|
|
def check_gen(actual, severity: Severity = severity, name: str = name):
|
|
if hasattr(actual, "NET"):
|
|
check_name = actual.name + "_" + name
|
|
if not actual.voltage:
|
|
return
|
|
voltage = actual.voltage
|
|
net_name = actual.name
|
|
else:
|
|
voltage = Voltage(actual)
|
|
net_name = name
|
|
check_name = name
|
|
builtin.add_electrical_check(
|
|
name=check_name,
|
|
check_fn=ensure_voltage_within,
|
|
inputs={"voltage": voltage, "within": within, "net_name": net_name},
|
|
severity=severity.value,
|
|
)
|
|
|
|
return check_gen
|