diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /appl/cmd/auxi/fpgaload.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/cmd/auxi/fpgaload.b')
| -rw-r--r-- | appl/cmd/auxi/fpgaload.b | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/appl/cmd/auxi/fpgaload.b b/appl/cmd/auxi/fpgaload.b new file mode 100644 index 00000000..5c37b80b --- /dev/null +++ b/appl/cmd/auxi/fpgaload.b @@ -0,0 +1,67 @@ +implement Fpgaload; + +include"sys.m"; + sys: Sys; + +include "draw.m"; + +include "arg.m"; + +Fpgaload: module +{ + init: fn(nil: ref Draw->Context, nil: list of string); +}; + +init(nil: ref Draw->Context, args: list of string) +{ + sys = load Sys Sys->PATH; + arg := load Arg Arg->PATH; + if(arg == nil) + error(sys->sprint("can't load %s: %r", Arg->PATH)); + arg->init(args); + arg->setusage("fpgaload [-c clock] file.rbf"); + clock := -1; + while((c := arg->opt()) != 0) + case c { + 'c' => + clock = int arg->earg(); + if(clock <= 0) + error("invalid clock value"); + * => + arg->usage(); + } + args = arg->argv(); + if(args == nil) + arg->usage(); + arg = nil; + + fd := sys->open(hd args, Sys->OREAD); + if(fd == nil) + error(sys->sprint("can't open %s: %r", hd args)); + ofd := sys->open("#G/fpgaprog", Sys->OWRITE); + if(ofd == nil) + error(sys->sprint("can't open %s: %r", "#G/fpgaprog")); + a := array[128*1024] of byte; + while((n := sys->read(fd, a, len a)) > 0) + if(sys->write(ofd, a, n) != n) + error(sys->sprint("write error: %r")); + if(n < 0) + error(sys->sprint("read error: %r")); + if(clock >= 0) + setclock(clock); +} + +setclock(n: int) +{ + fd := sys->open("#G/fpgactl", Sys->OWRITE); + if(fd == nil) + error(sys->sprint("can't open %s: %r", "#G/fpgactl")); + if(sys->fprint(fd, "bclk %d", n) < 0) + error(sys->sprint("can't set clock to %d: %r", n)); +} + +error(s: string) +{ + sys->fprint(sys->fildes(2), "fpgaload: %s\n", s); + raise "fail:error"; +} |
