Commit 471d6db9 authored by Federico Vaga's avatar Federico Vaga

tst: add trigger threshold tests

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 3d3786f1
......@@ -4,7 +4,8 @@ SPDX-FileCopyrightText: 2020 CERN
"""
import pytest
from PyAdcLib import PyAdcConf, PyFmcAdc100m14b4ch, timeval
from PyAdcLib import PyAdcConf, PyFmcAdc100m14b4ch, timeval, PyAdcAbstract, \
adc_buffer_get_sample
class TestAdcTriggerSoftware(object):
......@@ -48,3 +49,121 @@ class TestAdcTriggerSoftware(object):
adc_simple.trigger_fire()
adc_simple.retrieve_config(conf)
assert conf.value_get(PyAdcConf.ADC_CONF_BRD_STATE_MACHINE_STATUS) == adc_simple.ADC_CONF_100M14B4CHA_FSM_STATE_IDLE
class TestAdcTriggerThreshold(object):
@pytest.mark.parametrize("channel", range(4))
def test_adc_trg_thr_disable(self, adc_simple, channel):
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_TRG_THR, channel)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_THRESHOLD, 0x1FFF)
adc_simple.apply_config(conf, 0)
buf = adc_simple.request_buffer(3, None, 0) # adc_simple does 3
adc_simple.pattern_data = 0
adc_simple.acq_start(PyFmcAdc100m14b4ch.ADC_F_FLUSH, timeval(0, 0))
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(1,0))
adc_simple.pattern_data = 0x3FFF
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(1,0))
adc_simple.pattern_data = 0
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(1,0))
@pytest.mark.parametrize("channel", range(4))
@pytest.mark.parametrize("threshold", [0xFFC, ])
def test_adc_trg_thr_positive(self, adc_simple, channel, threshold):
"""The trigger threshold fire on positive slopes.
Rembember that the ADC raw data is shifted by 2, so we use a
threshold that does not use the last two bits"""
min_value = 0
adc_simple.pattern_data = min_value
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_TRG_THR, channel)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_ENABLE, 1)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_POLARITY,
PyAdcAbstract.ADC_TRG_POL_POS)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_DELAY, 0)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_THRESHOLD, threshold)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_HYSTERESIS, 0)
adc_simple.apply_config(conf, 0)
adc_simple.acq_start(PyFmcAdc100m14b4ch.ADC_F_FLUSH, timeval(0, 0))
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
adc_simple.pattern_data = (threshold >> 2) - 1
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
adc_simple.pattern_data = min_value
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
value = (threshold >> 2) + 1
adc_simple.pattern_data = value
adc_simple.acq_poll(0, timeval(0, 1000))
buf = adc_simple.request_buffer(3, None, 0)
adc_simple.fill_buffer(buf, 0, timeval(10, 0))
assert buf.contents.nsamples == 3
assert adc_buffer_get_sample(buf, channel, 0) == min_value, \
buf.contents.data[:3*4]
assert adc_buffer_get_sample(buf, channel, 1) == value << 2, \
buf.contents.data[:3*4]
assert adc_buffer_get_sample(buf, channel, 2) == value << 2, \
buf.contents.data[:3*4]
adc_simple.acq_start(PyFmcAdc100m14b4ch.ADC_F_FLUSH, timeval(0, 0))
adc_simple.pattern_data = min_value
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
@pytest.mark.parametrize("channel", range(4))
@pytest.mark.parametrize("threshold", [0xFFC, ])
def test_adc_trg_thr_negative(self, adc_simple, channel, threshold):
"""The trigger threshold fire on negative slopes.
Rembember that the ADC raw data is shifted by 2, so we use a
threshold that does not use the last two bits"""
max_value = 0x1FFF
adc_simple.pattern_data = max_value
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_TRG_THR, channel)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_ENABLE, 1)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_POLARITY,
PyAdcAbstract.ADC_TRG_POL_NEG)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_DELAY, 0)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_THRESHOLD, threshold)
conf.value_set(PyAdcConf.ADC_CONF_TRG_THR_HYSTERESIS, 0)
adc_simple.apply_config(conf, 0)
adc_simple.acq_start(PyFmcAdc100m14b4ch.ADC_F_FLUSH, timeval(0, 0))
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
adc_simple.pattern_data = (threshold >> 2) + 1
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
adc_simple.pattern_data = max_value
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
value = (threshold >> 2) - 1
adc_simple.pattern_data = value
adc_simple.acq_poll(0, timeval(0, 1000))
buf = adc_simple.request_buffer(3, None, 0)
adc_simple.fill_buffer(buf, 0, timeval(10, 0))
assert buf.contents.nsamples == 3
assert adc_buffer_get_sample(buf, channel, 0) == max_value << 2, \
buf.contents.data[:3*4]
assert adc_buffer_get_sample(buf, channel, 1) == value << 2, \
buf.contents.data[:3*4]
assert adc_buffer_get_sample(buf, channel, 2) == value << 2, \
buf.contents.data[:3*4]
adc_simple.acq_start(PyFmcAdc100m14b4ch.ADC_F_FLUSH, timeval(0, 0))
adc_simple.pattern_data = max_value
with pytest.raises(OSError):
adc_simple.acq_poll(0, timeval(2,0))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment