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 ACD functional block hierarchy" 00013 __author__ = "Selim Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST LAT I&T/Online" 00014 __date__ = ("$Date: 2005/12/21 01:07:55 $").split(' ')[1] 00015 __version__ = "$Revision: 2.17 $" 00016 __release__ = "$Name: R04-12-00 $" 00017 __credits__ = "SLAC" 00018 00019 import LATTE.copyright_SLAC 00020 00021 import time 00022 import gDb 00023 import gAttr 00024 import LATTE.client.gRegister as gRegister 00025 import LATTE.client.gException as gException 00026 00027 class GAEM(gDb.Gdb): 00028 """\brief ACD Common Controller. 00029 00030 Has GAEM specific registers and dataless commands. 00031 00032 Valid Registers: 00033 - \c configuration 00034 - \c common_status 00035 - \c freeboard_status 00036 - \c command_response 00037 - \c trgseq 00038 - \c power_status 00039 - \c address 00040 - \c timeout 00041 - \c relocation 00042 - \c response_timeout 00043 - \c power_up 00044 - \c power_down 00045 - \c trigger_statistics 00046 00047 Dataless Commands: 00048 - \c cmd_reset 00049 00050 """ 00051 __attrs = [ 00052 gAttr.GattrReg('configuration', 0, 4), 00053 gAttr.GattrReg('common_status', 1, 4), 00054 gAttr.GattrReg('freeboard_status', 2, 4), 00055 gAttr.GattrReg('command_response', 3, 4), 00056 gAttr.GattrReg('trgseq', 4, 4), 00057 gAttr.GattrReg('power_status', 5, 4), 00058 gAttr.GattrReg('address', 6, 4), 00059 gAttr.GattrReg('timeout', 7, 4), 00060 gAttr.GattrReg('relocation', 8, 4), 00061 gAttr.GattrReg('response_timeout', 9, 4), 00062 gAttr.GattrReg('power_up', 10, 4), 00063 gAttr.GattrReg('power_down', 11, 4), 00064 gAttr.GattrReg('trigger_statistics', 12, 4), 00065 gAttr.GattrDlc('cmd_reset', 1, 0), 00066 ] 00067 00068 def __init__(self, client, parent): 00069 """\brief Initialize valid registers as Gattrs. 00070 00071 Assign default values to members 00072 """ 00073 self.ARC = gDb.Children(self, GARC) 00074 self.AEQ = None 00075 flags = {'CmdrspFabric' : 'On', 00076 'EventFabric' : 'On', 00077 'UsePdu1' : False, 00078 'UseRedundantConv': False} 00079 gDb.Gdb.__init__(self, client, parent, 0, self.__attrs, None, flags) 00080 00081 def read(self, reg): 00082 return self.cmdrsp('AEM_read', gDb.Lem.ADDR_AEM, reg, '!I') 00083 00084 def load(self, reg, value): 00085 return self.cmdrsp('AEM_load', gDb.Lem.ADDR_AEM, reg, value) 00086 00087 def send(self, cmd): 00088 return self.cmdrsp('AEM_cmd', gDb.Lem.ADDR_AEM, cmd) 00089 00090 def downARC(self, arcId): 00091 """\brief Navigate to the GARC indicated by \a childId 00092 00093 \param childId The id of the child GARC 00094 00095 \return A GARC object instance 00096 """ 00097 return self.ARC.down(arcId) 00098 00099 def allARC(self): 00100 """\brief Navigate to the broadcast GARC 00101 00102 \return The broadcast GARC object instance 00103 """ 00104 return self.ARC.all() 00105 00106 def existsARC(self, arcId): 00107 """\brief Check if the GARC instance with the id 00108 \a arcId exists in the schema. 00109 00110 \param arcId ACD readout controller id 00111 00112 \return 1 if it exists, 0 if it doesn't. 00113 """ 00114 return self.ARC.exists(arcId) 00115 00116 def downAEQ(self): 00117 """\brief Navigate to the GAEQ 00118 00119 \return The GAEQ object instance 00120 """ 00121 return self.AEQ 00122 00123 def existsAEQ(self): 00124 """\brief Check if the GAEQ instance exists in the schema. 00125 00126 \return 1 if it exists, 0 if it doesn't. 00127 """ 00128 return self.AEQ != None 00129 00130 ## private: 00131 def __removeARC(self, arcId): 00132 self.ARC.remove(arcId) 00133 00134 def __addARC(self, arcId): 00135 return self.ARC.add(arcId) 00136 00137 def __removeAEQ(self): 00138 self.AEQ = None 00139 00140 def __addAEQ(self): 00141 self.AEQ = GAEQ(self.client(), self) 00142 return self.AEQ 00143 00144 class GAEQ(gDb.Gdb): 00145 """\brief ACD Environmental Monitors. 00146 00147 Has GAEQ specific registers and dataless commands. 00148 00149 Valid Registers: 00150 - \c env_free_1la 00151 - \c env_free_1rb 00152 - \c env_free_2la 00153 - \c env_free_2lb 00154 - \c env_free_2ra 00155 - \c env_free_2rb 00156 - \c env_free_3la 00157 - \c env_free_3rb 00158 - \c env_free_4la 00159 - \c env_free_4lb 00160 - \c env_free_4ra 00161 - \c env_free_4rb 00162 - \c env_daq 00163 00164 Pseudo registers: 00165 - \c env_vdd_xxx 00166 - \c env_temp_xxx 00167 - \c env_hv1_xxx 00168 - \c env_hv2_xxx 00169 - \c env_dac_digital_3_3i 00170 - \c env_dac_temp 00171 - \c env_dac_hv_i 00172 - \c env_dac_v 00173 00174 """ 00175 __attrs = [ 00176 # Registers 00177 gAttr.GattrReg('env_free_1la', 0, 8), 00178 gAttr.GattrReg('env_free_1rb', 1, 8), 00179 gAttr.GattrReg('env_free_2la', 2, 8), 00180 gAttr.GattrReg('env_free_2lb', 3, 8), 00181 gAttr.GattrReg('env_free_2ra', 4, 8), 00182 gAttr.GattrReg('env_free_2rb', 5, 8), 00183 gAttr.GattrReg('env_free_3la', 6, 8), 00184 gAttr.GattrReg('env_free_3rb', 7, 8), 00185 gAttr.GattrReg('env_free_4la', 8, 8), 00186 gAttr.GattrReg('env_free_4lb', 9, 8), 00187 gAttr.GattrReg('env_free_4ra', 10, 8), 00188 gAttr.GattrReg('env_free_4rb', 11, 8), 00189 gAttr.GattrReg('env_daq', 12, 8), 00190 ] 00191 __STALE_TMO = 1.0 # Timeout in seconds before considering adcs value stale 00192 __GAEQ_ENV_VDD_1LA = 20 00193 __ADCS_BASE = 20 00194 00195 i = __ADCS_BASE 00196 for env in ('1la','1rb','2la','2lb','2ra','2rb', 00197 '3la','3rb','4la','4lb','4ra','4rb'): 00198 __attrs.append(gAttr.GattrReg('env_vdd_'+env, i, 2)) 00199 i+=1 00200 __attrs.append(gAttr.GattrReg('env_temp_'+env, i, 2)) 00201 i+=1 00202 __attrs.append(gAttr.GattrReg('env_hv1_'+env, i, 2)) 00203 i+=1 00204 __attrs.append(gAttr.GattrReg('env_hv2_'+env, i, 2)) 00205 i+=1 00206 __attrs.append(gAttr.GattrReg('env_dac_digital_3_3i', 68, 2)) 00207 __attrs.append(gAttr.GattrReg('env_dac_temp', 69, 2)) 00208 __attrs.append(gAttr.GattrReg('env_dac_hv_i', 70, 2)) 00209 __attrs.append(gAttr.GattrReg('env_dac_v', 71, 2)) 00210 00211 def __init__(self, client, parent): 00212 """\brief Initialize valid registers as Gattrs. 00213 00214 Assign default values to members 00215 """ 00216 self.__envs = 13*[(None, 0)] # [gRegister.Register, time.time()] 00217 gDb.Gdb.__init__(self, client, parent, 0, self.__attrs) 00218 00219 def read(self, reg): 00220 if reg < GAEQ.__ADCS_BASE: 00221 rsp = self.cmdrsp('AEM_ENV_read', gDb.Lem.ADDR_AEM, reg, '!I', '!I') 00222 timestamp = rsp.timestamp() 00223 status = rsp.status() 00224 payloads = (rsp.payloads()[1], rsp.payloads()[0]) 00225 return gRegister.Register(timestamp, status, payloads, 'II') 00226 else: 00227 return self.__fetchReg(reg) 00228 00229 def load(self, reg, value): 00230 return self.cmdrsp('AEM_ENV_load', gDb.Lem.ADDR_AEM, reg, value) 00231 00232 def __fetchReg(self, reg): 00233 mux = (reg - GAEQ.__ADCS_BASE) / 4 00234 which = (reg - GAEQ.__ADCS_BASE) % 4 00235 now = time.time() 00236 (rsp, rt) = self.__envs[mux] 00237 if ((rsp is None) or (now - rt) > GAEQ.__STALE_TMO): 00238 rsp = self.cmdrsp('AEM_ENV_acquire', gDb.Lem.ADDR_AEM, mux, '!I', '!I') 00239 notready = (rsp.payloads()[0]>>31) & 1 00240 tmo = ((rsp.payloads()[0]>>28) & 1) | ((rsp.payloads()[0]>>12) & 1) |\ 00241 ((rsp.payloads()[1]>>28) & 1) | ((rsp.payloads()[1]>>12) & 1) 00242 if notready: 00243 status = gException.LATInterfaceStatus.status('OCS_BDADC') 00244 raise gException.LATInterfaceException(status) 00245 if tmo: 00246 status = gException.LATInterfaceStatus.status('OCS_TMOADC') 00247 raise gException.LATInterfaceException(status) 00248 self.__envs[mux] = (rsp, now) 00249 timestamp = rsp.timestamp() 00250 status = rsp.status() 00251 payload = rsp.payloads()[0] << 32 | rsp.payloads()[1] 00252 value = int((payload >> (16 * which)) & 0xfff) 00253 payloads = [value] 00254 return gRegister.Register(timestamp, status, payloads, 'H') 00255 00256 class GARC(gDb.Gdb): 00257 """\brief ACD Readout Controller. 00258 00259 Has GARC specific registers and dataless commands. 00260 00261 Valid Registers: 00262 - function block 0 00263 - \c veto_delay 00264 - \c hvbs 00265 - \c saa 00266 - \c use_hv_normal 00267 - \c use_hv_saa 00268 - \c hold_delay 00269 - \c veto_width 00270 - \c hitmap_width 00271 - \c hitmap_deadtime 00272 - function block 1 00273 - \c look_at_me 00274 - \c hitmap_delay 00275 - \c pha_en_0 00276 - \c veto_en_0 00277 - \c hld_en_0 00278 - \c pha_en_1 00279 - \c veto_en_1 00280 - \c hld_en_1 00281 - \c max_pha 00282 - function block 2 00283 - \c mode 00284 - \c status 00285 - \c last_cmd 00286 - \c diagnostic 00287 - \c cmd_reject 00288 - \c free_id 00289 - \c garc_version 00290 - function block 3 00291 - \c pha_threshold_0 00292 - \c pha_threshold_1 00293 - \c pha_threshold_2 00294 - \c pha_threshold_3 00295 - \c pha_threshold_4 00296 - \c pha_threshold_5 00297 - \c pha_threshold_6 00298 - function block 4 00299 - \c pha_threshold_7 00300 - \c pha_threshold_8 00301 - \c pha_threshold_9 00302 - \c pha_threshold_10 00303 - \c pha_threshold_11 00304 - \c pha_threshold_12 00305 - \c pha_threshold_13 00306 - function block 5 00307 - \c pha_threshold_14 00308 - \c pha_threshold_15 00309 - \c pha_threshold_16 00310 - \c pha_threshold_17 00311 - \c adc_tacq 00312 00313 Dataless Commands 00314 - \c cmd_reset 00315 - \c cmd_calstrobe 00316 - \c cmd_set_hvbs 00317 - \c cmd_set_hvsaa 00318 00319 """ 00320 __attrs = [ 00321 # Registers 00322 # function block 0 00323 gAttr.GattrReg('veto_delay', 2, 2), 00324 gAttr.GattrReg('hvbs', 8, 2), 00325 gAttr.GattrReg('saa', 9, 2), 00326 gAttr.GattrReg('use_hv_normal', 10, 2), 00327 gAttr.GattrReg('use_hv_saa', 11, 2), 00328 gAttr.GattrReg('hold_delay', 12, 2), 00329 gAttr.GattrReg('veto_width', 13, 2), 00330 gAttr.GattrReg('hitmap_width', 14, 2), 00331 gAttr.GattrReg('hitmap_deadtime', 15, 2), 00332 # function block 1 00333 gAttr.GattrReg('look_at_me', 20, 2), 00334 gAttr.GattrReg('hitmap_delay', 24, 2), 00335 gAttr.GattrReg('pha_en_0', 25, 2), 00336 gAttr.GattrReg('veto_en_0', 26, 2), 00337 gAttr.GattrReg('pha_en_1', 28, 2), 00338 gAttr.GattrReg('veto_en_1', 29, 2), 00339 gAttr.GattrReg('max_pha', 31, 2), 00340 # function block 2 00341 gAttr.GattrReg('mode', 40, 2), 00342 gAttr.GattrReg('status', 41, 2), 00343 gAttr.GattrReg('last_cmd', 42, 2), 00344 gAttr.GattrReg('diagnostic', 43, 2), 00345 gAttr.GattrReg('cmd_reject', 44, 2), 00346 gAttr.GattrReg('free_id', 45, 2), 00347 gAttr.GattrReg('garc_version', 46, 2), 00348 # function block 3 00349 gAttr.GattrReg('pha_threshold_0', 56, 2), 00350 gAttr.GattrReg('pha_threshold_1', 57, 2), 00351 gAttr.GattrReg('pha_threshold_2', 58, 2), 00352 gAttr.GattrReg('pha_threshold_3', 59, 2), 00353 gAttr.GattrReg('pha_threshold_4', 60, 2), 00354 gAttr.GattrReg('pha_threshold_5', 61, 2), 00355 gAttr.GattrReg('pha_threshold_6', 62, 2), 00356 # function block 4 00357 gAttr.GattrReg('pha_threshold_7', 72, 2), 00358 gAttr.GattrReg('pha_threshold_8', 73, 2), 00359 gAttr.GattrReg('pha_threshold_9', 74, 2), 00360 gAttr.GattrReg('pha_threshold_10', 75, 2), 00361 gAttr.GattrReg('pha_threshold_11', 76, 2), 00362 gAttr.GattrReg('pha_threshold_12', 77, 2), 00363 gAttr.GattrReg('pha_threshold_13', 78, 2), 00364 # function block 5 00365 gAttr.GattrReg('pha_threshold_14', 88, 2), 00366 gAttr.GattrReg('pha_threshold_15', 89, 2), 00367 gAttr.GattrReg('pha_threshold_16', 90, 2), 00368 gAttr.GattrReg('pha_threshold_17', 91, 2), 00369 gAttr.GattrReg('adc_tacq', 92, 2), 00370 # Dataless Commands 00371 gAttr.GattrDlc('cmd_reset', 1, 0), 00372 gAttr.GattrDlc('cmd_calstrobe', 3, 0), 00373 gAttr.GattrDlc('cmd_set_hvbs', 10, 0), 00374 gAttr.GattrDlc('cmd_set_hvsaa', 11, 0) 00375 ] 00376 00377 def __init__(self, client, parent, id): 00378 """\brief Initialize valid registers as Gattrs. 00379 00380 Assign default values to members 00381 """ 00382 if id < gDb.Lem.NARCS: 00383 addr = id 00384 elif id == gDb.Children.BCASTID: 00385 addr = gDb.Lem.ARCBCAST 00386 else: 00387 raise KeyError("*** gAEM: GARC id %d is invalid" %(id)) 00388 self.AFE = gDb.Children(self, GAFE) 00389 gDb.Gdb.__init__(self, client, parent, id, self.__attrs, addr) 00390 00391 def read(self, reg): 00392 return self.cmdrsp('ARC_read', gDb.Lem.ADDR_AEM, self.addr(), reg, '!I') 00393 00394 def load(self, reg, value): 00395 return self.cmdrsp('ARC_load', gDb.Lem.ADDR_AEM, self.addr(), reg, value) 00396 00397 def send(self, cmd): 00398 return self.cmdrsp('ARC_cmd', gDb.Lem.ADDR_AEM, self.addr(), cmd) 00399 00400 def downAFE(self, afeId): 00401 """\brief Navigate to the GAFE indicated by \a childId 00402 00403 \param childId The id of the child GAFE 00404 00405 \return A GAFE object instance 00406 """ 00407 return self.AFE.down(afeId) 00408 00409 def allAFE(self): 00410 """\brief Navigate to the broadcast GAFE 00411 00412 \return The broadcast GAFE object instance 00413 """ 00414 return self.AFE.all() 00415 00416 def existsAFE(self, afeId): 00417 """\brief Check if the GAFE instance with the id 00418 \a afeId exists in the schema. 00419 00420 \param afeId ACD readout controller id 00421 00422 \return 1 if it exists, 0 if it doesn't. 00423 """ 00424 return self.AFE.exists(afeId) 00425 00426 ## private: 00427 def __removeAFE(self, afeId): 00428 self.AFE.remove(afeId) 00429 00430 def __addAFE(self, afeId): 00431 return self.AFE.add(afeId) 00432 00433 00434 class GAFE(gDb.Gdb): 00435 """\brief ACD Front-End Controller. 00436 00437 Has GAFE specific registers and dataless commands. 00438 00439 Valid Registers: 00440 - \c configuration 00441 - \c veto_dac 00442 - \c hld_dac 00443 - \c veto_vernier 00444 - \c bias_dac 00445 - \c tci_dac 00446 - \c vers_addr 00447 - \c write_ctr 00448 - \c reject_ctr 00449 - \c loop_ctr 00450 - \c chip_addr 00451 00452 """ 00453 __attrs = [ 00454 # Registers 00455 gAttr.GattrReg('configuration', 0, 2), 00456 gAttr.GattrReg('veto_dac', 1, 2), 00457 gAttr.GattrReg('veto_vernier', 2, 2), 00458 gAttr.GattrReg('hld_dac', 3, 2), 00459 gAttr.GattrReg('bias_dac', 4, 2), 00460 gAttr.GattrReg('tci_dac', 5, 2), 00461 gAttr.GattrReg('vers_addr', 6, 2), 00462 gAttr.GattrReg('write_ctr', 7, 2), 00463 gAttr.GattrReg('reject_ctr', 8, 2), 00464 gAttr.GattrReg('loop_ctr', 9, 2), 00465 gAttr.GattrReg('chip_addr', 10, 2) 00466 ] 00467 00468 def __init__(self, client, parent, id): 00469 """\brief Initialize valid registers as Gattrs. 00470 00471 """ 00472 if id < gDb.Lem.NAFES: 00473 addr = id 00474 elif id == gDb.Children.BCASTID: 00475 addr = gDb.Lem.AFEBCAST 00476 else: 00477 raise KeyError("*** gAEM: GAFE id %d is invalid" %(id)) 00478 gDb.Gdb.__init__(self, client, parent, id, self.__attrs, addr) 00479 00480 def read(self, reg): 00481 return self.cmdrsp('AFE_read', gDb.Lem.ADDR_AEM, self.up().addr(), self.addr(), reg, '!I') 00482 00483 def load(self, reg, value): 00484 return self.cmdrsp('AFE_load', gDb.Lem.ADDR_AEM, self.up().addr(), self.addr(), reg, value) 00485 00486 def send(self, cmd): 00487 return self.cmdrsp('AFE_cmd', gDb.Lem.ADDR_AEM, self.up().addr(), self.addr(), cmd) 00488