From 578c4859e4de315f70791f0b90adc04301cf70d2 Mon Sep 17 00:00:00 2001 From: James Bielman Date: Thu, 3 Jan 2013 15:41:36 -0800 Subject: [PATCH] AP_HAL_SMACCM: Update to new semaphore interface. - Renamed files to match AVR HAL. --- .../AP_HAL_SMACCM/AP_HAL_SMACCM_Private.h | 2 +- libraries/AP_HAL_SMACCM/SPIDriver.cpp | 2 + libraries/AP_HAL_SMACCM/SPIDriver.h | 2 +- libraries/AP_HAL_SMACCM/Semaphore.cpp | 40 ------------------- libraries/AP_HAL_SMACCM/Semaphore.h | 22 ---------- libraries/AP_HAL_SMACCM/Semaphores.cpp | 36 +++++++++++++++++ libraries/AP_HAL_SMACCM/Semaphores.h | 22 ++++++++++ 7 files changed, 62 insertions(+), 64 deletions(-) delete mode 100644 libraries/AP_HAL_SMACCM/Semaphore.cpp delete mode 100644 libraries/AP_HAL_SMACCM/Semaphore.h create mode 100644 libraries/AP_HAL_SMACCM/Semaphores.cpp create mode 100644 libraries/AP_HAL_SMACCM/Semaphores.h diff --git a/libraries/AP_HAL_SMACCM/AP_HAL_SMACCM_Private.h b/libraries/AP_HAL_SMACCM/AP_HAL_SMACCM_Private.h index 16982cc596..23e8aca1f6 100644 --- a/libraries/AP_HAL_SMACCM/AP_HAL_SMACCM_Private.h +++ b/libraries/AP_HAL_SMACCM/AP_HAL_SMACCM_Private.h @@ -15,7 +15,7 @@ #include "GPIO.h" #include "RCInput.h" #include "RCOutput.h" -#include "Semaphore.h" +#include "Semaphores.h" #include "Scheduler.h" #include "Util.h" #include "PrivateMember.h" diff --git a/libraries/AP_HAL_SMACCM/SPIDriver.cpp b/libraries/AP_HAL_SMACCM/SPIDriver.cpp index 1df532f09a..a2d4a7e804 100644 --- a/libraries/AP_HAL_SMACCM/SPIDriver.cpp +++ b/libraries/AP_HAL_SMACCM/SPIDriver.cpp @@ -24,6 +24,7 @@ SMACCMSPIDeviceDriver::SMACCMSPIDeviceDriver(spi_bus *bus, spi_device *device) void SMACCMSPIDeviceDriver::init() { + _semaphore.init(); } AP_HAL::Semaphore* SMACCMSPIDeviceDriver::get_semaphore() @@ -88,6 +89,7 @@ void SMACCMSPIDeviceManager::init(void *) spi_init(spi1); spi_device_init(&g_mpu6000_spi_dev); + g_mpu6000_dev.init(); } AP_HAL::SPIDeviceDriver* SMACCMSPIDeviceManager::device(AP_HAL::SPIDevice dev) diff --git a/libraries/AP_HAL_SMACCM/SPIDriver.h b/libraries/AP_HAL_SMACCM/SPIDriver.h index 56c748aa36..3664536e81 100644 --- a/libraries/AP_HAL_SMACCM/SPIDriver.h +++ b/libraries/AP_HAL_SMACCM/SPIDriver.h @@ -12,7 +12,7 @@ #define __AP_HAL_SMACCM_SPIDRIVER_H__ #include -#include "Semaphore.h" +#include "Semaphores.h" #include diff --git a/libraries/AP_HAL_SMACCM/Semaphore.cpp b/libraries/AP_HAL_SMACCM/Semaphore.cpp deleted file mode 100644 index c46f4154e6..0000000000 --- a/libraries/AP_HAL_SMACCM/Semaphore.cpp +++ /dev/null @@ -1,40 +0,0 @@ - -#include "Semaphore.h" - -using namespace SMACCM; - -SMACCMSemaphore::SMACCMSemaphore() : - _owner(NULL), - _k(NULL) -{} - - -bool SMACCMSemaphore::get(void* owner) { - if (_owner == NULL) { - _owner = owner; - return true; - } else { - return false; - } -} - -bool SMACCMSemaphore::release(void* owner) { - if (_owner == NULL || _owner != owner) { - return false; - } else { - _owner = NULL; - if (_k){ - _k(); - _k = NULL; - } - return true; - } -} - -bool SMACCMSemaphore::call_on_release(void* caller, AP_HAL::Proc k) { - /* idk what semantics randy was looking for here, honestly. - * seems like a bad idea. */ - _k = k; - return true; -} - diff --git a/libraries/AP_HAL_SMACCM/Semaphore.h b/libraries/AP_HAL_SMACCM/Semaphore.h deleted file mode 100644 index 8bd9a02921..0000000000 --- a/libraries/AP_HAL_SMACCM/Semaphore.h +++ /dev/null @@ -1,22 +0,0 @@ - -#ifndef __AP_HAL_SMACCM_SEMAPHORE_H__ -#define __AP_HAL_SMACCM_SEMAPHORE_H__ - -#include - -class SMACCM::SMACCMSemaphore : public AP_HAL::Semaphore { -public: - SMACCMSemaphore(); - // get - to claim ownership of the semaphore - bool get(void* owner); - // release - to give up ownership of the semaphore - bool release(void* owner); - // call_on_release - returns true if caller successfully added to the - // queue to be called back - bool call_on_release(void* caller, AP_HAL::Proc k); -private: - void* _owner; - AP_HAL::Proc _k; -}; - -#endif // __AP_HAL_SMACCM_SEMAPHORE_H__ diff --git a/libraries/AP_HAL_SMACCM/Semaphores.cpp b/libraries/AP_HAL_SMACCM/Semaphores.cpp new file mode 100644 index 0000000000..890edfb997 --- /dev/null +++ b/libraries/AP_HAL_SMACCM/Semaphores.cpp @@ -0,0 +1,36 @@ + +#include "Semaphores.h" + +using namespace SMACCM; + +SMACCMSemaphore::SMACCMSemaphore() + : m_semaphore(NULL) +{ +} + +void SMACCMSemaphore::init() +{ + m_semaphore = xSemaphoreCreateMutex(); +} + +bool SMACCMSemaphore::take(uint32_t timeout_ms) +{ + portTickType delay; + + if (timeout_ms == HAL_SEMAPHORE_BLOCK_FOREVER) + delay = portMAX_DELAY; + else + delay = timeout_ms / portTICK_RATE_MS; + + return xSemaphoreTake(m_semaphore, delay); +} + +bool SMACCMSemaphore::take_nonblocking() +{ + return xSemaphoreTake(m_semaphore, 0); +} + +bool SMACCMSemaphore::give() +{ + return xSemaphoreGive(m_semaphore); +} diff --git a/libraries/AP_HAL_SMACCM/Semaphores.h b/libraries/AP_HAL_SMACCM/Semaphores.h new file mode 100644 index 0000000000..9375b5cb41 --- /dev/null +++ b/libraries/AP_HAL_SMACCM/Semaphores.h @@ -0,0 +1,22 @@ + +#ifndef __AP_HAL_SMACCM_SEMAPHORE_H__ +#define __AP_HAL_SMACCM_SEMAPHORE_H__ + +#include +#include +#include + +class SMACCM::SMACCMSemaphore : public AP_HAL::Semaphore { +public: + SMACCMSemaphore(); + + void init(); + virtual bool take(uint32_t timeout_ms); + virtual bool take_nonblocking(); + virtual bool give(); + +private: + xSemaphoreHandle m_semaphore; +}; + +#endif // __AP_HAL_SMACCM_SEMAPHORE_H__