#!/usr/local/bin/perl #----------------------------------------------------------------------------- # File : pads2ucf.pl # Author : Ryan Herbst, rherbst@slac.stanford.edu # Created : 11/21/2009 #----------------------------------------------------------------------------- # Description: # Generate UCF file location constraints from pads netlist. # This script converts schematic net names # ADC_CLK to adcClk, ADC_DATA10 to adcData(10) #----------------------------------------------------------------------------- # Copyright (c) 2004 by Ryan Herbst. All rights reserved. #----------------------------------------------------------------------------- # Modification history: # 11/21/2009: created. #----------------------------------------------------------------------------- local $/ = "\r\n"; if ( @ARGV != 3 ) { print "Usage: pads2ucf.pl netlist refdes ucf\n"; exit; } # Open netlist $netfile="$ARGV[0]"; open(NET,$netfile) || die("Could not open file: $netfile"); @raw_net=; close(NET); $refdes = $ARGV[1]; # Open ucf $ucffile=">$ARGV[2]"; open(UCF,$ucffile) || die("Could not open file: $ucffile"); # Go through each line in the file $signal = ""; foreach $src_line (@raw_net) { chomp($src_line); # Split line into words @words = split (/ /,$src_line); # Is this a net declaration if ( $words[0] eq "\*SIGNAL\*" ) { $signal = $words[1]; $signal =~ s/.*\\//; # Only take last part of net name $signal =~ tr/A-Z/a-z/; # Convert to lowercase $signal =~ s/_([a-z])/\u\1/g; # Dump '_' and convert next char to uppercase $signal =~ s/(\d+\z)/\(\1\)/g; # Add parenthesis around numbers at end of string } # Possible net line elsif ( $signal ne "" ) { if ( $net eq "" ) { # Split first entry @fields = split (/\./,$words[0]); # Does field 0 match if ( $fields[0] eq $refdes ) { $net = $fields[1]; } else { # Split second entry @fields = split (/\./,$words[1]); # Does field 1 match if ( $fields[0] eq $refdes ) { $net = $fields[1]; } } } if ( $net ne "" ) { $sta = "NET \"$signal\""; $stb = "LOC = \"$net\""; $stc = "| IOSTANDARD = \"LVCMOS33\";"; print UCF "$sta"; $len = (25 - length($sta)); for ( $x=0; $x < $len; $x++ ) { print UCF " "; } print UCF "$stb"; $len = (15 - length($stb)); for ( $x=0; $x < $len; $x++ ) { print UCF " "; } print UCF "$stc\n"; $signal = ""; $net = ""; } } }