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/assess-ddr-c1-outward-launch.ts
/** Bounded C1 outward dogbone preflight using the existing launch template. */
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
import { resolve } from 'node:path'
import { objectHash } from './improve-ddr-a9-power-launches'
import { sharedViaApproaches } from './plan-ddr-ram-power-via-reuse'
import { verifyDdrSystemCopper, auditDdrTraceJunctions } from './check-ddr-system-copper'
import { auditRouteAngles } from './check-route-angles'
const [parentDir, outArg, dxArg='.4', dyArg='-.4', byteArg='both'] = process.argv.slice(2)
const dx=Number(dxArg),dy=Number(dyArg),bytes=byteArg==='both'?[0,1]:[Number(byteArg)]
if(!Number.isFinite(dx)||!Number.isFinite(dy)||bytes.some(b=>![0,1].includes(b)))throw Error('Invalid explicit launch')
if (!outArg) throw Error('Usage: current-board output')
const out = resolve(outArg), inputs: Record<string, string> = {}
const read = (name: string) => { const value = JSON.parse(readFileSync(resolve(parentDir!, name), 'utf8')); inputs[name] = objectHash(value); return value }
const parent = read('candidate.circuit.json'), report = read('report.json'), host = read('host-bundle.json'), input = read('routing-input.json')
if (report.candidateCircuitSha256 !== objectHash(parent) || host.traces.length !== 20 || report.launchQualified !== 57) throw Error('Expected checked20/57 parent')
const changes = bytes.map(byte => {
const before = parent.find((e: any) => e.type === 'pcb_trace' && e.pcb_trace_id === `saved_fanout_pcb_group_${byte ? 5 : 3}_2`)
const start = before.route[0], pad = parent.find((e: any) => e.type === 'pcb_smtpad' && e.pcb_port_id === start.start_pcb_port_id)
if (!pad || Math.hypot(pad.x - start.x, pad.y - start.y) > 1e-8) throw Error('Missing C1 source pad')
const via = { x: pad.x + dx, y: pad.y + dy }
const route = sharedViaApproaches(start, via)[0]
if (!route || before.route.some((p: any) => p.route_type === 'via')) throw Error('Unexpected C1 retained barrel')
const after = { ...before, route: [...route, { route_type: 'via', ...via, from_layer: 'top', to_layer: 'inner3', via_diameter: .4572, via_hole_diameter: .254 }], trace_length: Math.max(Math.abs(dx),Math.abs(dy))+(Math.SQRT2-1)*Math.min(Math.abs(dx),Math.abs(dy)), connectsTo: [before.source_trace_id, start.start_pcb_port_id] }
delete after.connection_name
return { byte, before, after, via, lengthMm: after.trace_length }
})
const candidate = parent.map((e: any) => changes.find(c => c.before.pcb_trace_id === e.pcb_trace_id && e.type === 'pcb_trace')?.after ?? e)
const fresh = [...host.traces, ...changes.map(c => c.after)], ids = new Set(fresh.map(t => t.pcb_trace_id))
const conductor = verifyDdrSystemCopper(candidate.filter((e: any) => e.type !== 'pcb_copper_pour' && !ids.has(e.pcb_trace_id)), fresh, input.connections, {}, 100, { reportSameNetContacts: true })
const angles = auditRouteAngles(candidate.filter((e: any) => e.type === 'pcb_trace')), junctions = auditDdrTraceJunctions(candidate, input.connections)
for (const [name, hash] of Object.entries(inputs)) if (objectHash(JSON.parse(readFileSync(resolve(parentDir!, name), 'utf8'))) !== hash) throw Error('Input changed')
mkdirSync(out, { recursive: true })
writeFileSync(resolve(out, 'report.json'), JSON.stringify({ parentDirectory: resolve(parentDir!), parentCircuitSha256: objectHash(parent), inputObjectHashes: inputs, changes, conductor, angles, junctions, accepted: false, conductorClear: !conductor.errors.length && !conductor.violations.length && angles.valid && junctions.valid, scope: 'Explicit C1 conventional-via preflight using the existing <=1.524mm octilinear launch template. Current E1/E2/E3 and all20 hosts retained. Plane antipads, annulus contacts and complete power qualification are not provided; this is not an accepted board.' }, null, 2) + '\n')
console.log(JSON.stringify({ errors: conductor.errors, violations: conductor.violations.length, angles: angles.valid, junctions: junctions.valid, changes: changes.map(c => ({ byte: c.byte, via: c.via, lengthMm: c.lengthMm })) }))