esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% LeCroy1151.mac
#%NAME% LeCroy1151.mac
#
#%CATEGORY% Detection, Counting
#
#%LOG%
# $Revision: 1.5 $
#
#%DESCRIPTION%
# Use this macro set to control a LeCroy 1151 counter card by the use of
# macro counters.
# %BR%
# For the internals:
# %BR%
# %BR%
# the channels are cleared before starting the counter; signal "prestart_all".
# %BR%
# all channels are read only once at the signal "halt_all".
# %BR%
# then each channel receives its value, signal "counts".
#%SETUP%
# The macro set needs the vmeds.mac file.
# %BR%
# %BR%
# In the config editor:
# %BR%    
# create a scaler controller like follows:
# %BR%
# YES          L1151  IDXX/L1151/0      16                     Macro Counter
# %BR% 
# then create up to 16 counters:
# %BR%
# 12      L1151_1    L1151_1   MAC_CNT     0     0(to15)    counter         1
#%END%
# Information about the card addresses and their contents have been taken from
# the OS9 device server sources and with friendly help of F. Epaud.
# /segfs/os9/drv/cnttim/l1151 and /segfs/dserver/classes/das/cnttim
#
# Modifications history:
# 20/03/2007 Creation 

need vmeds

def L1151_config(mne,type,unit,mod,chan) '{
  local manufacturer, nm
  global L1151[]

  if (mne != "..") {
    if (DEBUG & 128) print "Configuring " cnt_name(mne) " as a LeCroy 1151 channel on " L1151_ADDR
    
  } else {
#    L1151[0]=0 #make sure the array is there
    # Try to read the manufacturer code, offset 0xfc, short
    if (manufacturer = (vmeds_get(L1151_ADDR, 0xfc, "D16")) != 1031) {
      eprint "Card with server name", L1151_ADDR, "does not seem to be a"
      eprint "LeCroy 1151! Macro counter disabled!", manufacturer
      return ".error."
    }
    # stlist doesnt accept numbers as members
    # so     list_add(L1151, unit), when unit is 1 or 2 wont work!
#    list_add(L1151, unit)
#    list_setpar (L1151, unit, "addr", L1151_ADDR)
    L1151[unit]["addr"] = L1151_ADDR
    # note, no other members than addr are allowed.
  }
}'

def L1151_cmd(mne, cmd, p1, p2, unit) '{
  local dsname, dings, ldata, n

  if (mne == "..") { # here we can use "unit" from spec 5.07.03-3 on
    if (cmd == "prestart_all") {
      dsname = L1151[unit]["addr"]
      if(dsname == "") {
        eprint "LeCroy 1151: device server name undefined."
        return(0)
      }
      # Clear all
      vmeds_put(dsname, 0, 1, "D16")
      # possibly try to reset by reading
      # vmeds_get(L1151_ADDR, 0, "D16")
      # or each channel by reading 
      # vmeds_get(L1151_ADDR, 0x40 + channel * 4, "D32")
    } else if (cmd == "halt_all") {
      # for halt_all the unit is the third arg, no p1 or p2
      dsname = L1151[p1]["addr"]
      if(dsname == "") {
        eprint "LeCroy 1151: device server name undefined."
        return(0)
      }
      ldata = "L1151_" p1 "_DATA"
      global ulong array @ldata[0x40]
      # read hardware only once per card
      vmeds_move(dsname, 0x40,  @ldata, 0x10,"D32")
    }
  } else if (cmd == "counts") {
    unit = counter_par(mne,"unit")
    ldata = "L1151_" unit "_DATA"
    if((chan = counter_par(mne,"channel")) > 0x10) {
      eprint "LeCroy 1151! not enough channels for channel", chan, "!"
      return ".error."
    }
    return(@ldata[chan])
  }
}'

#%DEPENDENCIES%
# vmeds.mac must already be read in.
#%AUTHOR% BLISS - ESRF, H. Witsch
#$Revision: 1.5 $, $Date: 2008/07/17 15:13:08 $
#%TOC%