array ( "pin" => "13" , "desc" => "Oscillator" , "level" => "" , "shared" => "" , "dedicated" => "1" ) , "PPortToPC7" => array ( "pin" => "75" , "desc" => "Parallel Port To PC, Data 7" , "level" => "" , "shared" => "" , "dedicated" => "" ) , "PPortToPC6" => array ( "pin" => "69" , "desc" => "Parallel Port To PC, Data 6" , "level" => "" , "shared" => "" , "dedicated" => "" ) , "PPortToPC5" => array ( "pin" => "66" , "desc" => "Parallel Port To PC, Data 5" , "level" => "" , "shared" => "" , "dedicated" => "" ) , "PPortToPC4" => array ( "pin" => "77" , "desc" => "Parallel Port To PC, Data 4" , "level" => "" , "shared" => "" , "dedicated" => "" ) , "PPortToPC3" => array ( "pin" => "70" , "desc" => "Parallel Port To PC, Data 3" , "level" => "" , "shared" => "" , "dedicated" => "" ) , "PPortFromPC5" => array ( "pin" => "49" , "desc" => "Parallel Port From PC, Data 5" , "level" => "" , "shared" => "" , "dedicated" => "1" ) , "PPortFromPC4" => array ( "pin" => "48" , "desc" => "Parallel Port From PC, Data 4" , "level" => "" , "shared" => "" , "dedicated" => "1" ) , "PPortFromPC3" => array ( "pin" => "47" , "desc" => "Parallel Port From PC, Data 3" , "level" => "" , "shared" => "" , "dedicated" => "1" ) , "PPortFromPC2" => array ( "pin" => "46" , "desc" => "Parallel Port From PC, Data 2" , "level" => "" , "shared" => "" , "dedicated" => "1" ) , "PPortFromPC1" => array ( "pin" => "45" , "desc" => "Parallel Port From PC, Data 1" , "level" => "" , "shared" => "" , "dedicated" => "1" ) , "PPortFromPC0" => array ( "pin" => "44" , "desc" => "Parallel Port From PC, Data 0" , "level" => "" , "shared" => "" , "dedicated" => "1" ) , "MicroReset" => array ( "pin" => "36" , "desc" => "Micro Reset" , "level" => "H" , "shared" => "" ) , "RAMOE" => array ( "pin" => "61" , "desc" => "RAM Output Enable" , "level" => "L" , "shared" => "" ) , "RAMCE" => array ( "pin" => "65" , "desc" => "RAM Chip Enable" , "level" => "L" , "shared" => "" ) , "RAMWE" => array ( "pin" => "62" , "desc" => "RAM Write Enable" , "level" => "L" , "shared" => "Micro P3.6 (_WR)" ) , "RAMA14" => array ( "pin" => "60" , "desc" => "RAM Address 14" , "level" => "" , "shared" => "Micro P2.6 (A14)" ) , "RAMA13" => array ( "pin" => "58" , "desc" => "RAM Address 13" , "level" => "" , "shared" => "Micro P2.5 (A13)" ) , "RAMA12" => array ( "pin" => "50" , "desc" => "RAM Address 12" , "level" => "" , "shared" => "Micro P2.4 (A12)" ) , "RAMA11" => array ( "pin" => "56" , "desc" => "RAM Address 11" , "level" => "" , "shared" => "Micro P2.3 (A11)" ) , "RAMA10" => array ( "pin" => "51" , "desc" => "RAM Address 10" , "level" => "" , "shared" => "Micro P2.2 (A10)" ) , "RAMA09" => array ( "pin" => "57" , "desc" => "RAM Address 9" , "level" => "" , "shared" => "Micro P2.1 (A9)" ) , "RAMA08" => array ( "pin" => "59" , "desc" => "RAM Address 8" , "level" => "" , "shared" => "Micro P2.0 (A8)" ) , "RAMA07" => array ( "pin" => "84" , "desc" => "RAM Address 7" , "level" => "" , "shared" => "" ) , "RAMA06" => array ( "pin" => "83" , "desc" => "RAM Address 6" , "level" => "" , "shared" => "" ) , "RAMA05" => array ( "pin" => "82" , "desc" => "RAM Address 5" , "level" => "" , "shared" => "" ) , "RAMA04" => array ( "pin" => "79" , "desc" => "RAM Address 4" , "level" => "" , "shared" => "" ) , "RAMA03" => array ( "pin" => "78" , "desc" => "RAM Address 3" , "level" => "" , "shared" => "" ) , "RAMA02" => array ( "pin" => "5" , "desc" => "RAM Address 2" , "level" => "" , "shared" => "" ) , "RAMA01" => array ( "pin" => "4" , "desc" => "RAM Address 1" , "level" => "" , "shared" => "" ) , "RAMA00" => array ( "pin" => "3" , "desc" => "RAM Address 0" , "level" => "" , "shared" => "" ) , "RAMD07" => array ( "pin" => "10" , "desc" => "RAM Data 7" , "level" => "" , "shared" => "Micro P0.7 (A7/D7)" ) , "RAMD06" => array ( "pin" => "80" , "desc" => "RAM Data 6" , "level" => "" , "shared" => "Micro P0.6 (A6/D6)" ) , "RAMD05" => array ( "pin" => "81" , "desc" => "RAM Data 5" , "level" => "" , "shared" => "Micro P0.5 (A5/D5)" ) , "RAMD04" => array ( "pin" => "35" , "desc" => "RAM Data 4" , "level" => "" , "shared" => "Micro P0.4 (A4/D4)" ) , "RAMD03" => array ( "pin" => "38" , "desc" => "RAM Data 3" , "level" => "" , "shared" => "Micro P0.3 (A3/D3)" ) , "RAMD02" => array ( "pin" => "39" , "desc" => "RAM Data 2" , "level" => "" , "shared" => "Micro P0.2 (A2/D2)" ) , "RAMD01" => array ( "pin" => "40" , "desc" => "RAM Data 1" , "level" => "" , "shared" => "Micro P0.1 (A1/D1)" ) , "RAMD00" => array ( "pin" => "41" , "desc" => "RAM Data 0" , "level" => "" , "shared" => "Micro P0.0 (A0/D0)" ) , "PS2DATA" => array ( "pin" => "69" , "desc" => "PS/2 Data" , "level" => "" , "shared" => "Micro P3.1 (TXD)" ) , "PS2CLK" => array ( "pin" => "68" , "desc" => "PS/2 Clock" , "level" => "" , "shared" => "Micro P3.4 (T0)" ) , "LEDa" => array ( "pin" => "19" , "desc" => "LED a" , "level" => "H" , "shared" => "VGA Horizontal Sync" ) , "LEDb" => array ( "pin" => "23" , "desc" => "LED b" , "level" => "H" , "shared" => "VGA Red 0" ) , "LEDc" => array ( "pin" => "26" , "desc" => "LED c" , "level" => "H" , "shared" => "VGA Blue 1" ) , "LEDd" => array ( "pin" => "25" , "desc" => "LED d" , "level" => "H" , "shared" => "VGA Blue 0" ) , "LEDe" => array ( "pin" => "24" , "desc" => "LED e" , "level" => "H" , "shared" => "VGA Green 0" ) , "LEDf" => array ( "pin" => "18" , "desc" => "LED f" , "level" => "H" , "shared" => "VGA Red 1" ) , "LEDg" => array ( "pin" => "20" , "desc" => "LED g" , "level" => "H" , "shared" => "VGA Green 1" ) , "VGAR1" => array ( "pin" => "18" , "desc" => "VGA Red 1" , "level" => "" , "shared" => "LED f" ) , "VGAR0" => array ( "pin" => "23" , "desc" => "VGA Red 0" , "level" => "" , "shared" => "LED b" ) , "VGAG1" => array ( "pin" => "20" , "desc" => "VGA Green 1" , "level" => "" , "shared" => "LED g" ) , "VGAG0" => array ( "pin" => "24" , "desc" => "VGA Green 0" , "level" => "" , "shared" => "LED g" ) , "VGAB1" => array ( "pin" => "26" , "desc" => "VGA Blue 1" , "level" => "" , "shared" => "LED c" ) , "VGAB0" => array ( "pin" => "25" , "desc" => "VGA Blue 0" , "level" => "" , "shared" => "LED d" ) , "VGAH" => array ( "pin" => "19" , "desc" => "VGA Horizontal Sync" , "level" => "" , "shared" => "LED a" ) , "VGAV" => array ( "pin" => "67" , "desc" => "VGA Vertical Sync" , "level" => "" , "shared" => "Micro P1.7" ) ); $Unused = array ( "pin" => "?" , "desc" => "uncommitted" , "level" => "" , "shared" => "" ); // Function definitions: function PageHeader($page) { echo "

