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
2024-05-06 01:02:46 +00:00
if { $argc < 3 } {
2024-05-05 01:55:57 +00:00
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]
2024-05-06 01:02:46 +00:00
# Convert JEDEC file to bin
exec jedutil - convert $jedec_file __temp.bin
# Find chip being used
set jedec_bin_size [ file size __temp.bin]
if { $jedec_bin_size == 279 } {
set chip GAL16V8
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 \] " ]
} elseif { $jedec_bin_size == 741 } {
set chip GAL22V10
set pin_mapping [ dict create 1 " i n \[ 0 \] " 2 " i n \[ 1 \] " 3 " i n \[ 2 \] " 4 " i n \[ 3 \] " 5 " i n \[ 4 \] " 6 " i n \[ 5 \] " 7 " i n \[ 6 \] " 8 " i n \[ 7 \] " 9 " i n \[ 8 \] " 10 " i n \[ 9 \] " 11 " i n \[ 1 0 \] " 12 " i n \[ 1 1 \] " 13 " i n \[ 1 2 \] " 14 " i o \[ 9 \] " 15 " i o \[ 8 \] " 16 " i o \[ 7 \] " 17 " i o \[ 6 \] " 18 " i o \[ 5 \] " 19 " i o \[ 4 \] " 20 " i o \[ 3 \] " 21 " i o \[ 2 \] " 22 " i o \[ 1 \] " 23 " i o \[ 0 \] " ]
} else {
puts " E r r o r : U n k n o w n c h i p f o r J E D E C f i l e "
exit
}
puts " C h i p f o u n d t o b e $ c h i p "
# Convert binary JEDEC file to hex for Verilog
exec xxd - ps - c 1 __temp.bin $ { chip } _reg.hex
exec rm __temp.bin
2024-05-05 01:55:57 +00:00
# Read and synthesize original Verilog
read_verilog $verilog_files
hierarchy - auto-top
2024-05-06 01:02:46 +00:00
2024-05-05 02:23:50 +00:00
tribuf
2024-05-04 02:44:22 +00:00
synth
2024-05-06 01:02:46 +00:00
# yosys proc
# yosys memory
# clean -purge
flatten
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 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-06 01:02:46 +00:00
read_verilog $ { chip } _wrapper.v $ { chip } _reg.v
2024-05-05 02:23:50 +00:00
tribuf
2024-05-04 02:44:22 +00:00
synth
2024-05-06 01:02:46 +00:00
# yosys proc
# yosys memory
# clean -purge
flatten
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 "
2024-05-06 01:02:46 +00:00
} elseif { $pin_name == " o e _ n " && $chip == " G A L 1 6 V 8 " } {
2024-05-05 01:55:57 +00:00
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-05 02:23:50 +00:00
tribuf - formal equiv
2024-05-04 02:44:22 +00:00
equiv_induct equiv
2024-05-06 01:02:46 +00:00
shell
2024-05-04 02:44:22 +00:00
equiv_status - assert equiv