#!/usr/local/bin/perl -w

if($#ARGV == 0)
{
    $MHZ = $ARGV[0];
}
else
{
    print STDERR "usage: speed mhz\n";
    exit(1);
}

$cnt = 129 - 2 * $MHZ;

#open(JTL, "|/home/pram/bin/jtl -cmd 'connect real 0x03bc'");
open(JTL, "|/home/pram/bin/jtl -cmd 'connect real /dev/pram0/control'");
#open(JTL, "|cat");
print JTL
    "include /home/pram/jtag/path/root.jtl\n"
    ."select root:clock:U1\n"
    ."instr sample\n";

sub shift
{
    printf JTL
    "shift 000000000000000000%d00000000000000000000000000000000000%d00%d00%d00%d00%d00%d00%d00%d00000000000000000000000000000000\n",
    $clk, $ld, $pl[0], $pl[1], $pl[2], $pl[3], $pl[4], $pl[5], $pl[6];
}

for($i=0; $i<7; $i++)
{
    $pl[$i] = ($cnt >> $i) % 2;
}

$clk = 0;
$ld = 1;
&shift;

print JTL
    "view normal\n"
    ."instr intest\n";

$clk = 1;
&shift;

$clk = 0;
$ld = 0;
&shift;

print JTL
    "instr bypass\n"
    ."select\n";
close JTL;