VTM - Verilog Template Maker

"; echo "$page"; echo "
"; } function PageFooter($lastupdate,$php_self) { echo "
"; echo ""; echo "

"; echo ""; echo ""; echo "All comments, suggestions, and bug reports to the author: ed.doering at rose-hulman.edu"; // echo "Ed.Doering@Rose-Hulman.edu.\n\n"; echo "
"; echo "VTM last updated $lastupdate"; echo "
"; echo "
"; echo "


"; //phpinfo(); } function LogUsage($page,$incval,$host,$addr) { // Filenames for log file and counter file $logname = "counters/log_VTM.txt"; $cntname = "counters/cnt_VTM.txt"; // Record the day and time $today = date("Y.m.d_G:i"); // Append info to a file $fp = fopen ($logname, "a"); fwrite ($fp, "$today\t$addr\t$host\t$page\n"); fclose ($fp); // Update counter $counterval = 0; $fp = fopen ($cntname, "r"); $counterval = fread ($fp, filesize ($cntname)); fclose( $fp ); $counterval = (integer)$counterval + 1; $fp = fopen( $cntname,"w"); fwrite( $fp, $counterval); fclose( $fp ); // Send email note whenever counter rolls over to another increment if ($counterval % $incval == 0) { $body = "VTM counter has had another $incval hits ($counterval to date):\n\n"; $body = $body.`/usr/bin/tail -$incval $logname`; $from = "From: VTM.Counter\r\n"; $subj = "$counterval VTM hits to date"; $to = "Ed.Doering@Rose-Hulman.edu"; //mail ($to, $subj, $body, $from); // commented out 15-Dec-2014 } } function ValidateIdentifier($s,$type) { //echo "Processing '$s'

"; // Extract characters used in the string // Note: The second argument ("1") says to return character frequencies > 0 $chars = count_chars($s,1); // Initialize error flag $error = 0; $firsterror = 1; // Verify that identifier has been entered (string length is greater than 1) if (!count($chars)) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

Identifier '$s' has no characters!"; $error = 1; } // Verify that each character is in proper range (A-Z, a-z, 0-9, $ or _) foreach ($chars as $key => $val) { if (!( (48 <= $key && $key <= 57) // 0-9 || (97 <= $key && $key <= 122) // a-z || (65 <= $key && $key <= 90) // A-Z || ($key == 36) // $ || ($key == 95) // _ )) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

Identifier '$s' contains one or more illegal characters!"; $error = 1; } } // Verify that first character is letter or underscore $first = ord($s{0}); if ( (48 <= $first && $first <= 57) // 0-9 || ($first == 36) // $ ) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

Identifier '$s' begins with illegal character!"; $error = 1; } // Verify that last character is not a number (only applies to bit vectors) if ($type) { $last = ord($s{strlen($s)-1}); if ( (48 <= $last && $last <= 57) // 0-9 ) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

Identifier '$s' (a bit vector) ends with a number!"; echo "
(while this is valid Verilog syntax, it will cause"; echo " problems with implementation in Xilinx FPGA tools)"; $error = 1; } } // Explain the rules if ($error) { echo "

