fixed mutex bug

This commit is contained in:
Jakob Meier 2021-05-12 17:40:14 +02:00
parent 425cfd2aba
commit 49da48dc0d

View File

@ -5,7 +5,6 @@
#include <FSFWConfig.h>
#include <fsfw/ipc/MutexFactory.h>
#include <fsfw/ipc/MutexGuard.h>
#include <fsfw/globalfunctions/arrayprinter.h>
#include <linux/spi/spidev.h>
@ -180,8 +179,11 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
/* Pull SPI CS low. For now, no support for active high given */
if(gpioId != gpio::NO_GPIO) {
/* GPIO access is mutex protected */
MutexGuard(spiMutex, timeoutType, timeoutMs);
result = spiMutex->lockMutex(timeoutType, timeoutMs);
if (result != RETURN_OK) {
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl;
return result;
}
gpioComIF->pullLow(gpioId);
}
@ -226,6 +228,11 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s
if(gpioId != gpio::NO_GPIO) {
gpioComIF->pullHigh(gpioId);
result = spiMutex->unlockMutex();
if (result != RETURN_OK) {
sif::error << "SpiComIF::sendMessage: Failed to unlock mutex" << std::endl;
return result;
}
}
return result;
}
@ -263,7 +270,11 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe
gpioId_t gpioId = spiCookie->getChipSelectPin();
if(gpioId != gpio::NO_GPIO) {
MutexGuard(spiMutex, timeoutType, timeoutMs);
result = spiMutex->lockMutex(timeoutType, timeoutMs);
if (result != RETURN_OK) {
sif::error << "SpiComIF::getSendSuccess: Failed to lock mutex" << std::endl;
return result;
}
gpioComIF->pullLow(gpioId);
}
@ -280,6 +291,11 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe
if(gpioId != gpio::NO_GPIO) {
gpioComIF->pullHigh(gpioId);
result = spiMutex->unlockMutex();
if (result != RETURN_OK) {
sif::error << "SpiComIF::getSendSuccess: Failed to unlock mutex" << std::endl;
return result;
}
}
return HasReturnvaluesIF::RETURN_OK;