Source code for cmd_skiroc

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright 2012-2017 Frédéric Magniette, Miguel Rubio-Roy
# This file is part of Pyrame.
#
# Pyrame is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrame is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrame.  If not, see <http://www.gnu.org/licenses/>

import pools,common_roc

def init():
    common_roc.nb_chans=64

skiroc_pool=pools.pool("skiroc")

skiroc_bs_length=616

#************************* BITSTREAM MANIPULATION FUNCTIONS ***************

# **************************************************************************
# trigger mode
# **************************************************************************

def extract_trig_mode(skiroc,xml_value=True):
    bit=skiroc["bitstream_bin"][9:10]
    if xml_value:
        if bit=="1":
            return "ext"
        if bit=="0":
            return "int"
    return bit

def set_trig_mode_reg(skiroc,trig_mode):
    if trig_mode!="undef":
        if trig_mode not in ["ext","int"]:
            return 0,"Unknown trig_mode %s. Supported trig_modes are int or ext"%(trig_mode)
        if trig_mode=="ext":
            return common_roc.apply_mask(skiroc,9,common_roc.split_bin(1,1))
        if trig_mode=="int":
            return common_roc.apply_mask(skiroc,9,common_roc.split_bin(0,1))
    return 1,"ok"

[docs]def set_trig_mode_skiroc(skiroc_id,trig_mode): "set the trigger mode of a skiroc" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_trig_mode,set_trig_mode_reg,"trig_mode",trig_mode)
# ************************************************************************** # trigger threshold # ************************************************************************** def extract_gtrigger(skiroc): return str(int(skiroc["bitstream_bin"][41:51][::-1],2)) def set_gtrigger_reg(skiroc,gtrigger): if gtrigger!="undef": return common_roc.apply_inv_mask(skiroc,41,common_roc.split_bin(int(gtrigger),10)) return 1,"ok"
[docs]def set_gtrigger_skiroc(skiroc_id,gtrigger): "set the trigger threshold of a skiroc" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_gtrigger,set_gtrigger_reg,"gtrigger",gtrigger)
# ************************************************************************** # DAC1 gain select # ************************************************************************** def extract_dac1_gain(skiroc,xml_value=True): return str(int(skiroc["bitstream_bin"][31:41][::-1],2)) def set_dac1_gain_reg(skiroc,value): if value!="undef": return common_roc.apply_inv_mask(skiroc,31,common_roc.split_bin(int(value),10)) return 1,"ok"
[docs]def set_dac1_gain_skiroc(skiroc_id,value): "Set the DAC1 gain value (10-bit)" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_dac1_gain,set_dac1_gain_reg,"dac1_gain",value)
# ************************************************************************** # Fast shaper time constant # ************************************************************************** fs_tau_strings=["30ns","60ns","90ns","120ns"] def extract_fs_tau(skiroc,xml_value=True): fs_tau=int(skiroc["bitstream_bin"][407:409][::-1],2) if xml_value: return fs_tau_strings[fs_tau] return str(fs_tau) def set_fs_tau_reg(skiroc,value): if value!="undef": if value not in fs_tau_strings: return "fs_tau: unknown value %s. accepted values are 30ns,60ns,90ns,120ns"%(value) i=fs_tau_strings.index(value) return common_roc.apply_inv_mask(skiroc,407,common_roc.split_bin(i,2)) return 1,"ok"
[docs]def set_fs_tau_skiroc(skiroc_id,fs_tau): "Set the fast shaper time constant: accepted values are 30ns,60ns,90ns,120ns" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_fs_tau,set_fs_tau_reg,"fs_tau",fs_tau)
# ************************************************************************** # hold delay # ************************************************************************** def extract_delay(skiroc): return str(int(skiroc["bitstream_bin"][63:71][::-1],2)) def set_delay_reg(skiroc,delay): if delay!="undef": return common_roc.apply_inv_mask(skiroc,63,common_roc.split_bin(int(delay),8)) return 1,"ok"
[docs]def set_delay_skiroc(skiroc_id,delay): "set the hold delay of a skiroc (8-bit integer)" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_delay,set_delay_reg,"delay",delay)
# ************************************************************************** # compensation capacitance # ************************************************************************** # The fourth item of cpcap_strings corresponds to the 1+2pF configuration # A random string is used to disable this configuration in favour of the single # 3pF capacitance configuration cpcap_strings=["0pF","1pF","2pF","X!X!X","3pF","4pF","5pF","6pF"] def extract_cpcap(skiroc,xml_value=True): cpcap=int(skiroc["bitstream_bin"][611:614][::-1],2) if xml_value: return cpcap_strings[cpcap] return str(cpcap) def set_cpcap_reg(skiroc,cpcap): if cpcap!="undef": if cpcap not in cpcap_strings: return "unknown value %s. accepted values are 0pF,1pF,2pF,3pF,4pF,5pF,6pF"%(cpcap) i=cpcap_strings.index(cpcap) return common_roc.apply_inv_mask(skiroc,611,common_roc.split_bin(i,3)) return 1,"ok"
[docs]def set_cpcap_skiroc(skiroc_id,cpcap): "set the compensation capacitance of a skiroc" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_cpcap,set_cpcap_reg,"cpcap",cpcap)
# ************************************************************************** # feedback capacitance # ************************************************************************** fbcap_strings=["0pF","0.4pF","0.8pF","1.2pF","1.6pF","2pF","2.4pF","2.8pF","3.2pF","3.6pF","4pF","4.4pF","4.8pF","5.2pF","5.6pF","6pF"] def extract_fbcap(skiroc,xml_value=True): fbcap=int(skiroc["bitstream_bin"][607:611][::-1],2) if xml_value: return fbcap_strings[fbcap] return str(fbcap) def set_fbcap_reg(skiroc,fbcap): if fbcap!="undef": if fbcap not in fbcap_strings: return 0,"unknown value %s. accepted values are 0pF,0.4pF,0.8pF,1.2pF,1.6pF,2pF,2.4pF,2.8pF,3.2pF,3.6pF,4pF,4.4pF,4.8pF,5.2pF,5.6pF,6pF"%(fbcap) i=fbcap_strings.index(fbcap) return common_roc.apply_inv_mask(skiroc,607,common_roc.split_bin(i,4)) return 1,"ok"
[docs]def set_fbcap_skiroc(skiroc_id,fbcap): "set the feedback capacitance of a skiroc" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_fbcap,set_fbcap_reg,"fbcap",fbcap)
# ************************************************************************** # readout set # ************************************************************************** def extract_start_ro(skiroc,xml_value=True): bit=skiroc["bitstream_bin"][5:6] if xml_value: if bit=="1": return "1" if bit=="0": return "2" return bit def set_start_ro_reg(skiroc,start_ro): if start_ro!="undef": if start_ro not in ["1","2"]: return 0,"invalid value: %s"%(start_ro) if start_ro=="1": return common_roc.apply_mask(skiroc,5,common_roc.split_bin(1,1)) elif start_ro=="2": return common_roc.apply_mask(skiroc,5,common_roc.split_bin(0,1)) return 1,"ok"
[docs]def set_start_ro_skiroc(skiroc_id,start_ro): "start the readout set" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_start_ro,set_start_ro_reg,"start_ro",start_ro)
# ************************************************************************** def extract_end_ro(skiroc,xml_value=True): bit=skiroc["bitstream_bin"][6:7] if xml_value: if bit=="1": return "1" if bit=="0": return "2" return bit def set_end_ro_reg(skiroc,end_ro): if end_ro!="undef": if end_ro not in ["1","2"]: return 0,"invalid value: %s"%(end_ro) if end_ro=="1": return common_roc.apply_mask(skiroc,6,common_roc.split_bin(1,1)) elif end_ro=="2": return common_roc.apply_mask(skiroc,6,common_roc.split_bin(0,1)) return 1,"ok"
[docs]def set_end_ro_skiroc(skiroc_id,end_ro): "end the readout set" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_end_ro,set_end_ro_reg,"end_ro",end_ro)
# ************************************************************************** # chipid # ************************************************************************** def set_chipid(skiroc_id,skiroc): idbin=common_roc.split_bin(common_roc.bin2gray(int(skiroc["chipid"])),8) return common_roc.apply_to_roc(skiroc_pool,skiroc_id,None,common_roc.apply_mask,"undef",10,idbin)
[docs]def set_chipid_param_skiroc(skiroc_id,chipid): "set the chipid of a skiroc chip on the pool" try: skiroc=skiroc_pool.get(skiroc_id) except Exception as e: return 0,str(e) if chipid!="undef": skiroc["chipid"]=chipid return 1,"ok"
[docs]def get_chipid_skiroc(skiroc_id): "get the chipid of a skiroc" try: skiroc=skiroc_pool.get(skiroc_id) except Exception as e: return 0,str(e) return 1,"chipid=%s"%(skiroc["chipid"])
# ************************************************************************** # preamps enable/disable # ************************************************************************** def extract_enable_preamp_chans(skiroc): return common_roc.extract_bit_chans(skiroc,417,3,0) def enable_preamp_chan(skiroc,chan): return common_roc.apply_mask(skiroc,417+(63-chan)*3,common_roc.split_bin(0,1))
[docs]def enable_preamp_chans_skiroc(skiroc_id,chans): "enable the preamplifier on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_enable_preamp_chans,enable_preamp_chan,"enable_preamp_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["disable_preamp_chans"]=extract_disable_preamp_chans(skiroc) return 1,"ok"
# ************************************************************************** def extract_disable_preamp_chans(skiroc): return common_roc.extract_bit_chans(skiroc,417,3,1) def disable_preamp_chan(skiroc,chan): return common_roc.apply_mask(skiroc,417+(63-chan)*3,common_roc.split_bin(1,1))
[docs]def disable_preamp_chans_skiroc(skiroc_id,chans): "disable the preamplifier on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_disable_preamp_chans,disable_preamp_chan,"disable_preamp_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["enable_preamp_chans"]=extract_enable_preamp_chans(skiroc) return 1,"ok"
# ************************************************************************** # calibration capacitor # ************************************************************************** def extract_enable_calib_chans(skiroc): return common_roc.extract_bit_chans(skiroc,416,3,1) def enable_calib_chan(skiroc,chan): return common_roc.apply_mask(skiroc,416+(63-chan)*3,common_roc.split_bin(1,1))
[docs]def enable_calib_chans_skiroc(skiroc_id,chans): "enable calibration capacitor on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_enable_calib_chans,enable_calib_chan,"enable_calib_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["disable_calib_chans"]=extract_disable_calib_chans(skiroc) return 1,"ok"
# ************************************************************************** def extract_disable_calib_chans(skiroc): return common_roc.extract_bit_chans(skiroc,416,3,0) def disable_calib_chan(skiroc,chan): return common_roc.apply_mask(skiroc,416+(63-chan)*3,common_roc.split_bin(0,1))
[docs]def disable_calib_chans_skiroc(skiroc_id,chans): "disable calibration capacitor on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_disable_calib_chans,disable_calib_chan,"disable_calib_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["enable_calib_chans"]=extract_enable_calib_chans(skiroc) return 1,"ok"
# ************************************************************************** # high leakage # ************************************************************************** def extract_enable_high_leak_chans(skiroc): return common_roc.extract_bit_chans(skiroc,415,3,1) def enable_high_leak_chan(skiroc,chan): return common_roc.apply_mask(skiroc,415+(63-chan)*3,common_roc.split_bin(1,1))
[docs]def enable_high_leak_chans_skiroc(skiroc_id,chans): "enable high leakage current on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_enable_high_leak_chans,enable_high_leak_chan,"enable_high_leak_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["disable_high_leak_chans"]=extract_disable_high_leak_chans(skiroc) return 1,"ok"
# ************************************************************************** def extract_disable_high_leak_chans(skiroc): return common_roc.extract_bit_chans(skiroc,415,3,0) def disable_high_leak_chan(skiroc,chan): return common_roc.apply_mask(skiroc,415+(63-chan)*3,common_roc.split_bin(0,1))
[docs]def disable_high_leak_chans_skiroc(skiroc_id,chans): "disable high leakage current on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_disable_high_leak_chans,disable_high_leak_chan,"disable_high_leak_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["enable_high_leak_chans"]=extract_enable_high_leak_chans(skiroc) return 1,"ok"
# ************************************************************************** # triggers # ************************************************************************** def extract_allow_trig_chans(skiroc): return common_roc.extract_bit_chans(skiroc,73,1,0,False) def allow_trig(skiroc,chan): return common_roc.apply_mask(skiroc,73+chan,common_roc.split_bin(0,1))
[docs]def allow_trig_chans_skiroc(skiroc_id,chans): "allow trigger on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_allow_trig_chans,allow_trig,"allow_trig_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["disallow_trig_chans"]=extract_disallow_trig_chans(skiroc) return 1,"ok"
# ************************************************************************** def extract_disallow_trig_chans(skiroc): return common_roc.extract_bit_chans(skiroc,73,1,1,False) def disallow_trig(skiroc,chan): return common_roc.apply_mask(skiroc,73+chan,common_roc.split_bin(1,1))
[docs]def disallow_trig_chans_skiroc(skiroc_id,chans): "disallow trigger on channels" retcode,res=common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_disallow_trig_chans,disallow_trig,"disallow_trig_chans") if retcode==0: return 0,res skiroc=skiroc_pool.get(skiroc_id) skiroc["allow_trig_chans"]=extract_allow_trig_chans(skiroc) return 1,"ok"
# ************************************************************************** # dac adjustment # ************************************************************************** def extract_dacadj(skiroc,chan): pos=137+4*(63-chan) return str(int(skiroc["bitstream_bin"][pos:pos+4],2)) def set_dacadj(skiroc,chan,dacadj): if dacadj!="undef": return common_roc.apply_mask(skiroc,137+4*(63-chan),common_roc.split_bin(int(dacadj),4)) return 1,"ok"
[docs]def set_dacadj_chans_skiroc(skiroc_id,chans,dacadj): "set the dac adjustment to channels" return common_roc.apply_to_chans(skiroc_pool,skiroc_id,chans,extract_dacadj,set_dacadj,"undef",dacadj)
# ************************************************************************** # Trigger delay # ************************************************************************** def extract_trig_delay(skiroc,xml_value=True): return skiroc["bitstream_bin"][72:73]
[docs]def set_trig_delay_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) trigger delay" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_trig_delay,common_roc.on_off_bit,"trig_delay",72,value)
# ************************************************************************** # Auto gain # ************************************************************************** def extract_auto_gain(skiroc,xml_value=True): return skiroc["bitstream_bin"][62:63]
[docs]def set_auto_gain_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) auto gain" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_auto_gain,common_roc.on_off_bit,"auto_gain",62,value)
# ************************************************************************** # Forced gain select # ************************************************************************** forced_gain_strings=["high","low"] def extract_forced_gain(skiroc,xml_value=True): forced_gain=int(skiroc["bitstream_bin"][61:62]) if xml_value: return forced_gain_strings[forced_gain] return str(forced_gain)
[docs]def set_forced_gain_skiroc(skiroc_id,value): "Select forced gain: accepted values are high and low" if value=="undef": rvalue="undef" elif value not in forced_gain_strings: return 0,"forced_gain: unknown value %s. accepted values are high and low" else: rvalue=forced_gain_strings.index(value) return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_forced_gain,common_roc.on_off_bit,"forced_gain",61,rvalue)
# ************************************************************************** # ADC discri # ************************************************************************** def extract_adc_discri(skiroc,xml_value=True): return skiroc["bitstream_bin"][56:57]
[docs]def set_adc_discri_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) ADC discriminator" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_adc_discri,common_roc.on_off_bit,"adc_discri",56,value)
# ************************************************************************** # gain select # ************************************************************************** def extract_gain_select(skiroc,xml_value=True): return skiroc["bitstream_bin"][57:58]
[docs]def set_gain_select_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) gain select discriminator" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_gain_select,common_roc.on_off_bit,"gain_select",57,value)
# ************************************************************************** # power pulsing functions # ************************************************************************** def extract_pp_preamp(skiroc,xml_value=True): value=skiroc["bitstream_bin"][614:615] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_preamp_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) preamp power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_preamp,common_roc.on_off_bit,"pp_preamp",614,value,True)
# ************************************************************************** def extract_pp_ss_g1(skiroc,xml_value=True): value=skiroc["bitstream_bin"][413:414] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_ss_g1_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) slow shaper G1 power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_ss_g1,common_roc.on_off_bit,"pp_ss_g1",413,value,True)
# ************************************************************************** def extract_pp_ss_g10(skiroc,xml_value=True): value=skiroc["bitstream_bin"][411:412] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_ss_g10_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) slow shaper G10 power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_ss_g10,common_roc.on_off_bit,"pp_ss_g10",411,value,True)
# ************************************************************************** def extract_pp_fs(skiroc,xml_value=True): value=skiroc["bitstream_bin"][409:410] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_fs_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) fast shaper power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_fs,common_roc.on_off_bit,"pp_fs",409,value,True)
# ************************************************************************** def extract_pp_sca(skiroc,xml_value=True): value=skiroc["bitstream_bin"][405:406] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_sca_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) SCA power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_sca,common_roc.on_off_bit,"pp_sca",405,value,True)
# ************************************************************************** def extract_pp_dac4(skiroc,xml_value=True): value=skiroc["bitstream_bin"][395:396] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_dac4_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) 4-bit DAC adjustment power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_dac4,common_roc.on_off_bit,"pp_dac4",395,value,True)
# ************************************************************************** def extract_pp_trig_discri(skiroc,xml_value=True): value=skiroc["bitstream_bin"][393:394] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_trig_discri_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) trigger discriminator power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_trig_discri,common_roc.on_off_bit,"pp_trig_discri",393,value,True)
# ************************************************************************** def extract_pp_trig_delay(skiroc,xml_value=True): value=skiroc["bitstream_bin"][71:72] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_trig_delay_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) trigger delay power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_trig_delay,common_roc.on_off_bit,"pp_trig_delay",71,value,True)
# ************************************************************************** def extract_pp_gain_select(skiroc,xml_value=True): value=skiroc["bitstream_bin"][58:59] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_gain_select_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) gain select discriminator power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_gain_select,common_roc.on_off_bit,"pp_gain_select",58,value,True)
# ************************************************************************** def extract_pp_adc_discri(skiroc,xml_value=True): value=skiroc["bitstream_bin"][55:56] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_adc_discri_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) ADC discriminator power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_adc_discri,common_roc.on_off_bit,"pp_adc_discri",55,value,True)
# ************************************************************************** def extract_pp_bandgap(skiroc,xml_value=True): value=skiroc["bitstream_bin"][53:54] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_bandgap_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) bandgap OTA power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_bandgap,common_roc.on_off_bit,"pp_bandgap",53,value,True)
# ************************************************************************** def extract_pp_10bit_dual_dac(skiroc,xml_value=True): value=skiroc["bitstream_bin"][51:52] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_10bit_dual_dac_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) 10-bit DAC power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_10bit_dual_dac,common_roc.on_off_bit,"pp_10bit_dual_dac",51,value,True)
# ************************************************************************** def extract_pp_adc_ramp(skiroc,xml_value=True): value=skiroc["bitstream_bin"][25:26] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_adc_ramp_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) ADC ramp power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_adc_ramp,common_roc.on_off_bit,"pp_adc_ramp",25,value,True)
# ************************************************************************** def extract_pp_lvds_recv(skiroc,xml_value=True): value=skiroc["bitstream_bin"][7:8] if xml_value: return common_roc.not_bit(value) return value
[docs]def set_pp_lvds_recv_skiroc(skiroc_id,value): "Activate (ON or 1) or desactivate (OFF or 0) LVDS receivers power pulsing mode" return common_roc.apply_to_roc(skiroc_pool,skiroc_id,extract_pp_lvds_recv,common_roc.on_off_bit,"pp_lvds_recv",7,value,True)
#********************************** GENERAL PUBLIC FUNCTIONS ***************
[docs]def dump_sc_skiroc(skiroc_id): "Returns bitstream of *skiroc_id* in binary format" try: skiroc=skiroc_pool.get(skiroc_id) except Exception as e: return 0,str(e) #return the bitstream bitstream=skiroc["bitstream_bin"] if not skiroc["missing"] else "" return 1,bitstream
[docs]def set_missing_skiroc(skiroc_id,missing): "Set skiroc missing state" try: skiroc=skiroc_pool.get(skiroc_id) except Exception as e: return 0,str(e) skiroc["missing"]=1 if missing=="1" else 0 return 1,"ok"
[docs]def explain_sc_skiroc(skiroc_id): "Explains the content of a bitsteam in human readable form" try: skiroc=skiroc_pool.get(skiroc_id) except Exception as e: return 0,str(e) if skiroc["bitstream"]!="0x%s"%(common_roc.bin2hexa(skiroc["bitstream_bin"],msb_padding=False)): return 0,"invalid hex bitstream" print("hexa bitstream: ") print("0x"+skiroc["bitstream"].upper()) print("binary bitstream: ") print("0b"+skiroc["bitstream_bin"]) print("chan preamp cal_capa high_leak trig dacadj") enabled_preamps=extract_enable_preamp_chans(skiroc).split(",") if enabled_preamps[0]!="": enabled_preamps=map(int,enabled_preamps) calib_chans=extract_enable_calib_chans(skiroc).split(",") if calib_chans[0]!="": calib_chans=map(int,calib_chans) high_leak_chans=extract_enable_high_leak_chans(skiroc).split(",") if high_leak_chans[0]!="": high_leak_chans=map(int,high_leak_chans) allowed_chans=extract_allow_trig_chans(skiroc).split(",") if allowed_chans[0]!="": allowed_chans=map(int,allowed_chans) for channel in range(64): if channel in enabled_preamps: print_preamp="enabled" else: print_preamp="disabled" if channel in calib_chans: print_cal_capa="disabled" else: print_cal_capa="enabled" if channel in high_leak_chans: print_high_leak="enabled" else: print_high_leak="disabled" if channel in allowed_chans: print_trig="allowed" else: print_trig="disallowed" print_dacadj_int=int(extract_dacadj(skiroc,channel)) print_dacadj_bin=bin(print_dacadj_int) print_dacadj_hex=hex(print_dacadj_int) print("{0:<5d}{1:10s}{2:9s}{3:10s}{4:12s}{5:4s}({6:1s})".format(channel,print_preamp,print_cal_capa,print_high_leak,print_trig,print_dacadj_bin,print_dacadj_hex)) chipid=skiroc["bitstream_bin"][10:18] print("Chipid in gray: %s"%(chipid)) delay=int(extract_delay(skiroc)) print("Delay for the trigger signals: %d(0x%x)"%(delay,delay)) trig=int(extract_gtrigger(skiroc)) print("Trigger Threshold: %d(0x%x) "%(trig,trig)) fbcap_xml=extract_fbcap(skiroc) fbcap_int=int(extract_fbcap(skiroc,False)) print("Feedback capacitance: %d(0x%x) value=%s "%(fbcap_int,fbcap_int,fbcap_xml)) cpcap_xml=extract_cpcap(skiroc) cpcap_int=int(extract_cpcap(skiroc,False)) print("Compensation capacitance: %d(0x%x) value=%s "%(cpcap_int,cpcap_int,cpcap_xml)) start_ro_xml=extract_start_ro(skiroc) start_ro_int=int(extract_start_ro(skiroc,False)) print("Start read-out: %d(0x%x) value=%s "%(start_ro_int,start_ro_int,start_ro_xml)) end_ro_xml=extract_end_ro(skiroc) end_ro_int=int(extract_end_ro(skiroc,False)) print("End read-out: %d(0x%x) value=%s "%(end_ro_int,end_ro_int,end_ro_xml)) trig_mode_xml=extract_trig_mode(skiroc) trig_mode_int=int(extract_trig_mode(skiroc,False)) print("Trigger mode: %d value=%s "%(trig_mode_int,trig_mode_xml)) adc_discri_xml=extract_adc_discri(skiroc) adc_discri_int=int(extract_adc_discri(skiroc,False)) print("ADC discriminator: %d value=%s"%(adc_discri_int,adc_discri_xml)) auto_gain_xml=extract_auto_gain(skiroc) auto_gain_int=int(extract_auto_gain(skiroc,False)) print("Auto Gain: %d value=%s"%(auto_gain_int,auto_gain_xml)) dac1_gain_xml=extract_dac1_gain(skiroc) dac1_gain_int=int(extract_dac1_gain(skiroc,False)) print("DAC1 Gain: %d value=%s"%(dac1_gain_int,dac1_gain_xml)) forced_gain_xml=extract_forced_gain(skiroc) forced_gain_int=int(extract_forced_gain(skiroc,False)) print("Forced Gain: %d value=%s"%(forced_gain_int,forced_gain_xml)) fs_tau_xml=extract_fs_tau(skiroc) fs_tau_int=int(extract_fs_tau(skiroc,False)) print("Fast shaper time constant: %d value=%s"%(fs_tau_int,fs_tau_xml)) gain_select_xml=extract_gain_select(skiroc) gain_select_int=int(extract_gain_select(skiroc,False)) print("Gain select: %d value=%s"%(gain_select_int,gain_select_xml)) pp_10bit_dual_dac_xml=extract_pp_10bit_dual_dac(skiroc) pp_10bit_dual_dac_int=int(extract_pp_10bit_dual_dac(skiroc,False)) print("Power pulsing 10bit dual DAC: %d value=%s"%(pp_10bit_dual_dac_int,pp_10bit_dual_dac_xml)) pp_adc_discri_xml=extract_pp_adc_discri(skiroc) pp_adc_discri_int=int(extract_pp_adc_discri(skiroc,False)) print("Power pulsing ADC discriminator: %d value=%s"%(pp_adc_discri_int,pp_adc_discri_xml)) pp_adc_ramp_xml=extract_pp_adc_ramp(skiroc) pp_adc_ramp_int=int(extract_pp_adc_ramp(skiroc,False)) print("Power pulsing ADC Ramp: %d value=%s"%(pp_adc_ramp_int,pp_adc_ramp_xml)) pp_bandgap_xml=extract_pp_bandgap(skiroc) pp_bandgap_int=int(extract_pp_bandgap(skiroc,False)) print("Power pulsing bandgap: %d value=%s"%(pp_bandgap_int,pp_bandgap_xml)) pp_dac4_xml=extract_pp_dac4(skiroc) pp_dac4_int=int(extract_pp_dac4(skiroc,False)) print("Power pulsing 4bit DAC: %d value=%s"%(pp_dac4_int,pp_dac4_xml)) pp_fs_xml=extract_pp_fs(skiroc) pp_fs_int=int(extract_pp_fs(skiroc,False)) print("Power pulsing fast shaper: %d value=%s"%(pp_fs_int,pp_fs_xml)) pp_gain_select_xml=extract_pp_gain_select(skiroc) pp_gain_select_int=int(extract_pp_gain_select(skiroc,False)) print("Power pulsing gain select: %d value=%s"%(pp_gain_select_int,pp_gain_select_xml)) pp_lvds_recv_xml=extract_pp_lvds_recv(skiroc) pp_lvds_recv_int=int(extract_pp_lvds_recv(skiroc,False)) print("Power pulsing LVDS receivers: %d value=%s"%(pp_lvds_recv_int,pp_lvds_recv_xml)) pp_preamp_xml=extract_pp_preamp(skiroc) pp_preamp_int=int(extract_pp_preamp(skiroc,False)) print("Power pulsing preamp: %d value=%s"%(pp_preamp_int,pp_preamp_xml)) pp_sca_xml=extract_pp_sca(skiroc) pp_sca_int=int(extract_pp_sca(skiroc,False)) print("Power pulsing sca: %d value=%s"%(pp_sca_int,pp_sca_xml)) pp_ss_g10_xml=extract_pp_ss_g10(skiroc) pp_ss_g10_int=int(extract_pp_ss_g10(skiroc,False)) print("Power pulsing slow shaper gain 10: %d value=%s"%(pp_ss_g10_int,pp_ss_g10_xml)) pp_ss_g1_xml=extract_pp_ss_g1(skiroc) pp_ss_g1_int=int(extract_pp_ss_g1(skiroc,False)) print("Power pulsing slow shaper gain 1: %d value=%s"%(pp_ss_g1_int,pp_ss_g1_xml)) pp_trig_delay_xml=extract_pp_trig_delay(skiroc) pp_trig_delay_int=int(extract_pp_trig_delay(skiroc,False)) print("Power pulsing trigger delay: %d value=%s"%(pp_trig_delay_int,pp_trig_delay_xml)) pp_trig_discri_xml=extract_pp_trig_discri(skiroc) pp_trig_discri_int=int(extract_pp_trig_discri(skiroc,False)) print("Power pulsing trigger discriminator: %d value=%s"%(pp_trig_discri_int,pp_trig_discri_xml)) trig_delay_xml=extract_trig_delay(skiroc) trig_delay_int=int(extract_trig_delay(skiroc,False)) print("Trigger delay: %d value=%s"%(trig_delay_int,trig_delay_xml)) return 1,"ok"
#****************************** PHASES *************************************
[docs]def init_skiroc(skiroc_id): "Initialize a skiroc" skiroc_pool.new(skiroc_id,{"missing":0}) return 1,"ok"
[docs]def deinit_skiroc(skiroc_id): "Deinitialize skiroc *skiroc_id*" try: skiroc=skiroc_pool.get(skiroc_id) except Exception as e: return 1,str(e) skiroc_pool.remove(skiroc_id) return 1,"ok"
[docs]def config_skiroc(skiroc_id,file,bitstream,gtrigger,delay,fbcap,cpcap,start_ro,end_ro,enable_preamp_chans,disable_preamp_chans,enable_calib_chans,disable_calib_chans,enable_high_leak_chans,disable_high_leak_chans,allow_trig_chans,disallow_trig_chans,trig_mode,pp_preamp,pp_ss_g1,pp_ss_g10,pp_fs,fs_tau,pp_sca,pp_dac4,pp_trig_discri,trig_delay,pp_trig_delay,auto_gain,forced_gain,pp_gain_select,gain_select,pp_adc_discri,adc_discri,pp_bandgap,pp_10bit_dual_dac,dac1_gain,pp_adc_ramp,pp_lvds_recv): "Prepare the bitstream for configuring a chip" try: skiroc=skiroc_pool.get(skiroc_id) except Exception as e: return 0,str(e) #empty the bitstream skiroc["bitstream_bin"]="" #load bitstream if bitstream!="undef": retcode,res=common_roc.load_str(bitstream,skiroc_bs_length) if retcode==0: return 0,"cant parse bitstream: %s"%(res) skiroc["bitstream_bin"]=res #load bitstream from file if file!="undef": retcode,res=common_roc.load_file(file,skiroc_bs_length) if retcode==0: return 0,"cant open config file: %s"%(res) skiroc["bitstream_bin"]=res if skiroc["bitstream_bin"]=="": return 0,"no bitstream defined for skiroc %s"%(skiroc_id) #set chip id retcode,res=set_chipid(skiroc_id,skiroc) if retcode==0: return 0,"cant set chipid: %s"%(res) #set global trigger threshold retcode,res=set_gtrigger_skiroc(skiroc_id,gtrigger) if retcode==0: return 0,"cant set trigger threshold: %s"%(res) #set delay retcode,res=set_delay_skiroc(skiroc_id,delay) if retcode==0: return 0,"cant set delay: %s"%(res) #set fbcap retcode,res=set_fbcap_skiroc(skiroc_id,fbcap) if retcode==0: return 0,"cant set fbcap: %s"%(res) #set cpcap retcode,res=set_cpcap_skiroc(skiroc_id,cpcap) if retcode==0: return 0,"cant set cpcap: %s"%(res) #set start_ro retcode,res=set_start_ro_skiroc(skiroc_id,start_ro) if retcode==0: return 0,"cant set start_ro: %s"%(res) #set end_ro retcode,res=set_end_ro_skiroc(skiroc_id,end_ro) if retcode==0: return 0,"cant set end_ro: %s"%(res) #enable charge preamp retcode,res=enable_preamp_chans_skiroc(skiroc_id,enable_preamp_chans) if retcode==0: return 0,"cant enable preamps: %s"%(res) # disable charge preamp retcode,res=disable_preamp_chans_skiroc(skiroc_id,disable_preamp_chans) if retcode==0: return 0,"cant disable preamps: %s"%(res) # enable calibration capacitor retcode,res=enable_calib_chans_skiroc(skiroc_id,enable_calib_chans) if retcode==0: return 0,"cant enable calib chans: %s"%(res) # disable calibration capacitor retcode,res=disable_calib_chans_skiroc(skiroc_id,disable_calib_chans) if retcode==0: return 0,"cant disable calib chans: %s"%(res) # allows to trigger retcode,res=allow_trig_chans_skiroc(skiroc_id,allow_trig_chans) if retcode==0: return 0,"cant allow to trigger allow_trig_chans: %s"%(res) # disallows to trigger retcode,res=disallow_trig_chans_skiroc(skiroc_id,disallow_trig_chans) if retcode==0: return 0,"cant disallow to trigger disallow_trig_chans: %s"%(res) # enable high leakage current channel retcode,res=enable_high_leak_chans_skiroc(skiroc_id,enable_high_leak_chans) if retcode==0: return 0,"cant enable high_leak: %s"%(res) # disable high leakage current channel retcode,res=disable_high_leak_chans_skiroc(skiroc_id,disable_high_leak_chans) if retcode==0: return 0,"cant disable high_leak: %s"%(res) # set trigger mode (external/internal) retcode,res=set_trig_mode_skiroc(skiroc_id,trig_mode) if retcode==0: return 0,"cant set trig_mode: %s"%(res) # enable preamp power pulsing mode retcode,res=set_pp_preamp_skiroc(skiroc_id,pp_preamp) if retcode==0: return 0,"cant set pp_preamp: %s"%(res) # enable slow shaper G1 power pulsing mode retcode,res=set_pp_ss_g1_skiroc(skiroc_id,pp_ss_g1) if retcode==0: return 0,"cant set pp_ss_g1: %s"%(res) # enable slow shaper G10 power pulsing mode retcode,res=set_pp_ss_g10_skiroc(skiroc_id,pp_ss_g10) if retcode==0: return 0,"cant set pp_ss_g10: %s"%(res) # enable fast shaper power pulsing mode retcode,res=set_pp_fs_skiroc(skiroc_id,pp_fs) if retcode==0: return 0,"cant set pp_fs: %s"%(res) # set fast shaper time constant retcode,res=set_fs_tau_skiroc(skiroc_id,fs_tau) if retcode==0: return 0,"cant set fs_tau: %s"%(res) # enable SCA power pulsing mode retcode,res=set_pp_sca_skiroc(skiroc_id,pp_sca) if retcode==0: return 0,"cant set pp_sca: %s"%(res) # enable 4-bit DAC adjustment power pulsing mode retcode,res=set_pp_dac4_skiroc(skiroc_id,pp_dac4) if retcode==0: return 0,"cant set pp_dac4: %s"%(res) # enable trigger discriminator power pulsing mode retcode,res=set_pp_trig_discri_skiroc(skiroc_id,pp_trig_discri) if retcode==0: return 0,"cant set pp_trig_discri: %s"%(res) # enable trigger delay function retcode,res=set_trig_delay_skiroc(skiroc_id,trig_delay) if retcode==0: return 0,"cant set enable_trig_delay: %s"%(res) # enable trigger delay power pulsing mode retcode,res=set_pp_trig_delay_skiroc(skiroc_id,pp_trig_delay) if retcode==0: return 0,"cant set pp_trig_delay: %s"%(res) # set autogain selection retcode,res=set_auto_gain_skiroc(skiroc_id,auto_gain) if retcode==0: return 0,"cant set auto_gain selection: %s"%(res) # set forced gain value retcode,res=set_forced_gain_skiroc(skiroc_id,forced_gain) if retcode==0: return 0,"cant set forced_gain value: %s"%(res) # enable gain select discriminator power pulsing mode retcode,res=set_pp_gain_select_skiroc(skiroc_id,pp_gain_select) if retcode==0: return 0,"cant set pp_gain_select: %s"%(res) # enable gain select discriminator retcode,res=set_gain_select_skiroc(skiroc_id,gain_select) if retcode==0: return 0,"cant set enable_gain_select: %s"%(res) # enable ADC discriminator power pulsing mode retcode,res=set_pp_adc_discri_skiroc(skiroc_id,pp_adc_discri) if retcode==0: return 0,"cant set pp_adc_discri: %s"%(res) # enable ADC discriminator retcode,res=set_adc_discri_skiroc(skiroc_id,adc_discri) if retcode==0: return 0,"cant set enable_adc_discri: %s"%(res) # enable bandgap OTA power pulsing mode retcode,res=set_pp_bandgap_skiroc(skiroc_id,pp_bandgap) if retcode==0: return 0,"cant set pp_bandgap: %s"%(res) # enable 10-bit dual DAC power pulsing mode retcode,res=set_pp_10bit_dual_dac_skiroc(skiroc_id,pp_10bit_dual_dac) if retcode==0: return 0,"cant set pp_10bit_dual_dac: %s"%(res) # set 10-bit DAC for gain select discriminator threshold retcode,res=set_dac1_gain_skiroc(skiroc_id,dac1_gain) if retcode==0: return 0,"cant set dac1_gain: %s"%(res) # enable ADC ramp power pulsing mode retcode,res=set_pp_adc_ramp_skiroc(skiroc_id,pp_adc_ramp) if retcode==0: return 0,"cant set pp_adc_ramp: %s"%(res) # enable LVDS receivers power pulsing mode retcode,res=set_pp_lvds_recv_skiroc(skiroc_id,pp_lvds_recv) if retcode==0: return 0,"cant set pp_lvds_recv: %s"%(res) #update the bitstream in cmod common_roc.update_bitstream(skiroc) return 1,"ok"
[docs]def get_param_skiroc(skiroc_id,param_name): "parameter extraction" return common_roc.get_param_roc(skiroc_pool,skiroc_id,param_name)