Identifier rules:"; echo "
1. Valid characters include letters, numbers, dollar sign $, and underscore _"; echo "
2. First character must be letter or underscore"; } // Return error flag return($error); } function DescriptionUCF($CommentStyle) { echo "$CommentStyle VTM (Verilog Template Maker) created this UCF file at\n"; echo "$CommentStyle "; echo (date("h:i a")); echo " on "; echo (date("F d")); echo(", "); echo(date("Y")); echo ". All comments, suggestions, and bug reports to the author: e.doering at mnsu.edu\n\n"; //echo "Ed.Doering@Rose-Hulman.edu.\n\n"; } function Description($CommentStyle) { echo "$CommentStyle VTM (Verilog Template Maker) created this template file at\n"; echo "$CommentStyle "; echo (date("h:i a")); echo " on "; echo (date("F d")); echo(", "); echo(date("Y")); echo ".\n// All comments, suggestions, and bug reports to the author: e.doering at mnsu.edu\n\n"; //echo "Ed.Doering@Rose-Hulman.edu.\n\n"; } function Disclaimer($CommentStyle) { echo "$CommentStyle It is your responsibility to modify, add, or delete sections of this template\n"; echo "$CommentStyle to make your system work properly. The output from VTM should be considered as\n"; echo "$CommentStyle only a starting point.\n"; echo "$CommentStyle-------------------------------------------------------------------------------\n\n"; } function MakeMenu ($Handle,$Name,$Pins) { // Begin the menu echo "\n"; } /* // echo "\n"; */ function Heading ( $Label ) { echo " - - - - - - - - - - "; echo $Label; echo " - - - - - - - - - - "; } function MakePortNumberForm ($php_self) { // Make initial entry form (collect number of ports) echo "

"; //echo "XS-40 users: Please "; //echo "read me "; //echo "if you do not require either the microcontroller or RAM devices in your design.

"; echo "Enter number of each type of port (multi-bit ports count as one port):

"; echo " inputs, "; echo " outputs, and "; echo " bidirectionals."; echo "

"; echo ""; echo ""; echo ""; echo "

"; } function MakePortEntryFields ($basename,$number) { for ($k=0; $k<$number; $k++) { echo ""; echo ""; echo "
"; } echo "

"; } function MakePortNameForm ($numI,$numO,$numB,$php_self) { // Make port name entry form echo "

"; echo "Enter module name and description:

"; echo ""; echo ""; echo "

"; echo " Use standard prefixes below
"; echo " input port
"; echo " output port
"; echo " bidirectional port
"; echo " registered identifier
"; echo " wire identifier
"; echo "

"; if ($numI>0) { echo "Enter name, width, and description of each input port:

"; MakePortEntryFields("I",$numI); echo "

"; } if ($numO>0) { echo "Enter name, width, and description of each output port:

"; MakePortEntryFields("O",$numO); echo "

"; } if ($numB>0) { echo "Enter name, width, and description of each bidirectional port:

"; MakePortEntryFields("B",$numB); echo "

"; } echo ""; echo ""; // echo ""; echo ""; echo ""; echo ""; echo ""; echo "

"; } // Select an action if (isset($_POST["Action"])) switch ($_POST["Action"]) { case "MakePortNameForm": PageHeader("Enter module and port names..."); $NumI = $_POST["NumI"]; $NumO = $_POST["NumO"]; $NumB = $_POST["NumB"]; MakePortNameForm ($NumI,$NumO,$NumB,$PHP_SELF); PageFooter($lastupdate,$PHP_SELF); LogUsage("Entered number of ports ($NumI,$NumO,$NumB)",$rate,$REMOTE_HOST,$REMOTE_ADDR); break; case "Make Circuit": { // Create shorter variable names from POST variables $ModN = $_POST["ModN"]; $ModD = $_POST["ModD"]; $NumI = $_POST["NumI"]; $NumO = $_POST["NumO"]; $NumB = $_POST["NumB"]; if (isset($_POST["UsePrefixes"])) $UsePrefixes = $_POST["UsePrefixes"]; else $UsePrefixes = 0; $PrefI = $_POST["PrefI"]; $PrefO = $_POST["PrefO"]; $PrefB = $_POST["PrefB"]; $PrefW = $_POST["PrefW"]; $PrefR = $_POST["PrefR"]; //$numi = $_POST["numi"]; //$numo = $_POST["numo"]; //$numb = $_POST["numb"]; // Initialize error flag $error = 0; $firsterror = 1; // Check for illegal characters in module name if (ValidateIdentifier($ModN,0)) { $error = 1; echo "

Module name '$ModN' has problems!"; } // Check for illegal characters in identifier names if ($NumI) { for ($k=0; $k<$NumI; $k++) { $name = $_POST["NI$k"]; // Check for non-empty form field if (!strlen($name)) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

One or more input entry fields is empty!"; $error = 1; } if ($UsePrefixes) $name = $PrefI.$name; // Check final name for validity if (ValidateIdentifier($name,0)) { $error = 1; echo "

Identifier name '$name' has problems!"; } // Verify that last character is not a number for bit vectors $topval = $_POST["WI$k"]-1; if ($topval>0) if (ValidateIdentifier($name,1)) { $error = 1; echo "

Identifier name '$name' (a bit vector) has problems!"; } } } if ($NumO) { for ($k=0; $k<$NumO; $k++) { $name = $HTTP_POST_VARS["NO$k"]; // Check for non-empty form field if (!strlen($name)) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

One or more output entry fields is empty!"; $error = 1; } if ($UsePrefixes) $name = $PrefO.$name; // Check final name for validity if (ValidateIdentifier($name,0)) { $error = 1; echo "

Identifier name '$name' has problems!"; } // Verify that last character is not a number for bit vectors $topval = $HTTP_POST_VARS["WO$k"]-1; if ($topval>0) if (ValidateIdentifier($name,1)) { $error = 1; echo "

