From fbca75a6ec02c32b391c09a83dfe6aea751b586c Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 13 Dec 2005 22:43:50 +0000 Subject: [PATCH] crashread seems to work host-only, needs for-real testing --- detpic/crashread | 61 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/detpic/crashread b/detpic/crashread index 445168b..70b97d8 100755 --- a/detpic/crashread +++ b/detpic/crashread @@ -127,30 +127,63 @@ fconfigure $p -blocking yes -buffering none \ set ms [expr { $slave < 0 ? "t" : - $slave ? "m" : - "s" + $slave ? "s" : + "m" }] proc xmit {b} { global p - p $p [format %c $b] +#puts stderr >xmit|$b< + set b [expr $b] + set c [binary format c* $b] + puts -nonewline $p [format %c $b] +} +proc recv {n} { + global p + set l {} + while {$n > 0} { + set c [read $p 1] + binary scan $c c* d + if {![llength $d]} { error "comms eof" } + lappend l $d + incr n -1 + } + return $l +} + +proc selectslave_s {} { + global slave + xmit "$slave ^ 0x30" } proc xmit_s {b} { - xmit [expr {$b | 0x80}] - xmit [expr {$slave ^ 0x30}] + xmit "$b | 0x80" + selectslave_s + recv 1 } proc setup_m {} { xmit 0 } proc setup_s {} { xmit 0; xmit_s 0 } proc setup_t {} { } -proc selectaddr_m {a} { error } -proc selectaddr_s {a} { error } +proc selectaddr_ms {xmit a} { + $xmit "($a >> 6) | 0x40" + $xmit "($a & 0x3c) | 0x40" +} +proc selectaddr_m {a} { selectaddr_ms xmit $a } +proc selectaddr_s {a} { selectaddr_ms xmit_s $a } proc selectaddr_t {a} { global tsa; set tsa $a } -proc readbytes_m {n} { error } -proc readbytes_s {n} { error } +proc readbytes_m {n} { + xmit "$n | 0x10" + return [recv $n] +} +proc readbytes_s {n} { + xmit $n + selectslave_s + return [recv $n] +} + proc readbytes_t {n} { global tsa set l {} @@ -170,9 +203,10 @@ proc readbytes {addr n} { if {$addr & ~0x0fff} { error "bad addr $addr" } if {$n > (0x1000 - $addr)} { error "bad len $addr+$n" } selectaddr_$ms $addr - set readcursor [expr {$addr + $n}] } - return [readbytes_$ms $n] + set r [readbytes_$ms $n] + set readcursor [expr {$addr + $n}] + return $r } proc thingbynum {thing nnum} { @@ -211,10 +245,10 @@ set now_max 4 set inline -1 set displine 0 -setup_$ms - proc p {s} { puts -nonewline $s } +setup_$ms + proc endline {} { global inline displine if {$inline} { p "\n"; incr displine } @@ -283,3 +317,4 @@ while {$sectionnum < [llength $sections]} { } set inline 1 } +endline -- 2.30.2