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:
65:5798e58a58b1
--- a/PortInOut.h	Wed May 25 16:44:06 2016 +0100
+++ b/PortInOut.h	Thu Jul 07 14:34:11 2016 +0100
@@ -21,10 +21,13 @@
 #if DEVICE_PORTINOUT
 
 #include "port_api.h"
+#include "critical.h"
 
 namespace mbed {
 
 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
+ *
+ * @Note Synchronization level: Interrupt safe
  */
 class PortInOut {
 public:
@@ -35,7 +38,9 @@
      *  @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
      */
     PortInOut(PortName port, int mask = 0xFFFFFFFF) {
+        core_util_critical_section_enter();
         port_init(&_port, port, mask, PIN_INPUT);
+        core_util_critical_section_exit();
     }
 
     /** Write the value to the output port
@@ -58,13 +63,17 @@
     /** Set as an output
      */
     void output() {
+        core_util_critical_section_enter();
         port_dir(&_port, PIN_OUTPUT);
+        core_util_critical_section_exit();
     }
 
     /** Set as an input
      */
     void input() {
+        core_util_critical_section_enter();
         port_dir(&_port, PIN_INPUT);
+        core_util_critical_section_exit();
     }
 
     /** Set the input pin mode
@@ -72,7 +81,9 @@
      *  @param mode PullUp, PullDown, PullNone, OpenDrain
      */
     void mode(PinMode mode) {
+        core_util_critical_section_enter();
         port_mode(&_port, mode);
+        core_util_critical_section_exit();
     }
 
     /** A shorthand for write()