Identifier name '$name' (a bit vector) has problems!"; } } } if ($NumB) { for ($k=0; $k<$NumB; $k++) { $name = $HTTP_POST_VARS["NB$k"]; // Check for non-empty form field if (!strlen($name)) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

One or more bidirectional entry fields is empty!"; $error = 1; } if ($UsePrefixes) $name = $PrefB.$name; // Check final name for validity if (ValidateIdentifier($name,0)) { $error = 1; echo "

Identifier name '$name' has problems!"; } // Verify that last character is not a number for bit vectors $topval = $HTTP_POST_VARS["WB$k"]-1; if ($topval>0) if (ValidateIdentifier($name,1)) { $error = 1; echo "

Identifier name '$name' (a bit vector) has problems!"; } } } if ($error) { echo "

Please backup and correct the problem..."; PageFooter($lastupdate,$PHP_SELF); LogUsage("Errors when creating circuit for '$ModN'",$rate,$REMOTE_HOST,$REMOTE_ADDR); } else { echo "

"; echo ""; //echo ""; echo "
"; // Save state of form entries echo ""; echo ""; //echo ""; //echo ""; //echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($NumI) for ($k=0; $k<$NumI; $k++) { echo ""; echo ""; echo ""; } if ($NumO) for ($k=0; $k<$NumO; $k++) { echo ""; echo ""; echo ""; } if ($NumB) for ($k=0; $k<$NumB; $k++) { echo ""; echo ""; echo ""; } echo "
";
// Generate description and disclaimer
Description("//");
Disclaimer("//");

// Generate descriptive comment about this module
echo "//----- Synthesizable Circuit -----\n\n";

// Generate module name and port names list
echo "module $ModN (\n";
if (strlen($ModD)) echo "// $ModD\n";
if ($NumI) {
	echo "\n\t// Inputs:\n";
	for ($k=0; $k<$NumI; $k++) {
		echo "\t";
		if ($UsePrefixes) echo $PrefI;
		echo $HTTP_POST_VARS["NI$k"];
		if ($k==$NumI-1 && $NumO==0 && $NumB==0) echo ""; else echo ",";
		$desc = $HTTP_POST_VARS["DI$k"];
		if (strlen($desc)) echo "\t// $desc";
		echo "\n";
	}
}
if ($NumO) {
	echo "\n\t// Outputs:\n";
	for ($k=0; $k<$NumO; $k++) {
		echo "\t";
		if ($UsePrefixes) echo $PrefO;
		echo $HTTP_POST_VARS["NO$k"];
		if ($k==$NumO-1 && $NumB==0) echo ""; else echo ",";
		$desc = $HTTP_POST_VARS["DO$k"];
		if (strlen($desc)) echo "\t// $desc";
		echo "\n";
	}
}
if ($NumB) {
	echo "\n\t// Bidirectionals:\n";
	for ($k=0; $k<$NumB; $k++) {
		echo "\t";
		if ($UsePrefixes) echo $PrefB;
		echo $HTTP_POST_VARS["NB$k"];
		if ($k==$NumB-1) echo ""; else echo ",";
		$desc = $HTTP_POST_VARS["DB$k"];
		if (strlen($desc)) echo "\t// $desc";
		echo "\n";
	}
}
echo ");\n";

// Generate port mode list
echo "\n// Port mode declarations:";
if ($NumI) {
	echo "\n\t// Inputs:\n";
	for ($k=0; $k<$NumI; $k++) {
		$topval = $HTTP_POST_VARS["WI$k"]-1;
		echo "input\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefI;
		echo $HTTP_POST_VARS["NI$k"];
		echo ";\n";
	}
}
if ($NumO) {
	echo "\n\t// Outputs:\n";
	for ($k=0; $k<$NumO; $k++) {
		$topval = $HTTP_POST_VARS["WO$k"]-1;
		echo "output\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefO;
		echo $HTTP_POST_VARS["NO$k"];
		echo ";\n";
	}
}
if ($NumB) {
	echo "\n\t// Bidirectionals:\n";
	for ($k=0; $k<$NumB; $k++) {
		$topval = $HTTP_POST_VARS["WB$k"]-1;
		echo "inout\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefB;
		echo $HTTP_POST_VARS["NB$k"];
		echo ";\n";
	}
}

// Generate registered identifiers section
if ($NumO) {
	echo "\n\n// Registered identifiers:\n";
	echo "// NOTE: Remove (or comment out) each line for which the 'assign' method is used\n";
	for ($k=0; $k<$NumO; $k++) {
		$topval = $HTTP_POST_VARS["WO$k"]-1;
		echo "reg\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefO;
		echo $HTTP_POST_VARS["NO$k"];
		echo ";\n";
	}
}
// Generate standard structure for bidirectional port
if ($NumB) {
	for ($k=0; $k<$NumB; $k++) {
		$name = $HTTP_POST_VARS["NB$k"];
		echo "\n\n// Circuit for bidirectional port '$name'";

		// Declare tri-state output control as 'reg'
		echo "\nreg\t";
		if ($UsePrefixes) echo $PrefR;
		echo "Enable$name"."AsOutput;\t// Enables tri-state output (active high)";

		// Declare inbound signal as wire
		if (strlen($HTTP_POST_VARS["WB$k"]))
			$topval = $HTTP_POST_VARS["WB$k"]-1;
		else
			$topval = 0;
		echo "\nwire\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefW;
		echo "From$name;\t// Data from port '$name' for use in your system";

		// Declare outbound signal as 'reg'
		echo "\nreg\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefR;
		echo "To$name;\t// Data generated by your system to send to port '$name'";

		// Make tri-state driver
		echo "\nassign ";
		if ($UsePrefixes) echo $PrefB;
		echo "$name = ( ";
		if ($UsePrefixes) echo $PrefR;
		echo "Enable$name"."AsOutput ) ? ";
		if ($UsePrefixes) echo $PrefR;
		echo "To$name : ";
		echo $topval+1;
		echo "'bz;";

		// Connect inbound signal to port
		echo "\nassign ";
		if ($UsePrefixes) echo $PrefW;
		echo "From$name = ";
		if ($UsePrefixes) echo $PrefB;
		echo "$name;";
	}
}

