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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [bin/] [ti_rri] - Blame information for rev 15

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 15 wfjm
# $Id: ti_rri 435 2011-12-04 20:15:25Z mueller $
4 10 wfjm
#
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 15 wfjm
# 2011-12-04   435   1.0.2  add flow attribute to --term
19 12 wfjm
# 2011-04-22   379   1.0.1  check for RETROBASE; proper exit handling; help text
20 11 wfjm
# 2011-04-17   376   1.0    Initial version
21 10 wfjm
# 2011-03-19   371   0.1    First draft
22
#
23
#
24
# --fifo[=name,keep]
25 15 wfjm
# --term[=name,baud,break,flow]
26 10 wfjm
# --run=command
27
# --log=filename      ; default "-"
28
# --logl=n            ; default 2
29
# --dmpl=n            ; default 0
30
# --tiol=n            ; default 0
31
# --int
32
# --help
33
# --
34
#   tcl cmds
35
#   @...tcl
36
#
37
 
38
array set opts {
39
    fifo   0
40
    fifo_  ""
41
    term   0
42
    term_  ""
43
    run_   ""
44
    log_   "-"
45
    logl_  2
46
    dmpl_  0
47
    tiol_  0
48
    int    0
49
    help   0
50
}
51
 
52
set clist {}
53
set optsendseen 0
54 12 wfjm
set runpid {}
55 10 wfjm
 
56 12 wfjm
#
57
# cleanup handler
58
#   must be in a proc so that it can be called from tclreadline
59
#   must be defined before ::tclreadline::Loop called (all after ignored...)
60
#
61
proc exit_cleanup {} {
62
  global opts
63
  global runpid
64
 
65
  # now close rlink connection
66
  if { $opts(fifo) || $opts(term) } {
67
    rlc close
68
  }
69
 
70
  # FIXME_code: should sync here with -run process run-down
71
  #             but no wait available in tcl (grr...)
72
  if { "$runpid" ne ""  } {
73
    after 100;                          # currently just wait 100ms
74
  }
75
  return
76
}
77
 
78 10 wfjm
foreach arg $argv {
79
  if { $optsendseen } {
80
    lappend clist $arg
81
    continue
82
  }
83
  switch -regexp -- $arg {
84
    ^--?fifo=?.*$ { set opts(fifo) 1; regexp -- {=(.*)} $arg dummy opts(fifo_) }
85
    ^--?term=?.*$ { set opts(term) 1; regexp -- {=(.*)} $arg dummy opts(term_) }
86
    ^--?run=.+$   { regexp -- {=(.*)} $arg dummy opts(run_) }
87
    ^--?log=.+$   { regexp -- {=(.*)} $arg dummy opts(log_) }
88
    ^--?logl=.+$  { regexp -- {=(.*)} $arg dummy opts(logl_) }
89
    ^--?dmpl=.+$  { regexp -- {=(.*)} $arg dummy opts(dmpl_) }
90
    ^--?tiol=.+$  { regexp -- {=(.*)} $arg dummy opts(tiol_) }
91
    ^--?int$      { set opts(int) 1 }
92
    ^--?help$     { set opts(help) 1 }
93
    ^--$          { set optsendseen 1 }
94
    ^--.+$        { puts "-E: bad option $arg, see --help for proper usage"
95
                    return 1
96
                  }
97
    default       { lappend clist $arg }
98
  }
99
}
100
 
