OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [tools/] [bin/] [ti_rri] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 wfjm
#! /usr/bin/env tclsh
2
# -*- tcl -*-
3
# $Id: ti_rri 375 2011-04-02 07:56:47Z mueller $
4
#
5
# Copyright 2011- by Walter F.J. Mueller 
6
#
7
# This program is free software; you may redistribute and/or modify it under
8
# the terms of the GNU General Public License as published by the Free
9
# Software Foundation, either version 2, or at your option any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
13
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
# for complete details.
15
#
16
#  Revision History:
17
# Date         Rev Version  Comment
18
# 2011-04-02   376   1.0    Initial version
19
# 2011-03-19   371   0.1    First draft
20
#
21
#
22
# --fifo[=name,keep]
23
# --term[=???]        ; not yet implemented...
24
# --run=command
25
# --log=filename      ; default "-"
26
# --logl=n            ; default 2
27
# --dmpl=n            ; default 0
28
# --tiol=n            ; default 0
29
# --int
30
# --help
31
# --
32
#   tcl cmds
33
#   @...tcl
34
#
35
 
36
array set opts {
37
    fifo   0
38
    fifo_  ""
39
    term   0
40
    term_  ""
41
    run_   ""
42
    log_   "-"
43
    logl_  2
44
    dmpl_  0
45
    tiol_  0
46
    int    0
47
    help   0
48
}
49
 
50
set clist {}
51
set optsendseen 0
52
 
53
foreach arg $argv {
54
  if { $optsendseen } {
55
    lappend clist $arg
56
    continue
57
  }
58
  switch -regexp -- $arg {
59
    ^--?fifo=?.*$ { set opts(fifo) 1; regexp -- {=(.*)} $arg dummy opts(fifo_) }
60
    ^--?term=?.*$ { set opts(term) 1; regexp -- {=(.*)} $arg dummy opts(term_) }
61
    ^--?run=.+$   { regexp -- {=(.*)} $arg dummy opts(run_) }
62
    ^--?log=.+$   { regexp -- {=(.*)} $arg dummy opts(log_) }
63
    ^--?logl=.+$  { regexp -- {=(.*)} $arg dummy opts(logl_) }
64
    ^--?dmpl=.+$  { regexp -- {=(.*)} $arg dummy opts(dmpl_) }
65
    ^--?tiol=.+$  { regexp -- {=(.*)} $arg dummy opts(tiol_) }
66
    ^--?int$      { set opts(int) 1 }
67
    ^--?help$     { set opts(help) 1 }
68
    ^--$          { set optsendseen 1 }
69
    ^--.+$        { puts "-E: bad option $arg, see --help for proper usage"
70
                    return 1
71
                  }
72
    default       { lappend clist $arg }
73
  }
74
}
75
 
76
if { $opts(help) } {
77
  puts "usage: ti_rri"
78
  return 0
79
}
80
 
81
if { $opts(fifo) && $opts(term) } {
82
  puts "-E: both --fifo and --term given, only one allowed"
83
  return 1
84
}
85
 
86
lappend auto_path [file join $env(RETROBASE) tools tcl]
87
lappend auto_path [file join $env(RETROBASE) tools lib]
88
 
89
package require rlink
90
package require rutiltpp
91
package require rlinktpp
92
 
93
rlinkconnect rlc
94
 
95
# setup logging
96
if { $opts(log_) ne "-" } {
97
  rlc config -logfile       $opts(log_)
98
}
99
rlc config -logprintlevel $opts(logl_)
100
rlc config -logdumplevel  $opts(dmpl_)
101
rlc config -logtracelevel $opts(tiol_)
102
 
103
# first start, if specified with -run, the test bench
104
set runpid {}
105
if { $opts(run_) ne "" } {
106
  if { [catch {eval "exec $opts(run_) &" } runpid] } {
107
    puts "-E: failed to execute \"$opts(run_)\" with error message\n  $runpid"
108
    puts "aborting..."
109
    return 1
110
  }
111
}
112
 
113
# than open the rlink connection
114
# handle --fifo
115
if { $opts(fifo) } {
116
  set nlist [split $opts(fifo_) ","]
117
  set path [lindex $nlist 0]
118
  set keep [lindex $nlist 1]
119
  if {$path eq ""} {set path "rlink_cext_fifo"}
120
  set url "fifo:$path"
121
  if {$keep ne ""} {append url "?keep"}
122
  rlc open $url
123
}
124
 
125
# handle --term
126
if { $opts(term) } {
127
  set nlist [split $opts(term_) ","]
128
  set dev  [lindex $nlist 0]
129
  set baud [lindex $nlist 1]
130
  set brk  [lindex $nlist 2]
131
  if {$dev  eq ""} {set dev  "/dev/ttyS0"}
132
  if {$baud eq ""} {set baud "115k"}
133
  set url "term:$dev?baud=$baud"
134
  if {$brk ne ""} {append url ";break"}
135
  rlc open $url
136
}
137
 
138
# setup simulation mode default
139
set rlink::sim_mode [rlink::isfifo]
140
 
141
foreach cmd $clist {
142
  # handle @filename commands
143
  if { [regexp {^@(.+)} $cmd dummy filename] } {
144
    # handle @file.tcl --> source tcl file
145
    if { [regexp {\.tcl$} $filename] } {
146
      if { [catch {source $filename} errmsg] } {
147
        puts "-E: failed to source file \"$filename\" with error message:"
148
        if {[info exists errorInfo]} {puts $errorInfo} else {puts $errmsg}
149
        puts "aborting..."
150
        break
151
      }
152
    # handle @file.dat ect --> not yet supported
153
    } else {
154
      puts "-E: only tcl supported but $filename found"
155
      puts "aborting..."
156
      break
157
    }
158
 
159
  # handle normal tcl commands --> eval them
160
  } else {
161
    if { [catch {eval $cmd} errmsg] } {
162
      puts "-E: eval of \"$cmd\" failed with error message:"
163
      if {[info exists errorInfo]} {puts $errorInfo} else {puts $errmsg}
164
      puts "aborting..."
165
      break
166
    }
167
  }
168
}
169
 
170
# if tclsh runs a script given on the command line or is invoked
171
# like here via a shebang the tcl_interactive is always set to 0
172
# so we have to check whether stdin/stdout is a terminal and set
173
# tcl_interactive accordingly
174
 
175
# FIXME_code: fstat not available (grr...), currently just assume istty
176
set tcl_interactive 1
177
 
178
if { $opts(int) || [llength $clist] == 0 } {
179
  if {$tcl_interactive} {
180
    package require tclreadline
181
    namespace eval tclreadline {
182
      proc prompt1 {} {
183
        set version [info tclversion]
184
        return "ti_rri > "
185
      }
186
    }
187
    ::tclreadline::Loop
188
  }
189
}
190
 
191
#
192
# now close rlink connection
193
#
194
if { $opts(fifo) || $opts(term) } {
195
  rlc close
196
}
197
 
198
# FIXME_code: should sync here with -run process run-down
199
#             but no wait available in tcl (grr...)
200
if { $runpid } {
201
  after 100;                            # currently just wait 100ms
202
}
203
 
204
return 0

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.