// Generate comment for "functionality" section
echo "\n\n// Functionality:";
echo "\n//";
echo "\n//--- INSERT YOUR CIRCUIT DESCRIPTION HERE";
echo "\n//";
echo "\n\n";
if ($NumB) {
	echo "// NOTE: Your circuit has at least one bidirectional port. A tri-state\n";
	echo "// output structure has been constructed above. Your circuit must generate\n";
	echo "// the 'EnablePortAsOutput' tri-state control signal and the outbound 'ToPort' signal\n";
	echo "// (refer to the structure(s) above for the specific names).\n";
	echo "// The 'FromPort' signal serves as your connection to inbound data from the port.\n";
}

// Generate "endmodule" line
echo "\nendmodule";

echo "
"; echo "
"; LogUsage("Created circuit for '$ModN'",$rate,$REMOTE_HOST,$REMOTE_ADDR); } //phpinfo(); } break; case "Make Testbench": // Initialize error flag $error = 0; $firsterror = 1; // Create shorter variable names $ModN = $_POST["ModN"]; $ModD = $_POST["ModD"]; $NumI = $_POST["NumI"]; $NumO = $_POST["NumO"]; $NumB = $_POST["NumB"]; if (isset($_POST["UsePrefixes"])) $UsePrefixes = $_POST["UsePrefixes"]; else $UsePrefixes = 0; $PrefI = $_POST["PrefI"]; $PrefO = $_POST["PrefO"]; $PrefB = $_POST["PrefB"]; $PrefW = $_POST["PrefW"]; $PrefR = $_POST["PrefR"]; // Check for illegal characters in module name if (ValidateIdentifier($ModN,0)) { $error = 1; echo "

Module name '$ModN' has problems!"; } // Check for illegal characters in identifier names if ($NumI) { for ($k=0; $k<$NumI; $k++) { $name = $HTTP_POST_VARS["NI$k"]; // Check for non-empty form field if (!strlen($name)) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

One or more input entry fields is empty!"; $error = 1; } if ($UsePrefixes) $name = $PrefI.$name; // Check final name for validity if (ValidateIdentifier($name,0)) { $error = 1; echo "

Identifier name '$name' has problems!"; } // Verify that last character is not a number for bit vectors $topval = $HTTP_POST_VARS["WI$k"]-1; if ($topval>0) if (ValidateIdentifier($name,1)) { $error = 1; echo "

Identifier name '$name' (a bit vector) has problems!"; } } } if ($NumO) { for ($k=0; $k<$NumO; $k++) { $name = $HTTP_POST_VARS["NO$k"]; // Check for non-empty form field if (!strlen($name)) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

One or more output entry fields is empty!"; $error = 1; } if ($UsePrefixes) $name = $PrefO.$name; // Check final name for validity if (ValidateIdentifier($name,0)) { $error = 1; echo "

Identifier name '$name' has problems!"; } // Verify that last character is not a number for bit vectors $topval = $HTTP_POST_VARS["WO$k"]-1; if ($topval>0) if (ValidateIdentifier($name,1)) { $error = 1; echo "

Identifier name '$name' (a bit vector) has problems!"; } } } if ($NumB) { for ($k=0; $k<$NumB; $k++) { $name = $HTTP_POST_VARS["NB$k"]; // Check for non-empty form field if (!strlen($name)) { if ($firsterror) { PageHeader("Errors need correcting!"); $firsterror = 0; } echo "

One or more bidirectional entry fields is empty!"; $error = 1; } if ($UsePrefixes) $name = $PrefB.$name; // Check final name for validity if (ValidateIdentifier($name,0)) { $error = 1; echo "

Identifier name '$name' has problems!"; } // Verify that last character is not a number for bit vectors $topval = $HTTP_POST_VARS["WB$k"]-1; if ($topval>0) if (ValidateIdentifier($name,1)) { $error = 1; echo "

Identifier name '$name' (a bit vector) has problems!"; } } } if ($error) { echo "

Please backup and correct the problem..."; PageFooter($lastupdate,$PHP_SELF); LogUsage("Errors when creating testbench for '$ModN'",$rate,$REMOTE_HOST,$REMOTE_ADDR); } else { echo "

"; echo ""; //echo ""; echo "
"; // Save state of form entries echo ""; echo ""; //echo ""; //echo ""; //echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($NumI) for ($k=0; $k<$NumI; $k++) { echo ""; echo ""; echo ""; } if ($NumO) for ($k=0; $k<$NumO; $k++) { echo ""; echo ""; echo ""; } if ($NumB) for ($k=0; $k<$NumB; $k++) { echo ""; echo ""; echo ""; } echo "
";
// Generate description and disclaimer
Description("//");
Disclaimer("//");

echo "//----- Testbench -----\n\n";

// Generate timescale
echo "// Timescale: one time unit = 1ns (e.g., delay specification of #42 means 42ns of time), and\n";
echo "// simulator resolution is 0.1 ns\n";
echo "`timescale 1ns / 100ps";

// Generate module name 
echo "\n\nmodule $ModN"."_TESTBENCH;\n";

// Generate registered identifiers for input stimulus
if ($NumI) {
	echo "\n// Input stimulus:\n";
	for ($k=0; $k<$NumI; $k++) {
		$topval = $HTTP_POST_VARS["WI$k"]-1;
		echo "reg\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefI;
		echo $HTTP_POST_VARS["NI$k"];
		echo ";\n";
	}
}

