2024-05-04 02:44:22 +00:00
# !/usr/bin/env -S yosys -c
yosys - import
2024-05-05 01:55:57 +00:00
# Parse arguments
if { $argc < 3 } {
puts " U S A G E : $ a r g v 0 - - < J E D E C _ F I L E > < P C F _ F I L E > < V E R I L O G F I L E S > . . . "
exit
}
set jedec_file [ lindex $argv 0 ]
set pcf_file [ lindex $argv 1 ]
set verilog_files [ lrange $argv 2 end]
# Convert JEDEC file to hex for Verilog model
exec jedutil - convert $jedec_file GAL16V8_reg.bin
exec xxd - ps - c 1 GAL16V8_reg.bin GAL16V8_reg.hex
# Read and synthesize original Verilog
read_verilog $verilog_files
hierarchy - auto-top
2024-05-04 02:44:22 +00:00
flatten
synth
2024-05-05 01:55:57 +00:00
splitnets - ports
yosys rename - top __original
select - module __original
# Process PCF file and rename ports
set used [ list ]
set pin_mapping [ dict create 1 " c l k " 2 " i n \[ 0 \] " 3 " i n \[ 1 \] " 4 " i n \[ 2 \] " 5 " i n \[ 3 \] " 6 " i n \[ 4 \] " 7 " i n \[ 5 \] " 8 " i n \[ 6 \] " 9 " i n \[ 7 \] " 11 " o e _ n " 12 " i o \[ 7 \] " 13 " i o \[ 6 \] " 14 " i o \[ 5 \] " 15 " i o \[ 4 \] " 16 " i o \[ 3 \] " 17 " i o \[ 2 \] " 18 " i o \[ 1 \] " 19 " i o \[ 0 \] " ]
set pcf_fp [ open $pcf_file r]
foreach line [ split [ read $pcf_fp ] " \n " ] {
puts $line
if { [ regexp { set_io \ s+ ( . * ) \ s+ ( [ 0-9 ] + ) } $line - > net pin] } {
# Rename nets to match GAL model
yosys rename $net __[ dict get $pin_mapping $pin ]
2024-05-04 02:44:22 +00:00
2024-05-05 01:55:57 +00:00
# Mark as used
lappend used [ dict get $pin_mapping $pin ]
}
}
select - clear
design - stash __original
# Read and synthesize GAL model
2024-05-04 02:44:22 +00:00
read_verilog wrapper.v GAL16V8_reg.v
flatten
synth
2024-05-05 01:55:57 +00:00
splitnets - ports
select - module __wrapper
# Delete extra "unused" ports
foreach pin_name [ dict values $pin_mapping ] {
if { [ lsearch - exact $used $pin_name ] >= 0 } {
puts " $ p i n _ n a m e i s u s e d "
} elseif { $pin_name == " o e _ n " } {
puts " $ p i n _ n a m e i s n o t u s e d "
# Enable registered outputs if net unused
connect - set __oe_n ' 0
delete - port __$pin_name
} else {
puts " $ p i n _ n a m e i s n o t u s e d "
delete - port __$pin_name
}
}
select - clear
# Make and check equivalence circuit
design - copy-from __original - as __original A:top
2024-05-04 02:44:22 +00:00
2024-05-05 01:55:57 +00:00
equiv_make __original __wrapper equiv
2024-05-04 02:44:22 +00:00
equiv_induct equiv
equiv_status - assert equiv