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/compensate-ddr-clock-e7-host.ts
/** Replay the existing D7 chamfered excursion with the measured E7 local delta. */
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
import { resolve } from 'node:path'
import { objectHash as hash } from './improve-ddr-a9-power-launches'
import { addWestwardTuningExcursion } from './tune-ddr-data-mask'
import { auditCompositeHostTopology } from './ddr-composite-routing-context'
import { auditRouteAngles } from './check-route-angles'
import { auditDdrTraceJunctions } from './check-ddr-system-copper'
const parent=resolve('dist/ddr-twenty-one-power58-current'), local=resolve('dist/ddr-clock-e7-local'), out=resolve('dist/ddr-clock-e7-compensated'), read=(p:string)=>JSON.parse(readFileSync(p,'utf8'))
const original=read(parent+'/candidate.circuit.json'), report=read(parent+'/report.json'), hosts=read(parent+'/host-bundle.json'), input=read(parent+'/routing-input.json'), base=read(local+'/candidate.diagnostic.circuit.json'), localReport=read(local+'/report.json'), inputEvidence=read(local+'/input-evidence.json'), localChange=read(local+'/e7-replacement.json'), oldRecipe=read('dist/ddr-dq7-ordered-retuned/report.json').recipe, originalHost=read('dist/ddr-dq7-ordered-retuned/dq7-replacement.json').before
if(hash(original)!==report.candidateCircuitSha256||hash(original)!==localReport.parentCandidateSha256||hash(hosts.traces)!==inputEvidence.retainedHostsSha256)throw Error('Parent provenance mismatch')
const before=hosts.traces.find((t:any)=>t.source_trace_id==='source_trace_582'), planar=(r:any[])=>r.slice(1).reduce((s:number,b:any,i:number)=>{const a=r[i];return s+(a.route_type==='wire'&&b.route_type==='wire'&&a.layer===b.layer?Math.hypot(a.x-b.x,a.y-b.y):0)},0), reverse=(t:any)=>({...t,route:[...t.route].reverse()}), regenerate=(added:number)=>reverse(addWestwardTuningExcursion(reverse(originalHost),oldRecipe.index,oldRecipe.entry,oldRecipe.exit,added,oldRecipe.sign)), currentAdded=planar(before.route)-planar(originalHost.route), replay=regenerate(currentAdded)
if(replay.route.length!==before.route.length||replay.route.some((p:any,i:number)=>Math.hypot(p.x-before.route[i].x,p.y-before.route[i].y)>1e-8||p.layer!==before.route[i].layer||p.width!==before.route[i].width))throw Error('Current D7 no longer matches authoritative existing excursion')
const delta=planar(localChange.before.route)-planar(localChange.after.route), after={...before,route:regenerate(currentAdded+delta).route}
if(delta<=0||hash(after.route[0])!==hash(before.route[0])||hash(after.route.at(-1))!==hash(before.route.at(-1))||Math.abs(planar(after.route)-planar(before.route)-delta)>1e-8)throw Error('Compensation endpoint or length mismatch')
const candidate=base.map((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===before.pcb_trace_id?after:e), traces=hosts.traces.map((e:any)=>e.pcb_trace_id===before.pcb_trace_id?after:e), connections=input.connections.map((n:any)=>({...n,pointsToConnect:n.pointsToConnect.map((p:any)=>{const e=candidate.find((e:any)=>e.type==='pcb_breakout_point'&&e.pcb_breakout_point_id===p.pointId);return e?{...p,x:e.x,y:e.y,layer:e.layer}:p})})), topology=auditCompositeHostTopology(candidate,traces,connections), angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')), joins=auditDdrTraceJunctions(candidate,connections)
const bounds=(traces:any[])=>{const points=traces.flatMap(t=>t.route.map((p:any)=>({x:p.x,y:p.y,r:p.route_type==='via'?p.via_diameter/2:(p.width??t.width??.12)/2})));return {minX:Math.min(...points.map(p=>p.x-p.r)),maxX:Math.max(...points.map(p=>p.x+p.r)),minY:Math.min(...points.map(p=>p.y-p.r)),maxY:Math.max(...points.map(p=>p.y+p.r))}}
const cacheBounds=[3,5].map(g=>{const select=(c:any[])=>c.filter(e=>e.type==='pcb_trace'&&e.pcb_trace_id.startsWith(`saved_fanout_pcb_group_${g}_`)),old=bounds(select(original)),next=bounds(select(candidate));return {group:g,before:old,after:next,noGrowth:next.minX>=old.minX-1e-8&&next.maxX<=old.maxX+1e-8&&next.minY>=old.minY-1e-8&&next.maxY<=old.maxY+1e-8}})
mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(out+'/'+n,JSON.stringify(v,null,2)+'\n');write('report.json',{accepted:false,hostCompensationValid:topology.valid&&angles.valid&&joins.valid,parentCandidateSha256:hash(original),diagnosticParentSha256:hash(base),candidateCircuitSha256:hash(candidate),previousHostSha256:hash(hosts.traces),hostTracesSha256:hash(traces),hostCount:traces.length,preservedOtherHosts:traces.length-1,deltaMm:delta,beforeHostMm:planar(before.route),afterHostMm:planar(after.route),localBeforeMm:planar(localChange.before.route),localAfterMm:planar(localChange.after.route),totalDeltaMm:planar(after.route)-planar(before.route)-delta,recipe:{...oldRecipe,currentAdded,newAdded:currentAdded+delta},cacheBounds,topology,angles,joins,scope:'D7 host and E7 local compensation verified against actual proposed copper. Full clock-plane qualification remains pending; not accepted.'});write('candidate.diagnostic.circuit.json',candidate);write('host-bundle.json',{...hosts,traces});write('routing-input.json',{...input,connections,traces});write('host-replacement.json',{id:`pcb_trace:${before.pcb_trace_id}`,before,after,beforeSha256:hash(before),afterSha256:hash(after),reason:'Existing chamfered excursion compensates measured shorter RAM0 E7 escape exactly.'})
console.log(JSON.stringify({hostCompensationValid:topology.valid&&angles.valid&&joins.valid,delta,cacheBounds,errors:topology.errors,violations:topology.physical.violations.map((v:any)=>({layer:v.layer,gap:v.gapMm,a:v.aShape.traceId,b:v.bShape.traceId})),candidateHash:hash(candidate)}))
if(hash(read(parent+'/candidate.circuit.json'))!==hash(original)||hash(read(local+'/candidate.diagnostic.circuit.json'))!==hash(base))throw Error('Input changed')