[PATCH 06/12] spi: Use self-contained mutex
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Dec 21 14:09:54 UTC 2017
Update #2843.
---
cpukit/dev/include/dev/spi/spi.h | 5 +++--
cpukit/dev/spi/spi-bus.c | 36 ++++++------------------------------
2 files changed, 9 insertions(+), 32 deletions(-)
diff --git a/cpukit/dev/include/dev/spi/spi.h b/cpukit/dev/include/dev/spi/spi.h
index 66bbac2427..f0f84f1461 100644
--- a/cpukit/dev/include/dev/spi/spi.h
+++ b/cpukit/dev/include/dev/spi/spi.h
@@ -7,7 +7,7 @@
*/
/*
- * Copyright (c) 2016 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2016, 2017 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -27,6 +27,7 @@
#include <rtems.h>
#include <rtems/seterr.h>
+#include <rtems/thread.h>
#ifdef __cplusplus
extern "C" {
@@ -96,7 +97,7 @@ struct spi_bus {
/**
* @brief Mutex to protect the bus access.
*/
- rtems_id mutex;
+ rtems_recursive_mutex mutex;
/**
* @brief Maximum Speed in Hz
diff --git a/cpukit/dev/spi/spi-bus.c b/cpukit/dev/spi/spi-bus.c
index 343e203485..a3ee6f14fb 100644
--- a/cpukit/dev/spi/spi-bus.c
+++ b/cpukit/dev/spi/spi-bus.c
@@ -7,7 +7,7 @@
*/
/*
- * Copyright (c) 2016 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2016, 2017 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -33,20 +33,12 @@
static void spi_bus_obtain(spi_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);
}
static void spi_bus_release(spi_bus *bus)
{
- rtems_status_code sc;
-
- sc = rtems_semaphore_release(bus->mutex);
- _Assert(sc == RTEMS_SUCCESSFUL);
- (void) sc;
+ rtems_recursive_mutex_unlock(&bus->mutex);
}
static void spi_bus_set_defaults(spi_bus *bus, spi_ioc_transfer *msg)
@@ -304,34 +296,18 @@ static int spi_bus_do_init(
void (*destroy)(spi_bus *bus)
)
{
- rtems_status_code sc;
-
- sc = rtems_semaphore_create(
- rtems_build_name('S', 'P', 'I', ' '),
- 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, "SPI Bus");
bus->transfer = spi_bus_transfer_default;
bus->setup = spi_bus_setup_default;
bus->destroy = destroy;
bus->bits_per_word = 8;
+
return 0;
}
void spi_bus_destroy(spi_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 spi_bus_destroy_and_free(spi_bus *bus)
--
2.12.3
More information about the devel
mailing list