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:
93:e188a91d3eaa
Child:
123:b0220dba8be7
--- a/DigitalOut.h	Wed May 25 16:44:06 2016 +0100
+++ b/DigitalOut.h	Thu Jul 07 14:34:11 2016 +0100
@@ -18,11 +18,14 @@
 
 #include "platform.h"
 #include "gpio_api.h"
+#include "critical.h"
 
 namespace mbed {
 
 /** A digital output, used for setting the state of a pin
  *
+ * @Note Synchronization level: Interrupt safe
+ *
  * Example:
  * @code
  * // Toggle a LED
@@ -46,6 +49,7 @@
      *  @param pin DigitalOut pin to connect to
      */
     DigitalOut(PinName pin) : gpio() {
+        // No lock needed in the constructor
         gpio_init_out(&gpio, pin);
     }
 
@@ -55,6 +59,7 @@
      *  @param value the initial pin value
      */
     DigitalOut(PinName pin, int value) : gpio() {
+        // No lock needed in the constructor
         gpio_init_out_ex(&gpio, pin, value);
     }
 
@@ -64,6 +69,7 @@
      *      0 for logical 0, 1 (or any other non-zero value) for logical 1
      */
     void write(int value) {
+        // Thread safe / atomic HAL call
         gpio_write(&gpio, value);
     }
 
@@ -74,6 +80,7 @@
      *    0 for logical 0, 1 for logical 1
      */
     int read() {
+        // Thread safe / atomic HAL call
         return gpio_read(&gpio);
     }
 
@@ -84,6 +91,7 @@
      *    0 if gpio object was initialized with NC
      */
     int is_connected() {
+        // Thread safe / atomic HAL call
         return gpio_is_connected(&gpio);
     }
 
@@ -91,18 +99,22 @@
     /** A shorthand for write()
      */
     DigitalOut& operator= (int value) {
+        // Underlying write is thread safe
         write(value);
         return *this;
     }
 
     DigitalOut& operator= (DigitalOut& rhs) {
+        core_util_critical_section_enter();
         write(rhs.read());
+        core_util_critical_section_exit();
         return *this;
     }
 
     /** A shorthand for read()
      */
     operator int() {
+        // Underlying call is thread safe
         return read();
     }
 #endif