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/audit-ddr-trunk-directions.ts
import {currentDdrTrunkContract} from './ddr-current-trunk-contract'
/** Directed CPU→RAM0→RAM1 junction feasibility, not a route generator. */
import {readFileSync,writeFileSync} from 'node:fs'
import {resolve} from 'node:path'
import {createHash} from 'node:crypto'
const heading=(a:any,b:any)=>(Math.atan2(b.y-a.y,b.x-a.x)*180/Math.PI+360)%360
const turn=(a:number,b:number)=>Math.abs((a-b+540)%360-180)
export function trunkHeadingOptions(branchHeading:number){
if(!Number.isFinite(branchHeading)||Math.abs(branchHeading/45-Math.round(branchHeading/45))>1e-6)throw Error('Non-octilinear branch')
branchHeading=((Math.round(branchHeading/45)*45)%360+360)%360
const result:Array<{incomingTravelDegrees:number;outgoingTravelDegrees:number}>=[]
for(let incoming=0;incoming<360;incoming+=45)for(let outgoing=0;outgoing<360;outgoing+=45){
// Both paths driven from the CPU must obey the maximum-turn rule. Two
// coincident outgoing rays are not a separated branch junction.
if(turn(incoming,branchHeading)<=45&&turn(incoming,outgoing)<=45&&turn(outgoing,branchHeading)>1e-6)result.push({incomingTravelDegrees:incoming,outgoingTravelDegrees:outgoing})
}
return result
}
if(import.meta.main){
const [captureArg,boardArg]=process.argv.slice(2);if(!captureArg||!boardArg)throw Error('Usage: capture board')
const capture=resolve(captureArg),board=resolve(boardArg),hash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex'),read=(p:string)=>JSON.parse(readFileSync(p,'utf8'))
const candidate=read(`${board}/candidate.circuit.json`),contract=currentDdrTrunkContract(read(`${capture}/forced-trunk-contract.json`),read(`${board}/routing-input.json`),candidate),manifest=read(`${board}/current-evidence-manifest.json`)
if(hash(candidate)!==manifest.candidateCircuitSha256)throw Error('Candidate manifest mismatch')
const rows=contract.forcedTrunks.flatMap((trunk:any)=>[0,1].map(byte=>{
const tap=trunk[`ram${byte}Tap`],exit=candidate.find((e:any)=>e.pcb_breakout_point_id===tap.pointId)
if(!exit||exit.layer!==tap.layer||Math.hypot(exit.x-tap.x,exit.y-tap.y)>1e-7)throw Error(`Stale tap ${tap.pointId}`)
const traces=candidate.filter((e:any)=>e.type==='pcb_trace'&&e.source_trace_id===exit.source_trace_id&&e.route.at(-1)?.layer===tap.layer&&Math.hypot(e.route.at(-1).x-tap.x,e.route.at(-1).y-tap.y)<1e-7)
if(traces.length!==1)throw Error('Ambiguous tap-owned saved copper')
const trace=traces[0],previous=[...trace.route].reverse().find((p:any)=>p.route_type==='wire'&&p.layer===tap.layer&&Math.hypot(p.x-tap.x,p.y-tap.y)>1e-7)
if(!previous)throw Error('Missing stub tangent')
const branchHeading=heading(tap,previous),options=trunkHeadingOptions(branchHeading)
return {terminal:trunk.terminal,byte,pointId:tap.pointId,tap,sourceTraceId:exit.source_trace_id,savedTraceId:trace.pcb_trace_id,memoryBranchTravelDegrees:branchHeading,options,straightNorthAllowed:options.some(o=>o.incomingTravelDegrees===90&&o.outgoingTravelDegrees===90),straightSouthAllowed:options.some(o=>o.incomingTravelDegrees===270&&o.outgoingTravelDegrees===270)}
}))
const report={candidateCircuitSha256:hash(candidate),forcedTrunkContractSha256:hash(contract),rows,scope:'Local directed-junction feasibility only, with physical inner6 headings: 0 east,90 north,180 west,270 south. Incoming means travel from CPU; outgoing means travel toward the next RAM or termination. No clearance, route reachability, stub timing, termination, or electrical qualification is implied.'}
writeFileSync(`${board}/trunk-direction-audit.json`,JSON.stringify(report,null,2)+'\n')
console.log(JSON.stringify({taps:rows.length,straightNorthAllowed:rows.filter((r:any)=>r.straightNorthAllowed).length,straightSouthAllowed:rows.filter((r:any)=>r.straightSouthAllowed).length}))
}