// Generate wires for output connections
if ($NumO) {
	echo "\n// Output connections:\n";
	for ($k=0; $k<$NumO; $k++) {
		$topval = $HTTP_POST_VARS["WO$k"]-1;
		echo "wire\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefO;
		echo $HTTP_POST_VARS["NO$k"];
		echo ";\n";
	}
}

// Generate wires for bidirectional connections
if ($NumB) {
	echo "\n// Bidirectional connections:\n";
	for ($k=0; $k<$NumB; $k++) {
		$topval = $HTTP_POST_VARS["WB$k"]-1;
		echo "wire\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefB;
		echo $HTTP_POST_VARS["NB$k"];
		echo ";\n";
	}
}

// Generate standard structure for bidirectional port
if ($NumB) {
	for ($k=0; $k<$NumB; $k++) {
		if (strlen($HTTP_POST_VARS["WB$k"]))
			$topval = $HTTP_POST_VARS["WB$k"]-1;
		else
			$topval = 0;

		$name = $HTTP_POST_VARS["NB$k"];
		echo "\n\n// Connection for bidirectional port '$name'";

		// Declare tri-state output control as 'reg'
		echo "\nreg\t";
		if ($UsePrefixes) echo $PrefR;
		echo "ApplyStimulusTo$name;\t// Applies stimulus to port (active high)";

		// Declare applied signal as 'reg'
		echo "\nreg\t";
		if ($topval>0) echo "[$topval:0]\t";
		if ($UsePrefixes) echo $PrefR;
		echo "StimulusTo$name;\t// Stimulus to be applied to port '$name'";

		// Make tri-state driver
		echo "\nassign ";
		if ($UsePrefixes) echo $PrefB;
		echo "$name = ( ";
		if ($UsePrefixes) echo $PrefR;
		echo "ApplyStimulusTo$name ) ? ";
		if ($UsePrefixes) echo $PrefR;
		echo "StimulusTo$name : ";
		echo $topval+1;
		echo "'bz;";
	}
}

// Generate "device instantiation" section
echo "\n\n//Instantiate the DUT (device under test):\n";
echo "$ModN DUT (";

if ($NumI) {
	echo "\n\t// Inputs:\n";
	for ($k=0; $k<$NumI; $k++) {
		echo "\t.";
		if ($UsePrefixes) echo $PrefI;
		echo $HTTP_POST_VARS["NI$k"];
		echo " ( ";
		if ($UsePrefixes) echo $PrefI;
		echo $HTTP_POST_VARS["NI$k"];
		echo " )";
		if ($k==$NumI-1 && $NumO==0 && $NumB==0) echo ""; else echo ",";
		$desc = $HTTP_POST_VARS["DI$k"];
		if (strlen($desc)) echo "\t// $desc";
		echo "\n";
	}
}
if ($NumO) {
	echo "\n\t// Outputs:\n";
	for ($k=0; $k<$NumO; $k++) {
		echo "\t.";
		if ($UsePrefixes) echo $PrefO;
		echo $HTTP_POST_VARS["NO$k"];
		echo " ( ";
		if ($UsePrefixes) echo $PrefO;
		echo $HTTP_POST_VARS["NO$k"];
		echo " )";
		if ($k==$NumO-1 && $NumB==0) echo ""; else echo ",";
		$desc = $HTTP_POST_VARS["DO$k"];
		if (strlen($desc)) echo "\t// $desc";
		echo "\n";
	}
}
if ($NumB) {
	echo "\n\t// Bidirectionals:\n";
	for ($k=0; $k<$NumB; $k++) {
		echo "\t.";
		if ($UsePrefixes) echo $PrefB;
		echo $HTTP_POST_VARS["NB$k"];
		echo " ( ";
		if ($UsePrefixes) echo $PrefB;
		echo $HTTP_POST_VARS["NB$k"];
		echo " )";
		if ($k==$NumB-1) echo ""; else echo ",";
		$desc = $HTTP_POST_VARS["DB$k"];
		if (strlen($desc)) echo "\t// $desc";
		echo "\n";
	}
}
echo ");\n";

// Generate "stimulus" section
echo "\n\t// Specify input stimulus:\n";
echo "\ninitial begin\n";

// Set initial values for input stimulus
if ($NumI) {
	echo "\n\t// Initial values for input stimulus:\n";
	for ($k=0; $k<$NumI; $k++) {
		if (strlen($HTTP_POST_VARS["WI$k"]))
			$bitwidth = $HTTP_POST_VARS["WI$k"];
		else
			$bitwidth = 1;
		echo "\t";
		if ($UsePrefixes) echo $PrefI;
		echo $HTTP_POST_VARS["NI$k"];
		echo " = $bitwidth'b0;\n";
	}
}

echo "\n\t//";
echo "\n\t//--- INSERT YOUR INPUT STIMULUS DESCRIPTION HERE ---";
echo "\n\t//";
if ($NumB>0) {
	echo "\n\t// NOTE: Your circuit has at least one bidirectional port. A tri-state";
	echo "\n\t// stimulus structure has been constructed above. Your testbench must generate";
	echo "\n\t// the 'ApplyStimToPort' tri-state control signal and the 'StimulusToPort' stimulus";
	echo "\n\t// (refer to the structure(s) above for the specific names).";
}

echo "\n\n\t#10 \$stop;\n";
echo "end\n";

// Generate sample clock stimulus
echo "\n\t// Template for master clock. Uncomment and modify signal name as needed.";
echo "\n\t// Remember to set the initial value of 'Clock' in the 'initial' block above.";
echo "\n//always #5 Clock = ~Clock;";



// Generate "endmodule" line
echo "\n\n\nendmodule";

echo "
"; echo "
"; LogUsage("Created testbench for '$ModN'",$rate,$REMOTE_HOST,$REMOTE_ADDR); } break; case "MakeUCF2": { PageHeader("Match FPGA pins to specific XS-40 resources..."); // Issue comments about suggested usage based on form selections if (!$UseMicro) { echo "

