[rtems commit] spi: Use self-contained mutex
Sebastian Huber
sebh at rtems.org
Fri Feb 2 14:22:16 UTC 2018
Module: rtems
Branch: master
Commit: 36304f3d7a32fc4e7573fa6f3db2efb437416639
Changeset: http://git.rtems.org/rtems/commit/?id=36304f3d7a32fc4e7573fa6f3db2efb437416639
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Dec 8 15:56:26 2017 +0100
spi: Use self-contained mutex
Update #2843.
---
cpukit/dev/spi/spi-bus.c | 36 ++++++------------------------------
cpukit/include/dev/spi/spi.h | 5 +++--
2 files changed, 9 insertions(+), 32 deletions(-)
diff --git a/cpukit/dev/spi/spi-bus.c b/cpukit/dev/spi/spi-bus.c
index 343e203..a3ee6f1 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)
diff --git a/cpukit/include/dev/spi/spi.h b/cpukit/include/dev/spi/spi.h
index 66bbac2..f0f84f1 100644
--- a/cpukit/include/dev/spi/spi.h
+++ b/cpukit/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
More information about the vc
mailing list