include("dlg02_form.php");
?>
|
if (isset($_POST["action"])) {
print "" . $txt["RESULTCODE"] . "\n";
print "";
printCommentLine( "avr delay loop generator V $version" );
printCommentLine( "feel free to use the generated code." );
printCommentLine( "------------------------------------" );
// ----------------------------------------------------
// ----------------------------------------------------------------------------
// main program starts here: --------------------------------------------------
$cpuspeed_value = $cpuspeed_type == "select" ? $cpuspeed_select : $cpuspeed_entry;
$cpuspeed = false;
if (preg_match( "/^(\d[0-9.]*)\s*(MHz)?/i" , $cpuspeed_value, $matches )) {
$cpuspeed = (float)$matches[1];
// print "$cpuspeed \n";
if (isset( $matches[2] )) {
$cpuspeed *= 1000000;
}
// $cpuspeed = round( $cpuspeed );
}
printCommentLine( "CPUSPEED = $cpuspeed [1/sec]" );
// time to burn:
// way #1:
$time_to_burn = 0.0; // [sec]
// convert a string like 5s65ms to a sec-Value:
$tmp = trim( $delaytime_entry );
if ($delaytime_type == "entry1") {
while (preg_match("/^([0-9][0-9.]*)([hmsu]+)/i", $tmp, $matches )) {
$number = (float)$matches[1];
$timename = $matches[2];
if ($timename == "us") {
$number = $number / 1000000.0;
}
elseif ($timename == "ms") {
$number = $number / 1000.0;
}
elseif ($timename == "m") {
$number = $number * 60.0;
}
elseif ($timename == "h") {
$number = $number * 3600.0;
}
elseif ($timename == "s") {
$number = $number;
}
else {
print "unknown time format in '$tmp'. \n";
return 0;
}
$time_to_burn += $number;
$tmp = substr( $tmp, strlen($matches[1] . $matches[2]) );
}
printCommentLine( "time to delay: $time_to_burn [sec]" );
$cycles_to_burn = $time_to_burn * $cpuspeed;
$cycles_to_burn = (int)round( $cycles_to_burn );
}
else {
$cycles_to_burn = (int)$tmp;
if ($cpuspeed > 0) {
$time_to_burn = $cycles_to_burn / $cpuspeed;
printCommentLine( "time to delay: $time_to_burn [sec]" );
}
}
printCommentLine( "cycles to delay: " . $cycles_to_burn );
//$cycles_to_burn = 13;
//printCommentLine( "test cycles to burn: " . $cycles_to_burn . "");
if ($time_to_burn > 0.05) {
printCommentLine( "");
printCommentLine( "Sorry, but this online version calculates");
printCommentLine( "only loops with up to 0.05 seconds.");
exit();
}
// zu verbratende Zyklen coden:
printCommentLine("");
$minus1 = num_start_code_cycles( $cycles_to_burn );
$minus2 = num_end_code_cycles( $cycles_to_burn );
printCommentLine("$minus1, $minus2");
$cycles_to_burn = $cycles_to_burn - $minus1 - $minus2;
printCommentLine( "cycles to delay: " . $cycles_to_burn . " + $minus1 + $minus2" );
burn_start_code( $cycles_to_burn );
$maxiter = 30;
while (( $cycles_to_burn > 0 ) && ($maxiter > 0)) {
printCodeLine( "", "", "cycles to do = $cycles_to_burn");
$gewinn = burn_cycles( $cycles_to_burn );
printCodeLine( "", "", "gain = $gewinn");
$cycles_to_burn -= $gewinn;
$maxiter -= 1;
}
burn_end_code( $cycles_to_burn );
?>
if ($maxiter <= 0) {
print "Iteration overflow!";
}
} // action
else {
print " \n";
}
// ----------------------------------------------------------------------------
?>
|