def __init__(self, intr_pin, intr_ack_gpio):
        """Create a new _MBInterruptEvent object

        Parameters
        ----------
        intr_pin : str
            Name of the interrupt pin for the Microblaze.
        intr_ack_gpio : int
            Number of the GPIO pin used to clear the interrupt.

        """
        self.interrupt = Interrupt(intr_pin)
        self.gpio = GPIO(GPIO.get_gpio_pin(intr_ack_gpio), "out")
Esempio n. 2
0
    def __init__(self, index):
        """Create a new Switch object.

        Parameters
        ----------
        index : int
            The index of the onboard switches, from 0 to 3.

        """
        if Switch._mmio is None:
            Switch._mmio = MMIO(PL.ip_dict["SEG_swsleds_gpio_Reg"][0], 512)
        self.index = index
        self.interrupt = None
        try:
            self.interrupt = Interrupt('swsleds_gpio/ip2intc_irpt')
            # Enable interrupts
            Switch._mmio.write(0x11C, 0x80000000)
            Switch._mmio.write(0x128, 0x00000001)
        except ValueError as err:
            print(err)
Esempio n. 3
0
    def __init__(self, index):
        """Create a new Button object.

        Parameters
        ----------
        index : int
            The index of the push-buttons, from 0 to 3.

        """
        if Button._mmio is None:
            Button._mmio = MMIO(PL.ip_dict["SEG_btns_gpio_Reg"][0], 512)
        self.index = index
        self.interrupt = None
        try:
            self.interrupt = Interrupt('btns_gpio/ip2intc_irpt')
            # Enable interrupts
            Button._mmio.write(0x11C, 0x80000000)
            Button._mmio.write(0x128, 0x00000001)
        except ValueError:
            pass
Esempio n. 4
0
    def __init__(self, index):
        """Create a new Button object.

        Parameters
        ----------
        index : int
            The index of the push-buttons, from 0 to 1.

        """
        if Button._mmio is None:
            base_addr = PL.ip_dict["axi_gpio_0_button"]["phys_addr"]
            Button._mmio = MMIO(base_addr, 512)
        self.index = index
        self.interrupt = None
        try:
            self.interrupt = Interrupt('axi_gpio_0_button/ip2intc_irpt')
            # Enable interrupts
            Button._mmio.write(0x11C, 0x80000000)
            Button._mmio.write(0x128, 0x00000001)
        except ValueError:
            pass
class MBInterruptEvent:
    """The class provides and asyncio Event-like interface to
    the interrupt subsystem for a Microblaze. The event is set by
    raising an interrupt and cleared using the clear function.

    Typical use is to call clear prior to sending a request to
    the Microblaze and waiting in a loop until the response is received.
    This order of operations will avoid race conditions between the
    Microblaze and the host code.

    """
    def __init__(self, intr_pin, intr_ack_gpio):
        """Create a new _MBInterruptEvent object

        Parameters
        ----------
        intr_pin : str
            Name of the interrupt pin for the Microblaze.
        intr_ack_gpio : int
            Number of the GPIO pin used to clear the interrupt.

        """
        self.interrupt = Interrupt(intr_pin)
        self.gpio = GPIO(GPIO.get_gpio_pin(intr_ack_gpio), "out")

    @asyncio.coroutine
    def wait(self):
        """Coroutine to wait until the event is set by an interrupt.

        """
        yield from self.interrupt.wait()

    def clear(self):
        """Clear the interrupt and reset the event. Resetting the event
        should be done before sending a request that will be acknowledged
        interrupts.

        """
        self.gpio.write(1)
        self.gpio.write(0)
Esempio n. 6
0
class Switch(object):
    """This class controls the onboard switches.

    Attributes
    ----------
    index : int
        Index of the onboard switches, starting from 0.

    """
    _mmio = None

    def __init__(self, index):
        """Create a new Switch object.

        Parameters
        ----------
        index : int
            The index of the onboard switches, from 0 to 3.

        """
        if Switch._mmio is None:
            base_addr = PL.ip_dict["switches_gpio"]["phys_addr"]
            Switch._mmio = MMIO(base_addr, 512)
        self.index = index
        self.interrupt = None
        try:
            self.interrupt = Interrupt('switches_gpio/ip2intc_irpt')
            # Enable interrupts
            Switch._mmio.write(0x11C, 0x80000000)
            Switch._mmio.write(0x128, 0x00000001)
        except ValueError as err:
            print(err)

    def read(self):
        """Read the current value of the switch.

        Returns
        -------
        int
            Either 0 if the switch is off or 1 if the switch is on

        """
        curr_val = Switch._mmio.read()
        return (curr_val & (1 << self.index)) >> self.index

    @asyncio.coroutine
    def wait_for_value_async(self, value):
        """Wait for the switch to be set to a particular position

        Parameters
        ----------
        value: int
            1 for the switch up and 0 for the switch down

        This function is an asyncio coroutine

        """
        if self.interrupt is None:
            raise RuntimeError('Interrupts not available in this Overlay')
        while self.read() != value:
            yield from self.interrupt.wait()
            if Switch._mmio.read(0x120) & 0x1:
                Switch._mmio.write(0x120, 0x00000001)

    def wait_for_value(self, value):
        """Wait for the switch to be set to a particular position

        Parameters
        ----------
        value: int
            1 for the switch up and 0 for the switch down

        This function wraps the coroutine form so the asyncio
        event loop will run until the function returns

        """
        if self.interrupt is None:
            raise RuntimeError('Interrupts not available in this Overlay')
        loop = asyncio.get_event_loop()
        loop.run_until_complete(
            asyncio.ensure_future(self.wait_for_value_async(value)))
class Button(object):
    """This class controls the onboard push-buttons.

    Attributes
    ----------
    index : int
        Index of the push-buttons, starting from 0.

    """
    _mmio = None

    def __init__(self, index):
        """Create a new Button object.

        Parameters
        ----------
        index : int
            The index of the push-buttons, from 0 to 3.

        """
        if Button._mmio is None:
            base_addr = PL.ip_dict["btns_gpio"]["phys_addr"]
            Button._mmio = MMIO(base_addr, 512)
        self.index = index
        self.interrupt = None
        try:
            self.interrupt = Interrupt('btns_gpio/ip2intc_irpt')
            # Enable interrupts
            Button._mmio.write(0x11C, 0x80000000)
            Button._mmio.write(0x128, 0x00000001)
        except ValueError:
            pass

    def read(self):
        """Read the current value of the button.

        Returns
        -------
        int
            Either 1 if the button is pressed or 0 otherwise

        """
        curr_val = Button._mmio.read()
        return (curr_val & (1 << self.index)) >> self.index

    @asyncio.coroutine
    def wait_for_value_async(self, value):
        """Wait for the button to be pressed or released

        Parameters
        ----------
        value: int
            1 to wait for press or 0 to wait for release

        This function is an asyncio coroutine

        """
        if self.interrupt is None:
            raise RuntimeError('Interrupts not available in this Overlay')
        while self.read() != value:
            yield from self.interrupt.wait()
            if Button._mmio.read(0x120) & 0x1:
                Button._mmio.write(0x120, 0x00000001)

    def wait_for_value(self, value):
        """Wait for the button to be pressed or released

        Parameters
        ----------
        value: int
            1 to wait for press or 0 to wait for release

        This function wraps the coroutine form so the asyncio
        event loop will run until the function returns

        """
        if self.interrupt is None:
            raise RuntimeError('Interrupts not available in this Overlay')
        loop = asyncio.get_event_loop()
        loop.run_until_complete(
            asyncio.ensure_future(self.wait_for_value_async(value)))