mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Revision:
122:f9eeca106725
Parent:
102:da0ca467f8b5
Child:
123:b0220dba8be7
diff -r 6c34061e7c34 -r f9eeca106725 SPI.h
--- a/SPI.h	Wed May 25 16:44:06 2016 +0100
+++ b/SPI.h	Thu Jul 07 14:34:11 2016 +0100
@@ -39,6 +39,8 @@
  * Most SPI devices will also require Chip Select and Reset signals. These
  * can be controlled using <DigitalOut> pins
  *
+ * @Note Synchronization level: Thread safe
+ *
  * Example:
  * @code
  * // Send a byte to a SPI slave, and record the response
@@ -56,10 +58,13 @@
  *     // hardware ssel (where applicable)
  *     //int response = device.write(0xFF);
  *
+ *     device.lock();
  *     // software ssel
  *     cs = 0;
  *     int response = device.write(0xFF);
  *     cs = 1;
+ *     device.unlock();
+ *
  * }
  * @endcode
  */
@@ -109,6 +114,14 @@
     */
     virtual int write(int value);
 
+    /** Acquire exclusive access to this SPI bus
+     */
+    virtual void lock(void);
+
+    /** Release exclusive access to this SPI bus
+     */
+    virtual void unlock(void);
+
 #if DEVICE_SPI_ASYNCH
 
     /** Start non-blocking SPI transfer using 8bit buffers.
@@ -233,6 +246,7 @@
 
     void aquire(void);
     static SPI *_owner;
+    PlatformMutex _mutex;
     int _bits;
     int _mode;
     int _hz;