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-f8-ram1-power.ts

/** Full plane preflight for the distinct RAM1 F8/E9 co-design. */
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{refreshDdrPlaneContacts}from'./ddr-plane-contact-audit'
import{verifyDdrSystemCopper,auditDdrTraceJunctions}from'./check-ddr-system-copper'
import{auditRouteAngles}from'./check-route-angles'
const[dirArg,trialArg,outArg]=process.argv.slice(2),dir=resolve(dirArg!),out=resolve(outArg!),read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),hash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex'),parent=read(`${dir}/candidate.circuit.json`),prior=read(`${dir}/report.json`),host=read(`${dir}/host-bundle.json`),input=read(`${dir}/routing-input.json`),source=read(`${trialArg}/report.json`),a=source.attempts.find((a:any)=>a.byte===1),t=parent.find((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id==='saved_fanout_pcb_group_5_65'),e9={...t,route:a.reuse[0].route,connectsTo:[t.source_trace_id,t.route[0].start_pcb_port_id,'pcb_via_235']},patches:any[]=[];delete e9.connection_name
if(source.parentCircuitSha256!==hash(parent)||a.relocation.errors.length||a.relocation.violations.length||a.reuse[0].physical.errors.length||a.reuse[0].physical.violations.length)throw Error('Conductor preflight invalid')
let child=structuredClone(parent);function replace(after:any,reason:string){const id=`${after.type}:${after[`${after.type}_id`]}`,i=child.findIndex((e:any)=>`${e.type}:${e[`${e.type}_id`]}`===id),before=child[i];if(i<0)throw Error('Missing object');child[i]=after;patches.push({id,before,after,beforeSha256:hash(before),afterSha256:hash(after),reason})}
replace(a.moved,'Opposite diagonal F8 ground launch');replace(a.movedVia,'Move exact standalone F8 barrel with inline via');replace(e9,'E9 source-owned top launch to existing G8 power barrel, two pads per barrel')
let planeError:string|undefined,planePlan:any;try{planePlan=planDdrGroundAntipads(parent.filter((e:any)=>e.type==='pcb_copper_pour'&&e.layer==='inner3'),[{...a.via,net:'foreign-ground'}]);for(const p of planePlan.planes)replace(p,'Foreign F8 ground-barrel antipad in supply plane; default .1524 mm web retained')}catch(e){planeError=String(e)}
const witnesses=structuredClone(prior.planeAudit);for(const p of witnesses)if(['inner1','inner5'].includes(p.layer))for(const c of p.viaContacts)if(Math.hypot(c.x-a.oldVia.x,c.y-a.oldVia.y)<1e-7){c.x=a.via.x;c.y=a.via.y}
let planeAudit:any,contactError:string|undefined;try{planeAudit=refreshDdrPlaneContacts(witnesses,child.filter((e:any)=>e.type==='pcb_copper_pour'),child)}catch(e){contactError=String(e)}
const fresh=[...host.traces,a.moved,e9],ids=new Set(fresh.map((t:any)=>t.pcb_trace_id)),fixed=child.filter((e:any)=>!ids.has(e.pcb_trace_id)||e.type==='pcb_via');fixed.push(a.moved);const physical=verifyDdrSystemCopper(fixed,fresh,input.connections,{},50,{reportSameNetContacts:true}),angles=auditRouteAngles(child.filter((e:any)=>e.type==='pcb_trace')),junctions=auditDdrTraceJunctions(child,input.connections),accepted=!planeError&&!contactError&&!physical.errors.length&&!physical.violations.length&&angles.valid&&junctions.valid,report={captureHash:prior.captureHash,parentCircuitSha256:hash(parent),candidateCircuitSha256:hash(child),sourceTrialSha256:hash(source),accepted,planeError,contactError,planePlan,planeAudit,physical,angles,junctions,hostsPreserved:host.traces.every((t:any)=>child.some((e:any)=>hash(e)===hash(t))),scope:'RAM1-only F8/E9 co-design candidate. Three exact copper replacements and explicit supply antipad; no policy relaxation. Final all60 power-launch audit required before acceptance into a board.'}
mkdirSync(out,{recursive:true});for(const[n,v]of Object.entries({'report.json':report,'candidate.circuit.json':child,'original-copper-replacements.json':{parentCircuitSha256:hash(parent),candidateCircuitSha256:hash(child),replacements:patches}}))writeFileSync(`${out}/${n}`,JSON.stringify(v,null,2));console.log(JSON.stringify({accepted,planeError,contactError,errors:physical.errors,violations:physical.violations.length,angles:angles.valid,junctions:junctions.valid}))