QueueInterrupt¶
-
class
mono::
QueueInterrupt
¶ 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.Inherits from InterruptIn, mono::IRunLoopTask
Public Functions
-
QueueInterrupt
(PinName inputPinName = NC, PinMode mode = PullNone)¶ 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
DeactivateUntilHandled
(bool deactive = true)¶ 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
OPTIONAL
-Set this to false, to not disable interrupts while processing. Default is
true
-
bool
IsInterruptsWhilePendingActive
() const¶ Get the state of the DeactivateUntilHandled property. If
true
the hardware interrupt is deactivated until the handler has run. Iffalse
(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
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
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
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
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
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
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
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
- template <typename T>
-
void mono::QueueInterrupt::change(T * tptr, void(T::*)(void) mptr)
Attach a function to call when a rising or falling edge occurs on the input
- Parameters
fptr
-A pointer to a void function, or 0 to set as noneAttach a member function to call when a rising or falling edge occurs on the input
tptr
-pointer to the object to call the member function on
mptr
-pointer to the member function to be called
Protected Functions
-
virtual void
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.
-