Root/ioscript/ioscript

1#!/usr/bin/perl
2
3$PDDAT = 0x10010310;
4$PDDATS = 0x10010314;
5$PDDATC = 0x10010318;
6$PDFUNC = 0x10010348;
7$PDDIR = 0x10010360;
8$PDDIRS = 0x10010364;
9$PDDIRC = 0x10010368;
10
11$bit{"DAT2"} = 12;
12$bit{"DAT3"} = 13;
13$bit{"CMD"} = 8;
14$bit{"VDD"} = 2;
15$bit{"CLK"} = 9;
16$bit{"DAT0"} = 10;
17$bit{"DAT1"} = 11;
18
19
20sub poke
21{
22    local ($a, $v) = @_;
23
24    return unless $v;
25    $c = sprintf("ssh jlime poke 0x%0x 0x%0x", $a, $v & $mask);
26#print STDERR "$c\n";
27    system($c);
28}
29
30
31sub peek
32{
33    local ($a) = @_;
34
35    $c = sprintf("ssh jlime poke 0x%x", $a);
36#print STDERR "$c\n";
37    return hex(`$c`);
38}
39
40
41$mask = 0;
42for (values %bit) {
43    $mask |= 1 << $_;
44}
45&poke($PDFUNC, $mask);
46
47$dat = 1 << $bit{"VDD"};
48$dir = $dat;
49&poke($PDDATS, $dat);
50&poke($PDDATC, $mask ^ $dat);
51&poke($PDDIRS, $dir);
52&poke($PDDIRC, $mask ^ $dir);
53
54while (<>) {
55    print STDERR;
56    chop;
57    s/#.*//;
58    next if /^\s*$/;
59    if (/^\S+,(\S+,)*\S+/) {
60        @pos = ();
61        for (split /,/) {
62            die "unknown bit \"$_\"" unless defined $bit{$_};
63            push(@pos, $_);
64        }
65    } elsif (/^(\S+)=(\S+)\s*/) {
66        die "unknown bit \"$2\"" unless defined $bit{$2};
67        die "bit \"$1\" is already defined" if defined $bit{$1};
68        $bit{$1} = $bit{$2};
69    } elsif (/^echo\s+/) {
70        print "$'\n";
71    } elsif (/^show\s*$/) {
72        $tdir = &peek($PDDIR);
73        $tdat = &peek($PDDAT);
74        for (@pos) {
75            $v = 1 << $bit{$_};
76            print "$_($bit{$_})=",
77                $tdir & $v ? $tdat & $v ? "1" : "0" : "Z", " ";
78        }
79        print "\n";
80    } elsif (/^wait\s+([01-]+)\s*$/) {
81        $m = 0;
82        $c = 0;
83        @p = @pos;
84        $s = $1;
85        while (length $s) {
86            die "out of bits" unless @p;
87            $v = 1 << $bit[shift @p];
88            if ($s =~ /^0/) {
89                $m |= $v;
90            } elsif ($s =~ /^1/) {
91                $m |= $v;
92                $c |= $v;
93            }
94            $s = substr($s, 1);
95        }
96# @@@ to do
97    } elsif (/^sleep\s+(\d+|\d*\.\d*)\s*$/) {
98        select(undef, undef, undef, $1);
99    } elsif (/^([-01zZ]+)\s*$/) {
100        @p = @pos;
101        ($tdir, $tdat) = ($dir, $dat);
102        $s = $1;
103        while (length $s) {
104            die "out of bits" unless @p;
105            $v = 1 << $bit{shift @p};
106            if ($s =~ /^0/) {
107                $tdir |= $v;
108                $tdat &= ~$v;
109            } elsif ($s =~ /^1/) {
110                $tdir |= $v;
111                $tdat |= $v;
112            } elsif ($s =~ /^[zZ]/) {
113                $tdir &= ~$v;
114            }
115            $s = substr($s, 1);
116        }
117        &poke($PDDATS, $tdat & ~$dat);
118        &poke($PDDATC, ~$tdat & $dat);
119        &poke($PDDIRS, $tdir & ~$dir);
120        &poke($PDDIRC, ~$tdir & $dir);
121        ($dir, $dat) = ($tdir, $tdat);
122    } else {
123        die "unrecognized command \"$_\"";
124    }
125}
126

Archive Download this file

Branches:
master



interactive