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-trunk-order-variants.ts
import {currentDdrTrunkContract} from './ddr-current-trunk-contract'
/** Explicit planning contracts for the two RAM traversal orders. No copper edits. */
import {readFileSync,writeFileSync,mkdirSync} from 'node:fs'
import {resolve} from 'node:path'
import {createHash} from 'node:crypto'
const[captureArg,boardArg,outArg]=process.argv.slice(2)
if(!captureArg||!boardArg||!outArg)throw Error('Usage: capture current-board output')
const capture=resolve(captureArg),board=resolve(boardArg),out=resolve(outArg),read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),hash=(v:any)=>createHash('sha256').update(JSON.stringify(v)).digest('hex')
const input=read(`${board}/routing-input.json`),candidate=read(`${board}/candidate.circuit.json`),manifest=read(`${board}/current-evidence-manifest.json`),contract=currentDdrTrunkContract(read(`${capture}/forced-trunk-contract.json`),input,candidate),directions=read(`${board}/trunk-direction-audit.json`)
if(hash(candidate)!==manifest.candidateCircuitSha256||directions.candidateCircuitSha256!==hash(candidate)||hash(input)!==manifest.files['routing-input.json'])throw Error('Stale parent or direction audit')
mkdirSync(out,{recursive:true})
const variants=[]
for(const order of [[0,1],[1,0]]){
const connections=structuredClone(input.connections),trunks=[]
for(const t of contract.forcedTrunks){
const firstByte=order[0]!,lastByte=order[1]!,ids=[t.firstConnection,t.secondConnection],first=connections.find((c:any)=>c.name===ids[firstByte]),last=connections.find((c:any)=>c.name===ids[lastByte]),firstTap=t[`ram${firstByte}Tap`],lastTap=t[`ram${lastByte}Tap`]
if(!first||!last)throw Error('Missing mapped shared branch')
const cpu=first.pointsToConnect.find((p:any)=>p.pointId===t.cpuPoint.pointId)
if(!cpu)throw Error('Missing actual CPU endpoint')
for(const tap of [firstTap,lastTap]){const e=candidate.find((e:any)=>e.pcb_breakout_point_id===tap.pointId);if(!e||e.layer!==tap.layer||Math.hypot(e.x-tap.x,e.y-tap.y)>1e-7)throw Error('Stale tap')}
first.pointsToConnect=[cpu,firstTap];last.pointsToConnect=[firstTap,lastTap]
first.rootConnectionName=first.name;last.rootConnectionName=first.name
const heading=firstByte===0?90:270,tapRows=directions.rows.filter((r:any)=>r.terminal===t.terminal)
trunks.push({terminal:t.terminal,order:[`RAM${firstByte}`,`RAM${lastByte}`],firstConnection:first.name,secondConnection:last.name,cpuPoint:cpu,firstTap,lastTap,layer:firstTap.layer,interRamStraightHeadingDegrees:heading,straightInterRamDirectionPermittedAtBothTaps:tapRows.length===2&&tapRows.every((r:any)=>r.options.some((o:any)=>o.incomingTravelDegrees===heading&&o.outgoingTravelDegrees===heading)),terminationAfter:`RAM${lastByte}`,terminationImplemented:false})
}
const name=`cpu-ram${order[0]}-ram${order[1]}`,v={name,candidateCircuitSha256:hash(candidate),parentRoutingInputSha256:hash(input),connections,trunks,scope:'Planning-only ordered branch constraints using current physical endpoints. Requires fresh actual-copper obstacle projection, explicit directed junctions, termination and full physical/timing validation before routing or acceptance. Existing board copper and public profiles are unchanged.'}
writeFileSync(`${out}/${name}.json`,JSON.stringify(v,null,2)+'\n')
variants.push({name,sha256:hash(v),sharedSignalCount:trunks.length,straightInterRamDirectionPermittedAtBothTaps:trunks.filter(t=>t.straightInterRamDirectionPermittedAtBothTaps).length})
}
writeFileSync(`${out}/report.json`,JSON.stringify({candidateCircuitSha256:hash(candidate),variants,acceptedCopper:false},null,2)+'\n')
console.log(JSON.stringify(variants))