"""Conditional external timing coverage classification. Copyright (c) 2026 Brian K. Holman. BSD-3-Clause; see LICENSES/. """ import re def parse_ucp(path): text = path.read_text(errors='replace') counts = {m[1].strip(): {'setup': int(m[2]), 'hold': int(m[3])} for m in re.finditer(r';\s*(Illegal Clocks|Unconstrained [^;]+?)\s*;\s*(\d+)\s*;\s*(\d+)\s*;', text)} inventory = {'input_ports': {}, 'output_ports': {}} section = None # Retain only the setup inventory (hold inventory repeats it). for line in text.split('; Hold Analysis ;')[0].splitlines(): cols = [x.strip() for x in line.split(';')[1:-1]] if cols == ['Unconstrained Input Ports']: section = 'input_ports' elif cols == ['Unconstrained Output Ports']: section = 'output_ports' elif cols and cols[0] in ('Unconstrained Input Port Paths', 'Unconstrained Output Port Paths'): section = None elif section and len(cols) == 2 and cols[0] not in ('Input Port', 'Output Port'): inventory[section][cols[0]] = cols[1] if len(counts) != 6: raise RuntimeError('Incomplete unconstrained-count summary') return counts, inventory def classify(port): if port.startswith('SDRAM_'): return 'SDRAM synchronous: must be explicitly timed; no exception allowed' if port == 'HDMI_TX_CLK': return 'Forwarded video clock: two generated-clock modes; clock waveform/output latency, not a data receiver' if port.startswith('HDMI_TX_'): return 'ADV7513 video: both clock mux modes require setup/hold budgets' if port in ('HDMI_I2S', 'HDMI_LRCLK', 'HDMI_SCLK'): return 'ADV7513 I2S: source protocol slots plus bounded output propagation' if port == 'HDMI_MCLK': return 'Forwarded audio clock: clock waveform/output latency, not a data receiver' if port.startswith('HDMI_I2C_'): return 'HPS hard I2C peripheral boundary: fabric STA does not prove slave bus timing' if port in ('IO_SCL', 'IO_SDA'): return 'MCP23009 I2C: require source-matched protocol slots, propagation and board RC/slave contract' if port == 'SDCD_SPDIF': return 'Mode-dependent asynchronous card detect / SPDIF output' if port.startswith('SDIO_') or port == 'SD_SPI_CS': return 'Mode-dependent HPS SD-SPI / analog VGA mux; cannot use one synchronous pin budget' if port.startswith('LED['): return 'Human status indicator / overtake mode; no synchronous external receiver' if port == 'USER_IO[1]': return 'Optional external UART input: UART synchronizer and direct bit-banged PIA fanout' if port.startswith('USER_IO['): return 'Open-drain serial/debug output or alternate I2S; receiver/RC is external' if port.startswith('altera_reserved_'): return 'Tool-generated JTAG interface: separate programming/test timing contract' return 'UNCLASSIFIED: investigation required'