# $Id: util.tcl 516 2013-05-05 21:24:52Z mueller $
|
# $Id: util.tcl 516 2013-05-05 21:24:52Z mueller $
|
#
|
#
|
# Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
# Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
#
|
#
|
# This program is free software; you may redistribute and/or modify it under
|
# This program is free software; you may redistribute and/or modify it under
|
# the terms of the GNU General Public License as published by the Free
|
# the terms of the GNU General Public License as published by the Free
|
# Software Foundation, either version 2, or at your option any later version.
|
# Software Foundation, either version 2, or at your option any later version.
|
#
|
#
|
# This program is distributed in the hope that it will be useful, but
|
# This program is distributed in the hope that it will be useful, but
|
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
# for complete details.
|
# for complete details.
|
#
|
#
|
# Revision History:
|
# Revision History:
|
# Date Rev Version Comment
|
# Date Rev Version Comment
|
# 2011-04-17 376 1.0.1 add proc read
|
# 2011-04-17 376 1.0.1 add proc read
|
# 2011-04-02 375 1.0 Initial version
|
# 2011-04-02 375 1.0 Initial version
|
#
|
#
|
|
|
package provide rbemon 1.0
|
package provide rbemon 1.0
|
|
|
package require rutil
|
package require rutil
|
package require rlink
|
package require rlink
|
|
|
namespace eval rbemon {
|
namespace eval rbemon {
|
#
|
#
|
# setup register descriptions for rbd_eyemon
|
# setup register descriptions for rbd_eyemon
|
#
|
#
|
regdsc CNTL {ena01 3} {ena10 2} {clr 1} {go 0}
|
regdsc CNTL {ena01 3} {ena10 2} {clr 1} {go 0}
|
regdsc RDIV {rdiv 7 8}
|
regdsc RDIV {rdiv 7 8}
|
regdsc ADDR {addr 9 10 "-"} {laddr 9 8} {waddr 0}
|
regdsc ADDR {addr 9 10 "-"} {laddr 9 8} {waddr 0}
|
#
|
#
|
# setup: amap definitions for rbd_eyemon
|
# setup: amap definitions for rbd_eyemon
|
#
|
#
|
proc setup {base} {
|
proc setup {base} {
|
rlc amap -insert em.cntl [expr {$base + 0x00}]
|
rlc amap -insert em.cntl [expr {$base + 0x00}]
|
rlc amap -insert em.rdiv [expr {$base + 0x01}]
|
rlc amap -insert em.rdiv [expr {$base + 0x01}]
|
rlc amap -insert em.addr [expr {$base + 0x02}]
|
rlc amap -insert em.addr [expr {$base + 0x02}]
|
rlc amap -insert em.data [expr {$base + 0x03}]
|
rlc amap -insert em.data [expr {$base + 0x03}]
|
}
|
}
|
#
|
#
|
# init: reset rbd_eyemon (stop monitor, clear rdiv and addr)
|
# init: reset rbd_eyemon (stop monitor, clear rdiv and addr)
|
#
|
#
|
proc init {} {
|
proc init {} {
|
rlc exec \
|
rlc exec \
|
-wreg em.cntl 0x0000 \
|
-wreg em.cntl 0x0000 \
|
-wreg em.rdiv 0x0000
|
-wreg em.rdiv 0x0000
|
}
|
}
|
#
|
#
|
# clear: clear eyemon data
|
# clear: clear eyemon data
|
#
|
#
|
proc clear {} {
|
proc clear {} {
|
set clrbit [regbld rbemon::CNTL clr]
|
set clrbit [regbld rbemon::CNTL clr]
|
rlc exec -rreg em.cntl cur_cntl
|
rlc exec -rreg em.cntl cur_cntl
|
rlc exec -wreg em.cntl [expr {$cur_cntl | $clrbit}]
|
rlc exec -wreg em.cntl [expr {$cur_cntl | $clrbit}]
|
set clrrun $clrbit
|
set clrrun $clrbit
|
set npoll 0
|
set npoll 0
|
while {$clrrun != 0} {
|
while {$clrrun != 0} {
|
rlc exec -rreg em.cntl cur_cntl
|
rlc exec -rreg em.cntl cur_cntl
|
set clrrun [expr {$cur_cntl & $clrbit}]
|
set clrrun [expr {$cur_cntl & $clrbit}]
|
incr npoll 1
|
incr npoll 1
|
if {$npoll > 10} {
|
if {$npoll > 10} {
|
error "-E: rbemon::clear failed, CNTL.clr didn't go back to 0"
|
error "-E: rbemon::clear failed, CNTL.clr didn't go back to 0"
|
}
|
}
|
}
|
}
|
return ""
|
return ""
|
}
|
}
|
#
|
#
|
# start: start the eyemon
|
# start: start the eyemon
|
#
|
#
|
proc start {{ena01 0} {ena10 0}} {
|
proc start {{ena01 0} {ena10 0}} {
|
if {$ena01 == 0 && $ena10 == 0} {
|
if {$ena01 == 0 && $ena10 == 0} {
|
set ena01 1
|
set ena01 1
|
set ena10 1
|
set ena10 1
|
}
|
}
|
rlc exec -wreg em.cntl [regbld rbemon::CNTL go \
|
rlc exec -wreg em.cntl [regbld rbemon::CNTL go \
|
[list ena01 $ena01] [list ena10 $ena10] ]
|
[list ena01 $ena01] [list ena10 $ena10] ]
|
}
|
}
|
#
|
#
|
# stop: stop the eyemon
|
# stop: stop the eyemon
|
#
|
#
|
proc stop {} {
|
proc stop {} {
|
rlc exec -wreg em.cntl 0x0000
|
rlc exec -wreg em.cntl 0x0000
|
}
|
}
|
#
|
#
|
# read: read eyemon data
|
# read: read eyemon data
|
#
|
#
|
proc read {{nval 512}} {
|
proc read {{nval 512}} {
|
set addr 0
|
set addr 0
|
set rval {}
|
set rval {}
|
while {$nval > 0} {
|
while {$nval > 0} {
|
set nblk [expr {$nval << 1}]
|
set nblk [expr {$nval << 1}]
|
if {$nblk > 256} {set nblk 256}
|
if {$nblk > 256} {set nblk 256}
|
rlc exec \
|
rlc exec \
|
-wreg em.addr $addr \
|
-wreg em.addr $addr \
|
-rblk em.data $nblk rawdat
|
-rblk em.data $nblk rawdat
|
foreach {dl dh} $rawdat {
|
foreach {dl dh} $rawdat {
|
lappend rval [expr {( $dh << 16 ) | $dl}]
|
lappend rval [expr {( $dh << 16 ) | $dl}]
|
}
|
}
|
incr addr $nblk
|
incr addr $nblk
|
set nval [expr {$nval - ( $nblk >> 1 ) }]
|
set nval [expr {$nval - ( $nblk >> 1 ) }]
|
}
|
}
|
return $rval
|
return $rval
|
}
|
}
|
|
|
}
|
}
|
|
|