From 9d59f960a46473422d3223cb6fe666deec863d6c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 16 Feb 2023 19:51:30 +0100 Subject: [PATCH] continue testing --- bsp_q7s/obsw.cpp | 9 ++- linux/devices/RwPollingTask.cpp | 59 ++++++++++--------- linux/devices/RwPollingTask.h | 2 +- mission/devices/devicedefinitions/rwHelpers.h | 2 +- mission/system/objects/RwAssembly.cpp | 2 +- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index 6df92158..cfd28565 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -74,16 +74,23 @@ int obsw::obsw() { scheduling::initMission(); -#if OBSW_COMMAND_SAFE_MODE_AT_STARTUP == 1 // Command the EIVE system to safe mode auto sysQueueId = satsystem::EIVE_SYSTEM.getCommandQueue(); CommandMessage msg; +#if OBSW_COMMAND_SAFE_MODE_AT_STARTUP == 1 ModeMessage::setCmdModeMessage(msg, acs::AcsMode::SAFE, 0); ReturnValue_t result = MessageQueueSenderIF::sendMessage(sysQueueId, &msg, MessageQueueIF::NO_QUEUE, false); if (result != returnvalue::OK) { sif::error << "Sending safe mode command to EIVE system failed" << std::endl; } +#else + ModeMessage::setModeAnnounceMessage(msg, true); + ReturnValue_t result = + MessageQueueSenderIF::sendMessage(sysQueueId, &msg, MessageQueueIF::NO_QUEUE, false); + if (result != returnvalue::OK) { + sif::error << "Sending safe mode command to EIVE system failed" << std::endl; + } #endif for (;;) { diff --git a/linux/devices/RwPollingTask.cpp b/linux/devices/RwPollingTask.cpp index feb906c8..9a4fd87a 100644 --- a/linux/devices/RwPollingTask.cpp +++ b/linux/devices/RwPollingTask.cpp @@ -59,23 +59,23 @@ ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) { if (readAllRws(rws::SET_SPEED) != returnvalue::OK) { continue; } - prepareSimpleCommand(rws::GET_LAST_RESET_STATUS); - if (writeAndReadAllRws(rws::GET_LAST_RESET_STATUS) != returnvalue::OK) { - continue; - } - prepareSimpleCommand(rws::GET_RW_STATUS); - if (writeAndReadAllRws(rws::GET_RW_STATUS) != returnvalue::OK) { - continue; - } - prepareSimpleCommand(rws::GET_TEMPERATURE); - if (writeAndReadAllRws(rws::GET_TEMPERATURE) != returnvalue::OK) { - continue; - } - prepareSimpleCommand(rws::CLEAR_LAST_RESET_STATUS); - if (writeAndReadAllRws(rws::CLEAR_LAST_RESET_STATUS) != returnvalue::OK) { - continue; - } - handleSpecialRequests(); +// prepareSimpleCommand(rws::GET_LAST_RESET_STATUS); +// if (writeAndReadAllRws(rws::GET_LAST_RESET_STATUS) != returnvalue::OK) { +// continue; +// } +// prepareSimpleCommand(rws::GET_RW_STATUS); +// if (writeAndReadAllRws(rws::GET_RW_STATUS) != returnvalue::OK) { +// continue; +// } +// prepareSimpleCommand(rws::GET_TEMPERATURE); +// if (writeAndReadAllRws(rws::GET_TEMPERATURE) != returnvalue::OK) { +// continue; +// } +// prepareSimpleCommand(rws::CLEAR_LAST_RESET_STATUS); +// if (writeAndReadAllRws(rws::CLEAR_LAST_RESET_STATUS) != returnvalue::OK) { +// continue; +// } +// handleSpecialRequests(); } return returnvalue::OK; @@ -208,19 +208,20 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf int fd = 0; gpioId_t gpioId = rwCookie.getChipSelectPin(); uint8_t byteRead = 0; - for (unsigned idx = 0; idx < MAX_RETRIES_REPLY; idx++) { - result = openSpi(O_RDWR, fd); - if (result != returnvalue::OK) { - return result; - } - pullCsLow(gpioId, spiLock, gpioIF); + bool exitOuter = false; + for (unsigned retryIdx = 0; retryIdx < MAX_RETRIES_REPLY; retryIdx++) { /** * The reaction wheel responds with empty frames while preparing the reply data. * However, receiving more than 5 empty frames will be interpreted as an error. */ for (int idx = 0; idx < 5; idx++) { + result = openSpi(O_RDWR, fd); + if (result != returnvalue::OK) { + return result; + } + pullCsLow(gpioId, gpioIF); if (read(fd, &byteRead, 1) != 1) { - sif::error << "RwPollingTask: Read failed" << std::endl; + sif::error << "RwPollingTask: Read failed. " << strerror(errno) << std::endl; pullCsHigh(gpioId, gpioIF); closeSpi(fd); return rws::SPI_READ_FAILURE; @@ -235,6 +236,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf } if (byteRead != rws::FRAME_DELIMITER) { + exitOuter = true; break; } @@ -244,8 +246,11 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf sif::error << "rwSpiCallback::spiCallback: Empty frame timeout" << std::endl; return rws::NO_REPLY; } - TaskFactory::delayTask(5); } + if(exitOuter) { + break; + } + TaskFactory::delayTask(5); } #if FSFW_HAL_SPI_WIRETAPPING == 1 sif::info << "RW start marker detected" << std::endl; @@ -448,7 +453,7 @@ ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) { sif::debug << "rwSpiCallback::spiCallback: Mutex or GPIO interface invalid" << std::endl; return returnvalue::FAILED; } - pullCsLow(gpioId, spiLock, gpioIF); + pullCsLow(gpioId, gpioIF); // Add datalinklayer like specified in the datasheet. size_t lenToSend = 0; rws::encodeHdlc(writeBuffer.data(), writeLen, encodedBuffer.data(), lenToSend); @@ -461,7 +466,7 @@ ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) { return returnvalue::OK; } -ReturnValue_t RwPollingTask::pullCsLow(gpioId_t gpioId, MutexIF* spiLock, GpioIF& gpioIF) { +ReturnValue_t RwPollingTask::pullCsLow(gpioId_t gpioId, GpioIF& gpioIF) { ReturnValue_t result = spiLock->lockMutex(TIMEOUT_TYPE, TIMEOUT_MS); if (result != returnvalue::OK) { sif::debug << "RwPollingTask::pullCsLow: Failed to lock mutex" << std::endl; diff --git a/linux/devices/RwPollingTask.h b/linux/devices/RwPollingTask.h index a1bd4cc5..ada6c390 100644 --- a/linux/devices/RwPollingTask.h +++ b/linux/devices/RwPollingTask.h @@ -74,7 +74,7 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override; ReturnValue_t openSpi(int flags, int& fd); - ReturnValue_t pullCsLow(gpioId_t gpioId, MutexIF* spiLock, GpioIF& gpioIF); + ReturnValue_t pullCsLow(gpioId_t gpioId, GpioIF& gpioIF); void prepareSimpleCommand(DeviceCommandId_t id); ReturnValue_t prepareSetSpeedCmd(uint8_t rwIdx); diff --git a/mission/devices/devicedefinitions/rwHelpers.h b/mission/devices/devicedefinitions/rwHelpers.h index 832cf275..f9f737eb 100644 --- a/mission/devices/devicedefinitions/rwHelpers.h +++ b/mission/devices/devicedefinitions/rwHelpers.h @@ -62,7 +62,7 @@ static constexpr Event ERROR_STATE = MAKE_EVENT(1, severity::HIGH); static constexpr Event RESET_OCCURED = event::makeEvent(SUBSYSTEM_ID, 2, severity::LOW); //! Minimal delay as specified by the datasheet. -static const uint32_t SPI_REPLY_DELAY = 20000; // us +static const uint32_t SPI_REPLY_DELAY = 70000; // us enum PoolIds : lp_id_t { TEMPERATURE_C, diff --git a/mission/system/objects/RwAssembly.cpp b/mission/system/objects/RwAssembly.cpp index 6e1c86ae..805863f1 100644 --- a/mission/system/objects/RwAssembly.cpp +++ b/mission/system/objects/RwAssembly.cpp @@ -167,7 +167,7 @@ bool RwAssembly::isUseable(object_id_t object, Mode_t mode) { return false; } -ReturnValue_t RwAssembly::initialize() { return SubsystemBase::initialize(); } +ReturnValue_t RwAssembly::initialize() { return AssemblyBase::initialize(); } void RwAssembly::handleModeTransitionFailed(ReturnValue_t result) { if (targetMode == MODE_OFF) {