QueueInterrupt

class

An queued input pin interrupt function callback handler This class represents an input pin on mono, and provides up to 3 different callback handler functions. You can installed callback function for rising, falling or both edges.

Queued interrupts

In Mono framework a queued interrupt is handled inside the normal execution context, and not the hardware interrupt routine. In embedded programming it is good practice not to do any real work, inside the hardware interrupt routine. Instead the best practice method is to set a signal flag, and handled the event in a run loop.

QueueInterrupt does this for you. The rise, fall and change callback are all executed by the default mono run loop (AppRunLoop) You can safely do heavy calculations or use slow I/O in the callback routines you assign to QueueInterrupt!

Latency

The run loop might handle the interrupt callback some time after it occur, if it is busy doing other stuff. THerefore you cannot expect to have your callback executed the instant the interrupt fires. (If you need that use DirectInterrupt) QueueInterrupt holds the latest interrupt trigger timestamp, to help you determine the latency between the actual interrupt and you callback. Also, many interrupt triggering signal edges might occur, before the run loop executes you handler. The timestamp only shows the latest one.

Public Functions

QueueInterrupt::QueueInterrupt(PinName inputPinName, PinMode mode)

Assign a queued inetrrupt handler to a physical pin

Parameters
  • inputPinName -

    The actual pin to listen on (must be PORT0 - PORT15)

  • mode -

    OPTIONAL: The pin mode, default is Hi-Impedance input.

void QueueInterrupt::DeactivateUntilHandled(bool deactive)

Set this property to true, to turn off incoming interrupts while waiting for the run loop to finish process a pending interrupt.

If you want to do heavy calculations or loading in your interrupt function, you might want to not queue up new interrupts while you process a previous one.

Parameters
  • deactive -

    OPTIONAL: Set this to false, to not disable interrupts while processing. Default is true

bool QueueInterrupt::IsInterruptsWhilePendingActive()
const

Get the state of the DeactivateUntilHandled property. If true the hardware interrupt is deactivated until the handler has run. If false (the default when constructing the object), all interrupt are intercepted, and will be handled. This means the handler can be executed two times in row.

Return
true if incomming interrupt are displaed, until previous is handled.

void QueueInterrupt::setDebouncing(bool active)

Enable/Disable interrupt de-bounce.

Switches state change might cause multiple interrupts to fire, or electrostatic discharges might cause nano seconds changes to I/O lines. The debounce ensures the interrupt will only be triggered, on sane button presses.

void QueueInterrupt::setDebounceTimeout(int timeUs)

Change the timeout for the debounce mechanism.

Parameters
  • timeUs -

    The time from interrupt to the signal is considered stable, in micro-seconds

void mono::QueueInterrupt::rise(void (*fptr)(void))

Attach a function to call when a rising edge occurs on the input

Parameters
  • fptr -

    A pointer to a void function, or 0 to set as none

template <typename T>
void mono::QueueInterrupt::rise(T * tptr, void(T::*)(void) mptr)

Attach a member function to call when a rising edge occurs on the input

Parameters
  • tptr -

    pointer to the object to call the member function on

  • mptr -

    pointer to the member function to be called

void mono::QueueInterrupt::fall(void (*fptr)(void))

Attach a function to call when a falling edge occurs on the input

Parameters
  • fptr -

    A pointer to a void function, or 0 to set as none

template <typename T>
void mono::QueueInterrupt::fall(T * tptr, void(T::*)(void) mptr)

Attach a member function to call when a falling edge occurs on the input

Parameters
  • tptr -

    pointer to the object to call the member function on

  • mptr -

    pointer to the member function to be called

uint32_t QueueInterrupt::FallTimeStamp()

On fall interrupts, this is the µSec. ticker timestamp for the falling edge inetrrupt. You can use this to calculate the time passed from the interrupt occured, to the time you process it in the application run loop.

Return
The ticker time of the falling edge in micro seconds

uint32_t QueueInterrupt::RiseTimeStamp()

On rise interrupts, this is the µSec. ticker timestamp for the rising edge inetrrupt. You can use this to calculate the time passed from the interrupt occured, to the time you process it in the application run loop.

Return
The ticker time of the rising edge in micro seconds

bool QueueInterrupt::Snapshot()

The pin value at the moment the H/W interrupt triggered The callback might be executed some time after the actual inetrrupt occured. THis method return the pin state at the moment of the interrupt.

Return
The pin state, at the time of the interrupt

bool QueueInterrupt::willInterruptSleep()
const

Interrupt will abort sleep mode to run handler.

If interrupt fires during sleep mode, Mono will wake up to service the handler in the run loop

void QueueInterrupt::setInterruptsSleep(bool wake)

Set if this interrupt will wake Mono from sleep.

Set to true to wake from sleep and continue the run loop upon interrupts.

Parameters
  • wake -

    true to enabled wake-from-sleep

template <typename T>
void mono::QueueInterrupt::change(T * tptr, void(T::*)(void) mptr)

Attach a member function to call when a rising or falling edge occurs on the input

Parameters
  • tptr -

    pointer to the object to call the member function on

  • mptr -

    pointer to the member function to be called

Protected Functions

virtual void QueueInterrupt::taskHandler()

This is the method that gets called by the run loop.

NOTE that this is not an interrupt function, you can do stuff that take some time.