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/prepare-ddr-d14-checked-transition.ts

/** Revalidate the existing checked CPU-prefix template against the revised RAM board. */
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{planDdrGroundAntipads}from'./ddr-ground-plane-antipads'
import{verifyDdrSystemCopper}from'./check-ddr-system-copper'
import{auditHostSelfContacts}from'./audit-ddr-host-self-contacts'
import{classifyHostFixedContact}from'./audit-ddr-host-fixed-contacts'
const[dir,templateDir,out]=process.argv.slice(2),bound:Record<string,string>={},fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{p=resolve(p);bound[p]=fh(p);return JSON.parse(readFileSync(p,'utf8'))},hash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex'),c=read(resolve(dir,'candidate.circuit.json')),h=read(resolve(dir,'host-bundle.json')),i=read(resolve(dir,'routing-input.json')),r=read(resolve(dir,'report.json')),old=read(resolve(templateDir,'report.json')),connection=i.connections.find((c:any)=>c.source_trace_id==='source_trace_692'),source=connection.pointsToConnect.find((p:any)=>p.x>0),target=connection.pointsToConnect.find((p:any)=>p.x<0),trace={...old.trace,route:old.trace.route.map((p:any)=>p.route_type==='via'?{...p,to_layer:target.layer}:p.layer==='inner6'?{...p,layer:target.layer}:p)},viaPoint=trace.route.find((p:any)=>p.route_type==='via'),via={x:viaPoint.x,y:viaPoint.y}
if(!r.accepted||!old.accepted||r.captureHash!==old.captureHash||h.traces.length!==15||source.layer!=='inner4'||!['inner2','inner6'].includes(target.layer)||trace.source_trace_id!==connection.source_trace_id||Math.hypot(trace.route[0].x-source.x,trace.route[0].y-source.y)>1e-7)throw Error('Template/current source differs')
const planes=planDdrGroundAntipads(c.filter((e:any)=>e.type==='pcb_copper_pour'),[{x:via.x,y:via.y,net:'DDR_D14'}]),ids=new Set(h.traces.map((t:any)=>t.pcb_trace_id)),fixed=c.filter((e:any)=>!ids.has(e.pcb_trace_id)&&e.type!=='pcb_copper_pour'),physical=verifyDdrSystemCopper([...fixed,...planes.planes],[...h.traces,trace],i.connections,{},50,{reportSameNetContacts:true}),contacts=(physical.sameNetContacts??[]).filter((x:any)=>x.aShape.traceId===trace.pcb_trace_id||x.bShape.traceId===trace.pcb_trace_id).map(x=>classifyHostFixedContact(x,trace)),endpoint=c.find((e:any)=>e.pcb_breakout_point_id===source.pointId),same=(p:any)=>p.layer===source.layer&&Math.hypot(p.x-source.x,p.y-source.y)<1e-7,terminalOnly=contacts.length===1&&contacts.every(x=>{const saved=fixed.find((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===x.fixedTraceId);return saved?.source_trace_id===endpoint?.source_trace_id&&same(saved.route.at(-1))&&[x.hostShape.a,x.hostShape.b].some(same)&&[x.fixedShape.a,x.fixedShape.b].some(same)}),selfContacts=auditHostSelfContacts([...h.traces,trace]),clean=terminalOnly&&selfContacts.valid&&!physical.errors.length&&!physical.violations.length&&physical.angles.valid&&!physical.joinedBends.length
const planar=(r:any[])=>r.slice(1).reduce((n:number,b:any,j:number)=>{const a=r[j];return n+(a.route_type==='wire'&&b.route_type==='wire'&&a.layer===b.layer?Math.hypot(a.x-b.x,a.y-b.y):0)},0),escape=(p:any)=>{const e=c.find((e:any)=>e.pcb_breakout_point_id===p.pointId),t=c.find((e:any)=>e.type==='pcb_trace'&&e.source_trace_id===c.find((x:any)=>x.pcb_breakout_point_id===p.pointId)?.source_trace_id);if(!e||!t)throw Error('Missing source escape');return planar(t.route)},dx=Math.abs(via.x-target.x),dy=Math.abs(via.y-target.y),budget={ramEscapeMm:escape(target),cpuEscapeMm:escape(source),transitionMm:planar(trace.route),remainingOctileMm:Math.max(dx,dy)+(Math.SQRT2-1)*Math.min(dx,dy),nominalMm:27.3001,targetPlanarMm:27}
mkdirSync(out,{recursive:true});writeFileSync(resolve(out,'transition-plan.json'),JSON.stringify({captureHash:r.captureHash,parentCircuitSha256:hash(c),hostTracesSha256:hash(h.traces),inputHashes:bound,connection,accepted:clean?[{trace,via,source,target,budget,terminalOnly,selfContacts,contacts,addedAntipads:planes.added}]:[],physical,scope:'Existing exact checked CPU-prefix template revalidated; D14RAMinner6 continuation still pending.'},null,2));writeFileSync(resolve(out,'planes.json'),JSON.stringify(planes.planes,null,2));for(const[p,h]of Object.entries(bound))if(fh(p)!==h)throw Error('Input changed');console.log(JSON.stringify({clean,budget,errors:physical.errors.length,violations:physical.violations.length}));if(!clean)process.exitCode=1