0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
scripts/ddr-verified-seed.ts
import {createHash}from'node:crypto'
import {verifyDdrSystemCopper}from'./check-ddr-system-copper'
export const ddrSeedTraceHash=(traces:any[])=>createHash('sha256').update(JSON.stringify(traces)).digest('hex')
export function resolveDdrTraceNet(trace:any,connections:any[]):string{
const aliases=connections.flatMap(c=>[c.name,c.source_trace_id,c.rootConnectionName,...c.mergedConnectionNames??[]].filter(Boolean).map(alias=>({alias,name:c.name}))).sort((a,b)=>b.alias.length-a.alias.length)
const resolved=new Set<string>()
for(const id of [trace.connection_name,trace.source_trace_id,...trace.connectionNames??[]].filter(Boolean)){
const match=aliases.find(a=>id===a.alias||id.startsWith(a.alias+'_'));if(match)resolved.add(match.name)
}
if(resolved.size!==1)throw Error(`Cannot uniquely resolve seed/host net for ${trace.pcb_trace_id??trace.connection_name}`)
return [...resolved][0]!
}
const clean=(r:ReturnType<typeof verifyDdrSystemCopper>)=>!r.errors.length&&!r.violations.length&&r.angles.valid&&!r.joinedBends.length
/** All seed copper is checked before selection; only complete source-to-every-
* load nets survive. Surviving paths are cloned byte-for-byte in JSON semantics,
* never simplified or normalized. The caller must verify its capture manifest.
*/
export function selectVerifiedDdrSeed({captureHash,bundle,original,leads,connections,expectedNetCount=50}:{captureHash:string;bundle:any;original:any[];leads:any[];connections:any[];expectedNetCount?:number}){
if(bundle.captureHash!==captureHash)throw Error('Seed capture hash mismatch')
if(bundle.layerSpace!=='physical'||!Array.isArray(bundle.traces))throw Error('Seed must contain physical-layer traces')
const ids=bundle.traces.map((t:any)=>t.pcb_trace_id);if(ids.some((id:any)=>!id)||new Set(ids).size!==ids.length)throw Error('Seed trace IDs must be unique and present')
const nets=bundle.traces.map((t:any)=>resolveDdrTraceNet(t,connections))
const report=verifyDdrSystemCopper(original,[...leads,...bundle.traces],connections,{},expectedNetCount)
if(!clean(report))throw Error(`Seed copper is not clean: ${report.errors.length} errors, ${report.violations.length} clearances, ${report.angles.violations.length} angles, ${report.joinedBends.length} joins`)
const connectedNetNames=report.connectivity.filter(c=>c.connected).map(c=>c.name),connected=new Set(connectedNetNames)
const traces=structuredClone(bundle.traces.filter((_:any,i:number)=>connected.has(nets[i])))
const selectedReport=verifyDdrSystemCopper(original,[...leads,...traces],connections,{},expectedNetCount)
if(!clean(selectedReport)||connectedNetNames.some(name=>!selectedReport.connectivity.find(c=>c.name===name)?.connected))throw Error('Selected seed subset lost physical validity or connectivity')
return {traces,connectedNetNames,seedTraceHash:ddrSeedTraceHash(traces),report:selectedReport,discardedIncompleteTraceCount:bundle.traces.length-traces.length}
}