From 4b37a196448bfa96a542175a9cee944d6fd9e7a1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:21:45 +0100 Subject: [PATCH 01/20] try to use more locks with timeouts --- bsp_q7s/fs/SdCardManager.cpp | 24 ++++++++++++------------ bsp_q7s/fs/SdCardManager.h | 4 +++- fsfw | 2 +- mission/config/torquer.h | 2 ++ mission/controller/AcsController.cpp | 2 +- mission/devices/ImtqHandler.cpp | 2 +- mission/devices/PcduHandler.cpp | 16 +++++++++------- mission/devices/PcduHandler.h | 5 ++++- 8 files changed, 33 insertions(+), 24 deletions(-) diff --git a/bsp_q7s/fs/SdCardManager.cpp b/bsp_q7s/fs/SdCardManager.cpp index f8da9bee..45c9f0d0 100644 --- a/bsp_q7s/fs/SdCardManager.cpp +++ b/bsp_q7s/fs/SdCardManager.cpp @@ -20,14 +20,14 @@ SdCardManager* SdCardManager::INSTANCE = nullptr; SdCardManager::SdCardManager() : SystemObject(objects::SDC_MANAGER), cmdExecutor(256) { - mutex = MutexFactory::instance()->createMutex(); - ReturnValue_t result = mutex->lockMutex(); + sdLock = MutexFactory::instance()->createMutex(); + ReturnValue_t result = sdLock->lockMutex(); if (result != returnvalue::OK) { sif::error << "SdCardManager::SdCardManager: Mutex lock failed" << std::endl; } uint8_t prefSdRaw = 0; result = scratch::readNumber(scratch::PREFERED_SDC_KEY, prefSdRaw); - if (mutex->unlockMutex() != returnvalue::OK) { + if (sdLock->unlockMutex() != returnvalue::OK) { sif::error << "SdCardManager::SdCardManager: Mutex unlock failed" << std::endl; } @@ -195,7 +195,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) { ReturnValue_t SdCardManager::getSdCardsStatus(SdStatePair& active) { using namespace std; - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); if (not filesystem::exists(SD_STATE_FILE)) { return STATUS_FILE_NEXISTS; } @@ -378,7 +378,7 @@ void SdCardManager::processSdStatusLine(std::pair& act } std::optional SdCardManager::getPreferredSdCard() const { - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); auto res = mg.getLockResult(); if (res != returnvalue::OK) { sif::error << "SdCardManager::getPreferredSdCard: Lock error" << std::endl; @@ -387,7 +387,7 @@ std::optional SdCardManager::getPreferredSdCard() const { } ReturnValue_t SdCardManager::setPreferredSdCard(sd::SdCard sdCard) { - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); if (sdCard == sd::SdCard::BOTH) { return returnvalue::FAILED; } @@ -399,7 +399,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) { return CommandExecutor::COMMAND_PENDING; } - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); // Use q7hw utility and pipe the command output into the state file std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE); cmdExecutor.load(updateCmd, blocking, printCmdOutput); @@ -411,7 +411,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { } const char* SdCardManager::getCurrentMountPrefix() const { - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); if (currentPrefix.has_value()) { return currentPrefix.value().c_str(); } @@ -464,7 +464,7 @@ void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = p bool SdCardManager::isSdCardUsable(std::optional sdCard) { { - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); if (markedUnusable) { return false; } @@ -560,7 +560,7 @@ ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, in } void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); sdInfo.active = sdCard; if (sdInfo.active == sd::SdCard::SLOT_0) { currentPrefix = config::SD_0_MOUNT_POINT; @@ -570,7 +570,7 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { } std::optional SdCardManager::getActiveSdCard() const { - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); if (markedUnusable) { return std::nullopt; } @@ -578,6 +578,6 @@ std::optional SdCardManager::getActiveSdCard() const { } void SdCardManager::markUnusable() { - MutexGuard mg(mutex); + MutexGuard mg(sdLock, lockType, lockTimeout); markedUnusable = true; } diff --git a/bsp_q7s/fs/SdCardManager.h b/bsp_q7s/fs/SdCardManager.h index 77055589..1b538dad 100644 --- a/bsp_q7s/fs/SdCardManager.h +++ b/bsp_q7s/fs/SdCardManager.h @@ -223,7 +223,9 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { bool sdCardActive = true; bool printCmdOutput = true; bool markedUnusable = false; - MutexIF* mutex = nullptr; + MutexIF* sdLock = nullptr; + MutexIF::TimeoutType lockType = MutexIF::TimeoutType::WAITING; + uint32_t lockTimeout = 40; SdCardManager(); diff --git a/fsfw b/fsfw index 511d07c0..f8409754 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 511d07c0c78de7b1850e341dfcf8be7589f3c523 +Subproject commit f84097543e59a3564eae4ac19b7118102728c8a9 diff --git a/mission/config/torquer.h b/mission/config/torquer.h index 10a27991..8241eb83 100644 --- a/mission/config/torquer.h +++ b/mission/config/torquer.h @@ -9,6 +9,8 @@ namespace torquer { // Additional buffer time to accont for time until I2C command arrives and ramp up / ramp down // time of the MGT static constexpr dur_millis_t TORQUE_BUFFER_TIME_MS = 20; +static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; +static constexpr uint32_t LOCK_TIMEOUT = 20; MutexIF* lazyLock(); extern bool TORQUEING; diff --git a/mission/controller/AcsController.cpp b/mission/controller/AcsController.cpp index c0853695..5aa12523 100644 --- a/mission/controller/AcsController.cpp +++ b/mission/controller/AcsController.cpp @@ -429,7 +429,7 @@ ReturnValue_t AcsController::commandActuators(int16_t xDipole, int16_t yDipole, uint16_t rampTime) { { PoolReadGuard pg(&dipoleSet); - MutexGuard mg(torquer::lazyLock()); + MutexGuard mg(torquer::lazyLock(), torquer::LOCK_TYPE, torquer::LOCK_TIMEOUT); torquer::NEW_ACTUATION_FLAG = true; dipoleSet.setDipoles(xDipole, yDipole, zDipole, dipoleTorqueDuration); } diff --git a/mission/devices/ImtqHandler.cpp b/mission/devices/ImtqHandler.cpp index 5c5bdb61..fadf5a63 100644 --- a/mission/devices/ImtqHandler.cpp +++ b/mission/devices/ImtqHandler.cpp @@ -214,7 +214,7 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma << ", y = " << dipoleSet.yDipole.value << ", z = " << dipoleSet.zDipole.value << ", duration = " << dipoleSet.currentTorqueDurationMs.value << std::endl; } - MutexGuard mg(torquer::lazyLock()); + MutexGuard mg(torquer::lazyLock(), torquer::LOCK_TYPE, torquer::LOCK_TIMEOUT); torquer::TORQUEING = true; torquer::TORQUE_COUNTDOWN.setTimeout(dipoleSet.currentTorqueDurationMs.value); rawPacket = commandBuffer; diff --git a/mission/devices/PcduHandler.cpp b/mission/devices/PcduHandler.cpp index 46106796..5ed227cd 100644 --- a/mission/devices/PcduHandler.cpp +++ b/mission/devices/PcduHandler.cpp @@ -18,7 +18,7 @@ PCDUHandler::PCDUHandler(object_id_t setObjectId, size_t cmdQueueSize) auto mqArgs = MqArgs(setObjectId, static_cast(this)); commandQueue = QueueFactory::instance()->createMessageQueue( cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); - pwrMutex = MutexFactory::instance()->createMutex(); + pwrLock = MutexFactory::instance()->createMutex(); } PCDUHandler::~PCDUHandler() {} @@ -41,7 +41,7 @@ ReturnValue_t PCDUHandler::performOperation(uint8_t counter) { if (pg.getReadResult() == returnvalue::OK) { if (switcherSet.p60Dock5VStack.value != switchState) { triggerEvent(power::SWITCH_HAS_CHANGED, switchState, pcdu::Switches::P60_DOCK_5V_STACK); - MutexGuard mg(pwrMutex); + MutexGuard mg(pwrLock); switchStates[pcdu::P60_DOCK_5V_STACK] = switchState; } switcherSet.p60Dock5VStack.setValid(true); @@ -179,7 +179,7 @@ void PCDUHandler::updatePdu2SwitchStates() { switcherSet.pdu2Switches[idx] = pdu2CoreHk.outputEnables[idx]; } switcherSet.pdu2Switches.setValid(true); - MutexGuard mg(pwrMutex); + MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); checkAndUpdatePduSwitch(pdu, Switches::PDU2_CH0_Q7S, pdu2CoreHk.outputEnables[Channels::Q7S]); checkAndUpdatePduSwitch(pdu, Switches::PDU2_CH1_PL_PCDU_BATT_0_14V8, @@ -216,7 +216,7 @@ void PCDUHandler::updatePdu1SwitchStates() { switcherSet.pdu1Switches[idx] = pdu1CoreHk.outputEnables[idx]; } switcherSet.pdu1Switches.setValid(true); - MutexGuard mg(pwrMutex); + MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); checkAndUpdatePduSwitch(pdu, Switches::PDU1_CH0_TCS_BOARD_3V3, pdu1CoreHk.outputEnables[Channels::TCS_BOARD_3V3]); checkAndUpdatePduSwitch(pdu, Switches::PDU1_CH1_SYRLINKS_12V, @@ -402,9 +402,11 @@ ReturnValue_t PCDUHandler::getSwitchState(uint8_t switchNr) const { sif::debug << "PCDUHandler::getSwitchState: Invalid switch number" << std::endl; return returnvalue::FAILED; } - pwrMutex->lockMutex(); - uint8_t currentState = switchStates[switchNr]; - pwrMutex->unlockMutex(); + uint8_t currentState = 0; + { + MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); + currentState = switchStates[switchNr]; + } if (currentState == 1) { return PowerSwitchIF::SWITCH_ON; } else { diff --git a/mission/devices/PcduHandler.h b/mission/devices/PcduHandler.h index d1f3996b..45bbd392 100644 --- a/mission/devices/PcduHandler.h +++ b/mission/devices/PcduHandler.h @@ -51,7 +51,10 @@ class PCDUHandler : public PowerSwitchIF, private: uint32_t pstIntervalMs = 0; - MutexIF* pwrMutex = nullptr; + MutexIF* pwrLock = nullptr; + static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; + static constexpr uint32_t LOCK_TIMEOUT = 20; + static constexpr char LOCK_CTX[] = "PcduHandler"; /** Housekeeping manager. Handles updates of local pool variables. */ LocalDataPoolManager poolManager; From 7b539e2fa5089131e4cd9862805066c64fbf33b3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:22:21 +0100 Subject: [PATCH 02/20] rework lock handling --- bsp_q7s/core/CoreController.cpp | 2 +- common/config/eive/definitions.h | 2 +- mission/core/pollingSeqTables.cpp | 224 +++++++++++++++++++----------- mission/devices/ImtqHandler.cpp | 2 +- mission/devices/PcduHandler.cpp | 4 +- mission/devices/SusHandler.h | 1 + mission/system/tree/system.cpp | 10 +- 7 files changed, 157 insertions(+), 88 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 8977bab7..01757f28 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -1224,7 +1224,7 @@ ReturnValue_t CoreController::handleProtInfoUpdateLine(std::string nextLine) { } } wordIdx++; - if(wordIdx >= 10) { + if (wordIdx >= 10) { break; } } diff --git a/common/config/eive/definitions.h b/common/config/eive/definitions.h index 3990ac26..99ce4437 100644 --- a/common/config/eive/definitions.h +++ b/common/config/eive/definitions.h @@ -83,7 +83,7 @@ static constexpr float SCHED_BLOCK_7_PERIOD = static_cast(SCHED_BLOCK_7_R static constexpr float SCHED_BLOCK_8_PERIOD = static_cast(SCHED_BLOCK_8_PLPCDU_MS) / 400.0; static constexpr float SCHED_BLOCK_9_PERIOD = static_cast(SCHED_BLOCK_9_RAD_SENS_MS) / 400.0; -} // namespace acs +} // namespace spiSched } // namespace config diff --git a/mission/core/pollingSeqTables.cpp b/mission/core/pollingSeqTables.cpp index 780b0e7f..88b5b95a 100644 --- a/mission/core/pollingSeqTables.cpp +++ b/mission/core/pollingSeqTables.cpp @@ -251,53 +251,77 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SUS_0_N_LOC_XFYFZM_PT_XF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_0_N_LOC_XFYFZM_PT_XF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_1_N_LOC_XBYFZM_PT_XB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_1_N_LOC_XBYFZM_PT_XB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_2_N_LOC_XFYBZB_PT_YB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_2_N_LOC_XFYBZB_PT_YB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_3_N_LOC_XFYBZF_PT_YF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_3_N_LOC_XFYBZF_PT_YF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_4_N_LOC_XMYFZF_PT_ZF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_4_N_LOC_XMYFZF_PT_ZF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_5_N_LOC_XFYMZB_PT_ZB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_5_N_LOC_XFYMZB_PT_ZB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_6_R_LOC_XFYBZM_PT_XF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_6_R_LOC_XFYBZM_PT_XF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_7_R_LOC_XBYBZM_PT_XB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_7_R_LOC_XBYBZM_PT_XB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_8_R_LOC_XBYBZB_PT_YB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_8_R_LOC_XBYBZB_PT_YB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_9_R_LOC_XBYBZB_PT_YF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_9_R_LOC_XBYBZB_PT_YF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_10_N_LOC_XMYBZF_PT_ZF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_10_N_LOC_XMYBZF_PT_ZF, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SUS_11_R_LOC_XBYMZB_PT_ZB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_11_R_LOC_XBYMZB_PT_ZB, - length * config::spiSched::SCHED_BLOCK_1_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_1_PERIOD, + DeviceHandlerIF::GET_READ); } if (cfg.scheduleStr) { @@ -313,15 +337,20 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg if (cfg.scheduleAcsBoard) { if (enableAside) { // A side - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, @@ -331,23 +360,31 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, - length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::GET_READ); } if (enableBside) { // B side - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, @@ -357,11 +394,14 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, - length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::GET_READ); } if (enableAside) { thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, @@ -371,21 +411,29 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, - length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); - - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::GYRO_0_ADIS_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); } if (enableBside) { @@ -396,21 +444,29 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::GYRO_2_ADIS_HANDLER, - length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::GYRO_2_ADIS_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::GYRO_2_ADIS_HANDLER, - length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); - - thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_2_PERIOD, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::GYRO_2_ADIS_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, length * config::spiSched::SCHED_BLOCK_3_PERIOD, + thisSequence->addSlot(objects::GYRO_2_ADIS_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::GET_READ); + + thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_2_PERIOD, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::GYRO_3_L3G_HANDLER, + length * config::spiSched::SCHED_BLOCK_3_PERIOD, DeviceHandlerIF::GET_READ); } } @@ -429,7 +485,8 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg imtq::ComStep::READ_MEASURE_GET); } - thisSequence->addSlot(objects::ACS_CONTROLLER, length * config::spiSched::SCHED_BLOCK_4_PERIOD, 0); + thisSequence->addSlot(objects::ACS_CONTROLLER, length * config::spiSched::SCHED_BLOCK_4_PERIOD, + 0); if (cfg.scheduleImtq) { // This is the torquing cycle. @@ -491,23 +548,34 @@ ReturnValue_t pst::pstTcsAndAcs(FixedTimeslotTaskIF *thisSequence, AcsPstCfg cfg DeviceHandlerIF::GET_READ); } - thisSequence->addSlot(objects::SPI_RTD_COM_IF, length * config::spiSched::SCHED_BLOCK_RTD_PERIOD, 0); + thisSequence->addSlot(objects::SPI_RTD_COM_IF, length * config::spiSched::SCHED_BLOCK_RTD_PERIOD, + 0); #if OBSW_ADD_PL_PCDU == 1 - thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::PLPCDU_HANDLER, length * config::spiSched::SCHED_BLOCK_8_PERIOD, + DeviceHandlerIF::GET_READ); #endif #if OBSW_ADD_RAD_SENSORS == 1 /* Radiation sensor */ - thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * config::spiSched::SCHED_BLOCK_9_PERIOD, + DeviceHandlerIF::GET_READ); #endif return returnvalue::OK; } diff --git a/mission/devices/ImtqHandler.cpp b/mission/devices/ImtqHandler.cpp index fadf5a63..c6dfe955 100644 --- a/mission/devices/ImtqHandler.cpp +++ b/mission/devices/ImtqHandler.cpp @@ -849,7 +849,7 @@ void ImtqHandler::fillCalibratedMtmDataset(const uint8_t* packet) { void ImtqHandler::fillRawMtmDataset(imtq::RawMtmMeasurementSet& set, const uint8_t* packet) { PoolReadGuard rg(&set); - if(rg.getReadResult() != returnvalue::OK) { + if (rg.getReadResult() != returnvalue::OK) { sif::error << "ImtqHandler::fillRawMtmDataset: Lock failure" << std::endl; } unsigned int offset = 2; diff --git a/mission/devices/PcduHandler.cpp b/mission/devices/PcduHandler.cpp index 5ed227cd..f5873fcf 100644 --- a/mission/devices/PcduHandler.cpp +++ b/mission/devices/PcduHandler.cpp @@ -41,7 +41,7 @@ ReturnValue_t PCDUHandler::performOperation(uint8_t counter) { if (pg.getReadResult() == returnvalue::OK) { if (switcherSet.p60Dock5VStack.value != switchState) { triggerEvent(power::SWITCH_HAS_CHANGED, switchState, pcdu::Switches::P60_DOCK_5V_STACK); - MutexGuard mg(pwrLock); + MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); switchStates[pcdu::P60_DOCK_5V_STACK] = switchState; } switcherSet.p60Dock5VStack.setValid(true); @@ -405,7 +405,7 @@ ReturnValue_t PCDUHandler::getSwitchState(uint8_t switchNr) const { uint8_t currentState = 0; { MutexGuard mg(pwrLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - currentState = switchStates[switchNr]; + currentState = switchStates[switchNr]; } if (currentState == 1) { return PowerSwitchIF::SWITCH_ON; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 9f4b35ba..6eb781db 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -3,6 +3,7 @@ #include #include + #include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw/globalfunctions/PeriodicOperationDivider.h" #include "mission/devices/devicedefinitions/acsPolling.h" diff --git a/mission/system/tree/system.cpp b/mission/system/tree/system.cpp index 710698a1..195b6905 100644 --- a/mission/system/tree/system.cpp +++ b/mission/system/tree/system.cpp @@ -93,13 +93,13 @@ void buildSafeSequence(Subsystem& ss, ModeListEntry& eh) { ctxc); // Build SAFE transition 1 - //check(ss.addTable(TableEntry(EIVE_TABLE_SAFE_TRANS_1.first, &EIVE_TABLE_SAFE_TRANS_1.second)), + // check(ss.addTable(TableEntry(EIVE_TABLE_SAFE_TRANS_1.first, &EIVE_TABLE_SAFE_TRANS_1.second)), // ctxc); // Build Safe sequence ihs(EIVE_SEQUENCE_SAFE.second, EIVE_TABLE_SAFE_TGT.first, 0, false); ihs(EIVE_SEQUENCE_SAFE.second, EIVE_TABLE_SAFE_TRANS_0.first, 0, false); - //ihs(EIVE_SEQUENCE_SAFE.second, EIVE_TABLE_SAFE_TRANS_1.first, 0, false); + // ihs(EIVE_SEQUENCE_SAFE.second, EIVE_TABLE_SAFE_TRANS_1.first, 0, false); check(ss.addSequence(SequenceEntry(EIVE_SEQUENCE_SAFE.first, &EIVE_SEQUENCE_SAFE.second, EIVE_SEQUENCE_SAFE.first)), ctxc); @@ -135,13 +135,13 @@ void buildIdleSequence(Subsystem& ss, ModeListEntry& eh) { ctxc); // Build SAFE transition 1 - //check(ss.addTable(TableEntry(EIVE_TABLE_IDLE_TRANS_1.first, &EIVE_TABLE_IDLE_TRANS_1.second)), - // ctxc); + // check(ss.addTable(TableEntry(EIVE_TABLE_IDLE_TRANS_1.first, &EIVE_TABLE_IDLE_TRANS_1.second)), + // ctxc); // Build Safe sequence ihs(EIVE_SEQUENCE_IDLE.second, EIVE_TABLE_IDLE_TGT.first, 0, false); ihs(EIVE_SEQUENCE_IDLE.second, EIVE_TABLE_IDLE_TRANS_0.first, 0, false); - //ihs(EIVE_SEQUENCE_IDLE.second, EIVE_TABLE_IDLE_TRANS_1.first, 0, false); + // ihs(EIVE_SEQUENCE_IDLE.second, EIVE_TABLE_IDLE_TRANS_1.first, 0, false); check(ss.addSequence(SequenceEntry(EIVE_SEQUENCE_IDLE.first, &EIVE_SEQUENCE_IDLE.second, EIVE_SEQUENCE_SAFE.first)), ctxc); From dfb1e88f552d2afada9b8ed68e1a37564e388222 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:32:12 +0100 Subject: [PATCH 03/20] lockslockslocks --- linux/devices/AcsBoardPolling.cpp | 34 +++++++++++------------ linux/devices/AcsBoardPolling.h | 3 ++ mission/config/comCfg.cpp | 4 +-- mission/config/torquer.h | 1 + mission/controller/AcsController.cpp | 3 +- mission/devices/HeaterHandler.cpp | 18 ++++++------ mission/devices/HeaterHandler.h | 5 +++- mission/devices/ImtqHandler.cpp | 3 +- mission/system/objects/Stack5VHandler.cpp | 8 +++--- mission/system/objects/Stack5VHandler.h | 4 +++ 10 files changed, 48 insertions(+), 35 deletions(-) diff --git a/linux/devices/AcsBoardPolling.cpp b/linux/devices/AcsBoardPolling.cpp index 871cfdd0..6a16d816 100644 --- a/linux/devices/AcsBoardPolling.cpp +++ b/linux/devices/AcsBoardPolling.cpp @@ -105,7 +105,7 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != adis.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { adis.type = req->type; @@ -135,7 +135,7 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != gyro.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { std::memcpy(gyro.sensorCfg, req->ctrlRegs, 5); @@ -154,7 +154,7 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != mgm.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { mgm.performStartup = true; @@ -173,7 +173,7 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != mgm.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { mgm.performStartup = true; @@ -218,7 +218,7 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send break; } } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (state == InternalState::IDLE) { state = InternalState::BUSY; semaphore->release(); @@ -238,7 +238,7 @@ ReturnValue_t AcsBoardPolling::readReceivedMessage(CookieIF* cookie, uint8_t** b if (spiCookie == nullptr) { return returnvalue::FAILED; } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); auto handleAdisReply = [&](GyroAdis& gyro) { std::memcpy(&gyro.readerReply, &gyro.ownReply, sizeof(acs::Adis1650XReply)); *buffer = reinterpret_cast(&gyro.readerReply); @@ -297,7 +297,7 @@ void AcsBoardPolling::gyroL3gHandler(GyroL3g& l3g) { acs::SimpleSensorMode mode; bool gyroPerformStartup; { - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); mode = l3g.mode; gyroPerformStartup = l3g.performStartup; } @@ -320,7 +320,7 @@ void AcsBoardPolling::gyroL3gHandler(GyroL3g& l3g) { if (result != returnvalue::OK) { l3g.replyResult = returnvalue::OK; } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); // Cross check configuration as verification that communication is working for (uint8_t idx = 0; idx < 5; idx++) { if (rawReply[idx + 1] != l3g.sensorCfg[idx]) { @@ -345,7 +345,7 @@ void AcsBoardPolling::gyroL3gHandler(GyroL3g& l3g) { l3g.replyResult = returnvalue::FAILED; return; } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); // The regular read function always returns the full sensor config as well. Use that // to verify communications. for (uint8_t idx = 0; idx < 5; idx++) { @@ -444,7 +444,7 @@ void AcsBoardPolling::gyroAdisHandler(GyroAdis& gyro) { bool cdHasTimedOut = false; bool mustPerformStartup = false; { - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); mode = gyro.mode; cdHasTimedOut = gyro.countdown.hasTimedOut(); mustPerformStartup = gyro.performStartup; @@ -478,7 +478,7 @@ void AcsBoardPolling::gyroAdisHandler(GyroAdis& gyro) { gyro.replyResult = returnvalue::FAILED; return; } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); gyro.ownReply.cfgWasSet = true; gyro.ownReply.cfg.diagStat = (rawReply[2] << 8) | rawReply[3]; gyro.ownReply.cfg.filterSetting = (rawReply[4] << 8) | rawReply[5]; @@ -525,7 +525,7 @@ void AcsBoardPolling::gyroAdisHandler(GyroAdis& gyro) { return; } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); gyro.ownReply.dataWasSet = true; gyro.ownReply.cfg.diagStat = rawReply[2] << 8 | rawReply[3]; gyro.ownReply.data.angVelocities[0] = (rawReply[4] << 8) | rawReply[5]; @@ -545,7 +545,7 @@ void AcsBoardPolling::mgmLis3Handler(MgmLis3& mgm) { acs::SimpleSensorMode mode; bool mustPerformStartup = false; { - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); mode = mgm.mode; mustPerformStartup = mgm.performStartup; } @@ -605,7 +605,7 @@ void AcsBoardPolling::mgmLis3Handler(MgmLis3& mgm) { return; } { - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); mgm.ownReply.dataWasSet = true; mgm.ownReply.sensitivity = mgmLis3::getSensitivityFactor(mgmLis3::getSensitivity(mgm.cfg[1])); mgm.ownReply.mgmValuesRaw[0] = @@ -627,7 +627,7 @@ void AcsBoardPolling::mgmLis3Handler(MgmLis3& mgm) { mgm.replyResult = result; return; } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); mgm.ownReply.temperatureWasSet = true; mgm.ownReply.temperatureRaw = (rawReply[2] << 8) | rawReply[1]; } @@ -638,7 +638,7 @@ void AcsBoardPolling::mgmRm3100Handler(MgmRm3100& mgm) { acs::SimpleSensorMode mode; bool mustPerformStartup = false; { - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); mode = mgm.mode; mustPerformStartup = mgm.performStartup; } @@ -712,7 +712,7 @@ void AcsBoardPolling::mgmRm3100Handler(MgmRm3100& mgm) { mgm.replyResult = result; return; } - MutexGuard mg(ipcLock); + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); for (uint8_t idx = 0; idx < 3; idx++) { // Hardcoded, but note that the gain depends on the cycle count // value which is configurable! diff --git a/linux/devices/AcsBoardPolling.h b/linux/devices/AcsBoardPolling.h index 9d642dc8..e3c3bd24 100644 --- a/linux/devices/AcsBoardPolling.h +++ b/linux/devices/AcsBoardPolling.h @@ -22,6 +22,9 @@ class AcsBoardPolling : public SystemObject, private: enum class InternalState { IDLE, BUSY } state = InternalState::IDLE; MutexIF* ipcLock; + static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; + static constexpr uint32_t LOCK_TIMEOUT = 20; + static constexpr char LOCK_CTX[] = "AcsBoardPolling"; SemaphoreIF* semaphore; std::array cmdBuf; diff --git a/mission/config/comCfg.cpp b/mission/config/comCfg.cpp index 9e350a9d..8387214d 100644 --- a/mission/config/comCfg.cpp +++ b/mission/config/comCfg.cpp @@ -9,12 +9,12 @@ MutexIF* DATARATE_LOCK = nullptr; MutexIF* lazyLock(); com::Datarate com::getCurrentDatarate() { - MutexGuard mg(lazyLock()); + MutexGuard mg(lazyLock(), MutexIF::TimeoutType::WAITING, 20, "com"); return DATARATE_CFG_RAW; } void com::setCurrentDatarate(com::Datarate newRate) { - MutexGuard mg(lazyLock()); + MutexGuard mg(lazyLock(), MutexIF::TimeoutType::WAITING, 20, "com"); DATARATE_CFG_RAW = newRate; } diff --git a/mission/config/torquer.h b/mission/config/torquer.h index 8241eb83..bb5a101f 100644 --- a/mission/config/torquer.h +++ b/mission/config/torquer.h @@ -11,6 +11,7 @@ namespace torquer { static constexpr dur_millis_t TORQUE_BUFFER_TIME_MS = 20; static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; static constexpr uint32_t LOCK_TIMEOUT = 20; +static constexpr char LOCK_CTX[] = "torquer"; MutexIF* lazyLock(); extern bool TORQUEING; diff --git a/mission/controller/AcsController.cpp b/mission/controller/AcsController.cpp index 5aa12523..58b9dbfc 100644 --- a/mission/controller/AcsController.cpp +++ b/mission/controller/AcsController.cpp @@ -429,7 +429,8 @@ ReturnValue_t AcsController::commandActuators(int16_t xDipole, int16_t yDipole, uint16_t rampTime) { { PoolReadGuard pg(&dipoleSet); - MutexGuard mg(torquer::lazyLock(), torquer::LOCK_TYPE, torquer::LOCK_TIMEOUT); + MutexGuard mg(torquer::lazyLock(), torquer::LOCK_TYPE, torquer::LOCK_TIMEOUT, + torquer::LOCK_CTX); torquer::NEW_ACTUATION_FLAG = true; dipoleSet.setDipoles(xDipole, yDipole, zDipole, dipoleTorqueDuration); } diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 2cde7f1e..150c4778 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -30,8 +30,8 @@ HeaterHandler::HeaterHandler(object_id_t setObjectId_, GpioIF* gpioInterface_, H if (mainLineSwitcher == nullptr) { throw std::invalid_argument("HeaterHandler::HeaterHandler: Invalid PowerSwitchIF"); } - heaterHealthAndStateMutex = MutexFactory::instance()->createMutex(); - if (heaterHealthAndStateMutex == nullptr) { + handlerLock = MutexFactory::instance()->createMutex(); + if (handlerLock == nullptr) { throw std::runtime_error("HeaterHandler::HeaterHandler: Creating Mutex failed"); } auto mqArgs = MqArgs(setObjectId_, static_cast(this)); @@ -144,7 +144,7 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t if (action == SwitchAction::SET_SWITCH_ON) { HasHealthIF::HealthState health; { - MutexGuard mg(heaterHealthAndStateMutex); + MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); health = heater.healthDevice->getHealth(); } if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY or @@ -270,7 +270,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { } else { triggerEvent(HEATER_WENT_ON, heaterIdx, 0); { - MutexGuard mg(heaterHealthAndStateMutex); + MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); heater.switchState = ON; } } @@ -320,7 +320,7 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) { triggerEvent(GPIO_PULL_LOW_FAILED, result); } else { { - MutexGuard mg(heaterHealthAndStateMutex); + MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); heater.switchState = OFF; } triggerEvent(HEATER_WENT_OFF, heaterIdx, 0); @@ -346,7 +346,7 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) { } HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers switchNr) const { - MutexGuard mg(heaterHealthAndStateMutex); + MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); return heaterVec.at(switchNr).switchState; } @@ -396,7 +396,7 @@ object_id_t HeaterHandler::getObjectId() const { return SystemObject::getObjectI ReturnValue_t HeaterHandler::getAllSwitchStates(std::array& statesBuf) { { - MutexGuard mg(heaterHealthAndStateMutex); + MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { return returnvalue::FAILED; } @@ -409,7 +409,7 @@ ReturnValue_t HeaterHandler::getAllSwitchStates(std::array& stat bool HeaterHandler::allSwitchesOff() { bool allSwitchesOrd = false; - MutexGuard mg(heaterHealthAndStateMutex); + MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); /* Or all switches. As soon one switch is on, allSwitchesOrd will be true */ for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) { allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState; @@ -442,7 +442,7 @@ uint32_t HeaterHandler::getSwitchDelayMs(void) const { return 2000; } HasHealthIF::HealthState HeaterHandler::getHealth(heater::Switchers heater) { auto* healthDev = heaterVec.at(heater).healthDevice; if (healthDev != nullptr) { - MutexGuard mg(heaterHealthAndStateMutex); + MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); return healthDev->getHealth(); } return HasHealthIF::HealthState::FAULTY; diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index ffc38440..42f42abf 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -136,7 +136,10 @@ class HeaterHandler : public ExecutableObjectIF, HeaterMap heaterVec = {}; - MutexIF* heaterHealthAndStateMutex = nullptr; + MutexIF* handlerLock = nullptr; + static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; + static constexpr uint32_t LOCK_TIMEOUT = 20; + static constexpr char LOCK_CTX[] = "HeaterHandler"; HeaterHelper helper; ModeHelper modeHelper; diff --git a/mission/devices/ImtqHandler.cpp b/mission/devices/ImtqHandler.cpp index c6dfe955..4d4f3650 100644 --- a/mission/devices/ImtqHandler.cpp +++ b/mission/devices/ImtqHandler.cpp @@ -214,7 +214,8 @@ ReturnValue_t ImtqHandler::buildCommandFromCommand(DeviceCommandId_t deviceComma << ", y = " << dipoleSet.yDipole.value << ", z = " << dipoleSet.zDipole.value << ", duration = " << dipoleSet.currentTorqueDurationMs.value << std::endl; } - MutexGuard mg(torquer::lazyLock(), torquer::LOCK_TYPE, torquer::LOCK_TIMEOUT); + MutexGuard mg(torquer::lazyLock(), torquer::LOCK_TYPE, torquer::LOCK_TIMEOUT, + torquer::LOCK_CTX); torquer::TORQUEING = true; torquer::TORQUE_COUNTDOWN.setTimeout(dipoleSet.currentTorqueDurationMs.value); rawPacket = commandBuffer; diff --git a/mission/system/objects/Stack5VHandler.cpp b/mission/system/objects/Stack5VHandler.cpp index 1a3141c4..6c3c94d9 100644 --- a/mission/system/objects/Stack5VHandler.cpp +++ b/mission/system/objects/Stack5VHandler.cpp @@ -5,7 +5,7 @@ Stack5VHandler::Stack5VHandler(PowerSwitchIF& switcher) : switcher(switcher) { } ReturnValue_t Stack5VHandler::deviceToOn(StackCommander commander, bool updateStates) { - MutexGuard mg(stackLock); + MutexGuard mg(stackLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (updateStates) { updateInternalStates(); } @@ -27,7 +27,7 @@ ReturnValue_t Stack5VHandler::deviceToOn(StackCommander commander, bool updateSt } ReturnValue_t Stack5VHandler::deviceToOff(StackCommander commander, bool updateStates) { - MutexGuard mg(stackLock); + MutexGuard mg(stackLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (updateStates) { updateInternalStates(); } @@ -55,12 +55,12 @@ ReturnValue_t Stack5VHandler::deviceToOff(StackCommander commander, bool updateS } bool Stack5VHandler::isSwitchOn() { - MutexGuard mg(stackLock); + MutexGuard mg(stackLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); return updateInternalStates(); } void Stack5VHandler::update() { - MutexGuard mg(stackLock); + MutexGuard mg(stackLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); updateInternalStates(); } diff --git a/mission/system/objects/Stack5VHandler.h b/mission/system/objects/Stack5VHandler.h index 46fc963a..364d744b 100644 --- a/mission/system/objects/Stack5VHandler.h +++ b/mission/system/objects/Stack5VHandler.h @@ -21,7 +21,11 @@ class Stack5VHandler { void update(); private: + static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; + static constexpr uint32_t LOCK_TIMEOUT = 20; + MutexIF* stackLock; + static constexpr char LOCK_CTX[] = "Stack5VHandler"; PowerSwitchIF& switcher; bool switchIsOn = false; bool targetState = false; From 7b571bc007202e1fd1a2691c5fd7d6befe8d45d5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:38:20 +0100 Subject: [PATCH 04/20] refactore more lock handling --- fsfw | 2 +- linux/devices/Max31865RtdPolling.cpp | 14 +++++++------- linux/devices/Max31865RtdPolling.h | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fsfw b/fsfw index f8409754..245886c5 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit f84097543e59a3564eae4ac19b7118102728c8a9 +Subproject commit 245886c55500b9e70ba71eab68c46d44af9f6836 diff --git a/linux/devices/Max31865RtdPolling.cpp b/linux/devices/Max31865RtdPolling.cpp index e59c2ef2..3071975d 100644 --- a/linux/devices/Max31865RtdPolling.cpp +++ b/linux/devices/Max31865RtdPolling.cpp @@ -19,7 +19,7 @@ static constexpr uint8_t BASE_CFG = Max31865RtdPolling::Max31865RtdPolling(object_id_t objectId, SpiComIF* lowLevelComIF, GpioIF* gpioIF) : SystemObject(objectId), rtds(EiveMax31855::NUM_RTDS), comIF(lowLevelComIF), gpioIF(gpioIF) { - readerMutex = MutexFactory::instance()->createMutex(); + readerLock = MutexFactory::instance()->createMutex(); } ReturnValue_t Max31865RtdPolling::performOperation(uint8_t operationCode) { @@ -63,7 +63,7 @@ bool Max31865RtdPolling::periodicInitHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicInitHandling: Mutex lock failed" << std::endl; return false; @@ -119,7 +119,7 @@ ReturnValue_t Max31865RtdPolling::periodicReadReqHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicReadReqHandling: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -144,7 +144,7 @@ ReturnValue_t Max31865RtdPolling::periodicReadHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicReadHandling: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -200,7 +200,7 @@ ReturnValue_t Max31865RtdPolling::initializeInterface(CookieIF* cookie) { throw std::invalid_argument("Invalid RTD index"); } rtds[rtdCookie->idx] = rtdCookie; - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (dbLen == 0) { dbLen = rtdCookie->db.getSerializedSize(); } @@ -216,7 +216,7 @@ ReturnValue_t Max31865RtdPolling::sendMessage(CookieIF* cookie, const uint8_t* s if (sendLen < 1) { return returnvalue::OK; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::sendMessage: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -312,7 +312,7 @@ ReturnValue_t Max31865RtdPolling::requestReceiveMessage(CookieIF* cookie, size_t ReturnValue_t Max31865RtdPolling::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { // TODO: Emit warning return returnvalue::FAILED; diff --git a/linux/devices/Max31865RtdPolling.h b/linux/devices/Max31865RtdPolling.h index a34c8e53..da27de68 100644 --- a/linux/devices/Max31865RtdPolling.h +++ b/linux/devices/Max31865RtdPolling.h @@ -48,7 +48,10 @@ class Max31865RtdPolling : public SystemObject, std::vector rtds; std::array cmdBuf = {}; size_t dbLen = 0; - MutexIF* readerMutex; + MutexIF* readerLock; + static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; + static constexpr uint32_t LOCK_TIMEOUT = 20; + static constexpr char LOCK_CTX[] = "Max31865RtdPolling"; SpiComIF* comIF; GpioIF* gpioIF; From ad4ab9835652dd057692aa5aa1ba04e134dbdc1e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:41:09 +0100 Subject: [PATCH 05/20] lock context for sd card manager --- bsp_q7s/fs/SdCardManager.cpp | 18 +++++++++--------- bsp_q7s/fs/SdCardManager.h | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bsp_q7s/fs/SdCardManager.cpp b/bsp_q7s/fs/SdCardManager.cpp index 45c9f0d0..1663f7cc 100644 --- a/bsp_q7s/fs/SdCardManager.cpp +++ b/bsp_q7s/fs/SdCardManager.cpp @@ -195,7 +195,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) { ReturnValue_t SdCardManager::getSdCardsStatus(SdStatePair& active) { using namespace std; - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (not filesystem::exists(SD_STATE_FILE)) { return STATUS_FILE_NEXISTS; } @@ -378,7 +378,7 @@ void SdCardManager::processSdStatusLine(std::pair& act } std::optional SdCardManager::getPreferredSdCard() const { - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); auto res = mg.getLockResult(); if (res != returnvalue::OK) { sif::error << "SdCardManager::getPreferredSdCard: Lock error" << std::endl; @@ -387,7 +387,7 @@ std::optional SdCardManager::getPreferredSdCard() const { } ReturnValue_t SdCardManager::setPreferredSdCard(sd::SdCard sdCard) { - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (sdCard == sd::SdCard::BOTH) { return returnvalue::FAILED; } @@ -399,7 +399,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) { return CommandExecutor::COMMAND_PENDING; } - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); // Use q7hw utility and pipe the command output into the state file std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE); cmdExecutor.load(updateCmd, blocking, printCmdOutput); @@ -411,7 +411,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { } const char* SdCardManager::getCurrentMountPrefix() const { - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (currentPrefix.has_value()) { return currentPrefix.value().c_str(); } @@ -464,7 +464,7 @@ void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = p bool SdCardManager::isSdCardUsable(std::optional sdCard) { { - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (markedUnusable) { return false; } @@ -560,7 +560,7 @@ ReturnValue_t SdCardManager::performFsck(sd::SdCard sdcard, bool printOutput, in } void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); sdInfo.active = sdCard; if (sdInfo.active == sd::SdCard::SLOT_0) { currentPrefix = config::SD_0_MOUNT_POINT; @@ -570,7 +570,7 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { } std::optional SdCardManager::getActiveSdCard() const { - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (markedUnusable) { return std::nullopt; } @@ -578,6 +578,6 @@ std::optional SdCardManager::getActiveSdCard() const { } void SdCardManager::markUnusable() { - MutexGuard mg(sdLock, lockType, lockTimeout); + MutexGuard mg(sdLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); markedUnusable = true; } diff --git a/bsp_q7s/fs/SdCardManager.h b/bsp_q7s/fs/SdCardManager.h index 1b538dad..0a7b92c9 100644 --- a/bsp_q7s/fs/SdCardManager.h +++ b/bsp_q7s/fs/SdCardManager.h @@ -224,8 +224,9 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { bool printCmdOutput = true; bool markedUnusable = false; MutexIF* sdLock = nullptr; - MutexIF::TimeoutType lockType = MutexIF::TimeoutType::WAITING; - uint32_t lockTimeout = 40; + static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; + static constexpr uint32_t LOCK_TIMEOUT = 40; + static constexpr char LOCK_CTX[] = "SdCardManager"; SdCardManager(); From f43a93842e9a478929bb00f93852765a629071ac Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:41:49 +0100 Subject: [PATCH 06/20] max31865 lock improvements --- linux/devices/Max31865RtdPolling.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/linux/devices/Max31865RtdPolling.cpp b/linux/devices/Max31865RtdPolling.cpp index 3071975d..004e7c60 100644 --- a/linux/devices/Max31865RtdPolling.cpp +++ b/linux/devices/Max31865RtdPolling.cpp @@ -63,7 +63,7 @@ bool Max31865RtdPolling::periodicInitHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerLock); + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicInitHandling: Mutex lock failed" << std::endl; return false; @@ -119,7 +119,7 @@ ReturnValue_t Max31865RtdPolling::periodicReadReqHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerLock); + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicReadReqHandling: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -144,7 +144,7 @@ ReturnValue_t Max31865RtdPolling::periodicReadHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerLock); + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicReadHandling: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -200,7 +200,7 @@ ReturnValue_t Max31865RtdPolling::initializeInterface(CookieIF* cookie) { throw std::invalid_argument("Invalid RTD index"); } rtds[rtdCookie->idx] = rtdCookie; - MutexGuard mg(readerLock); + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (dbLen == 0) { dbLen = rtdCookie->db.getSerializedSize(); } @@ -216,7 +216,7 @@ ReturnValue_t Max31865RtdPolling::sendMessage(CookieIF* cookie, const uint8_t* s if (sendLen < 1) { return returnvalue::OK; } - MutexGuard mg(readerLock); + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::sendMessage: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -312,7 +312,7 @@ ReturnValue_t Max31865RtdPolling::requestReceiveMessage(CookieIF* cookie, size_t ReturnValue_t Max31865RtdPolling::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { - MutexGuard mg(readerLock); + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { // TODO: Emit warning return returnvalue::FAILED; From 25dfb54be01d1164b8976e5f83b97066e4c08915 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:44:07 +0100 Subject: [PATCH 07/20] bump changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index baad285b..ed671555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ will consitute of a breaking change warranting a new major release: - Moved polling of all SPI parts to the same PST. - Allow quicker transition for the EIVE system component by allowing consecutive TCS and ACS component commanding again. +- Changed a lot of lock guards to use timeouts ## Fixed From 1cf3fbaabe8a45bcf40feed4c9428fa823b862f2 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 3 Mar 2023 10:48:59 +0100 Subject: [PATCH 08/20] fixed that mgm value was overwritten in wrong unit --- mission/controller/acs/control/SafeCtrl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mission/controller/acs/control/SafeCtrl.cpp b/mission/controller/acs/control/SafeCtrl.cpp index 3a69e343..9ef9acf5 100644 --- a/mission/controller/acs/control/SafeCtrl.cpp +++ b/mission/controller/acs/control/SafeCtrl.cpp @@ -94,7 +94,8 @@ ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBVal } // change unit from uT to T - VectorOperations::mulScalar(magFieldB, 1e-6, magFieldB, 3); + double magFieldBT[3] = {0,0,0}; + VectorOperations::mulScalar(magFieldB, 1e-6, magFieldBT, 3); // normalize sunDir and magDir double magDirB[3] = {0, 0, 0}; From ff50203fbb463bfb66df5715b47fa2ba3e7e4d21 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 11:04:08 +0100 Subject: [PATCH 09/20] smaller lock tweaks --- linux/devices/AcsBoardPolling.cpp | 87 +++++++++++---------- mission/controller/acs/control/SafeCtrl.cpp | 9 ++- tmtc | 2 +- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/linux/devices/AcsBoardPolling.cpp b/linux/devices/AcsBoardPolling.cpp index 6a16d816..aad802d2 100644 --- a/linux/devices/AcsBoardPolling.cpp +++ b/linux/devices/AcsBoardPolling.cpp @@ -25,7 +25,7 @@ AcsBoardPolling::AcsBoardPolling(object_id_t objectId, SpiComIF& lowLevelComIF, ReturnValue_t AcsBoardPolling::performOperation(uint8_t operationCode) { while (true) { - ipcLock->lockMutex(); + ipcLock->lockMutex(LOCK_TYPE, LOCK_TIMEOUT); state = InternalState::IDLE; ipcLock->unlockMutex(); semaphore->acquire(); @@ -173,7 +173,6 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != mgm.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { mgm.performStartup = true; @@ -184,45 +183,47 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send } return returnvalue::OK; }; - switch (spiCookie->getChipSelectPin()) { - case (gpioIds::MGM_0_LIS3_CS): { - handleLis3Request(mgm0Lis3); - break; + { + MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); + switch (spiCookie->getChipSelectPin()) { + case (gpioIds::MGM_0_LIS3_CS): { + handleLis3Request(mgm0Lis3); + break; + } + case (gpioIds::MGM_1_RM3100_CS): { + handleRm3100Request(mgm1Rm3100); + break; + } + case (gpioIds::MGM_2_LIS3_CS): { + handleLis3Request(mgm2Lis3); + break; + } + case (gpioIds::MGM_3_RM3100_CS): { + handleRm3100Request(mgm3Rm3100); + break; + } + case (gpioIds::GYRO_0_ADIS_CS): { + handleAdisRequest(gyro0Adis); + break; + } + case (gpioIds::GYRO_2_ADIS_CS): { + handleAdisRequest(gyro2Adis); + break; + } + case (gpioIds::GYRO_1_L3G_CS): { + handleL3gRequest(gyro1L3g); + break; + } + case (gpioIds::GYRO_3_L3G_CS): { + handleL3gRequest(gyro3L3g); + break; + } } - case (gpioIds::MGM_1_RM3100_CS): { - handleRm3100Request(mgm1Rm3100); - break; - } - case (gpioIds::MGM_2_LIS3_CS): { - handleLis3Request(mgm2Lis3); - break; - } - case (gpioIds::MGM_3_RM3100_CS): { - handleRm3100Request(mgm3Rm3100); - break; - } - case (gpioIds::GYRO_0_ADIS_CS): { - handleAdisRequest(gyro0Adis); - break; - } - case (gpioIds::GYRO_2_ADIS_CS): { - handleAdisRequest(gyro2Adis); - break; - } - case (gpioIds::GYRO_1_L3G_CS): { - handleL3gRequest(gyro1L3g); - break; - } - case (gpioIds::GYRO_3_L3G_CS): { - handleL3gRequest(gyro3L3g); - break; + if (state == InternalState::IDLE) { + state = InternalState::BUSY; } } - MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - if (state == InternalState::IDLE) { - state = InternalState::BUSY; - semaphore->release(); - } + semaphore->release(); return returnvalue::OK; } @@ -294,8 +295,8 @@ ReturnValue_t AcsBoardPolling::readReceivedMessage(CookieIF* cookie, uint8_t** b void AcsBoardPolling::gyroL3gHandler(GyroL3g& l3g) { ReturnValue_t result; - acs::SimpleSensorMode mode; - bool gyroPerformStartup; + acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF; + bool gyroPerformStartup = false; { MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); mode = l3g.mode; @@ -440,7 +441,7 @@ ReturnValue_t AcsBoardPolling::readAdisCfg(SpiCookie& cookie, size_t transferLen void AcsBoardPolling::gyroAdisHandler(GyroAdis& gyro) { ReturnValue_t result; - acs::SimpleSensorMode mode; + acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF; bool cdHasTimedOut = false; bool mustPerformStartup = false; { @@ -542,7 +543,7 @@ void AcsBoardPolling::gyroAdisHandler(GyroAdis& gyro) { void AcsBoardPolling::mgmLis3Handler(MgmLis3& mgm) { ReturnValue_t result; - acs::SimpleSensorMode mode; + acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF; bool mustPerformStartup = false; { MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); @@ -635,7 +636,7 @@ void AcsBoardPolling::mgmLis3Handler(MgmLis3& mgm) { void AcsBoardPolling::mgmRm3100Handler(MgmRm3100& mgm) { ReturnValue_t result; - acs::SimpleSensorMode mode; + acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF; bool mustPerformStartup = false; { MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); diff --git a/mission/controller/acs/control/SafeCtrl.cpp b/mission/controller/acs/control/SafeCtrl.cpp index 3a69e343..e6b45318 100644 --- a/mission/controller/acs/control/SafeCtrl.cpp +++ b/mission/controller/acs/control/SafeCtrl.cpp @@ -84,10 +84,11 @@ ReturnValue_t SafeCtrl::safeMekf(timeval now, double *quatBJ, bool quatBJValid, } // Will be the version in worst case scenario in event of no working MEKF (nor GYRs) -ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBValid, double *sunRateB, - bool sunRateBValid, double *magFieldB, bool magFieldBValid, - double *magRateB, bool magRateBValid, double *sunDirRef, - double *satRateRef, double *outputAngle, double *outputMagMomB) { +ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBValid, + double *sunRateB, bool sunRateBValid, double *magFieldB, + bool magFieldBValid, double *magRateB, bool magRateBValid, + double *sunDirRef, double *satRateRef, double *outputAngle, + double *outputMagMomB) { // Check for invalid Inputs if (!susDirBValid || !magFieldBValid || !magRateBValid) { return returnvalue::FAILED; diff --git a/tmtc b/tmtc index 77fbcede..74e6d6fe 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 77fbcede10d44fd15dc7d5d1b3965f06c6a8e7fc +Subproject commit 74e6d6fe5f10121e8444662a79fa10fada3d978c From 60afb573a0f47eba4865b99d2f338ec487c40250 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 11:06:30 +0100 Subject: [PATCH 10/20] comment --- linux/devices/AcsBoardPolling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/devices/AcsBoardPolling.cpp b/linux/devices/AcsBoardPolling.cpp index aad802d2..a9128242 100644 --- a/linux/devices/AcsBoardPolling.cpp +++ b/linux/devices/AcsBoardPolling.cpp @@ -39,7 +39,7 @@ ReturnValue_t AcsBoardPolling::performOperation(uint8_t operationCode) { mgmRm3100Handler(mgm3Rm3100); mgmLis3Handler(mgm0Lis3); mgmLis3Handler(mgm2Lis3); - // To prevent task being not reactivated by tardy tasks + // To prevent task being reactivated by tardy tasks TaskFactory::delayTask(20); } return returnvalue::OK; From fcba76b7f1098e3d062e8f32c3340cd77caf116a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 11:43:47 +0100 Subject: [PATCH 11/20] rework lock handling in rtd handler --- linux/devices/Max31865RtdPolling.cpp | 82 +++++++++++---------- linux/devices/Max31865RtdPolling.h | 5 +- mission/controller/acs/control/SafeCtrl.cpp | 9 ++- tmtc | 2 +- 4 files changed, 54 insertions(+), 44 deletions(-) diff --git a/linux/devices/Max31865RtdPolling.cpp b/linux/devices/Max31865RtdPolling.cpp index 004e7c60..6cfb2000 100644 --- a/linux/devices/Max31865RtdPolling.cpp +++ b/linux/devices/Max31865RtdPolling.cpp @@ -56,19 +56,28 @@ bool Max31865RtdPolling::rtdIsActive(uint8_t idx) { return false; } -bool Max31865RtdPolling::periodicInitHandling() { +ReturnValue_t Max31865RtdPolling::periodicInitHandling() { using namespace MAX31865; ReturnValue_t result = returnvalue::OK; for (auto& rtd : rtds) { if (rtd == nullptr) { continue; } - MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - if (mg.getLockResult() != returnvalue::OK) { - sif::warning << "Max31865RtdReader::periodicInitHandling: Mutex lock failed" << std::endl; - return false; + bool mustPerformInitHandling = false; + bool doWriteLowThreshold = false; + bool doWriteHighThreshold = false; + { + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); + if (mg.getLockResult() != returnvalue::OK) { + sif::warning << "Max31865RtdReader::periodicInitHandling: Mutex lock failed" << std::endl; + continue; + } + mustPerformInitHandling = + (rtd->on or rtd->db.active) and not rtd->db.configured and rtd->cd.hasTimedOut(); + doWriteHighThreshold = rtd->writeHighThreshold; + doWriteLowThreshold = rtd->writeLowThreshold; } - if ((rtd->on or rtd->db.active) and not rtd->db.configured and rtd->cd.hasTimedOut()) { + if (mustPerformInitHandling) { // Please note that using the manual CS lock wrapper here is problematic. Might be a SPI // or hardware specific issue where the CS needs to be pulled high and then low again // between transfers @@ -77,13 +86,13 @@ bool Max31865RtdPolling::periodicInitHandling() { handleSpiError(rtd, result, "writeCfgReg"); continue; } - if (rtd->writeLowThreshold) { + if (doWriteLowThreshold) { result = writeLowThreshold(rtd->spiCookie, rtd->lowThreshold); if (result != returnvalue::OK) { handleSpiError(rtd, result, "writeLowThreshold"); } } - if (rtd->writeHighThreshold) { + if (doWriteHighThreshold) { result = writeHighThreshold(rtd->spiCookie, rtd->highThreshold); if (result != returnvalue::OK) { handleSpiError(rtd, result, "writeHighThreshold"); @@ -93,23 +102,12 @@ bool Max31865RtdPolling::periodicInitHandling() { if (result != returnvalue::OK) { handleSpiError(rtd, result, "clearFaultStatus"); } + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); rtd->db.configured = true; rtd->db.active = true; } } - bool someRtdUsable = false; - for (auto& rtd : rtds) { - if (rtd == nullptr) { - continue; - } - if (rtdIsActive(rtd->idx)) { -#if OBSW_RTD_AUTO_MODE == 0 - result = writeBiasSel(Bias::ON, rtd->spiCookie, BASE_CFG); -#endif - someRtdUsable = true; - } - } - return someRtdUsable; + return returnvalue::OK; } ReturnValue_t Max31865RtdPolling::periodicReadReqHandling() { @@ -119,12 +117,8 @@ ReturnValue_t Max31865RtdPolling::periodicReadReqHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - if (mg.getLockResult() != returnvalue::OK) { - sif::warning << "Max31865RtdReader::periodicReadReqHandling: Mutex lock failed" << std::endl; - return returnvalue::FAILED; - } - if (rtdIsActive(rtd->idx)) { + updateActiveRtdsArray(); + if (activeRtdsArray[rtd->idx]) { ReturnValue_t result = writeCfgReg(rtd->spiCookie, BASE_CFG | (1 << CfgBitPos::ONE_SHOT)); if (result != returnvalue::OK) { handleSpiError(rtd, result, "writeCfgReg"); @@ -144,12 +138,8 @@ ReturnValue_t Max31865RtdPolling::periodicReadHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); - if (mg.getLockResult() != returnvalue::OK) { - sif::warning << "Max31865RtdReader::periodicReadHandling: Mutex lock failed" << std::endl; - return returnvalue::FAILED; - } - if (rtdIsActive(rtd->idx)) { + updateActiveRtdsArray(); + if (activeRtdsArray[rtd->idx]) { // Please note that using the manual CS lock wrapper here is problematic. Might be a SPI // or hardware specific issue where the CS needs to be pulled high and then low again // between transfers @@ -166,6 +156,7 @@ ReturnValue_t Max31865RtdPolling::periodicReadHandling() { handleSpiError(rtd, result, "readRtdVal"); continue; } + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (faultBitSet) { rtd->db.faultBitSet = faultBitSet; } @@ -212,6 +203,10 @@ ReturnValue_t Max31865RtdPolling::sendMessage(CookieIF* cookie, const uint8_t* s if (cookie == nullptr) { return returnvalue::FAILED; } + auto* rtdCookie = dynamic_cast(cookie); + if (rtdCookie == nullptr) { + return returnvalue::FAILED; + } // Empty command.. don't fail for now if (sendLen < 1) { return returnvalue::OK; @@ -221,7 +216,6 @@ ReturnValue_t Max31865RtdPolling::sendMessage(CookieIF* cookie, const uint8_t* s sif::warning << "Max31865RtdReader::sendMessage: Mutex lock failed" << std::endl; return returnvalue::FAILED; } - auto* rtdCookie = dynamic_cast(cookie); uint8_t cmdRaw = sendData[0]; if (cmdRaw > EiveMax31855::RtdCommands::NUM_CMDS) { sif::warning << "Max31865RtdReader::sendMessage: Invalid command" << std::endl; @@ -312,15 +306,15 @@ ReturnValue_t Max31865RtdPolling::requestReceiveMessage(CookieIF* cookie, size_t ReturnValue_t Max31865RtdPolling::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { + auto* rtdCookie = dynamic_cast(cookie); + if (rtdCookie == nullptr) { + return returnvalue::FAILED; + } MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (mg.getLockResult() != returnvalue::OK) { // TODO: Emit warning return returnvalue::FAILED; } - auto* rtdCookie = dynamic_cast(cookie); - if (rtdCookie == nullptr) { - return returnvalue::FAILED; - } uint8_t* exchangePtr = rtdCookie->exchangeBuf.data(); size_t serLen = 0; auto result = rtdCookie->db.serialize(&exchangePtr, &serLen, rtdCookie->exchangeBuf.size(), @@ -461,6 +455,18 @@ ReturnValue_t Max31865RtdPolling::readNFromReg(SpiCookie* cookie, uint8_t reg, s return returnvalue::OK; } +ReturnValue_t Max31865RtdPolling::updateActiveRtdsArray() { + MutexGuard mg(readerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); + if (mg.getLockResult() != returnvalue::OK) { + sif::warning << "Max31865RtdReader::periodicReadHandling: Mutex lock failed" << std::endl; + return returnvalue::FAILED; + } + for (const auto& rtd : rtds) { + activeRtdsArray[rtd->idx] = rtdIsActive(rtd->idx); + } + return returnvalue::OK; +} + ReturnValue_t Max31865RtdPolling::handleSpiError(Max31865ReaderCookie* cookie, ReturnValue_t result, const char* ctx) { cookie->db.spiErrorCount.value += 1; diff --git a/linux/devices/Max31865RtdPolling.h b/linux/devices/Max31865RtdPolling.h index da27de68..ef73fb8b 100644 --- a/linux/devices/Max31865RtdPolling.h +++ b/linux/devices/Max31865RtdPolling.h @@ -47,6 +47,7 @@ class Max31865RtdPolling : public SystemObject, private: std::vector rtds; std::array cmdBuf = {}; + std::array activeRtdsArray{}; size_t dbLen = 0; MutexIF* readerLock; static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; @@ -59,7 +60,7 @@ class Max31865RtdPolling : public SystemObject, uint32_t csTimeoutMs = spi::RTD_CS_TIMEOUT; MutexIF* csLock = nullptr; - bool periodicInitHandling(); + ReturnValue_t periodicInitHandling(); ReturnValue_t periodicReadReqHandling(); ReturnValue_t periodicReadHandling(); @@ -84,6 +85,8 @@ class Max31865RtdPolling : public SystemObject, ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override; ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override; + ReturnValue_t updateActiveRtdsArray(); + ReturnValue_t handleSpiError(Max31865ReaderCookie* cookie, ReturnValue_t result, const char* ctx); }; diff --git a/mission/controller/acs/control/SafeCtrl.cpp b/mission/controller/acs/control/SafeCtrl.cpp index 3a69e343..e6b45318 100644 --- a/mission/controller/acs/control/SafeCtrl.cpp +++ b/mission/controller/acs/control/SafeCtrl.cpp @@ -84,10 +84,11 @@ ReturnValue_t SafeCtrl::safeMekf(timeval now, double *quatBJ, bool quatBJValid, } // Will be the version in worst case scenario in event of no working MEKF (nor GYRs) -ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBValid, double *sunRateB, - bool sunRateBValid, double *magFieldB, bool magFieldBValid, - double *magRateB, bool magRateBValid, double *sunDirRef, - double *satRateRef, double *outputAngle, double *outputMagMomB) { +ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBValid, + double *sunRateB, bool sunRateBValid, double *magFieldB, + bool magFieldBValid, double *magRateB, bool magRateBValid, + double *sunDirRef, double *satRateRef, double *outputAngle, + double *outputMagMomB) { // Check for invalid Inputs if (!susDirBValid || !magFieldBValid || !magRateBValid) { return returnvalue::FAILED; diff --git a/tmtc b/tmtc index 77fbcede..74e6d6fe 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 77fbcede10d44fd15dc7d5d1b3965f06c6a8e7fc +Subproject commit 74e6d6fe5f10121e8444662a79fa10fada3d978c From ec2ec32af420e3004e09e5915c013142a45e7a88 Mon Sep 17 00:00:00 2001 From: meggert Date: Fri, 3 Mar 2023 11:56:31 +0100 Subject: [PATCH 12/20] actually use the stuff i wrote --- mission/controller/acs/control/SafeCtrl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mission/controller/acs/control/SafeCtrl.cpp b/mission/controller/acs/control/SafeCtrl.cpp index 9ef9acf5..32a77591 100644 --- a/mission/controller/acs/control/SafeCtrl.cpp +++ b/mission/controller/acs/control/SafeCtrl.cpp @@ -99,7 +99,7 @@ ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBVal // normalize sunDir and magDir double magDirB[3] = {0, 0, 0}; - VectorOperations::normalize(magFieldB, magDirB, 3); + VectorOperations::normalize(magFieldBT, magDirB, 3); VectorOperations::normalize(susDirB, susDirB, 3); // Cosinus angle between sunDir and magDir @@ -160,8 +160,8 @@ ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBVal // Magnetic moment double magMomB[3] = {0, 0, 0}; double crossMagFieldTorque[3] = {0, 0, 0}; - VectorOperations::cross(magFieldB, torqueB, crossMagFieldTorque); - double magMomFactor = pow(VectorOperations::norm(magFieldB, 3), 2); + VectorOperations::cross(magFieldBT, torqueB, crossMagFieldTorque); + double magMomFactor = pow(VectorOperations::norm(magFieldBT, 3), 2); VectorOperations::mulScalar(crossMagFieldTorque, 1 / magMomFactor, magMomB, 3); std::memcpy(outputMagMomB, magMomB, 3 * sizeof(double)); From 7a7f25a63837f530a835358693a9e3f99a037187 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 3 Mar 2023 14:36:52 +0100 Subject: [PATCH 13/20] lets see if this fixes issues --- CHANGELOG.md | 3 +++ fsfw | 2 +- linux/devices/AcsBoardPolling.cpp | 1 - linux/devices/GpsHyperionLinuxController.cpp | 5 ++--- linux/devices/GpsHyperionLinuxController.h | 4 ++-- linux/devices/Max31865RtdPolling.cpp | 2 -- linux/devices/RwPollingTask.cpp | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3fea248..496d9cfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ will consitute of a breaking change warranting a new major release: - IMTQ: Sets were filled with wrong data, e.g. Raw MTM was filled with calibrated MTM measurements. - Set RM3100 dataset to valid. - Fixed units in calculation of ACS control laws safe and detumble. +- Bump FSFW for change in Countdown: Use system clock instead of reading uptime from file + to prevent possible race condition. +- GPS: No fix for 30 minutes considered a faulty now instead of 5 hours. ## Added diff --git a/fsfw b/fsfw index 245886c5..78cf0031 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 245886c55500b9e70ba71eab68c46d44af9f6836 +Subproject commit 78cf00315d5bb9a05d47976a564d16c5978f1f41 diff --git a/linux/devices/AcsBoardPolling.cpp b/linux/devices/AcsBoardPolling.cpp index 6a16d816..5685cbde 100644 --- a/linux/devices/AcsBoardPolling.cpp +++ b/linux/devices/AcsBoardPolling.cpp @@ -110,7 +110,6 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send if (req->mode == acs::SimpleSensorMode::NORMAL) { adis.type = req->type; adis.countdown.setTimeout(adis1650x::START_UP_TIME); - adis.countdown.resetTimer(); if (adis.type == adis1650x::Type::ADIS16507) { adis.ownReply.data.accelScaling = adis1650x::ACCELEROMETER_RANGE_16507; } else if (adis.type == adis1650x::Type::ADIS16505) { diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index 3b396504..e3982a1c 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -20,7 +20,6 @@ GpsHyperionLinuxController::GpsHyperionLinuxController(object_id_t objectId, object_id_t parentId, bool debugHyperionGps) : ExtendedControllerBase(objectId), gpsSet(this), debugHyperionGps(debugHyperionGps) { - timeUpdateCd.resetTimer(); } GpsHyperionLinuxController::~GpsHyperionLinuxController() { @@ -196,8 +195,8 @@ ReturnValue_t GpsHyperionLinuxController::handleGpsReadData() { if (mode != MODE_OFF) { if (maxTimeToReachFix.hasTimedOut() and oneShotSwitches.cantGetFixSwitch) { sif::warning << "GpsHyperionLinuxController: No mode could be set in allowed " - << maxTimeToReachFix.timeout / 1000 << " seconds" << std::endl; - triggerEvent(GpsHyperion::CANT_GET_FIX, maxTimeToReachFix.timeout); + << maxTimeToReachFix.getTimeoutMs() / 1000 << " seconds" << std::endl; + triggerEvent(GpsHyperion::CANT_GET_FIX, maxTimeToReachFix.getTimeoutMs()); oneShotSwitches.cantGetFixSwitch = false; } modeIsSet = false; diff --git a/linux/devices/GpsHyperionLinuxController.h b/linux/devices/GpsHyperionLinuxController.h index df08d8a4..f00724bd 100644 --- a/linux/devices/GpsHyperionLinuxController.h +++ b/linux/devices/GpsHyperionLinuxController.h @@ -23,7 +23,8 @@ */ class GpsHyperionLinuxController : public ExtendedControllerBase { public: - static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 60 * 5; + // 30 minutes + static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 30; enum ReadModes { SHM = 0, SOCKET = 1 }; @@ -79,7 +80,6 @@ class GpsHyperionLinuxController : public ExtendedControllerBase { bool debugHyperionGps = false; int32_t noModeSetCntr = 0; - Countdown timeUpdateCd = Countdown(60); // Returns true if the function should be called again or false if other // controller handling can be done. diff --git a/linux/devices/Max31865RtdPolling.cpp b/linux/devices/Max31865RtdPolling.cpp index 004e7c60..53aad8fe 100644 --- a/linux/devices/Max31865RtdPolling.cpp +++ b/linux/devices/Max31865RtdPolling.cpp @@ -240,7 +240,6 @@ ReturnValue_t Max31865RtdPolling::sendMessage(CookieIF* cookie, const uint8_t* s case (EiveMax31855::RtdCommands::ON): { if (not rtdCookie->on) { rtdCookie->cd.setTimeout(MAX31865::WARMUP_MS); - rtdCookie->cd.resetTimer(); rtdCookie->on = true; rtdCookie->db.active = false; rtdCookie->db.configured = false; @@ -253,7 +252,6 @@ ReturnValue_t Max31865RtdPolling::sendMessage(CookieIF* cookie, const uint8_t* s case (EiveMax31855::RtdCommands::ACTIVE): { if (not rtdCookie->on) { rtdCookie->cd.setTimeout(MAX31865::WARMUP_MS); - rtdCookie->cd.resetTimer(); rtdCookie->on = true; rtdCookie->db.active = true; rtdCookie->db.configured = false; diff --git a/linux/devices/RwPollingTask.cpp b/linux/devices/RwPollingTask.cpp index 2d05ac8b..7dff31bb 100644 --- a/linux/devices/RwPollingTask.cpp +++ b/linux/devices/RwPollingTask.cpp @@ -220,7 +220,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf } pullCsLow(gpioId, gpioIF); bool lastByteWasFrameMarker = false; - Countdown cd(3000); + Countdown cd(2000); size_t readIdx = 0; while (true) { From 53133573e137f104543206bf49ec3263fc0e5b06 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 3 Mar 2023 14:58:03 +0100 Subject: [PATCH 14/20] measurement base code and comment --- fsfw | 2 +- linux/devices/AcsBoardPolling.cpp | 21 ++++++++++++-------- linux/devices/GpsHyperionLinuxController.cpp | 3 +-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/fsfw b/fsfw index 78cf0031..64537d44 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 78cf00315d5bb9a05d47976a564d16c5978f1f41 +Subproject commit 64537d442a335500bdc87ff382099de65f0b7aa7 diff --git a/linux/devices/AcsBoardPolling.cpp b/linux/devices/AcsBoardPolling.cpp index 5685cbde..3b35167d 100644 --- a/linux/devices/AcsBoardPolling.cpp +++ b/linux/devices/AcsBoardPolling.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -31,14 +32,18 @@ ReturnValue_t AcsBoardPolling::performOperation(uint8_t operationCode) { semaphore->acquire(); // Give all tasks or the PST some time to submit all consecutive requests. TaskFactory::delayTask(2); - gyroAdisHandler(gyro0Adis); - gyroAdisHandler(gyro2Adis); - gyroL3gHandler(gyro1L3g); - gyroL3gHandler(gyro3L3g); - mgmRm3100Handler(mgm1Rm3100); - mgmRm3100Handler(mgm3Rm3100); - mgmLis3Handler(mgm0Lis3); - mgmLis3Handler(mgm2Lis3); + { + // Measured to take 0-1 ms in debug build. + // Stopwatch watch; + gyroAdisHandler(gyro0Adis); + gyroAdisHandler(gyro2Adis); + gyroL3gHandler(gyro1L3g); + gyroL3gHandler(gyro3L3g); + mgmRm3100Handler(mgm1Rm3100); + mgmRm3100Handler(mgm3Rm3100); + mgmLis3Handler(mgm0Lis3); + mgmLis3Handler(mgm2Lis3); + } // To prevent task being not reactivated by tardy tasks TaskFactory::delayTask(20); } diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index e3982a1c..3beb0d87 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -19,8 +19,7 @@ GpsHyperionLinuxController::GpsHyperionLinuxController(object_id_t objectId, object_id_t parentId, bool debugHyperionGps) - : ExtendedControllerBase(objectId), gpsSet(this), debugHyperionGps(debugHyperionGps) { -} + : ExtendedControllerBase(objectId), gpsSet(this), debugHyperionGps(debugHyperionGps) {} GpsHyperionLinuxController::~GpsHyperionLinuxController() { gps_stream(&gps, WATCH_DISABLE, nullptr); From 59e165be4f95e742b677ae7d7cd553a13a322c80 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 3 Mar 2023 15:10:52 +0100 Subject: [PATCH 15/20] lockfix --- linux/devices/AcsBoardPolling.cpp | 3 --- linux/devices/Max31865RtdPolling.cpp | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/linux/devices/AcsBoardPolling.cpp b/linux/devices/AcsBoardPolling.cpp index 6a16d816..4742910d 100644 --- a/linux/devices/AcsBoardPolling.cpp +++ b/linux/devices/AcsBoardPolling.cpp @@ -105,7 +105,6 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != adis.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { adis.type = req->type; @@ -135,7 +134,6 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != gyro.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { std::memcpy(gyro.sensorCfg, req->ctrlRegs, 5); @@ -154,7 +152,6 @@ ReturnValue_t AcsBoardPolling::sendMessage(CookieIF* cookie, const uint8_t* send return returnvalue::FAILED; } auto* req = reinterpret_cast(sendData); - MutexGuard mg(ipcLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); if (req->mode != mgm.mode) { if (req->mode == acs::SimpleSensorMode::NORMAL) { mgm.performStartup = true; diff --git a/linux/devices/Max31865RtdPolling.cpp b/linux/devices/Max31865RtdPolling.cpp index 004e7c60..e9053af7 100644 --- a/linux/devices/Max31865RtdPolling.cpp +++ b/linux/devices/Max31865RtdPolling.cpp @@ -26,6 +26,7 @@ ReturnValue_t Max31865RtdPolling::performOperation(uint8_t operationCode) { using namespace MAX31865; ReturnValue_t result = returnvalue::OK; static_cast(result); + // Measured to take 0-1 ms in debug build // Stopwatch watch; if (periodicInitHandling()) { #if OBSW_RTD_AUTO_MODE == 0 From 05be1708908f8a32bdc4feb5fba0ac5f26d435c6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 16:06:38 +0100 Subject: [PATCH 16/20] hotfixees --- CHANGELOG.md | 1 + fsfw | 2 +- linux/devices/Max31865RtdPolling.cpp | 17 +++++------------ mission/controller/acs/control/SafeCtrl.cpp | 2 +- mission/core/GenericFactory.cpp | 6 ++++-- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 496d9cfe..590a2cfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ will consitute of a breaking change warranting a new major release: - Allow quicker transition for the EIVE system component by allowing consecutive TCS and ACS component commanding again. - Changed a lot of lock guards to use timeouts +- Queue sizes of TCP/UDP servers increased from 20 to 50 ## Fixed diff --git a/fsfw b/fsfw index 6e17e455..6006c97e 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 6e17e45506b0d9834d3ae9ded6f044e13e3c4abd +Subproject commit 6006c97e48b7e6dc3b45a832bdd027a510b67f16 diff --git a/linux/devices/Max31865RtdPolling.cpp b/linux/devices/Max31865RtdPolling.cpp index 2edd726f..db13a76c 100644 --- a/linux/devices/Max31865RtdPolling.cpp +++ b/linux/devices/Max31865RtdPolling.cpp @@ -28,17 +28,10 @@ ReturnValue_t Max31865RtdPolling::performOperation(uint8_t operationCode) { static_cast(result); // Measured to take 0-1 ms in debug build // Stopwatch watch; - if (periodicInitHandling()) { -#if OBSW_RTD_AUTO_MODE == 0 - // 10 ms delay for VBIAS startup - TaskFactory::delayTask(10); -#endif - } else { - // No devices usable (e.g. TCS board off) - return returnvalue::OK; - } - + periodicInitHandling(); #if OBSW_RTD_AUTO_MODE == 0 + // 10 ms delay for VBIAS startup + TaskFactory::delayTask(10); result = periodicReadReqHandling(); if (result != returnvalue::OK) { return result; @@ -113,12 +106,12 @@ ReturnValue_t Max31865RtdPolling::periodicInitHandling() { ReturnValue_t Max31865RtdPolling::periodicReadReqHandling() { using namespace MAX31865; + updateActiveRtdsArray(); // Now request one shot config for all active RTDs for (auto& rtd : rtds) { if (rtd == nullptr) { continue; } - updateActiveRtdsArray(); if (activeRtdsArray[rtd->idx]) { ReturnValue_t result = writeCfgReg(rtd->spiCookie, BASE_CFG | (1 << CfgBitPos::ONE_SHOT)); if (result != returnvalue::OK) { @@ -134,12 +127,12 @@ ReturnValue_t Max31865RtdPolling::periodicReadReqHandling() { ReturnValue_t Max31865RtdPolling::periodicReadHandling() { using namespace MAX31865; auto result = returnvalue::OK; + updateActiveRtdsArray(); // Now read the RTD values for (auto& rtd : rtds) { if (rtd == nullptr) { continue; } - updateActiveRtdsArray(); if (activeRtdsArray[rtd->idx]) { // Please note that using the manual CS lock wrapper here is problematic. Might be a SPI // or hardware specific issue where the CS needs to be pulled high and then low again diff --git a/mission/controller/acs/control/SafeCtrl.cpp b/mission/controller/acs/control/SafeCtrl.cpp index 23a86551..5c665156 100644 --- a/mission/controller/acs/control/SafeCtrl.cpp +++ b/mission/controller/acs/control/SafeCtrl.cpp @@ -95,7 +95,7 @@ ReturnValue_t SafeCtrl::safeNoMekf(timeval now, double *susDirB, bool susDirBVal } // change unit from uT to T - double magFieldBT[3] = {0,0,0}; + double magFieldBT[3] = {0, 0, 0}; VectorOperations::mulScalar(magFieldB, 1e-6, magFieldBT, 3); // normalize sunDir and magDir diff --git a/mission/core/GenericFactory.cpp b/mission/core/GenericFactory.cpp index 87b08b49..b6119eda 100644 --- a/mission/core/GenericFactory.cpp +++ b/mission/core/GenericFactory.cpp @@ -117,14 +117,16 @@ void ObjectFactory::produceGenericObjects(HealthTableIF** healthTable_, PusTmFun #if OBSW_ADD_TCPIP_SERVERS == 1 #if OBSW_ADD_TMTC_UDP_SERVER == 1 - auto udpBridge = new UdpTmTcBridge(objects::UDP_TMTC_SERVER, objects::CCSDS_PACKET_DISTRIBUTOR); + auto udpBridge = + new UdpTmTcBridge(objects::UDP_TMTC_SERVER, objects::CCSDS_PACKET_DISTRIBUTOR, 50); new UdpTcPollingTask(objects::UDP_TMTC_POLLING_TASK, objects::UDP_TMTC_SERVER); sif::info << "Created UDP server for TMTC commanding with listener port " << udpBridge->getUdpPort() << std::endl; udpBridge->setMaxNumberOfPacketsStored(config::MAX_STORED_CMDS_UDP); #endif #if OBSW_ADD_TMTC_TCP_SERVER == 1 - auto tcpBridge = new TcpTmTcBridge(objects::TCP_TMTC_SERVER, objects::CCSDS_PACKET_DISTRIBUTOR); + auto tcpBridge = + new TcpTmTcBridge(objects::TCP_TMTC_SERVER, objects::CCSDS_PACKET_DISTRIBUTOR, 50); TcpTmTcServer::TcpConfig cfg(true, true); auto tcpServer = new TcpTmTcServer(objects::TCP_TMTC_POLLING_TASK, objects::TCP_TMTC_SERVER, cfg); // TCP is stream based. Use packet ID as start marker when parsing for space packets From 3b383b98df182be0c6321b5e468c7fb637264db5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 16:45:25 +0100 Subject: [PATCH 17/20] prep v1.34.0 --- CHANGELOG.md | 22 ++++++++++++++-------- CMakeLists.txt | 2 +- fsfw | 2 +- tmtc | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 590a2cfd..90845628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,12 @@ will consitute of a breaking change warranting a new major release: # [unreleased] +# [v1.34.0] 2023-03-03 + +This might include the fix for the race condition where CPU usage jumped to 200 %. The race +condition was traced to the `Countdown` class, more specifically to the `getUptime` function where +the `/proc/uptime` file is read. + ## Changed - Moved polling of all SPI parts to the same PST. @@ -37,7 +43,7 @@ will consitute of a breaking change warranting a new major release: - Added Syrlinks Assembly object to allow recovery handling and to fix faulty FDIR behaviour. -# [v1.33.0] +# [v1.33.0] 2023-03-01 eive-tmtc: v2.16.2 @@ -51,7 +57,7 @@ eive-tmtc: v2.16.2 - Linux GPS handler now checks the individual `*_SET` flags when analysing the `gpsd` struct. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/400 -# [v1.32.0] +# [v1.32.0] 2023-02-24 eive-tmtc: v2.16.1 @@ -92,7 +98,7 @@ eive-tmtc: v2.16.1 - `RwDummy` now initializes with a non faulty state -# [v1.31.1] +# [v1.31.1] 2023-02-23 ## Fixed @@ -102,7 +108,7 @@ eive-tmtc: v2.16.1 for actuator control which lead to a crash. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/403 -# [v1.31.0] +# [v1.31.0] 2023-02-23 eive-tmtc: v2.16.0 @@ -143,7 +149,7 @@ COM PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/364 - `MekfData` now includes `mekfStatus` - `CtrlValData` now includes `tgtRotRate` -# [v1.30.0] +# [v1.30.0] 2023-02-22 eive-tmtc: v2.14.0 @@ -160,7 +166,7 @@ Event IDs for PDEC handler have changed in a breaking manner. an event is triggered and the task is delayed for 400 ms. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/393 -# [v1.29.1] +# [v1.29.1] 2023-02-21 ## Fixed @@ -172,7 +178,7 @@ Event IDs for PDEC handler have changed in a breaking manner. Issue: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/issues/388 - Disable stopwatch in MAX31865 polling task -# [v1.29.0] +# [v1.29.0] 2023-02-21 eive-tmtc: v2.13.0 @@ -193,7 +199,7 @@ eive-tmtc: v2.13.0 will be part of the TCS tree. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/351 -# [v1.28.1] +# [v1.28.1] 2023-02-21 ## Fixed diff --git a/CMakeLists.txt b/CMakeLists.txt index f477d205..588bf233 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.13) set(OBSW_VERSION_MAJOR 1) -set(OBSW_VERSION_MINOR 33) +set(OBSW_VERSION_MINOR 34) set(OBSW_VERSION_REVISION 0) # set(CMAKE_VERBOSE TRUE) diff --git a/fsfw b/fsfw index 6006c97e..33de1520 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 6006c97e48b7e6dc3b45a832bdd027a510b67f16 +Subproject commit 33de15205b4560c54a108e35609536374b026c22 diff --git a/tmtc b/tmtc index 783d5a8e..a9e59ae4 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 783d5a8ed56a9683fc75d2aaffcabe82af34ffa9 +Subproject commit a9e59ae42b3f2f3a13a0bc96f56524f2d78e1eba From 0d175951ec7044805dae33d0f56f69ecfa135ef7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 16:49:21 +0100 Subject: [PATCH 18/20] some missing changelog entries --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90845628..80fd32f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ the `/proc/uptime` file is read. component commanding again. - Changed a lot of lock guards to use timeouts - Queue sizes of TCP/UDP servers increased from 20 to 50 +- Significantly simplified and improved lock guard handling in TCS and ACS board polling + tasks. ## Fixed @@ -37,7 +39,10 @@ the `/proc/uptime` file is read. - Fixed units in calculation of ACS control laws safe and detumble. - Bump FSFW for change in Countdown: Use system clock instead of reading uptime from file to prevent possible race condition. -- GPS: No fix for 30 minutes considered a faulty now instead of 5 hours. +- GPS: No fix considered a fault now after 30 minutes instead of 5 hours. +- SUS Assembly FDIR: Prevent permanent SAFE mode fallbacks by introducing special health + handling. + PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/418/files ## Added From 982db82ddbacdd59f0dc60cd80355bc50028ca02 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 16:52:10 +0100 Subject: [PATCH 19/20] bump tmtc --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index a9e59ae4..94ae2d16 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a9e59ae42b3f2f3a13a0bc96f56524f2d78e1eba +Subproject commit 94ae2d16e21ade8f89723b2e62356967a67b171d From e6b0b4048c7cf1af1a568b15068c65c1978b478f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 3 Mar 2023 16:52:38 +0100 Subject: [PATCH 20/20] changelog eive-tmtc version --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80fd32f4..0e279f6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ will consitute of a breaking change warranting a new major release: # [v1.34.0] 2023-03-03 +eive-tmtc: v2.16.3 + This might include the fix for the race condition where CPU usage jumped to 200 %. The race condition was traced to the `Countdown` class, more specifically to the `getUptime` function where the `/proc/uptime` file is read.