NOTE: "; echo "Apply high level to Micro Reset (P36) to force all microcontroller pins to Hi Z."; } if (!$UseRAM) { echo "

NOTE: "; echo "Apply high level to SRAM Output Enable (P61) to force all RAM data pins to Hi Z."; } if ($UseLED && $UseVGA) { echo "

CAUTION: "; echo "You cannot independently use the LED and VGA port at the same time!"; } if ($UsePPortFromPC) { echo "

NOTE: "; echo "The upper two bits of the PC parallel port (Bits 7 and 6) require special treatment in order to "; echo "be used as inputs for your design. "; echo "Read me "; echo "to learn how."; } // Begin with all pins available foreach ($Resources as $resource) if (!$resource[dedicated]) $Pins[$resource[pin]] = $Unused; // Assign resources as requested if (!$UseMicro) $Pins[$Resources[MicroReset][pin]] = $Resources[MicroReset]; if (!$UseRAM) $Pins[$Resources[RAMOE][pin]] = $Resources[RAMOE]; if ($UseOsc) { $Pins[$Resources[OSC][pin]] = $Resources[OSC]; } if ($UsePPortFromPC) { $Pins[$Resources[PPortFromPC5][pin]] = $Resources[PPortFromPC5]; $Pins[$Resources[PPortFromPC4][pin]] = $Resources[PPortFromPC4]; $Pins[$Resources[PPortFromPC3][pin]] = $Resources[PPortFromPC3]; $Pins[$Resources[PPortFromPC2][pin]] = $Resources[PPortFromPC2]; $Pins[$Resources[PPortFromPC1][pin]] = $Resources[PPortFromPC1]; $Pins[$Resources[PPortFromPC0][pin]] = $Resources[PPortFromPC0]; } if ($UsePPortToPC) { $Pins[$Resources[PPortToPC7][pin]] = $Resources[PPortToPC7]; $Pins[$Resources[PPortToPC6][pin]] = $Resources[PPortToPC6]; $Pins[$Resources[PPortToPC5][pin]] = $Resources[PPortToPC5]; $Pins[$Resources[PPortToPC4][pin]] = $Resources[PPortToPC4]; $Pins[$Resources[PPortToPC3][pin]] = $Resources[PPortToPC3]; } if ($UseVGA) { $Pins[$Resources[VGAR1][pin]] = $Resources[VGAR1]; $Pins[$Resources[VGAR0][pin]] = $Resources[VGAR0]; $Pins[$Resources[VGAG1][pin]] = $Resources[VGAG1]; $Pins[$Resources[VGAG0][pin]] = $Resources[VGAG0]; $Pins[$Resources[VGAB1][pin]] = $Resources[VGAB1]; $Pins[$Resources[VGAB0][pin]] = $Resources[VGAB0]; $Pins[$Resources[VGAH][pin]] = $Resources[VGAH]; $Pins[$Resources[VGAV][pin]] = $Resources[VGAV]; } if ($UseLED) { $Pins[$Resources[LEDa][pin]] = $Resources[LEDa]; $Pins[$Resources[LEDb][pin]] = $Resources[LEDb]; $Pins[$Resources[LEDc][pin]] = $Resources[LEDc]; $Pins[$Resources[LEDd][pin]] = $Resources[LEDd]; $Pins[$Resources[LEDe][pin]] = $Resources[LEDe]; $Pins[$Resources[LEDf][pin]] = $Resources[LEDf]; $Pins[$Resources[LEDg][pin]] = $Resources[LEDg]; } if ($UsePS2) { $Pins[$Resources[PS2DATA][pin]] = $Resources[PS2DATA]; $Pins[$Resources[PS2CLK][pin]] = $Resources[PS2CLK]; } if ($UseRAM) { $Pins[$Resources[RAMOE][pin]] = $Resources[RAMOE]; $Pins[$Resources[RAMWE][pin]] = $Resources[RAMWE]; $Pins[$Resources[RAMCE][pin]] = $Resources[RAMCE]; $Pins[$Resources[RAMA14][pin]] = $Resources[RAMA14]; $Pins[$Resources[RAMA13][pin]] = $Resources[RAMA13]; $Pins[$Resources[RAMA12][pin]] = $Resources[RAMA12]; $Pins[$Resources[RAMA11][pin]] = $Resources[RAMA11]; $Pins[$Resources[RAMA10][pin]] = $Resources[RAMA10]; $Pins[$Resources[RAMA09][pin]] = $Resources[RAMA09]; $Pins[$Resources[RAMA08][pin]] = $Resources[RAMA08]; $Pins[$Resources[RAMA07][pin]] = $Resources[RAMA07]; $Pins[$Resources[RAMA06][pin]] = $Resources[RAMA06]; $Pins[$Resources[RAMA05][pin]] = $Resources[RAMA05]; $Pins[$Resources[RAMA04][pin]] = $Resources[RAMA04]; $Pins[$Resources[RAMA03][pin]] = $Resources[RAMA03]; $Pins[$Resources[RAMA02][pin]] = $Resources[RAMA02]; $Pins[$Resources[RAMA01][pin]] = $Resources[RAMA01]; $Pins[$Resources[RAMA00][pin]] = $Resources[RAMA00]; $Pins[$Resources[RAMD07][pin]] = $Resources[RAMD07]; $Pins[$Resources[RAMD06][pin]] = $Resources[RAMD06]; $Pins[$Resources[RAMD05][pin]] = $Resources[RAMD05]; $Pins[$Resources[RAMD04][pin]] = $Resources[RAMD04]; $Pins[$Resources[RAMD03][pin]] = $Resources[RAMD03]; $Pins[$Resources[RAMD02][pin]] = $Resources[RAMD02]; $Pins[$Resources[RAMD01][pin]] = $Resources[RAMD01]; $Pins[$Resources[RAMD00][pin]] = $Resources[RAMD00]; } // Separate pins into committed and uncommitted pins foreach ($Pins as $pin => $resource) if ($resource[desc]=="uncommitted") $Upins[$pin]=$resource; else $Cpins[$resource[desc]]=$resource; // Sort the pin lists ksort($Upins); ksort($Cpins); //echo "

