The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Revision:
122:f9eeca106725
Parent:
85:024bf7f99721
Child:
123:b0220dba8be7
--- a/CAN.h	Wed May 25 16:44:06 2016 +0100
+++ b/CAN.h	Thu Jul 07 14:34:11 2016 +0100
@@ -22,11 +22,13 @@
 
 #include "can_api.h"
 #include "can_helper.h"
-#include "FunctionPointer.h"
+#include "Callback.h"
 
 namespace mbed {
 
 /** CANMessage class
+ *
+ * @Note Synchronization level: Thread safe
  */
 class CANMessage : public CAN_Message {
 
@@ -206,34 +208,45 @@
     /** Attach a function to call whenever a CAN frame received interrupt is
      *  generated.
      *
-     *  @param fptr A pointer to a void function, or 0 to set as none
+     *  @param func A pointer to a void function, or 0 to set as none
      *  @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, CAN::TxIrq for transmitted or aborted, CAN::EwIrq for error warning, CAN::DoIrq for data overrun, CAN::WuIrq for wake-up, CAN::EpIrq for error passive, CAN::AlIrq for arbitration lost, CAN::BeIrq for bus error)
      */
-    void attach(void (*fptr)(void), IrqType type=RxIrq);
+    void attach(Callback<void()> func, IrqType type=RxIrq);
 
    /** Attach a member function to call whenever a CAN frame received interrupt
     *  is generated.
     *
-    *  @param tptr pointer to the object to call the member function on
-    *  @param mptr pointer to the member function to be called
+    *  @param obj pointer to the object to call the member function on
+    *  @param method pointer to the member function to be called
     *  @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
     */
-   template<typename T>
-   void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
-        if((mptr != NULL) && (tptr != NULL)) {
-            _irq[type].attach(tptr, mptr);
-            can_irq_set(&_can, (CanIrqType)type, 1);
-        }
-        else {
-            can_irq_set(&_can, (CanIrqType)type, 0);
-        }
+    template<typename T>
+    void attach(T* obj, void (T::*method)(), IrqType type=RxIrq) {
+        // Underlying call thread safe
+        attach(Callback<void()>(obj, method), type);
+    }
+
+   /** Attach a member function to call whenever a CAN frame received interrupt
+    *  is generated.
+    *
+    *  @param obj pointer to the object to call the member function on
+    *  @param method pointer to the member function to be called
+    *  @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
+    */
+    template<typename T>
+    void attach(T* obj, void (*method)(T*), IrqType type=RxIrq) {
+        // Underlying call thread safe
+        attach(Callback<void()>(obj, method), type);
     }
 
     static void _irq_handler(uint32_t id, CanIrqType type);
 
 protected:
-    can_t           _can;
-    FunctionPointer _irq[9];
+    virtual void lock();
+    virtual void unlock();
+    can_t               _can;
+    Callback<void()>    _irq[9];
+    PlatformMutex       _mutex;
 };
 
 } // namespace mbed