101
if { $opts(help) } {
102 12 wfjm
  # use {} as defimiter here to avoid that escaping of all []
103
  puts {usage: ti_rri [OPTION]... [COMMAND]...}
104
  puts {}
105
  puts {Options:}
106
  puts {  --run=CMD      exec's CMD as subprocess before the rlink port opened}
107
  puts {                 useful to start test benches, usually via 'tbw'}
108
  puts {  --fifo[=ARGS]  open fifo type rlink port. Optional arguments are:}
109
  puts {                   --fifo=[NAME[,KEEP]]}
110
  puts {                     NAME  fifo name prefix, default 'rlink_cext_fifo'}
111
  puts {                     KEEP  if non-empty the fifo is kept open on exit}
112
  puts {  --term[=ARGS]  open term type rlink port. Optional arguments are:}
113 15 wfjm
  puts {                   --term=[NAME[,BAUD[,BREAK[,FLOW]]]]}
114 12 wfjm
  puts {                     NAME  tty device name, default 'USB0'}
115
  puts {                           if not starting with '/' the name is}
116
  puts {                           prefixed with '/dev/tty'}
117
  puts {                     BAUD  serial port baud rate, default '115k'}
118
  puts {                           allowed baud rate settings are:}
119
  puts {                             9600, 19200, 19k, 38400, 38k, 57600, 57k}
120
  puts {                             115200, 115k, 230400, 230k, 460800, 460k}
121
  puts {                             500000, 500k, 921600, 921k, 1000000, 1M}
122
  puts {                             2000000, 2M, 3000000, 3M}
123 15 wfjm
  puts {                     BREAK controls whether a break will be send:}
124
  puts {                             0 no break (default)}
125
  puts {                             1 send break, do autobaud}
126
  puts {                     FLOW  controls flow control regime:}
127
  puts {                             0 no flow control (default)}
128
  puts {                             1 cts/rts hardware flow control}
129 12 wfjm
  puts {  --log=FILE     set log file name. Default is to write to stdout.}
130
  puts {  --logl=LVL     set log level, default is '2' allowed values:}
131
  puts {                   0 no logging}
132
  puts {                   1 log rlink commands with communication errors}
133
  puts {                   2 log rlink commands with failed checks}
134
  puts {                   3 log all rlink commands}
135
  puts {  --dmpl=LVL     set dump level, default is '0', values like logl}
136
  puts {  --tiol=LVL     set i/o trace level, default is '0', allowed values:}
137
  puts {                   0 no i/o trace}
138
  puts {                   1 trace buffer activities}
139
  puts {                   2 trace character activities}
140
  puts {  --int          enter interactive mode even when commands given}
141
  puts {  --help         display this help and exit}
142
  puts {  --             all following arguments are treated as tcl commands}
143
  puts {}
144
  puts {Command handling:}
145
  puts {  For arguments of the form '@.tcl' the respective file is}
146
  puts {  sourced. All other arguments are treated as Tcl commands and executed}
147
  puts {  with eval.}
148
  puts {}
149
  puts {For further details consults the ti_rri man page.}
150 10 wfjm
  return 0
151
}
152
 
153 12 wfjm
if {![info exists env(RETROBASE)]} {
154
  puts "-E: RETROBASE environment variable not defined"
155
  return 1
156
}
157
 
158 10 wfjm
if { $opts(fifo) && $opts(term) } {
159
  puts "-E: both --fifo and --term given, only one allowed"
160
  return 1
161
}
162
 
163
lappend auto_path [file join $env(RETROBASE) tools tcl]
164
lappend auto_path [file join $env(RETROBASE) tools lib]
165
 
166
package require rlink
167
package require rutiltpp
168
package require rlinktpp
169
 
170
rlinkconnect rlc
171
 
172
# setup logging
173
if { $opts(log_) ne "-" } {
174
  rlc config -logfile       $opts(log_)
175
}
176
rlc config -logprintlevel $opts(logl_)
177
rlc config -logdumplevel  $opts(dmpl_)
178
rlc config -logtracelevel $opts(tiol_)
179
 
180 12 wfjm
# first start, if specified with --run, the test bench
181 10 wfjm
if { $opts(run_) ne "" } {
182
  if { [catch {eval "exec $opts(run_) &" } runpid] } {
183
    puts "-E: failed to execute \"$opts(run_)\" with error message\n  $runpid"
184
    puts "aborting..."
185
    return 1
186
  }
187
}
188
 
189
# than open the rlink connection
190
# handle --fifo
191
if { $opts(fifo) } {
192
  set nlist [split $opts(fifo_) ","]
193
  set path [lindex $nlist 0]
194
  set keep [lindex $nlist 1]
195
  if {$path eq ""} {set path "rlink_cext_fifo"}
196
  set url "fifo:$path"
197
  if {$keep ne ""} {append url "?keep"}
198
  rlc open $url
199
}
200
 
201
# handle --term
202
if { $opts(term) } {
203
  set nlist [split $opts(term_) ","]
204
  set dev  [lindex $nlist 0]
205
  set baud [lindex $nlist 1]
206
  set brk  [lindex $nlist 2]
207 15 wfjm
  set flow [lindex $nlist 3]
208 11 wfjm
  if {$dev  eq ""} {set dev  "USB0"}
209 10 wfjm
  if {$baud eq ""} {set baud "115k"}
210 15 wfjm
  if {$brk  eq ""} {set brk  0}
211
  if {$flow eq ""} {set flow 0}
212 12 wfjm
  if {! [regexp -- {^/} $dev]} {
213 11 wfjm
    set dev "/dev/tty$dev"
214
  }
215 10 wfjm
  set url "term:$dev?baud=$baud"
216 15 wfjm
  if {$brk  eq 1} {append url ";break"}
217
  if {$flow eq 1} {append url ";cts"}
218
  # puts "-I: $url"
219 10 wfjm
  rlc open $url
220
}
221
 
222
# setup simulation mode default
223
set rlink::sim_mode [rlink::isfifo]
224
 
225
foreach cmd $clist {
226
  # handle @filename commands
227
  if { [regexp {^@(.+)} $cmd dummy filename] } {
228
    # handle @file.tcl --> source tcl file
229
    if { [regexp {\.tcl$} $filename] } {
230
      if { [catch {source $filename} errmsg] } {
231
        puts "-E: failed to source file \"$filename\" with error message:"
232
        if {[info exists errorInfo]} {puts $errorInfo} else {puts $errmsg}
233
        puts "aborting..."
234
        break
235
      }
236
    # handle @file.dat ect --> not yet supported
237
    } else {
238
      puts "-E: only tcl supported but $filename found"
239
      puts "aborting..."
240
      break
241
    }
242
 
243
  # handle normal tcl commands --> eval them
244
  } else {
245
    if { [catch {eval $cmd} errmsg] } {
246
      puts "-E: eval of \"$cmd\" failed with error message:"
247
      if {[info exists errorInfo]} {puts $errorInfo} else {puts $errmsg}
248
      puts "aborting..."
249
      break
250
    }
251
  }
252
}
253
 
254
# if tclsh runs a script given on the command line or is invoked
255
# like here via a shebang the tcl_interactive is always set to 0
256
# so we have to check whether stdin/stdout is a terminal and set
257
# tcl_interactive accordingly
258
 
259
# FIXME_code: fstat not available (grr...), currently just assume istty
260
set tcl_interactive 1
261
 
262
if { $opts(int) || [llength $clist] == 0 } {
263
  if {$tcl_interactive} {
264
    package require tclreadline
265
    namespace eval tclreadline {
266
      proc prompt1 {} {
267
        set version [info tclversion]
268
        return "ti_rri > "
269
      }
270
    }
271 12 wfjm
    ::tclreadline::readline eofchar {::exit_cleanup; puts {}; exit}
272 10 wfjm
    ::tclreadline::Loop
273
  }
274 12 wfjm
} else {
275
  exit_cleanup
276 10 wfjm
}
277
 
278
return 0

powered by: WebSVN 2.1.0

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