Date:2012-11-06 16:05:52 (11 years 4 months ago)
Author:Werner Almesberger
Commit:025726e48be9ee123c2793e1b89ee675b27020f6
Message:ioscript/: script-based toggling of IO pins (for device testing)

Files: ioscript/ioscript (1 diff)
ioscript/try (1 diff)

Change Details

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        for (split /,/) {
61            die "unknown bit \"$_\"" unless defined $bit{$_};
62            push(@pos, $_);
63        }
64    } elsif (/^(\S+)=(\S+)\s*/) {
65        die "unknown bit \"$2\"" unless defined $bit{$2};
66        die "bit \"$1\" is already defined" if defined $bit{$1};
67        $bit{$1} = $bit{$2};
68    } elsif (/^echo\s+/) {
69        print "$'\n";
70    } elsif (/^show\s*$/) {
71        $tdir = &peek($PDDIR);
72        $tdat = &peek($PDDAT);
73        for (@pos) {
74            $v = 1 << $bit{$_};
75            print "$_($bit{$_})=",
76                $tdir & $v ? $tdat & $v ? "1" : "0" : "Z", " ";
77        }
78        print "\n";
79    } elsif (/^wait\s+([01-]+)\s*$/) {
80        $m = 0;
81        $c = 0;
82        @p = @pos;
83        $s = $1;
84        while (length $s) {
85            die "out of bits" unless @p;
86            $v = 1 << $bit[shift @p];
87            if ($s =~ /^0/) {
88                $m |= $v;
89            } elsif ($s =~ /^1/) {
90                $m |= $v;
91                $c |= $v;
92            }
93            $s = substr($s, 1);
94        }
95# @@@ to do
96    } elsif (/^sleep\s+(\d+|\d*\.\d*)\s*$/) {
97        select(undef, undef, undef, $1);
98    } elsif (/^([-01zZ]+)\s*$/) {
99        @p = @pos;
100        ($tdir, $tdat) = ($dir, $dat);
101        $s = $1;
102        while (length $s) {
103            die "out of bits" unless @p;
104            $v = 1 << $bit{shift @p};
105            if ($s =~ /^0/) {
106                $tdir |= $v;
107                $tdat &= ~$v;
108            } elsif ($s =~ /^1/) {
109                $tdir |= $v;
110                $tdat |= $v;
111            } elsif ($s =~ /^[zZ]/) {
112                $tdir &= ~$v;
113            }
114            $s = substr($s, 1);
115        }
116        &poke($PDDATS, $tdat & ~$dat);
117        &poke($PDDATC, ~$tdat & $dat);
118        &poke($PDDIRS, $tdir & ~$dir);
119        &poke($PDDIRC, ~$tdir & $dir);
120        ($dir, $dat) = ($tdir, $tdat);
121    } else {
122        die "unrecognized command \"$_\"";
123    }
124}
ioscript/try
1# test script for antorcha/whip/led/
2
3#DAT2,DAT3,CMD,VDD,CLK,DAT0,DAT1
4
5SCLK=DAT1
6LCLK=DAT0
7DS=CLK
8
9VDD,DS,SCLK,LCLK
10show
111111 # power off, drive all data lines to 1
12sleep 0.1 # let caps trickle-charge
130000 # power on
14-1-- # send "1"
15--1-
16--0-
17--1- # send another "1"
18--0-
19---1 # latch
20---0
21sleep 1
22-0-- # send "0"
23--1-
24--0-
25---1 # latch
26---0
27sleep 1

Archive Download the corresponding diff file

Branches:
master



interactive