Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:16:12

0001 #! /usr/bin/perl -w

0002 #

0003 #  This script is used to identify any layer 1-13 vias inside the 

0004 #  connector blocks and change them to have an extent of only 1-8.

0005 #

0006 use strict;
0007 use CGI qw(:standard);
0008 
0009 open (ORIG, "<", "PadMap.txt") or die "Can't open original file $!/n";
0010 open (OLD, "<", "StonyBrookUniversity-R2pad-Rev_B-badVia.brd") or die "Can't open original file $!/n";
0011 open (NEW, ">", "StonyBrookUniversity-R2pad-Rev_B-goodVia.brd") or die "Can't open original file $!/n";
0012 
0013 my %PadMap;
0014 
0015 while (<ORIG>)
0016 {
0017     my $line = $_;
0018     my @lineValues = split(/,/,$line);
0019 
0020     my $CurrentSignal = $lineValues[0];
0021     $PadMap{$CurrentSignal}=$line;
0022 }
0023 close (ORIG);
0024 
0025 my $CurrentSignal="NOSIGNAL";
0026 my @X=();
0027 my @Y=();
0028 my @Xgnd=();
0029 my @Ygnd=();
0030 
0031 while (<OLD>)
0032 {
0033     my $line = $_;
0034     
0035     if ($line =~ /<signal name/)
0036     {
0037     my @lineValues = split(/"/,$line);

0038     $CurrentSignal = $lineValues[1];

0039     @X=();

0040     @Y=();

0041     @Xgnd=();

0042     @Ygnd=();

0043     }

0044     

0045 #  Fix up the current signal using the pad map...

0046     if ($CurrentSignal =~ /ZZ/ && $line =~ /<via/ && $line =~ /extent=\"2-15\"/)

0047     {

0048     my @lineValues = split(/"/,$line);
0049     push @X, $lineValues[1];
0050     push @Y, $lineValues[3];
0051     }
0052 
0053     if ($CurrentSignal =~ /ZZ/ && $line =~ /<\/signal/)
0054     {
0055     my @Offsets = (461.2386, 522.1986);
0056     my @ROTATE = (-0.202458193, -0.151843645, -0.101229097, -0.050614548, 0, 0.050614548, 0.101229097, 0.151843645);
0057     
0058     
0059     #  Determine which rotation and which offset using the PadMap.

0060     my $PadInfo = $PadMap{$CurrentSignal};
0061     my @PadDetails = split(/,/,$PadInfo);
0062     my $Connector = $PadDetails[1];
0063     my @ConnDetails = split(/\$/,$Connector);
0064     my $ConnIndex = $ConnDetails[1];
0065     print "ConnIndex $ConnIndex\n";
0066     my $iROT = int(($ConnIndex-1.0)/2.0);
0067     my $iSAM = ($ConnIndex)%2;
0068     
0069     my @let  = ("F", "E", "D", "C", "B", "A");
0070     my %Rows = ("F" => "0", "E"=>"1", "D"=>"2", "C"=>"3", "B"=>"4", "A"=>"5");
0071     
0072     my $iROW = $Rows{$PadDetails[3]};;
0073     my $iCOL = $PadDetails[4]-1;
0074     
0075     print "$iROT  $iSAM  $CurrentSignal\n";
0076     #  We have now reached the point where we need to add a contactref line to the file...

0077     my $BESTDISTANCE = 999999;
0078     my $BESTWIRE  = -1;
0079     my $BESTROT   = -1;
0080     my $BESTSAM   = -1;
0081     my $BESTROW   = -1;
0082     my $BESTCOL   = -1;
0083     for (my $iWIRE=0; $iWIRE<@X; $iWIRE++)
0084     {
0085         my $THETA = $ROTATE[$iROT];
0086         my $Xprime = ( cos($THETA)*$X[$iWIRE] + sin($THETA)*$Y[$iWIRE])*1000.0/25.4;
0087         my $Yprime = (-sin($THETA)*$X[$iWIRE] + cos($THETA)*$Y[$iWIRE])*1000.0/25.4;
0088         #print "$X[$iWIRE] $Y[$iWIRE] $iROT $THETA $Xprime $Yprime\n";

0089         
0090         my $Xoffset = 0.0;
0091         my $Yoffset = $Offsets[$iSAM];
0092         
0093         my $Xcircle = $Xoffset + (-125.0+$iROW*50.0);
0094         my $Ycircle = $Yoffset*1000.0/25.4 + (-(25.0 + 14.0*50.0) + $iCOL*50.0);
0095         
0096         my $Distance = sqrt(($Xprime-$Xcircle)**2.0 + ($Yprime-$Ycircle)**2.0);
0097         if ($Distance < $BESTDISTANCE)
0098         {
0099         $BESTDISTANCE = $Distance;
0100         $BESTWIRE     = $iWIRE;
0101         }
0102     }
0103     
0104     print "Distance = $BESTDISTANCE mils ";
0105     print "iWIRE = $BESTWIRE ";
0106     print "iROT  = $BESTROT ";
0107     print "iSAM  = $BESTSAM ";
0108     print "iROW  = $BESTROW ";
0109     print "iCOL  = $BESTCOL \n";
0110     
0111     if ($BESTDISTANCE > 50)
0112     {
0113         print "FAILURE ON DISTANCE!\n";
0114         print "$BESTDISTANCE \n";
0115         exit;
0116     }
0117     
0118     #  Put in one via and two new wires...good luck...

0119     my $THETA = -$ROTATE[$iROT];  # rotate the OTHER way...

0120     my $Xoffset = 0.0;
0121     my $Yoffset = $Offsets[$iSAM];  
0122         my $Xcircle = $Xoffset + (-125.0+$iROW*50.0);
0123     my $Ycircle = $Yoffset*1000.0/25.4 + (-(25.0 + 14.0*50.0) + $iCOL*50.0);
0124     my $x1 = ( cos($THETA)*$Xcircle + sin($THETA)*$Ycircle)*25.4/1000.0;   # location of the original pin...

0125     my $y1 = (-sin($THETA)*$Xcircle + cos($THETA)*$Ycircle)*25.4/1000.0;
0126 
0127 
0128     $Ycircle = $Ycircle + 25;
0129     my $x2 = ( cos($THETA)*$Xcircle + sin($THETA)*$Ycircle)*25.4/1000.0;   # location of the new via...

0130     my $y2 = (-sin($THETA)*$Xcircle + cos($THETA)*$Ycircle)*25.4/1000.0;
0131 
0132     my $x3 = $X[$BESTWIRE];  # location of the existing via...

0133     my $y3 = $Y[$BESTWIRE];
0134 
0135 
0136     print NEW "<via x=\"$x2\" y=\"$y2\" extent=\"1-2\" drill=\"0.127\"/>\n";
0137     print NEW "<wire x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" width=\"0.1016\" layer=\"1\"/>\n";
0138     print NEW "<wire x1=\"$x2\" y1=\"$y2\" x2=\"$x3\" y2=\"$y3\" width=\"0.1016\" layer=\"2\"/>\n";
0139 
0140     }
0141 
0142 
0143 #  Fix up the GND vias by looping over all of them (much slower since so many...).

0144     if ($CurrentSignal =~ /GND/ && $line =~ /<via/ && $line =~ /extent=\"2-15\"/)

0145     {

0146     my @lineValues = split(/"/,$line);
0147     push @Xgnd, $lineValues[1];
0148     push @Ygnd, $lineValues[3];
0149     }
0150 
0151     if ($CurrentSignal =~ /GND/ && $line =~ /<\/signal/)
0152     {
0153     my @Offsets = (461.2386, 522.1986);
0154     my @ROTATE = (-0.202458193, -0.151843645, -0.101229097, -0.050614548, 0, 0.050614548, 0.101229097, 0.151843645);
0155     my @ConnNames = ("Uy1", "Uy2", "Uy3", "Uy4", "Uy5", "Uy6", "Uy7", "Uy8", "Uy9", "Uy10", "Uy11", "Uy12", "Uy13", "Uy14", "Uy15", "Uy16");
0156     my @GndPad = ("Ay1",  "Ay2",  "Ay3",  "Ay4",  "Ay5",  "Ay6",  "Ay7",  "Ay8",  "Ay9",  "Ay10", 
0157               "Ay11", "Ay12", "Ay13", "Ay14", "Ay15", "Ay16", "Ay17", "Ay18", "Ay19", "Ay20", 
0158               "Ay21", "Ay22", "Ay23", "Ay24", "Ay25", "Ay26", "Ay27", "Ay28", "Ay29", 
0159               "By1",  "By2",  "By9",  "By16", "By23", "By30", 
0160               "Cy1",  "Cy2",  "Cy9",  "Cy16", "Cy23", "Cy30", 
0161               "Dy1",  "Dy2",  "Dy9",  "Dy16", "Dy23", "Dy30", 
0162               "Ey1",  "Ey30", 
0163               "Fy1",  "Fy30" );
0164     
0165 
0166     for my $Connector (@ConnNames)
0167     {
0168         my @ConnDetails = split(/y/,$Connector);
0169         my $ConnIndex = $ConnDetails[1];
0170         print "ConnIndex $ConnIndex\n";
0171         my $iROT = int(($ConnIndex-1.0)/2.0);
0172         my $iSAM = ($ConnIndex)%2;
0173         
0174         for my $PadInfo (@GndPad)
0175         {
0176         my @PadDetails = split(/y/,$PadInfo);
0177         
0178         my @let  = ("F", "E", "D", "C", "B", "A");
0179         my %Rows = ("F" => "0", "E"=>"1", "D"=>"2", "C"=>"3", "B"=>"4", "A"=>"5");
0180         
0181         my $iROW = $Rows{$PadDetails[0]};;
0182         my $iCOL = $PadDetails[1]-1;
0183         
0184         print "$iROT  $iSAM  $CurrentSignal\n";
0185         #  We have now reached the point where we need to add a contactref line to the file...

0186         my $BESTDISTANCE = 999999;
0187         my $BESTWIRE  = -1;
0188         my $BESTROT   = -1;
0189         my $BESTSAM   = -1;
0190         my $BESTROW   = -1;
0191         my $BESTCOL   = -1;
0192         for (my $iWIRE=0; $iWIRE<@Xgnd; $iWIRE++)
0193         {
0194             my $THETA = $ROTATE[$iROT];
0195             my $Xprime = ( cos($THETA)*$Xgnd[$iWIRE] + sin($THETA)*$Ygnd[$iWIRE])*1000.0/25.4;
0196             my $Yprime = (-sin($THETA)*$Xgnd[$iWIRE] + cos($THETA)*$Ygnd[$iWIRE])*1000.0/25.4;
0197             #print "$Xgnd[$iWIRE] $Ygnd[$iWIRE] $iROT $THETA $Xprime $Yprime\n";

0198             
0199             my $Xoffset = 0.0;
0200             my $Yoffset = $Offsets[$iSAM];
0201             
0202             my $Xcircle = $Xoffset + (-125.0+$iROW*50.0);
0203             my $Ycircle = $Yoffset*1000.0/25.4 + (-(25.0 + 14.0*50.0) + $iCOL*50.0);
0204 
0205             #  Shift the search region a little bit for accuracy of the search...

0206             $Xcircle = $Xcircle - 20;
0207             $Ycircle = $Ycircle + 20;
0208 
0209             my $Distance = sqrt(($Xprime-$Xcircle)**2.0 + ($Yprime-$Ycircle)**2.0);
0210             if ($Distance < $BESTDISTANCE)
0211             {
0212             $BESTDISTANCE = $Distance;
0213             $BESTWIRE     = $iWIRE;
0214             }
0215         }
0216         
0217         print "Distance = $BESTDISTANCE mils ";
0218         print "iWIRE = $BESTWIRE ";
0219         print "iROT  = $BESTROT ";
0220         print "iSAM  = $BESTSAM ";
0221         print "iROW  = $BESTROW ";
0222         print "iCOL  = $BESTCOL \n";
0223         
0224         if ($BESTDISTANCE > 10)
0225         {
0226             print "FAILURE ON DISTANCE!\n";
0227             print "$BESTDISTANCE \n";
0228             print "iWIRE = $BESTWIRE ";
0229             print "iROT  = $BESTROT ";
0230             print "iSAM  = $BESTSAM ";
0231             print "iROW  = $BESTROW ";
0232             print "iCOL  = $BESTCOL ";
0233             print "Connector  = $Connector ";
0234             print "PadInfo    = $PadInfo ";
0235             print "\n";
0236             exit;
0237         }
0238         
0239         #  Put in one via and two new wires...good luck...

0240         my $THETA = -$ROTATE[$iROT];  # rotate the OTHER way...

0241         my $Xoffset = 0.0;
0242         my $Yoffset = $Offsets[$iSAM];  
0243         my $Xcircle = $Xoffset + (-125.0+$iROW*50.0);
0244         my $Ycircle = $Yoffset*1000.0/25.4 + (-(25.0 + 14.0*50.0) + $iCOL*50.0);
0245         my $x1 = ( cos($THETA)*$Xcircle + sin($THETA)*$Ycircle)*25.4/1000.0;   # location of the original pin...

0246         my $y1 = (-sin($THETA)*$Xcircle + cos($THETA)*$Ycircle)*25.4/1000.0;
0247         
0248         
0249         $Ycircle = $Ycircle + 25;
0250         my $x2 = ( cos($THETA)*$Xcircle + sin($THETA)*$Ycircle)*25.4/1000.0;   # location of the new via...

0251         my $y2 = (-sin($THETA)*$Xcircle + cos($THETA)*$Ycircle)*25.4/1000.0;
0252         
0253         my $x3 = $Xgnd[$BESTWIRE];  # location of the existing via...

0254         my $y3 = $Ygnd[$BESTWIRE];
0255         
0256         
0257         print NEW "<via x=\"$x2\" y=\"$y2\" extent=\"1-2\" drill=\"0.127\"/>\n";
0258         print NEW "<wire x1=\"$x1\" y1=\"$y1\" x2=\"$x2\" y2=\"$y2\" width=\"0.1016\" layer=\"1\"/>\n";
0259         print NEW "<wire x1=\"$x2\" y1=\"$y2\" x2=\"$x3\" y2=\"$y3\" width=\"0.1016\" layer=\"2\"/>\n";
0260         }
0261     }
0262     }
0263 
0264     print NEW $line;
0265     
0266 }
0267 close (OLD);
0268 close (NEW);