I2CRTOS Driver by Helmut Schmücker. Removed included mbed-rtos library to prevent multiple definition. Make sure to include mbed-rtos library in your program!

Fork of I2cRtosDriver by Helmut Schmücker

Revision:
6:5b98c902a659
Parent:
5:8a418c89e515
Child:
7:04824382eafb
diff -r 8a418c89e515 -r 5b98c902a659 I2CDriver.h
--- a/I2CDriver.h	Sat Apr 20 11:56:35 2013 +0000
+++ b/I2CDriver.h	Sat Apr 20 20:06:44 2013 +0000
@@ -178,26 +178,18 @@
     ///Creates a stop condition on the I2C bus
     void stopMaster(void);
 
-
-
     /// Wait until the i2c driver becomes available.
     ///
     /// Useful if you want to run a sequence of command without interrution by another thread.
     /// There's no need to call this function for running single request, because all driver functions
     /// will lock the device for exclusive access automatically.
-    void lock()  {
-        // One and the same thread can lock twice, but then it needs also to unlock twice.
-        // exactly what we need here
-        m_channel->mutex.lock(osWaitForever);
-    }
+    void lock();
 
     /// Unlock the driver that has previously been locked by the same thread.
-    void unlock() {
-        m_channel->mutex.unlock();
-    }
+    void unlock();
 
 protected:
-    // commands sent from user to drive thread 
+    // commands sent from user to drive thread
     enum Command {
         START,
         STOP,
@@ -210,7 +202,7 @@
         WRITE_BYTE,
         RECEIVE
     };
-    
+
     // data transfer struct for communication between user and driver thread
     struct Transfer {
         Command cmd;
@@ -228,36 +220,42 @@
         osThreadId caller;
     };
 
-    // structure that holds handles/locks for accessing the I2C channels 
+    // structure that holds handles/locks for accessing the I2C channels
     struct Channel {
-        osThreadId driver; 
+        osThreadId driver;
         rtos::Mutex  mutex;
         volatile Transfer transfer;
     };
-    
+
     // current frequency setting
     int m_freq;
     // current slave address setting
     int m_slaveAdr;
-    
+    // prio of current caller thread
+    osPriority m_callerPrio;
+    // ID of current caller thread
+    osThreadId m_callerID;
+
+    // i2c driver prio
+    static const osPriority c_drvPrio = osPriorityRealtime;
     // the pin names fo the i2c channels
     static const PinName c_sdas[2];
     static const PinName c_scls[2];
 
-    // static storage for the I2C channel access objects  
+    // static storage for the I2C channel access objects
     static Channel* s_channels[2];
-    
+
     // i2c channel object of this driver interface, in fact just pointer
     /// to one of the entries in s_channels
     Channel* m_channel;
-    
-    // ISRs  
+
+    // ISRs
     static void channel_0_ISR();
     static void channel_1_ISR();
-    
+
     // the driver thread function
     static void threadFun(void const *args);
-    
+
     int sendNwait();
 };
 }