Complete prove_equiv script and add flashing script

This commit is contained in:
annoyatron255 2024-05-04 20:55:57 -05:00
parent 7ce252b0cb
commit 45b86e75bb
No known key found for this signature in database
GPG key ID: 95283811BE4E93F8
7 changed files with 117 additions and 309 deletions

34
flash_minipro.sh Executable file
View file

@ -0,0 +1,34 @@
#!/bin/bash
set -e
# Check args
if [[ $# -ne 2 ]]; then
echo "USAGE: $0 <JEDEC FILE> <CHIP>"
exit 1
fi
# Program GAL
minipro -p "$2" -w "$1"
# Read GAL
READBACK=/tmp/gal_tmp
minipro -p "$2" -r "$READBACK.jed"
# Fix JEDEC for jedutil
truncate -s -7 "$READBACK.jed"
printf "*\r\n\x03" >> "$READBACK.jed"
od -t u1 -An -w1 -v "$READBACK.jed" | awk '{s+=$1; if(s > 65535) s = and(65535, s)} END {printf("%04X\r\n", s)}' >> "$READBACK.jed"
# Convert to binary and compare
jedutil -convert "$READBACK.jed" "$READBACK.bin"
jedutil -convert "$1" "${1%.jed}.bin"
if cmp -s "$READBACK.bin" "${1%.jed}.bin"; then
echo "VERIFICATION OK!"
else
echo "VERIFICATION FAILED!"
fi
# Clean up
rm "$READBACK.jed" "$READBACK.bin" "${1%.jed}.bin"

View file

@ -1,279 +0,0 @@
00
00
08
92
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
fe
ff
ff
ff
ef
ff
ff
ff
ff
fe
ff
ff
ff
ef
ff
ff
ff
ff
fe
ff
ff
ff
ef
ff
00
00
00
00
00
00
00
00
ee
ee
ee
ff
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
ff
ff
de
ff
ff
ff
ed
ff
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
ff
fe
ff
ff
ff
ef
ff
ff
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
ee
ff
ff
ff
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
f0
c2
f6
b6
46
2a
a6
ce
2e
00
ff
ff
ff
ff
ff
ff
ff
ff
02

View file

@ -1,9 +1,9 @@
`default_nettype none `default_nettype none
module GAL16V8_reg ( module GAL16V8_reg (
input wire clk, input wire clk, // Pin 1
input wire [7:0] in, input wire [7:0] in, // Pin {9, 8, 7, 6, 5, 4, 3, 2}
input wire oe_n, input wire oe_n, // Pin 11
inout wire [7:0] io inout wire [7:0] io // Pin {12, 13, 14, 15, 16, 17, 18, 19}
); );
// Read in binary JEDEC file // Read in binary JEDEC file
reg [7:0] jed_bin_file [0:278]; reg [7:0] jed_bin_file [0:278];
@ -63,7 +63,7 @@ module GAL16V8_reg (
.NUM_PRODUCTS(1), .NUM_PRODUCTS(1),
.NUM_INPUTS(16) .NUM_INPUTS(16)
) one_sop_inst ( ) one_sop_inst (
.sop_fuses(sop_fuses[i][255:224]), .sop_fuses(sop_fuses[i][31:0]),
.ptd_fuses(ptd_fuses[i][0]), .ptd_fuses(ptd_fuses[i][0]),
.in(interleaved), .in(interleaved),
.out(one_sop_out) .out(one_sop_out)
@ -74,7 +74,7 @@ module GAL16V8_reg (
.NUM_PRODUCTS(7), .NUM_PRODUCTS(7),
.NUM_INPUTS(16) .NUM_INPUTS(16)
) sop_inst ( ) sop_inst (
.sop_fuses(sop_fuses[i][223:0]), .sop_fuses(sop_fuses[i][255:32]),
.ptd_fuses(ptd_fuses[i][7:1]), .ptd_fuses(ptd_fuses[i][7:1]),
.in(interleaved), .in(interleaved),
.out(sop_out) .out(sop_out)
@ -168,7 +168,7 @@ module olmc (
reg_out <= out; reg_out <= out;
end end
assign feedback = ac1_fuse ? !reg_out : out; assign feedback = ac1_fuse ? !out : !reg_out;
assign io = ac1_fuse ? (one_sop ? !out : 1'bz) : // Combinational assign io = ac1_fuse ? (one_sop ? !out : 1'bz) : // Combinational
(oe_n ? 1'bz : !reg_out); // Registered (oe_n ? 1'bz : !reg_out); // Registered

View file

@ -19,16 +19,16 @@ initial begin
$dumpfile("dump.vcd"); $dumpfile("dump.vcd");
$dumpvars(0, GAL16V8_reg_tb); $dumpvars(0, GAL16V8_reg_tb);
#3; #3;
in = 8'b0000_1100; in = 8'b0000_0000;
oe_n = 0; oe_n = 0;
#10; #10;
in = 8'b0000_1001; in = 8'b0000_0001;
#10; #10;
in = 8'b0000_0110; in = 8'b0000_0010;
#10; #10;
in = 8'b0000_0011; in = 8'b0000_0011;
#10; #10;
in = 8'b0000_1100; in = 8'b0000_1101;
#30; #30;
oe_n = 1; oe_n = 1;
#10; #10;

View file

@ -1,14 +1,74 @@
#!/usr/bin/env -S yosys -c #!/usr/bin/env -S yosys -c
yosys -import yosys -import
read_verilog original.v # Parse arguments
if { $argc < 3 } {
puts "USAGE: $argv0 -- <JEDEC_FILE> <PCF_FILE> <VERILOG FILES> ..."
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
flatten flatten
synth synth
splitnets -ports
yosys rename -top __original
select -module __original
# Process PCF file and rename ports
set used [list]
set pin_mapping [dict create 1 "clk" 2 "in\[0\]" 3 "in\[1\]" 4 "in\[2\]" 5 "in\[3\]" 6 "in\[4\]" 7 "in\[5\]" 8 "in\[6\]" 9 "in\[7\]" 11 "oe_n" 12 "io\[7\]" 13 "io\[6\]" 14 "io\[5\]" 15 "io\[4\]" 16 "io\[3\]" 17 "io\[2\]" 18 "io\[1\]" 19 "io\[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]
# Mark as used
lappend used [dict get $pin_mapping $pin]
}
}
select -clear
design -stash __original
# Read and synthesize GAL model
read_verilog wrapper.v GAL16V8_reg.v read_verilog wrapper.v GAL16V8_reg.v
flatten flatten
synth synth
splitnets -ports
select -module __wrapper
equiv_make original wrapper equiv # Delete extra "unused" ports
foreach pin_name [dict values $pin_mapping] {
if {[lsearch -exact $used $pin_name] >= 0} {
puts "$pin_name is used"
} elseif {$pin_name == "oe_n"} {
puts "$pin_name is not used"
# Enable registered outputs if net unused
connect -set __oe_n '0
delete -port __$pin_name
} else {
puts "$pin_name is not used"
delete -port __$pin_name
}
}
select -clear
# Make and check equivalence circuit
design -copy-from __original -as __original A:top
equiv_make __original __wrapper equiv
equiv_induct equiv equiv_induct equiv
equiv_status -assert equiv equiv_status -assert equiv

View file

@ -1,22 +1,16 @@
module wrapper ( `default_nettype none
input wire clk, module __wrapper (
input wire [5:0] in, input wire __clk, // Pin 1
output wire [4:0] out input wire [7:0] __in, // Pin {9, 8, 7, 6, 5, 4, 3, 2}
input wire __oe_n, // Pin 11
inout wire [7:0] __io // Pin {12, 13, 14, 15, 16, 17, 18, 19}
); );
wire [7:0] in_int;
wire [7:0] io_int;
wire oe_n;
assign oe_n = 0;
assign in_int = {3'b0, in};
assign out = {io_int[3], io_int[4], io_int[5], io_int[6], io_int[7]};
GAL16V8_reg GAL16V8_reg_inst ( GAL16V8_reg GAL16V8_reg_inst (
.clk(clk), .clk(__clk),
.in(in_int), .in(__in),
.oe_n(oe_n), .oe_n(__oe_n),
.io(io_int) .io(__io)
); );
endmodule endmodule

View file

@ -1,4 +1,3 @@
set_io clk 1
set_io A[0] 2 set_io A[0] 2
set_io A[1] 3 set_io A[1] 3
set_io A[2] 4 set_io A[2] 4