00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2004 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 00011 __facility__ = "Online" 00012 __abstract__ = "GLAST LCB functional block" 00013 __author__ = "R. Claus <claus@slac.stanford.edu> SLAC - GLAST LAT I&T/Online" 00014 __date__ = ("$Date: 2005/05/27 01:37:40 $").split(' ')[1] 00015 __version__ = "$Revision: 2.12 $" 00016 __release__ = "$Name: R04-12-00 $" 00017 __credits__ = "SLAC" 00018 00019 import LATTE.copyright_SLAC 00020 00021 import gDb 00022 import gAttr 00023 00024 import logging 00025 00026 class GLCB(gDb.Gdb): 00027 """\brief LCB node. 00028 00029 Has GLCB specific registers and dataless commands. 00030 00031 Valid Registers: 00032 - \c parity_latp_cell_header 00033 - \c parity_latp_cell_body 00034 - \c back_pressure_once 00035 - \c back_pressure 00036 - \c board_id 00037 00038 """ 00039 Online = 0 00040 Offline = 1 00041 Uninitialized = 2 00042 00043 State = {Online: "online", 00044 Offline: "offline", 00045 Uninitialized: "uninitialized"} 00046 00047 __attrs = [ 00048 # Registers 00049 gAttr.GattrBF('parity_latp_cell_header', 0, 4, 5), 00050 gAttr.GattrBF('parity_latp_cell_body', 0, 5, 6), 00051 gAttr.GattrBF('back_pressure_once', 0, 6, 7), 00052 gAttr.GattrBF('back_pressure', 0, 7, 8), 00053 gAttr.GattrBF('board_id', 0, 8, 13) 00054 ] 00055 00056 __tmo = 100 00057 00058 def __init__(self, client): 00059 """\brief Initialize valid registers as Gattrs. 00060 """ 00061 flags = {'BoardId' : 0x22, 00062 'UseRedundant' : 0, 00063 'UseBitWide' : 0, 00064 'UseTrailingIclock' : 0, 00065 'UseTrailingOclock' : 0, 00066 'IgnoreMissingNodes': 1} 00067 self.stats = GLCBSTATS(client, self) 00068 gDb.Gdb.__init__(self, client, None, 0, self.__attrs, None, flags) 00069 00070 def read(self, reg): 00071 return self.cmdrsp('LCBC_csr_access', 'lcb', 0, 0, self.__tmo, '!I', '!I') 00072 00073 def load(self, reg, value): 00074 return self.cmdrsp('LCBC_csr_access', 'lcb', value, 0xffff, self.__tmo, 0, 0) 00075 00076 def setEvtEnable(self, enable): 00077 """\brief Sets the LCB event enable bit to true or false. 00078 00079 \param enable boolean. 00080 """ 00081 return self.cmdrsp('LCBD_evt_enable', 'lcb', enable) 00082 00083 def start(self, lcbmask): 00084 rsp = self.cmdrsp('load_lcb', lcbmask) 00085 return rsp.status() 00086 00087 def start_wait(self, lcbmask, timeout): 00088 tmo = self.client().gettimeout() 00089 if timeout is not None: 00090 self.client().settimeout(timeout) 00091 rsp = self.cmdrsp('load_wait_lcb', lcbmask) 00092 self.client().settimeout(tmo) 00093 return rsp.status() 00094 00095 def switch(self, lcbmask): 00096 rsp = self.cmdrsp('switch_lcb', lcbmask) 00097 return rsp.status() 00098 00099 def switch_wait(self, timeout): 00100 tmo = self.client().gettimeout() 00101 if timeout is not None: 00102 self.client().settimeout(timeout) 00103 rsp = self.cmdrsp('switch_wait_lcb') 00104 self.client().settimeout(tmo) 00105 return rsp.status() 00106 00107 def state(self): 00108 rsp = self.cmdrsp('LCBD_state_get', 'lcb') 00109 return rsp.status() 00110 00111 00112 class GLCBSTATS(gDb.Gdb): 00113 """\brief LCB stats access 00114 00115 Has stats-specific registers 00116 00117 Valid Registers: 00118 - \c packets_received Number of event packets received 00119 - \c body_parity_error Latched data cell parity error 00120 - \c header_parity_error Latched data header parity error 00121 - \c latp_address_error Improperly addressed packet rejected 00122 """ 00123 00124 # Registers 00125 __attrs = [ 00126 gAttr.GattrBF('packets_received' , 0, 0, 14, gAttr.ATTR_READ_ONLY), 00127 gAttr.GattrBF('body_parity_error', 0, 14, 15, gAttr.ATTR_READ_ONLY), 00128 gAttr.GattrBF('header_parity_error', 0, 15, 16, gAttr.ATTR_READ_ONLY), 00129 gAttr.GattrBF('latp_address_error', 0, 16, 17, gAttr.ATTR_READ_ONLY) 00130 ] 00131 00132 __tmo = 100 00133 00134 def __init__(self, client, parent): 00135 """\brief Initialize valid registers as Gattrs. 00136 """ 00137 gDb.Gdb.__init__(self, client, parent, 0, self.__attrs) 00138 00139 def read(self, reg): 00140 return self.cmdrsp('LCBC_rxstats_access', 'lcb', 0, 0, self.__tmo, '!I', '!I') 00141 00142 def reset(self): 00143 return self.cmdrsp('LCBC_rxstats_access', 'lcb', 0, 0xFFFF, self.__tmo, 0, 0) 00144