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/shorten-ddr-dqs0.ts

/** Reuse the existing coupled-pair template to remove obsolete overlength tuning. */
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{loadAcceptedOrderedHostContext,auditCompositeHostTopology}from'./ddr-composite-routing-context'
import{fitDqsPairMean}from'./tune-ddr-dqs'
import{auditRouteAngles}from'./check-route-angles'
import{auditDdrTraceJunctions}from'./check-ddr-system-copper'
import{checkHostTerminalContract}from'./route-ddr-sequential'
import{objectHash}from'./improve-ddr-a9-power-launches'
const[capture,parent,ordered,accepted,out]=process.argv.slice(2);if(!out)throw Error('Usage: capture parent ordered-exit accepted-DM-host output')
const c=await loadAcceptedOrderedHostContext(capture,parent,ordered,accepted),connections=c.input.connections.filter((x:any)=>x.ramByte===0&&['DQS_P','DQS_N'].includes(x.ramTerminal)),old=c.host.traces.filter((t:any)=>connections.some((x:any)=>x.name===t.connection_name)),oldIds=new Set(old.map((t:any)=>t.pcb_trace_id)),fixed=c.candidate.filter((e:any)=>!oldIds.has(e.pcb_trace_id)),target=c.measuredDm.totalPlanarMm
if(old.length!==2||connections.length!==2)throw Error('Missing original pair')
const planar=(route:any[])=>route.reduce((sum:number,b:any,i:number)=>{const a=route[i-1];return sum+(a?.route_type==='wire'&&b.route_type==='wire'&&a.layer===b.layer?Math.hypot(b.x-a.x,b.y-a.y):0)},0)
const escapeLengths=connections.map((x:any)=>x.pointsToConnect.reduce((sum:number,p:any)=>{const e=c.candidate.find((e:any)=>e.pcb_breakout_point_id===p.pointId),trace=c.candidate.find((t:any)=>t.type==='pcb_trace'&&t.source_trace_id===e.source_trace_id&&t.route.at(-1)?.layer===p.layer&&Math.hypot(t.route.at(-1).x-p.x,t.route.at(-1).y-p.y)<1e-7);if(!trace)throw Error('Missing actual saved escape');return sum+planar(trace.route)},0))
const auditPath=resolve('/Users/ankan/Documents/Codex/2026-09-10/what-x20/outputs/mt41k512m8da-107-it-p-fanout/scripts/audit-am3352-dqs-pair.ts'),fileHash=()=>createHash('sha256').update(readFileSync(auditPath)).digest('hex'),auditHash=fileHash(),{verifyHostDqsPair}=await import(auditPath)
mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(resolve(out,n),JSON.stringify(v,null,2)+'\n'),attempts:any[]=[];let chosen:any
for(const entryX of[1.9,1.7,1.5]){
 const fitted=fitDqsPairMean(connections,escapeLengths,target,entryX),y=fitted.excursionY,raw=fitted.traces
 const traces=raw.map((t:any)=>({...t,connectsTo:connections.find((x:any)=>x.name===t.connection_name).pointsToConnect.map((p:any)=>p.pointId)})),candidate=c.candidate.map((e:any)=>traces.find((t:any)=>t.pcb_trace_id===e.pcb_trace_id)??e),host={...c.host,traces:c.host.traces.map((e:any)=>traces.find((t:any)=>t.pcb_trace_id===e.pcb_trace_id)??e)}
 if(traces.some((t:any)=>!oldIds.has(t.pcb_trace_id)))throw Error('Pair IDs changed')
 const lengths=traces.map((t:any,i:number)=>planar(t.route)+escapeLengths[i]),actualMean=lengths.reduce((a:number,b:number)=>a+b,0)/2,topology=auditCompositeHostTopology(candidate,host.traces,c.input.connections),allAngles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),allJunctions=auditDdrTraceJunctions(candidate,c.input.connections),terminal=checkHostTerminalContract(host.traces,c.input.connections.filter((x:any)=>host.traces.some((t:any)=>t.connection_name===x.name))),pair=verifyHostDqsPair({...c.input,connections},c.fixed,traces)
 const ok=topology.valid&&allAngles.valid&&allJunctions.valid&&terminal.valid&&pair.status==='pair-geometry-pass'&&Math.abs(actualMean-target)<1e-6&&lengths.every((n:number)=>n<c.measuredDm.nominalMm)&&topology.physical.connectivity.filter((x:any)=>x.connected).length===10
 const summary={entryX,excursionY:y,accepted:ok,targetMm:target,lengthsMm:lengths,meanMm:actualMean,topologyErrors:topology.errors,physicalErrors:topology.physical.errors,violations:topology.physical.violations,angles:allAngles.violations,junctions:allJunctions.joinedBends,pair,terminal};attempts.push(summary)
 if(ok){chosen={candidate,host,traces,topology,allAngles,allJunctions,terminal,summary};break}
}
c.assertUnchanged();if(fileHash()!==auditHash)throw Error('Pair auditor changed')
write('report.json',{accepted:!!chosen,parentCandidateSha256:objectHash(c.candidate),contextEvidence:c.evidence,externalPairAuditorSha256:auditHash,attempts,scope:'Coupled DQS0 shortening to current DM0 planar mean only. Complete byte timing remains invalid due to other overlong/short/missing data routes.'})
if(chosen){write('candidate.circuit.json',chosen.candidate);write('host-bundle.json',chosen.host);write('replacements.json',old.map((before:any)=>({before,after:chosen.traces.find((t:any)=>t.pcb_trace_id===before.pcb_trace_id)})));write('physical-report.json',chosen.topology);write('routing-input.json',{...c.input,obstacles:undefined,traces:chosen.host.traces});}
console.log(JSON.stringify({accepted:!!chosen,attempts:attempts.map(a=>({entryX:a.entryX,y:a.excursionY,lengths:a.lengthsMm,errors:a.physicalErrors.length,violations:a.violations.length,topology:a.topologyErrors.length,pair:a.pair.status}))}));if(!chosen)process.exitCode=1