[rtems commit] i2c: Use self-contained mutex

Sebastian Huber sebh at rtems.org
Fri Feb 2 14:22:04 UTC 2018


Module:    rtems
Branch:    master
Commit:    dc158ad4ec9546a826d2a4ea3ec09dcbdaa594f2
Changeset: http://git.rtems.org/rtems/commit/?id=dc158ad4ec9546a826d2a4ea3ec09dcbdaa594f2

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Dec  8 15:47:09 2017 +0100

i2c: Use self-contained mutex

Update #2843.

---

 cpukit/dev/i2c/i2c-bus.c     | 36 +++++-------------------------------
 cpukit/include/dev/i2c/i2c.h |  5 +++--
 2 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/cpukit/dev/i2c/i2c-bus.c b/cpukit/dev/i2c/i2c-bus.c
index 1297b1e..23311ae 100644
--- a/cpukit/dev/i2c/i2c-bus.c
+++ b/cpukit/dev/i2c/i2c-bus.c
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -33,20 +33,12 @@
 
 void i2c_bus_obtain(i2c_bus *bus)
 {
-  rtems_status_code sc;
-
-  sc = rtems_semaphore_obtain(bus->mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-  _Assert(sc == RTEMS_SUCCESSFUL);
-  (void) sc;
+  rtems_recursive_mutex_lock(&bus->mutex);
 }
 
 void i2c_bus_release(i2c_bus *bus)
 {
-  rtems_status_code sc;
-
-  sc = rtems_semaphore_release(bus->mutex);
-  _Assert(sc == RTEMS_SUCCESSFUL);
-  (void) sc;
+  rtems_recursive_mutex_unlock(&bus->mutex);
 }
 
 int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count)
@@ -286,21 +278,7 @@ static int i2c_bus_do_init(
   void (*destroy)(i2c_bus *bus)
 )
 {
-  rtems_status_code sc;
-
-  sc = rtems_semaphore_create(
-    rtems_build_name('I', '2', 'C', ' '),
-    1,
-    RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
-    0,
-    &bus->mutex
-  );
-  if (sc != RTEMS_SUCCESSFUL) {
-    (*destroy)(bus);
-
-    rtems_set_errno_and_return_minus_one(ENOMEM);
-  }
-
+  rtems_recursive_mutex_init(&bus->mutex, "I2C Bus");
   bus->transfer = i2c_bus_transfer_default;
   bus->set_clock = i2c_bus_set_clock_default;
   bus->destroy = destroy;
@@ -310,11 +288,7 @@ static int i2c_bus_do_init(
 
 void i2c_bus_destroy(i2c_bus *bus)
 {
-  rtems_status_code sc;
-
-  sc = rtems_semaphore_delete(bus->mutex);
-  _Assert(sc == RTEMS_SUCCESSFUL);
-  (void) sc;
+  rtems_recursive_mutex_destroy(&bus->mutex);
 }
 
 void i2c_bus_destroy_and_free(i2c_bus *bus)
diff --git a/cpukit/include/dev/i2c/i2c.h b/cpukit/include/dev/i2c/i2c.h
index 2ace4fc..5f6caf6 100644
--- a/cpukit/include/dev/i2c/i2c.h
+++ b/cpukit/include/dev/i2c/i2c.h
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -28,6 +28,7 @@
 
 #include <rtems.h>
 #include <rtems/seterr.h>
+#include <rtems/thread.h>
 
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -139,7 +140,7 @@ struct i2c_bus {
   /**
    * @brief Mutex to protect the bus access.
    */
-  rtems_id mutex;
+  rtems_recursive_mutex mutex;
 
   /**
    * @brief Default slave device address.



More information about the vc mailing list