Interrupts

This sections describes the interface for interacting with hardware interrupt sources: their configuration and definition of handlers to be called when an interrupt is triggered.

General interface

There two classes in VSlib implementing the Interrupt interface: TimerInterrupt and PeripheralInterrupt. Those two classes thus require a unique name to identify the interrupt, require a pointer to the owning (templated) user-defined Converter class, and a callback.

The callback function (handler) is expected to have the following signature: void(Converter&), so that the handler has the context of Components and other objects defined by your Converter instance.

There are also two methods used to enable and disable interrupt handling: start and stop, respectively. They are overwritten by each implementation of the interface to perform actions necessary to enable/disable the relevant interrupt handling.

TimerInterrupt

TimerInterrupt defines an interrupt to be called every defined number of microseconds. The constructor takes four parameters: a unique std::string name, a pointer to the owning parent (assumed to be your own class defining the Converter), the delay in microseconds, and a callback function.

The clock used to trigger this interrupt is the single CPU clock, and is not synchronised (nor synchronisable) with the programmable logic (PL). The main use of this class is all testing purposes when interactions with the PL is not desired.

For more details regarding the API, see the API documentation for TimerInterrupt.

Usage example

#include "timerInterrupt.h"
#include "converter.h"
#include "rootComponent.h"

class Converter : public vslib::RootComponent
{
  public:
    Converter() noexcept
    : vslib::RootComponent("example"),
      interrupt_1("cpu_timer", this, 10.0, RTTask) // 10 microseconds
    {
        // initialize all your objects that need initializing
    }

    // Define your public Components here
    vslib::TimerInterrupt<Converter> interrupt_1;

    void init() override
    {
        interrupt_t.start(); // enables the handling of the interrupt
    }

    //! Callback used when interrupt_1 triggers
    static void RTTask(Converter& converter)
    {
        // perform real-time actions expected when interrupt_1 is triggered
    }

    private:
        int m_interrupt_id;
};

PeripheralInterrupt

PeripheralInterrupt defines an interrupt to be called based on the trigger located in the programmable logic (PL). The constructor takes five parameters: a unique std::string name, a pointer to the owning parent (assumed to be your own class defining the Converter), unique interrupt ID corresponding to the interrupt in the PL, an interrupt priority (of type vslib::InterruptPriority), and a callback function. There are three possible InterruptPriority levels: low, medium, and high.

For more details regarding the API, see the API documentation for PeripheralInterrupt.

Usage example

#include "peripheralInterrupt.h"
#include "converter.h"
#include "rootComponent.h"

class Converter : public vslib::RootComponent
{
  public:
    Converter() noexcept
    : vslib::RootComponent("example"),
      m_interrupt_id{121 + 0},   // interrupt ID
      interrupt_1("AuroraLink", this, m_interrupt_id, vslib::InterruptPriority::high, RTTask)
    {
        // initialize all your objects that need initializing
    }

    // Define your public Components here
    vslib::PeripheralInterrupt<Converter> interrupt_1;

    void init() override
    {
        interrupt_t.start(); // enables the handling of the interrupt
    }

    //! Callback used when interrupt_1 triggers
    static void RTTask(Converter& converter)
    {
        // perform real-time actions expected when interrupt_1 is triggered
    }

    private:
        int m_interrupt_id;
};