Commit 895b138a authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by bliss administrator

Systematically check IRQ handler act. on each board IRQ config change

parent dc8ac670
......@@ -1825,6 +1825,7 @@ class BaseCard:
self.__log = logging.getLogger("P201." + address)
self.__address = address
self.__dev = None
self.__interrupt_buffer_size = 0
self.connect(address)
def __str__(self):
......@@ -1953,9 +1954,9 @@ class BaseCard:
"""
self.__ioctl(CT2_IOC_DEVRST)
def enable_interrupts(self, fifo_size):
def __enable_interrupts(self, fifo_size):
"""
Enable card interrupts with the given number of FIFO entries
Enables driver IRQ handler with the given number of FIFO entries
:param fifo_size: FIFO depth (number of FIFO entries)
:type fifo_size: int
......@@ -1964,12 +1965,35 @@ class BaseCard:
"""
self.__ioctl(CT2_IOC_EDINT, fifo_size)
def disable_interrupts(self):
def __disable_interrupts(self):
"""
Disables the card interrupts
Disables the driver IRQ handler
"""
self.__ioctl(CT2_IOC_DDINT)
def __source_irq_reg_name(self, reg):
return "SOURCE_IT_" + reg
def __read_source_irq_reg(self, reg):
"""
Reads the source IRQ register
"""
return self.read_reg(self.__source_irq_reg_name(reg))
def __write_source_irq_reg(self, reg, val):
"""
Writes on source IRQ register and enable/disable IRQ handler
"""
# Ensure that the kernel will handle IRQs before enabling ...
if val:
self.__enable_interrupts(self.__interrupt_buffer_size)
self.write_reg(self.__source_irq_reg_name(reg), val)
# Check if IRQ handler can be disabled
if not val:
other = "A" if reg == "B" else "B"
if not self.__read_source_irq_reg(other):
self.__disable_interrupts()
def acknowledge_interrupt(self):
"""
Acknowledge interrupt.
......@@ -2407,7 +2431,7 @@ class BaseCard:
:rtype: dict<int: :class:`TriggerInterrupt`>
"""
result = {}
register = self.read_reg("SOURCE_IT_A")
register = self.__read_source_irq_reg("A")
mask = (1<<0) | (1<<16)
for channel in self.CHANNELS:
reg = (register >> (channel-1)) & mask
......@@ -2430,11 +2454,11 @@ class BaseCard:
register = 0
for channel, triggers in channels_triggers.items():
register |= triggers.value << (channel-1)
self.write_reg("SOURCE_IT_A", register)
self.__write_source_irq_reg("A", register)
def __get_source_it_b(self):
counters = {}
register = self.read_reg("SOURCE_IT_B")
register = self.__read_source_irq_reg("B")
for counter in self.COUNTERS:
counters[counter] = (register & 1 << (counter-1)) != 0
dma, fifo, error = (register & (1 << 12)) != 0
......@@ -2452,10 +2476,10 @@ class BaseCard:
register = 0
for counter in counters:
register |= 1 << (counter-1)
register |= (dma and 1 or 0) << 12
register |= (fifo_half_full and 1 or 0) << 13
register |= (error and 1 or 0) << 14
self.write_reg("SOURCE_IT_B", register)
register |= (1 << 12) if dma else 0
register |= (1 << 13) if fifo_half_full else 0
register |= (1 << 14) if error else 0
self.__write_source_irq_reg("B", register)
def get_counters_interrupts(self):
"""
......@@ -2527,11 +2551,8 @@ class BaseCard:
"""
# First, make sure we leave bits 0 to 11 unchanged
# (these correspond to counter stop trigerred interrupts)
register = self.read_reg("SOURCE_IT_B") & 0xFFF
register |= (dma and 1 or 0) << 12
register |= (fifo_half_full and 1 or 0) << 13
register |= (error and 1 or 0) << 14
self.write_reg("SOURCE_IT_B", register)
counters = self.get_counters_interrupts()
self.__set_source_it_b(counters, dma, fifo_half_full, error)
def get_interrupts(self):
"""
......@@ -3363,7 +3384,7 @@ def create_and_configure_card(config_or_name):
card_config = config_or_name
card = create_card_from_configure(card_config)
card.request_exclusive_access()
card.disable_interrupts()
card.set_interrupts()
card.reset_FIFO_error_flags()
card.reset()
card.software_reset()
......@@ -3400,8 +3421,6 @@ def configure_card(card, config):
fifo_hf_int = __get(config, 'fifo half full interrupt', False)
error_int = __get(config, 'error interrupt', False)
interrupt_buffer_size = __get(config, 'interrupt buffer size', 0)
ct_cfgs = {}
ct_latch_srcs = {}
ct_sw_enables = {}
......@@ -3487,14 +3506,8 @@ def configure_card(card, config):
card.set_counters_software_enable_disable(ct_sw_enables)
card.set_counters_comparators_values(ct_cmpts)
enable_interrupts = any(list(ct_ints.values()) + [dma_int, fifo_hf_int, error_int,
interrupt_buffer_size])
card.set_interrupts(ch_ints, ct_ints, dma_int, fifo_hf_int, error_int)
if enable_interrupts:
interrupt_buffer_size = interrupt_buffer_size and interrupt_buffer_size or 100
card.enable_interrupts(interrupt_buffer_size)
def main():
#logging.basicConfig(level=logging.DEBUG)
......
......@@ -301,10 +301,6 @@ class CT2Device(BaseCT2Device):
# the acquisition has finished without having to query its status
int_counters.append(point_nb_ct)
# first, be sure interrupts are anabled
interrupt_buffer_size = 0
card.enable_interrupts(interrupt_buffer_size)
# make master enabled by software
card.enable_counters_software((timer_ct, point_nb_ct))
......
......@@ -27,7 +27,7 @@ from bliss.controllers.ct2 import CtClockSrc, CtGateSrc, CtHardStartSrc, CtHardS
def configure(device, channels):
device.request_exclusive_access()
device.disable_interrupts()
device.set_interrupts()
device.reset()
device.software_reset()
......
......@@ -30,11 +30,10 @@ from bliss.controllers.ct2 import CtClockSrc, CtGateSrc, CtHardStartSrc, CtHardS
def configure(device, channels):
device.request_exclusive_access()
device.disable_interrupts()
device.set_interrupts()
device.reset()
device.software_reset()
device.reset_FIFO_error_flags()
device.enable_interrupts(100)
# -------------------------------------------------------------------------
# Channel configuration (could be loaded from beacon, for example. We
......@@ -175,7 +174,7 @@ def main():
sys.excepthook(*sys.exc_info())
finally:
print ("Clean up!")
device.disable_interrupts()
device.set_interrupts()
device.reset()
device.software_reset()
device.relinquish_exclusive_access()
......
......@@ -238,8 +238,6 @@ def go(card):
poll = select.epoll()
poll.register(card, select.EPOLLIN | select.EPOLLHUP | select.EPOLLERR)
card.enable_interrupts(100)
card.set_interrupts(counters=counter_interrupts,
dma=True, fifo_half_full=True, error=True)
......@@ -309,7 +307,6 @@ def handle_event(card, fifo, fd, event):
def clean_up(card):
card.set_interrupts()
card.disable_interrupts()
card.disable_counters_software(card.COUNTERS)
......
......@@ -46,7 +46,7 @@ def main():
sys.stdout.flush()
p201 = P201Card()
p201.disable_interrupts()
p201.set_interrupts()
p201.request_exclusive_access()
p201.reset()
p201.software_reset()
......
......@@ -84,10 +84,9 @@ def main():
p201 = P201Card()
p201.request_exclusive_access()
p201.disable_interrupts()
p201.set_interrupts()
p201.reset()
p201.software_reset()
p201.enable_interrupts(100)
poll = select.epoll()
poll.register(p201, select.EPOLLIN | select.EPOLLHUP | select.EPOLLERR)
......@@ -117,7 +116,7 @@ def main():
print("\rCtrl-C pressed. Bailing out!")
finally:
print ("Clean up!")
p201.disable_interrupts()
p201.set_interrupts()
p201.reset()
p201.software_reset()
......
......@@ -126,11 +126,10 @@ def main():
p201 = P201Card()
p201.request_exclusive_access()
p201.disable_interrupts()
p201.set_interrupts()
p201.reset()
p201.software_reset()
p201.reset_FIFO_error_flags()
p201.enable_interrupts(100)
poll = select.epoll()
poll.register(p201, select.EPOLLIN | select.EPOLLHUP | select.EPOLLERR)
......@@ -165,7 +164,7 @@ def main():
sys.excepthook(*sys.exc_info())
finally:
print ("Clean up!")
p201.disable_interrupts()
p201.set_interrupts()
p201.reset()
p201.software_reset()
......
......@@ -258,7 +258,7 @@ class CT2Window(Qt.QMainWindow):
if card is None:
return
card.request_exclusive_access()
card.disable_interrupts()
card.set_interrupts()
card.reset_FIFO_error_flags()
card.reset()
card.software_reset()
......
......@@ -214,11 +214,10 @@ def test_p201():
chain = AcquisitionChain()
p201_device = P201()
p201_device.request_exclusive_access()
p201_device.disable_interrupts()
p201_device.set_interrupts()
p201_device.reset()
p201_device.software_reset()
p201_device.reset_FIFO_error_flags()
p201_device.enable_interrupts(100)
p201_device.set_clock(Clock.CLK_100_MHz)
p201_master = P201AcquisitionMaster(p201_device,nb_points=100000,acq_expo_time=50e-6)
p201_counters = P201AcquisitionDevice(p201_device,nb_points=100000,acq_expo_time=50e-6,
......@@ -382,11 +381,10 @@ def test_emotion_p201():
p201_device = P201()
p201_device.request_exclusive_access()
p201_device.disable_interrupts()
p201_device.set_interrupts()
p201_device.reset()
p201_device.software_reset()
p201_device.reset_FIFO_error_flags()
p201_device.enable_interrupts(100)
p201_device.set_clock(Clock.CLK_100_MHz)
p201_master = P201AcquisitionMaster(p201_device,nb_points=10,acq_expo_time=1e-3)
p201_counters = P201AcquisitionDevice(p201_device,nb_points=10,acq_expo_time=1e-3,
......
......@@ -68,12 +68,12 @@ class TestP201(unittest.TestCase):
def setUp(self):
self.p201 = ct2.P201Card()
self.p201.disable_interrupts()
self.p201.set_interrupts()
self.p201.reset()
self.p201.software_reset()
def tearDown(self):
self.p201.disable_interrupts()
self.p201.set_interrupts()
self.p201.reset()
self.p201.software_reset()
......
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