def __init__(self, axi4_bus, fft_data_cnt=None): if isinstance(axi4_bus, basestring): # device path; create axi4lite instance self.axi4_bus = AXI4LiteBus(axi4_bus, MIXAUT1SGRDef.REG_SIZE) else: self.axi4_bus = axi4_bus if self.axi4_bus is None: self.analyzer = MIXFftAnalyzerSGEmulator( 'mix_fftanalyzer_sg_emulator') self.signal_source = MIXSignalSourceSGEmulator( "mix_signalsource_sg_emulator") self.gpio = MIXGPIOSGEmulator("mix_gpio_sg_emulator", 256) else: self.fft_analyzer_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT1SGRDef.MIX_FFT_ANAYLZER_IPCORE_ADDR, MIXAUT1SGRDef.MIX_FFT_REG_SIZE) self.analyzer = MIXFftAnalyzerSG(self.fft_analyzer_axi4_bus, fft_data_cnt) self.signal_source_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT1SGRDef.MIX_SIGNAL_SOURCE_IPCORE_ADDR, MIXAUT1SGRDef.MIX_SIGNAL_SOURCE_REG_SIZE) self.signal_source = MIXSignalSourceSG(self.signal_source_axi4_bus) self.gpio_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT1SGRDef.MIX_GPIO_IPCORE_ADDR, MIXAUT1SGRDef.MIX_GPIO_REG_SIZE) self.gpio = MIXGPIOSG(self.gpio_axi4_bus) self.adc_rst_pin = Pin(self.gpio, MIXAUT1SGRDef.ADC_RESET_PIN) self.i2s_rx_en_pin = Pin(self.gpio, MIXAUT1SGRDef.I2S_RX_EN_PIN) self.dac_rst_pin = Pin(self.gpio, MIXAUT1SGRDef.DAC_RESET_PIN) self.i2s_tx_en_pin = Pin(self.gpio, MIXAUT1SGRDef.I2S_TX_EN_PIN)
def create_ltc2378_dbg(meter_dev, bus_dev, audio_dev, adc_volt_range): ltc2378_dbg = LTC2378Debuger() if meter_dev == '': meter_bus = None else: if utility.is_pl_device(meter_dev): axi4_bus = AXI4LiteBus(meter_dev, 1024) meter_bus = MIXSignalMeterSG(axi4_bus) else: meter_bus = MIXSignalMeterSG(meter_dev) if bus_dev == '': spi_adc_bus = None else: if utility.is_pl_device(bus_dev): adc_bus = AXI4LiteBus(bus_dev, 256) spi_adc_bus = PLSPIADC(adc_bus) else: spi_adc_bus = PLSPIADC(adc_bus) if audio_dev == '': audio_bus = None else: if utility.is_pl_device(audio_dev): axi4_bus = AXI4LiteBus(audio_dev, 65536) audio_bus = MIXFftAnalyzerSG(axi4_bus) else: audio_bus = MIXFftAnalyzerSG(axi4_bus) ltc2378_dbg.ltc2378 = LTC2378( meter_bus, spi_adc_bus, audio_bus, adc_volt_range) return ltc2378_dbg
def __init__(self, axi4_bus, fft_data_cnt=None): if isinstance(axi4_bus, basestring): # device path; create axi4lite instance self.axi4_bus = AXI4LiteBus(axi4_bus, MIXMagneto002SGRDef.REG_SIZE) else: self.axi4_bus = axi4_bus self.fft_analyzer_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXMagneto002SGRDef.MIX_FFT_ANAYLZER_IPCORE_ADDR, MIXMagneto002SGRDef.MIX_FFT_REG_SIZE) self.gpio_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXMagneto002SGRDef.MIX_GPIO_IPCORE_ADDR, MIXMagneto002SGRDef.MIX_GPIO_REG_SIZE) self.gpio = MIXGPIOSG(self.gpio_axi4_bus) self.i2s_conf_0 = Pin(self.gpio, MIXMagneto002SGRDef.I2S_CONF0_BIT) self.i2s_conf_1 = Pin(self.gpio, MIXMagneto002SGRDef.I2S_CONF1_BIT) self.cs5361_ovfl = Pin(self.gpio, MIXMagneto002SGRDef.CS5361_OVFL_BIT) self.cs5361_rst = Pin(self.gpio, MIXMagneto002SGRDef.CS5361_RST_BIT) self.i2s_en = Pin(self.gpio, MIXMagneto002SGRDef.I2S_EN_BIT) self.analyzer = MIXFftAnalyzerSG(self.fft_analyzer_axi4_bus, fft_data_cnt) self.reset()
def __init__(self, axi4_bus, fft_data_cnt=None, use_signal_source=True, use_analyzer=True, use_gpio=True): if isinstance(axi4_bus, basestring): # device path; create axi4lite instance axi4_bus = AXI4LiteBus(axi4_bus, MIXAUT3SGRDef.REG_SIZE) if axi4_bus is not None: if use_gpio: self._gpio_axi4_bus = AXI4LiteSubBus( axi4_bus, MIXAUT3SGRDef.MIX_GPIO_IPCORE_ADDR, MIXAUT3SGRDef.MIX_GPIO_REG_SIZE) self.gpio = MIXGPIOSG(self._gpio_axi4_bus) if use_signal_source: self._signal_source_axi4_bus = AXI4LiteSubBus( axi4_bus, MIXAUT3SGRDef.MIX_SIGNAL_SOURCE_SG_IPCORE_ADDR, MIXAUT3SGRDef.MIX_SIGNAL_SOURCE_REG_SIZE) self.signal_source = MIXSignalSourceSG( self._signal_source_axi4_bus) if use_analyzer: self._fft_axi4_bus = AXI4LiteSubBus( axi4_bus, MIXAUT3SGRDef.MIX_FFT_ANALYZER_SG_IPCORE_ADDR, MIXAUT3SGRDef.MIX_FFT_REG_SIZE) self.analyzer = MIXFftAnalyzerSG(self._fft_axi4_bus, fft_data_cnt) else: self.analyzer = MIXFftAnalyzerSGEmulator( 'mix_fftanalyzer_sg_emulator') self.signal_source = MIXSignalSourceSGEmulator( "mix_signalsource_sg_emulator") self.gpio = MIXGPIOSGEmulator("mix_gpio_sg_emulator", 256)
def __init__(self, i2c, ipcore=None, analyzer=None, adc_rst_pin=None, adc_ovfl_l_pin=None, i2s_rx_en_pin=None, i2s_ch_select_pin=None, tone_detect_pin=None, upload_ch_select_pin=None, sample_rate=48000): assert sample_rate > 0 and sample_rate <= WarlockDef.MAX_SAMPLING_RATE if (i2c and analyzer and adc_rst_pin and adc_ovfl_l_pin and i2s_rx_en_pin and i2s_ch_select_pin and tone_detect_pin and upload_ch_select_pin): self.i2c = i2c if isinstance(analyzer, basestring): self.analyzer = MIXFftAnalyzerSG(analyzer) else: self.analyzer = analyzer self.adc_rst_pin = adc_rst_pin self.adc_ovfl_l_pin = adc_ovfl_l_pin self.i2s_rx_en_pin = i2s_rx_en_pin self.i2s_ch_select_pin = i2s_ch_select_pin self.tone_detect_pin = tone_detect_pin self.upload_ch_select_pin = upload_ch_select_pin elif (ipcore and i2c): self.i2c = i2c if isinstance(ipcore, basestring): axi4_bus = AXI4LiteBus(ipcore, WarlockDef.MIX_MIK002_REG_SIZE) self.ipcore = MIXMIK002SGR(axi4_bus) else: self.ipcore = ipcore self.analyzer = self.ipcore.analyzer self.adc_rst_pin = Pin(self.ipcore.gpio, WarlockDef.ADC_RST_PIN) self.adc_ovfl_l_pin = Pin(self.ipcore.gpio, WarlockDef.ADC_OVFL_L_PIN) self.i2s_rx_en_pin = Pin(self.ipcore.gpio, WarlockDef.I2S_RX_EN_PIN) self.i2s_ch_select_pin = Pin(self.ipcore.gpio, WarlockDef.I2S_CH_SELECT_PIN) self.tone_detect_pin = Pin(self.ipcore.gpio, WarlockDef.TONE_DETECT_PIN) self.upload_ch_select_pin = Pin(self.ipcore.gpio, WarlockDef.UPLOAD_CH_SELECT_PIN) else: raise WarlockException("Parameter error") self.eeprom = CAT24C32(WarlockDef.EEPROM_DEV_ADDR, i2c) self.nct75 = NCT75(WarlockDef.SENSOR_DEV_ADDR, i2c) self.cat9555 = CAT9555(WarlockDef.CAT9555_DEV_ADDR, i2c) super(Warlock, self).__init__(self.eeprom, self.nct75, cal_table={}, range_table=warlock_range_table) self.sampling_rate = sample_rate self.scope = "" self.mode = ""
def create_magneto002002_dbg(i2c_bus0, led1642_bus, pwm_gck_led, pwm_output, uart_rs485, ad5592r_spi, ad9833_spi, analyzer, gpio_state_pin, pwm1_en_pin, pwm2_en_pin, pwm3_en_pin, pwm4_en_pin, pwm5_en_pin, pwm6_en_pin, pwm7_en_pin, pwm8_en_pin, signal_out_en, iis_rx_en, iis_rx_ovfl, iis_rx_rst): i2c = I2C(i2c_bus0) led1642_bus = AXI4LiteBus(led1642_bus, 256) pwm_gck_led = MIXPWMSG(pwm_gck_led, 1024) pwm_output = MIXPWMSG(pwm_output, 1024) uart_rs485 = UART(uart_rs485) axi4 = AXI4LiteBus(ad5592r_spi, 256) ad5592r_spi = MIXQSPISG(axi4) axi4 = AXI4LiteBus(ad9833_spi, 256) ad9833_spi = MIXQSPISG(axi4) analyzer = MIXFftAnalyzerSG(analyzer) gpio_state_pin = GPIO(int(gpio_state_pin)) pwm1_en_pin = GPIO(int(pwm1_en_pin)) pwm2_en_pin = GPIO(int(pwm2_en_pin)) pwm3_en_pin = GPIO(int(pwm3_en_pin)) pwm4_en_pin = GPIO(int(pwm4_en_pin)) pwm5_en_pin = GPIO(int(pwm5_en_pin)) pwm6_en_pin = GPIO(int(pwm6_en_pin)) pwm7_en_pin = GPIO(int(pwm7_en_pin)) pwm8_en_pin = GPIO(int(pwm8_en_pin)) signal_out_en = GPIO(int(signal_out_en)) iis_rx_en = GPIO(int(iis_rx_en)) iis_rx_ovfl = GPIO(int(iis_rx_ovfl)) iis_rx_rst = GPIO(int(iis_rx_rst)) magneto002002 = MAGNETO002002( i2c, led1642_bus, pwm_gck_led, pwm_output, uart_rs485, ad5592r_spi, ad9833_spi, analyzer, gpio_state_pin, pwm1_en_pin, pwm2_en_pin, pwm3_en_pin, pwm4_en_pin, pwm5_en_pin, pwm6_en_pin, pwm7_en_pin, pwm8_en_pin, signal_out_en, iis_rx_en, iis_rx_ovfl, iis_rx_rst) magneto002002_dbg = MAGNETO002002Debuger() magneto002002.module_init() magneto002002_dbg.magneto002002 = magneto002002 return magneto002002_dbg
def create_warlock_dbg(ipcore_name, i2c_dev, analyzer_dev, adc_rst_pin, adc_ovfl_l_pin, i2s_rx_en_pin, i2s_ch_select_pin, tone_detect_pin): warlock_dbg = WarlockDebuger() if i2c_dev != '': if utility.is_pl_device(i2c_dev): axi4_bus = AXI4LiteBus(i2c_dev, 256) i2c_bus = MIXI2CSG(axi4_bus) else: i2c_bus = I2C(i2c_dev) else: i2c_bus = None if ipcore_name != '': ipcore = MIXMIK002SGR(ipcore_name) warlock_dbg.warlock = Warlock(i2c_bus, ipcore=ipcore) else: axi4 = AXI4LiteBus(analyzer_dev, 65535) analyzer = MIXFftAnalyzerSG(axi4) adc_rst_pin = GPIO(int(adc_rst_pin), 'output') if adc_rst_pin != "" else None adc_ovfl_l_pin = GPIO(int(adc_ovfl_l_pin), 'output') if adc_ovfl_l_pin != "" else None i2s_rx_en_pin = GPIO(int(i2s_rx_en_pin), 'output') if i2s_rx_en_pin != "" else None i2s_ch_select_pin = GPIO(int(i2s_ch_select_pin), 'output') if i2s_ch_select_pin != "" else None tone_detect_pin = GPIO(int(tone_detect_pin), 'output') if tone_detect_pin != "" else None warlock_dbg.warlock = Warlock(i2c=i2c_bus, ipcore=None, analyzer=analyzer, adc_rst_pin=adc_rst_pin, adc_ovfl_l_pin=adc_ovfl_l_pin, i2s_rx_en_pin=i2s_rx_en_pin, i2s_ch_select_pin=i2s_ch_select_pin, tone_detect_pin=tone_detect_pin, upload_ch_select_pin=None, sample_rate=48000) return warlock_dbg
def create_dazzler_dbg(fftrt_dev, i2s_rx_en_pin, adc_rst_pin, gpio_dev, signal_source_dev, i2s_tx_en_pin, dac_rst_pin, i2c_dev, mix_aut1_dev): dazzler_dbg = DazzlerDebuger() if i2c_dev != '': if utility.is_pl_device(i2c_dev): axi4_bus = AXI4LiteBus(i2c_dev, 256) i2c_bus = MIXI2CSG(axi4_bus) else: i2c_bus = I2C(i2c_dev) else: i2c_bus = None if mix_aut1_dev != '': axi4 = AXI4LiteBus(mix_aut1_dev, 0x8000) mix_aut1 = MIXAUT1SGR(axi4) dazzler_dbg.audio = Dazzler(i2c_bus, ip=mix_aut1) else: axi4 = AXI4LiteBus(fftrt_dev, 256) analyzer = MIXFftAnalyzerSG(axi4) axi4 = AXI4LiteBus(signal_source_dev, 256) signal_source = MIXSignalSourceSG(axi4) axi4 = AXI4LiteBus(gpio_dev, 256) gpio = MIXGPIOSG(axi4) analyzer_rst = Pin(gpio, adc_rst_pin) analyzer_en = Pin(gpio, i2s_rx_en_pin) signal_source_rst = Pin(gpio, dac_rst_pin) signal_source_en = Pin(gpio, i2s_tx_en_pin) dazzler_dbg.audio = Dazzler(i2c_bus, analyzer=analyzer, signal_source=signal_source, adc_rst_pin=analyzer_rst, i2s_rx_en_pin=analyzer_en, dac_rst_pin=signal_source_rst, i2s_tx_en_pin=signal_source_en, ip=mix_aut1) return dazzler_dbg
def create_negasonic_dbg(fftrt_dev, i2s_rx_en_pin, adc_rst_pin, gpio_dev, signal_source_dev, i2s_tx_en_pin, dac_rst_pin, i2c_dev, mix_aut1_dev): audio002002_dbg = NegasonicDebuger() if utility.is_pl_device(i2c_dev): axi4_bus = AXI4LiteBus(i2c_dev, 256) i2c_bus = MIXI2CSG(axi4_bus) else: i2c_bus = I2C(i2c_dev) if mix_aut1_dev != '': axi4 = AXI4LiteBus(mix_aut1_dev, 0x8000) mix_aut1 = MIXAUT1(axi4) audio002002_dbg.audio = Negasonic(i2c_bus, ip=mix_aut1) else: axi4 = AXI4LiteBus(fftrt_dev, 256) analyzer = MIXFftAnalyzerSG(axi4) axi4 = AXI4LiteBus(signal_source_dev, 256) signal_source = MIXSignalSourceSG(axi4) axi4 = AXI4LiteBus(gpio_dev, 256) gpio = MIXGPIOSG(axi4) analyzer_rst = Pin(gpio, adc_rst_pin) analyzer_en = Pin(gpio, i2s_rx_en_pin) signal_source_rst = Pin(gpio, dac_rst_pin) signal_source_en = Pin(gpio, i2s_tx_en_pin) audio002002_dbg.audio = Negasonic(i2c_bus, analyzer=analyzer, signal_sourc=signal_source, analyzer_rst=analyzer_rst, analyzer_en=analyzer_en, signal_source_rst=signal_source_rst, signal_source_en=signal_source_en) return audio002002_dbg
def __init__(self, axi4_bus, fft_data_cnt=None): if axi4_bus: if isinstance(axi4_bus, basestring): # device path; create axi4lite instance self.axi4_bus = AXI4LiteBus(axi4_bus, MIXAudio005SGRDef.REG_SIZE) else: self.axi4_bus = axi4_bus else: raise MIXAudio005SGRException( "parameter 'axi4_bus' can not be None") self.fft_analyzer_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAudio005SGRDef.MIX_FFT_ANAYLZER_IPCORE_ADDR, MIXAudio005SGRDef.MIX_FFT_REG_SIZE) self.analyzer = MIXFftAnalyzerSG(self.fft_analyzer_axi4_bus, fft_data_cnt) self.signal_source_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAudio005SGRDef.MIX_SIGNAL_SOURCE_IPCORE_ADDR, MIXAudio005SGRDef.MIX_SIGNAL_SOURCE_REG_SIZE) self.signal_source = MIXSignalSourceSG(self.signal_source_axi4_bus) self.gpio_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAudio005SGRDef.MIX_GPIO_IPCORE_ADDR, MIXAudio005SGRDef.MIX_GPIO_REG_SIZE) self.gpio = MIXGPIOSG(self.gpio_axi4_bus) self.ram_signal_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAudio005SGRDef.MIX_RAM_SIGNAL_IPCORE_ADDR, MIXAudio005SGRDef.MIX_RAM_SIGNAL_REG_SIZE) self.ram_signal = MIXRamSignalSG(self.ram_signal_axi4_bus) self.audio_cache_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAudio005SGRDef.MIX_AUDIO_CACHE_IPCORE_ADDR, MIXAudio005SGRDef.MIX_AUDIO_CACHE_REG_SIZE) self.audio_cache = MIXAudioCacheSG(self.audio_cache_axi4_bus)
def open(self): ''' MIXSolarisSGR open device Examples: ip.open() ''' self.meter_axi4_bus = AXI4LiteSubBus(self.axi4_bus, MIXSolarisSGRDef.MIX_SIGNALMETER_ADDR, MIXSolarisSGRDef.SIGNALMETER_REG_SIZE) self.meter = MIXSignalMeterSG(self.meter_axi4_bus) self.spi_adc_axi4_bus = AXI4LiteSubBus(self.axi4_bus, MIXSolarisSGRDef.MIX_SPIADC_ADDR, MIXSolarisSGRDef.SPIADC_REG_SIZE) self.spi_adc = PLSPIADC(self.spi_adc_axi4_bus) self.audio_axi4_bus = AXI4LiteSubBus(self.axi4_bus, MIXSolarisSGRDef.MIX_FFTANALYZER_ADDR, MIXSolarisSGRDef.FFTANALYZER_REG_SIZE) self.audio = MIXFftAnalyzerSG(self.audio_axi4_bus) self.spi_axi4_bus = AXI4LiteSubBus(self.axi4_bus, MIXSolarisSGRDef.MIX_SPIMASTER_ADDR, MIXSolarisSGRDef.SPIMASTER_REG_SIZE) self.spi_bus = MIXQSPISG(self.spi_axi4_bus) self.source_axi4_bus = AXI4LiteSubBus(self.axi4_bus, MIXSolarisSGRDef.MIX_SIGNALSOURCE_ADDR, MIXSolarisSGRDef.SIGNALSOURCE_REG_SIZE) self.source = MIXSignalSourceSG(self.source_axi4_bus) self.gpio_axi4_bus = AXI4LiteSubBus(self.axi4_bus, MIXSolarisSGRDef.MIX_GPIO_ADDR, MIXSolarisSGRDef.GPIO_REG_SIZE) self.gpio = MIXGPIOSG(self.gpio_axi4_bus) self.spi_dac_axi4_bus = AXI4LiteSubBus(self.axi4_bus, MIXSolarisSGRDef.MIX_SPIDAC_ADDR, MIXSolarisSGRDef.SPIDAC_REG_SIZE) self.spi_dac = PLSPIDAC(self.spi_dac_axi4_bus)
def __init__(self, axi4_bus=None, fft_data_cnt=None, ad717x_chip="ad7175", ad717x_mvref=5000, code_polar="bipolar", reference="extern", buffer_flag="enable", clock="crystal"): if isinstance(axi4_bus, basestring): # device path; create axi4lite instance self.axi4_bus = AXI4LiteBus(axi4_bus, MIXAUT5SGRDef.REG_SIZE) else: self.axi4_bus = axi4_bus if self.axi4_bus is None: self.analyzer = MIXFftAnalyzerSGEmulator( 'mix_fftanalyzer_sg_emulator') self.signal_source = MIXSignalSourceSGEmulator( "mix_signalsource_sg_emulator") self.gpio = MIXGPIOSGEmulator("mix_gpio_sg_emulator", 256) if ad717x_chip == 'ad7175': self.ad717x = MIXAd7175SGEmulator("mix_ad7175_sg_emulator", 2500) else: self.ad717x = MIXAd7177SGEmulator("mix_ad7177_sg_emulator", 2500) else: self.fft_analyzer_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT5SGRDef.MIX_FFT_ANAYLZER_IPCORE_ADDR, MIXAUT5SGRDef.MIX_FFT_REG_SIZE) self.analyzer = MIXFftAnalyzerSG(self.fft_analyzer_axi4_bus, fft_data_cnt) self.signal_source_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT5SGRDef.MIX_SIGNAL_SOURCE_IPCORE_ADDR, MIXAUT5SGRDef.MIX_SIGNAL_SOURCE_REG_SIZE) self.signal_source = MIXSignalSourceSG(self.signal_source_axi4_bus) self.gpio_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT5SGRDef.MIX_GPIO_IPCORE_ADDR, MIXAUT5SGRDef.MIX_GPIO_REG_SIZE) self.gpio = MIXGPIOSG(self.gpio_axi4_bus) self.ad717x_chip = ad717x_chip self.ad717x_mvref = ad717x_mvref self.code_polar = code_polar self.reference = reference self.buffer_flag = buffer_flag self.clock = clock # self.open() self.ad717x_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT5SGRDef.MIX_AD717X_IPCORE_ADDR, MIXAUT5SGRDef.AD717X_REG_SIZE) if self.ad717x_chip == "ad7175": self.ad717x = MIXAd7175SG(self.ad717x_axi4_bus, self.ad717x_mvref, self.code_polar, self.reference, self.buffer_flag, self.clock) elif self.ad717x_chip == "ad7177": self.ad717x = MIXAd7177SG(self.ad717x_axi4_bus, self.ad717x_mvref, self.code_polar, self.reference, self.buffer_flag, self.clock) else: raise MIXDAQT5Exception("Unsupported AD717x chip type %s." % (self.ad717x_chip))
class MIXAUT1SGR(object): ''' MIXAUT1SGR aggregated IPcore has 3 child IP, MIXFftAnalyzerSG, MIXSignalSourceSG, MIXGPIOSG. ClassType = MIXAUT1SGR Args: axi4_bus: instance(AXI4LiteBus)/string, axi4lite instance or dev path. fft_data_cnt: int, get fft absolute data count, if not give, with get count from register. Examples: mix_aut1 = MIXAUT1SGR('/dev/MIX_AUT1_x') ''' rpc_public_api = [ 'reset_adc', 'reset_dac', 'enable_rx', 'disable_rx', 'enable_tx', 'disable_tx', 'enable_upload', 'disable_upload', 'measure', 'enable_output', 'disable_output' ] def __init__(self, axi4_bus, fft_data_cnt=None): if isinstance(axi4_bus, basestring): # device path; create axi4lite instance self.axi4_bus = AXI4LiteBus(axi4_bus, MIXAUT1SGRDef.REG_SIZE) else: self.axi4_bus = axi4_bus if self.axi4_bus is None: self.analyzer = MIXFftAnalyzerSGEmulator( 'mix_fftanalyzer_sg_emulator') self.signal_source = MIXSignalSourceSGEmulator( "mix_signalsource_sg_emulator") self.gpio = MIXGPIOSGEmulator("mix_gpio_sg_emulator", 256) else: self.fft_analyzer_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT1SGRDef.MIX_FFT_ANAYLZER_IPCORE_ADDR, MIXAUT1SGRDef.MIX_FFT_REG_SIZE) self.analyzer = MIXFftAnalyzerSG(self.fft_analyzer_axi4_bus, fft_data_cnt) self.signal_source_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT1SGRDef.MIX_SIGNAL_SOURCE_IPCORE_ADDR, MIXAUT1SGRDef.MIX_SIGNAL_SOURCE_REG_SIZE) self.signal_source = MIXSignalSourceSG(self.signal_source_axi4_bus) self.gpio_axi4_bus = AXI4LiteSubBus( self.axi4_bus, MIXAUT1SGRDef.MIX_GPIO_IPCORE_ADDR, MIXAUT1SGRDef.MIX_GPIO_REG_SIZE) self.gpio = MIXGPIOSG(self.gpio_axi4_bus) self.adc_rst_pin = Pin(self.gpio, MIXAUT1SGRDef.ADC_RESET_PIN) self.i2s_rx_en_pin = Pin(self.gpio, MIXAUT1SGRDef.I2S_RX_EN_PIN) self.dac_rst_pin = Pin(self.gpio, MIXAUT1SGRDef.DAC_RESET_PIN) self.i2s_tx_en_pin = Pin(self.gpio, MIXAUT1SGRDef.I2S_TX_EN_PIN) def reset_adc(self, delay_ms): ''' Reset ADC. Args: delay_ms: int, unit ms, reset time in ms Returns: "done" ''' self.adc_rst_pin.set_level(0) time.sleep(delay_ms / 1000.0) self.adc_rst_pin.set_level(1) return "done" def reset_dac(self, delay_ms): ''' Reset DAC. Args: delay_ms: int, unit ms, reset time in ms Returns: "done" ''' self.dac_rst_pin.set_level(0) time.sleep(delay_ms / 1000.0) self.dac_rst_pin.set_level(1) return "done" def enable_rx(self): ''' Enable I2S RX ''' self.i2s_rx_en_pin.set_level(1) return "done" def disable_rx(self): ''' Disable I2S RX ''' self.i2s_rx_en_pin.set_level(0) return "done" def enable_tx(self): ''' Enable I2S TX ''' self.i2s_tx_en_pin.set_level(1) return "done" def disable_tx(self): ''' Disable I2S TX ''' self.i2s_tx_en_pin.set_level(0) return "done" def enable_upload(self): ''' Enable FFT data upload Returns: string, "done", api execution successful. ''' self.analyzer.enable_upload() return "done" def disable_upload(self): ''' Disable FFT data upload Returns: string, "done", api execution successful. ''' self.analyzer.disable_upload() return "done" def measure(self, sampling_rate, decimation_type, bandwidth_hz='auto', harmonic_num=None, freq_point=None): ''' Measure signal's freq, vpp, THD+N, THD. Args: sample_rate: int, Sample rate of your ADC device, unit is Hz. Eg. 192000. decimation_type: int, [1~255], Decimation for FPGA to get datas. If decimation is 0xFF, FPGA will choose one suitable number. bandwidth: int/string, FFT calculation bandwidth limit, must smaller than half of sample_rate, unit is Hz. Eg. 20000. If 'auto' given, bandwidth will be automatically adjust based on base frequency. harmonic_count: int/None, [1~10] The harmonic count of signal, default is None will not do calculate. freq_point: int/None, Specified frequency for calculating amplitude at this special frequency, default is None will not do this. Returns: dict, {'vpp': value, 'freq': value, 'thd': value, 'thdn': value), dict with vpp, freq, thd, thdn. Examples: result = aut1.measure(48000, 5, 0xff) print(result['frequency'], result['vpp'], ['thdn'], ['thd']) ''' self.analyzer.disable() self.analyzer.enable() self.analyzer.analyze_config(sampling_rate, decimation_type, bandwidth_hz, harmonic_num, freq_point) self.analyzer.analyze() result = dict() result["vpp"] = self.analyzer.get_vpp() result["freq"] = self.analyzer.get_frequency() result["thd"] = self.analyzer.get_thd() result["thdn"] = self.analyzer.get_thdn() return result def enable_output(self, sampling_rate, freq, vpp): ''' Enable signal source output Args: sampling_rate: int, in SPS, DAC sampling rate. freq: int, unit Hz, Ouput signal's frequency. vpp: float, [0.000~0.999], output signal vpp scale. Returns: string, "done", api execution successful. Examples: aut1.enable_output(10000, 500) ''' self.signal_source.open() self.signal_source.set_signal_type(MIXAUT1SGRDef.OUTPUT_TYPE) self.signal_source.set_signal_time(MIXAUT1SGRDef.ALWAYS_OUTPUT) self.signal_source.set_swg_paramter(sampling_rate, freq, vpp, MIXAUT1SGRDef.OUTPUT_DUTY) self.signal_source.output_signal() return "done" def disable_output(self): ''' Disable signal source output ''' self.signal_source.close() return "done"
def __init__(self, i2c_0=None, i2c_1=None, i2c_2=None, dma=None, thdn_dma_channel=2, rms_dma_channel=1, ipcore=None, meter=None, spi_adc=None, audio=None, spi_bus=None, source=None, gpio=None, spi_dac=None, ad5761_mvref=2500): self.ipcore = ipcore self.pcal6524 = list() self.adg2128 = list() self.i2c_0 = i2c_0 self.i2c_1 = i2c_1 self.i2c_2 = i2c_2 self.dma_inited = False self.dma_channel = {"rms": rms_dma_channel, "thdn": thdn_dma_channel} if not ipcore and not i2c_0 and not i2c_1 and not i2c_2 and not dma \ and not meter and not spi_adc and not audio and not spi_bus \ and not source and not gpio and not spi_dac: self.i2c_0 = I2CBusEmulator("i2c_emulator", 256) self.i2c_1 = I2CBusEmulator("i2c_emulator", 256) self.i2c_2 = I2CBusEmulator("i2c_emulator", 256) self.eeprom = EepromEmulator('m24128_emulator') self.ltc2378 = LTC2378Emulator("ltc2378") self.ad5761 = AD5761Emulator("ad5761") self.gpio = MIXGPIOSGEmulator("gpio", 256) self.signal_source = MIXSignalSourceSGEmulator( "pl_signal_source_emulator") self.spi_dac = PLSPIDACEmulator("pl_spi_dac_emulator") self.dma = MIXDMASGEmulator('dma') self.eeprom = EepromEmulator('m24128_emulator') for i in range(SolarisDef.PCAL6524_CHIP_NUM): self.pcal6524.append( PCAL6524Emulator(SolarisDef.PCAL6524_DEV_ADDR[i], self.i2c_0)) for i in range(8): self.adg2128.append( ADG2128Emulator(SolarisDef.ADG2128_DEV_ADDR[i])) for i in range(8): self.adg2128.append( ADG2128Emulator(SolarisDef.ADG2128_DEV_ADDR[i])) self.tmp108 = TMP108(SolarisDef.TMP108_DEV_ADDR, self.i2c_2) self.ad5272 = AD5272Emulator("ad5272") for i in range(2): self.adg2128.append( ADG2128Emulator(SolarisDef.ADG2128_DEV_ADDR[i])) else: if ipcore and i2c_0 and i2c_1 and i2c_2 and dma \ and not meter and not spi_adc and not audio and not spi_bus \ and not source and not gpio and not spi_dac: if isinstance(ipcore, basestring): self.ipcore = MIXSolarisSGR(ipcore) self.ltc2378 = LTC2378(self.ipcore.meter, self.ipcore.spi_adc, self.ipcore.audio, SolarisDef.LTC2378_VOLT_RANGE) self.ad5761 = AD5761(ad5761_mvref, self.ipcore.spi_bus) self.gpio = self.ipcore.gpio self.signal_source = self.ipcore.source self.spi_dac = self.ipcore.spi_dac elif not ipcore and i2c_0 and i2c_1 and i2c_2 and dma and \ meter and spi_adc and audio and spi_bus \ and source and gpio and spi_dac: if isinstance(meter, basestring): meter = MIXSignalMeterSG(meter) if isinstance(spi_adc, basestring): spi_adc = PLSPIADC(spi_adc) if isinstance(audio, basestring): audio = MIXFftAnalyzerSG(audio) if isinstance(source, basestring): source = MIXSignalSourceSG(source) if isinstance(spi_dac, basestring): spi_dac = PLSPIDAC(spi_dac) self.ltc2378 = LTC2378(meter, spi_adc, audio, SolarisDef.LTC2378_VOLT_RANGE) self.ad5761 = AD5761(ad5761_mvref, spi_bus) self.gpio = gpio self.signal_source = source self.spi_dac = spi_dac else: raise SolarisException( 'Not allowed to use both aggregated IP and\ meter,spi_adc,audio,spi_bus,source,gpio,spi_dac at the same time' ) self.dma = dma self.eeprom = M24128(SolarisDef.M24128_DEV_ADDR, self.i2c_0) for i in range(SolarisDef.PCAL6524_CHIP_NUM): self.pcal6524.append( PCAL6524(SolarisDef.PCAL6524_DEV_ADDR[i], self.i2c_0)) for i in range(8): self.adg2128.append( ADG2128(SolarisDef.ADG2128_DEV_ADDR[i], self.i2c_0)) for i in range(8): self.adg2128.append( ADG2128(SolarisDef.ADG2128_DEV_ADDR[i], self.i2c_1)) self.tmp108 = TMP108(SolarisDef.TMP108_DEV_ADDR, self.i2c_2) self.ad5272 = AD5272(SolarisDef.AD5272_DEV_ADDR, self.i2c_2) for i in range(2): self.adg2128.append( ADG2128(SolarisDef.ADG2128_DEV_ADDR[i], self.i2c_2)) super(Solaris, self).__init__(self.eeprom, self.tmp108)
class Warlock(SGModuleDriver): ''' Warlock is a high-pressure differential input digital audio module. compatible = ["GQQ-Q58K-5-010", "GQQ-Q58K-5-020"] Args: i2c: instance(I2C), the instance of I2C bus. which will be used to used to control eeprom, sensor and io expander. ipcore: instance(MIXMIK002SGR)/string, the instance of Ipcore, which has 2 child IP, MIXFftAnalyzerSG, MIXGPIOSG. analyzer: instance(PLFFTAnalyzer)/string, if not given, will create emulator. adc_rst_pin: instance(GPIO), used to reset IIS of the CS5381. adc_ovfl_l_pin: instance(GPIO), used to get state of the ovfl_l pin for CS5381. i2s_rx_en_pin: instance(GPIO), used to enable fft analyzer module. i2s_ch_select_pin: instance(GPIO), used to select measure channel for CS5381. tone_detect_pin: instance(GPIO), used to get state of the tone detect pin. upload_ch_select_pin: instance(GPIO), used to select fft measuring or upload to DMA directly. sample_rate: int, unit Hz, default 48000, used to configure the CS5381. Examples: # use non-aggregated IP i2c_bus = I2C('/dev/i2c-1') axi4 = AXI4LiteBus(analyzer_dev, 256) analyzer = MIXFftAnalyzerSG(axi4) adc_rst_pin = GPIO(88, 'output') adc_ovfl_l_pin = GPIO(93, 'output') i2s_rx_en_pin = GPIO(87, 'output') i2s_ch_select_pin = GPIO(95, 'output') tone_detect_pin = GPIO(94, 'output') upload_ch_select_pin = GPIO(97, 'output') warlock = Warlock(i2c=i2c_bus, ipcore=None, analyzer=analyzer, adc_rst_pin=adc_rst_pin, adc_ovfl_l_pin=adc_ovfl_l_pin, i2s_rx_en_pin=i2s_rx_en_pin, i2s_ch_select_pin=i2s_ch_select_pin, tone_detect_pin=tone_detect_pin, upload_ch_select_pin=upload_ch_select_pin, sample_rate=48000) # use MIXMIK002SGR aggregated IP i2c_bus = I2C('/dev/i2c-1') ipcore = MIXMIK002SGR('/dev/MIX_MIK002_SG_R') warlock = Warlock(i2c=i2c_bus, ipcore=ipcore) # measure left channel input in china mode. warlock.headphone_out('1Vrms', 'CH') warlock.measure('left', 20000, 5) # measure xtalk signal in china mode. warlock.hp2mic_xtalk('CH') warlock.xtalk_measure('hp2mic') ''' # launcher will use this to match driver compatible string and load driver if matched. compatible = ["GQQ-Q58K-5-010", "GQQ-Q58K-5-020"] rpc_public_api = ['enable_upload', 'disable_upload', 'measure', 'xtalk_measure', 'mikey_tone', 'get_tone_detect_state', 'set_sampling_rate', 'get_sampling_rate', 'adc_hpf_state', 'headset_loopback', 'line_out', 'headphone_out', 'hp2mic_xtalk', 'io_set', 'io_dir_set', 'adc_reset', 'get_overflow_state', 'io_dir_read', 'io_read', 'start_record_data', 'stop_record_data'] + SGModuleDriver.rpc_public_api def __init__(self, i2c, ipcore=None, analyzer=None, adc_rst_pin=None, adc_ovfl_l_pin=None, i2s_rx_en_pin=None, i2s_ch_select_pin=None, tone_detect_pin=None, upload_ch_select_pin=None, sample_rate=48000): assert sample_rate > 0 and sample_rate <= WarlockDef.MAX_SAMPLING_RATE if (i2c and analyzer and adc_rst_pin and adc_ovfl_l_pin and i2s_rx_en_pin and i2s_ch_select_pin and tone_detect_pin and upload_ch_select_pin): self.i2c = i2c if isinstance(analyzer, basestring): self.analyzer = MIXFftAnalyzerSG(analyzer) else: self.analyzer = analyzer self.adc_rst_pin = adc_rst_pin self.adc_ovfl_l_pin = adc_ovfl_l_pin self.i2s_rx_en_pin = i2s_rx_en_pin self.i2s_ch_select_pin = i2s_ch_select_pin self.tone_detect_pin = tone_detect_pin self.upload_ch_select_pin = upload_ch_select_pin elif (ipcore and i2c): self.i2c = i2c if isinstance(ipcore, basestring): axi4_bus = AXI4LiteBus(ipcore, WarlockDef.MIX_MIK002_REG_SIZE) self.ipcore = MIXMIK002SGR(axi4_bus) else: self.ipcore = ipcore self.analyzer = self.ipcore.analyzer self.adc_rst_pin = Pin(self.ipcore.gpio, WarlockDef.ADC_RST_PIN) self.adc_ovfl_l_pin = Pin(self.ipcore.gpio, WarlockDef.ADC_OVFL_L_PIN) self.i2s_rx_en_pin = Pin(self.ipcore.gpio, WarlockDef.I2S_RX_EN_PIN) self.i2s_ch_select_pin = Pin(self.ipcore.gpio, WarlockDef.I2S_CH_SELECT_PIN) self.tone_detect_pin = Pin(self.ipcore.gpio, WarlockDef.TONE_DETECT_PIN) self.upload_ch_select_pin = Pin(self.ipcore.gpio, WarlockDef.UPLOAD_CH_SELECT_PIN) else: raise WarlockException("Parameter error") self.eeprom = CAT24C32(WarlockDef.EEPROM_DEV_ADDR, i2c) self.nct75 = NCT75(WarlockDef.SENSOR_DEV_ADDR, i2c) self.cat9555 = CAT9555(WarlockDef.CAT9555_DEV_ADDR, i2c) super(Warlock, self).__init__(self.eeprom, self.nct75, range_table=warlock_range_table) self.sampling_rate = sample_rate self.scope = "" self.mode = "" def post_power_on_init(self, timeout=WarlockDef.DEFAULT_TIMEOUT): ''' Init Warlock module to a know harware state. This function will reset adc and i2s module. Args: timeout: float, (>=0), default 1, unit Second, execute timeout. ''' self.reset(timeout) def reset(self, timeout=WarlockDef.DEFAULT_TIMEOUT): ''' Reset the instrument module to a know hardware state. Args: timeout: float, (>=0), default 1, unit Second, execute timeout. Returns: string, "done", if execute successfully. ''' start_time = time.time() while True: try: self.cat9555.set_pins_dir([0x00, 0xf0]) self.adc_rst_pin.set_dir(WarlockDef.IO_OUTPUT_DIR) self.i2s_rx_en_pin.set_dir(WarlockDef.IO_OUTPUT_DIR) self.i2s_ch_select_pin.set_dir(WarlockDef.IO_OUTPUT_DIR) self.upload_ch_select_pin.set_dir(WarlockDef.IO_OUTPUT_DIR) self.tone_detect_pin.set_dir(WarlockDef.IO_INPUT_DIR) self.adc_ovfl_l_pin.set_dir(WarlockDef.IO_INPUT_DIR) # reset ADC self.adc_reset() self.i2s_rx_en_pin.set_level(1) io_states = self.cat9555.get_ports() self.cat9555.set_ports([0x00, io_states[1] & 0xf0]) self._get_default_sampling_rate() return "done" except Exception as e: if time.time() - start_time > timeout: raise WarlockException("Timeout: {}".format(e.message)) return "done" def pre_power_down(self, timeout=WarlockDef.DEFAULT_TIMEOUT): ''' Put the hardware in a safe state to be powered down. Args: timeout: float, (>=0), default 1, unit Second, execute timeout. ''' start_time = time.time() while True: try: self.adc_rst_pin.set_level(0) self.i2s_rx_en_pin.set_level(0) return except Exception as e: if time.time() - start_time > timeout: raise WarlockException("Timeout: {}".format(e.message)) def start_record_data(self, channel): ''' Warlock start collect the data and upload to DMA directly. Args: channel: string, ['left', 'right']. Returns: string, 'done', api execution successful. Examples: warlock.start_record_data('left') ''' assert channel in WarlockDef.AUDIO_CHANNEL_LIST self._audio_channel_select(channel) self.i2s_rx_en_pin.set_level(0) self.upload_ch_select_pin.set_level(1) time.sleep(WarlockDef.GPIO_DELAY_MS / 1000.0) self.i2s_rx_en_pin.set_level(1) return "done" def stop_record_data(self): ''' Warlock stop collect the data. Returns: string, 'done', api execution successful. Examples: warlock.stop_record_data() ''' self.i2s_rx_en_pin.set_level(0) self.upload_ch_select_pin.set_level(0) self.i2s_rx_en_pin.set_level(1) time.sleep(WarlockDef.GPIO_DELAY_MS / 1000.0) return "done" def _get_default_sampling_rate(self): io_states = self.cat9555.get_ports() target_pin = io_states[1] & WarlockDef.sample_rate_pin_mask if target_pin in WarlockDef.sampling_rate_select: self.sampling_rate = WarlockDef.sampling_rate_select[target_pin] else: self.set_sampling_rate(self.sampling_rate) def _set_function_path(self, config, scope): ''' Warlock set function path Args: config: string, ['mode_select', 'range_select','mikey_tone', 'short_circuit_detect', 'extra']. scope: string, ['GB','CH','HP_1Vrms','HP_3.5Vrms','line_out','s1_enable', 's2_enable','s3_enable','all_disable','MIC_S0_enable', 'MIC_S0_disable','enable','disable','hp2mic_xtalk']. Returns: string, 'done', api execution successful. Examples: warlock._set_function_path('mode_select', 'GB') ''' assert config in warlock_function_info assert scope in warlock_function_info[config] bits = warlock_function_info[config][scope]['bits'] for bit in bits: self.cat9555.set_pin(bit[0], bit[1]) time.sleep(WarlockDef.RELAY_DELAY_MS / 1000.0) def _volt_to_target_unit(self, scope, volt): ''' Warlock get target unit value from measured voltage. Args: scope: string, the range of channel measure. volt: float, the measured voltage. Returns: float, value. ''' assert scope in warlock_function_info['range_select'] return volt * warlock_function_info['range_select'][scope]['coefficient'] def _audio_channel_select(self, channel): ''' Warlock cs5381 chip channel select. Args: channel: string, ['left','right'], Use for select which channel to measure. Returns: string, 'done', api execution successful. Examples: warlock._audio_channel_select('left') ''' if channel == 'left': self.i2s_ch_select_pin.set_level(0) else: self.i2s_ch_select_pin.set_level(1) return "done" def enable_upload(self): ''' Warlock upoad mode open. Control audio upload data of ADC when doing measurement. It's not necessary enable upload when doing measurement. Note that data transfered into DMA is 32bit each data, but high 24bit data is valid. Low 8bit data is invalid. The data format is twos complement. Returns: string, 'done', api execution successful. ''' self.analyzer.enable_upload() return "done" def disable_upload(self): ''' Warlock upoad mode close. Close data upload doesn't influence to measure. Returns: string, 'done', api execution successful. ''' self.analyzer.disable_upload() return "done" def set_sampling_rate(self, sampling_rate): ''' Warlock set sampling rate. Args: sampling_rate: int, [192000, 96000, 48000], unit Hz, adc measure sampling rate. Returns: string, 'done', api execution successful. Examples: warlock.set_sampling_rate(96000) ''' assert str(sampling_rate) + "Hz" in warlock_function_info["adc_sample_rate"] io_dir_state = self.cat9555.get_pins_dir() if io_dir_state[1] & WarlockDef.sample_rate_pin_mask != 0: self.cat9555.set_pins_dir([io_dir_state[0], io_dir_state[1] & ~WarlockDef.sample_rate_pin_mask]) self._set_function_path("adc_sample_rate", str(sampling_rate) + "Hz") self.sampling_rate = sampling_rate if isinstance(sampling_rate, int) else int(sampling_rate) return "done" def get_sampling_rate(self): ''' Warlock get sampling rate. Returns: int, unit Hz. Examples: warlock.get_sampling_rate() ''' return self.sampling_rate def headset_loopback(self, mode): ''' Warlock set headset_loopback function. Args: mode: string, ['GB', 'CH'], GB mean global mode, CH mean china mode. Returns: string, 'done', api execution successful. Examples: warlock.headset_loopback('CH') ''' assert mode in warlock_function_info["mode_select"] self._set_function_path("extra", "headset_loopback") self._set_function_path("mode_select", mode) return "done" def headphone_out(self, range_name, mode): ''' Warlock set headphone_out function. Args: range_name: string, ['1Vrms', '3.5Vrms']. mode: string, ['GB', 'CH'], GB mean global mode, CH mean china mode. Returns: string, 'done', api execution successful. Examples: warlock.headphone_out('1Vrms', 'CH') ''' assert ("HP_" + range_name) in warlock_function_info["range_select"] assert mode in warlock_function_info["mode_select"] self._set_function_path("range_select", "HP_" + range_name) self._set_function_path("mode_select", mode) self.mode = mode self.scope = "HP_" + range_name return "done" def line_out(self): ''' Warlock set line_out function. Returns: string, 'done', api execution successful. Examples: warlock.line_out() ''' self._set_function_path("range_select", "line_out") self.scope = "line_out" return "done" def hp2mic_xtalk(self, mode): ''' Warlock set hp2mic_xtalk function. Args: mode: string, ['GB', 'CH'], GB mean global mode, CH mean china mode. Returns: string, 'done', api execution successful. Examples: warlock.hp2mic_xtalk('CH') ''' assert mode in warlock_function_info["mode_select"] self._set_function_path("extra", "hp2mic_xtalk") self._set_function_path("range_select", "HP_1Vrms") self._set_function_path("mode_select", mode) self.mode = mode self.scope = "HP_1Vrms" return "done" def io_set(self, io_list): ''' Warlock set io state, this is a debug function. Args: io_list: list, [[pin,state],[pin,state]], pin [0~15], state [0,1]. Returns: string, 'done', api execution successful. Examples: warlock.io_set([[0,1],[1,1]]) ''' assert isinstance(io_list, list) assert all([isinstance(io, list) and len(io) == 2 for io in io_list]) assert all([io[0] in xrange(16) and io[1] in xrange(2) for io in io_list]) for io in io_list: self.cat9555.set_pin(io[0], io[1]) return "done" def io_dir_set(self, io_list): ''' Warlock set io direction, this is a debug function. Args: io_list: list, [[pin,state],[pin,state]], pin [0~15], state ['input','output']. Returns: string, 'done', api execution successful. Examples: warlock.io_dir_set([[0,'output'],[1,'output']]) ''' assert isinstance(io_list, list) assert all([isinstance(io, list) and len(io) == 2 for io in io_list]) assert all([io[0] in xrange(16) and io[1] in ['output', 'input'] for io in io_list]) for io in io_list: self.cat9555.set_pin_dir(io[0], io[1]) return 'done' def io_read(self, io_list): ''' Warlock set io state, this is a debug function. Args: io_list: list, [pinx,pinx,… ,pinx], pin x mean [0~15]. Returns: list, [[pin,state],[pin,state]], pin [0~15], state [0,1]. Examples: warlock.read_pin([0,1,2,7]) ''' assert isinstance(io_list, list) assert all([isinstance(io, int) for io in io_list]) assert all([0 <= io <= 15 for io in io_list]) data_list = [] for io in io_list: data_list.append([io, self.cat9555.get_pin(io)]) return data_list def io_dir_read(self, io_list): ''' Warlock set io direction, this is a debug function. Args: io_list: list, [pinx,pinx,… ,pinx], pin x mean [0~15]. Returns: list, [[pin,state],[pin,state]], pin [0~15], state ['input','output']. Examples: warlock.read_pin_dir([0,1]) ''' assert isinstance(io_list, list) assert all([isinstance(io, int) for io in io_list]) assert all([0 <= io <= 15 for io in io_list]) data_list = [] for io in io_list: data_list.append([io, self.cat9555.get_pin_dir(io)]) return data_list def adc_reset(self): ''' Warlock reset adc. Returns: string, 'done', api execution successful. Examples: warlock.adc_reset() ''' self.adc_rst_pin.set_level(0) time.sleep(WarlockDef.RST_DELAY_MS / 1000.0) self.adc_rst_pin.set_level(1) return "done" def measure(self, channel, bandwidth_hz=20000, harmonic_num=5, decimation_type=1): ''' Warlock measure signal's Vpp, RMS, THD+N, THD. Args: channel: string, ['left', 'right']. bandwidth_hz: int, [50~95977], default 20000, unit Hz, Measure signal's limit bandwidth, The frequency of the signal should not be greater than half of the bandwidth. harmonic_num: int, [2~10], default 5, Use for measuring signal's THD. decimation_type: int, [1~255], default 1, Decimation for FPGA to get datas, If decimation is 0xFF, FPGA will choose one suitable number. Returns: dict, {'vpp': value, 'freq': value, 'thd': value, 'thdn': value, 'rms': value), dict with vpp, freq, thd, thdn, rms. Examples: result = warlock.measure('left', 20000, 5) print result.frequency, result.vpp, result.thdn, result.thd, result.rms ''' assert channel in WarlockDef.AUDIO_CHANNEL_LIST assert bandwidth_hz == WarlockDef.BANDWIDTH_AUTO or isinstance(bandwidth_hz, int) assert WarlockDef.BANDWIDTH_MIN <= bandwidth_hz <= WarlockDef.BANDWIDTH_MAX assert isinstance(harmonic_num, int) and\ WarlockDef.HARMONIC_CNT_MIN <= harmonic_num <= WarlockDef.HARMONIC_CNT_MAX assert isinstance(decimation_type, int) and\ WarlockDef.DECIMATION_TYPE_MIN <= decimation_type <= WarlockDef.DECIMATION_TYPE_MAX self._audio_channel_select(channel) self.stop_record_data() self.analyzer.disable() self.analyzer.enable() self.analyzer.analyze_config(self.sampling_rate, decimation_type, bandwidth_hz, harmonic_num) self.analyzer.analyze() # calculate the actual vpp of HW by VREF vpp = self.analyzer.get_vpp() * WarlockDef.AUDIO_ANALYZER_VREF vpp = self._volt_to_target_unit(self.scope, vpp) # vpp = RMS * 2 * sqrt(2) rms = vpp / WarlockDef.RMS_TO_VPP_RATIO range_name = (channel + "_" + WarlockDef.RMS_LIST[self.scope]).upper() rms = self.calibrate(range_name, rms) # rms = self.calibrate(WarlockDef.MEASURE_CAL_ITEM, rms) vpp = rms * WarlockDef.RMS_TO_VPP_RATIO result = dict() result["vpp"] = vpp result["freq"] = self.analyzer.get_frequency() result["thd"] = self.analyzer.get_thd() result["thdn"] = self.analyzer.get_thdn() result["snr"] = -1 * result["thdn"] result["rms"] = rms return result def xtalk_measure(self, channel, bandwidth_hz=50000, harmonic_num=5, decimation_type=1): ''' Warlock Crosstalk mode measure. Args: channel: string, ['hp2mic', 'hpl2r', 'hpr2l']. bandwidth_hz: int, [50~95977], default 50000, unit Hz, Measure signal's limit bandwidth, The frequency of the signal should not be greater than half of the bandwidth. harmonic_num: int, [2~10], default 5, Use for measuring signal's THD. decimation_type: int, [1~255], default 1, Decimation for FPGA to get data, If decimation is 0xFF, FPGA will choose one suitable number. Returns: list, [value, db]. Examples: warlock.xtalk_measure('hp2mic') ''' assert channel in ["hp2mic", "hpl2r", "hpr2l"] Va = self.measure("left", bandwidth_hz, harmonic_num, decimation_type)["rms"] Vb = self.measure("right", bandwidth_hz, harmonic_num, decimation_type)["rms"] if channel == "hpr2l": return [20 * math.log(Vb / Va, 10), "db"] else: return [20 * math.log(Va / Vb, 10), "db"] def mikey_tone(self, freq="default", mode="GB"): ''' Warlock set signal output. Args: freq: string, ['S1', 'S2', 'S3', 'S0', 'default'], default 'default' mean (S0, S1, S2, S3)=0. mode: string, ['GB', 'CH'], default 'GB', GB mean global mode, CH mean china mode. Returns: string, 'done', api execution successful. Examples: warlock.mikey_tone('S1', 'CH') ''' assert freq in warlock_function_info["mikey_tone"] assert mode in warlock_function_info["mode_select"] self._set_function_path("mode_select", mode) self._set_function_path("mikey_tone", freq) return "done" def get_tone_detect_state(self): ''' Warlock get tone detect state. Returns: int, [1,0], 1 mean high level, 0 mean low level. Examples: warlock.get_tone_detect_state() ''' return self.tone_detect_pin.get_level() def get_overflow_state(self): ''' Warlock get overflow pin state. Returns: int, [1,0], 1 mean high level, 0 mean low level. Examples: warlock.get_overflow_state() ''' return self.adc_ovfl_l_pin.get_level() def adc_hpf_state(self, state): ''' Warlock set adc hpf pin. Args: state: string, ['enable', 'disable']. Returns: string, 'done', api execution successful. Examples: warlock.adc_hpf_state('enable') ''' assert state in ["enable", "disable"] if self.cat9555.get_pin_dir(WarlockDef.ADC_HPF_PIN) != WarlockDef.IO_OUTPUT_DIR: self.cat9555.set_pin_dir(WarlockDef.ADC_HPF_PIN, WarlockDef.IO_OUTPUT_DIR) self._set_function_path("ADC_HPF", state) return "done" def get_driver_version(self): ''' Get Warlock driver version. Returns: string, current driver version. ''' return __version__
def __init__(self, i2c_bus0=None, led1642_bus=None, pwm_gck_led=None, pwm_output=None, uart_rs485=None, ad5592r_spi=None, ad9833_spi=None, analyzer=None, gpio_state_pin=None, pwm1_en_pin=None, pwm2_en_pin=None, pwm3_en_pin=None, pwm4_en_pin=None, pwm5_en_pin=None, pwm6_en_pin=None, pwm7_en_pin=None, pwm8_en_pin=None, signal_out_en=None, iis_rx_en=None, iis_rx_ovfl=None, iis_rx_rst=None): if i2c_bus0: self.cat9555_0 = CAT9555(MAGNETO002002Def.CAT9555_ADDR_0, i2c_bus0) self.cat9555_1 = CAT9555(MAGNETO002002Def.CAT9555_ADDR_1, i2c_bus0) self.cat9555_2 = CAT9555(MAGNETO002002Def.CAT9555_ADDR_2, i2c_bus0) self.cat9555_3 = CAT9555(MAGNETO002002Def.CAT9555_ADDR_3, i2c_bus0) self.cat9555_4 = CAT9555(MAGNETO002002Def.CAT9555_ADDR_4, i2c_bus0) self.cat9555_5 = CAT9555(MAGNETO002002Def.CAT9555_ADDR_5, i2c_bus0) self.eeprom = CAT24C32(MAGNETO002002Def.EEPROM_DEV_ADDR, i2c_bus0) else: self.cat9555_0 = CAT9555Emulator(MAGNETO002002Def.CAT9555_ADDR_0, None, None) self.cat9555_1 = CAT9555Emulator(MAGNETO002002Def.CAT9555_ADDR_1, None, None) self.cat9555_2 = CAT9555Emulator(MAGNETO002002Def.CAT9555_ADDR_2, None, None) self.cat9555_3 = CAT9555Emulator(MAGNETO002002Def.CAT9555_ADDR_3, None, None) self.cat9555_4 = CAT9555Emulator(MAGNETO002002Def.CAT9555_ADDR_4, None, None) self.cat9555_5 = CAT9555Emulator(MAGNETO002002Def.CAT9555_ADDR_5, None, None) self.eeprom = EepromEmulator('eeprom_emulator') if ad5592r_spi: self.ad5592r = AD5592R(ad5592r_spi, MAGNETO002002Def.MVREF, 'internal', MAGNETO002002Def.ADC_GAIN, MAGNETO002002Def.DAC_GAIN) else: self.ad5592r = AD5592REmulator('ad5592r') self.dds_dev = AD9833(ad9833_spi) if ad9833_spi else AD9833Emulator() self.uart_rs485 = uart_rs485 or UARTBusEmulator( 'uart_emulator', MAGNETO002002Def.UART_SIZE) self.pwm_led = pwm_gck_led if pwm_gck_led else MIXPWMSG( 'pwm_gck_led', MAGNETO002002Def.PWM_SIZE) self.pwm_dev = pwm_output if pwm_output else MIXPWMSG( 'pwm_output', MAGNETO002002Def.PWM_SIZE) if isinstance(analyzer, basestring): analyzer = MIXFftAnalyzerSG(analyzer) elif analyzer: self.analyzer = analyzer else: self.analyzer = MIXFftAnalyzerSGEmulator( 'mix_fftanalyzer_sg_emulator') self.gpio_map = { "PWM1_EN_PIN": pwm1_en_pin or GPIOEmulator("PWM1_EN_PIN"), "PWM2_EN_PIN": pwm2_en_pin or GPIOEmulator("PWM2_EN_PIN"), "PWM3_EN_PIN": pwm3_en_pin or GPIOEmulator("PWM3_EN_PIN"), "PWM4_EN_PIN": pwm4_en_pin or GPIOEmulator("PWM4_EN_PIN"), "PWM5_EN_PIN": pwm5_en_pin or GPIOEmulator("PWM5_EN_PIN"), "PWM6_EN_PIN": pwm6_en_pin or GPIOEmulator("PWM6_EN_PIN"), "PWM7_EN_PIN": pwm7_en_pin or GPIOEmulator("PWM7_EN_PIN"), "PWM8_EN_PIN": pwm8_en_pin or GPIOEmulator("PWM8_EN_PIN"), "SIGNAL_OUT_EN": signal_out_en or GPIOEmulator("SIGNAL_OUT_EN"), "GPIO_STATE_PIN": gpio_state_pin or GPIOEmulator("GPIO_STATE_PIN"), "IIS_RX_EN": iis_rx_en or GPIOEmulator("IIS_RX_EN"), "IIS_RX_OVFL": iis_rx_ovfl or GPIOEmulator("IIS_RX_OVFL"), "IIS_RX_RST": iis_rx_rst or GPIOEmulator("IIS_RX_RST") } if led1642_bus: self.led1642 = LED1642(led1642_bus, self.gpio_map['SIGNAL_OUT_EN']) else: self.led1642 = LED1642Emulator(None, None) super(MAGNETO002002, self).__init__(self.eeprom, None, cal_table=magneto002002_calibration_info, range_table=magneto002002_range_table)
def __init__(self, i2c, analyzer=None, signal_source=None, adc_rst_pin=None, i2s_rx_en_pin=None, dac_rst_pin=None, i2s_tx_en_pin=None, sample_rate=192000, ipcore=None, eeprom_dev_addr=NegasonicDef.EEPROM_I2C_ADDR, sensor_dev_addr=NegasonicDef.SENSOR_I2C_ADDR, cal_info=None, range_table=None): assert sample_rate > 0 and sample_rate <= NegasonicDef.MAX_SAMPLING_RATE self.i2c = i2c if self.i2c is None: self.eeprom = EepromEmulator("cat24cxx_emulator") self.nct75 = NCT75Emulator("nct75_emulator") else: self.eeprom = CAT24C32(eeprom_dev_addr, i2c) self.nct75 = NCT75(sensor_dev_addr, i2c) super(NegasonicBase, self).__init__(self.eeprom, self.nct75, cal_table=cal_info, range_table=range_table) if (ipcore and not analyzer and not signal_source): if isinstance(ipcore, basestring): axi4 = AXI4LiteBus(ipcore, NegasonicDef.MIXAUT1_REG_SIZE) self.ipcore = MIXAUT1SGR(axi4) else: self.ipcore = ipcore self.analyzer = self.ipcore.analyzer self.signal_source = self.ipcore.signal_source self.adc_rst_pin = adc_rst_pin or Pin(self.ipcore.gpio, NegasonicDef.ADC_RESET_PIN) self.i2s_rx_en_pin = i2s_rx_en_pin or Pin( self.ipcore.gpio, NegasonicDef.I2S_RX_EN_PIN) self.dac_rst_pin = dac_rst_pin or Pin(self.ipcore.gpio, NegasonicDef.DAC_RESET_PIN) self.i2s_tx_en_pin = i2s_tx_en_pin or Pin( self.ipcore.gpio, NegasonicDef.I2S_TX_EN_PIN) elif (not ipcore and analyzer and signal_source): if isinstance(analyzer, basestring): axi4 = AXI4LiteBus(analyzer, NegasonicDef.ANALYZER_REG_SIZE) analyzer = MIXFftAnalyzerSG(axi4) else: self.analyzer = analyzer if isinstance(signal_source, basestring): axi4 = AXI4LiteBus(signal_source, NegasonicDef.SIGNALSOURCE_REG_SIZE) signal_source = MIXSignalSourceSG(axi4) else: self.signal_source = signal_source self.adc_rst_pin = adc_rst_pin self.i2s_rx_en_pin = i2s_rx_en_pin self.dac_rst_pin = dac_rst_pin self.i2s_tx_en_pin = i2s_tx_en_pin elif (not ipcore and not analyzer and not signal_source and not adc_rst_pin and not i2s_rx_en_pin and not dac_rst_pin and not i2s_tx_en_pin): self.analyzer = MIXFftAnalyzerSGEmulator( "mix_fftanalyzer_sg_emulator") self.signal_source = MIXSignalSourceSGEmulator( "mix_signalsource_sg_emulator") self.adc_rst_pin = Pin(None, NegasonicDef.ADC_RESET_PIN) self.i2s_rx_en_pin = Pin(None, NegasonicDef.I2S_RX_EN_PIN) self.dac_rst_pin = Pin(None, NegasonicDef.DAC_RESET_PIN) self.i2s_tx_en_pin = Pin(None, NegasonicDef.I2S_TX_EN_PIN) else: if ipcore: raise NegasonicException( "parameter 'ipcore' can not be given at same time with 'analyzer', " "'signal_source', 'adc_rst_pin', 'i2s_rx_en_pin', " "'dac_rst_pin', 'i2s_tx_en_pin'") else: raise NegasonicException( "parameter 'analyzer', 'signal_source', 'adc_rst_pin', " "'i2s_rx_en_pin', 'dac_rst_pin' and 'i2s_tx_en_pin'" " must be given at the same time") self.sample_rate = sample_rate
def __init__(self, ipcore=None, spi_adc=None, audio_analyzer=None, signal_meter=None, signal_source_0=None, signal_source_1=None, spi_dac_0=None, spi_dac_1=None, i2c_0=None, i2c_1=None, i2c_2=None, dma=None, rms_dma_channel=1): self.dma_channel = {"rms": rms_dma_channel} self.i2c_1 = i2c_1 self.i2c_2 = i2c_2 self.pcal6524 = list() if not ipcore and not spi_adc and not audio_analyzer and not signal_meter \ and not signal_source_0 and not signal_source_1 and not spi_dac_0 \ and not spi_dac_1 and not i2c_0 and not i2c_1 and not i2c_2 and not dma: self.dma = MIXDMASGEmulator('dma') self.i2c_1 = I2CBusEmulator("i2c_emulator", 256) self.i2c_2 = I2CBusEmulator("i2c_emulator", 256) self.ltc2378 = LTC2378Emulator("ltc2378") self.ad5061_0 = AD5061Emulator("ad5061") self.ad5061_1 = AD5061Emulator("ad5061") self.eeprom = EepromEmulator('m24128_emulator') self.tmp108 = TMP108(SodiumDef.TMP108_DEV_ADDR, self.i2c_1) for i in range(SodiumDef.PCAL6524_CHIP_NUM): self.pcal6524.append( PCAL6524Emulator(SodiumDef.PCAL6524_DEV_ADDR[i], self.i2c_1)) else: if ipcore and i2c_0 and i2c_1 and i2c_2 and dma and not spi_adc and not audio_analyzer \ and not signal_meter and not signal_source_0 and not signal_source_1 \ and not spi_dac_0 and not spi_dac_1: if isinstance(ipcore, basestring): self.ipcore = MIXSodiumSGR(ipcore) else: self.ipcore = ipcore self.spi_adc = self.ipcore.spi_adc self.signal_meter = self.ipcore.signal_meter self.signal_source_0 = self.ipcore.signal_source_0 self.signal_source_1 = self.ipcore.signal_source_1 self.spi_dac_0 = self.ipcore.spi_dac_0 self.spi_dac_1 = self.ipcore.spi_dac_1 elif not ipcore and i2c_0 and i2c_1 and i2c_2 and dma and spi_adc and audio_analyzer \ and signal_source_0 and signal_source_1 and spi_dac_0 and spi_dac_1: if isinstance(signal_meter, basestring): self.signal_meter = MIXSignalMeterSG(signal_meter) else: self.signal_meter = signal_meter if isinstance(spi_adc, basestring): self.spi_adc = PLSPIADC(spi_adc) else: self.spi_adc = spi_adc if isinstance(audio_analyzer, basestring): self.audio_analyzer = MIXFftAnalyzerSG(audio_analyzer) else: self.audio_analyzer = audio_analyzer if isinstance(signal_source_0, basestring): self.signal_source_0 = MIXSignalSourceSG(signal_source_0) else: self.signal_source_0 = signal_source_0 if isinstance(signal_source_1, basestring): self.signal_source_1 = MIXSignalSourceSG(signal_source_1) else: self.signal_source_1 = signal_source_1 if isinstance(spi_dac_0, basestring): self.spi_dac_0 = PLSPIDAC(spi_dac_0) else: self.spi_dac_0 = spi_dac_0 if isinstance(spi_dac_1, basestring): self.spi_dac_1 = PLSPIDAC(spi_dac_1) else: self.spi_dac_1 = spi_dac_1 else: raise SodiumException( "Not allowed to use both aggregated IP and " "spi_adc,audio_analyzer,signal_meter," "signal_source_0,signal_source_1,spi_dac_0,spi_dac_1 at the same time" ) self.dma = dma self.ad5061_0 = AD506x(SodiumDef.AD5061_OUTPUT_RANGE[0], SodiumDef.AD5061_OUTPUT_RANGE[1], SodiumDef.AD5061_SAMPLE_RATE, SodiumDef.AD5061_SCK_SPEED, self.signal_source_0, self.spi_dac_0) self.ad5061_1 = AD506x(SodiumDef.AD5061_OUTPUT_RANGE[0], SodiumDef.AD5061_OUTPUT_RANGE[1], SodiumDef.AD5061_SAMPLE_RATE, SodiumDef.AD5061_SCK_SPEED, self.signal_source_1, self.spi_dac_1) self.ltc2378 = LTC2378(self.signal_meter, self.spi_adc, None, SodiumDef.LTC2378_VOLT_RANGE) self.eeprom = M24128(SodiumDef.M24128_DEV_ADDR, self.i2c_1) self.pcal6524 = list() for i in range(SodiumDef.PCAL6524_CHIP_NUM): self.pcal6524.append( PCAL6524(SodiumDef.PCAL6524_DEV_ADDR[i], self.i2c_1)) self.tmp108 = TMP108(SodiumDef.TMP108_DEV_ADDR, self.i2c_2) self.waveforms = {0: self.ad5061_0, 1: self.ad5061_1} super(Sodium, self).__init__(self.eeprom, self.tmp108)