committed pins"; //foreach ($Cpins as $pin => $resource) echo "
$pin is $resource[desc]"; //echo "

uncommitted pins"; //foreach ($Upins as $pin => $resource) echo "
$pin is $resource[desc]"; // Reassemble pin lists unset($Pins); foreach ($Cpins as $resource) $Pins[$resource[pin]]=$resource; foreach ($Upins as $pin => $resource) $Pins[$pin]=$resource; // Display pin usage to date //echo "

Reassembled pins"; //foreach ($Pins as $pin => $resource) echo "
$pin is $resource[desc]"; // Start the form echo "

"; if ($NumI) { // Input table echo "Select a resource for each input pin:"; echo "\n"; // Make a row for each input $handle=0; for ($k=0; $k<$NumI; $k++) { // Determine bit width of identifier if (strlen($HTTP_POST_VARS["WI$k"])) $topval = $HTTP_POST_VARS["WI$k"]-1; else $topval = 0; // Show identifier for ($j=$topval; $j>=0; $j--) { echo ""; // Make menu echo ""; } // End of row echo ""; } // End the table echo "
"; $name=$HTTP_POST_VARS["NI$k"]; echo ""; if ($UsePrefixes) $name=$PrefI.$name; if ($topval) $name=$name."<$j>"; echo "$name"; echo ""; echo ""; MakeMenu("NI$handle",$name,$Pins); $handle++; echo "
"; echo "

"; } // Record total number of input pins $numi = $handle; $handle=0; if ($NumO) { // Output table echo "Select a resource for each output pin:"; echo "\n"; // Make a row for each output for ($k=0; $k<$NumO; $k++) { // Determine bit width of identifier if (strlen($HTTP_POST_VARS["WO$k"])) $topval = $HTTP_POST_VARS["WO$k"]-1; else $topval = 0; // Show identifier for ($j=$topval; $j>=0; $j--) { echo ""; // Make menu echo ""; } // End of row echo ""; } // End the table echo "
"; $name=$HTTP_POST_VARS["NO$k"]; echo ""; if ($UsePrefixes) $name=$PrefO.$name; if ($topval) $name=$name."<$j>"; echo "$name"; echo ""; echo ""; MakeMenu("NO$handle",$name,$Pins); $handle++; echo "
"; echo "

"; } // Record total number of output pins $numo = $handle; $handle=0; if ($NumB) { // Bidirectional table echo "Select a resource for each bidirectional pin:"; echo "\n"; // Make a row for each output for ($k=0; $k<$NumB; $k++) { // Determine bit width of identifier if (strlen($HTTP_POST_VARS["WB$k"])) $topval = $HTTP_POST_VARS["WB$k"]-1; else $topval = 0; // Show identifier for ($j=$topval; $j>=0; $j--) { echo ""; // Make menu echo ""; } // End of row echo ""; } // End the table echo "
"; $name=$HTTP_POST_VARS["NB$k"]; echo ""; if ($UsePrefixes) $name=$PrefB.$name; if ($topval) $name=$name."<$j>"; echo "$name"; echo ""; echo ""; MakeMenu("NB$handle",$name,$Pins); $handle++; echo "
"; echo "

"; } // Record total number of bidirectional pins $numb = $handle; // Make entry buttons echo ""; echo ""; // Save number of pins for each type echo ""; echo ""; echo ""; // Specify next action echo ""; // End the form echo "

"; } PageFooter($lastupdate,$PHP_SELF); LogUsage("Matching FPGA pins to XS40 resources",$rate,$REMOTE_HOST,$REMOTE_ADDR); break; case "Make UCF": { PageHeader("Select XS-40 resources..."); echo "Select the XS-40 resources you require:"; echo "
"; echo " Seven-segment LED
"; echo " Oscillator
"; echo " Parallel Port From PC
"; echo " Parallel Port To PC
"; echo " VGA Port
"; echo " PS/2 Port
"; echo " 8031 Microcontroller [not implemented yet]
"; echo " SRAM (32Kx8)
"; echo "

"; echo ""; echo ""; // Specify next action echo ""; // Save state of form entries echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($NumI) for ($k=0; $k<$NumI; $k++) { echo ""; echo ""; echo ""; } if ($NumO) for ($k=0; $k<$NumO; $k++) { echo ""; echo ""; echo ""; } if ($NumB) for ($k=0; $k<$NumB; $k++) { echo ""; echo ""; echo ""; } echo "

"; } PageFooter($lastupdate,$PHP_SELF); LogUsage("Selecting XS40 resources",$rate,$REMOTE_HOST,$REMOTE_ADDR); break; case "MakeUCF3": { /* echo "Total of $numi input pins
"; echo "Total of $numo output pins
"; echo "Total of $numb bidirectional pins
"; */ echo "
";

// Generate description
DescriptionUCF("#");

// Generate the UCF text
echo <<";
}
	LogUsage("Created UCF",$rate,$REMOTE_HOST,$REMOTE_ADDR);
	break;

	case "Home":
	PageHeader("Welcome to VTM!");
	MakePortNumberForm($PHP_SELF);
	PageFooter($lastupdate,$PHP_SELF);
	LogUsage("Arrived at top-level page",$rate,$REMOTE_HOST,$REMOTE_ADDR);
	break;

	default:
		echo "Unrecognized action \"$Action\"";
	}
else {
	PageHeader("Welcome to VTM!");
	MakePortNumberForm($PHP_SELF);
	PageFooter($lastupdate,$PHP_SELF);
	LogUsage("Arrived at top-level page",$rate,$REMOTE_HOST,$REMOTE_ADDR);
}
	
//phpinfo();

?>