|
|
|
|
|
|
|
|
// default way to use EventResponder. Calls from yield() allow use |
|
|
// default way to use EventResponder. Calls from yield() allow use |
|
|
// of Arduino libraries, String, Serial, etc. |
|
|
// of Arduino libraries, String, Serial, etc. |
|
|
void attach(EventResponderFunction function, uint8_t priority=128) { |
|
|
void attach(EventResponderFunction function, uint8_t priority=128) { |
|
|
detach(); |
|
|
|
|
|
|
|
|
bool irq = disableInterrupts(); |
|
|
|
|
|
detachNoInterrupts(); |
|
|
_function = function; |
|
|
_function = function; |
|
|
_type = EventTypeYield; |
|
|
_type = EventTypeYield; |
|
|
|
|
|
enableInterrupts(irq); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Attach a function to be called immediately. This provides the |
|
|
// Attach a function to be called immediately. This provides the |
|
|
// fastest possible response, but your function must be carefully |
|
|
// fastest possible response, but your function must be carefully |
|
|
// designed. |
|
|
// designed. |
|
|
void attachImmediate(EventResponderFunction function) { |
|
|
void attachImmediate(EventResponderFunction function) { |
|
|
detach(); |
|
|
|
|
|
|
|
|
bool irq = disableInterrupts(); |
|
|
|
|
|
detachNoInterrupts(); |
|
|
_function = function; |
|
|
_function = function; |
|
|
_type = EventTypeImmediate; |
|
|
_type = EventTypeImmediate; |
|
|
|
|
|
enableInterrupts(irq); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Attach a function to be called from a low priority interrupt. |
|
|
// Attach a function to be called from a low priority interrupt. |
|
|
|
|
|
|
|
|
// interrupts, this allow fast interrupt-based response, but with less |
|
|
// interrupts, this allow fast interrupt-based response, but with less |
|
|
// disruption to other libraries requiring their own interrupts. |
|
|
// disruption to other libraries requiring their own interrupts. |
|
|
void attachInterrupt(EventResponderFunction function, uint8_t priority=128) { |
|
|
void attachInterrupt(EventResponderFunction function, uint8_t priority=128) { |
|
|
detach(); |
|
|
|
|
|
|
|
|
bool irq = disableInterrupts(); |
|
|
|
|
|
detachNoInterrupts(); |
|
|
_function = function; |
|
|
_function = function; |
|
|
_type = EventTypeInterrupt; |
|
|
_type = EventTypeInterrupt; |
|
|
SCB_SHPR3 |= 0x00FF0000; // configure PendSV, lowest priority |
|
|
SCB_SHPR3 |= 0x00FF0000; // configure PendSV, lowest priority |
|
|
|
|
|
enableInterrupts(irq); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Attach a function to be called as its own thread. Boards not running |
|
|
// Attach a function to be called as its own thread. Boards not running |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do not call any function. The user's program must occasionally check |
|
|
// Do not call any function. The user's program must occasionally check |
|
|
// whether the event has occurred, or use one of the wait functions. |
|
|
// whether the event has occurred, or use one of the wait functions. |
|
|
void detach(); |
|
|
|
|
|
|
|
|
void detach() { |
|
|
|
|
|
bool irq = disableInterrupts(); |
|
|
|
|
|
detachNoInterrupts(); |
|
|
|
|
|
enableInterrupts(irq); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Trigger the event. An optional status code and data may be provided. |
|
|
// Trigger the event. An optional status code and data may be provided. |
|
|
// The code triggering the event does NOT control which of the above |
|
|
// The code triggering the event does NOT control which of the above |
|
|
|
|
|
|
|
|
operator bool() { return _triggered; } |
|
|
operator bool() { return _triggered; } |
|
|
protected: |
|
|
protected: |
|
|
void triggerEventNotImmediate(); |
|
|
void triggerEventNotImmediate(); |
|
|
|
|
|
void detachNoInterrupts(); |
|
|
int _status = 0; |
|
|
int _status = 0; |
|
|
EventResponderFunction _function = nullptr; |
|
|
EventResponderFunction _function = nullptr; |
|
|
void *_data = nullptr; |
|
|
void *_data = nullptr; |