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/assemble-ddr-supported-candidate.ts
import {readFileSync,writeFileSync,mkdirSync} from 'node:fs'
import {resolve} from 'node:path'
import {createHash} from 'node:crypto'
import {verifyDdrCapture} from './ddr-capture-provenance'
import {loadDdrSupportRoutingContext} from './ddr-support-routing-context'
import {verifyDdrSystemCopper} from './check-ddr-system-copper'
import {resolveDdrTraceNet} from './ddr-verified-seed'
import {planDdrGroundAntipads} from './ddr-ground-plane-antipads'
import {refreshDdrPlaneContacts} from './ddr-plane-contact-audit'
const [dir,supportPath,hostPath,out,transitionDirectory]=process.argv.slice(2)
if(!dir||!supportPath||!hostPath||!out)throw Error('Usage: capture support-circuit host-bundle output')
const read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),hash=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex')
const {captureHash}=verifyDdrCapture(dir),original=read(resolve(dir,'unrouted.circuit.json')),host=read(hostPath),support=read(supportPath),connections=read(resolve(dir,'routing-input.json')).connections
if(host.captureHash!==captureHash||host.layerSpace!=='physical')throw Error('Host capture mismatch')
const present=new Set(support.filter((e:any)=>e.type==='pcb_trace').map((e:any)=>e.pcb_trace_id)),retained=host.traces.filter((t:any)=>present.has(t.pcb_trace_id))
const context=await loadDdrSupportRoutingContext(dir,supportPath,original,retained,captureHash)
const traces=host.traces.map((t:any)=>{
const name=resolveDdrTraceNet(t,connections),c=connections.find((c:any)=>c.name===name),sourceId=c?.source_trace_id??name
if(!c||c.pointsToConnect.length!==2||!original.some((e:any)=>e.type==='source_trace'&&e.source_trace_id===sourceId))throw Error('Expected complete two-point data connection')
return {...t,source_trace_id:sourceId,connectsTo:c.pointsToConnect.map((p:any)=>p.pointId)}
})
let fixed=context.fixed,planeChanges:any=null
const supportReport=read(resolve(supportPath,'../report.json'))
let planeAudit=supportReport.planeAudit
if(transitionDirectory){
const plan=read(resolve(transitionDirectory,'transition-plan.json')),planes=read(resolve(transitionDirectory,'planes.json')),jsonHash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex')
if(plan.captureHash!==captureHash||plan.parentCircuitSha256!==jsonHash(support)||plan.accepted.length!==1)throw Error('Plane transition provenance mismatch')
const actualVia=plan.accepted[0].via,signal=plan.accepted[0].trace.connection_name
if(!traces.some((t:any)=>t.connection_name===signal&&t.route.some((p:any)=>p.route_type==='via'&&Math.hypot(p.x-actualVia.x,p.y-actualVia.y)<1e-7)))throw Error('Approved transition via absent from host route')
const regenerated=planDdrGroundAntipads(fixed.filter((e:any)=>e.type==='pcb_copper_pour'),[{...actualVia,net:signal}])
if(jsonHash(regenerated.planes)!==jsonHash(planes))throw Error('Unexpected plane geometry change')
fixed=[...fixed.filter((e:any)=>e.type!=='pcb_copper_pour'),...planes]
planeAudit=refreshDdrPlaneContacts(planeAudit,planes,[...fixed,...traces]).map(p=>({...p,foreignConductors:p.foreignConductors+1,minForeignClearanceMm:Math.min(p.minForeignClearanceMm,.1016)}))
planeChanges={transitionPlanSha256:hash(resolve(transitionDirectory,'transition-plan.json')),addedAntipads:regenerated.added,existingContactsRechecked:true}
}
const physical=verifyDdrSystemCopper(fixed,traces,connections,{})
if(physical.errors.length||physical.violations.length||!physical.angles.valid||physical.joinedBends.length)throw Error('Alias-free integrated physical check failed')
const expected=new Set(traces.map((t:any)=>resolveDdrTraceNet(t,connections)))
if([...expected].some(name=>!physical.connectivity.some(c=>c.name===name&&c.connected)))throw Error('Host copper does not complete every represented net')
mkdirSync(out,{recursive:true})
const report={captureHash,planeAudit,planeChanges,inheritedPlaneAuditFromSha256:hash(resolve(supportPath,'../report.json')),hostTracesSha256:createHash('sha256').update(JSON.stringify(traces)).digest('hex'),dropReplacementsSha256:supportReport.dropReplacementsSha256,aliases:{},supportCircuitSha256:hash(supportPath),hostBundleSha256:hash(hostPath),physical,externalAliasesUsed:false,scope:'Integrated partial signal/power candidate. Unrouted nets, complete timing, remaining power launches, fabrication and SI unqualified.'}
writeFileSync(resolve(out,'candidate.circuit.json'),JSON.stringify([...fixed,...traces],null,2)+'\n')
writeFileSync(resolve(out,'host-bundle.json'),JSON.stringify({captureHash,layerSpace:'physical',traces},null,2)+'\n')
writeFileSync(resolve(out,'report.json'),JSON.stringify(report,null,2)+'\n')
console.log(JSON.stringify({connected:physical.connectivity.filter(c=>c.connected).length,errors:physical.errors.length,violations:physical.violations.length,externalAliasesUsed:false}))