verify: model-driven pin checks (contention / undriven / NC-wired)

New bsdl_check.{hpp,cpp}: check_pin_specs(System*) walks the nets and uses
each pin's PinSpec direction/function to flag DriveContention (>=2 push-pull
output drivers), UndrivenNet (a multi-pin net with input(s) but no driver),
and NcWired (a no-connect pin wired onto a multi-pin net). Added as a pass in
`verify`; AnomalyKind extended accordingly. Nets with no direction data are
skipped, so un-modelled parts produce no noise. Covered by test_bsdl_check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 15:15:11 +02:00
parent 943b808a75
commit 5caa4c530d
6 changed files with 241 additions and 4 deletions

View File

@@ -20,9 +20,12 @@ const char *group_kind_name(GroupKind k) {
const char *anomaly_kind_name(AnomalyKind k) {
switch (k) {
case AnomalyKind::DiffPairOrphan: return "diff-pair-orphan";
case AnomalyKind::BusGap: return "bus-gap";
case AnomalyKind::DiffBusGap: return "diff-bus-gap";
case AnomalyKind::DiffPairOrphan: return "diff-pair-orphan";
case AnomalyKind::BusGap: return "bus-gap";
case AnomalyKind::DiffBusGap: return "diff-bus-gap";
case AnomalyKind::DriveContention: return "drive-contention";
case AnomalyKind::UndrivenNet: return "undriven-net";
case AnomalyKind::NcWired: return "nc-wired";
}
return "?";
}

View File

@@ -31,6 +31,9 @@ enum class AnomalyKind {
DiffPairOrphan, ///< X_P present without X_N (or vice versa).
BusGap, ///< NAME[0..N] has a missing index inside the range.
DiffBusGap, ///< Diff bus MDI[0..3]_P/N is missing one of its lanes.
DriveContention, ///< A net has ≥2 push-pull output (Out) drivers.
UndrivenNet, ///< A net has input(s) but no driver (Out/Bidir/Power).
NcWired, ///< A no-connect pin is wired onto a multi-pin net.
};
struct Anomaly {

111
src/system/bsdl_check.cpp Normal file
View File

@@ -0,0 +1,111 @@
#include "bsdl_check.hpp"
#include "modules.hpp"
#include "nets.hpp"
#include "parts.hpp"
#include "pin_spec.hpp"
#include "pins.hpp"
#include "signals.hpp"
#include "system.hpp"
#include <string>
#include <vector>
namespace {
std::string pin_label(const Pin *p)
{
std::string part = (p && p->prnt) ? p->prnt->name : std::string("?");
return part + "/" + (p ? p->name : std::string("?"));
}
std::string join_labels(const std::vector<Pin *> &pins)
{
std::string s;
for (const Pin *p : pins)
s += (s.empty() ? "" : ", ") + pin_label(p);
return s;
}
} // namespace
std::vector<Anomaly> check_pin_specs(System *sys)
{
std::vector<Anomaly> out;
if (!sys)
return out;
for (const Net &net : compute_all_nets(sys)) {
std::vector<Pin *> pins;
std::vector<Signal *> sigs;
Module *mod = nullptr;
std::string label;
for (const auto &mp : net.members) {
if (!mod)
mod = mp.first;
sigs.push_back(mp.second);
if (label.empty() && mp.first && mp.second)
label = mp.first->name + "/" + mp.second->name;
for (auto &kv : *mp.second)
pins.push_back(kv.second);
}
if (pins.size() < 2)
continue; // singleton net — nothing to compare
int outs = 0, drivers = 0, ins = 0, known = 0;
std::vector<Pin *> out_pins, in_pins, nc_pins;
for (Pin *p : pins) {
const PinSpec &s = p->spec;
if (s.function == PinFunction::NoConnect)
nc_pins.push_back(p);
if (s.direction == PinDirection::Unknown)
continue;
++known;
switch (s.direction) {
case PinDirection::Out: ++outs; ++drivers; out_pins.push_back(p); break;
case PinDirection::Bidir: ++drivers; break;
case PinDirection::Power: ++drivers; break;
case PinDirection::In: ++ins; in_pins.push_back(p); break;
default: break;
}
}
// A no-connect pin that is nonetheless on a multi-pin net.
for (Pin *p : nc_pins) {
Anomaly a;
a.kind = AnomalyKind::NcWired;
a.module = mod;
a.involved = sigs;
a.message = pin_label(p) + " is marked no-connect but wired to net " + label;
out.push_back(std::move(a));
}
if (!known)
continue; // no direction data on this net — skip drive checks
if (outs >= 2) {
Anomaly a;
a.kind = AnomalyKind::DriveContention;
a.module = mod;
a.involved = sigs;
a.message = "net " + label + ": " + std::to_string(outs)
+ " output drivers (" + join_labels(out_pins) + ")";
out.push_back(std::move(a));
}
if (ins >= 1 && drivers == 0) {
Anomaly a;
a.kind = AnomalyKind::UndrivenNet;
a.module = mod;
a.involved = sigs;
a.message = "net " + label + ": input(s) with no driver ("
+ join_labels(in_pins) + ")";
out.push_back(std::move(a));
}
}
return out;
}

19
src/system/bsdl_check.hpp Normal file
View File

@@ -0,0 +1,19 @@
#ifndef _BSDL_CHECK_HPP_
#define _BSDL_CHECK_HPP_
#include "analysis.hpp" // Anomaly, AnomalyKind
#include <vector>
class System;
// Model-driven pin checks over the system's nets, using the PinSpec
// direction/function populated by connector or BSDL models. Emits:
// - DriveContention : a net with ≥2 push-pull output drivers;
// - UndrivenNet : a multi-pin net with input(s) but no driver;
// - NcWired : a no-connect pin wired onto a multi-pin net.
// Read-only; nets with no direction data are skipped (no false positives on
// un-modelled parts).
std::vector<Anomaly> check_pin_specs(System *sys);
#endif // _BSDL_CHECK_HPP_

View File

@@ -9,6 +9,7 @@
#include "system/persist.hpp"
#include "system/pin_role.hpp"
#include "system/bsdl_model.hpp"
#include "system/bsdl_check.hpp"
#include "system/pins.hpp"
#include "system/signals.hpp"
#include "system/system.hpp"
@@ -295,8 +296,16 @@ void Tui::RegisterCommands() {
+ " orphan pin(s) at import ("
+ std::to_string(orph_imported) + " imported NC, "
+ std::to_string(orph_dropped) + " dropped singleton).");
// Model-driven pin checks (drive contention / undriven net / NC-wired)
// from the PinSpec direction/function populated by connector/BSDL models.
auto pin_anoms = check_pin_specs(sys.get());
for (const auto &a : pin_anoms)
Print(" [" + std::string(anomaly_kind_name(a.kind)) + "] " + a.message);
Print("verify: " + std::to_string(pin_anoms.size())
+ " model-driven pin anomaly(ies).");
}, true,
"check pin roles locally and signal-type consistency across bridged nets" };
"check pin roles, bridged-net consistency, and model-driven pin specs (contention/undriven/NC)" };
commands["dashboard"] = { {}, [this](auto &) {
screen_idx = 4;