added local parameter handler to PdecConfig to store persistent parameters

This commit is contained in:
Jakob Meier 2023-02-23 10:09:04 +01:00
parent 28f3b07c5c
commit 3b17af9d07
8 changed files with 89 additions and 47 deletions

View File

@ -22,7 +22,7 @@ ReturnValue_t FilesystemHelper::checkPath(std::string path) {
}
} else if (path.substr(0, sizeof(config::SD_1_MOUNT_POINT)) ==
std::string(config::SD_1_MOUNT_POINT)) {
if (!sdcMan->isSdCardUsable(sd::SLOT_0)) {
if (!sdcMan->isSdCardUsable(sd::SLOT_1)) {
sif::warning << "FilesystemHelper::checkPath: SD card 1 not mounted" << std::endl;
return SD_NOT_MOUNTED;
}

View File

@ -8,7 +8,14 @@ LocalParameterHandler::~LocalParameterHandler() {
}
ReturnValue_t LocalParameterHandler::initialize() {
std::string mountPrefix = sdcMan->getCurrentMountPrefix();
std::string mountPrefix;
auto activeSd = sdcMan->getActiveSdCard();
if (activeSd and sdcMan->isSdCardUsable(activeSd.value())) {
mountPrefix = sdcMan->getCurrentMountPrefix();
} else {
return SD_NOT_READY;
}
mountPrefix = sdcMan->getCurrentMountPrefix();
std::string fullname = mountPrefix + "/" + sdRelativeName;
setFullName(fullname);
ReturnValue_t result = readJsonFile();

View File

@ -13,6 +13,10 @@
*/
class LocalParameterHandler : public NVMParameterBase {
public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_PARAM_HANDLER;
static constexpr ReturnValue_t SD_NOT_READY = returnvalue::makeCode(INTERFACE_ID, 0);
/**
* @brief Constructor
*

View File

@ -15,6 +15,7 @@ enum {
CLASS_ID_START = COMMON_CLASS_ID_END,
SD_CARD_MANAGER, // SDMA
SCRATCH_BUFFER, // SCBU
LOCAL_PARAM_HANDLER, // LPH
CLASS_ID_END // [EXPORT] : [END]
};
}

View File

@ -4,7 +4,7 @@
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "pdecconfigdefs.h"
PdecConfig::PdecConfig() : localParameterHandler("conf/pdecconfig", SdCardManager::instance()) {}
PdecConfig::PdecConfig() : localParameterHandler("conf/pdecconfig.json", SdCardManager::instance()) {}
PdecConfig::~PdecConfig() {}
@ -35,15 +35,13 @@ ReturnValue_t PdecConfig::write() {
ReturnValue_t PdecConfig::initializePersistentParameters() {
ReturnValue_t result = localParameterHandler.initialize();
if (result != returnvalue::OK) {
if (result == HasFileSystemIF::FILE_DOES_NOT_EXIST) {
result = createPersistentConfig();
if (result != returnvalue::OK) {
return result;
}
}
}
return returnvalue::OK;
if (result == HasFileSystemIF::FILE_DOES_NOT_EXIST) {
result = createPersistentConfig();
if (result != returnvalue::OK) {
return result;
}
}
return result;
}
ReturnValue_t PdecConfig::createPersistentConfig() {

View File

@ -77,22 +77,6 @@ ReturnValue_t PdecHandler::initialize() {
return returnvalue::FAILED;
}
result = pdecConfig.write();
if (result != returnvalue::OK) {
sif::error << "PdecHandler::initialize: Failed to write PDEC config" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
result = releasePdec();
if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
// This configuration must be done while the PDEC is not held in reset.
if (OP_MODE == Modes::IRQ) {
// Configure interrupt mask register to enable interrupts
*(registerBaseAddress + PDEC_IMR_OFFSET) = pdecConfig.getImrReg();
}
result = actionHelper.initialize(commandQueue);
if (result != returnvalue::OK) {
return result;
@ -101,6 +85,36 @@ ReturnValue_t PdecHandler::initialize() {
return returnvalue::OK;
}
ReturnValue_t PdecHandler::firstLoop() {
ReturnValue_t result = pdecConfig.write();
if (result != returnvalue::OK) {
if (result == LocalParameterHandler::SD_NOT_READY) {
return result;
} else {
sif::error << "PdecHandler::firstLoop: Failed to write PDEC config" << std::endl;
}
return returnvalue::FAILED;
}
result = releasePdec();
if (result != returnvalue::OK) {
return returnvalue::FAILED;
}
// This configuration must be done while the PDEC is not held in reset.
if (OP_MODE == Modes::IRQ) {
// Configure interrupt mask register to enable interrupts
*(registerBaseAddress + PDEC_IMR_OFFSET) = pdecConfig.getImrReg();
}
result = resetFarStatFlag();
if (result != returnvalue::OK) {
// Requires reconfiguration and reinitialization of PDEC
triggerEvent(INVALID_FAR);
return result;
}
return returnvalue::OK;
}
ReturnValue_t PdecHandler::performOperation(uint8_t operationCode) {
if (OP_MODE == Modes::POLLED) {
return polledOperation();
@ -111,19 +125,11 @@ ReturnValue_t PdecHandler::performOperation(uint8_t operationCode) {
}
ReturnValue_t PdecHandler::polledOperation() {
ReturnValue_t result = returnvalue::OK;
readCommandQueue();
switch (state) {
case State::INIT:
resetFarStatFlag();
if (result != returnvalue::OK) {
// Requires reconfiguration and reinitialization of PDEC
triggerEvent(INVALID_FAR);
state = State::WAIT_FOR_RECOVERY;
break;
}
state = State::RUNNING;
handleInitState();
break;
case State::RUNNING:
if (newTcReceived()) {
@ -143,7 +149,6 @@ ReturnValue_t PdecHandler::polledOperation() {
// See https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html for more information.
ReturnValue_t PdecHandler::irqOperation() {
ReturnValue_t result = returnvalue::OK;
int fd = open(uioNames.irq, O_RDWR);
if (fd < 0) {
sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed"
@ -166,14 +171,7 @@ ReturnValue_t PdecHandler::irqOperation() {
readCommandQueue();
switch (state) {
case State::INIT:
result = resetFarStatFlag();
if (result != returnvalue::OK) {
// Requires reconfiguration and reinitialization of PDEC
triggerEvent(INVALID_FAR);
state = State::WAIT_FOR_RECOVERY;
return result;
}
state = State::RUNNING;
handleInitState();
break;
case State::RUNNING: {
checkAndHandleIrqs(fd, info);
@ -194,6 +192,27 @@ ReturnValue_t PdecHandler::irqOperation() {
return returnvalue::OK;
}
void PdecHandler::handleInitState() {
ReturnValue_t result = firstLoop();
if (result != returnvalue::OK) {
if (result == LocalParameterHandler::SD_NOT_READY) {
TaskFactory::delayTask(400);
if (initTries == MAX_INIT_TRIES) {
sif::error << "PdecHandler::handleInitState: SD card never "
"becomes ready"
<< std::endl;
state = State::WAIT_FOR_RECOVERY;
return;
} else {
state = State::INIT;
return;
}
}
state = State::WAIT_FOR_RECOVERY;
}
state = State::RUNNING;
}
ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) {
ssize_t nb = write(fd, &info, sizeof(info));
if (nb != static_cast<ssize_t>(sizeof(info))) {

View File

@ -169,6 +169,8 @@ class PdecHandler : public SystemObject,
static const uint32_t NO_RF_MASK = 0x8000;
static const uint32_t NO_BITLOCK_MASK = 0x4000;
static const uint32_t MAX_INIT_TRIES = 20;
class ParameterId {
public:
// ID of the parameter to update the positive window of AD frames
@ -258,6 +260,16 @@ class PdecHandler : public SystemObject,
PdecConfig pdecConfig;
uint32_t initTries = 0;
/**
* @brief Performs initialization stuff which must be performed in first
* loop of running task
*
* @return OK if successful, otherwise FAILED
*/
ReturnValue_t firstLoop();
/**
* @brief Reads and handles messages stored in the commandQueue
*/
@ -265,6 +277,7 @@ class PdecHandler : public SystemObject,
ReturnValue_t polledOperation();
ReturnValue_t irqOperation();
void handleInitState();
ReturnValue_t checkAndHandleIrqs(int fd, uint32_t& info);
uint32_t readFar();

View File

@ -664,7 +664,7 @@ ReturnValue_t PayloadPcduHandler::getParameter(uint8_t domainId, uint8_t uniqueI
}
void PayloadPcduHandler::handleFailureInjection(std::string output, Event event) {
sif::info << "PayloadPcduHandler::checkAdcValues: " << output
sif::info << "PayloadPcduHandler::handleFailureInjection: " << output
<< " failure injection. "
"Transitioning back to off"
<< std::endl;