Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
Diff: InterruptManager.h
- Revision:
- 122:f9eeca106725
- Parent:
- 85:024bf7f99721
- Child:
- 123:b0220dba8be7
--- a/InterruptManager.h Wed May 25 16:44:06 2016 +0100
+++ b/InterruptManager.h Thu Jul 07 14:34:11 2016 +0100
@@ -1,6 +1,8 @@
#ifndef MBED_INTERRUPTMANAGER_H
#define MBED_INTERRUPTMANAGER_H
+#include "platform.h"
+
#include "cmsis.h"
#include "CallChain.h"
#include <string.h>
@@ -9,6 +11,8 @@
/** Use this singleton if you need to chain interrupt handlers.
*
+ * @Note Synchronization level: Thread safe
+ *
* Example (for LPC1768):
* @code
* #include "InterruptManager.h"
@@ -52,6 +56,7 @@
* The function object created for 'function'
*/
pFunctionPointer_t add_handler(void (*function)(void), IRQn_Type irq) {
+ // Underlying call is thread safe
return add_common(function, irq);
}
@@ -64,6 +69,7 @@
* The function object created for 'function'
*/
pFunctionPointer_t add_handler_front(void (*function)(void), IRQn_Type irq) {
+ // Underlying call is thread safe
return add_common(function, irq, true);
}
@@ -78,6 +84,7 @@
*/
template<typename T>
pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IRQn_Type irq) {
+ // Underlying call is thread safe
return add_common(tptr, mptr, irq);
}
@@ -92,6 +99,7 @@
*/
template<typename T>
pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IRQn_Type irq) {
+ // Underlying call is thread safe
return add_common(tptr, mptr, irq, true);
}
@@ -109,6 +117,9 @@
InterruptManager();
~InterruptManager();
+ void lock();
+ void unlock();
+
// We declare the copy contructor and the assignment operator, but we don't
// implement them. This way, if someone tries to copy/assign our instance,
// he will get an error at compile time.
@@ -117,12 +128,14 @@
template<typename T>
pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front=false) {
+ _mutex.lock();
int irq_pos = get_irq_index(irq);
bool change = must_replace_vector(irq);
pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(tptr, mptr) : _chains[irq_pos]->add(tptr, mptr);
if (change)
NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper);
+ _mutex.unlock();
return pf;
}
@@ -135,6 +148,7 @@
CallChain* _chains[NVIC_NUM_VECTORS];
static InterruptManager* _instance;
+ PlatformMutex _mutex;
};
} // namespace mbed


