Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

FEpowerUp.py

00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2002
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 __facility__ = "Online"
00011 __abstract__ = "Front End power up / power down routines"
00012 __author__   = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__     = ("$Date: 2005/02/11 03:58:33 $").split(' ')[1]
00014 __version__  = "$Revision: 2.16 $"
00015 __credits__  = "SLAC"
00016 
00017 import LATTE.copyright_SLAC
00018 
00019 from time import sleep
00020 import           sys
00021 import           logging as log
00022 
00023 from LATTE.client.gException import LATInterfaceException
00024 
00025 class FEpowerUp(object):
00026   def __init__(self, acdPowerUp=None, temPowerUp=None):
00027     self.acdPowerUp = acdPowerUp
00028     self.temPowerUp = temPowerUp
00029     self.__nominal  = 0x800
00030 
00031   def initialize(self, lat, xbrd):
00032     self.lat        = lat
00033     self.xbrd       = xbrd
00034 
00035   def setAcdPowerUp(self, acdPowerUp):
00036     self.acdPowerUp = acdPowerUp
00037 
00038   def setTemPowerUp(self, temPowerUp):
00039     self.temPowerUp = temPowerUp
00040 
00041   def up(self):
00042     # Power up TEM(s)
00043     activeTEMs = self.getActiveTEMs(self.lat)
00044     #for (temId, tem) in activeTEMs.items():
00045     #  if self.temPowerUp is None or temId in self.temPowerUp:
00046     #    # turn off front ends
00047     #    tic = tem.TIC
00048     #    if self.temPowerUp is None:
00049     #      tic.POWER_SUPPLY = 0x0
00050     #    else:
00051     #      powerSupply = tic.POWER_SUPPLY
00052     #      if powerSupply & self.temPowerUp[temId] != 0:
00053     #        powerSupply &= ~self.temPowerUp[temId]
00054     #        tic.POWER_SUPPLY = powerSupply
00055 
00056     xbrd = self.xbrd
00057     if xbrd is not None:
00058       # set all margin DACs to "middle" values
00059       # ggDACload() take the following values:
00060       #   0x000 - maximum voltage
00061       #   0x800 - nominal
00062       #   0xFFF - minimum voltage
00063 
00064       # Adjust TKR Analog 2.5v
00065       margin = 0x800
00066       if margin != self.__nominal:
00067         log.warn("dac_tkr_analog_2_5 is being set to 0x%03x" % margin)
00068       xbrd.dac_tkr_analog_2_5 = margin
00069 
00070       # Adjust TKR Digital 2.5v
00071       margin = 0x800
00072       if margin != self.__nominal:
00073         log.warn("dac_tkr_digital_2_5 is being set to 0x%03x" % margin)
00074       xbrd.dac_tkr_digital_2_5 = margin
00075 
00076       # Adjust TKR Analog 1.5v _and_ CAL Analog 3.3v
00077       margin = 0x800
00078       if margin != self.__nominal:
00079         log.warn("dac_tkr_cal_analog is being set to 0x%03x" % margin)
00080       xbrd.dac_tkr_cal_analog = margin
00081 
00082       # Adjust CAL Digital 3.3v
00083       margin = 0x800
00084       if margin != self.__nominal:
00085         log.warn("dac_cal_digital_3_3 is being set to 0x%03x" % margin)
00086       xbrd.dac_cal_digital_3_3 = margin
00087 
00088       # Adjust TEM Digital 3.3v
00089       margin = 0x800
00090       if margin != self.__nominal:
00091         log.warn("dac_tem_voltage is being set to 0x%03x" % margin)
00092       xbrd.dac_tem_voltage = margin
00093 
00094       ##
00095       ##  HIGH VOLTAGES for TKR and CAL
00096       ##  Disable by default
00097       ##
00098       ##  Note:  These take different values then ggDACload()
00099       ##
00100       ##    0x4000 - 0 V
00101       ##    0x5000 - plus half scale
00102       ##    0x5FFE - plus full scale
00103       ##
00104 
00105       # Adjust TKR High Voltage
00106       #tic.tkr_biasdac = 0x4000
00107 
00108       # Adjust CAL High Voltage
00109       #tic.cal_biasdac = 0x5000
00110 
00111     for (temId, tem) in activeTEMs.items():
00112       # turn on TKR and/or CAL front ends
00113       if self.temPowerUp is None or temId in self.temPowerUp:
00114         tic = tem.TIC
00115         if self.temPowerUp is None:
00116           tic.POWER_SUPPLY = 0x3
00117         else:
00118           powerSupply = tic.POWER_SUPPLY
00119           if powerSupply | self.temPowerUp[temId] != powerSupply:
00120             tkrPowerUp = 0
00121             if self.temPowerUp[temId] & 1 == 1 and powerSupply & 1 == 0:
00122               # TKR power up requested
00123               tkrPowerUp = 1
00124               if tem.allTCC() is None:
00125                 msg = "Broadcast TCC needs to be defined in the schema for TKR power up"
00126                 log.error(msg)
00127                 raise RuntimeError, msg
00128             tic.POWER_SUPPLY = powerSupply | self.temPowerUp[temId]
00129             # We don't want to reset the TEM since it causes events
00130             # to be triggered
00131             #tem.CMD_RESET = 1
00132             if tkrPowerUp:
00133               sleep(1.0)
00134               tem.allTCC().CMD_RESET = 1
00135 
00136     # Power up AEM
00137     aem = self.lat.AEM
00138     if not self.isAEMactive(aem):
00139       aem = None
00140     else:
00141       for (arcId, arc) in aem.ARC.items():
00142         if self.acdPowerUp is None or arcId in self.acdPowerUp:
00143           aem.power_down = arcId
00144           aem.power_up = arcId
00145           sleep(1.5)  # Gotta wait 1.5 seconds before *any* read can work.
00146           arc.look_at_me = 0xeb90
00147     return self.checkPower(aem, activeTEMs)
00148 
00149   def down(self):
00150     # Power down TEM
00151     activeTEMs = self.getActiveTEMs(self.lat)
00152     for (temId, tem) in activeTEMs.items():
00153       if self.temPowerUp is None or temId in self.temPowerUp:
00154         # turn off CAL and/or TKR front ends
00155         tic = tem.TIC
00156         if self.temPowerUp is None:
00157           tic.POWER_SUPPLY = 0x0
00158         else:
00159           powerSupply = tic.POWER_SUPPLY
00160           if powerSupply & ~self.temPowerUp[temId] != powerSupply:
00161             tic.POWER_SUPPLY = powerSupply & ~self.temPowerUp[temId]
00162 
00163     xbrd = self.xbrd
00164 
00165     if xbrd is not None:
00166       # set all margin DACs to "middle" values (as per Leonid's request)
00167 
00168       # Adjust TKR Analog 2.5v
00169       xbrd.dac_tkr_analog_2_5 = self.__nominal
00170 
00171       # Adjust TKR Digital 2.5v
00172       xbrd.dac_tkr_digital_2_5 = self.__nominal
00173 
00174       # Adjust TKR Analog 1.5v _and_ CAL Analog 3.3v
00175       xbrd.dac_tkr_cal_analog = self.__nominal
00176 
00177       # Adjust CAL Digital 3.3v
00178       xbrd.dac_cal_digital_3_3 = self.__nominal
00179 
00180       # Adjust TEM Digital 3.3v
00181       xbrd.dac_tem_voltage = self.__nominal
00182 
00183     # Power down AEM
00184     aem = self.lat.AEM
00185     if not self.isAEMactive(aem):
00186       aem = None
00187     else:
00188       for arcId in aem.ARC:
00189         if self.acdPowerUp is None or arcId in self.acdPowerUp:
00190           try:
00191             arc = aem.ARC[arcId]
00192             for mode in (0xF8F, 0xFF1): # Enable HVBS 1 and then HVBS 2
00193               arc.mode &= mode
00194               hvbs = arc.hvbs
00195               while hvbs > 0:
00196                 hvbs -= 200 # Ramp-down in 200 DAC step decrements
00197                 if hvbs >= 0:
00198                   arc.hvbs = hvbs
00199                 else:
00200                   arc.hvbs = 0
00201                 arc.cmd_set_hvbs = 1
00202                 sleep(1)
00203           except LATInterfaceException:
00204             if sys.exc_info()[1].errstr()[0] in ('LCB_RTOERR', 'LCBD_RTOERR') \
00205                 and self.lat.getDeclarations()['options']['ignorehardwaretimeouts']:
00206               pass
00207             else:
00208               raise LATInterfaceException(sys.exc_info()[1].status)
00209           aem.power_down = arcId
00210     return self.checkPower(aem, activeTEMs)
00211 
00212   def getActiveTEMs(self, lat):
00213     activeTEMs = {}
00214     if lat.TEMcnt() > 0:
00215       for (temId, tem) in lat.TEM.items():
00216         try:
00217           tem.configuration # Check to see if this TEM really exists
00218           activeTEMs[temId] = tem
00219         except LATInterfaceException:
00220           if sys.exc_info()[1].errstr()[0] in ('LCB_RTOERR', 'LCBD_RTOERR') \
00221               and lat.getDeclarations()['options']['ignorehardwaretimeouts']:
00222             continue
00223           else:
00224             raise LATInterfaceException(sys.exc_info()[1].status)
00225     return activeTEMs
00226 
00227   def isAEMactive(self, aem):
00228     if aem is None:
00229       return False
00230     else:
00231       try:
00232         aem.configuration # Check to see if the AEM really exists
00233       except LATInterfaceException:
00234         if sys.exc_info()[1].errstr()[0] in ('LCB_RTOERR', 'LCBD_RTOERR') \
00235             and aem.up().getDeclarations()['options']['ignorehardwaretimeouts']:
00236           return False
00237         else:
00238           raise LATInterfaceException(sys.exc_info()[1].status)
00239     return True
00240 
00241   def refreshPowerStatus(self):
00242     activeTEMs = self.getActiveTEMs(self.lat)
00243     aem = self.lat.AEM
00244     if not self.isAEMactive(aem):
00245       aem = None
00246     return self.checkPower(aem, activeTEMs)
00247 
00248   def checkPower(self, aem, activeTEMs):
00249     aemPowerCheck = []
00250     calPowerCheck = []
00251     tkrPowerCheck = []
00252 
00253     # Prepare feedback as to which CAL & TKR front ends were really turned on
00254     for (temId, tem) in activeTEMs.items():
00255       tic = tem.TIC
00256       powerSupply = tic.POWER_SUPPLY
00257       if powerSupply & 1:
00258         tkrPowerCheck.append(temId)
00259       if powerSupply & 2:
00260         calPowerCheck.append(temId)
00261 
00262     if aem is not None:
00263       # Prepare feedback as to which free-boards were really turned on
00264       powerStatus = aem.power_status
00265       for i in range(12):
00266         if powerStatus & (1 << i):
00267           aemPowerCheck.append(i)
00268     return (aemPowerCheck, calPowerCheck, tkrPowerCheck)

Generated on Fri Jul 21 13:26:27 2006 for LATTE R04-12-00 by doxygen 1.4.3