sus delay implementation
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <mission/devices/SusHandler.h>
|
||||
#include <OBSWConfig.h>
|
||||
#include <fsfw_hal/linux/spi/SpiComIF.h>
|
||||
|
||||
SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie,
|
||||
LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId) :
|
||||
@ -17,6 +18,24 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo
|
||||
SusHandler::~SusHandler() {
|
||||
}
|
||||
|
||||
ReturnValue_t SusHandler::initialize() {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = DeviceHandlerBase::initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
auto spiComIF = dynamic_cast<SpiComIF*>(communicationInterface);
|
||||
if (spiComIF == nullptr) {
|
||||
sif::debug << "SusHandler::initialize: Invalid communication interface" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
spiMutex = spiComIF->getMutex();
|
||||
if (spiMutex == nullptr) {
|
||||
sif::debug << "SusHandler::initialize: Failed to get spi mutex" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void SusHandler::doStartUp(){
|
||||
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
||||
@ -62,8 +81,20 @@ ReturnValue_t SusHandler::buildCommandFromCommand(
|
||||
* measurement the setup has to be rewritten. There must also be a little delay between
|
||||
* the transmission of the setup byte and the first conversion. Thus the conversion
|
||||
* will be performed in an extra step.
|
||||
* Because the chip select is driven manually by the SusHandler the SPI bus must be
|
||||
* protected with a mutex here.
|
||||
*/
|
||||
//TODO: Protect spi bus with mutex
|
||||
ReturnValue_t result = spiMutex->lockMutex(timeoutType, timeoutMs);
|
||||
if(result == MutexIF::MUTEX_TIMEOUT) {
|
||||
sif::error << "SusHandler::buildCommandFromCommand: Mutex timeout" << std::endl;
|
||||
return ERROR_LOCK_MUTEX;
|
||||
}
|
||||
else if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "SusHandler::buildCommandFromCommand: Failed to lock spi mutex"
|
||||
<< std::endl;
|
||||
return ERROR_LOCK_MUTEX;
|
||||
}
|
||||
|
||||
gpioComIF->pullLow(chipSelectId);
|
||||
cmdBuffer[0] = SUS::SETUP;
|
||||
rawPacket = cmdBuffer;
|
||||
@ -132,6 +163,12 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
#endif
|
||||
/** SUS can now be shutdown and thus the SPI bus released again */
|
||||
gpioComIF->pullHigh(chipSelectId);
|
||||
ReturnValue_t result = spiMutex->unlockMutex();
|
||||
if (result != RETURN_OK) {
|
||||
sif::error << "SusHandler::interpretDeviceReply: Failed to unlock spi mutex"
|
||||
<< std::endl;
|
||||
return ERROR_UNLOCK_MUTEX;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
Reference in New Issue
Block a user